Optimized app search.

This commit is contained in:
iaom 2021-09-14 10:22:18 +08:00
parent c94f70e042
commit ac8013e047
2 changed files with 53 additions and 110 deletions

View File

@ -100,7 +100,7 @@ void AppMatch::getAllDesktopFilePath(QString path) {
qDebug() << fileInfo.filePath(); qDebug() << fileInfo.filePath();
} else { } else {
QString filePathStr = fileInfo.filePath(); QString filePathStr = fileInfo.filePath();
if(m_filePathList.contains(filePathStr)) { if(m_ExcludedDesktopfiles.contains(filePathStr)) {
++i; ++i;
continue; continue;
} }
@ -135,80 +135,9 @@ void AppMatch::getAllDesktopFilePath(QString path) {
m_installAppMap.insert(appname, appInfolist); m_installAppMap.insert(appname, appInfolist);
++i; ++i;
} }
} }
} }
/**
* @brief AppMatch::getDesktopFilePath
*
*/
void AppMatch::getDesktopFilePath() {
m_filePathList.clear();
m_installAppMap.clear();
m_filePathList.append("/usr/share/applications/software-properties-livepatch.desktop");
m_filePathList.append("/usr/share/applications/mate-color-select.desktop");
m_filePathList.append("/usr/share/applications/blueman-adapters.desktop");
m_filePathList.append("/usr/share/applications/blueman-manager.desktop");
m_filePathList.append("/usr/share/applications/mate-user-guide.desktop");
m_filePathList.append("/usr/share/applications/nm-connection-editor.desktop");
m_filePathList.append("/usr/share/applications/debian-uxterm.desktop");
m_filePathList.append("/usr/share/applications/debian-xterm.desktop");
m_filePathList.append("/usr/share/applications/im-config.desktop");
m_filePathList.append("/usr/share/applications/fcitx.desktop");
m_filePathList.append("/usr/share/applications/fcitx-configtool.desktop");
m_filePathList.append("/usr/share/applications/onboard-settings.desktop");
m_filePathList.append("/usr/share/applications/info.desktop");
m_filePathList.append("/usr/share/applications/ukui-power-preferences.desktop");
m_filePathList.append("/usr/share/applications/ukui-power-statistics.desktop");
m_filePathList.append("/usr/share/applications/software-properties-drivers.desktop");
m_filePathList.append("/usr/share/applications/software-properties-gtk.desktop");
m_filePathList.append("/usr/share/applications/gnome-session-properties.desktop");
m_filePathList.append("/usr/share/applications/org.gnome.font-viewer.desktop");
m_filePathList.append("/usr/share/applications/xdiagnose.desktop");
m_filePathList.append("/usr/share/applications/gnome-language-selector.desktop");
m_filePathList.append("/usr/share/applications/mate-notification-properties.desktop");
m_filePathList.append("/usr/share/applications/transmission-gtk.desktop");
m_filePathList.append("/usr/share/applications/mpv.desktop");
m_filePathList.append("/usr/share/applications/system-config-printer.desktop");
m_filePathList.append("/usr/share/applications/org.gnome.DejaDup.desktop");
m_filePathList.append("/usr/share/applications/yelp.desktop");
m_filePathList.append("/usr/share/applications/peony-computer.desktop");
m_filePathList.append("/usr/share/applications/peony-home.desktop");
m_filePathList.append("/usr/share/applications/peony-trash.desktop");
// m_filePathList.append("/usr/share/applications/peony.desktop");
//v10
m_filePathList.append("/usr/share/applications/mate-about.desktop");
m_filePathList.append("/usr/share/applications/time.desktop");
m_filePathList.append("/usr/share/applications/network.desktop");
m_filePathList.append("/usr/share/applications/shares.desktop");
m_filePathList.append("/usr/share/applications/mate-power-statistics.desktop");
m_filePathList.append("/usr/share/applications/display-im6.desktop");
m_filePathList.append("/usr/share/applications/display-im6.q16.desktop");
m_filePathList.append("/usr/share/applications/openjdk-8-policytool.desktop");
m_filePathList.append("/usr/share/applications/kylin-io-monitor.desktop");
m_filePathList.append("/usr/share/applications/wps-office-uninstall.desktop");
// QString desktop;
// QStringList applist;
// QMap<QString, QList<QString>>::const_iterator i;
// for(i=m_installAppMap.constBegin();i!=m_installAppMap.constEnd();++i){
// applist=i.value();
// if(m_filePathList.contains(applist.at(0)))
// m_filterInstallAppMap.insert(i.key(),applist);
// }
}
void AppMatch::getAppName(QMap<NameString, QStringList> &installed) {
// QMap<NameString, QStringList>::const_iterator i;
// for(i = m_installAppMap.constBegin(); i != m_installAppMap.constEnd(); ++i) {
// appNameMatch(i.key().app_name, installed);
// }
// appNameMatch(installed);
// qDebug() << "installed app match is successful!";
}
/** /**
* @brief AppMatch::appNameMatch * @brief AppMatch::appNameMatch
* *
@ -342,26 +271,6 @@ void AppMatch::parseSoftWareCenterReturn(QList<QMap<QString, QString>> list, siz
} }
} }
void AppMatch::getInstalledAppsVersion(QString appname) {
// qWarning()<<"apt show "+appname;
// m_versionCommand->start("apt show "+appname);
// m_versionCommand->startDetached(m_versionCommand->program());
// m_versionCommand->waitForFinished();
// connect(m_versionCommand,&QProcess::readyReadStandardOutput,this,[=](){
// QString result=m_versionCommand->readAllStandardOutput();
// if(!result.isEmpty()){
// QStringList strlist=result.split("\n");
// QString str=strlist.at(1);
// if(!str.contains("Version")){
// return;
// }
// qWarning()<<strlist.at(1);
// qWarning()<<"-----------------------------------------------";
// }
// });
// m_versionCommand->close();
}
void AppMatch::creatResultInfo(SearchPluginIface::ResultInfo &ri, QMapIterator<NameString, QStringList> &iter, bool isInstalled) void AppMatch::creatResultInfo(SearchPluginIface::ResultInfo &ri, QMapIterator<NameString, QStringList> &iter, bool isInstalled)
{ {
// ri.icon = QIcon::fromTheme(iter.value().at(1), QIcon(":/res/icons/desktop.png")); // ri.icon = QIcon::fromTheme(iter.value().at(1), QIcon(":/res/icons/desktop.png"));
@ -372,16 +281,14 @@ void AppMatch::creatResultInfo(SearchPluginIface::ResultInfo &ri, QMapIterator<N
} }
void AppMatch::run() { void AppMatch::run() {
qDebug() << "AppMatch running.."; qDebug() << "App map init..";
this->getDesktopFilePath();
this->getAllDesktopFilePath("/usr/share/applications/"); this->getAllDesktopFilePath("/usr/share/applications/");
this->getAllDesktopFilePath(ANDROID_APP_DESKTOP_PATH); this->getAllDesktopFilePath(ANDROID_APP_DESKTOP_PATH);
connect(m_watchAppDir, &QFileSystemWatcher::directoryChanged, this, [ = ](const QString & path) { connect(m_watchAppDir, &QFileSystemWatcher::directoryChanged, this, [ = ](const QString & path) {
if(path == "/usr/share/applications/") { m_installAppMap.clear();
this->getAllDesktopFilePath("/usr/share/applications/"); this->getAllDesktopFilePath("/usr/share/applications/");
} else if(path == ANDROID_APP_DESKTOP_PATH) {
this->getAllDesktopFilePath(ANDROID_APP_DESKTOP_PATH); this->getAllDesktopFilePath(ANDROID_APP_DESKTOP_PATH);
} qDebug() << "App map update " << m_installAppMap.size();
}); });
qDebug() << "AppMatch finish.."; qDebug() << "App map init finished.." << m_installAppMap.size();
} }

View File

@ -38,6 +38,9 @@ public:
bool operator<(const NameString& name) const { bool operator<(const NameString& name) const {
return this->app_name.length() <= name.app_name.length(); return this->app_name.length() <= name.app_name.length();
} }
bool operator==(const NameString& name) const {
return this->app_name == name.app_name;
}
}; };
//struct NameString //struct NameString
@ -64,32 +67,65 @@ private:
explicit AppMatch(QObject *parent = nullptr); explicit AppMatch(QObject *parent = nullptr);
~AppMatch(); ~AppMatch();
void getAllDesktopFilePath(QString path); void getAllDesktopFilePath(QString path);
void getDesktopFilePath();
void getAppName(QMap<NameString, QStringList> &installed);
// void appNameMatch(QString appname,QString desktoppath,QString appicon);
// void appNameMatch(QString keyWord, QString appname, QMap<NameString, QStringList> &installed);
void appNameMatch(QString keyWord, size_t uniqueSymbol, DataQueue<SearchPluginIface::ResultInfo> *searchResult); void appNameMatch(QString keyWord, size_t uniqueSymbol, DataQueue<SearchPluginIface::ResultInfo> *searchResult);
void softWareCenterSearch(QMap<NameString, QStringList> &softwarereturn); void softWareCenterSearch(QMap<NameString, QStringList> &softwarereturn);
void parseSoftWareCenterReturn(QList<QMap<QString, QString>> list, size_t uniqueSymbol, DataQueue<SearchPluginIface::ResultInfo> *searchResult); void parseSoftWareCenterReturn(QList<QMap<QString, QString>> list, size_t uniqueSymbol, DataQueue<SearchPluginIface::ResultInfo> *searchResult);
void getInstalledAppsVersion(QString appname);
void creatResultInfo(SearchPluginIface::ResultInfo &ri, QMapIterator<NameString, QStringList> &iter, bool isInstalled = true); void creatResultInfo(SearchPluginIface::ResultInfo &ri, QMapIterator<NameString, QStringList> &iter, bool isInstalled = true);
QString m_sourceText; QString m_sourceText;
size_t m_uniqueSymbol; size_t m_uniqueSymbol;
DataQueue<SearchPluginIface::ResultInfo> *m_search_result = nullptr; DataQueue<SearchPluginIface::ResultInfo> *m_search_result = nullptr;
QStringList m_filePathList;
QDBusInterface *m_interFace = nullptr; QDBusInterface *m_interFace = nullptr;
QFileSystemWatcher *m_watchAppDir = nullptr; QFileSystemWatcher *m_watchAppDir = nullptr;
QMap<NameString, QStringList> m_installAppMap; QMap<NameString, QStringList> m_installAppMap;
QStringList m_ExcludedDesktopfiles = {
"/usr/share/applications/software-properties-livepatch.desktop",
"/usr/share/applications/mate-color-select.desktop",
"/usr/share/applications/blueman-adapters.desktop",
"/usr/share/applications/blueman-manager.desktop",
"/usr/share/applications/mate-user-guide.desktop",
"/usr/share/applications/nm-connection-editor.desktop",
"/usr/share/applications/debian-uxterm.desktop",
"/usr/share/applications/debian-xterm.desktop",
"/usr/share/applications/im-config.desktop",
"/usr/share/applications/fcitx.desktop",
"/usr/share/applications/fcitx-configtool.desktop",
"/usr/share/applications/onboard-settings.desktop",
"/usr/share/applications/info.desktop",
"/usr/share/applications/ukui-power-preferences.desktop",
"/usr/share/applications/ukui-power-statistics.desktop",
"/usr/share/applications/software-properties-drivers.desktop",
"/usr/share/applications/software-properties-gtk.desktop",
"/usr/share/applications/gnome-session-properties.desktop",
"/usr/share/applications/org.gnome.font-viewer.desktop",
"/usr/share/applications/xdiagnose.desktop",
"/usr/share/applications/gnome-language-selector.desktop",
"/usr/share/applications/mate-notification-properties.desktop",
"/usr/share/applications/transmission-gtk.desktop",
"/usr/share/applications/mpv.desktop",
"/usr/share/applications/system-config-printer.desktop",
"/usr/share/applications/org.gnome.DejaDup.desktop",
"/usr/share/applications/yelp.desktop",
"/usr/share/applications/peony-computer.desktop",
"/usr/share/applications/peony-home.desktop",
"/usr/share/applications/peony-trash.desktop",
//v10
"/usr/share/applications/mate-about.desktop",
"/usr/share/applications/time.desktop",
"/usr/share/applications/network.desktop",
"/usr/share/applications/shares.desktop",
"/usr/share/applications/mate-power-statistics.desktop",
"/usr/share/applications/display-im6.desktop",
"/usr/share/applications/display-im6.q16.desktop",
"/usr/share/applications/openjdk-8-policytool.desktop",
"/usr/share/applications/kylin-io-monitor.desktop",
"/usr/share/applications/wps-office-uninstall.desktop",
};
private Q_SLOTS: private Q_SLOTS:
void slotDBusCallFinished(QString keyWord, size_t uniqueSymbol, DataQueue<SearchPluginIface::ResultInfo> *searchResult); void slotDBusCallFinished(QString keyWord, size_t uniqueSymbol, DataQueue<SearchPluginIface::ResultInfo> *searchResult);
//Q_SIGNALS:
}; };
} }