diff --git a/.gitignore b/.gitignore index 20e2d0e..fab7372 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,7 @@ *.so.* *_pch.h.cpp *_resource.rc -#*.qm +*.qm .#* *.*# core diff --git a/data/org.ukui.log4qt.ukui-search.gschema.xml b/data/org.ukui.log4qt.ukui-search.gschema.xml new file mode 100644 index 0000000..c36f8d9 --- /dev/null +++ b/data/org.ukui.log4qt.ukui-search.gschema.xml @@ -0,0 +1,39 @@ + + + + "true" + hook qt messages + Control if hook qt messages + + + "WARN,console,daily" + config rootLogger's level and appenders + config rootLogger's level and appenders:"level,appender" + + + ".yyyy-MM-dd" + daily log file pattern + set daily log file pattern format:one day + + + "%d{yyyy-MM-dd HH:mm:ss,zzz}(%-4r)[%t]|%-5p| - %m%n" + set log message's format + set log message's format + + + 3600 + set check log files delay time + set check log files delay time + + + 7 + set log files count + set log files count,unit s + + + 512 + set log files total size + set log files total size, unit M + + + diff --git a/data/org.ukui.search.data.gschema.xml b/data/org.ukui.search.data.gschema.xml new file mode 100644 index 0000000..f4f0158 --- /dev/null +++ b/data/org.ukui.search.data.gschema.xml @@ -0,0 +1,14 @@ + + + + false + search method + Is current search-method index-search. + + + "baidu" + web engine + Web engine to search keyword online. + + + diff --git a/data/ukui-search-menu.desktop b/data/ukui-search-menu.desktop index eeaf1ab..085b75c 100644 --- a/data/ukui-search-menu.desktop +++ b/data/ukui-search-menu.desktop @@ -8,4 +8,8 @@ Comment[zh_CN]=全局搜索 Exec=/usr/bin/ukui-search -s Type=Application Icon=kylin-search +X-UKUI-AutoRestart=true +NoDisplay=true +OnlyShowIn=UKUI +X-UKUI-Autostart-Phase=Application Terminal=false diff --git a/data/ukui-search.desktop b/data/ukui-search.desktop index db77937..1a8bbe0 100644 --- a/data/ukui-search.desktop +++ b/data/ukui-search.desktop @@ -8,6 +8,7 @@ Comment[zh_CN]=全局搜索 Exec=/usr/bin/ukui-search %U Type=Application Icon=kylin-search -OnlyShowIn=MATE; -X-MATE-Autostart-Phase=Application -X-MATE-AutoRestart=true +X-UKUI-AutoRestart=true +OnlyShowIn=UKUI +X-UKUI-Autostart-Phase=Application +Terminal=false diff --git a/debian/control b/debian/control index a59ed26..3a03d6d 100644 --- a/debian/control +++ b/debian/control @@ -11,12 +11,14 @@ Build-Depends: debhelper (>=9.0.0), qtscript5-dev, qttools5-dev-tools, libxapian-dev, - libquazip5-dev, + libquazip5-dev(>=0.7.6-6build1), libglib2.0-dev, + libkf5windowsystem-dev, libgsettings-qt-dev, libqt5x11extras5-dev, libuchardet-dev, - libpoppler-qt5-dev + libpoppler-qt5-dev, + libukui-log4qt-dev Standards-Version: 4.5.0 Homepage: https://www.ukui.org/ Vcs-Git: https://github.com/ukui/ukui-search.git @@ -42,14 +44,6 @@ Description: Libraries for chinese-segmentation This package contains a few runtime libraries needed by libsearch. -Package: libchinese-segmentation-dev -Section: libdevel -Architecture: any -Depends: ${misc:Depends}, - ${shlibs:Depends}, - libchinese-segmentation0 (= ${binary:Version}) -Description: Libraries for chinese-segmentation(development files). - Package: libukui-search0 Section: libs Architecture: any diff --git a/debian/ukui-search.install b/debian/ukui-search.install index d0ffb18..d7f1780 100644 --- a/debian/ukui-search.install +++ b/debian/ukui-search.install @@ -1,3 +1,5 @@ usr/bin/ukui-search etc/xdg/autostart/*.desktop usr/share/applications/*.desktop +src/.qm/*.qm usr/share/ukui-search/translations +usr/share/glib-2.0/schemas/*.xml diff --git a/libchinese-segmentation/chinese-segmentation.h b/libchinese-segmentation/chinese-segmentation.h index 7e1e440..01e8046 100644 --- a/libchinese-segmentation/chinese-segmentation.h +++ b/libchinese-segmentation/chinese-segmentation.h @@ -39,7 +39,7 @@ struct SKeyWord { ~SKeyWord() { word = std::move(""); offsets.clear(); -// offsets.shrink_to_fit(); + offsets.shrink_to_fit(); } }; diff --git a/libchinese-segmentation/cppjieba/cppjieba.pri b/libchinese-segmentation/cppjieba/cppjieba.pri index fffe320..cec0ba9 100644 --- a/libchinese-segmentation/cppjieba/cppjieba.pri +++ b/libchinese-segmentation/cppjieba/cppjieba.pri @@ -16,6 +16,6 @@ HEADERS += \ $$PWD/SegmentBase.hpp \ $$PWD/SegmentTagged.hpp \ $$PWD/TextRankExtractor.hpp \ -# $$PWD/Trie.hpp \ + $$PWD/Trie.hpp \ $$PWD/Unicode.hpp include(limonp/limonp.pri) diff --git a/libchinese-segmentation/libchinese-segmentation.pro b/libchinese-segmentation/libchinese-segmentation.pro index dc26ddc..28fb1a1 100644 --- a/libchinese-segmentation/libchinese-segmentation.pro +++ b/libchinese-segmentation/libchinese-segmentation.pro @@ -40,11 +40,12 @@ unix { target.path = $$[QT_INSTALL_LIBS] } !isEmpty(target.path): INSTALLS += target -header.path = /usr/include/chinese-seg/ -header.files = *.h -header_cppjieba.path = /usr/include/chinese-seg/cppjieba/ -header_cppjieba.files = cppjieba/* -INSTALLS += header header_cppjieba + + header.path = /usr/include/chinese-seg/ + header.files += *.h + headercppjieba.path = /usr/include/chinese-seg/cppjieba/ + headercppjieba.files = cppjieba/* + INSTALLS += header headercppjieba #DISTFILES += \ # jiaba/jieba.pri diff --git a/libsearch/file-utils.cpp b/libsearch/file-utils.cpp index 393ed72..113fbf5 100644 --- a/libsearch/file-utils.cpp +++ b/libsearch/file-utils.cpp @@ -26,8 +26,7 @@ using namespace Zeeker; size_t FileUtils::_max_index_count = 0; size_t FileUtils::_current_index_count = 0; unsigned short FileUtils::_index_status = 0; -//FileUtils::SearchMethod FileUtils::searchMethod = FileUtils::SearchMethod::DIRECTSEARCH; -FileUtils::SearchMethod FileUtils::searchMethod = FileUtils::SearchMethod::INDEXSEARCH; +FileUtils::SearchMethod FileUtils::searchMethod = FileUtils::SearchMethod::DIRECTSEARCH; QMap FileUtils::map_chinese2pinyin = QMap(); FileUtils::FileUtils() { @@ -181,9 +180,9 @@ QString FileUtils::getSettingName(const QString& setting) { bool FileUtils::isOrUnder(QString pathA, QString pathB) { - if(!pathA.startsWith("/")) + if(pathA[0] != "/") pathA.prepend("/"); - if(!pathB.startsWith("/")) + if(pathB[0] != "/") pathB.prepend("/"); if(pathA.length() < pathB.length()) diff --git a/libsearch/global-settings.cpp b/libsearch/global-settings.cpp index aa848fc..3aebc89 100644 --- a/libsearch/global-settings.cpp +++ b/libsearch/global-settings.cpp @@ -37,14 +37,14 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent) { // m_settings->setAtomicSyncRequired(false); m_block_dirs_settings = new QSettings(BLOCK_DIRS, QSettings::IniFormat, this); m_block_dirs_settings->setIniCodec(QTextCodec::codecForName("UTF-8")); -// m_block_dirs_settings->setValue("These_are_block_dirs_conf_for_ukui_search","0"); -// m_block_dirs_settings->sync(); -// m_confWatcher = new QFileSystemWatcher(this); -// m_confWatcher->addPath(BLOCK_DIRS); -// connect(m_confWatcher, &QFileSystemWatcher::fileChanged, this, [ & ]() { -// m_block_dirs_settings->sync(); -// m_confWatcher->addPath(BLOCK_DIRS); -// }); + m_block_dirs_settings->setValue("These_are_block_dirs_conf_for_ukui_search","0"); + m_block_dirs_settings->sync(); + m_confWatcher = new QFileSystemWatcher(this); + m_confWatcher->addPath(BLOCK_DIRS); + connect(m_confWatcher, &QFileSystemWatcher::fileChanged, this, [ & ]() { + m_block_dirs_settings->sync(); + m_confWatcher->addPath(BLOCK_DIRS); + }); m_search_record_settings = new QSettings(SEARCH_HISTORY, QSettings::IniFormat, this); m_search_record_settings->setIniCodec(QTextCodec::codecForName("UTF-8")); @@ -60,10 +60,9 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent) { qWarning() << "Kylinssoclient Dbus connect fail!"; this->forceSync(); - m_cache.insert(FONT_SIZE_KEY, 11); //the default number of transparency in mainwindow is 0.7 //if someone changes the num in mainwindow, here should be modified too - m_cache.insert(TRANSPARENCY_KEY, 1); + m_cache.insert(TRANSPARENCY_KEY, 0.7); if(QGSettings::isSchemaInstalled(CONTROL_CENTER_PERSONALISE_GSETTINGS_ID)) { m_trans_gsettings = new QGSettings(CONTROL_CENTER_PERSONALISE_GSETTINGS_ID, QByteArray(), this); connect(m_trans_gsettings, &QGSettings::changed, this, [ = ](const QString & key) { diff --git a/libsearch/global-settings.h b/libsearch/global-settings.h index 5ded1cf..de520ab 100644 --- a/libsearch/global-settings.h +++ b/libsearch/global-settings.h @@ -51,13 +51,9 @@ #define PATH_NOT_IN_HOME 2; #define PATH_PARENT_BLOCKED 3; -//#define MAIN_SETTINGS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search.conf" -//#define BLOCK_DIRS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-block-dirs.conf" -//#define SEARCH_HISTORY QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-history.conf" - -#define MAIN_SETTINGS "/media/用户保险箱/.ukui-search/ukui-search.conf" -#define BLOCK_DIRS "/media/用户保险箱/.ukui-search/ukui-search-block-dirs.conf" -#define SEARCH_HISTORY "/media/用户保险箱/.ukui-search/ukui-search-history.conf" +#define MAIN_SETTINGS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search.conf" +#define BLOCK_DIRS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-block-dirs.conf" +#define SEARCH_HISTORY QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-history.conf" //#define CLOUD_HISTORY "history" //#define CLOUD_APPLICATIONS "applications" diff --git a/libsearch/index/first-index.cpp b/libsearch/index/first-index.cpp index d1ecc0d..15f6429 100644 --- a/libsearch/index/first-index.cpp +++ b/libsearch/index/first-index.cpp @@ -169,12 +169,7 @@ void FirstIndex::run() { // QtConcurrent::run([&](){ sem.acquire(1); mutex1.unlock(); - QStringList pathList; - pathList.append("/media/用户保险箱"); - pathList.append("/media/邮件保险箱"); - pathList.append("/media/公共保险箱"); - pathList.append("/media/备份保险箱"); - this->setPath(pathList); + this->setPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); this->Traverse(); FileUtils::_max_index_count = this->q_index->length(); qDebug() << "max_index_count:" << FileUtils::_max_index_count; @@ -244,7 +239,7 @@ void FirstIndex::run() { if(p_indexGenerator) delete p_indexGenerator; p_indexGenerator = nullptr; - +// GlobalSettings::getInstance()->forceSync(); IndexStatusRecorder::getInstance()->setStatus(INDEX_DATABASE_STATE, "2"); IndexStatusRecorder::getInstance()->setStatus(CONTENT_INDEX_DATABASE_STATE, "2"); ::_exit(0); diff --git a/libsearch/index/first-index.h b/libsearch/index/first-index.h index d6ff2e9..ab1d23e 100644 --- a/libsearch/index/first-index.h +++ b/libsearch/index/first-index.h @@ -33,7 +33,6 @@ #include #include #include -#include "assert.h" #include #include //#include diff --git a/libsearch/index/index-generator.cpp b/libsearch/index/index-generator.cpp index 6ac571a..06efc6e 100644 --- a/libsearch/index/index-generator.cpp +++ b/libsearch/index/index-generator.cpp @@ -31,10 +31,8 @@ #include #include -//#define INDEX_PATH (QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.config/org.ukui/ukui-search/index_data").toStdString() -//#define CONTENT_INDEX_PATH (QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.config/org.ukui/ukui-search/content_index_data").toStdString() -#define INDEX_PATH "/media/用户保险箱/.ukui-search/index_data" -#define CONTENT_INDEX_PATH "/media/用户保险箱/.ukui-search/content_index_data" +#define INDEX_PATH (QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.config/org.ukui/ukui-search/index_data").toStdString() +#define CONTENT_INDEX_PATH (QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.config/org.ukui/ukui-search/content_index_data").toStdString() using namespace Zeeker; diff --git a/libsearch/index/index-status-recorder.h b/libsearch/index/index-status-recorder.h index 3900165..bf65850 100644 --- a/libsearch/index/index-status-recorder.h +++ b/libsearch/index/index-status-recorder.h @@ -8,8 +8,8 @@ #define CONTENT_INDEX_DATABASE_STATE "content_index_database_state" #define INDEX_DATABASE_STATE "index_database_state" #define INOTIFY_NORMAL_EXIT "inotify_normal_exit" -#define INDEX_STATUS "/media/用户保险箱/.ukui-search/ukui-search-index-status.conf" #define PENDING_FILE_QUEUE_FINISH "pending_file_queue_finish" +#define INDEX_STATUS QDir::homePath() + "/.config/org.ukui/ukui-search/ukui-search-index-status.conf" namespace Zeeker { //fixme: we need a better way to record index status. class IndexStatusRecorder : public QObject diff --git a/libsearch/index/inotify-index.cpp b/libsearch/index/inotify-index.cpp index 924adbb..04351f1 100644 --- a/libsearch/index/inotify-index.cpp +++ b/libsearch/index/inotify-index.cpp @@ -38,7 +38,7 @@ QFileInfo fi(tmp); \ if(!fi.isSymLink()){ \ AddWatch(tmp); \ - setPath(QStringList(tmp)); \ + setPath(tmp); \ Traverse(); \ } @@ -47,7 +47,7 @@ CREATE_FILE_NAME_INDEX \ CREATE_FILE_CONTENT_INDEX using namespace Zeeker; -InotifyIndex::InotifyIndex(const QStringList &pathList) : Traverse_BFS(pathList) { +InotifyIndex::InotifyIndex(const QString& path) : Traverse_BFS(path) { qDebug() << "setInotifyMaxUserWatches start"; UkuiSearchQDBus usQDBus; usQDBus.setInotifyMaxUserWatches(); @@ -62,21 +62,18 @@ InotifyIndex::~InotifyIndex() { void InotifyIndex::firstTraverse() { QQueue bfs; - for(QString path : this->m_pathList) { - this->AddWatch(path); - bfs.enqueue(path); - QFileInfoList list; - QDir dir; - dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); - dir.setSorting(QDir::DirsFirst); - while(!bfs.empty()) { - dir.setPath(bfs.dequeue()); - list = dir.entryInfoList(); - for(auto i : list) { - if(i.isDir() && (!(i.isSymLink()))) { - this->AddWatch(i.absoluteFilePath()); - bfs.enqueue(i.absoluteFilePath()); - } + bfs.enqueue(this->path); + QFileInfoList list; + QDir dir; + dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); + dir.setSorting(QDir::DirsFirst); + while(!bfs.empty()) { + dir.setPath(bfs.dequeue()); + list = dir.entryInfoList(); + for(auto i : list) { + if(i.isDir() && (!(i.isSymLink()))) { + this->AddWatch(i.absoluteFilePath()); + bfs.enqueue(i.absoluteFilePath()); } } } @@ -252,8 +249,8 @@ void InotifyIndex::run() { m_fd = inotify_init(); qDebug() << "m_fd----------->" << m_fd; -// this->AddWatch(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); -// this->setPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + this->AddWatch(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + this->setPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); this->firstTraverse(); int fifo_fd; diff --git a/libsearch/index/inotify-index.h b/libsearch/index/inotify-index.h index d9f8f4a..1b31f2a 100644 --- a/libsearch/index/inotify-index.h +++ b/libsearch/index/inotify-index.h @@ -41,13 +41,13 @@ static InotifyIndex* global_instance_of_index = nullptr; class InotifyIndex : public QThread, public Traverse_BFS { Q_OBJECT public: - static InotifyIndex* getInstance(const QStringList &pathList) { + static InotifyIndex* getInstance(const QString& path) { if(!global_instance_of_index) { - global_instance_of_index = new InotifyIndex(pathList); + global_instance_of_index = new InotifyIndex(path); } return global_instance_of_index; } - InotifyIndex(const QStringList &pathList); + InotifyIndex(const QString&); ~InotifyIndex(); bool AddWatch(const QString&); diff --git a/libsearch/index/inotify-watch.cpp b/libsearch/index/inotify-watch.cpp index 8b51d8d..eb845a8 100644 --- a/libsearch/index/inotify-watch.cpp +++ b/libsearch/index/inotify-watch.cpp @@ -5,15 +5,15 @@ using namespace Zeeker; static InotifyWatch* global_instance_InotifyWatch = nullptr; -Zeeker::InotifyWatch *Zeeker::InotifyWatch::getInstance(const QStringList &pathList) +Zeeker::InotifyWatch *Zeeker::InotifyWatch::getInstance(const QString &path) { if(!global_instance_InotifyWatch) { - global_instance_InotifyWatch = new InotifyWatch(pathList); + global_instance_InotifyWatch = new InotifyWatch(path); } return global_instance_InotifyWatch; } -Zeeker::InotifyWatch::InotifyWatch(const QStringList &pathList): Traverse_BFS(pathList) +Zeeker::InotifyWatch::InotifyWatch(const QString &path): Traverse_BFS(path) { qDebug() << "setInotifyMaxUserWatches start"; UkuiSearchQDBus usQDBus; @@ -98,21 +98,18 @@ void InotifyWatch::DoSomething(const QFileInfo &info) void InotifyWatch::firstTraverse() { QQueue bfs; - for(QString path : this->m_pathList) { - this->addWatch(path); - bfs.enqueue(path); - QFileInfoList list; - QDir dir; - dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); - dir.setSorting(QDir::DirsFirst); - while(!bfs.empty()) { - dir.setPath(bfs.dequeue()); - list = dir.entryInfoList(); - for(auto i : list) { - if(i.isDir() && (!(i.isSymLink()))) { - this->addWatch(i.absoluteFilePath()); - bfs.enqueue(i.absoluteFilePath()); - } + bfs.enqueue(this->path); + QFileInfoList list; + QDir dir; + dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); + dir.setSorting(QDir::DirsFirst); + while(!bfs.empty()) { + dir.setPath(bfs.dequeue()); + list = dir.entryInfoList(); + for(auto i : list) { + if(i.isDir() && (!(i.isSymLink()))) { + this->addWatch(i.absoluteFilePath()); + bfs.enqueue(i.absoluteFilePath()); } } } @@ -150,8 +147,8 @@ void InotifyWatch::run() } } -// this->addWatch(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); -// this->setPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + this->addWatch(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + this->setPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); this->firstTraverse(); int fifo_fd; @@ -399,7 +396,7 @@ void InotifyWatch::eventProcess(const char *buffer, ssize_t len) if(event->mask & IN_ISDIR) { if(!QFileInfo(path).isSymLink()){ addWatch(path); - setPath(QStringList(path)); + setPath(path); Traverse(); } } @@ -439,7 +436,7 @@ void InotifyWatch::eventProcess(const char *buffer, ssize_t len) if(!QFileInfo(path).isSymLink()){ addWatch(path); - setPath(QStringList(path)); + setPath(path); Traverse(); } } else { diff --git a/libsearch/index/inotify-watch.h b/libsearch/index/inotify-watch.h index a4a3909..eb21587 100644 --- a/libsearch/index/inotify-watch.h +++ b/libsearch/index/inotify-watch.h @@ -20,7 +20,7 @@ class InotifyWatch : public QThread, public Traverse_BFS { Q_OBJECT public: - static InotifyWatch* getInstance(const QStringList &pathList); + static InotifyWatch* getInstance(const QString& path); bool addWatch(const QString &path); bool removeWatch(const QString &path, bool removeFromDatabase = true); @@ -34,7 +34,7 @@ protected: private Q_SLOTS: void slotEvent(char *buf, ssize_t len); private: - explicit InotifyWatch(const QStringList &pathList); + explicit InotifyWatch(const QString& path); ~InotifyWatch(); char * filter(); void eventProcess(int socket); diff --git a/libsearch/index/search-manager.cpp b/libsearch/index/search-manager.cpp index fbb6969..c501594 100644 --- a/libsearch/index/search-manager.cpp +++ b/libsearch/index/search-manager.cpp @@ -31,35 +31,7 @@ SearchManager::SearchManager(QObject *parent) : QObject(parent) { m_pool.setExpiryTimeout(1000); } -void SearchManager::searchLocalFiles(std::string keyword, std::queue *searchResultFile, std::queue *searchResultDir, std::queue *searchResultContent) -{ - m_mutex1.lock(); - ++uniqueSymbol1; - m_mutex1.unlock(); - m_mutex2.lock(); - ++uniqueSymbol2; - m_mutex2.unlock(); - m_mutex3.lock(); - ++uniqueSymbol3; - m_mutex3.unlock(); - - FileSearchV4 *filesearch; - filesearch = new FileSearchV4(searchResultFile,uniqueSymbol1,QString::fromStdString(keyword),"0",1,0,5); - m_pool.start(filesearch); - - FileSearchV4 *dirsearch; - dirsearch = new FileSearchV4(searchResultDir,uniqueSymbol2,QString::fromStdString(keyword),"1",1,0,5); - m_pool.start(dirsearch); - - FileContentSearchV4 *contentSearch; - contentSearch = new FileContentSearchV4(searchResultContent,uniqueSymbol3,QString::fromStdString(keyword),0,5); - m_pool.start(contentSearch); - return; - -} - -SearchManager::~SearchManager() -{ +SearchManager::~SearchManager() { } int SearchManager::getCurrentIndexCount() { @@ -416,363 +388,7 @@ int FileContentSearch::getResult(Xapian::MSet &result, std::string &keyWord) { // // deleteAllIndex(pathTobeDelete) return 0; } -FileSearchV4::FileSearchV4(std::queue *searchResultFile, size_t uniqueSymbol, QString keyword, QString value, unsigned slot, int begin, int num) -{ - this->setAutoDelete(true); - m_search_result = searchResultFile; - m_uniqueSymbol = uniqueSymbol; - m_keyword = keyword; - m_value = value; - m_slot = slot; - m_begin = begin; - m_num = num; -} -FileSearchV4::~FileSearchV4() -{ - m_search_result = nullptr; -} - -void FileSearchV4::run() -{ - int resultCount = 0; - int total = 0; - while(total < 100) - { - resultCount = keywordSearchfile(); - if(resultCount == 0 || resultCount == -1) - break; - total += resultCount; - m_begin += m_num; - } - return; -} - -int FileSearchV4::keywordSearchfile() -{ - try - { - qDebug() << "--keywordSearchfile start--"; - Xapian::Database db(INDEX_PATH); - Xapian::Query query = creatQueryForFileSearch(db); - Xapian::Enquire enquire(db); - - Xapian::Query queryFile; - if(!m_value.isEmpty()) - { - std::string slotValue = m_value.toStdString(); - Xapian::Query queryValue = Xapian::Query(Xapian::Query::OP_VALUE_RANGE,m_slot,slotValue,slotValue); - queryFile = Xapian::Query(Xapian::Query::OP_AND,query,queryValue); - } - else - { - queryFile = query; - } - - qDebug() << "keywordSearchfile:"< v; - for(int i=0;iappend(QString::fromStdString(data)); - qDebug()<(info.size()); - sSearchResult.type = info.suffix().toStdString(); - sSearchResult.time = info.lastModified().toString("yyyy/MM/dd hh:mm:ss").toStdString(); - - switch (m_value.toInt()) - { - case 1: - SearchManager::m_mutex1.lock(); - if(m_uniqueSymbol == SearchManager::uniqueSymbol2) - { - m_search_result->push(sSearchResult); - SearchManager::m_mutex1.unlock(); - } - else - { - SearchManager::m_mutex1.unlock(); - return -1; - } - - break; - case 0: - SearchManager::m_mutex2.lock(); - if(m_uniqueSymbol == SearchManager::uniqueSymbol1) - { - m_search_result->push(sSearchResult); - SearchManager::m_mutex2.unlock(); - } - else - { - SearchManager::m_mutex2.unlock(); - return -1; - } - break; - default: - break; - } - // searchResult.append(path); - } - qDebug()<< "doc="<< path << ",weight=" <callSegement(ret, keyword.toLocal8Bit().data()); - for (::friso::ResultMap::iterator it_map = ret.begin(); it_map != ret.end(); ++it_map){ - target_str += it_map->first; - target_str += " "; - it_map->second.first.clear(); - ::std::vector().swap(it_map->second.first); - } - - ret.clear(); - ret.erase(ret.begin(), ret.end()); - ::friso::ResultMap().swap(ret); -*/ - QVector sKeyWord = ChineseSegmentation::getInstance()->callSegement(m_keyword.toStdString()); - //Creat a query - std::string words; - for(int i=0;i sKeyWord = ChineseSegmentation::getInstance()->callSegement(keyword); -// //Creat a query -// std::string words; -// for(int i=0;i v; - // for(int i=0;iappend(QString::fromStdString(data)); - qDebug()<(info.size()); - sSearchResult.type = info.suffix().toStdString(); - sSearchResult.time = info.lastModified().toString("yyyy/MM/dd hh:mm:ss").toStdString(); - - // Construct snippets containing keyword. -// snippets.append(QString::fromStdString( result.snippet(doc.get_data(),400))); -// qWarning()< 6 + QString::fromStdString(keyWord).size()) - snippet.replace(0,3,"...").replace(snippet.size()-3,3,"..."); - else - snippet.append("...").prepend("..."); - sSearchResult.snippets.push_back(snippet.toStdString()); - - QString().swap(snippet); - std::string().swap(s); - ++count; - } - std::string().swap(data); - -// for(QString i : QString::fromStdString(keyWord).split(" ",QString::SkipEmptyParts)) -// { -// std::string word = i.toStdString(); -// term.skip_to(word); -// int size = word.size(); -// auto pos = term.positionlist_begin(); -// std::string s = data.substr((*pos < 60)? 0: (*pos - 60) , size + 120); -// QString snippet = QString::fromStdString(s); -// snippet.replace(0,3,"...").replace(snippet.size()-3,3,"..."); -// snippets.append(snippet); -// std::string().swap(word); -// std::string().swap(s); -// QString().swap(snippet); -// } - - SearchManager::m_mutex3.lock(); - if(m_uniqueSymbol == SearchManager::uniqueSymbol3) - { - - m_search_result->push(sSearchResult); - SearchManager::m_mutex3.unlock(); - } - else - { - SearchManager::m_mutex3.unlock(); - return -1; - } - // searchResult.insert(path,snippets); - qDebug()<< "path="<< path << ",weight=" < snippets; - std::string time; - std::string type; - size_t size; -}; class LIBSEARCH_EXPORT SearchManager : public QObject { friend class FileSearch; friend class FileContentSearch; - friend class FileSearchV4; - friend class FileContentSearchV4; Q_OBJECT public: explicit SearchManager(QObject *parent = nullptr); - void searchLocalFiles(std::string keyword, - std::queue *searchResultFile, - std::queue *searchResultDir, - std::queue *searchResultContent); ~SearchManager(); static int getCurrentIndexCount(); @@ -78,7 +60,6 @@ public: static size_t uniqueSymbol1; static size_t uniqueSymbol2; static size_t uniqueSymbol3; - static QMutex m_mutex1; static QMutex m_mutex2; static QMutex m_mutex3; @@ -152,44 +133,6 @@ private: int m_num = 20; }; -class FileSearchV4 : public QRunnable -{ -public: - explicit FileSearchV4(std::queue *searchResult,size_t uniqueSymbol, QString keyword, QString value,unsigned slot = 1,int begin = 0, int num = 20); - ~FileSearchV4(); -protected: - void run(); -private: - int keywordSearchfile(); - Xapian::Query creatQueryForFileSearch(Xapian::Database &db); - int getResult(Xapian::MSet &result); - - std::queue *m_search_result = nullptr; - QString m_value; - unsigned m_slot = 1; - size_t m_uniqueSymbol; - QString m_keyword; - int m_begin = 0; - int m_num = 20; -}; -class FileContentSearchV4 : public QRunnable -{ -public: - explicit FileContentSearchV4(std::queue *searchResult,size_t uniqueSymbol, QString keyword, int begin = 0, int num = 20); - ~FileContentSearchV4(); -protected: - void run(); -private: - int keywordSearchContent(); - int getResult(Xapian::MSet &result,std::string &keyWord); - - std::queue *m_search_result = nullptr; - size_t m_uniqueSymbol; - QString m_keyword; - int m_begin = 0; - int m_num = 20; -}; - class DirectSearch : public QRunnable { public: explicit DirectSearch(QString keyword, QQueue *searchResultFile, QQueue *searchResultDir, size_t uniqueSymbol); diff --git a/libsearch/index/searchmethodmanager.cpp b/libsearch/index/searchmethodmanager.cpp index dae3ef3..bfdc7ee 100644 --- a/libsearch/index/searchmethodmanager.cpp +++ b/libsearch/index/searchmethodmanager.cpp @@ -2,12 +2,7 @@ using namespace Zeeker; SearchMethodManager::SearchMethodManager() { - QStringList pathList; - pathList.append("/media/用户保险箱"); - pathList.append("/media/邮件保险箱"); - pathList.append("/media/公共保险箱"); - pathList.append("/media/备份保险箱"); - m_iw = InotifyWatch::getInstance(pathList); + m_iw = InotifyWatch::getInstance(HOME_PATH); } void SearchMethodManager::searchMethod(FileUtils::SearchMethod sm) { diff --git a/libsearch/index/traverse_bfs.cpp b/libsearch/index/traverse_bfs.cpp index e8c99c7..97a5f13 100644 --- a/libsearch/index/traverse_bfs.cpp +++ b/libsearch/index/traverse_bfs.cpp @@ -19,36 +19,31 @@ */ #include "traverse_bfs.h" using namespace Zeeker; -Traverse_BFS::Traverse_BFS(const QStringList& pathList) { - for(QString path : pathList) { - Q_ASSERT('/' == path.at(0)); - } - - this->m_pathList = pathList; +Traverse_BFS::Traverse_BFS(const QString& path) { + Q_ASSERT('/' == path.at(0)); + this->path = path; } void Traverse_BFS::Traverse() { QQueue bfs; - for(QString path : m_pathList) { - bfs.enqueue(path); - QFileInfoList list; - QDir dir; - // QDir::Hidden - dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); - dir.setSorting(QDir::DirsFirst); - while(!bfs.empty()) { - dir.setPath(bfs.dequeue()); - list = dir.entryInfoList(); - for(auto i : list) { - if(i.isDir() && (!(i.isSymLink()))) { - bfs.enqueue(i.absoluteFilePath()); - } - DoSomething(i); + bfs.enqueue(this->path); + QFileInfoList list; + QDir dir; + // QDir::Hidden + dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); + dir.setSorting(QDir::DirsFirst); + while(!bfs.empty()) { + dir.setPath(bfs.dequeue()); + list = dir.entryInfoList(); + for(auto i : list) { + if(i.isDir() && (!(i.isSymLink()))) { + bfs.enqueue(i.absoluteFilePath()); } + DoSomething(i); } } } -void Traverse_BFS::setPath(const QStringList &pathList) { - this->m_pathList = pathList; +void Traverse_BFS::setPath(const QString& path) { + this->path = path; } diff --git a/libsearch/index/traverse_bfs.h b/libsearch/index/traverse_bfs.h index e7e21ac..a3388d0 100644 --- a/libsearch/index/traverse_bfs.h +++ b/libsearch/index/traverse_bfs.h @@ -31,10 +31,10 @@ public: void Traverse(); virtual ~Traverse_BFS() = default; virtual void DoSomething(const QFileInfo&) = 0; - void setPath(const QStringList &pathList); + void setPath(const QString&); protected: - Traverse_BFS(const QStringList &pathList); - QStringList m_pathList; + Traverse_BFS(const QString&); + QString path = "/home"; private: Traverse_BFS(const Traverse_BFS&) = delete; void operator=(const Traverse_BFS&) = delete; diff --git a/libsearch/libsearch.h b/libsearch/libsearch.h index cc79320..0fc1e02 100644 --- a/libsearch/libsearch.h +++ b/libsearch/libsearch.h @@ -43,5 +43,4 @@ namespace Zeeker { //}; } - #endif // LIBSEARCH_H diff --git a/libsearch/libsearch.pro b/libsearch/libsearch.pro index eeab32d..38cbb89 100644 --- a/libsearch/libsearch.pro +++ b/libsearch/libsearch.pro @@ -71,6 +71,7 @@ unix { INSTALLS += header } + INCLUDEPATH += $$PWD/../libchinese-segmentation DEPENDPATH += $$PWD/../libchinese-segmentation diff --git a/src/content-widget.cpp b/src/content-widget.cpp index 53b9c19..0fdcee8 100644 --- a/src/content-widget.cpp +++ b/src/content-widget.cpp @@ -62,8 +62,8 @@ void ContentWidget::initUI() { QPalette pal = palette(); QPalette scroll_bar_pal = palette(); // pal.setColor(QPalette::Base, QColor(0, 0, 0, 0)); -// pal.setColor(QPalette::Window, QColor(0, 0, 0, 0)); //使用此palette的窗口背景将为透明 -// scroll_bar_pal.setColor(QPalette::Base, QColor(0, 0, 0, 0)); + pal.setColor(QPalette::Window, QColor(0, 0, 0, 0)); //使用此palette的窗口背景将为透明 + scroll_bar_pal.setColor(QPalette::Base, QColor(0, 0, 0, 0)); m_homePage = new QWidget(this); m_homePageLyt = new QVBoxLayout(m_homePage); m_homePageLyt->setSpacing(0); @@ -108,8 +108,8 @@ void ContentWidget::initUI() { m_resultDetailArea->setFrameShape(QFrame::NoFrame); m_resultListArea->setPalette(pal); m_resultDetailArea->setPalette(pal); -// m_resultListArea->verticalScrollBar()->setPalette(scroll_bar_pal); -// m_resultDetailArea->verticalScrollBar()->setPalette(scroll_bar_pal); + m_resultListArea->verticalScrollBar()->setPalette(scroll_bar_pal); + m_resultDetailArea->verticalScrollBar()->setPalette(scroll_bar_pal); this->addWidget(m_homePage); this->addWidget(m_resultPage); diff --git a/src/control/config-file.h b/src/control/config-file.h index e7ec5a6..41bb24d 100644 --- a/src/control/config-file.h +++ b/src/control/config-file.h @@ -25,7 +25,7 @@ #include #include #include -#define HOMEPAGE_SETTINGS "media/用户保险箱/.ukui-search/ukui-search-homepage.conf" +#define HOMEPAGE_SETTINGS QDir::homePath()+"/.config/org.ukui/ukui-search/ukui-search-homepage.conf" namespace Zeeker { class ConfigFile : public QObject { Q_OBJECT diff --git a/src/control/search-list-view.cpp b/src/control/search-list-view.cpp index fb923fc..8a3f706 100644 --- a/src/control/search-list-view.cpp +++ b/src/control/search-list-view.cpp @@ -94,8 +94,6 @@ void SearchListView::setList(QStringList list) { this->blockSignals(false); } rowheight = this->rowHeight(this->model()->index(0, 0, QModelIndex())); - qDebug()<<"setList rowheight"<< rowheight; - qDebug()<<"setList indexRowSizeHint"<setFixedHeight(m_item->getCurrentSize() * rowheight + 4); } @@ -136,7 +134,6 @@ void SearchListView::refresh() * @brief SearchListView::setKeyword 设置关键词 * @param keyword 关键词 */ - void SearchListView::setKeyword(QString keyword) { m_styleDelegate->setSearchKeyword(keyword); } diff --git a/src/input-box.cpp b/src/input-box.cpp index ecb9b9a..1d3fcba 100644 --- a/src/input-box.cpp +++ b/src/input-box.cpp @@ -206,8 +206,7 @@ bool SearchBarHLayout::eventFilter(QObject *watched, QEvent *event) { */ SearchLineEdit::SearchLineEdit(QWidget *parent) : QLineEdit(parent) { this->setFocusPolicy(Qt::ClickFocus); - this->setAttribute(Qt::WA_InputMethodEnabled); -// this->installEventFilter(this); + this->installEventFilter(this); // this->setContextMenuPolicy(Qt::NoContextMenu); this->setMaxLength(100); diff --git a/src/main.cpp b/src/main.cpp index c139916..37674a2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -174,19 +174,6 @@ int main(int argc, char *argv[]) { syslog(LOG_ERR, "Home is not exits!!\n"); ::sleep(1); } - while(!QDir("/media/用户保险箱").exists()) { - qWarning() << "集中管控目录未挂载!!"; - printf("集中管控目录未挂载!!"); - syslog(LOG_ERR, "集中管控目录未挂载!!\n"); - ::sleep(1); - } - while(!QFileInfo("/media/用户保险箱").permission(QFileDevice::WriteUser)) { - qWarning() << "/media/用户保险箱 无写入权限!!"; - printf("/media/用户保险箱 无写入权限!!"); - syslog(LOG_ERR, "/media/用户保险箱 无写入权限!!\n"); - ::sleep(1); - } - // Output log to file qInstallMessageHandler(messageOutput); @@ -276,8 +263,7 @@ int main(int argc, char *argv[]) { // Load translations QTranslator translator; try { -// if (! translator.load("/usr/share/ukui-search/translations/" + QLocale::system().name())) throw -1; - if (! translator.load(":/res/translations/zh_CN.qm")) throw -1; + if(! translator.load("/usr/share/ukui-search/translations/" + QLocale::system().name())) throw - 1; app.installTranslator(&translator); } catch(...) { qDebug() << "Load translations file" << QLocale() << "failed!"; @@ -315,11 +301,9 @@ int main(int argc, char *argv[]) { if(QString::compare(QString("-s"), QString(QLatin1String(argv[1]))) == 0) { // w->moveToPanel(); centerToScreen(w); - #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) XAtomHelper::getInstance()->setWindowMotifHint(w->winId(), w->m_hints); #endif - w->show(); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index da169ae..e83f741 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -29,11 +29,11 @@ #include #include #include - -//#include #include -//#include "kwindowsystem.h" - +#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) +#include +#include "kwindowsystem.h" +#endif #include "qt-single-application.h" //#include "inotify-manager.h" @@ -75,7 +75,7 @@ MainWindow::MainWindow(QWidget *parent) : this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); this->setWindowTitle(tr("ukui-search")); initUi(); -// initTimer(); + initTimer(); #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) // setProperty("useStyleWindowManager", false); //禁止拖动 @@ -92,15 +92,6 @@ MainWindow::MainWindow(QWidget *parent) : setProperty("blurRegion", QRegion(path.toFillPolygon().toPolygon())); KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon())); #endif - connect(qApp, &QApplication::paletteChanged, this, [ = ](const QPalette & pal) { - this->setPalette(pal); - this->update(); - Q_FOREACH(QWidget *widget, this->findChildren()) { - if(widget) { - widget->update(); - } - } - }); m_search_result_file = new QQueue; m_search_result_dir = new QQueue; @@ -146,10 +137,9 @@ MainWindow::MainWindow(QWidget *parent) : } } }); -// QObject::connect(this, &MainWindow::searchMethodChanged, this, [ = ](FileUtils::SearchMethod sm) { -// this->m_searchMethodManager.searchMethod(sm); -// }); - this->m_searchMethodManager.searchMethod(FileUtils::SearchMethod::INDEXSEARCH); + QObject::connect(this, &MainWindow::searchMethodChanged, this, [ = ](FileUtils::SearchMethod sm) { + this->m_searchMethodManager.searchMethod(sm); + }); } @@ -168,14 +158,14 @@ MainWindow::~MainWindow() { m_settingsWidget = NULL; } #endif -// if(m_askDialog) { -// delete m_askDialog; -// m_askDialog = NULL; -// } -// if(m_askTimer) { -// delete m_askTimer; -// m_askTimer = NULL; -// } + if(m_askDialog) { + delete m_askDialog; + m_askDialog = NULL; + } + if(m_askTimer) { + delete m_askTimer; + m_askTimer = NULL; + } if(m_search_gsettings) { delete m_search_gsettings; m_search_gsettings = NULL; @@ -283,17 +273,14 @@ void MainWindow::initUi() { } // m_seach_app_thread->stop(); m_contentFrame->setCurrentIndex(0); -// m_askTimer->stop(); + m_askTimer->stop(); } else { m_contentFrame->setCurrentIndex(1); QTimer::singleShot(10, this, [ = ]() { startSearch(text); -// //允许弹窗且当前次搜索(为关闭主界面,算一次搜索过程)未询问且当前为暴力搜索 -// if(GlobalSettings::getInstance()->getValue(ENABLE_CREATE_INDEX_ASK_DIALOG).toString() != "false" && !m_currentSearchAsked && FileUtils::searchMethod == FileUtils::SearchMethod::DIRECTSEARCH) -// m_askTimer->start(); }); } -// m_researchTimer->stop(); //如果搜索内容发生改变,则停止建索引后重新搜索的倒计时 + m_researchTimer->stop(); //如果搜索内容发生改变,则停止建索引后重新搜索的倒计时 }); //初始化homepage @@ -301,34 +288,34 @@ void MainWindow::initUi() { m_contentFrame->initHomePage(); //创建索引询问弹窗 -// m_askDialog = new CreateIndexAskDialog(this); -//#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) -// MotifWmHints ask_dialog_hints; -// ask_dialog_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; -// ask_dialog_hints.functions = MWM_FUNC_ALL; -// ask_dialog_hints.decorations = MWM_DECOR_BORDER; -// XAtomHelper::getInstance()->setWindowMotifHint(m_askDialog->winId(), ask_dialog_hints); -//#endif -// connect(m_askDialog, &CreateIndexAskDialog::closed, this, [ = ]() { -// m_isAskDialogVisible = false; -// }); -// connect(m_askDialog, &CreateIndexAskDialog::btnClicked, this, [ = ](const bool & create_index, const bool & no_longer_ask) { -// if(no_longer_ask) { -// GlobalSettings::getInstance()->setValue(ENABLE_CREATE_INDEX_ASK_DIALOG, "false"); -// } else { -// GlobalSettings::getInstance()->setValue(ENABLE_CREATE_INDEX_ASK_DIALOG, "true"); -// } -// if(create_index) { -// if(m_search_gsettings && m_search_gsettings->keys().contains(SEARCH_METHOD_KEY)) { -// m_search_gsettings->set(SEARCH_METHOD_KEY, true); -// } else { -// //调用创建索引接口 -// Q_EMIT this->searchMethodChanged(FileUtils::SearchMethod::INDEXSEARCH); -// //创建索引十秒后重新搜索一次(如果用户十秒内没有退出搜索界面且没有重新搜索) -// m_researchTimer->start(); -// } -// } -// }); + m_askDialog = new CreateIndexAskDialog(this); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) + MotifWmHints ask_dialog_hints; + ask_dialog_hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; + ask_dialog_hints.functions = MWM_FUNC_ALL; + ask_dialog_hints.decorations = MWM_DECOR_BORDER; + XAtomHelper::getInstance()->setWindowMotifHint(m_askDialog->winId(), ask_dialog_hints); +#endif + connect(m_askDialog, &CreateIndexAskDialog::closed, this, [ = ]() { + m_isAskDialogVisible = false; + }); + connect(m_askDialog, &CreateIndexAskDialog::btnClicked, this, [ = ](const bool & create_index, const bool & no_longer_ask) { + if(no_longer_ask) { + GlobalSettings::getInstance()->setValue(ENABLE_CREATE_INDEX_ASK_DIALOG, "false"); + } else { + GlobalSettings::getInstance()->setValue(ENABLE_CREATE_INDEX_ASK_DIALOG, "true"); + } + if(create_index) { + if(m_search_gsettings && m_search_gsettings->keys().contains(SEARCH_METHOD_KEY)) { + m_search_gsettings->set(SEARCH_METHOD_KEY, true); + } else { + //调用创建索引接口 + Q_EMIT this->searchMethodChanged(FileUtils::SearchMethod::INDEXSEARCH); + //创建索引十秒后重新搜索一次(如果用户十秒内没有退出搜索界面且没有重新搜索) + m_researchTimer->start(); + } + } + }); installEventFilter(this); } @@ -399,9 +386,9 @@ void MainWindow::startSearch(QString keyword) { if(! m_search_result_thread->isRunning()) { m_search_result_thread->start(); } -// //允许弹窗且当前次搜索(为关闭主界面,算一次搜索过程)未询问且当前为暴力搜索 -// if(GlobalSettings::getInstance()->getValue(ENABLE_CREATE_INDEX_ASK_DIALOG).toString() != "false" && !m_currentSearchAsked && FileUtils::searchMethod == FileUtils::SearchMethod::DIRECTSEARCH) -// m_askTimer->start(); + //允许弹窗且当前次搜索(为关闭主界面,算一次搜索过程)未询问且当前为暴力搜索 + if(GlobalSettings::getInstance()->getValue(ENABLE_CREATE_INDEX_ASK_DIALOG).toString() != "false" && !m_currentSearchAsked && FileUtils::searchMethod == FileUtils::SearchMethod::DIRECTSEARCH) + m_askTimer->start(); m_contentFrame->setKeyword(keyword); @@ -499,28 +486,28 @@ void MainWindow::centerToScreen(QWidget* widget) { } void MainWindow::initGsettings() { -// const QByteArray id(UKUI_SEARCH_SCHEMAS); -// if(QGSettings::isSchemaInstalled(id)) { -// m_search_gsettings = new QGSettings(id); -// connect(m_search_gsettings, &QGSettings::changed, this, [ = ](const QString & key) { -// if(key == SEARCH_METHOD_KEY) { -// bool is_index_search = m_search_gsettings->get(SEARCH_METHOD_KEY).toBool(); -// this->setSearchMethod(is_index_search); -// } else if(key == WEB_ENGINE_KEY) { -// QString web_engine = m_search_gsettings->get(WEB_ENGINE_KEY).toString(); -// GlobalSettings::getInstance()->setValue(WEB_ENGINE, web_engine); -// Q_EMIT this->webEngineChanged(); -// } -// }); -// if(m_search_gsettings->keys().contains(SEARCH_METHOD_KEY)) { -// bool is_index_search = m_search_gsettings->get(SEARCH_METHOD_KEY).toBool(); -// this->setSearchMethod(is_index_search); -// } -// if(m_search_gsettings->keys().contains(WEB_ENGINE_KEY)) { -// QString web_engine = m_search_gsettings->get(WEB_ENGINE_KEY).toString(); -// GlobalSettings::getInstance()->setValue(WEB_ENGINE, web_engine); -// } -// } + const QByteArray id(UKUI_SEARCH_SCHEMAS); + if(QGSettings::isSchemaInstalled(id)) { + m_search_gsettings = new QGSettings(id); + connect(m_search_gsettings, &QGSettings::changed, this, [ = ](const QString & key) { + if(key == SEARCH_METHOD_KEY) { + bool is_index_search = m_search_gsettings->get(SEARCH_METHOD_KEY).toBool(); + this->setSearchMethod(is_index_search); + } else if(key == WEB_ENGINE_KEY) { + QString web_engine = m_search_gsettings->get(WEB_ENGINE_KEY).toString(); + GlobalSettings::getInstance()->setValue(WEB_ENGINE, web_engine); + Q_EMIT this->webEngineChanged(); + } + }); + if(m_search_gsettings->keys().contains(SEARCH_METHOD_KEY)) { + bool is_index_search = m_search_gsettings->get(SEARCH_METHOD_KEY).toBool(); + this->setSearchMethod(is_index_search); + } + if(m_search_gsettings->keys().contains(WEB_ENGINE_KEY)) { + QString web_engine = m_search_gsettings->get(WEB_ENGINE_KEY).toString(); + GlobalSettings::getInstance()->setValue(WEB_ENGINE, web_engine); + } + } } //使用GSetting获取当前窗口应该使用的透明度 @@ -528,26 +515,26 @@ double MainWindow::getTransparentData() { return GlobalSettings::getInstance()->getValue(TRANSPARENCY_KEY).toDouble(); } -//void MainWindow::initTimer() { -// m_askTimer = new QTimer; -// m_askTimer->setInterval(5 * 1000); -// connect(m_askTimer, &QTimer::timeout, this, [ = ]() { -// if(this->isVisible()) { -// m_isAskDialogVisible = true; -// m_askDialog->show(); -// m_currentSearchAsked = true; -// } -// m_askTimer->stop(); -// }); -// m_researchTimer = new QTimer; -// m_researchTimer->setInterval(10 * 1000); -// connect(m_researchTimer, &QTimer::timeout, this, [ = ]() { -// if(this->isVisible()) { -// searchContent(m_searchLayout->text()); -// } -// m_researchTimer->stop(); -// }); -//} +void MainWindow::initTimer() { + m_askTimer = new QTimer; + m_askTimer->setInterval(5 * 1000); + connect(m_askTimer, &QTimer::timeout, this, [ = ]() { + if(this->isVisible()) { + m_isAskDialogVisible = true; + m_askDialog->show(); + m_currentSearchAsked = true; + } + m_askTimer->stop(); + }); + m_researchTimer = new QTimer; + m_researchTimer->setInterval(10 * 1000); + connect(m_researchTimer, &QTimer::timeout, this, [ = ]() { + if(this->isVisible()) { + startSearch(m_searchLayout->text()); + } + m_researchTimer->stop(); + }); +} /** * @brief MainWindow::tryHideMainwindow 尝试隐藏主界面并停止部分未完成的动作,重置部分状态值 @@ -556,13 +543,13 @@ bool MainWindow::tryHideMainwindow() { if (!m_isAskDialogVisible) { qDebug()<<"Mainwindow will be hidden"; -// m_currentSearchAsked = false; + m_currentSearchAsked = false; this->hide(); -// m_askTimer->stop(); -// m_researchTimer->stop(); + m_askTimer->stop(); + m_researchTimer->stop(); m_contentFrame->closeWebView(); m_search_result_thread->requestInterruption(); -// m_search_result_thread->quit(); + m_search_result_thread->quit(); return true; } else { //有上层弹窗未关闭,不允许隐藏主界面 @@ -575,17 +562,17 @@ bool MainWindow::tryHideMainwindow() * @brief MainWindow::setSearchMethod 设置搜索模式 * @param is_index_search true为索引搜索,false为暴力搜索 */ -//void MainWindow::setSearchMethod(const bool &is_index_search) { -// if(is_index_search) { -// //调用创建索引接口 -// Q_EMIT this->searchMethodChanged(FileUtils::SearchMethod::INDEXSEARCH); -// //创建索引十秒后重新搜索一次(如果用户十秒内没有退出搜索界面且没有重新搜索) -// m_researchTimer->start(); -// } else { -// Q_EMIT this->searchMethodChanged(FileUtils::SearchMethod::DIRECTSEARCH); -// m_researchTimer->stop(); -// } -//} +void MainWindow::setSearchMethod(const bool &is_index_search) { + if(is_index_search) { + //调用创建索引接口 + Q_EMIT this->searchMethodChanged(FileUtils::SearchMethod::INDEXSEARCH); + //创建索引十秒后重新搜索一次(如果用户十秒内没有退出搜索界面且没有重新搜索) + m_researchTimer->start(); + } else { + Q_EMIT this->searchMethodChanged(FileUtils::SearchMethod::DIRECTSEARCH); + m_researchTimer->stop(); + } +} /** * @brief MainWindow::nativeEvent 处理窗口失焦事件 @@ -630,11 +617,11 @@ void MainWindow::keyPressEvent(QKeyEvent *event) bool MainWindow::eventFilter(QObject *watched, QEvent *event) { -// if (event->type() == QEvent::ActivationChange) { -// if(QApplication::activeWindow() != this) { -// tryHideMainwindow(); -// } -// } + if (event->type() == QEvent::ActivationChange) { + if(QApplication::activeWindow() != this) { + tryHideMainwindow(); + } + } return QMainWindow::eventFilter(watched,event); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 63f3f83..4895adf 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -44,16 +44,13 @@ #include #include #include - #include - #include "content-widget.h" #include "input-box.h" #include "index/index-generator.h" #include "libsearch.h" #include "search-app-thread.h" - #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) #include "xatom-helper.h" #endif @@ -66,7 +63,6 @@ #define SEARCH_METHOD_KEY "indexSearch" #define WEB_ENGINE_KEY "webEngine" - namespace Zeeker { class SearchResult; class MainWindow : public QMainWindow { @@ -94,7 +90,6 @@ public: MotifWmHints m_hints; #endif - private: // MainWindow quit when focus out. @@ -124,7 +119,7 @@ private: SearchManager* m_searcher = nullptr; SettingsMatch *m_settingsMatch = nullptr; QSystemTrayIcon *m_sys_tray_icon = nullptr; -// CreateIndexAskDialog * m_askDialog = nullptr; + CreateIndexAskDialog * m_askDialog = nullptr; bool m_isAskDialogVisible = false; QTimer * m_askTimer = nullptr; //询问是否创建索引弹窗弹出的计时器 @@ -134,9 +129,9 @@ private: SearchMethodManager m_searchMethodManager; -// void setSearchMethod(const bool&); + void setSearchMethod(const bool&); double getTransparentData(); -// void initTimer(); + void initTimer(); bool tryHideMainwindow(); protected: @@ -146,7 +141,7 @@ protected: void initUi(); Q_SIGNALS: -// void searchMethodChanged(FileUtils::SearchMethod); + void searchMethodChanged(FileUtils::SearchMethod); void webEngineChanged(); public Q_SLOTS: diff --git a/src/model/search-item-model.cpp b/src/model/search-item-model.cpp index 9ec3197..f011a18 100644 --- a/src/model/search-item-model.cpp +++ b/src/model/search-item-model.cpp @@ -66,7 +66,6 @@ int SearchItemModel::rowCount(const QModelIndex& index) const { * @param index 条目的索引 * @return model显示的列数 */ - int SearchItemModel::columnCount(const QModelIndex& index) const { return index.isValid() ? 0 : 1; } diff --git a/src/res/translations/zh_CN.qm b/src/res/translations/zh_CN.qm deleted file mode 100644 index de78a30..0000000 Binary files a/src/res/translations/zh_CN.qm and /dev/null differ diff --git a/src/resource.qrc b/src/resource.qrc index 207b8d7..8f84cfb 100644 --- a/src/resource.qrc +++ b/src/resource.qrc @@ -5,7 +5,6 @@ res/icons/close.svg res/qt-translations/qt_zh_CN.qm res/icons/net-disconnected.svg - res/translations/zh_CN.qm res/icons/system-search.symbolic.png diff --git a/src/settings-widget.cpp b/src/settings-widget.cpp index 36b2226..ca98ca2 100644 --- a/src/settings-widget.cpp +++ b/src/settings-widget.cpp @@ -34,7 +34,7 @@ extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int tran SettingsWidget::SettingsWidget(QWidget *parent) : QWidget(parent) { // this->setWindowIcon(QIcon::fromTheme("kylin-search")); this->setWindowTitle(tr("ukui-search-settings")); - this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint); +// this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint); // this->setAttribute(Qt::WA_TranslucentBackground); #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) @@ -226,6 +226,11 @@ void SettingsWidget::initUi() { // m_mainLyt->addWidget(m_bottomBtnFrame); m_contentLyt->addStretch(); + +#if (QT_VERSION < QT_VERSION_CHECK(5, 12, 0)) + this->m_titleFrame->hide(); + setAttribute(Qt::WA_DeleteOnClose); +#endif } /** diff --git a/src/settings-widget.h b/src/settings-widget.h index cd6236b..421a099 100644 --- a/src/settings-widget.h +++ b/src/settings-widget.h @@ -62,7 +62,6 @@ private: MotifWmHints m_hints; #endif - //标题栏 QVBoxLayout * m_mainLyt = nullptr; QFrame * m_contentFrame = nullptr; diff --git a/src/src.pro b/src/src.pro index 2c0ecdf..f61b5a7 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,4 +1,4 @@ -QT += core gui dbus xml x11extras +QT += core gui dbus KWindowSystem xml x11extras greaterThan(QT_MAJOR_VERSION, 4): QT += widgets @@ -9,7 +9,7 @@ TEMPLATE = app PKGCONFIG += gio-2.0 glib-2.0 gio-unix-2.0 CONFIG += c++11 link_pkgconfig no_keywords lrelease LIBS += -lxapian -lgsettings-qt -lquazip5 -lX11 -#LIBS += -lukui-log4qt +LIBS += -lukui-log4qt #-L/usr/local/lib/libjemalloc -ljemalloc # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the @@ -33,8 +33,8 @@ SOURCES += \ mainwindow.cpp \ search-app-thread.cpp \ search-result.cpp \ - settings-widget.cpp -# xatom-helper.cpp + settings-widget.cpp \ + xatom-helper.cpp HEADERS += \ @@ -44,8 +44,8 @@ HEADERS += \ mainwindow.h \ search-app-thread.h \ search-result.h \ - settings-widget.h -# xatom-helper.h + settings-widget.h \ + xatom-helper.h # Default rules for deployment. @@ -70,10 +70,10 @@ TRANSLATIONS += \ qm_files.path = /usr/share/ukui-search/translations/ qm_files.files = $$OUT_PWD/.qm/*.qm -#schemes.path = /usr/share/glib-2.0/schemas/ -#schemes.files += ../data/org.ukui.search.data.gschema.xml ../data/org.ukui.log4qt.ukui-search.gschema.xml +schemes.path = /usr/share/glib-2.0/schemas/ +schemes.files += ../data/org.ukui.search.data.gschema.xml ../data/org.ukui.log4qt.ukui-search.gschema.xml -INSTALLS += qm_files +INSTALLS += qm_files schemes LIBS += -L$$OUT_PWD/../libchinese-segmentation -lchinese-segmentation \ -L$$OUT_PWD/../libsearch -lukui-search @@ -83,3 +83,13 @@ DEPENDPATH += $$PWD/../libchinese-segmentation INCLUDEPATH += $$PWD/../libsearch DEPENDPATH += $$PWD/../libsearch + +#DISTFILES += \ +# ../data/ukui-search-menu.desktop \ +# $$OUT_PWD/.qm/bo.qm \ +# $$OUT_PWD/.qm/tr.qm \ +# $$OUT_PWD/.qm/zh_CN.qm + +DISTFILES += \ + ../data/org.ukui.log4qt.ukui-search.gschema.xml \ + ../data/org.ukui.search.data.gschema.xml diff --git a/translations/ukui-search/bo.ts b/translations/ukui-search/bo.ts index 01cca72..121582c 100644 --- a/translations/ukui-search/bo.ts +++ b/translations/ukui-search/bo.ts @@ -4,7 +4,7 @@ QObject - + ukui-search is already running! @@ -12,57 +12,57 @@ Zeeker::ContentWidget - + Recently Opened - + Open Quickly - + Commonly Used - + Apps - + Settings - + Files - + Dirs - + File Contents - + Best Matches - + Web Pages - + Unknown @@ -70,32 +70,32 @@ Zeeker::CreateIndexAskDialog - + ukui-search - + Search - + Creating index can help you getting results quickly, whether to create or not? - + Don't remind - + No - + Yes @@ -111,17 +111,17 @@ Zeeker::MainWindow - + ukui-search - + Global Search - + Search @@ -170,32 +170,32 @@ Zeeker::SearchDetailView - + Introduction: %1 - + Application - + Document - + Preview is not avaliable - + Path - + Last time modified @@ -208,155 +208,155 @@ - - - + + + Search - + <h2>Settings</h2> - + <h3>Index State</h3> - - + + ... - + <h3>File Index Settings</h3> - + Following folders will not be searched. You can set it by adding and removing folders. - + Add ignored folders - + <h3>Search Engine Settings</h3> - + Please select search engine you preferred. - + baidu - + sougou - + 360 - + Whether to delete this directory? - + Yes - + No - + Creating ... - + Done - + Index Entry: %1 - + Directories - + select blocked folder - + Select - + Position: - + FileName: - + FileType: - + Cancel - + Choosen path is Empty! - + Choosen path is not in "home"! - + Its' parent folder has been blocked! - + Set blocked folder failed! - + OK diff --git a/translations/ukui-search/tr.ts b/translations/ukui-search/tr.ts index 73ae8de..2b68a36 100644 --- a/translations/ukui-search/tr.ts +++ b/translations/ukui-search/tr.ts @@ -99,7 +99,7 @@ QObject - + ukui-search is already running! ukui-bul zaten çalışıyor! @@ -247,57 +247,57 @@ Zeeker::ContentWidget - + Recently Opened Yeni Açılan - + Open Quickly Hızlı Aç - + Commonly Used Genel olarak kullanılan - + Apps Uygulamalar - + Settings Ayarlar - + Files Dosyalar - + Dirs Dizinler - + File Contents Dosya İçeriği - + Best Matches En İyi Eşleşen - + Web Pages - + Unknown Bilinmeyen @@ -305,32 +305,32 @@ Zeeker::CreateIndexAskDialog - + ukui-search - + Search Ara - + Creating index can help you getting results quickly, whether to create or not? - + Don't remind - + No - + Yes @@ -346,17 +346,17 @@ Zeeker::MainWindow - + ukui-search - + Global Search Genel Arama - + Search Ara @@ -405,32 +405,32 @@ Zeeker::SearchDetailView - + Introduction: %1 - + Application Uygulama - + Document Belge - + Preview is not avaliable - + Path Yol - + Last time modified Son değiştirilme zamanı @@ -443,155 +443,155 @@ - - - + + + Search Ara - + <h2>Settings</h2> <h2>Ayarlar</h2> - + <h3>Index State</h3> <h3>Dizin Durumu</h3> - - + + ... ... - + <h3>File Index Settings</h3> <h3>Dosya Dizini Ayarları</h3> - + Following folders will not be searched. You can set it by adding and removing folders. Aşağıdaki klasörler aranmayacaktır. Klasör ekleyip kaldırarak ayarlayabilirsiniz. - + Add ignored folders Göz ardı edilen klasörleri ekleyin - + <h3>Search Engine Settings</h3> <h3>SArama Motoru Ayarları</h3> - + Please select search engine you preferred. Lütfen tercih ettiğiniz arama motorunu seçin. - + baidu - + sougou - + 360 - + Whether to delete this directory? Bu dizini silinsin mi? - + Yes - + No - + Creating ... Oluşturuluyor... - + Done Tamam - + Index Entry: %1 Dizin Girişi: %1 - + Directories Dizinler - + select blocked folder engellenen klasörü seç - + Select Seç - + Position: Pozisyon: - + FileName: Dosya Adı: - + FileType: Dosya Türü: - + Cancel İptal - + Choosen path is Empty! - + Choosen path is not in "home"! - + Its' parent folder has been blocked! - + Set blocked folder failed! - + OK diff --git a/translations/ukui-search/zh_CN.ts b/translations/ukui-search/zh_CN.ts index 18f6bf2..3b34cf8 100644 --- a/translations/ukui-search/zh_CN.ts +++ b/translations/ukui-search/zh_CN.ts @@ -4,7 +4,7 @@ QObject - + ukui-search is already running! @@ -12,57 +12,57 @@ Zeeker::ContentWidget - + Recently Opened 最近 - + Open Quickly 快速入口 - + Commonly Used 常用 - + Apps 应用 - + Settings 配置项 - + Files 文件 - + Dirs 文件夹 - + File Contents 文件内容 - + Best Matches 最佳匹配 - + Web Pages 网页 - + Unknown 未知 @@ -70,32 +70,32 @@ Zeeker::CreateIndexAskDialog - + ukui-search 搜索 - + Search 搜索 - + Creating index can help you getting results quickly, whether to create or not? 创建索引可以快速获取搜索结果,是否创建? - + Don't remind 不再提醒 - + No 否(N) - + Yes 是(Y) @@ -111,17 +111,17 @@ Zeeker::MainWindow - + ukui-search 搜索 - + Global Search 搜索 - + Search 搜索 @@ -170,32 +170,32 @@ Zeeker::SearchDetailView - + Introduction: %1 软件介绍: %1 - + Application 应用 - + Document 文件 - + Preview is not avaliable 当前预览不可用 - + Path 路径 - + Last time modified 上次修改时间 @@ -208,155 +208,155 @@ 搜索 - - - + + + Search 搜索 - + <h2>Settings</h2> <h2>设置</h2> - + <h3>Index State</h3> <h3>索引状态</h3> - - + + ... - + <h3>File Index Settings</h3> <h3>文件索引设置</h3> - + Following folders will not be searched. You can set it by adding and removing folders. 搜索将不再查看以下文件夹。通过增加和删除文件夹可进行文件索引设置。 - + Add ignored folders 添加文件夹至黑名单 - + <h3>Search Engine Settings</h3> <h3>搜索引擎设置</h3> - + Please select search engine you preferred. 设置互联网搜索引擎 - + baidu 百度 - + sougou 搜狗 - + 360 360 - + Whether to delete this directory? 是否要删除此目录 - + Yes 是(Y) - + No 否(N) - + Creating ... 正在索引 - + Done 索引完成 - + Index Entry: %1 索引项: %1 - + Directories 文件夹 - + select blocked folder 选择屏蔽文件夹 - + Select 选择 - + Position: 位置: - + FileName: 名称: - + FileType: 类型: - + Cancel 取消 - + Choosen path is Empty! 选择的路径不存在! - + Choosen path is not in "home"! 请选择家目录下的文件夹! - + Its' parent folder has been blocked! 父文件夹已被屏蔽! - + Set blocked folder failed! - + OK 好的