From 0e771323a6a98e65819eec3108bcb2a2ce050c2c Mon Sep 17 00:00:00 2001 From: sunfengsheng <327123947@qq.com> Date: Fri, 26 Feb 2021 11:21:41 +0800 Subject: [PATCH] Docking software store --- libsearch/appsearch/app-match.cpp | 164 ++++++++++++++++++++++++------ libsearch/appsearch/app-match.h | 26 ++++- 2 files changed, 156 insertions(+), 34 deletions(-) diff --git a/libsearch/appsearch/app-match.cpp b/libsearch/appsearch/app-match.cpp index 9e52edb..d75ff8d 100644 --- a/libsearch/appsearch/app-match.cpp +++ b/libsearch/appsearch/app-match.cpp @@ -21,30 +21,67 @@ #include #include "file-utils.h" AppMatch::AppMatch(QObject *parent) : QObject(parent) +// m_versionCommand(new QProcess(this)) { + this->getDesktopFilePath(); + qDBusRegisterMetaType>(); + qDBusRegisterMetaType>>(); + m_interFace=new QDBusInterface ("com.kylin.softwarecenter.getsearchresults", "/com/kylin/softwarecenter/getsearchresults", + "com.kylin.getsearchresults", + QDBusConnection::sessionBus()); + if (!m_interFace->isValid()) + { + qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message()); + } } QStringList AppMatch::startMatchApp(QString input){ input.replace(" ",""); m_sourceText=input; - m_returnResult.clear(); + m_softWareCenterMap.clear(); + m_matchInstallAppMap.clear(); + m_returnResult1.clear(); if(input.isEmpty()){ return m_returnResult; } - this->getAppName(); - m_returnResult=m_midResult; + softWareCenterSearch(); + getAppName(); + returnAppMap(); + m_returnResult1=m_midResult; m_midResult.clear(); -// qWarning()<<"m_returnResult :"<> AppMatch::startMatchApp(QString input,int i){ + input.replace(" ",""); + m_sourceText=input; + m_softWareCenterMap.clear(); + m_matchInstallAppMap.clear(); + m_returnResult1.clear(); + if(input.isEmpty()){ + return m_returnResult1; + } + softWareCenterSearch(); + getAppName(); + returnAppMap(); + m_returnResult1=m_midResult; + m_midResult.clear(); + qWarning()<<"m_returnResult :"<>::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); + } } /** @@ -197,27 +244,10 @@ void AppMatch::getDesktopFilePath() */ void AppMatch::getAppName() { - GKeyFileFlags flags=G_KEY_FILE_NONE; - GKeyFile* keyfile=g_key_file_new (); - - QByteArray fpbyte; - QString str; - char* filepath; - char* name; - QString namestr; - for(int i=0;i>::const_iterator i; + for(i=m_filterInstallAppMap.constBegin();i!=m_filterInstallAppMap.constEnd();++i){ + appNameMatch(i.key()); + } } /** @@ -228,20 +258,90 @@ void AppMatch::getAppName() * @param desktoppath * desktop路径 */ -void AppMatch::appNameMatch(QString appname,QString desktoppath){ +void AppMatch::appNameMatch(QString appname){ if(appname.contains(m_sourceText,Qt::CaseInsensitive)){ - m_midResult.append(desktoppath); + m_matchInstallAppMap.insert(appname,m_filterInstallAppMap.value(appname)); return; } QString shouzimu=FileUtils::findMultiToneWords(appname).at(1);// 中文转首字母 if(shouzimu.contains(m_sourceText,Qt::CaseInsensitive)){ - m_midResult.append(desktoppath); + m_matchInstallAppMap.insert(appname,m_filterInstallAppMap.value(appname)); return; } if(m_sourceText.size()<2) return; QString pinyin=FileUtils::findMultiToneWords(appname).at(0);// 中文转拼音 if(pinyin.contains(m_sourceText,Qt::CaseInsensitive)){ - m_midResult.append(desktoppath); + m_matchInstallAppMap.insert(appname,m_filterInstallAppMap.value(appname)); } } + +void AppMatch::softWareCenterSearch(){ + // 调用D-Bus接口的方法 +// QDBusPendingCall pcall = m_interFace->asyncCall("get_search_result", m_sourceText); + // 设置等待异步消息的信号槽 +// QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(pcall, nullptr); +// QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &AppMatch::slotDBusCallFinished); + slotDBusCallFinished(); +} + +void AppMatch::slotDBusCallFinished() +{ + QDBusReply>> reply = m_interFace->call("get_search_result",m_sourceText); //阻塞,直到远程方法调用完成。 +// QDBusPendingReply>> reply = *call; + if (reply.isValid()) + { + parseSoftWareCenterReturn(reply.value()); + } + else + { + qWarning() << "value method called failed!"; + } +// call->deleteLater(); +} + +void AppMatch::parseSoftWareCenterReturn(QList> list){ +// qWarning()<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()<close(); +} + +void AppMatch::returnAppMap(){ + QMap>::const_iterator i; + for(i=m_matchInstallAppMap.constBegin();i!=m_matchInstallAppMap.constEnd();++i){ + m_midResult.insert(i.key(),i.value()); + } + QMap>::const_iterator j; + for(j=m_softWareCenterMap.constBegin();j!=m_softWareCenterMap.constEnd();++j){ + m_midResult.insert(j.key(),j.value()); + } +} + diff --git a/libsearch/appsearch/app-match.h b/libsearch/appsearch/app-match.h index 62bf7ca..56b520f 100644 --- a/libsearch/appsearch/app-match.h +++ b/libsearch/appsearch/app-match.h @@ -24,24 +24,46 @@ #include #include #include +#include +#include +#include +#include + class AppMatch : public QObject { Q_OBJECT public: explicit AppMatch(QObject *parent = nullptr); QStringList startMatchApp(QString input); + QMap> startMatchApp(QString input,int i); private: void getAllDesktopFilePath(QString path); void getDesktopFilePath(); void getAppName(); - void appNameMatch(QString appname,QString desktoppath); +// void appNameMatch(QString appname,QString desktoppath,QString appicon); + void appNameMatch(QString appname); + void softWareCenterSearch(); + void parseSoftWareCenterReturn(QList> list); + void getInstalledAppsVersion(QString appname); + void returnAppMap(); private: QString m_sourceText; QStringList m_filePathList; QStringList m_returnResult; - QStringList m_midResult; + + QDBusInterface *m_interFace; + QMap> m_softWareCenterMap; + QMap> m_installAppMap; + QMap> m_filterInstallAppMap; + QMap> m_matchInstallAppMap; + QMap> m_returnResult1; + QMap> m_midResult; +// QProcess *m_versionCommand; + +private Q_SLOTS: + void slotDBusCallFinished(); };