From f150ebca0a7fe310551cc0852c789b0a8b351b98 Mon Sep 17 00:00:00 2001 From: iaom Date: Fri, 17 Mar 2023 16:08:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=BE=E7=BD=AE=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=90=AF=E5=8A=A8=E6=97=B6=E6=A0=A1=E9=AA=8C=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=88=97=E8=A1=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../settings-manager-private.h | 2 ++ .../settings-manager.cpp | 28 +++++++++++++++++++ notification-ukcc-plugin/CMakeLists.txt | 1 + notification-ukcc-plugin/noticemenu.h | 2 +- 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/libukui-notification/notification-settings/settings-manager-private.h b/libukui-notification/notification-settings/settings-manager-private.h index 3558edd..543e71d 100644 --- a/libukui-notification/notification-settings/settings-manager-private.h +++ b/libukui-notification/notification-settings/settings-manager-private.h @@ -51,6 +51,7 @@ private: QStringList getAppInfo(); void initSettingsData(QJsonObject &data); + void checkApplicationList(QJsonObject &data); public Q_SLOTS: void desktopFileAdd(const QStringList &data); @@ -65,6 +66,7 @@ private: QFileSystemWatcher *m_watcher = nullptr; UkuiSearch::ApplicationInfo * m_applicationInfo = nullptr; QJsonObject m_applicationDefaultSettings; + bool m_needCheckApplist = true; }; } diff --git a/libukui-notification/notification-settings/settings-manager.cpp b/libukui-notification/notification-settings/settings-manager.cpp index da2d6c0..9ae8386 100644 --- a/libukui-notification/notification-settings/settings-manager.cpp +++ b/libukui-notification/notification-settings/settings-manager.cpp @@ -82,6 +82,10 @@ void SettingsManagerPrivate::checkAndLoad() qDebug() << "Notification settings version is different, need update! configFile:" << version << " new:" << NOTIFICATION_SETTINGS_VERSION; updateSettingsFile(); } else { + if(m_needCheckApplist) { + checkApplicationList(settingsData); + m_needCheckApplist = false; + } m_settingsData.swap(settingsData); Q_EMIT settingsUpdateFinished(); m_watcher->addPath(SETTINGS_FILE_PATH_NAME); @@ -226,6 +230,30 @@ void SettingsManagerPrivate::save2SettingsFile(const QJsonObject &jsonDocData) settingsFile.close(); } +void SettingsManagerPrivate::checkApplicationList(QJsonObject &data) +{ + QStringList appList = getAppInfo(); + QStringList appNeedRemoved; + QJsonObject applicationSettings = data.value(QStringLiteral("Applications")).toObject(); + for(const QString &desktopFile : applicationSettings.keys()) { + if(appList.contains(desktopFile)) { + appList.removeAll(desktopFile); + } else { + appNeedRemoved.append(desktopFile); + } + } + //移除应用列表里已经不存在的应用 + for(const QString &desktopFile : appNeedRemoved) { + applicationSettings.remove(desktopFile); + } + //将配置文件中没有的应用插入 + for(const QString &desktopFile : appList) { + applicationSettings.insert(desktopFile, m_applicationDefaultSettings); + } + data.insert(QStringLiteral("Applications"), applicationSettings); + save2SettingsFile(data); +} + SettingsManager::SettingsManager(QObject *parent) : QObject(parent), d(new SettingsManagerPrivate(this)) { connect(d, &SettingsManagerPrivate::settingsUpdateFinished, this, &SettingsManager::settingsDataChanged); diff --git a/notification-ukcc-plugin/CMakeLists.txt b/notification-ukcc-plugin/CMakeLists.txt index d671460..80d4340 100644 --- a/notification-ukcc-plugin/CMakeLists.txt +++ b/notification-ukcc-plugin/CMakeLists.txt @@ -24,6 +24,7 @@ endforeach() include_directories(${Qt5Core_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}) include_directories(../libukui-notification/notification-settings) +include_directories(../libukui-notification) target_link_libraries(notification-ukcc-plugin PRIVATE diff --git a/notification-ukcc-plugin/noticemenu.h b/notification-ukcc-plugin/noticemenu.h index bdeb606..ad72804 100644 --- a/notification-ukcc-plugin/noticemenu.h +++ b/notification-ukcc-plugin/noticemenu.h @@ -8,7 +8,7 @@ #include #include -#include "notification-settings/applications-settings.h" +#include "applications-settings.h" using namespace kdk;