增加设置接口启动时校验应用列表功能
This commit is contained in:
parent
a3b53d48e4
commit
f150ebca0a
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <QFrame>
|
||||
|
||||
#include <kswitchbutton.h>
|
||||
#include "notification-settings/applications-settings.h"
|
||||
#include "applications-settings.h"
|
||||
|
||||
using namespace kdk;
|
||||
|
||||
|
|
Loading…
Reference in New Issue