Merge branch '0720-newfrontend' into 'new-frontend'
Merge from dev-unity and update app search. See merge request kylin-desktop/ukui-search!111
This commit is contained in:
commit
af28835640
|
@ -21,6 +21,7 @@
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include "file-utils.h"
|
#include "file-utils.h"
|
||||||
#include "app-search-plugin.h"
|
#include "app-search-plugin.h"
|
||||||
|
#define ANDROID_APP_DESKTOP_PATH QDir::homePath() + "/.local/share/applications/"
|
||||||
using namespace Zeeker;
|
using namespace Zeeker;
|
||||||
static AppMatch *app_match_Class = nullptr;
|
static AppMatch *app_match_Class = nullptr;
|
||||||
|
|
||||||
|
@ -35,10 +36,11 @@ AppMatch::AppMatch(QObject *parent) : QThread(parent)
|
||||||
{
|
{
|
||||||
m_watchAppDir = new QFileSystemWatcher(this);
|
m_watchAppDir = new QFileSystemWatcher(this);
|
||||||
m_watchAppDir->addPath("/usr/share/applications/");
|
m_watchAppDir->addPath("/usr/share/applications/");
|
||||||
QDir androidPath(QDir::homePath() + "/.local/share/applications/");
|
QDir androidPath(ANDROID_APP_DESKTOP_PATH);
|
||||||
if(androidPath.exists()) {
|
if(!androidPath.exists()) {
|
||||||
m_watchAppDir->addPath(QDir::homePath() + "/.local/share/applications/");
|
androidPath.mkpath(ANDROID_APP_DESKTOP_PATH);
|
||||||
}
|
}
|
||||||
|
m_watchAppDir->addPath(ANDROID_APP_DESKTOP_PATH);
|
||||||
qDBusRegisterMetaType<QMap<QString, QString>>();
|
qDBusRegisterMetaType<QMap<QString, QString>>();
|
||||||
qDBusRegisterMetaType<QList<QMap<QString, QString>>>();
|
qDBusRegisterMetaType<QList<QMap<QString, QString>>>();
|
||||||
m_interFace = new QDBusInterface("com.kylin.softwarecenter.getsearchresults", "/com/kylin/softwarecenter/getsearchresults",
|
m_interFace = new QDBusInterface("com.kylin.softwarecenter.getsearchresults", "/com/kylin/softwarecenter/getsearchresults",
|
||||||
|
@ -76,7 +78,6 @@ void AppMatch::getAllDesktopFilePath(QString path) {
|
||||||
|
|
||||||
char* name;
|
char* name;
|
||||||
char* icon;
|
char* icon;
|
||||||
QStringList applist;
|
|
||||||
|
|
||||||
GKeyFileFlags flags = G_KEY_FILE_NONE;
|
GKeyFileFlags flags = G_KEY_FILE_NONE;
|
||||||
GKeyFile* keyfile = g_key_file_new();
|
GKeyFile* keyfile = g_key_file_new();
|
||||||
|
@ -154,9 +155,14 @@ void AppMatch::getAllDesktopFilePath(QString path) {
|
||||||
icon = g_key_file_get_locale_string(keyfile, "Desktop Entry", "Icon", nullptr, nullptr);
|
icon = g_key_file_get_locale_string(keyfile, "Desktop Entry", "Icon", nullptr, nullptr);
|
||||||
if(!m_filePathList.contains(filePathStr)) {
|
if(!m_filePathList.contains(filePathStr)) {
|
||||||
NameString appname;
|
NameString appname;
|
||||||
|
QStringList appInfolist;
|
||||||
|
|
||||||
appname.app_name = QString::fromLocal8Bit(name);
|
appname.app_name = QString::fromLocal8Bit(name);
|
||||||
m_installAppMap.insert(appname, applist << filePathStr << QString::fromLocal8Bit(icon) << "" << "");
|
appInfolist << filePathStr << QString::fromLocal8Bit(icon);
|
||||||
applist.clear();
|
appInfolist.append(QString::fromLocal8Bit(g_key_file_get_string(keyfile, "Desktop Entry", "Name", nullptr)));
|
||||||
|
appInfolist.append(QString::fromLocal8Bit(g_key_file_get_string(keyfile, "Desktop Entry", "Name[zh_CN]", nullptr)));
|
||||||
|
|
||||||
|
m_installAppMap.insert(appname, appInfolist);
|
||||||
}
|
}
|
||||||
// m_filePathList.append(filePathStr);
|
// m_filePathList.append(filePathStr);
|
||||||
}
|
}
|
||||||
|
@ -251,9 +257,12 @@ void AppMatch::appNameMatch(QString keyWord, size_t uniqueSymbol, DataQueue<Sear
|
||||||
if(iter.key().app_name.contains(keyWord, Qt::CaseInsensitive)) {
|
if(iter.key().app_name.contains(keyWord, Qt::CaseInsensitive)) {
|
||||||
SearchPluginIface::ResultInfo ri;
|
SearchPluginIface::ResultInfo ri;
|
||||||
creatResultInfo(ri, iter, true);
|
creatResultInfo(ri, iter, true);
|
||||||
|
AppSearchPlugin::m_mutex.lock();
|
||||||
if (uniqueSymbol == AppSearchPlugin::uniqueSymbol) {
|
if (uniqueSymbol == AppSearchPlugin::uniqueSymbol) {
|
||||||
searchResult->enqueue(ri);
|
searchResult->enqueue(ri);
|
||||||
|
AppSearchPlugin::m_mutex.unlock();
|
||||||
} else {
|
} else {
|
||||||
|
AppSearchPlugin::m_mutex.unlock();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// installed.insert(name, list);
|
// installed.insert(name, list);
|
||||||
|
@ -268,9 +277,12 @@ void AppMatch::appNameMatch(QString keyWord, size_t uniqueSymbol, DataQueue<Sear
|
||||||
if(shouzimu.contains(keyWord, Qt::CaseInsensitive)) {
|
if(shouzimu.contains(keyWord, Qt::CaseInsensitive)) {
|
||||||
SearchPluginIface::ResultInfo ri;
|
SearchPluginIface::ResultInfo ri;
|
||||||
creatResultInfo(ri, iter, true);
|
creatResultInfo(ri, iter, true);
|
||||||
|
AppSearchPlugin::m_mutex.lock();
|
||||||
if (uniqueSymbol == AppSearchPlugin::uniqueSymbol) {
|
if (uniqueSymbol == AppSearchPlugin::uniqueSymbol) {
|
||||||
searchResult->enqueue(ri);
|
searchResult->enqueue(ri);
|
||||||
|
AppSearchPlugin::m_mutex.unlock();
|
||||||
} else {
|
} else {
|
||||||
|
AppSearchPlugin::m_mutex.unlock();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// installed.insert(name, list);
|
// installed.insert(name, list);
|
||||||
|
@ -281,16 +293,37 @@ void AppMatch::appNameMatch(QString keyWord, size_t uniqueSymbol, DataQueue<Sear
|
||||||
QString pinyin = pinyinlist.at(2 * i); // 中文转拼音
|
QString pinyin = pinyinlist.at(2 * i); // 中文转拼音
|
||||||
if(pinyin.contains(keyWord, Qt::CaseInsensitive)) {
|
if(pinyin.contains(keyWord, Qt::CaseInsensitive)) {
|
||||||
SearchPluginIface::ResultInfo ri;
|
SearchPluginIface::ResultInfo ri;
|
||||||
|
AppSearchPlugin::m_mutex.lock();
|
||||||
creatResultInfo(ri, iter, true);
|
creatResultInfo(ri, iter, true);
|
||||||
if (uniqueSymbol == AppSearchPlugin::uniqueSymbol) {
|
if (uniqueSymbol == AppSearchPlugin::uniqueSymbol) {
|
||||||
searchResult->enqueue(ri);
|
searchResult->enqueue(ri);
|
||||||
|
AppSearchPlugin::m_mutex.unlock();
|
||||||
} else {
|
} else {
|
||||||
|
AppSearchPlugin::m_mutex.lock();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// installed.insert(name, list);
|
// installed.insert(name, list);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
QStringList tmpList;
|
||||||
|
tmpList << iter.value().at(2) << iter.value().at(3);
|
||||||
|
for(QString s : tmpList) {
|
||||||
|
if(s.contains(keyWord, Qt::CaseInsensitive)) {
|
||||||
|
SearchPluginIface::ResultInfo ri;
|
||||||
|
AppSearchPlugin::m_mutex.lock();
|
||||||
|
creatResultInfo(ri, iter, true);
|
||||||
|
if (uniqueSymbol == AppSearchPlugin::uniqueSymbol) {
|
||||||
|
searchResult->enqueue(ri);
|
||||||
|
AppSearchPlugin::m_mutex.unlock();
|
||||||
|
} else {
|
||||||
|
AppSearchPlugin::m_mutex.unlock();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// installed.insert(name, list);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,9 +364,12 @@ void AppMatch::parseSoftWareCenterReturn(QList<QMap<QString, QString>> list, siz
|
||||||
ri.description.append(di);
|
ri.description.append(di);
|
||||||
ri.actionKey = list.at(i).value("appname");
|
ri.actionKey = list.at(i).value("appname");
|
||||||
ri.type = 1; //1 means not installed apps.
|
ri.type = 1; //1 means not installed apps.
|
||||||
|
AppSearchPlugin::m_mutex.lock();
|
||||||
if (uniqueSymbol == AppSearchPlugin::uniqueSymbol) {
|
if (uniqueSymbol == AppSearchPlugin::uniqueSymbol) {
|
||||||
searchResult->enqueue(ri);
|
searchResult->enqueue(ri);
|
||||||
|
AppSearchPlugin::m_mutex.unlock();
|
||||||
} else {
|
} else {
|
||||||
|
AppSearchPlugin::m_mutex.unlock();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -371,18 +407,12 @@ void AppMatch::run() {
|
||||||
qDebug() << "AppMatch is run";
|
qDebug() << "AppMatch is run";
|
||||||
this->getDesktopFilePath();
|
this->getDesktopFilePath();
|
||||||
this->getAllDesktopFilePath("/usr/share/applications/");
|
this->getAllDesktopFilePath("/usr/share/applications/");
|
||||||
QDir androidPath(QDir::homePath() + "/.local/share/applications/");
|
this->getAllDesktopFilePath(ANDROID_APP_DESKTOP_PATH);
|
||||||
if(androidPath.exists())
|
connect(m_watchAppDir, &QFileSystemWatcher::directoryChanged, this, [ = ](const QString & path) {
|
||||||
this->getAllDesktopFilePath(QDir::homePath() + "/.local/share/applications/");
|
|
||||||
connect(m_watchAppDir, &QFileSystemWatcher::directoryChanged, this, [ = ](const QString & path) {
|
|
||||||
this->getDesktopFilePath();
|
|
||||||
if(path == "/usr/share/applications/") {
|
if(path == "/usr/share/applications/") {
|
||||||
this->getAllDesktopFilePath("/usr/share/applications/");
|
this->getAllDesktopFilePath("/usr/share/applications/");
|
||||||
}
|
} else if(path == ANDROID_APP_DESKTOP_PATH) {
|
||||||
if(androidPath.exists()) {
|
this->getAllDesktopFilePath(ANDROID_APP_DESKTOP_PATH);
|
||||||
if(path == QDir::homePath() + "/.local/share/applications/") {
|
|
||||||
this->getAllDesktopFilePath(QDir::homePath() + "/.local/share/applications/");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,17 +33,17 @@ QString FileSearchPlugin::getPluginName()
|
||||||
|
|
||||||
void Zeeker::FileSearchPlugin::KeywordSearch(QString keyword, DataQueue<ResultInfo> *searchResult)
|
void Zeeker::FileSearchPlugin::KeywordSearch(QString keyword, DataQueue<ResultInfo> *searchResult)
|
||||||
{
|
{
|
||||||
SearchManager::m_mutex1.lock();
|
SearchManager::m_mutexFile.lock();
|
||||||
++SearchManager::uniqueSymbol1;
|
++SearchManager::uniqueSymbolFile;
|
||||||
SearchManager::m_mutex1.unlock();
|
SearchManager::m_mutexFile.unlock();
|
||||||
|
|
||||||
if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) {
|
if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) {
|
||||||
DirectSearch *directSearch;
|
DirectSearch *directSearch;
|
||||||
directSearch = new DirectSearch(keyword, searchResult, FILE_SEARCH_VALUE, SearchManager::uniqueSymbol1);
|
directSearch = new DirectSearch(keyword, searchResult, FILE_SEARCH_VALUE, SearchManager::uniqueSymbolFile);
|
||||||
m_pool.start(directSearch);
|
m_pool.start(directSearch);
|
||||||
} else if(FileUtils::SearchMethod::INDEXSEARCH == FileUtils::searchMethod) {
|
} else if(FileUtils::SearchMethod::INDEXSEARCH == FileUtils::searchMethod) {
|
||||||
FileSearch *filesearch;
|
FileSearch *filesearch;
|
||||||
filesearch = new FileSearch(searchResult, SearchManager::uniqueSymbol1, keyword, FILE_SEARCH_VALUE, 1, 0, 5);
|
filesearch = new FileSearch(searchResult, SearchManager::uniqueSymbolFile, keyword, FILE_SEARCH_VALUE, 1, 0, 5);
|
||||||
m_pool.start(filesearch);
|
m_pool.start(filesearch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,17 +222,17 @@ QString DirSearchPlugin::getPluginName()
|
||||||
|
|
||||||
void Zeeker::DirSearchPlugin::KeywordSearch(QString keyword, DataQueue<ResultInfo> *searchResult)
|
void Zeeker::DirSearchPlugin::KeywordSearch(QString keyword, DataQueue<ResultInfo> *searchResult)
|
||||||
{
|
{
|
||||||
SearchManager::m_mutex2.lock();
|
SearchManager::m_mutexDir.lock();
|
||||||
++SearchManager::uniqueSymbol2;
|
++SearchManager::uniqueSymbolDir;
|
||||||
SearchManager::m_mutex2.unlock();
|
SearchManager::m_mutexDir.unlock();
|
||||||
|
|
||||||
if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) {
|
if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) {
|
||||||
DirectSearch *directSearch;
|
DirectSearch *directSearch;
|
||||||
directSearch = new DirectSearch(keyword, searchResult, DIR_SEARCH_VALUE, SearchManager::uniqueSymbol2);
|
directSearch = new DirectSearch(keyword, searchResult, DIR_SEARCH_VALUE, SearchManager::uniqueSymbolDir);
|
||||||
m_pool.start(directSearch);
|
m_pool.start(directSearch);
|
||||||
} else if(FileUtils::SearchMethod::INDEXSEARCH == FileUtils::searchMethod) {
|
} else if(FileUtils::SearchMethod::INDEXSEARCH == FileUtils::searchMethod) {
|
||||||
FileSearch *filesearch;
|
FileSearch *filesearch;
|
||||||
filesearch = new FileSearch(searchResult, SearchManager::uniqueSymbol2, keyword, DIR_SEARCH_VALUE, 1, 0, 5);
|
filesearch = new FileSearch(searchResult, SearchManager::uniqueSymbolDir, keyword, DIR_SEARCH_VALUE, 1, 0, 5);
|
||||||
m_pool.start(filesearch);
|
m_pool.start(filesearch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -402,16 +402,16 @@ QString FileContengSearchPlugin::getPluginName()
|
||||||
|
|
||||||
void Zeeker::FileContengSearchPlugin::KeywordSearch(QString keyword, DataQueue<ResultInfo> *searchResult)
|
void Zeeker::FileContengSearchPlugin::KeywordSearch(QString keyword, DataQueue<ResultInfo> *searchResult)
|
||||||
{
|
{
|
||||||
SearchManager::m_mutex3.lock();
|
SearchManager::m_mutexContent.lock();
|
||||||
++SearchManager::uniqueSymbol3;
|
++SearchManager::uniqueSymbolContent;
|
||||||
SearchManager::m_mutex3.unlock();
|
SearchManager::m_mutexContent.unlock();
|
||||||
|
|
||||||
m_keyWord = keyword;
|
m_keyWord = keyword;
|
||||||
if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) {
|
if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) {
|
||||||
return;
|
return;
|
||||||
} else if(FileUtils::SearchMethod::INDEXSEARCH == FileUtils::searchMethod) {
|
} else if(FileUtils::SearchMethod::INDEXSEARCH == FileUtils::searchMethod) {
|
||||||
FileContentSearch *fileContentSearch;
|
FileContentSearch *fileContentSearch;
|
||||||
fileContentSearch = new FileContentSearch(searchResult, SearchManager::uniqueSymbol3, keyword, 0, 5);
|
fileContentSearch = new FileContentSearch(searchResult, SearchManager::uniqueSymbolContent, keyword, 0, 5);
|
||||||
m_pool.start(fileContentSearch);
|
m_pool.start(fileContentSearch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,13 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include "search-manager.h"
|
#include "search-manager.h"
|
||||||
|
|
||||||
using namespace Zeeker;
|
using namespace Zeeker;
|
||||||
size_t SearchManager::uniqueSymbol1 = 0;
|
size_t SearchManager::uniqueSymbolFile = 0;
|
||||||
size_t SearchManager::uniqueSymbol2 = 0;
|
size_t SearchManager::uniqueSymbolDir = 0;
|
||||||
size_t SearchManager::uniqueSymbol3 = 0;
|
size_t SearchManager::uniqueSymbolContent = 0;
|
||||||
QMutex SearchManager::m_mutex1;
|
QMutex SearchManager::m_mutexFile;
|
||||||
QMutex SearchManager::m_mutex2;
|
QMutex SearchManager::m_mutexDir;
|
||||||
QMutex SearchManager::m_mutex3;
|
QMutex SearchManager::m_mutexContent;
|
||||||
SearchManager::SearchManager(QObject *parent) : QObject(parent) {
|
SearchManager::SearchManager(QObject *parent) : QObject(parent) {
|
||||||
m_pool.setMaxThreadCount(3);
|
m_pool.setMaxThreadCount(3);
|
||||||
m_pool.setExpiryTimeout(1000);
|
m_pool.setExpiryTimeout(1000);
|
||||||
|
@ -46,31 +45,30 @@ int SearchManager::getCurrentIndexCount() {
|
||||||
|
|
||||||
void SearchManager::onKeywordSearch(QString keyword, QQueue<QString> *searchResultFile, QQueue<QString> *searchResultDir,
|
void SearchManager::onKeywordSearch(QString keyword, QQueue<QString> *searchResultFile, QQueue<QString> *searchResultDir,
|
||||||
QQueue<QPair<QString, QStringList>> *searchResultContent) {
|
QQueue<QPair<QString, QStringList>> *searchResultContent) {
|
||||||
m_mutex1.lock();
|
// m_mutexFile.lock();
|
||||||
++uniqueSymbol1;
|
// ++uniqueSymbolFile;
|
||||||
m_mutex1.unlock();
|
// m_mutexFile.unlock();
|
||||||
m_mutex2.lock();
|
// m_mutexDir.lock();
|
||||||
++uniqueSymbol2;
|
// ++uniqueSymbolDir;
|
||||||
m_mutex2.unlock();
|
// m_mutexDir.unlock();
|
||||||
m_mutex3.lock();
|
// m_mutexContent.lock();
|
||||||
++uniqueSymbol3;
|
// ++uniqueSymbolContent;
|
||||||
m_mutex3.unlock();
|
// m_mutexContent.unlock();
|
||||||
|
|
||||||
// if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) {
|
// if(FileUtils::SearchMethod::DIRECTSEARCH == FileUtils::searchMethod) {
|
||||||
// DirectSearch *directSearch;
|
// DirectSearch *directSearch;
|
||||||
// directSearch = new DirectSearch(keyword, searchResultFile, searchResultDir, uniqueSymbol1);
|
// directSearch = new DirectSearch(keyword, searchResultFile, searchResultDir, uniqueSymbolFile);
|
||||||
// m_pool.start(directSearch);
|
// m_pool.start(directSearch);
|
||||||
// } else if(FileUtils::SearchMethod::INDEXSEARCH == FileUtils::searchMethod) {
|
// } else if(FileUtils::SearchMethod::INDEXSEARCH == FileUtils::searchMethod) {
|
||||||
// FileSearch *filesearch;
|
// FileSearch *filesearch;
|
||||||
// filesearch = new FileSearch(searchResultFile, uniqueSymbol1, keyword, "0", 1, 0, 5);
|
// filesearch = new FileSearch(searchResultFile, uniqueSymbolFile, keyword, "0", 1, 0, 5);
|
||||||
// m_pool.start(filesearch);
|
// m_pool.start(filesearch);
|
||||||
|
|
||||||
// FileSearch *dirsearch;
|
// FileSearch *dirsearch;
|
||||||
// dirsearch = new FileSearch(searchResultDir, uniqueSymbol2, keyword, "1", 1, 0, 5);
|
// dirsearch = new FileSearch(searchResultDir, uniqueSymbolDir, keyword, "1", 1, 0, 5);
|
||||||
// m_pool.start(dirsearch);
|
// m_pool.start(dirsearch);
|
||||||
|
|
||||||
// FileContentSearch *contentSearch;
|
// FileContentSearch *contentSearch;
|
||||||
// contentSearch = new FileContentSearch(searchResultContent, uniqueSymbol3, keyword, 0, 5);
|
// contentSearch = new FileContentSearch(searchResultContent, uniqueSymbolContent, keyword, 0, 5);
|
||||||
// m_pool.start(contentSearch);
|
// m_pool.start(contentSearch);
|
||||||
// } else {
|
// } else {
|
||||||
// qWarning() << "Unknown search method! FileUtils::searchMethod: " << static_cast<int>(FileUtils::searchMethod);
|
// qWarning() << "Unknown search method! FileUtils::searchMethod: " << static_cast<int>(FileUtils::searchMethod);
|
||||||
|
@ -119,9 +117,20 @@ FileSearch::~FileSearch() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileSearch::run() {
|
void FileSearch::run() {
|
||||||
if(!m_search_result->isEmpty()) {
|
if(m_value == "0") {
|
||||||
m_search_result->clear();
|
SearchManager::m_mutexFile.lock();
|
||||||
|
if(!m_search_result->isEmpty()) {
|
||||||
|
m_search_result->clear();
|
||||||
|
}
|
||||||
|
SearchManager::m_mutexFile.unlock();
|
||||||
|
} else if(m_value == "1") {
|
||||||
|
SearchManager::m_mutexDir.lock();
|
||||||
|
if(!m_search_result->isEmpty()) {
|
||||||
|
m_search_result->clear();
|
||||||
|
}
|
||||||
|
SearchManager::m_mutexDir.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
int resultCount = 0;
|
int resultCount = 0;
|
||||||
int total = 0;
|
int total = 0;
|
||||||
while(total < 100) {
|
while(total < 100) {
|
||||||
|
@ -197,23 +206,23 @@ int FileSearch::getResult(Xapian::MSet &result) {
|
||||||
if(SearchManager::creatResultInfo(ri, path)) {
|
if(SearchManager::creatResultInfo(ri, path)) {
|
||||||
switch(m_value.toInt()) {
|
switch(m_value.toInt()) {
|
||||||
case 1:
|
case 1:
|
||||||
SearchManager::m_mutex1.lock();
|
SearchManager::m_mutexDir.lock();
|
||||||
if(m_uniqueSymbol == SearchManager::uniqueSymbol2) {
|
if(m_uniqueSymbol == SearchManager::uniqueSymbolDir) {
|
||||||
m_search_result->enqueue(ri);
|
m_search_result->enqueue(ri);
|
||||||
SearchManager::m_mutex1.unlock();
|
SearchManager::m_mutexDir.unlock();
|
||||||
} else {
|
} else {
|
||||||
SearchManager::m_mutex1.unlock();
|
SearchManager::m_mutexDir.unlock();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
SearchManager::m_mutex2.lock();
|
SearchManager::m_mutexFile.lock();
|
||||||
if(m_uniqueSymbol == SearchManager::uniqueSymbol1) {
|
if(m_uniqueSymbol == SearchManager::uniqueSymbolFile) {
|
||||||
m_search_result->enqueue(ri);
|
m_search_result->enqueue(ri);
|
||||||
SearchManager::m_mutex2.unlock();
|
SearchManager::m_mutexFile.unlock();
|
||||||
} else {
|
} else {
|
||||||
SearchManager::m_mutex2.unlock();
|
SearchManager::m_mutexFile.unlock();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -243,9 +252,11 @@ FileContentSearch::~FileContentSearch() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileContentSearch::run() {
|
void FileContentSearch::run() {
|
||||||
|
SearchManager::m_mutexContent.lock();
|
||||||
if(!m_search_result->isEmpty()) {
|
if(!m_search_result->isEmpty()) {
|
||||||
m_search_result->clear();
|
m_search_result->clear();
|
||||||
}
|
}
|
||||||
|
SearchManager::m_mutexContent.unlock();
|
||||||
int resultCount = 0;
|
int resultCount = 0;
|
||||||
int total = 0;
|
int total = 0;
|
||||||
|
|
||||||
|
@ -396,14 +407,15 @@ int FileContentSearch::getResult(Xapian::MSet &result, std::string &keyWord) {
|
||||||
// QString().swap(snippet);
|
// QString().swap(snippet);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
SearchManager::m_mutex3.lock();
|
|
||||||
if(m_uniqueSymbol == SearchManager::uniqueSymbol3) {
|
SearchManager::m_mutexContent.lock();
|
||||||
|
if(m_uniqueSymbol == SearchManager::uniqueSymbolContent) {
|
||||||
m_search_result->enqueue(ri);
|
m_search_result->enqueue(ri);
|
||||||
SearchManager::m_mutex3.unlock();
|
SearchManager::m_mutexContent.unlock();
|
||||||
// snippets.clear();
|
// snippets.clear();
|
||||||
// QStringList().swap(snippets);
|
// QStringList().swap(snippets);
|
||||||
} else {
|
} else {
|
||||||
SearchManager::m_mutex3.unlock();
|
SearchManager::m_mutexContent.unlock();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// searchResult.insert(path,snippets);
|
// searchResult.insert(path,snippets);
|
||||||
|
@ -441,7 +453,6 @@ void DirectSearch::run() {
|
||||||
list = dir.entryInfoList();
|
list = dir.entryInfoList();
|
||||||
for (auto i : list) {
|
for (auto i : list) {
|
||||||
if (i.isDir() && (!(i.isSymLink()))) {
|
if (i.isDir() && (!(i.isSymLink()))) {
|
||||||
|
|
||||||
bool findIndex = false;
|
bool findIndex = false;
|
||||||
for (QString j : blockList) {
|
for (QString j : blockList) {
|
||||||
if (FileUtils::isOrUnder(i.absoluteFilePath(), j)) {
|
if (FileUtils::isOrUnder(i.absoluteFilePath(), j)) {
|
||||||
|
@ -449,30 +460,39 @@ void DirectSearch::run() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (findIndex == true) {
|
if (findIndex == true) {
|
||||||
qDebug() << "path is blocked:" << i.absoluteFilePath();
|
qDebug() << "path is blocked:" << i.absoluteFilePath();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bfs.enqueue(i.absoluteFilePath());
|
bfs.enqueue(i.absoluteFilePath());
|
||||||
}
|
}
|
||||||
if(i.fileName().contains(m_keyword, Qt::CaseInsensitive)) {
|
if(i.fileName().contains(m_keyword, Qt::CaseInsensitive)) {
|
||||||
// qWarning() << i.fileName() << m_keyword;
|
// qWarning() << i.fileName() << m_keyword;
|
||||||
if(m_searchResult->length() > 49)
|
if(m_searchResult->length() > 49)
|
||||||
return;
|
return;
|
||||||
if((i.isDir() && m_value == DIR_SEARCH_VALUE) || (i.isFile() && m_value == FILE_SEARCH_VALUE)) {
|
if((i.isDir() && m_value == DIR_SEARCH_VALUE)) {
|
||||||
SearchPluginIface::ResultInfo ri;
|
SearchPluginIface::ResultInfo ri;
|
||||||
if(SearchManager::creatResultInfo(ri,i.absoluteFilePath())) {
|
if(SearchManager::creatResultInfo(ri,i.absoluteFilePath())) {
|
||||||
SearchManager::m_mutex1.lock();
|
SearchManager::m_mutexDir.lock();
|
||||||
if(m_uniqueSymbol == SearchManager::uniqueSymbol1) {
|
if(m_uniqueSymbol == SearchManager::uniqueSymbolDir) {
|
||||||
m_searchResult->enqueue(ri);
|
m_searchResult->enqueue(ri);
|
||||||
SearchManager::m_mutex1.unlock();
|
SearchManager::m_mutexDir.unlock();
|
||||||
} else {
|
} else {
|
||||||
SearchManager::m_mutex1.unlock();
|
SearchManager::m_mutexDir.unlock();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (i.isFile() && m_value == FILE_SEARCH_VALUE) {
|
||||||
|
SearchPluginIface::ResultInfo ri;
|
||||||
|
if(SearchManager::creatResultInfo(ri,i.absoluteFilePath())) {
|
||||||
|
SearchManager::m_mutexFile.lock();
|
||||||
|
if(m_uniqueSymbol == SearchManager::uniqueSymbolFile) {
|
||||||
|
m_searchResult->enqueue(ri);
|
||||||
|
SearchManager::m_mutexFile.unlock();
|
||||||
|
} else {
|
||||||
|
SearchManager::m_mutexFile.unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,12 +57,12 @@ public:
|
||||||
|
|
||||||
static int getCurrentIndexCount();
|
static int getCurrentIndexCount();
|
||||||
|
|
||||||
static size_t uniqueSymbol1;
|
static size_t uniqueSymbolFile;
|
||||||
static size_t uniqueSymbol2;
|
static size_t uniqueSymbolDir;
|
||||||
static size_t uniqueSymbol3;
|
static size_t uniqueSymbolContent;
|
||||||
static QMutex m_mutex1;
|
static QMutex m_mutexFile;
|
||||||
static QMutex m_mutex2;
|
static QMutex m_mutexDir;
|
||||||
static QMutex m_mutex3;
|
static QMutex m_mutexContent;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void onKeywordSearch(QString keyword, QQueue<QString> *searchResultFile, QQueue<QString> *searchResultDir, QQueue<QPair<QString, QStringList>> *searchResultContent);
|
void onKeywordSearch(QString keyword, QQueue<QString> *searchResultFile, QQueue<QString> *searchResultDir, QQueue<QPair<QString, QStringList>> *searchResultContent);
|
||||||
|
|
|
@ -44,31 +44,31 @@ void SearchResult::run() {
|
||||||
int emptyLists = 0;
|
int emptyLists = 0;
|
||||||
while(!isInterruptionRequested()) {
|
while(!isInterruptionRequested()) {
|
||||||
emptyLists = 0;
|
emptyLists = 0;
|
||||||
m_mainwindow->m_searcher->m_mutex1.lock();
|
m_mainwindow->m_searcher->m_mutexFile.lock();
|
||||||
if(!m_mainwindow->m_search_result_file->isEmpty()) {
|
if(!m_mainwindow->m_search_result_file->isEmpty()) {
|
||||||
Q_EMIT this->searchResultFile(m_mainwindow->m_search_result_file->dequeue());
|
Q_EMIT this->searchResultFile(m_mainwindow->m_search_result_file->dequeue());
|
||||||
m_mainwindow->m_searcher->m_mutex1.unlock();
|
m_mainwindow->m_searcher->m_mutexFile.unlock();
|
||||||
} else {
|
} else {
|
||||||
emptyLists ++;
|
emptyLists ++;
|
||||||
m_mainwindow->m_searcher->m_mutex1.unlock();
|
m_mainwindow->m_searcher->m_mutexFile.unlock();
|
||||||
}
|
}
|
||||||
m_mainwindow->m_searcher->m_mutex2.lock();
|
m_mainwindow->m_searcher->m_mutexDir.lock();
|
||||||
if(!m_mainwindow->m_search_result_dir->isEmpty()) {
|
if(!m_mainwindow->m_search_result_dir->isEmpty()) {
|
||||||
Q_EMIT this->searchResultDir(m_mainwindow->m_search_result_dir->dequeue());
|
Q_EMIT this->searchResultDir(m_mainwindow->m_search_result_dir->dequeue());
|
||||||
m_mainwindow->m_searcher->m_mutex2.unlock();
|
m_mainwindow->m_searcher->m_mutexDir.unlock();
|
||||||
} else {
|
} else {
|
||||||
emptyLists ++;
|
emptyLists ++;
|
||||||
m_mainwindow->m_searcher->m_mutex2.unlock();
|
m_mainwindow->m_searcher->m_mutexDir.unlock();
|
||||||
}
|
}
|
||||||
m_mainwindow->m_searcher->m_mutex3.lock();
|
m_mainwindow->m_searcher->m_mutexContent.lock();
|
||||||
// if (!m_mainwindow->m_search_result_content->isEmpty())
|
// if (!m_mainwindow->m_search_result_content->isEmpty())
|
||||||
// qDebug() << m_mainwindow->m_search_result_content->head();
|
// qDebug() << m_mainwindow->m_search_result_content->head();
|
||||||
if(!m_mainwindow->m_search_result_content->isEmpty()) {
|
if(!m_mainwindow->m_search_result_content->isEmpty()) {
|
||||||
Q_EMIT this->searchResultContent(m_mainwindow->m_search_result_content->dequeue());
|
Q_EMIT this->searchResultContent(m_mainwindow->m_search_result_content->dequeue());
|
||||||
m_mainwindow->m_searcher->m_mutex3.unlock();
|
m_mainwindow->m_searcher->m_mutexContent.unlock();
|
||||||
} else {
|
} else {
|
||||||
emptyLists ++;
|
emptyLists ++;
|
||||||
m_mainwindow->m_searcher->m_mutex3.unlock();
|
m_mainwindow->m_searcher->m_mutexContent.unlock();
|
||||||
}
|
}
|
||||||
if(m_timer->isActive() && m_timer->remainingTime() < 0.01) {
|
if(m_timer->isActive() && m_timer->remainingTime() < 0.01) {
|
||||||
this->requestInterruption();
|
this->requestInterruption();
|
||||||
|
|
Loading…
Reference in New Issue