From c77c00b4c94c85f131950df62ec11dd8898f1d57 Mon Sep 17 00:00:00 2001 From: gjq Date: Tue, 21 Mar 2023 14:31:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=90=9C=E7=B4=A2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/appdata/app-data-manager.cpp | 218 +++++++++++------- src/appdata/app-data-manager.h | 2 +- src/appdata/plugin/app-search-plugin.cpp | 21 +- .../extensions/favorite-extension.cpp | 6 +- 4 files changed, 151 insertions(+), 96 deletions(-) diff --git a/src/appdata/app-data-manager.cpp b/src/appdata/app-data-manager.cpp index 9ca2436..88627e7 100644 --- a/src/appdata/app-data-manager.cpp +++ b/src/appdata/app-data-manager.cpp @@ -18,7 +18,7 @@ #include "app-data-manager.h" -#include +#include #define APP_ICON_PREFIX "image://appicon/" @@ -39,44 +39,59 @@ Q_SIGNALS: private Q_SLOTS: void initAppData(); - void onAppAdded(const QVector &infos); - void onAppUpdated(QVector infos); + void onAppAdded(const QStringList &infos); + void onAppUpdated(const UkuiSearch::ApplicationInfoMap &infos); + void onAppUpdatedAll(const QStringList &infos); void onAppDeleted(QStringList infos); private: void updateFavoriteApps(); void removeApps(QStringList& appIdList, QStringList &removedIdList); - void updateApps(QVector &infos, QList &apps); - void appendApps(const QVector &infos, QList &apps); + void updateApps(const UkuiSearch::ApplicationInfoMap &infos, QList &apps); + void updateAppsAll(const QStringList &infos, QList &apps); + void appendApps(const QStringList &infos, QList &apps); + void addInfoToApp(const UkuiSearch::ApplicationPropertyMap &info, DataEntity &app); private: AppDataManager *m_appManager{nullptr}; - UkuiSearch::AppInfoTable *m_appInfoTable{nullptr}; + UkuiSearch::ApplicationInfo *m_applicationInfo{nullptr}; + UkuiSearch::ApplicationProperties m_appProperties; + UkuiSearch::ApplicationPropertyMap m_appPropertyMap; }; AppDataWorker::AppDataWorker(AppDataManager *appManager) : QObject(nullptr), m_appManager(appManager) { qRegisterMetaType >("QList"); qRegisterMetaType >("QVector"); - m_appInfoTable = new UkuiSearch::AppInfoTable(this); - if (!m_appInfoTable || !m_appManager) { + m_applicationInfo = new UkuiSearch::ApplicationInfo(this); + if (!m_applicationInfo || !m_appManager) { return; } initAppData(); - connect(m_appInfoTable, &UkuiSearch::AppInfoTable::appDBItems2BAdd, this, &AppDataWorker::onAppAdded); - connect(m_appInfoTable, &UkuiSearch::AppInfoTable::appDBItems2BUpdate, this, &AppDataWorker::onAppUpdated); - connect(m_appInfoTable, &UkuiSearch::AppInfoTable::appDBItems2BDelete, this, &AppDataWorker::onAppDeleted); - connect(m_appInfoTable, &UkuiSearch::AppInfoTable::DBOpenFailed, this, &AppDataWorker::appDataBaseOpenFailed); + connect(m_applicationInfo, &UkuiSearch::ApplicationInfo::appDBItems2BAdd, this, &AppDataWorker::onAppAdded); + connect(m_applicationInfo, &UkuiSearch::ApplicationInfo::appDBItems2BUpdate, this, &AppDataWorker::onAppUpdated); + connect(m_applicationInfo, &UkuiSearch::ApplicationInfo::appDBItems2BUpdateAll, this, &AppDataWorker::onAppUpdatedAll); + connect(m_applicationInfo, &UkuiSearch::ApplicationInfo::appDBItems2BDelete, this, &AppDataWorker::onAppDeleted); + connect(m_applicationInfo, &UkuiSearch::ApplicationInfo::DBOpenFailed, this, &AppDataWorker::appDataBaseOpenFailed); } void AppDataWorker::initAppData() { - QVector appInfos; - if (!m_appInfoTable->getAppInfoResults(appInfos)) { - return; - } + m_appProperties << UkuiSearch::ApplicationProperty::Property::Top + << UkuiSearch::ApplicationProperty::Property::Lock + << UkuiSearch::ApplicationProperty::Property::Favorites + << UkuiSearch::ApplicationProperty::Property::LaunchTimes + << UkuiSearch::ApplicationProperty::Property::DesktopFilePath + << UkuiSearch::ApplicationProperty::Property::Icon + << UkuiSearch::ApplicationProperty::Property::LocalName + << UkuiSearch::ApplicationProperty::Property::Category + << UkuiSearch::ApplicationProperty::Property::FirstLetterAll + << UkuiSearch::ApplicationProperty::Property::DontDisplay; + m_appPropertyMap.insert(UkuiSearch::ApplicationProperty::Property::DontDisplay, 0); + + UkuiSearch::ApplicationInfoMap appInfos = m_applicationInfo->getInfo(m_appProperties, m_appPropertyMap); if (appInfos.isEmpty()) { return; @@ -84,20 +99,9 @@ void AppDataWorker::initAppData() for (const auto &info : appInfos) { DataEntity app; - app.setTop(info.top); - app.setLock(info.lock == 1); - app.setFavorite(info.favorite); - app.setLaunchTimes(info.launchTimes); - - app.setId(info.desktopPath); - app.setIcon(APP_ICON_PREFIX + info.iconName); - app.setName(info.appLocalName); - app.setCategory(info.category); - app.setFirstLetter(info.firstLetter); - - m_appManager->m_normalApps.append(app); + addInfoToApp(info, app); + m_appManager->m_normalApps.insert(app.id(), app); } - updateFavoriteApps(); } @@ -110,15 +114,13 @@ void AppDataWorker::updateFavoriteApps() } } - if (favoriteApps.isEmpty()) { - return; + if (!favoriteApps.isEmpty()) { + // 排序搜藏夹数据 + std::sort(favoriteApps.begin(), favoriteApps.end(), [](const DataEntity& a, const DataEntity &b) { + return a.favorite() < b.favorite(); + }); } - // 排序搜藏夹数据 - std::sort(favoriteApps.begin(), favoriteApps.end(), [](const DataEntity& a, const DataEntity &b) { - return a.favorite() < b.favorite(); - }); - { QMutexLocker locker(&m_appManager->m_mutex); m_appManager->m_favoriteApps.swap(favoriteApps); @@ -127,7 +129,7 @@ void AppDataWorker::updateFavoriteApps() Q_EMIT favoriteAppChanged(); } -void AppDataWorker::onAppAdded(const QVector &infos) +void AppDataWorker::onAppAdded(const QStringList &infos) { if (infos.isEmpty()) { return; @@ -135,31 +137,39 @@ void AppDataWorker::onAppAdded(const QVector &infos) QList apps; appendApps(infos, apps); - Q_EMIT appAdded(apps); + + updateFavoriteApps(); } -void AppDataWorker::appendApps(const QVector &infos, QList &apps) +void AppDataWorker::appendApps(const QStringList &infos, QList &apps) { QMutexLocker locker(&m_appManager->m_mutex); - for (const auto &info : infos) { - DataEntity app; - app.setTop(info.top); - app.setLock(info.lock == 1); - app.setFavorite(info.favorite); - app.setLaunchTimes(info.launchTimes); - app.setId(info.desktopPath); - app.setIcon(APP_ICON_PREFIX + info.iconName); - app.setName(info.appLocalName); - app.setCategory(info.category); - app.setFirstLetter(info.firstLetter); - - m_appManager->m_normalApps.append(app); - apps.append(app); + for (const QString &info : infos) { + UkuiSearch::ApplicationPropertyMap appinfo = m_applicationInfo->getInfo(info, m_appProperties); + if (appinfo.value(UkuiSearch::ApplicationProperty::Property::DontDisplay).toInt() == 0) { + DataEntity app; + addInfoToApp(appinfo, app); + m_appManager->m_normalApps.insert(app.id(), app); + apps.append(app); + } } } -void AppDataWorker::onAppUpdated(QVector infos) +void AppDataWorker::addInfoToApp(const UkuiSearch::ApplicationPropertyMap &info, DataEntity &app) +{ + app.setTop(info.value(UkuiSearch::ApplicationProperty::Property::Top).toInt()); + app.setLock(info.value(UkuiSearch::ApplicationProperty::Property::Lock).toInt() == 1); + app.setFavorite(info.value(UkuiSearch::ApplicationProperty::Property::Favorites).toInt()); + app.setLaunchTimes(info.value(UkuiSearch::ApplicationProperty::Property::LaunchTimes).toInt()); + app.setId(info.value(UkuiSearch::ApplicationProperty::Property::DesktopFilePath).toString()); + app.setIcon(APP_ICON_PREFIX + info.value(UkuiSearch::ApplicationProperty::Property::Icon).toString()); + app.setName(info.value(UkuiSearch::ApplicationProperty::Property::LocalName).toString()); + app.setCategory(info.value(UkuiSearch::ApplicationProperty::Property::Category).toString()); + app.setFirstLetter(info.value(UkuiSearch::ApplicationProperty::Property::FirstLetterAll).toString()); +} + +void AppDataWorker::onAppUpdated(const UkuiSearch::ApplicationInfoMap &infos) { if (infos.isEmpty()) { return; @@ -172,29 +182,76 @@ void AppDataWorker::onAppUpdated(QVector infos) updateFavoriteApps(); } -void AppDataWorker::updateApps(QVector &infos, QList &apps) +void AppDataWorker::onAppUpdatedAll(const QStringList &infos) +{ + if (infos.isEmpty()) { + return; + } + + QList apps; + updateAppsAll(infos, apps); + Q_EMIT appUpdated(apps); + + updateFavoriteApps(); +} + +void AppDataWorker::updateApps(const UkuiSearch::ApplicationInfoMap &infos, QList &apps) { QMutexLocker locker(&m_appManager->m_mutex); - for (auto &app : m_appManager->m_normalApps) { - if (infos.isEmpty()) { - break; - } - for (int i = 0; i < infos.size(); ++i) { - const UkuiSearch::AppInfoResult &info = infos.at(i); - if (info.desktopPath == app.id()) { - app.setTop(info.top); - app.setLock(info.lock == 1); - app.setFavorite(info.favorite); - app.setLaunchTimes(info.launchTimes); - app.setIcon(APP_ICON_PREFIX + info.iconName); - app.setName(info.appLocalName); - app.setCategory(info.category); - app.setFirstLetter(info.firstLetter); - - apps.append(app); - infos.remove(i); - break; + if (infos.isEmpty()) { + return; + } + for (const QString &info : infos.keys()) { + if (m_appManager->m_normalApps.contains(info)) { + DataEntity &app = m_appManager->m_normalApps[info]; + for (auto &appProperty : infos.value(info).keys()) { + switch (appProperty) { + case UkuiSearch::ApplicationProperty::Property::Top: + app.setTop(infos.value(info).value(UkuiSearch::ApplicationProperty::Property::Top).toInt()); + break; + case UkuiSearch::ApplicationProperty::Property::Lock: + app.setLock(infos.value(info).value(UkuiSearch::ApplicationProperty::Property::Lock).toInt() == 1); + break; + case UkuiSearch::ApplicationProperty::Property::Favorites: + app.setFavorite(infos.value(info).value(UkuiSearch::ApplicationProperty::Property::Favorites).toInt()); + break; + case UkuiSearch::ApplicationProperty::Property::LaunchTimes: + app.setLaunchTimes(infos.value(info).value(UkuiSearch::ApplicationProperty::Property::LaunchTimes).toInt()); + break; + case UkuiSearch::ApplicationProperty::Property::DesktopFilePath: + app.setId(infos.value(info).value(UkuiSearch::ApplicationProperty::Property::DesktopFilePath).toString()); + break; + case UkuiSearch::ApplicationProperty::Property::Icon: + app.setIcon(APP_ICON_PREFIX + infos.value(info).value(UkuiSearch::ApplicationProperty::Property::Icon).toString()); + break; + case UkuiSearch::ApplicationProperty::Property::LocalName: + app.setName(infos.value(info).value(UkuiSearch::ApplicationProperty::Property::LocalName).toString()); + break; + case UkuiSearch::ApplicationProperty::Property::Category: + app.setCategory(infos.value(info).value(UkuiSearch::ApplicationProperty::Property::Category).toString()); + break; + case UkuiSearch::ApplicationProperty::Property::FirstLetterAll: + app.setFirstLetter(infos.value(info).value(UkuiSearch::ApplicationProperty::Property::FirstLetterAll).toString()); + break; + default: + break; + } } + apps.append(app); + } + } +} + +void AppDataWorker::updateAppsAll(const QStringList &infos, QList &apps) +{ + QMutexLocker locker(&m_appManager->m_mutex); + + for (const auto &info : infos) { + if (m_appManager->m_normalApps.contains(info)) { + UkuiSearch::ApplicationPropertyMap appinfo = m_applicationInfo->getInfo(info, m_appProperties); + DataEntity &app = m_appManager->m_normalApps[info]; + addInfoToApp(appinfo, app); + apps.append(app); } } } @@ -214,16 +271,11 @@ void AppDataWorker::onAppDeleted(QStringList infos) void AppDataWorker::removeApps(QStringList &appIdList, QStringList &removedIdList) { QMutexLocker locker(&m_appManager->m_mutex); - QList &normalApps = m_appManager->m_normalApps; - QList::iterator iterator = normalApps.begin(); - while (iterator != normalApps.end() && !appIdList.isEmpty()) { - if (appIdList.removeOne((*iterator).id())) { - removedIdList.append((*iterator).id()); - iterator = normalApps.erase(iterator); - continue; + for (const QString &id : appIdList) { + if (m_appManager->m_normalApps.remove(id)) { + removedIdList.append(id); } - ++iterator; } } @@ -257,7 +309,7 @@ AppDataManager::~AppDataManager() QList AppDataManager::normalApps() { QMutexLocker locker(&m_mutex); - return m_normalApps; + return m_normalApps.values(); } QVector AppDataManager::favoriteApps() diff --git a/src/appdata/app-data-manager.h b/src/appdata/app-data-manager.h index bc2f2de..88b2ec5 100644 --- a/src/appdata/app-data-manager.h +++ b/src/appdata/app-data-manager.h @@ -60,7 +60,7 @@ private: private: QMutex m_mutex; QThread m_workerThread; - QList m_normalApps; + QMap m_normalApps; QVector m_favoriteApps; }; diff --git a/src/appdata/plugin/app-search-plugin.cpp b/src/appdata/plugin/app-search-plugin.cpp index 62f27d8..6398ca6 100644 --- a/src/appdata/plugin/app-search-plugin.cpp +++ b/src/appdata/plugin/app-search-plugin.cpp @@ -50,10 +50,14 @@ AppSearchPluginPrivate::AppSearchPluginPrivate() : QThread(nullptr) m_appSearchTask = new UkuiSearch::UkuiSearchTask(this); m_dataQueue = m_appSearchTask->init(); - m_appSearchTask->initSearchPlugin(UkuiSearch::SearchType::Application); + m_appSearchTask->initSearchPlugin(UkuiSearch::SearchProperty::SearchType::Application); m_appSearchTask->setSearchOnlineApps(false); - m_appSearchTask->setResultDataType(UkuiSearch::SearchType::Application, - UkuiSearch::ApplicationDesktopPath | UkuiSearch::ApplicationLocalName | UkuiSearch::ApplicationIconName); + + UkuiSearch::SearchResultProperties searchResultProperties; + searchResultProperties << UkuiSearch::SearchProperty::SearchResultProperty::ApplicationDesktopPath + << UkuiSearch::SearchProperty::SearchResultProperty::ApplicationLocalName + << UkuiSearch::SearchProperty::SearchResultProperty::ApplicationIconName; + m_appSearchTask->setResultProperties(UkuiSearch::SearchProperty::SearchType::Application, searchResultProperties); m_timer = new QTimer; m_timer->setInterval(3000); @@ -68,7 +72,7 @@ void AppSearchPluginPrivate::startSearch(QString &keyword) m_appSearchTask->clearKeyWords(); m_appSearchTask->addKeyword(keyword); - m_searchId = m_appSearchTask->startSearch(UkuiSearch::SearchType::Application); + m_searchId = m_appSearchTask->startSearch(UkuiSearch::SearchProperty::SearchType::Application); } void AppSearchPluginPrivate::stopSearch() @@ -81,7 +85,7 @@ void AppSearchPluginPrivate::run() { while (!isInterruptionRequested()) { UkuiSearch::ResultItem result = m_dataQueue->tryDequeue(); - if(result.getSearchId() == 0 && result.getItemKey().isEmpty() && result.getExtral().isEmpty()) { + if(result.getSearchId() == 0 && result.getItemKey().isEmpty() && result.getAllValue().isEmpty()) { if(!m_timer->isActive()) { // 超时退出 m_timer->start(); @@ -90,12 +94,11 @@ void AppSearchPluginPrivate::run() } else { m_timer->stop(); if (result.getSearchId() == m_searchId) { - QVariantList list = result.getExtral(); DataEntity app; app.setType(DataType::Normal); - app.setId(list.at(0).toString()); - app.setName(list.at(1).toString()); - app.setIcon("image://appicon/" + list.at(2).toString()); + app.setId(result.getValue(UkuiSearch::SearchProperty::ApplicationDesktopPath).toString()); + app.setName(result.getValue(UkuiSearch::SearchProperty::ApplicationLocalName).toString()); + app.setIcon("image://appicon/" + result.getValue(UkuiSearch::SearchProperty::ApplicationIconName).toString()); Q_EMIT this->searchedOne(app); } diff --git a/src/extension/extensions/favorite-extension.cpp b/src/extension/extensions/favorite-extension.cpp index 0316822..da6f2fb 100644 --- a/src/extension/extensions/favorite-extension.cpp +++ b/src/extension/extensions/favorite-extension.cpp @@ -22,7 +22,7 @@ #include "commons.h" #include #include -#include +#include namespace UkuiMenu { @@ -48,7 +48,7 @@ public Q_SLOTS: private: QVector m_favoriteAppsData; - UkuiSearch::AppInfoTable *m_appInfoTable = nullptr; + UkuiSearch::ApplicationInfo *m_appInfoTable = nullptr; }; FavoriteExtension::FavoriteExtension(QObject *parent) : MenuExtensionIFace(parent) @@ -109,7 +109,7 @@ void FavoriteExtension::updateFavoriteData() FavoriteAppsModel::FavoriteAppsModel(QObject *parent) : QAbstractListModel(parent) { - m_appInfoTable = new UkuiSearch::AppInfoTable(this); + m_appInfoTable = new UkuiSearch::ApplicationInfo(this); } int FavoriteAppsModel::rowCount(const QModelIndex &parent) const