From 24ca01368fd83402c32ea2a558f92e95b13de10b Mon Sep 17 00:00:00 2001 From: gjq Date: Mon, 17 Apr 2023 17:23:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BA=94=E7=94=A8=E6=9C=80?= =?UTF-8?q?=E8=BF=91=E5=AE=89=E8=A3=85=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qml/AppControls2/AppItem.qml | 2 +- qml/AppUI/AppList.qml | 4 ++ src/appdata/app-data-manager.cpp | 20 ++++++- src/appdata/app-data-manager.h | 1 + src/appdata/plugin/all-app-data-provider.cpp | 59 ++++++++++++++++---- src/appdata/plugin/all-app-data-provider.h | 2 + src/data-entity.cpp | 34 +++++++++++ src/data-entity.h | 12 +++- src/model/app-model.cpp | 5 ++ src/model/app-model.h | 2 +- src/utils/app-manager.cpp | 6 ++ src/utils/app-manager.h | 1 + 12 files changed, 132 insertions(+), 16 deletions(-) diff --git a/qml/AppControls2/AppItem.qml b/qml/AppControls2/AppItem.qml index 4466642..cd19cc2 100644 --- a/qml/AppControls2/AppItem.qml +++ b/qml/AppControls2/AppItem.qml @@ -33,7 +33,7 @@ MouseArea { Loader { id: tag - property bool recentInsatlled: false + property bool recentInsatlled: (recentInstall === undefined) ? false : recentInstall property bool fixToTop: (toTop !== undefined) && (toTop !== 0) visible: fixToTop || recentInsatlled Layout.alignment: Qt.AlignRight | Qt.AlignVCenter diff --git a/qml/AppUI/AppList.qml b/qml/AppUI/AppList.qml index 41cc434..5d645f5 100644 --- a/qml/AppUI/AppList.qml +++ b/qml/AppUI/AppList.qml @@ -46,6 +46,7 @@ Item { property string name: model.name property string icon: model.icon property int toTop: model.top + property bool recentInstall: model.recentInstall sourceComponent: { if (type === DataType.Normal) { return appItem; @@ -72,6 +73,9 @@ Item { } if (mouse.button === Qt.LeftButton) { appManager.launchApp(id); + if (recentInstall) { + appManager.appLaunched(id); + } return; } } diff --git a/src/appdata/app-data-manager.cpp b/src/appdata/app-data-manager.cpp index 68f19c1..ac763b4 100644 --- a/src/appdata/app-data-manager.cpp +++ b/src/appdata/app-data-manager.cpp @@ -48,6 +48,7 @@ public Q_SLOTS: void fixToFavoriteSlot(const QString &path, const int &num); void changedFavoriteOrderSlot(const QString &path, const int &num); void fixToTopSlot(const QString &path, const int &num); + void setAppLaunched(const QString &path); private: void updateFavoriteApps(); @@ -93,8 +94,11 @@ void AppDataWorker::initAppData() << UkuiSearch::ApplicationProperty::Property::LocalName << UkuiSearch::ApplicationProperty::Property::Category << UkuiSearch::ApplicationProperty::Property::FirstLetterAll - << UkuiSearch::ApplicationProperty::Property::DontDisplay; + << UkuiSearch::ApplicationProperty::Property::DontDisplay + << UkuiSearch::ApplicationProperty::Property::InsertTime + << UkuiSearch::ApplicationProperty::Property::Launched; m_appPropertyMap.insert(UkuiSearch::ApplicationProperty::Property::DontDisplay, 0); + m_appPropertyMap.insert(UkuiSearch::ApplicationProperty::Property::AutoStart, 0); UkuiSearch::ApplicationInfoMap appInfos = m_applicationInfo->getInfo(m_appProperties, m_appPropertyMap); @@ -172,6 +176,8 @@ void AppDataWorker::addInfoToApp(const UkuiSearch::ApplicationPropertyMap &info, 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()); + app.setInsertTime(info.value(UkuiSearch::ApplicationProperty::Property::InsertTime).toString()); + app.setLaunched(info.value(UkuiSearch::ApplicationProperty::Property::Launched).toInt()); } void AppDataWorker::onAppUpdated(const UkuiSearch::ApplicationInfoMap &infos) @@ -239,6 +245,12 @@ void AppDataWorker::updateApps(const UkuiSearch::ApplicationInfoMap &infos, QLis case UkuiSearch::ApplicationProperty::Property::FirstLetterAll: app.setFirstLetter(infos.value(info).value(UkuiSearch::ApplicationProperty::Property::FirstLetterAll).toString()); break; + case UkuiSearch::ApplicationProperty::Property::InsertTime: + app.setInsertTime(infos.value(info).value(UkuiSearch::ApplicationProperty::Property::InsertTime).toString()); + break; + case UkuiSearch::ApplicationProperty::Property::Launched: + app.setLaunched(infos.value(info).value(UkuiSearch::ApplicationProperty::Property::Launched).toInt()); + break; default: break; } @@ -297,6 +309,11 @@ void AppDataWorker::fixToTopSlot(const QString &path, const int &num) } } +void AppDataWorker::setAppLaunched(const QString &path) +{ + m_applicationInfo->setAppLaunchedState(path); +} + void AppDataWorker::removeApps(QStringList &appIdList, QStringList &removedIdList) { QMutexLocker locker(&m_appManager->m_mutex); @@ -328,6 +345,7 @@ AppDataManager::AppDataManager() connect(this, &AppDataManager::fixToFavoriteSignal, appDataWorker, &AppDataWorker::fixToFavoriteSlot); connect(this, &AppDataManager::changedFavoriteOrderSignal, appDataWorker, &AppDataWorker::changedFavoriteOrderSlot); connect(this, &AppDataManager::fixToTop, appDataWorker, &AppDataWorker::fixToTopSlot); + connect(this, &AppDataManager::appLaunch, appDataWorker, &AppDataWorker::setAppLaunched); m_workerThread.start(); } diff --git a/src/appdata/app-data-manager.h b/src/appdata/app-data-manager.h index b807f88..03625e5 100644 --- a/src/appdata/app-data-manager.h +++ b/src/appdata/app-data-manager.h @@ -58,6 +58,7 @@ Q_SIGNALS: void fixToFavoriteSignal(const QString &path, const int &num); void changedFavoriteOrderSignal(const QString &path, const int &num); void fixToTop(const QString &path, const int &num); + void appLaunch(const QString &path); private: AppDataManager(); diff --git a/src/appdata/plugin/all-app-data-provider.cpp b/src/appdata/plugin/all-app-data-provider.cpp index 63349cd..a75f8a2 100644 --- a/src/appdata/plugin/all-app-data-provider.cpp +++ b/src/appdata/plugin/all-app-data-provider.cpp @@ -21,6 +21,7 @@ #include "app-folder-helper.h" #include +#include namespace UkuiMenu { @@ -92,23 +93,15 @@ void AllAppDataProvider::reloadAppData() return; } - for (const auto &app : apps) { + for (auto &app : apps) { if (AppFolderHelper::instance()->containApp(app.id())) { continue; } + setRecentState(app); appData.append(app); } - std::sort(appData.begin(), appData.end(), [](const DataEntity &a, const DataEntity &b) { - if (a.top() == 0) { - return (a.top() == b.top()) ? (a.launchTimes() > b.launchTimes()) : (a.top() > b.top()); - } else if (b.top() == 0) { - return a.top() > b.top(); - } else { - return a.top() < b.top(); - } - }); - + std::sort(appData.begin(), appData.end(), appDataSort); m_appData.swap(appData); } @@ -143,6 +136,43 @@ void AllAppDataProvider::mergeData(QVector &data) data.append(m_appData); } +bool AllAppDataProvider::appDataSort(const DataEntity &a, const DataEntity &b) +{ + if ((a.top() != 0) && (b.top() != 0)) { + return a.top() < b.top(); + } else if ((a.top() == 0) && (b.top() == 0)) { + if (a.isRecentInstall()) { + if (b.isRecentInstall()) { + return QDateTime::fromString(a.insertTime(), "yyyy-MM-dd hh:mm:ss") + > QDateTime::fromString(b.insertTime(), "yyyy-MM-dd hh:mm:ss"); + } else { + return true; + } + } else if (b.isRecentInstall()) { + return false; + } else { + return a.launchTimes() > b.launchTimes(); + } + } else { + return a.top() > b.top(); + } +} + +void AllAppDataProvider::setRecentState(DataEntity &app) +{ + if (app.launched() == 0) { + QDateTime installTime = QDateTime::fromString(app.insertTime(), "yyyy-MM-dd hh:mm:ss"); + if (installTime.isValid()) { + int appTime = installTime.secsTo(QDateTime::currentDateTime()); + if ((appTime >= 0 ) && (appTime <= 3600*48)) { + app.setRecentInstall(true); + return; + } + } + } + app.setRecentInstall(false); +} + void AllAppDataProvider::sendData() { QVector data; @@ -159,7 +189,11 @@ void AllAppDataProvider::onAppAdded(const QList& apps) { { QMutexLocker locker(&m_mutex); - m_appData.append(apps.toVector()); + for (auto app : apps) { + setRecentState(app); + m_appData.append(app); + } + std::sort(m_appData.begin(), m_appData.end(), appDataSort); } sendData(); } @@ -167,6 +201,7 @@ void AllAppDataProvider::onAppAdded(const QList& apps) void AllAppDataProvider::onAppDeleted(QStringList idList) { removeApps(idList); + reloadFolderData(); sendData(); } diff --git a/src/appdata/plugin/all-app-data-provider.h b/src/appdata/plugin/all-app-data-provider.h index 7073069..4e81c1f 100644 --- a/src/appdata/plugin/all-app-data-provider.h +++ b/src/appdata/plugin/all-app-data-provider.h @@ -52,6 +52,8 @@ private: void reloadAppData(); void reloadFolderData(); void mergeData(QVector &data); + static bool appDataSort(const DataEntity &a, const DataEntity &b); + static void setRecentState(DataEntity &app); private: QMutex m_mutex; diff --git a/src/data-entity.cpp b/src/data-entity.cpp index 0d19325..28cab5c 100644 --- a/src/data-entity.cpp +++ b/src/data-entity.cpp @@ -28,6 +28,8 @@ public: : type(type), name(std::move(name)), icon(std::move(icon)), comment(std::move(comment)), extraData(std::move(extraData)) {} bool lock{false}; // 应用锁定 + bool recentInstall{false}; + int launched{0}; // 是否启动过 int top{0}; // 置顶状态及序号 int favorite{0}; // 收藏状态及序号 int launchTimes{0}; // 启动次数 @@ -39,6 +41,7 @@ public: QString firstLetter; QString comment; // 应用描述 QString extraData; // 额外的数据 + QString insertTime; //安装的时间 }; DataEntity::DataEntity() : d(new DataEntityPrivate) {} @@ -69,6 +72,26 @@ void DataEntity::setLock(bool lock) d->lock = lock; } +bool DataEntity::isRecentInstall() const +{ + return d->recentInstall; +} + +void DataEntity::setRecentInstall(bool recentInsatll) +{ + d->recentInstall = recentInsatll; +} + +int DataEntity::launched() const +{ + return d->launched; +} + +void DataEntity::setLaunched(int launched) +{ + d->launched = launched; +} + int DataEntity::favorite() const { return d->favorite; @@ -89,6 +112,16 @@ void DataEntity::setLaunchTimes(int launchTimes) d->launchTimes = launchTimes; } +QString DataEntity::insertTime() const +{ + return d->insertTime; +} + +void DataEntity::setInsertTime(const QString &insertTime) +{ + d->insertTime = insertTime; +} + QString DataEntity::id() const { return d->id; @@ -179,6 +212,7 @@ QHash DataEntity::AppRoleNames() names.insert(DataEntity::Comment, "comment"); names.insert(DataEntity::ExtraData, "extraData"); names.insert(DataEntity::Top, "top"); + names.insert(DataEntity::RecentInstall, "recentInstall"); return names; } diff --git a/src/data-entity.h b/src/data-entity.h index ec09661..875694c 100644 --- a/src/data-entity.h +++ b/src/data-entity.h @@ -58,7 +58,8 @@ public: Name, Comment, ExtraData, - Top + Top, + RecentInstall }; DataEntity(); DataEntity(DataType::Type type, const QString& name, const QString& icon, const QString& comment, const QString& extraData); @@ -76,12 +77,21 @@ public: bool isLock() const; void setLock(bool lock); + bool isRecentInstall() const; + void setRecentInstall(bool recentInsatll); + + int launched() const; + void setLaunched(int launched); + int favorite() const; void setFavorite(int favorite); int launchTimes() const; void setLaunchTimes(int launchTimes); + QString insertTime() const; + void setInsertTime(const QString& insertTime); + QString id() const; void setId(const QString& id); diff --git a/src/model/app-model.cpp b/src/model/app-model.cpp index 1bc9c87..2e56065 100644 --- a/src/model/app-model.cpp +++ b/src/model/app-model.cpp @@ -63,6 +63,11 @@ QVariant AppModel::data(const QModelIndex &index, int role) const return m_apps.at(i).top(); } return 0; + case DataEntity::RecentInstall: + if (DataProviderManager::instance()->activatedProvider() == "all") { + return m_apps.at(i).isRecentInstall(); + } + return false; default: break; } diff --git a/src/model/app-model.h b/src/model/app-model.h index 2b882fd..7299730 100644 --- a/src/model/app-model.h +++ b/src/model/app-model.h @@ -61,7 +61,7 @@ private: QVector m_apps; Q_SIGNALS: - Q_INVOKABLE void renameText(QString id); + void renameText(QString id); }; } // UkuiMenu diff --git a/src/utils/app-manager.cpp b/src/utils/app-manager.cpp index f663579..147fd60 100644 --- a/src/utils/app-manager.cpp +++ b/src/utils/app-manager.cpp @@ -18,6 +18,7 @@ #include #include "app-manager.h" +#include "app-data-manager.h" #include #include @@ -76,6 +77,11 @@ bool AppManager::launchBinaryApp(const QString &app, const QString &args) return QProcess::startDetached(cmd); } +void AppManager::appLaunched(const QString &desktopFilePath) +{ + AppDataManager::instance()->appLaunch(desktopFilePath); +} + bool AppManager::launchAppWithDBus(const QString &app) { if (!m_appManagerDbusInterface) { diff --git a/src/utils/app-manager.h b/src/utils/app-manager.h index 5b8cf7a..aa39852 100644 --- a/src/utils/app-manager.h +++ b/src/utils/app-manager.h @@ -34,6 +34,7 @@ public: Q_INVOKABLE bool launchApp(const QString &desktopFilePath); Q_INVOKABLE bool launchBinaryApp(const QString &app, const QString &args = QString()); + Q_INVOKABLE void appLaunched(const QString &desktopFilePath); private: explicit AppManager(QObject *parent = nullptr);