Update app search.

This commit is contained in:
iaom 2021-08-26 19:59:31 +08:00
parent 96cc2b3bd0
commit d48fe5e52e
1 changed files with 46 additions and 16 deletions

View File

@ -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())
this->getAllDesktopFilePath(QDir::homePath() + "/.local/share/applications/");
connect(m_watchAppDir, &QFileSystemWatcher::directoryChanged, this, [ = ](const QString & path) { 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/");
}
} }
}); });
} }