From dae035d35b94d8bd8679e8f1aab50fc1ac2efe81 Mon Sep 17 00:00:00 2001 From: JunjieBai Date: Thu, 4 Jan 2024 17:16:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(ApplicationInfo):=E5=A4=9A=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E4=BD=BF=E7=94=A8=E6=95=B0=E6=8D=AE=E5=BA=93=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=9F=A5=E8=AF=A2=E6=97=B6=E4=BC=9A=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libsearch/appdata/app-info-table-private.h | 4 +- libsearch/appdata/app-info-table.cpp | 16 +--- libsearch/appdata/app-info-table.h | 19 ++-- libsearch/appdata/application-info.cpp | 106 ++++++++------------- libsearch/appdata/application-info.h | 3 +- 5 files changed, 56 insertions(+), 92 deletions(-) diff --git a/libsearch/appdata/app-info-table-private.h b/libsearch/appdata/app-info-table-private.h index f74ead9..1043c2d 100644 --- a/libsearch/appdata/app-info-table-private.h +++ b/libsearch/appdata/app-info-table-private.h @@ -49,7 +49,7 @@ public: //数据库错误信息 - QString lastError(void) const; + QString lastError() const; //通过pid查找desktop文件 bool tranPidToDesktopFp(uint pid, QString &desktopfp); @@ -75,7 +75,7 @@ private: QString m_ConnectionName; public Q_SLOTS: - void sendAppDBItemsUpdate(ApplicationInfoMap results); + void sendAppDBItemsUpdate(UkuiSearch::ApplicationInfoMap results); void sendAppDBItemsUpdateAll(QStringList desktopFilePaths); void sendAppDBItemsAdd(QStringList desktopFilePaths); void sendAppDBItemsDelete(QStringList desktopFilePaths); diff --git a/libsearch/appdata/app-info-table.cpp b/libsearch/appdata/app-info-table.cpp index b53ed4e..0a8bd78 100644 --- a/libsearch/appdata/app-info-table.cpp +++ b/libsearch/appdata/app-info-table.cpp @@ -130,7 +130,7 @@ bool AppInfoTablePrivate::searchInstallApp(QString &keyWord, QStringList &instal bool AppInfoTablePrivate::searchInstallApp(QStringList &keyWord, QStringList &installAppInfoRes) { bool res(true); - if (m_database->transaction() or keyWord.size() != 0) { + if (m_database->transaction() or !keyWord.isEmpty()) { QSqlQuery sql(*m_database); QString cmd; if (keyWord.at(0).size() < 2) { @@ -362,19 +362,11 @@ void AppInfoTablePrivate::sendAppDBItemsDelete(QStringList desktopFilePaths) Q_EMIT q->appDBItems2BDelete(desktopFilePaths); } -AppInfoTable *AppInfoTable::self() -{ - std::call_once(flag, [ & ] { - global_intance = new AppInfoTable(); - }); - return global_intance; -} - AppInfoTable::AppInfoTable(QObject *parent) : QObject(parent), d(new AppInfoTablePrivate(this)) { } -bool AppInfoTable::query(ApplicationPropertyMap &propertyMap, const QString &desktopFile, ApplicationProperties properties) +bool AppInfoTable::query(ApplicationPropertyMap &propertyMap, const QString &desktopFile, const ApplicationProperties& properties) { QString field; for(const ApplicationProperty::Property &pro : properties) { @@ -400,7 +392,7 @@ bool AppInfoTable::query(ApplicationPropertyMap &propertyMap, const QString &des return true; } -bool AppInfoTable::query(ApplicationInfoMap &infoMap, ApplicationProperties properties) +bool AppInfoTable::query(ApplicationInfoMap &infoMap, const ApplicationProperties& properties) { QString field; for(const ApplicationProperty::Property &pro : properties) { @@ -431,7 +423,7 @@ bool AppInfoTable::query(ApplicationInfoMap &infoMap, ApplicationProperties prop return true; } -bool AppInfoTable::query(ApplicationInfoMap &infoMap, ApplicationProperties properties, ApplicationPropertyMap restrictions) +bool AppInfoTable::query(ApplicationInfoMap &infoMap, const ApplicationProperties& properties, const ApplicationPropertyMap& restrictions) { QString field; for(const ApplicationProperty::Property &pro : properties) { diff --git a/libsearch/appdata/app-info-table.h b/libsearch/appdata/app-info-table.h index b32bcc5..e4b168f 100644 --- a/libsearch/appdata/app-info-table.h +++ b/libsearch/appdata/app-info-table.h @@ -35,14 +35,11 @@ class AppInfoTable : public QObject { Q_OBJECT public: - static AppInfoTable* self(); + explicit AppInfoTable(QObject *parent = nullptr); - AppInfoTable(AppInfoTable &) = delete; - AppInfoTable &operator =(const AppInfoTable &) = delete; - - bool query(ApplicationPropertyMap &propertyMap, const QString &desktopFile, ApplicationProperties properties); - bool query(ApplicationInfoMap &infoMap, ApplicationProperties properties); - bool query(ApplicationInfoMap &infoMap, ApplicationProperties properties, ApplicationPropertyMap restrictions); + bool query(ApplicationPropertyMap &propertyMap, const QString &desktopFile, const ApplicationProperties& properties); + bool query(ApplicationInfoMap &infoMap, const ApplicationProperties& properties); + bool query(ApplicationInfoMap &infoMap, const ApplicationProperties& properties, const ApplicationPropertyMap& restrictions); bool query(ApplicationInfoMap &infoMap, const ApplicationProperties& properties, const QStringList &keywords, const ApplicationPropertyMap& restrictions); /** @@ -77,16 +74,13 @@ public: void setAppLaunchedState(const QString &desktopFilePath, bool launched); - bool searchInstallApp(QString &keyWord, QStringList &installAppInfoRes); - bool searchInstallApp(QStringList &keyWord, QStringList &installAppInfoRes); - /** * @brief AppInfoTable::lastError * the last error of the database * @return QString: the text of the last error */ - QString lastError(void) const; + QString lastError() const; /** * @brief AppInfoTable::tranPid2DesktopFp @@ -106,9 +100,10 @@ private: bool setAppLaunchTimes(const QString &desktopfp, size_t num); bool setAppLockState(const QString &desktopfp, size_t num); bool updateAppLaunchTimes(const QString &desktopfp); + bool searchInstallApp(QString &keyWord, QStringList &installAppInfoRes); + bool searchInstallApp(QStringList &keyWord, QStringList &installAppInfoRes); private: - explicit AppInfoTable(QObject *parent = nullptr); AppInfoTablePrivate *d; Q_SIGNALS: diff --git a/libsearch/appdata/application-info.cpp b/libsearch/appdata/application-info.cpp index dd1eeec..4fac264 100644 --- a/libsearch/appdata/application-info.cpp +++ b/libsearch/appdata/application-info.cpp @@ -1,113 +1,91 @@ #include "application-info.h" #include "app-info-table.h" -#include "application-property-helper.h" + using namespace UkuiSearch; namespace UkuiSearch { -class ApplicationInfoPrivate +class ApplicationInfoPrivate : public QObject { +public: + explicit ApplicationInfoPrivate(ApplicationInfo *parent = nullptr) : QObject(parent), m_infoTable(new AppInfoTable(this)) {} + AppInfoTable *m_infoTable = nullptr; }; } -ApplicationInfo::ApplicationInfo(QObject *parent) - : QObject(parent), d(new ApplicationInfoPrivate) -{ - connect(AppInfoTable::self(), &AppInfoTable::appDBItems2BUpdate, this, &ApplicationInfo::appDBItems2BUpdate); - connect(AppInfoTable::self(), &AppInfoTable::appDBItems2BUpdateAll, this, &ApplicationInfo::appDBItems2BUpdateAll); - connect(AppInfoTable::self(), &AppInfoTable::appDBItems2BAdd, this, &ApplicationInfo::appDBItems2BAdd); - connect(AppInfoTable::self(), &AppInfoTable::appDBItems2BDelete, this, &ApplicationInfo::appDBItems2BDelete); + +ApplicationInfo::ApplicationInfo(QObject *parent) : QObject(parent), d(new ApplicationInfoPrivate(this)) { + connect(d->m_infoTable, &AppInfoTable::appDBItems2BUpdate, this, &ApplicationInfo::appDBItems2BUpdate); + connect(d->m_infoTable, &AppInfoTable::appDBItems2BUpdateAll, this, &ApplicationInfo::appDBItems2BUpdateAll); + connect(d->m_infoTable, &AppInfoTable::appDBItems2BAdd, this, &ApplicationInfo::appDBItems2BAdd); + connect(d->m_infoTable, &AppInfoTable::appDBItems2BDelete, this, &ApplicationInfo::appDBItems2BDelete); } -ApplicationInfo::~ApplicationInfo() -{ - if(d) { - delete d; - d = nullptr; - } -} - -QVariant UkuiSearch::ApplicationInfo::getInfo(const QString &desktopFile, ApplicationProperty::Property property) -{ +QVariant ApplicationInfo::getInfo(const QString &desktopFile, ApplicationProperty::Property property) { ApplicationPropertyMap map; - AppInfoTable::self()->query(map, desktopFile, ApplicationProperties{property}); + d->m_infoTable->query(map, desktopFile, ApplicationProperties{property}); return map.value(property); } -ApplicationPropertyMap ApplicationInfo::getInfo(const QString &desktopFile, ApplicationProperties properties) -{ +ApplicationPropertyMap ApplicationInfo::getInfo(const QString& desktopFile, ApplicationProperties properties) { ApplicationPropertyMap propertyMap; - AppInfoTable::self()->query(propertyMap, desktopFile, properties); + d->m_infoTable->query(propertyMap, desktopFile, properties); return propertyMap; } -ApplicationInfoMap ApplicationInfo::getInfo(ApplicationProperties properties) -{ +ApplicationInfoMap ApplicationInfo::getInfo(ApplicationProperties properties) { ApplicationInfoMap infoMap; - AppInfoTable::self()->query(infoMap, properties); + d->m_infoTable->query(infoMap, properties); return infoMap; } -ApplicationInfoMap ApplicationInfo::getInfo(ApplicationProperties properties, ApplicationPropertyMap restrictions) -{ +ApplicationInfoMap ApplicationInfo::getInfo(ApplicationProperties properties, ApplicationPropertyMap restrictions) { ApplicationInfoMap infoMap; - AppInfoTable::self()->query(infoMap, properties, restrictions); + d->m_infoTable->query(infoMap, properties, restrictions); return infoMap; } - -ApplicationInfoMap ApplicationInfo::searchApp(ApplicationProperties properties, const QString &keyword, ApplicationPropertyMap restrictions) -{ +ApplicationInfoMap ApplicationInfo::searchApp(ApplicationProperties properties, const QString &keyword, ApplicationPropertyMap restrictions) { ApplicationInfoMap infoMap; - AppInfoTable::self()->query(infoMap, properties, QStringList{keyword}, restrictions); + d->m_infoTable->query(infoMap, properties, QStringList{keyword}, restrictions); return infoMap; } -ApplicationInfoMap ApplicationInfo::searchApp(ApplicationProperties properties, const QStringList &keywords, ApplicationPropertyMap restrictions) -{ +ApplicationInfoMap ApplicationInfo::searchApp(ApplicationProperties properties, const QStringList &keywords, ApplicationPropertyMap restrictions) { ApplicationInfoMap infoMap; - AppInfoTable::self()->query(infoMap, properties, keywords, restrictions); + d->m_infoTable->query(infoMap, properties, keywords, restrictions); return infoMap; } -void ApplicationInfo::setAppToFavorites(const QString &desktopFilePath) -{ - AppInfoTable::self()->setAppFavoritesState(desktopFilePath); +void ApplicationInfo::setAppToFavorites(const QString &desktopFilePath) { + return d->m_infoTable->setAppFavoritesState(desktopFilePath); } -void ApplicationInfo::setFavoritesOfApp(const QString &desktopFilePath, size_t num) -{ - AppInfoTable::self()->setAppFavoritesState(desktopFilePath, num); +void ApplicationInfo::setFavoritesOfApp(const QString &desktopFilePath, size_t num) { + return d->m_infoTable->setAppFavoritesState(desktopFilePath, num); } -void ApplicationInfo::setAppToTop(const QString &desktopFilePath) -{ - AppInfoTable::self()->setAppTopState(desktopFilePath); +void ApplicationInfo::setAppToTop(const QString &desktopFilePath) { + return d->m_infoTable->setAppTopState(desktopFilePath); } -void ApplicationInfo::setTopOfApp(const QString &desktopFilePath, size_t num) -{ - AppInfoTable::self()->setAppTopState(desktopFilePath, num); +void ApplicationInfo::setTopOfApp(const QString &desktopFilePath, size_t num) { + return d->m_infoTable->setAppTopState(desktopFilePath, num); } -void ApplicationInfo::setAppLaunchedState(const QString &desktopFilePath, bool launched) -{ - AppInfoTable::self()->setAppLaunchedState(desktopFilePath, launched); +void ApplicationInfo::setAppLaunchedState(const QString &desktopFilePath, bool launched) { + return d->m_infoTable->setAppLaunchedState(desktopFilePath, launched); } -bool ApplicationInfo::tranPidToDesktopFp(int pid, QString &desktopFilePath) -{ - return AppInfoTable::self()->tranPidToDesktopFp(pid, desktopFilePath); +bool ApplicationInfo::tranPidToDesktopFp(int pid, QString &desktopFilePath) { + return d->m_infoTable->tranPidToDesktopFp(pid, desktopFilePath); } -bool ApplicationInfo::tranPidToDesktopFp(uint pid, QString &desktopFilePath) -{ - return AppInfoTable::self()->tranPidToDesktopFp(pid, desktopFilePath); +bool ApplicationInfo::tranPidToDesktopFp(uint pid, QString &desktopFilePath) { + return d->m_infoTable->tranPidToDesktopFp(pid, desktopFilePath); } -bool ApplicationInfo::desktopFilePathFromName(const QString &desktopFileName, QString &desktopFilePath) -{ - return AppInfoTable::self()->desktopFilePathFromName(desktopFileName, desktopFilePath); +bool ApplicationInfo::desktopFilePathFromName(const QString &desktopFileName, QString &desktopFilePath) { + return d->m_infoTable->desktopFilePathFromName(desktopFileName, desktopFilePath); } -bool ApplicationInfo::tranWinIdToDesktopFilePath(const QVariant &winId, QString &desktopFilePath) -{ - return AppInfoTable::self()->tranWinIdToDesktopFilePath(winId, desktopFilePath); -} +bool ApplicationInfo::tranWinIdToDesktopFilePath(const QVariant &winId, QString &desktopFilePath) { + return d->m_infoTable->tranWinIdToDesktopFilePath(winId, desktopFilePath); +} \ No newline at end of file diff --git a/libsearch/appdata/application-info.h b/libsearch/appdata/application-info.h index 393ae11..15642a4 100644 --- a/libsearch/appdata/application-info.h +++ b/libsearch/appdata/application-info.h @@ -30,7 +30,7 @@ class ApplicationInfo : public QObject Q_OBJECT public: explicit ApplicationInfo(QObject *parent = nullptr); - ~ApplicationInfo(); + ~ApplicationInfo() = default; /** * @brief getInfo 查询单个应用的单个属性 * @param desktopFile @@ -140,7 +140,6 @@ Q_SIGNALS: private: ApplicationInfoPrivate *d = nullptr; - }; }