Merge branch '0823-dev' into 'new-frontend'
Add note search plugin. See merge request kylin-desktop/ukui-search!110
This commit is contained in:
commit
23b9faf6c8
|
@ -837,3 +837,60 @@ QString FileUtils::chineseSubString(const std::string &myStr, int start, int len
|
|||
}
|
||||
return sub;
|
||||
}
|
||||
|
||||
QString FileUtils::getHtmlText(const QString &text, const QString &keyword)
|
||||
{
|
||||
QString htmlString;
|
||||
bool boldOpenned = false;
|
||||
for(int i = 0; i < text.length(); i++) {
|
||||
if((keyword.toUpper()).contains(QString(text.at(i)).toUpper())) {
|
||||
if(! boldOpenned) {
|
||||
boldOpenned = true;
|
||||
htmlString.append(QString("<b><font size=\"4\">"));
|
||||
}
|
||||
htmlString.append(FileUtils::escapeHtml(QString(text.at(i))));
|
||||
} else {
|
||||
if(boldOpenned) {
|
||||
boldOpenned = false;
|
||||
htmlString.append(QString("</font></b>"));
|
||||
}
|
||||
htmlString.append(FileUtils::escapeHtml(QString(text.at(i))));
|
||||
}
|
||||
}
|
||||
htmlString.replace("\n", "<br />");//替换换行符
|
||||
return htmlString;
|
||||
}
|
||||
|
||||
QString FileUtils::wrapData(QLabel *p_label, const QString &text)
|
||||
{
|
||||
QString wrapText = text;
|
||||
|
||||
QFontMetrics fontMetrics = p_label->fontMetrics();
|
||||
int textSize = fontMetrics.width(wrapText);
|
||||
|
||||
if(textSize > LABEL_MAX_WIDTH){
|
||||
int lastIndex = 0;
|
||||
int count = 0;
|
||||
|
||||
for(int i = lastIndex; i < wrapText.length(); i++) {
|
||||
|
||||
if(fontMetrics.width(wrapText.mid(lastIndex, i - lastIndex)) == LABEL_MAX_WIDTH) {
|
||||
lastIndex = i;
|
||||
wrapText.insert(i, '\n');
|
||||
count++;
|
||||
} else if(fontMetrics.width(wrapText.mid(lastIndex, i - lastIndex)) > LABEL_MAX_WIDTH) {
|
||||
lastIndex = i;
|
||||
wrapText.insert(i - 1, '\n');
|
||||
count++;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(count == 2){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// p_label->setText(wrapText);
|
||||
return wrapText;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QFontMetrics>
|
||||
#include <QLabel>
|
||||
|
||||
#include <quazip/quazipfile.h>
|
||||
#include <stdio.h>
|
||||
|
@ -62,6 +63,8 @@
|
|||
namespace Zeeker {
|
||||
class LIBSEARCH_EXPORT FileUtils {
|
||||
public:
|
||||
static QString getHtmlText(const QString & text, const QString & keyword);
|
||||
static QString wrapData(QLabel *p_label, const QString &text);
|
||||
static std::string makeDocUterm(QString);
|
||||
static QIcon getFileIcon(const QString &, bool checkValid = true);
|
||||
static QIcon getAppIcon(const QString &);
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
#include "libsearch_global.h"
|
||||
#include "appsearch/app-match.h"
|
||||
#include "settingsearch/setting-match.h"
|
||||
#include "file-utils.h"
|
||||
#include "global-settings.h"
|
||||
|
||||
|
|
|
@ -27,11 +27,10 @@ DEFINES += PLUGIN_INSTALL_DIRS='\\"$${PLUGIN_INSTALL_DIRS}\\"'
|
|||
include(pluginmanage/plugin-manager.pri)
|
||||
include(plugininterface/plugin-interface.pri)
|
||||
include(index/index.pri)
|
||||
include(parser/parser.pri))
|
||||
include(parser/parser.pri)
|
||||
include(appsearch/appsearch.pri)
|
||||
include(settingsearch/settingsearch.pri))
|
||||
|
||||
|
||||
include(notesearch/notesearch.pri)
|
||||
include(settingsearch/settingsearch.pri)
|
||||
|
||||
LIBS += -L$$OUT_PWD/../libchinese-segmentation/ -lchinese-segmentation
|
||||
LIBS += -lxapian -lquazip5 -luchardet #-L/usr/local/lib/libjemalloc -ljemalloc
|
||||
|
|
|
@ -0,0 +1,206 @@
|
|||
#include "note-search-plugin.h"
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include "file-utils.h"
|
||||
#include "chinese-segmentation.h"
|
||||
using namespace Zeeker;
|
||||
|
||||
NoteSearchPlugin::NoteSearchPlugin(QObject *parent)
|
||||
{
|
||||
g_uniqueSymbol = 0;
|
||||
SearchPluginIface::Actioninfo open { 0, tr("Open")};
|
||||
m_actionInfo << open;
|
||||
m_pool.setMaxThreadCount(1);
|
||||
m_pool.setExpiryTimeout(1000);
|
||||
initDetailPage();
|
||||
}
|
||||
|
||||
const QString NoteSearchPlugin::name()
|
||||
{
|
||||
return tr("Note Search");
|
||||
}
|
||||
|
||||
const QString NoteSearchPlugin::description()
|
||||
{
|
||||
return tr("Note Search.");
|
||||
}
|
||||
|
||||
QString NoteSearchPlugin::getPluginName()
|
||||
{
|
||||
return tr("Note Search");
|
||||
}
|
||||
|
||||
void NoteSearchPlugin::KeywordSearch(QString keyword, DataQueue<SearchPluginIface::ResultInfo> *searchResult)
|
||||
{
|
||||
g_mutex.lock();
|
||||
++g_uniqueSymbol;
|
||||
g_mutex.unlock();
|
||||
m_keyword = keyword;
|
||||
NoteSearch *ns = new NoteSearch(searchResult, keyword, g_uniqueSymbol);
|
||||
m_pool.start(ns);
|
||||
}
|
||||
|
||||
QList<SearchPluginIface::Actioninfo> NoteSearchPlugin::getActioninfo(int type)
|
||||
{
|
||||
return m_actionInfo;
|
||||
}
|
||||
|
||||
void NoteSearchPlugin::openAction(int actionkey, QString key, int type)
|
||||
{
|
||||
QProcess process;
|
||||
switch (actionkey) {
|
||||
case 0:
|
||||
process.startDetached(QString("ukui-notebook --show %1").arg(key.toInt()));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QWidget *NoteSearchPlugin::detailPage(const SearchPluginIface::ResultInfo &ri)
|
||||
{
|
||||
m_currentActionKey = ri.actionKey;
|
||||
m_iconLabel->setPixmap(ri.icon.pixmap(120, 120));
|
||||
QFontMetrics fontMetrics = m_nameLabel->fontMetrics();
|
||||
QString showname = fontMetrics.elidedText(ri.name, Qt::ElideRight, 215); //当字体长度超过215时显示为省略号
|
||||
m_nameLabel->setText(QString("<h3 style=\"font-weight:normal;\">%1</h3>").arg(FileUtils::escapeHtml(showname)));
|
||||
if(QString::compare(showname, ri.name)) {
|
||||
m_nameLabel->setToolTip(ri.name);
|
||||
}
|
||||
m_pluginLabel->setText(tr("Application"));
|
||||
QString showDesc = fontMetrics.elidedText(/*ri.description.at(0).key + " " + */ri.description.at(0).value, Qt::ElideRight, m_descLabel->width() * 2); //当字体长度超过215时显示为省略号
|
||||
m_descLabel->setText(FileUtils::getHtmlText(FileUtils::wrapData(m_descLabel, showDesc), m_keyword));
|
||||
m_descFrame->show();
|
||||
m_line_2->show();
|
||||
return m_detailPage;
|
||||
}
|
||||
|
||||
void NoteSearchPlugin::initDetailPage()
|
||||
{
|
||||
m_detailPage = new QWidget();
|
||||
m_detailPage->setFixedWidth(360);
|
||||
m_detailPage->setAttribute(Qt::WA_TranslucentBackground);
|
||||
m_detailLyt = new QVBoxLayout(m_detailPage);
|
||||
m_detailLyt->setContentsMargins(8, 0, 16, 0);
|
||||
m_iconLabel = new QLabel(m_detailPage);
|
||||
m_iconLabel->setAlignment(Qt::AlignCenter);
|
||||
m_iconLabel->setFixedHeight(128);
|
||||
|
||||
m_nameFrame = new QFrame(m_detailPage);
|
||||
m_nameFrameLyt = new QHBoxLayout(m_nameFrame);
|
||||
m_nameFrame->setLayout(m_nameFrameLyt);
|
||||
m_nameFrameLyt->setContentsMargins(8, 0, 0, 0);
|
||||
m_nameLabel = new QLabel(m_nameFrame);
|
||||
m_nameLabel->setMaximumWidth(280);
|
||||
m_pluginLabel = new QLabel(m_nameFrame);
|
||||
m_pluginLabel->setText(tr("Note Search"));
|
||||
m_pluginLabel->setEnabled(false);
|
||||
m_nameFrameLyt->addWidget(m_nameLabel);
|
||||
m_nameFrameLyt->addStretch();
|
||||
m_nameFrameLyt->addWidget(m_pluginLabel);
|
||||
|
||||
m_line_1 = new QFrame(m_detailPage);
|
||||
m_line_1->setLineWidth(0);
|
||||
m_line_1->setFixedHeight(1);
|
||||
m_line_1->setStyleSheet("QFrame{background: rgba(0,0,0,0.2);}");
|
||||
m_descFrame = new QFrame(m_detailPage);
|
||||
m_descFrameLyt = new QVBoxLayout(m_descFrame);
|
||||
m_descLabel = new QLabel(m_descFrame);
|
||||
m_descLabel->setTextFormat(Qt::AutoText);
|
||||
m_descLabel->setWordWrap(true);
|
||||
m_descFrameLyt->addWidget(m_descLabel);
|
||||
m_descFrame->setLayout(m_descFrameLyt);
|
||||
m_descFrameLyt->setContentsMargins(8, 0, 0, 0);
|
||||
m_line_2 = new QFrame(m_detailPage);
|
||||
m_line_2->setLineWidth(0);
|
||||
m_line_2->setFixedHeight(1);
|
||||
m_line_2->setStyleSheet("QFrame{background: rgba(0,0,0,0.2);}");
|
||||
|
||||
m_line_1 = new QFrame(m_detailPage);
|
||||
m_line_1->setLineWidth(0);
|
||||
m_line_1->setFixedHeight(1);
|
||||
m_line_1->setStyleSheet("QFrame{background: rgba(0,0,0,0.2);}");
|
||||
|
||||
m_actionFrame = new QFrame(m_detailPage);
|
||||
m_actionFrameLyt = new QVBoxLayout(m_actionFrame);
|
||||
m_actionFrameLyt->setContentsMargins(8, 0, 0, 0);
|
||||
m_actionLabel1 = new ActionLabel(tr("Open"), m_currentActionKey, m_actionFrame);
|
||||
|
||||
m_actionFrameLyt->addWidget(m_actionLabel1);;
|
||||
m_actionFrame->setLayout(m_actionFrameLyt);
|
||||
|
||||
m_detailLyt->addSpacing(50);
|
||||
m_detailLyt->addWidget(m_iconLabel);
|
||||
m_detailLyt->addWidget(m_nameFrame);
|
||||
m_detailLyt->addWidget(m_line_1);
|
||||
m_detailLyt->addWidget(m_descFrame);
|
||||
m_detailLyt->addWidget(m_line_2);
|
||||
m_detailLyt->addWidget(m_actionFrame);
|
||||
m_detailPage->setLayout(m_detailLyt);
|
||||
m_detailLyt->addStretch();
|
||||
|
||||
connect(m_actionLabel1, &ActionLabel::actionTriggered, [ & ](){
|
||||
openAction(0, m_currentActionKey, 0);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
NoteSearch::NoteSearch(DataQueue<SearchPluginIface::ResultInfo> *searchResult, const QString &keyword, size_t uniqueSymbol) {
|
||||
this->setAutoDelete(true);
|
||||
this->m_searchResult = searchResult;
|
||||
this->m_keyword = keyword;
|
||||
this->m_uniqueSymbol = uniqueSymbol;
|
||||
}
|
||||
|
||||
void NoteSearch::run() {
|
||||
QVector<SKeyWord> sKeyWordVec = ChineseSegmentation::getInstance()->callSegement(m_keyword.toStdString());
|
||||
QStringList keywordList;
|
||||
for (SKeyWord sKeyWord : sKeyWordVec) {
|
||||
keywordList.append(QString::fromStdString(sKeyWord.word));
|
||||
}
|
||||
QDBusInterface qi("org.ukui.note", "/org/ukui/note", "org.ukui.note.interface", QDBusConnection::sessionBus());
|
||||
QDBusReply<QVariantMap> reply = qi.call("keywordMatch", keywordList);
|
||||
|
||||
if(reply.isValid()) {
|
||||
if (m_uniqueSymbol ^ g_uniqueSymbol) {
|
||||
qDebug() << m_uniqueSymbol << g_uniqueSymbol;
|
||||
return;
|
||||
} else {
|
||||
qDebug() << m_uniqueSymbol << g_uniqueSymbol;
|
||||
|
||||
for (std::pair<QString, QVariant> it : reply.value().toStdMap()) {
|
||||
qDebug() << it.first;
|
||||
qDebug() << it.second;
|
||||
qDebug() << it.second.value<QDBusArgument>().currentType();
|
||||
QDBusArgument dbusArgs = it.second.value<QDBusArgument>();
|
||||
QStringList str;
|
||||
dbusArgs.beginArray();
|
||||
while (!dbusArgs.atEnd()) {
|
||||
QVariant tmp;
|
||||
dbusArgs >> tmp;
|
||||
str.append(tmp.toString());
|
||||
}
|
||||
dbusArgs.endArray();
|
||||
qDebug() << str;
|
||||
SearchPluginIface::ResultInfo ri = {
|
||||
icon : QIcon::fromTheme("kylin-notebook"),
|
||||
name : str.at(1),
|
||||
description : QVector<SearchPluginIface::DescriptionInfo>() << SearchPluginIface::DescriptionInfo {
|
||||
key : QString(tr("Note Description:")),
|
||||
value : str.at(0)
|
||||
},
|
||||
actionKey : it.first
|
||||
};
|
||||
if (m_uniqueSymbol ^ g_uniqueSymbol) {
|
||||
qDebug() << m_uniqueSymbol << g_uniqueSymbol;
|
||||
return;
|
||||
} else {
|
||||
m_searchResult->enqueue(ri);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qWarning() << "Note dbus called failed!" << qi.lastError();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
#ifndef NOTESEARCHPLUGIN_H
|
||||
#define NOTESEARCHPLUGIN_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QFrame>
|
||||
#include <QLabel>
|
||||
#include <QAction>
|
||||
#include <QDBusInterface>
|
||||
#include <QThreadPool>
|
||||
#include <QProcess>
|
||||
#include <QDBusReply>
|
||||
#include <typeinfo>
|
||||
#include "search-plugin-iface.h"
|
||||
#include "action-label.h"
|
||||
#include "libsearch_global.h"
|
||||
namespace Zeeker {
|
||||
|
||||
static size_t g_uniqueSymbol;
|
||||
static QMutex g_mutex;
|
||||
|
||||
class NoteSearch;
|
||||
|
||||
class LIBSEARCH_EXPORT NoteSearchPlugin : public QObject, public SearchPluginIface
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class NoteSearch;
|
||||
public:
|
||||
NoteSearchPlugin(QObject *parent = nullptr);
|
||||
PluginType pluginType() {return PluginType::SearchPlugin;}
|
||||
const QString name();
|
||||
const QString description();
|
||||
const QIcon icon() {return QIcon::fromTheme("folder");}
|
||||
void setEnable(bool enable) {m_enable = enable;}
|
||||
bool isEnable() {return m_enable;}
|
||||
QString getPluginName();
|
||||
|
||||
void KeywordSearch(QString keyword,DataQueue<ResultInfo> *searchResult);
|
||||
QList<SearchPluginIface::Actioninfo> getActioninfo(int type);
|
||||
void openAction(int actionkey, QString key, int type);
|
||||
// bool isPreviewEnable(QString key, int type);
|
||||
// QWidget *previewPage(QString key, int type, QWidget *parent);
|
||||
QWidget *detailPage(const ResultInfo &ri);
|
||||
|
||||
private:
|
||||
QDBusInterface *m_interFace = nullptr;
|
||||
void initDetailPage();
|
||||
QString m_currentActionKey;
|
||||
QWidget *m_detailPage = nullptr;
|
||||
QVBoxLayout *m_detailLyt = nullptr;
|
||||
QLabel *m_iconLabel = nullptr;
|
||||
QFrame *m_nameFrame = nullptr;
|
||||
QHBoxLayout *m_nameFrameLyt = nullptr;
|
||||
QLabel *m_nameLabel = nullptr;
|
||||
QLabel *m_pluginLabel = nullptr;
|
||||
QFrame *m_line_1 = nullptr;
|
||||
QFrame *m_descFrame = nullptr;
|
||||
QLabel *m_descLabel = nullptr;
|
||||
QVBoxLayout *m_descFrameLyt = nullptr;
|
||||
QFrame *m_line_2 = nullptr;
|
||||
QFrame *m_actionFrame = nullptr;
|
||||
QVBoxLayout *m_actionFrameLyt = nullptr;
|
||||
ActionLabel *m_actionLabel1 = nullptr;
|
||||
QVBoxLayout * m_actionLyt = nullptr;
|
||||
|
||||
bool m_enable = true;
|
||||
QString m_keyword;
|
||||
QList<NoteSearchPlugin::Actioninfo> m_actionInfo;
|
||||
QThreadPool m_pool;
|
||||
};
|
||||
|
||||
class NoteSearch : public QObject, public QRunnable {
|
||||
Q_OBJECT
|
||||
public:
|
||||
NoteSearch(DataQueue<SearchPluginIface::ResultInfo> *searchResult, const QString& keyword, size_t uniqueSymbol);
|
||||
~NoteSearch() = default;
|
||||
protected:
|
||||
void run() override;
|
||||
private:
|
||||
QString m_keyword;
|
||||
DataQueue<SearchPluginIface::ResultInfo> *m_searchResult = nullptr;
|
||||
size_t m_uniqueSymbol;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NOTESEARCHPLUGIN_H
|
|
@ -0,0 +1,7 @@
|
|||
INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/note-search-plugin.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/note-search-plugin.cpp
|
|
@ -1,8 +1,9 @@
|
|||
#include <QDebug>
|
||||
#include "search-plugin-manager.h"
|
||||
#include "file-search-plugin.h"
|
||||
#include "app-search-plugin.h"-
|
||||
#include "app-search-plugin.h"
|
||||
#include "settings-search-plugin.h"
|
||||
#include "note-search-plugin.h"
|
||||
|
||||
using namespace Zeeker;
|
||||
|
||||
|
@ -10,6 +11,7 @@ static SearchPluginManager *global_instance = nullptr;
|
|||
SearchPluginManager::SearchPluginManager(QObject *parent)
|
||||
{
|
||||
registerPlugin(new AppSearchPlugin(this));
|
||||
registerPlugin(new NoteSearchPlugin(this));
|
||||
registerPlugin(new SettingsSearchPlugin(this));
|
||||
registerPlugin(new DirSearchPlugin(this));
|
||||
registerPlugin(new FileSearchPlugin(this));
|
||||
|
|
|
@ -1,156 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2020, KylinSoft Co., Ltd.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: sunfengsheng <sunfengsheng@kylinos.cn>
|
||||
*
|
||||
*/
|
||||
#include "setting-match.h"
|
||||
#include "file-utils.h"
|
||||
#include <QProcessEnvironment>
|
||||
using namespace Zeeker;
|
||||
SettingsMatch::SettingsMatch(QObject *parent) : QObject(parent) {
|
||||
xmlElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SettingsMatch::startMatchApp
|
||||
* 返回给页面
|
||||
* @param source
|
||||
* 获取的字符串
|
||||
* @return
|
||||
*/
|
||||
QStringList SettingsMatch::startMatchApp(const QString &source) {
|
||||
m_sourceText = source;
|
||||
QStringList settingList = matching();
|
||||
return settingList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SettingsMatch::xmlElement
|
||||
* 将xml文件内容读到内存
|
||||
*/
|
||||
void SettingsMatch::xmlElement() {
|
||||
QString ChineseIndex;
|
||||
QString EnglishIndex;
|
||||
QString path = QProcessEnvironment::systemEnvironment().value("XDG_SESSION_TYPE");
|
||||
QString version;
|
||||
QFile file(QString::fromLocal8Bit("/usr/share/ukui-control-center/shell/res/search.xml"));
|
||||
if(!file.open(QIODevice::ReadOnly)) {
|
||||
return;
|
||||
}
|
||||
QDomDocument doc;
|
||||
doc.setContent(&file);
|
||||
QDomElement root = doc.documentElement();
|
||||
QDomNode node = root.previousSibling();
|
||||
node = root.firstChild();
|
||||
|
||||
while(!node.isNull()) {
|
||||
QDomElement element = node.toElement();
|
||||
QString key = element.attribute("name");
|
||||
m_chine_searchResult = m_chine_searchList.value(key);
|
||||
m_English_searchResult = m_English_searchList.value(key);
|
||||
QDomNodeList list = element.childNodes();
|
||||
for(int i = 0; i < list.count(); ++i) {
|
||||
QDomNode n = list.at(i);
|
||||
if(n.nodeName()==QString::fromLocal8Bit("Environment")){
|
||||
version=n.toElement().text();
|
||||
if((version=="v101"&&path=="wayland")||(version=="hw990"&&path=="x11")){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(n.nodeName() == QString::fromLocal8Bit("ChinesePlugin")) {
|
||||
ChineseIndex = n.toElement().text();
|
||||
}
|
||||
if(n.nodeName() == QString::fromLocal8Bit("ChineseFunc")) {
|
||||
ChineseIndex += QString::fromLocal8Bit("/") + n.toElement().text();
|
||||
m_chine_searchResult.append(ChineseIndex);
|
||||
}
|
||||
if(n.nodeName() == QString::fromLocal8Bit("EnglishFunc")) {
|
||||
EnglishIndex = QString::fromLocal8Bit("/") + n.toElement().text();
|
||||
m_English_searchResult.append(EnglishIndex);
|
||||
}
|
||||
}
|
||||
m_chine_searchList.insert(key, m_chine_searchResult);
|
||||
m_English_searchList.insert(key, m_English_searchResult);
|
||||
node = node.nextSibling();
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SettingsMatch::matching
|
||||
* 进行关键字匹配
|
||||
* @return
|
||||
*/
|
||||
QStringList SettingsMatch::matching() {
|
||||
QStringList returnresult;
|
||||
QStringList regmatch;
|
||||
QString key;
|
||||
QStringList pinyinlist;
|
||||
QMap<QString, QStringList>::const_iterator i;
|
||||
QLocale ql;
|
||||
if(ql.language() == QLocale::Chinese) {
|
||||
for(i = m_chine_searchList.constBegin(); i != m_chine_searchList.constEnd(); ++i) {
|
||||
regmatch = *i;
|
||||
key = i.key();
|
||||
for(int t = 0; t < regmatch.size(); t++) {
|
||||
if(m_sourceText == "/")
|
||||
continue;
|
||||
QString str = regmatch.at(t);
|
||||
pinyinlist = FileUtils::findMultiToneWords(str);
|
||||
if(str.contains(m_sourceText)) {
|
||||
str = key + "/" + str;
|
||||
returnresult.append(str);//中文名
|
||||
continue;
|
||||
}
|
||||
for(int i = 0; i < pinyinlist.size() / 2; i++) {
|
||||
str = regmatch.at(t);
|
||||
QString shouzimu = pinyinlist.at(2 * i + 1); // 中文转首字母
|
||||
if(shouzimu.contains(m_sourceText, Qt::CaseInsensitive)) {
|
||||
str = key + "/" + str;
|
||||
returnresult.append(str);
|
||||
break;
|
||||
}
|
||||
if(m_sourceText.size() < 2)
|
||||
break;
|
||||
QString pinyin = pinyinlist.at(2 * i); // 中文转拼音
|
||||
if(pinyin.contains(m_sourceText, Qt::CaseInsensitive)) {
|
||||
str = key + "/" + str;
|
||||
returnresult.append(str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if(ql.language() == QLocale::English) {
|
||||
for(i = m_English_searchList.constBegin(); i != m_English_searchList.constEnd(); ++i) {
|
||||
regmatch = *i;
|
||||
key = i.key();
|
||||
for(int t = 0; t < regmatch.size(); t++) {
|
||||
if(m_sourceText == "/")
|
||||
continue;
|
||||
QString str = regmatch.at(t);
|
||||
if(str.contains(m_sourceText, Qt::CaseInsensitive)) {
|
||||
str = key + "/" + str;
|
||||
returnresult.append(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnresult;
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2020, KylinSoft Co., Ltd.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: sunfengsheng <sunfengsheng@kylinos.cn>
|
||||
*
|
||||
*/
|
||||
#ifndef SETTINGSEARCH_H
|
||||
#define SETTINGSEARCH_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QFile>
|
||||
#include <QDomElement>
|
||||
#include <QDomDocument>
|
||||
#include <QDomNode>
|
||||
#include <QDomNodeList>
|
||||
#include <QMap>
|
||||
#include <QStringList>
|
||||
#include <QTimer>
|
||||
#include <QDebug>
|
||||
namespace Zeeker {
|
||||
class SettingsMatch : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SettingsMatch(QObject *parent = nullptr);
|
||||
QStringList startMatchApp(const QString &source);
|
||||
|
||||
private:
|
||||
void xmlElement();
|
||||
QStringList matching();
|
||||
|
||||
private:
|
||||
QMap<QString, QStringList> m_chine_searchList;
|
||||
QMap<QString, QStringList> m_English_searchList;
|
||||
QStringList m_chine_searchResult;
|
||||
QStringList m_English_searchResult;
|
||||
QString m_sourceText;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif // SETTINGSEARCH_H
|
|
@ -1,9 +1,7 @@
|
|||
INCLUDEPATH += $$PWD
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/setting-match.h \
|
||||
$$PWD/settings-search-plugin.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/setting-match.cpp \
|
||||
$$PWD/settings-search-plugin.cpp
|
||||
|
|
|
@ -2,13 +2,20 @@
|
|||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="zh_CN">
|
||||
<context>
|
||||
<name>Zeeker::AppSearch</name>
|
||||
<name>Zeeker::AppMatch</name>
|
||||
<message>
|
||||
<location filename="../../libsearch/appsearch/app-search-plugin.cpp" line="320"/>
|
||||
<location filename="../../libsearch/appsearch/app-match.cpp" line="329"/>
|
||||
<source>Application Description:</source>
|
||||
<translation>应用描述:</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Zeeker::AppSearch</name>
|
||||
<message>
|
||||
<source>Application Description:</source>
|
||||
<translation type="vanished">应用描述:</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Zeeker::AppSearchPlugin</name>
|
||||
<message>
|
||||
|
@ -107,13 +114,13 @@
|
|||
<name>Zeeker::FileContengSearchPlugin</name>
|
||||
<message>
|
||||
<location filename="../../libsearch/index/file-search-plugin.cpp" line="379"/>
|
||||
<location filename="../../libsearch/index/file-search-plugin.cpp" line="544"/>
|
||||
<location filename="../../libsearch/index/file-search-plugin.cpp" line="578"/>
|
||||
<source>Open</source>
|
||||
<translation>打开</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../libsearch/index/file-search-plugin.cpp" line="380"/>
|
||||
<location filename="../../libsearch/index/file-search-plugin.cpp" line="545"/>
|
||||
<location filename="../../libsearch/index/file-search-plugin.cpp" line="579"/>
|
||||
<source>Open path</source>
|
||||
<translation>打开文件所在路径</translation>
|
||||
</message>
|
||||
|
@ -143,17 +150,17 @@
|
|||
<translation>文件</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../libsearch/index/file-search-plugin.cpp" line="519"/>
|
||||
<location filename="../../libsearch/index/file-search-plugin.cpp" line="553"/>
|
||||
<source>Path</source>
|
||||
<translation>路径</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../libsearch/index/file-search-plugin.cpp" line="531"/>
|
||||
<location filename="../../libsearch/index/file-search-plugin.cpp" line="565"/>
|
||||
<source>Last time modified</source>
|
||||
<translation>上次修改时间</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../libsearch/index/file-search-plugin.cpp" line="546"/>
|
||||
<location filename="../../libsearch/index/file-search-plugin.cpp" line="580"/>
|
||||
<source>Copy path</source>
|
||||
<translation>复制路径</translation>
|
||||
</message>
|
||||
|
@ -209,6 +216,45 @@
|
|||
<translation>复制路径</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Zeeker::NoteSearch</name>
|
||||
<message>
|
||||
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="188"/>
|
||||
<source>Note Description:</source>
|
||||
<translatorcomment>便签内容:</translatorcomment>
|
||||
<translation>便签内容:</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Zeeker::NoteSearchPlugin</name>
|
||||
<message>
|
||||
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="11"/>
|
||||
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="126"/>
|
||||
<source>Open</source>
|
||||
<translatorcomment>打开</translatorcomment>
|
||||
<translation>打开</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="20"/>
|
||||
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="30"/>
|
||||
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="95"/>
|
||||
<source>Note Search</source>
|
||||
<translatorcomment>便签</translatorcomment>
|
||||
<translation>便签</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="25"/>
|
||||
<source>Note Search.</source>
|
||||
<translatorcomment>便签.</translatorcomment>
|
||||
<translation>便签.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../libsearch/notesearch/note-search-plugin.cpp" line="69"/>
|
||||
<source>Application</source>
|
||||
<translatorcomment>应用</translatorcomment>
|
||||
<translation>应用</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Zeeker::SearchManager</name>
|
||||
<message>
|
||||
|
@ -226,7 +272,7 @@
|
|||
<name>Zeeker::SettingsSearchPlugin</name>
|
||||
<message>
|
||||
<location filename="../../libsearch/settingsearch/settings-search-plugin.cpp" line="11"/>
|
||||
<location filename="../../libsearch/settingsearch/settings-search-plugin.cpp" line="251"/>
|
||||
<location filename="../../libsearch/settingsearch/settings-search-plugin.cpp" line="364"/>
|
||||
<source>Open</source>
|
||||
<translation>打开</translation>
|
||||
</message>
|
||||
|
@ -242,7 +288,7 @@
|
|||
<translation>设置。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../libsearch/settingsearch/settings-search-plugin.cpp" line="237"/>
|
||||
<location filename="../../libsearch/settingsearch/settings-search-plugin.cpp" line="350"/>
|
||||
<source>Settings</source>
|
||||
<translation>设置项</translation>
|
||||
</message>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<context>
|
||||
<name>QObject</name>
|
||||
<message>
|
||||
<location filename="../../frontend/main.cpp" line="182"/>
|
||||
<location filename="../../frontend/main.cpp" line="184"/>
|
||||
<source>ukui-search is already running!</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
@ -12,7 +12,7 @@
|
|||
<context>
|
||||
<name>Zeeker::BestListWidget</name>
|
||||
<message>
|
||||
<location filename="../../frontend/view/best-list-view.cpp" line="205"/>
|
||||
<location filename="../../frontend/view/best-list-view.cpp" line="293"/>
|
||||
<source>Best Matches</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
@ -79,16 +79,24 @@
|
|||
<context>
|
||||
<name>Zeeker::MainWindow</name>
|
||||
<message>
|
||||
<location filename="../../frontend/mainwindow.cpp" line="70"/>
|
||||
<location filename="../../frontend/mainwindow.cpp" line="71"/>
|
||||
<source>ukui-search</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../frontend/mainwindow.cpp" line="76"/>
|
||||
<location filename="../../frontend/mainwindow.cpp" line="77"/>
|
||||
<source>Global Search</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Zeeker::ResultArea</name>
|
||||
<message>
|
||||
<location filename="../../frontend/control/stack-pages/search-page-section.cpp" line="378"/>
|
||||
<source>Web Page</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Zeeker::SearchLineEdit</name>
|
||||
<message>
|
||||
|
@ -258,19 +266,4 @@
|
|||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Zeeker::ShowMoreLabel</name>
|
||||
<message>
|
||||
<location filename="../../frontend/control/list-labels/show-more-label.cpp" line="33"/>
|
||||
<location filename="../../frontend/control/list-labels/show-more-label.cpp" line="50"/>
|
||||
<location filename="../../frontend/control/list-labels/show-more-label.cpp" line="72"/>
|
||||
<source>Show More...</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../frontend/control/list-labels/show-more-label.cpp" line="68"/>
|
||||
<source>Retract</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -99,7 +99,7 @@
|
|||
<context>
|
||||
<name>QObject</name>
|
||||
<message>
|
||||
<location filename="../../frontend/main.cpp" line="182"/>
|
||||
<location filename="../../frontend/main.cpp" line="184"/>
|
||||
<source>ukui-search is already running!</source>
|
||||
<translation>ukui-bul zaten çalışıyor!</translation>
|
||||
</message>
|
||||
|
@ -247,7 +247,7 @@
|
|||
<context>
|
||||
<name>Zeeker::BestListWidget</name>
|
||||
<message>
|
||||
<location filename="../../frontend/view/best-list-view.cpp" line="205"/>
|
||||
<location filename="../../frontend/view/best-list-view.cpp" line="293"/>
|
||||
<source>Best Matches</source>
|
||||
<translation type="unfinished">En İyi Eşleşen</translation>
|
||||
</message>
|
||||
|
@ -357,12 +357,12 @@
|
|||
<context>
|
||||
<name>Zeeker::MainWindow</name>
|
||||
<message>
|
||||
<location filename="../../frontend/mainwindow.cpp" line="70"/>
|
||||
<location filename="../../frontend/mainwindow.cpp" line="71"/>
|
||||
<source>ukui-search</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../frontend/mainwindow.cpp" line="76"/>
|
||||
<location filename="../../frontend/mainwindow.cpp" line="77"/>
|
||||
<source>Global Search</source>
|
||||
<translation type="unfinished">Genel Arama</translation>
|
||||
</message>
|
||||
|
@ -394,6 +394,14 @@
|
|||
<translation type="obsolete">Yolu kopyala</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Zeeker::ResultArea</name>
|
||||
<message>
|
||||
<location filename="../../frontend/control/stack-pages/search-page-section.cpp" line="378"/>
|
||||
<source>Web Page</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Zeeker::SearchBarHLayout</name>
|
||||
<message>
|
||||
|
@ -592,16 +600,12 @@
|
|||
<context>
|
||||
<name>Zeeker::ShowMoreLabel</name>
|
||||
<message>
|
||||
<location filename="../../frontend/control/list-labels/show-more-label.cpp" line="33"/>
|
||||
<location filename="../../frontend/control/list-labels/show-more-label.cpp" line="50"/>
|
||||
<location filename="../../frontend/control/list-labels/show-more-label.cpp" line="72"/>
|
||||
<source>Show More...</source>
|
||||
<translation type="unfinished">Daha Fazla Göster...</translation>
|
||||
<translation type="obsolete">Daha Fazla Göster...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../frontend/control/list-labels/show-more-label.cpp" line="68"/>
|
||||
<source>Retract</source>
|
||||
<translation type="unfinished">Geri çek</translation>
|
||||
<translation type="obsolete">Geri çek</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Loading</source>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<context>
|
||||
<name>QObject</name>
|
||||
<message>
|
||||
<location filename="../../frontend/main.cpp" line="182"/>
|
||||
<location filename="../../frontend/main.cpp" line="184"/>
|
||||
<source>ukui-search is already running!</source>
|
||||
<translation></translation>
|
||||
</message>
|
||||
|
@ -12,7 +12,7 @@
|
|||
<context>
|
||||
<name>Zeeker::BestListWidget</name>
|
||||
<message>
|
||||
<location filename="../../frontend/view/best-list-view.cpp" line="205"/>
|
||||
<location filename="../../frontend/view/best-list-view.cpp" line="293"/>
|
||||
<source>Best Matches</source>
|
||||
<translation>最佳匹配</translation>
|
||||
</message>
|
||||
|
@ -126,12 +126,12 @@
|
|||
<context>
|
||||
<name>Zeeker::MainWindow</name>
|
||||
<message>
|
||||
<location filename="../../frontend/mainwindow.cpp" line="70"/>
|
||||
<location filename="../../frontend/mainwindow.cpp" line="71"/>
|
||||
<source>ukui-search</source>
|
||||
<translation>搜索</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../frontend/mainwindow.cpp" line="76"/>
|
||||
<location filename="../../frontend/mainwindow.cpp" line="77"/>
|
||||
<source>Global Search</source>
|
||||
<translation>搜索</translation>
|
||||
</message>
|
||||
|
@ -167,6 +167,14 @@
|
|||
<translation type="vanished">安装</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Zeeker::ResultArea</name>
|
||||
<message>
|
||||
<location filename="../../frontend/control/stack-pages/search-page-section.cpp" line="378"/>
|
||||
<source>Web Page</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>Zeeker::SearchBarHLayout</name>
|
||||
<message>
|
||||
|
@ -373,16 +381,12 @@
|
|||
<context>
|
||||
<name>Zeeker::ShowMoreLabel</name>
|
||||
<message>
|
||||
<location filename="../../frontend/control/list-labels/show-more-label.cpp" line="33"/>
|
||||
<location filename="../../frontend/control/list-labels/show-more-label.cpp" line="50"/>
|
||||
<location filename="../../frontend/control/list-labels/show-more-label.cpp" line="72"/>
|
||||
<source>Show More...</source>
|
||||
<translation>显示更多...</translation>
|
||||
<translation type="vanished">显示更多...</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../../frontend/control/list-labels/show-more-label.cpp" line="68"/>
|
||||
<source>Retract</source>
|
||||
<translation>收起</translation>
|
||||
<translation type="vanished">收起</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Loading</source>
|
||||
|
|
Loading…
Reference in New Issue