增加通知中心设置项读取写入接口
This commit is contained in:
parent
8dc1ed86a0
commit
fd2b80a585
|
@ -4,6 +4,19 @@ set(VERSION_MICRO 0)
|
|||
set(UKUI_NOTIFICATION_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO})
|
||||
set(settings_DIR notification-settings/)
|
||||
find_package(KF5WindowSystem)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
set(UKUI_NOTIFICATION_EXTERNAL_LIBS "")
|
||||
set(UKUI_NOTIFICATION_PC_PKGS ukui-search)
|
||||
|
||||
foreach(PC_LIB IN ITEMS ${UKUI_NOTIFICATION_PC_PKGS})
|
||||
pkg_check_modules(${PC_LIB} REQUIRED ${PC_LIB})
|
||||
if(${${PC_LIB}_FOUND})
|
||||
include_directories(${${PC_LIB}_INCLUDE_DIRS})
|
||||
link_directories(${${PC_LIB}_LIBRARY_DIRS})
|
||||
list(APPEND UKUI_NOTIFICATION_EXTERNAL_LIBS ${${PC_LIB}_LIBRARIES})
|
||||
endif()
|
||||
endforeach()
|
||||
include_directories(notification-settings)
|
||||
set(ukui-notification_LIB_SRCS
|
||||
notification-client.cpp
|
||||
notification-client.h
|
||||
|
@ -13,12 +26,14 @@ set(ukui-notification_LIB_SRCS
|
|||
notification-client-private.h
|
||||
utils.h
|
||||
utils.cpp
|
||||
${settings_DIR}notification-settings-properties.h
|
||||
${settings_DIR}notification-settings-info.h
|
||||
${settings_DIR}notification-settings-info.cpp
|
||||
${settings_DIR}notification-settings.h
|
||||
${settings_DIR}notification-settings.cpp
|
||||
${settings_DIR}notification-settings-private.h)
|
||||
${settings_DIR}settings-properties.h
|
||||
${settings_DIR}settings-properties-info.h
|
||||
${settings_DIR}settings-properties-info.cpp
|
||||
${settings_DIR}settings-manager-private.h
|
||||
${settings_DIR}settings-manager.h
|
||||
${settings_DIR}settings-manager.cpp
|
||||
${settings_DIR}/notification-global-settings.cpp
|
||||
${settings_DIR}/notification-global-settings.h notification-settings/single-application-settings.cpp notification-settings/single-application-settings.h notification-settings/applications-settings.cpp notification-settings/applications-settings.h)
|
||||
set(HEADERS
|
||||
notification-client.h
|
||||
popup-notification.h
|
||||
|
@ -38,7 +53,7 @@ target_link_libraries(ukui-notification
|
|||
Qt${QT_VERSION_MAJOR}::DBus
|
||||
Qt${QT_VERSION_MAJOR}::Gui
|
||||
KF5::WindowSystem
|
||||
ukui-search
|
||||
${UKUI_NOTIFICATION_EXTERNAL_LIBS}
|
||||
)
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
//
|
||||
// Created by zpf on 2023/2/27.
|
||||
//
|
||||
|
||||
#include "applications-settings.h"
|
||||
#include <mutex>
|
||||
#include "settings-manager.h"
|
||||
#include <QJsonObject>
|
||||
|
||||
using namespace UkuiNotification;
|
||||
static std::once_flag flag;
|
||||
static ApplicationsSettings *s_self;
|
||||
namespace UkuiNotification{
|
||||
class ApplicationsSettingsPrivate
|
||||
{
|
||||
friend class ApplicationsSettings;
|
||||
private:
|
||||
ApplicationsSettingsHash m_cache;
|
||||
QJsonObject m_settingsData;
|
||||
};
|
||||
}
|
||||
|
||||
ApplicationsSettings *UkuiNotification::ApplicationsSettings::self()
|
||||
{
|
||||
std::call_once(flag, [ & ] {
|
||||
s_self = new ApplicationsSettings();
|
||||
});
|
||||
return s_self;
|
||||
}
|
||||
|
||||
UkuiNotification::ApplicationsSettings::ApplicationsSettings(QObject *parent) : QObject(parent), d(new ApplicationsSettingsPrivate)
|
||||
{
|
||||
d->m_settingsData = SettingsManager::self()->getAllAppSettings();
|
||||
connect(SettingsManager::self(), &SettingsManager::appUninstalled, this, &ApplicationsSettings::applicationUninstalled);
|
||||
connect(SettingsManager::self(), &SettingsManager::settingsDataChanged, this, &ApplicationsSettings::settingsDataChanged);
|
||||
}
|
||||
|
||||
ApplicationsSettings::~ApplicationsSettings()
|
||||
{
|
||||
if(d) {
|
||||
delete d;
|
||||
d = nullptr;
|
||||
}
|
||||
}
|
||||
SingleApplicationSettings ApplicationsSettings::creatSettings(PopupNotification ¬ification)
|
||||
{
|
||||
QString desktopEntry = notification.desktopEntry();
|
||||
if(desktopEntry.isEmpty()) {
|
||||
desktopEntry = QStringLiteral("default");
|
||||
}
|
||||
if(d->m_cache.contains(desktopEntry)) {
|
||||
return d->m_cache.value(desktopEntry);
|
||||
}
|
||||
return d->m_cache.insert(desktopEntry, SingleApplicationSettings(desktopEntry)).value();
|
||||
}
|
||||
|
||||
ApplicationsSettingsHash &ApplicationsSettings::getAllApplicationsSettings()
|
||||
{
|
||||
for(const QString &desktopEntry : d->m_settingsData.keys()) {
|
||||
if(!d->m_cache.contains(desktopEntry)) {
|
||||
d->m_cache.insert(desktopEntry, SingleApplicationSettings(desktopEntry));
|
||||
}
|
||||
}
|
||||
return d->m_cache;
|
||||
}
|
||||
|
||||
QJsonObject ApplicationsSettings::getAppSettings(const QString &appDesktopName)
|
||||
{
|
||||
if(appDesktopName == QStringLiteral("default") || appDesktopName.isEmpty()) {
|
||||
return SettingsManager::self()->getAppDefaultSettings();
|
||||
}
|
||||
QJsonValue value = d->m_settingsData.value(appDesktopName);
|
||||
if(value.isUndefined()) {
|
||||
return SettingsManager::self()->getAppDefaultSettings();;
|
||||
}
|
||||
return value.toObject();
|
||||
}
|
||||
bool ApplicationsSettings::setAppSetting(const QString &appDesktopName, SettingsProperty::Property key,
|
||||
const QVariant &value)
|
||||
{
|
||||
return SettingsManager::self()->setAppSettings(appDesktopName, key, value);
|
||||
}
|
||||
|
||||
void ApplicationsSettings::clearCache()
|
||||
{
|
||||
d->m_cache.clear();
|
||||
}
|
||||
|
||||
void ApplicationsSettings::settingsDataChanged()
|
||||
{
|
||||
QJsonObject data = SettingsManager::self()->getAllAppSettings();
|
||||
if(d->m_settingsData == data) {
|
||||
return;
|
||||
}
|
||||
for(const QString &desktopEntry : data.keys()) {
|
||||
bool newInstalled = !d->m_settingsData.contains(desktopEntry);
|
||||
d->m_settingsData.insert(desktopEntry, data.value(desktopEntry));
|
||||
if(newInstalled) {
|
||||
Q_EMIT applicationInstalled(desktopEntry);
|
||||
}
|
||||
}
|
||||
Q_EMIT settingsUpdated();
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
//
|
||||
// Created by zpf on 2023/2/27.
|
||||
//
|
||||
|
||||
#ifndef UKUI_NOTIFICATION_APPLICATIONS_SETTINGS_H
|
||||
#define UKUI_NOTIFICATION_APPLICATIONS_SETTINGS_H
|
||||
#include <QObject>
|
||||
#include <QJsonObject>
|
||||
#include "single-application-settings.h"
|
||||
#include "popup-notification.h"
|
||||
namespace UkuiNotification{
|
||||
typedef QHash<QString, SingleApplicationSettings> ApplicationsSettingsHash;
|
||||
class ApplicationsSettingsPrivate;
|
||||
/**
|
||||
* SingleApplicationSettings 工厂
|
||||
*/
|
||||
class ApplicationsSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static ApplicationsSettings *self();
|
||||
~ApplicationsSettings();
|
||||
/**
|
||||
* 初始化一个应用设置项实例,使用完毕后需要调用者进行回收
|
||||
* @param notification
|
||||
* @return SingleApplicationSettings
|
||||
*/
|
||||
SingleApplicationSettings creatSettings(PopupNotification ¬ification);
|
||||
ApplicationsSettingsHash &getAllApplicationsSettings();
|
||||
/**
|
||||
* @brief getAppSettings
|
||||
* 获取当前用户某个应用通知相关配置信息。
|
||||
* @param appDesktopName 传"default"获取配置默认值
|
||||
*/
|
||||
QJsonObject getAppSettings(const QString &appDesktopName);
|
||||
bool setAppSetting(const QString &appDesktopName, SettingsProperty::Property key, const QVariant &value);
|
||||
void clearCache();
|
||||
Q_SIGNALS:
|
||||
void applicationUninstalled(const QString &desktopEntry);
|
||||
void settingsUpdated();
|
||||
void applicationInstalled(const QString &desktopEntry);
|
||||
private Q_SLOTS:
|
||||
|
||||
private:
|
||||
ApplicationsSettings(QObject *parent = nullptr);
|
||||
void settingsDataChanged();
|
||||
ApplicationsSettingsPrivate *d = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //UKUI_NOTIFICATION_APPLICATIONS_SETTINGS_H
|
|
@ -0,0 +1,135 @@
|
|||
//
|
||||
// Created by zpf on 2023/2/20.
|
||||
//
|
||||
|
||||
#include "notification-global-settings.h"
|
||||
#include <QJsonObject>
|
||||
#include "settings-manager.h"
|
||||
#include "settings-properties.h"
|
||||
#include "settings-properties-info.h"
|
||||
|
||||
namespace UkuiNotification{
|
||||
class NotificationGlobalSettingsPrivate
|
||||
{
|
||||
friend class NotificationGlobalSettings;
|
||||
private:
|
||||
QJsonObject m_settings;
|
||||
};
|
||||
}
|
||||
|
||||
using namespace UkuiNotification;// UkuiNotification
|
||||
|
||||
NotificationGlobalSettings::NotificationGlobalSettings(QObject *parent) : QObject(parent), d(new NotificationGlobalSettingsPrivate())
|
||||
{
|
||||
connect(SettingsManager::self(), &SettingsManager::settingsDataChanged, this, &NotificationGlobalSettings::settingsDataChanged);
|
||||
d->m_settings = SettingsManager::self()->getGlobalSettings();
|
||||
}
|
||||
|
||||
NotificationGlobalSettings::~NotificationGlobalSettings()
|
||||
{
|
||||
if(d) {
|
||||
delete d;
|
||||
d = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool NotificationGlobalSettings::scheduleTurnOnDND()
|
||||
{
|
||||
return d->m_settings.value(SettingsPropertiesInfo(SettingsProperty::ScheduleTurnOnDND).name()).toBool();
|
||||
}
|
||||
|
||||
QTime NotificationGlobalSettings::scheduleTurnOnDNDTime()
|
||||
{
|
||||
return QTime::fromString(d->m_settings.value(SettingsPropertiesInfo(SettingsProperty::ScheduleTurnOnDNDTime).name()).toString(), "HHmm");
|
||||
}
|
||||
|
||||
QTime NotificationGlobalSettings::scheduleTurnOffDNDTime()
|
||||
{
|
||||
return QTime::fromString(d->m_settings.value(SettingsPropertiesInfo(SettingsProperty::ScheduleTurnOffDNDTime).name()).toString(), "HHmm");
|
||||
}
|
||||
|
||||
bool NotificationGlobalSettings::DNDWhileMultiScreen()
|
||||
{
|
||||
return d->m_settings.value(SettingsPropertiesInfo(SettingsProperty::DNDWhileMultiScreen).name()).toBool();
|
||||
}
|
||||
|
||||
bool NotificationGlobalSettings::DNDWhileFullScreen()
|
||||
{
|
||||
return d->m_settings.value(SettingsPropertiesInfo(SettingsProperty::DNDWhileFullScreen).name()).toBool();
|
||||
}
|
||||
|
||||
bool NotificationGlobalSettings::notifyAlarmWhileDND()
|
||||
{
|
||||
return d->m_settings.value(SettingsPropertiesInfo(SettingsProperty::NotifyAlarmWhileDND).name()).toBool();
|
||||
}
|
||||
|
||||
bool NotificationGlobalSettings::receiveNotificationsFromApps()
|
||||
{
|
||||
return d->m_settings.value(SettingsPropertiesInfo(SettingsProperty::ReceiveNotificationsFromApps).name()).toBool();
|
||||
}
|
||||
|
||||
void NotificationGlobalSettings::settingsDataChanged()
|
||||
{
|
||||
QJsonObject data = SettingsManager::self()->getGlobalSettings();
|
||||
for(SettingsProperty::Property property : GLOBAL_SETTINGS) {
|
||||
QString name = SettingsPropertiesInfo(property).name();
|
||||
QJsonValue value = data.value(name);
|
||||
if(d->m_settings.value(name) != value) {
|
||||
d->m_settings.insert(name, value);
|
||||
}
|
||||
switch (property) {
|
||||
case SettingsProperty::ScheduleTurnOnDND:
|
||||
Q_EMIT scheduleTurnOnDNDChanged(value.toBool());
|
||||
case SettingsProperty::ScheduleTurnOnDNDTime:
|
||||
Q_EMIT scheduleTurnOnDNDTimeChanged(QTime::fromString(value.toString(), "HHmm"));
|
||||
case SettingsProperty::ScheduleTurnOffDNDTime:
|
||||
Q_EMIT scheduleTurnOffDNDTimeChanged(QTime::fromString(value.toString(), "HHmm"));
|
||||
case SettingsProperty::DNDWhileMultiScreen:
|
||||
Q_EMIT DNDWhileMultiScreenChanged(value.toBool());
|
||||
case SettingsProperty::DNDWhileFullScreen:
|
||||
Q_EMIT DNDWhileFullScreenChanged(value.toBool());
|
||||
case SettingsProperty::NotifyAlarmWhileDND:
|
||||
Q_EMIT notifyAlarmWhileDNDChanged(value.toBool());
|
||||
case SettingsProperty::ReceiveNotificationsFromApps:
|
||||
Q_EMIT receiveNotificationsFromAppsChanged(value.toBool());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationGlobalSettings::setScheduleTurnOnDND(bool enable)
|
||||
{
|
||||
SettingsManager::self()->setGlobalSettings(SettingsProperty::ScheduleTurnOnDND, enable);
|
||||
}
|
||||
|
||||
void NotificationGlobalSettings::setScheduleTurnOnDNDTime(const QTime &time)
|
||||
{
|
||||
SettingsManager::self()->setGlobalSettings(SettingsProperty::ScheduleTurnOnDNDTime, time);
|
||||
}
|
||||
|
||||
void NotificationGlobalSettings::setScheduleTurnOffDNDTime(const QTime &time)
|
||||
{
|
||||
SettingsManager::self()->setGlobalSettings(SettingsProperty::ScheduleTurnOffDNDTime, time);
|
||||
}
|
||||
|
||||
void NotificationGlobalSettings::setDNDWhileMultiScreen(bool enable)
|
||||
{
|
||||
SettingsManager::self()->setGlobalSettings(SettingsProperty::DNDWhileMultiScreen, enable);
|
||||
}
|
||||
|
||||
void NotificationGlobalSettings::setDNDWhileFullScreen(bool enable)
|
||||
{
|
||||
SettingsManager::self()->setGlobalSettings(SettingsProperty::DNDWhileFullScreen, enable);
|
||||
}
|
||||
|
||||
void NotificationGlobalSettings::setNotifyAlarmWhileDND(bool enable)
|
||||
{
|
||||
SettingsManager::self()->setGlobalSettings(SettingsProperty::NotifyAlarmWhileDND, enable);
|
||||
}
|
||||
|
||||
void NotificationGlobalSettings::setReceiveNotificationsFromApps(bool enable)
|
||||
{
|
||||
SettingsManager::self()->setGlobalSettings(SettingsProperty::ReceiveNotificationsFromApps, enable);
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
//
|
||||
// Created by zpf on 2023/2/20.
|
||||
//
|
||||
|
||||
#ifndef UKUI_NOTIFICATION_NOTIFICATION_GLOBAL_SETTINGS_H
|
||||
#define UKUI_NOTIFICATION_NOTIFICATION_GLOBAL_SETTINGS_H
|
||||
#include <QObject>
|
||||
#include "settings-properties.h"
|
||||
namespace UkuiNotification {
|
||||
class NotificationGlobalSettingsPrivate;
|
||||
class NotificationGlobalSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool scheduleTurnOnDND READ scheduleTurnOnDND WRITE setScheduleTurnOnDND NOTIFY scheduleTurnOnDNDChanged)
|
||||
Q_PROPERTY(QTime scheduleTurnOnDNDTime READ scheduleTurnOnDNDTime WRITE setScheduleTurnOnDNDTime NOTIFY scheduleTurnOnDNDTimeChanged)
|
||||
Q_PROPERTY(QTime scheduleTurnOffDNDTime READ scheduleTurnOffDNDTime WRITE setScheduleTurnOffDNDTime NOTIFY scheduleTurnOffDNDTimeChanged)
|
||||
Q_PROPERTY(bool DNDWhileMultiScreen READ DNDWhileMultiScreen WRITE setDNDWhileMultiScreen NOTIFY DNDWhileMultiScreenChanged)
|
||||
Q_PROPERTY(bool DNDWhileFullScreen READ DNDWhileFullScreen WRITE setDNDWhileFullScreen NOTIFY DNDWhileFullScreenChanged)
|
||||
Q_PROPERTY(bool notifyAlarmWhileDND READ notifyAlarmWhileDND WRITE setNotifyAlarmWhileDND NOTIFY notifyAlarmWhileDNDChanged)
|
||||
Q_PROPERTY(bool receiveNotificationsFromApps READ receiveNotificationsFromApps WRITE setReceiveNotificationsFromApps NOTIFY receiveNotificationsFromAppsChanged)
|
||||
|
||||
public:
|
||||
NotificationGlobalSettings(QObject *parent);
|
||||
~NotificationGlobalSettings();
|
||||
/**
|
||||
* 自动开启勿扰模式
|
||||
* @return true 自动开启 false 关闭
|
||||
*/
|
||||
bool scheduleTurnOnDND();
|
||||
void setScheduleTurnOnDND(bool enable);
|
||||
/**
|
||||
* 自动开启勿扰模式时间
|
||||
* @return
|
||||
*/
|
||||
QTime scheduleTurnOnDNDTime();
|
||||
void setScheduleTurnOnDNDTime(const QTime &time);
|
||||
/**
|
||||
* 自动关闭勿扰模式时间
|
||||
* @return
|
||||
*/
|
||||
QTime scheduleTurnOffDNDTime();
|
||||
void setScheduleTurnOffDNDTime(const QTime &time);
|
||||
/**
|
||||
* 多屏连接时自动开启勿扰模式
|
||||
* @return
|
||||
*/
|
||||
bool DNDWhileMultiScreen();
|
||||
void setDNDWhileMultiScreen(bool enable);
|
||||
/**
|
||||
* 全屏模式下自动开启勿扰模式
|
||||
* @return
|
||||
*/
|
||||
bool DNDWhileFullScreen();
|
||||
void setDNDWhileFullScreen(bool enable);
|
||||
/**
|
||||
* 勿扰模式下允许闹钟提示
|
||||
* @return
|
||||
*/
|
||||
bool notifyAlarmWhileDND();
|
||||
void setNotifyAlarmWhileDND(bool enable);
|
||||
/**
|
||||
* 获取来自应用的通知
|
||||
* @return
|
||||
*/
|
||||
bool receiveNotificationsFromApps();
|
||||
void setReceiveNotificationsFromApps(bool enable);
|
||||
Q_SIGNALS:
|
||||
void scheduleTurnOnDNDChanged(bool);
|
||||
void scheduleTurnOnDNDTimeChanged(QTime);
|
||||
void scheduleTurnOffDNDTimeChanged(QTime);
|
||||
void DNDWhileMultiScreenChanged(bool);
|
||||
void DNDWhileFullScreenChanged(bool);
|
||||
void notifyAlarmWhileDNDChanged(bool);
|
||||
void receiveNotificationsFromAppsChanged(bool);
|
||||
|
||||
private Q_SLOTS:
|
||||
void settingsDataChanged();
|
||||
private:
|
||||
NotificationGlobalSettingsPrivate *d = nullptr;
|
||||
};
|
||||
|
||||
} // UkuiNotification
|
||||
|
||||
#endif //UKUI_NOTIFICATION_NOTIFICATION_GLOBAL_SETTINGS_H
|
|
@ -1,178 +0,0 @@
|
|||
//
|
||||
//
|
||||
//
|
||||
#include "notification-settings-info.h"
|
||||
#include <QLocale>
|
||||
|
||||
using namespace UkuiNotification;
|
||||
|
||||
class UkuiNotification::NotificationSettingsInfoPrivate
|
||||
{
|
||||
public:
|
||||
Property prop;
|
||||
QString name;
|
||||
QString displayName;
|
||||
QVariant::Type valueType;
|
||||
QString defulatValue; //TODO 使用qstring存还是改为模板取对应类型存储?
|
||||
};
|
||||
|
||||
NotificationSettingsInfo::NotificationSettingsInfo():d(new NotificationSettingsInfoPrivate)
|
||||
{
|
||||
d->prop = Property::Empty;
|
||||
d->name = QStringLiteral("empty");
|
||||
d->valueType = QVariant::Invalid;
|
||||
}
|
||||
|
||||
NotificationSettingsInfo::NotificationSettingsInfo(Property property)
|
||||
: d(new NotificationSettingsInfoPrivate)
|
||||
{
|
||||
d->prop = property;
|
||||
|
||||
switch (property) {
|
||||
case Property::AutoStartDisturb:
|
||||
d->name = QStringLiteral("AutoStartDisturb");
|
||||
d->displayName = tr("AutoStartDisturb");
|
||||
d->valueType = QVariant::Bool;
|
||||
break;
|
||||
|
||||
case Property::AutoStartStartTime:
|
||||
d->name = QStringLiteral("AutoStartStartTime");
|
||||
d->displayName = tr("AutoStartStartTime");
|
||||
d->valueType = QVariant::String;
|
||||
break;
|
||||
|
||||
case Property::AutoStartEndTime:
|
||||
d->name = QStringLiteral("AutoStartEndTime");
|
||||
d->displayName = tr("AutoStartEndTime");
|
||||
d->valueType = QVariant::String;
|
||||
break;
|
||||
|
||||
case Property::ProjectionScreenDisturb:
|
||||
d->name = QStringLiteral("ProjectionScreenDisturb");
|
||||
d->displayName = tr("ProjectionScreenDisturb");
|
||||
d->valueType = QVariant::Bool;
|
||||
break;
|
||||
|
||||
case Property::FullScreenDisturb:
|
||||
d->name = QStringLiteral("FullScreenDisturb");
|
||||
d->displayName = tr("FullScreenDisturb");
|
||||
d->valueType = QVariant::Bool;
|
||||
break;
|
||||
|
||||
case Property::AlarmClockDisturb:
|
||||
d->name = QStringLiteral("AlarmClockDisturb");
|
||||
d->displayName = tr("AlarmClockDisturb");
|
||||
d->valueType = QVariant::Bool;
|
||||
break;
|
||||
|
||||
case Property::AppNotificationDisturb:
|
||||
d->name = QStringLiteral("AppNotificationDisturb");
|
||||
d->displayName = tr("AppNotificationDisturb");
|
||||
d->valueType = QVariant::Bool;
|
||||
break;
|
||||
|
||||
// case Property::ApplicationName:
|
||||
// d->name = QStringLiteral("ApplicationName");
|
||||
// d->displayName = tr("ApplicationName");
|
||||
// d->valueType = QVariant::Bool;
|
||||
// break;
|
||||
|
||||
case Property::OnOff:
|
||||
d->name = QStringLiteral("OnOff");
|
||||
d->displayName = tr("OnOff");
|
||||
d->valueType = QVariant::Bool;
|
||||
break;
|
||||
|
||||
case Property::voiceOn:
|
||||
d->name = QStringLiteral("voiceOn");
|
||||
d->displayName = tr("voiceOn");
|
||||
d->valueType = QVariant::Bool;
|
||||
break;
|
||||
|
||||
case Property::voiceFilePath:
|
||||
d->name = QStringLiteral("voiceFilePath");
|
||||
d->displayName = tr("voiceFilePath");
|
||||
d->valueType = QVariant::String;
|
||||
break;
|
||||
|
||||
case Property::ShowContentOnScreenlock:
|
||||
d->name = QStringLiteral("ShowContentOnScreenlock");
|
||||
d->displayName = tr("ShowContentOnScreenlock");
|
||||
d->valueType = QVariant::Bool;
|
||||
break;
|
||||
|
||||
case Property::ShowOnScreenlock:
|
||||
d->name = QStringLiteral("ShowOnScreenlock");
|
||||
d->displayName = tr("ShowOnScreenlock");
|
||||
d->valueType = QVariant::Bool;
|
||||
break;
|
||||
|
||||
case Property::Style:
|
||||
d->name = QStringLiteral("Style");
|
||||
d->displayName = tr("Style");
|
||||
d->valueType = QVariant::Int;
|
||||
break;
|
||||
// NOTE: new properties must also be added to ::fromName()
|
||||
}
|
||||
}
|
||||
|
||||
NotificationSettingsInfo::NotificationSettingsInfo(const NotificationSettingsInfo& pi)
|
||||
: d(new NotificationSettingsInfoPrivate(*pi.d))
|
||||
{
|
||||
}
|
||||
|
||||
NotificationSettingsInfo::~NotificationSettingsInfo() = default;
|
||||
|
||||
NotificationSettingsInfo& NotificationSettingsInfo::operator=(const NotificationSettingsInfo& rhs)
|
||||
{
|
||||
*d = *rhs.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool NotificationSettingsInfo::operator==(const NotificationSettingsInfo& rhs) const
|
||||
{
|
||||
return d->name == rhs.d->name && d->displayName == rhs.d->displayName &&
|
||||
d->prop == rhs.d->prop && d->valueType == rhs.d->valueType;
|
||||
}
|
||||
|
||||
QString NotificationSettingsInfo::displayName() const
|
||||
{
|
||||
return d->displayName;
|
||||
}
|
||||
|
||||
QString NotificationSettingsInfo::name() const
|
||||
{
|
||||
return d->name;
|
||||
}
|
||||
|
||||
Property NotificationSettingsInfo::property() const
|
||||
{
|
||||
return d->prop;
|
||||
}
|
||||
|
||||
QVariant::Type NotificationSettingsInfo::valueType() const
|
||||
{
|
||||
return d->valueType;
|
||||
}
|
||||
|
||||
NotificationSettingsInfo NotificationSettingsInfo::fromName(const QString& name)
|
||||
{
|
||||
static QHash<QString, Property> propertyHash = {
|
||||
{ QStringLiteral("AutoStartDisturb"), Property::AutoStartDisturb },
|
||||
{ QStringLiteral("AutoStartStartTime"), Property::AutoStartStartTime },
|
||||
{ QStringLiteral("AutoStartEndTime"), Property::AutoStartEndTime },
|
||||
{ QStringLiteral("ProjectionScreenDisturb"), Property::ProjectionScreenDisturb },
|
||||
{ QStringLiteral("FullScreenDisturb"), Property::FullScreenDisturb },
|
||||
{ QStringLiteral("AlarmClockDisturb"), Property::AlarmClockDisturb },
|
||||
{ QStringLiteral("AppNotificationDisturb"), Property::AppNotificationDisturb },
|
||||
//{ QStringLiteral("ApplicationName"), Property::ApplicationName },
|
||||
{ QStringLiteral("OnOff"), Property::OnOff },
|
||||
{ QStringLiteral("voiceOn"), Property::voiceOn },
|
||||
{ QStringLiteral("voiceFilePath"), Property::voiceFilePath },
|
||||
{ QStringLiteral("ShowContentOnScreenlock"), Property::ShowContentOnScreenlock },
|
||||
{ QStringLiteral("ShowOnScreenlock"), Property::ShowOnScreenlock },
|
||||
{ QStringLiteral("Style"), Property::Style },
|
||||
};
|
||||
|
||||
return NotificationSettingsInfo(propertyHash.value(name));
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
//
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef _UKUINOTIFICATION_SETTINGS_INFO_H
|
||||
#define _UKUINOTIFICATION_SETTINGS_INFO_H
|
||||
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
#include <QObject>
|
||||
#include "notification-settings-properties.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace UkuiNotification {
|
||||
|
||||
class NotificationSettingsInfoPrivate;
|
||||
/**
|
||||
* \class NotificationSettingsInfo NotificationSettingsInfo.h
|
||||
*
|
||||
* The NotificationSettingsInfo class can be used to obtain extra information
|
||||
* about any property. It is commonly used be indexers in order
|
||||
* to obtain a translatable name of the property along with
|
||||
* additional information such as if the property should be indexed.
|
||||
*/
|
||||
class Q_DECL_IMPORT NotificationSettingsInfo : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
NotificationSettingsInfo();
|
||||
NotificationSettingsInfo(Property property);
|
||||
NotificationSettingsInfo(const NotificationSettingsInfo& pi);
|
||||
~NotificationSettingsInfo();
|
||||
|
||||
NotificationSettingsInfo& operator=(const NotificationSettingsInfo& rhs);
|
||||
bool operator==(const NotificationSettingsInfo& rhs) const;
|
||||
|
||||
/**
|
||||
* The enumeration which represents this property
|
||||
*/
|
||||
Property property() const;
|
||||
|
||||
/**
|
||||
* The internal unique name used to refer to the property
|
||||
*/
|
||||
QString name() const;
|
||||
|
||||
/**
|
||||
* A user visible name of the property
|
||||
*/
|
||||
QString displayName() const;
|
||||
|
||||
/**
|
||||
* The type the value of this property should be.
|
||||
* Eg - Property::Height should be an integer
|
||||
*/
|
||||
QVariant::Type valueType() const;
|
||||
|
||||
/**
|
||||
* Construct a NotificationSettingsInfo from the internal property name.
|
||||
* The internal property name is case insensitive
|
||||
*/
|
||||
static NotificationSettingsInfo fromName(const QString& name);
|
||||
|
||||
private:
|
||||
const std::unique_ptr<NotificationSettingsInfoPrivate> d;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
Q_DECLARE_METATYPE(UkuiNotification::NotificationSettingsInfo)
|
||||
|
||||
|
||||
#endif // _UKUINOTIFICATION_SETTINGS_INFO_H
|
|
@ -1,83 +0,0 @@
|
|||
//
|
||||
//
|
||||
//
|
||||
#ifndef NotificationSettingsPrivate_H
|
||||
#define NotificationSettingsPrivate_H
|
||||
|
||||
#include "notification-settings/notification-settings.h"
|
||||
#include "ukui-search/UkuiSearchAppInfoTable"
|
||||
|
||||
namespace UkuiNotification {
|
||||
|
||||
#define NOTIFICATION_SETTINGS_FILE_PATH ".config/ukui-notification/"
|
||||
#define NOTIFICATION_SETTINGS_FILE_NAME "settings.json"
|
||||
|
||||
#define NOTIFICATION_SETTINGS_VERSION "1.0"
|
||||
|
||||
using namespace UkuiSearch;
|
||||
|
||||
class NotificationSettingsPrivate : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
NotificationSettingsPrivate(NotificationSettings::RoleType role, NotificationSettings* parent);
|
||||
~NotificationSettingsPrivate();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief checkSettingsFile
|
||||
* 检查通知配置文件,不存在则初始化生成默认配置文件,存在则根据配置文件版本判断是否更新配置文件。
|
||||
*/
|
||||
void checkSettingsFile();
|
||||
|
||||
/**
|
||||
* @brief createSettingsFile
|
||||
* 初始化创建通知配置文件。
|
||||
*/
|
||||
void createSettingsFile();
|
||||
|
||||
/**
|
||||
* @brief updateSettingsFile
|
||||
* 更新通知配置文件。
|
||||
*/
|
||||
void updateSettingsFile();
|
||||
|
||||
/**
|
||||
* @brief getAppInfo
|
||||
* 从搜索应用数据库服务中获取desktop信息。
|
||||
* @param appInfo
|
||||
* appInfo中的key为QString类型的desktop文件路径,value为QStringList类型的数据集,目前依次包括local_name、icon,可扩展
|
||||
*/
|
||||
void getAppInfo(QMap<QString, QStringList> appInfoMap);
|
||||
|
||||
void getInitConfigData(QJsonDocument &jsonDocData);
|
||||
|
||||
void initAppDataServiceConnection();
|
||||
|
||||
public Q_SLOTS:
|
||||
|
||||
void desktopFileAdd(QVector<AppInfoResult> data);
|
||||
void desktopFileUpdate(QVector<AppInfoResult> data);
|
||||
void desktopFileDelete(QStringList data);
|
||||
|
||||
void settingsFileChanged();
|
||||
|
||||
private:
|
||||
|
||||
void initSettingsFileWatchConnections();
|
||||
void loadSettingsData();
|
||||
void save2SettingsFile(QString fileName, QJsonDocument &jsonDocData);
|
||||
|
||||
NotificationSettings::RoleType m_role;
|
||||
QVariantMap m_disturbSettings;
|
||||
QMap<QString, QVariantMap> m_allAppSettingsMap;
|
||||
|
||||
AppInfoTable * m_appDataServiceClient = nullptr;
|
||||
|
||||
NotificationSettings * q = nullptr;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // NotificationSettingsPrivate_H
|
|
@ -1,48 +0,0 @@
|
|||
//
|
||||
//
|
||||
//
|
||||
#ifndef UKUINOTIFICATION_SETTINGS_PROPERTIES
|
||||
#define UKUINOTIFICATION_SETTINGS_PROPERTIES
|
||||
#include <QMap>
|
||||
#include <QVariant>
|
||||
|
||||
namespace UkuiNotification {
|
||||
|
||||
/**
|
||||
* @brief The Property enum contains all settings property types
|
||||
*
|
||||
*/
|
||||
enum Property {
|
||||
Empty = 0,
|
||||
|
||||
AutoStartDisturb, //是否在时间段内自动开启勿扰模式,bool类型,默认值false
|
||||
AutoStartStartTime, //勿扰模式开启时间,QString类型,默认值00:00
|
||||
AutoStartEndTime, //勿扰模式结束时间,QString类型,默认值00:00
|
||||
ProjectionScreenDisturb, //多屏启动时是否启动勿扰模式,bool类型,默认值false
|
||||
FullScreenDisturb, //全屏状态下是否启动勿扰模式,bool类型,默认值false
|
||||
AlarmClockDisturb, //勿扰模式下是否允许闹钟提示,bool类型,默认值false
|
||||
AppNotificationDisturb, //是否获取来自应用程序的通知,bool类型,默认值true
|
||||
|
||||
//single app notification settings
|
||||
//ApplicationName,
|
||||
OnOff, //是否接收当前应用通知,bool类型,默认值true
|
||||
voiceOn, //是否打开通知提示声,bool类型,默认值true
|
||||
voiceFilePath, //自定义提示声文件位置,QString类型,默认值为空
|
||||
ShowContentOnScreenlock, //锁屏界面是否显示通知内容信息,bool类型,默认值false
|
||||
ShowOnScreenlock, //锁屏界面是否显示通知,bool类型,默认值false
|
||||
Style, //通知样式,appNotificationStyle类型,默认值Mutative
|
||||
|
||||
//single app notification settings中的 Style 类型取值范围
|
||||
Mutative, //横幅模式,显示在右上角,会自动消失
|
||||
Always, //提示模式,会保留在屏幕上,直到被关闭
|
||||
None //无,通知不会显示在屏幕上,但是会进入通知中心
|
||||
};
|
||||
|
||||
typedef QMap<Property, QVariant> PropertyMap;
|
||||
using PropertyMultiMap = QMultiMap<Property, QVariant>;
|
||||
|
||||
} // namespace UkuiNotification
|
||||
|
||||
Q_DECLARE_METATYPE(UkuiNotification::Property)
|
||||
|
||||
#endif
|
|
@ -1,147 +0,0 @@
|
|||
//
|
||||
//
|
||||
//
|
||||
#include "notification-settings-server.h"
|
||||
#include <QMetaEnum>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QDebug>
|
||||
|
||||
using namespace UkuiNotification;
|
||||
|
||||
NotificationSettingsPrivate::NotificationSettingsPrivate()
|
||||
:NotificationSettings(NotificationSettings::RoleType::SERVICE)
|
||||
,m_appDataServiceClient(new AppInfoTable(this))
|
||||
{
|
||||
checkSettingsFile();
|
||||
}
|
||||
|
||||
NotificationSettingsPrivate::~NotificationSettingsPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::checkSettingsFile()
|
||||
{
|
||||
QFile settingsFile(QDir::homePath() + "/" + NOTIFICATION_SETTINGS_FILE_PATH + NOTIFICATION_SETTINGS_FILE_NAME);
|
||||
if (!settingsFile.exists()) {
|
||||
createSettingsFile();
|
||||
}
|
||||
|
||||
if (!settingsFile.open(QFile::ReadOnly)) {
|
||||
qWarning() << "NotificationSettingsPrivate: configuration file " << settingsFile.fileName() << "open failed !";
|
||||
return;
|
||||
}
|
||||
// 读取json数据
|
||||
QByteArray byteArray = settingsFile.readAll();
|
||||
settingsFile.close();
|
||||
QJsonParseError errRpt;
|
||||
QJsonDocument jsonDocument(QJsonDocument::fromJson(byteArray, &errRpt));
|
||||
if (errRpt.error != QJsonParseError::NoError) {
|
||||
qWarning() << "NotificationSettingsPrivate: Incorrect configuration files. JSON parse error";
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取到Json字符串的根节点
|
||||
QJsonObject rootObject = jsonDocument.object();
|
||||
QString version = rootObject.find("VERSION").value().toString();
|
||||
if (version != QString(NOTIFICATION_SETTINGS_VERSION)) {
|
||||
qDebug() << "Notification settings version is diffrent, need update! configFile:" << version << " new:" << NOTIFICATION_SETTINGS_VERSION;
|
||||
updateSettingsFile();
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::createSettingsFile()
|
||||
{
|
||||
QDir dir;
|
||||
QString configFileDir(QDir::homePath() + "/" + NOTIFICATION_SETTINGS_FILE_PATH);
|
||||
if (!dir.exists(configFileDir)) {
|
||||
if (!dir.mkdir(configFileDir)) {
|
||||
qWarning() << "Unable to create notification settings config file.";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QFile settingsFile(QDir::homePath() + "/" + NOTIFICATION_SETTINGS_FILE_PATH + NOTIFICATION_SETTINGS_FILE_NAME);
|
||||
settingsFile.open(QFile::WriteOnly);
|
||||
QJsonDocument configData;
|
||||
getInitConfigData(configData);
|
||||
if (settingsFile.write(configData.toJson()) == -1) {
|
||||
qWarning() << "NotificationSettingsPrivate: Error saving configuration file.";
|
||||
}
|
||||
settingsFile.flush();
|
||||
settingsFile.close();
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::updateSettingsFile()
|
||||
{
|
||||
//TODO 考虑不同版本设置项名称修改或扩展,考虑高低版本互相切换逻辑保留用户配置
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::getAppInfo(QMap<QString, QStringList> appInfoMap)
|
||||
{
|
||||
QVector<AppInfoResult> appInfoResults;
|
||||
if (!m_appDataServiceClient->getAppInfoResults(appInfoResults)) {
|
||||
qWarning() << "NotificationSettingsPrivate: Error getAppInfoResults." << m_appDataServiceClient->lastError();
|
||||
return;
|
||||
}
|
||||
for (AppInfoResult &appInfo : appInfoResults) {
|
||||
appInfoMap.insert(appInfo.desktopPath, QStringList() << appInfo.appLocalName << appInfo.iconName);
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::getInitConfigData(QJsonDocument &jsonDocData)
|
||||
{
|
||||
QJsonArray settingsDataArray;
|
||||
QJsonObject rootObject;
|
||||
rootObject.insert("VERSION", QString(NOTIFICATION_SETTINGS_VERSION));
|
||||
rootObject.insert(QString(this->disturbMetaEnum().valueToKey(DisturbSettingsName::AutoStartDisturb)), "false");
|
||||
rootObject.insert(QString(this->disturbMetaEnum().valueToKey(DisturbSettingsName::AutoStartStartTime)), "00:00");
|
||||
rootObject.insert(QString(this->disturbMetaEnum().valueToKey(DisturbSettingsName::AutoStartEndTime)), "00:00");
|
||||
rootObject.insert(QString(this->disturbMetaEnum().valueToKey(DisturbSettingsName::ProjectionScreenDisturb)), "false");
|
||||
rootObject.insert(QString(this->disturbMetaEnum().valueToKey(DisturbSettingsName::FullScreenDisturb)), "false");
|
||||
rootObject.insert(QString(this->disturbMetaEnum().valueToKey(DisturbSettingsName::AlarmClockDisturb)), "false");
|
||||
rootObject.insert(QString(this->disturbMetaEnum().valueToKey(DisturbSettingsName::AppNotificationDisturb)), "true");
|
||||
|
||||
QMap<QString, QStringList> appInfoMap;
|
||||
getAppInfo(appInfoMap);
|
||||
for (auto &appInfoPair : appInfoMap) {
|
||||
QJsonObject appObject;
|
||||
appObject.insert(QString(this->appNotificationSettingsMetaEnum().valueToKey(AppNotificationSettingsName::OnOff)), "true");
|
||||
appObject.insert(QString(this->appNotificationSettingsMetaEnum().valueToKey(AppNotificationSettingsName::voiceOn)), "true");
|
||||
appObject.insert(QString(this->appNotificationSettingsMetaEnum().valueToKey(AppNotificationSettingsName::voiceFilePath)), "");
|
||||
appObject.insert(QString(this->appNotificationSettingsMetaEnum().valueToKey(AppNotificationSettingsName::ShowContentOnScreenlock)), "false");
|
||||
appObject.insert(QString(this->appNotificationSettingsMetaEnum().valueToKey(AppNotificationSettingsName::ShowOnScreenlock)), "false");
|
||||
appObject.insert(QString(this->appNotificationSettingsMetaEnum().valueToKey(AppNotificationSettingsName::Style)), QString(this->appNotificationStyleMetaEnum().valueToKey(AppNotificationStyle::Mutative)));
|
||||
rootObject.insert(appInfoPair.first(), appObject);
|
||||
}
|
||||
settingsDataArray.append(rootObject);
|
||||
jsonDocData.setArray(settingsDataArray);
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::initAppDataServiceConnection()
|
||||
{
|
||||
connect(m_appDataServiceClient, &AppInfoTable::DBOpenFailed, this, [&] (){
|
||||
qWarning() << "NotificationSettingsPrivate: app database server open failed! " << m_appDataServiceClient->lastError();
|
||||
});
|
||||
connect(m_appDataServiceClient, &AppInfoTable::appDBItems2BAdd, this, &NotificationSettingsPrivate::desktopFileAdd);
|
||||
connect(m_appDataServiceClient, &AppInfoTable::appDBItems2BUpdate, this, &NotificationSettingsPrivate::desktopFileUpdate);
|
||||
connect(m_appDataServiceClient, &AppInfoTable::appDBItems2BDelete, this, &NotificationSettingsPrivate::desktopFileDelete);
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::desktopFileAdd(QVector<AppInfoResult> data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::desktopFileUpdate(QVector<AppInfoResult> data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::desktopFileDelete(QStringList data)
|
||||
{
|
||||
|
||||
}
|
|
@ -1,220 +0,0 @@
|
|||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include "notification-settings.h"
|
||||
#include "notification-settings-private.h"
|
||||
#include "notification-settings-properties.h"
|
||||
#include "notification-settings-info.h"
|
||||
#include <QMetaEnum>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QDebug>
|
||||
using namespace UkuiNotification;
|
||||
|
||||
NotificationSettingsPrivate::NotificationSettingsPrivate(NotificationSettings::RoleType role, NotificationSettings* parent)
|
||||
:m_appDataServiceClient(new AppInfoTable(this))
|
||||
,m_role(role)
|
||||
,QObject(parent)
|
||||
,q(parent)
|
||||
{
|
||||
checkSettingsFile();
|
||||
if (m_role == NotificationSettings::RoleType::SERVICE) {
|
||||
initAppDataServiceConnection();
|
||||
} else if (m_role == NotificationSettings::RoleType::CLIENT) {
|
||||
loadSettingsData();
|
||||
initSettingsFileWatchConnections();
|
||||
}
|
||||
}
|
||||
|
||||
NotificationSettingsPrivate::~NotificationSettingsPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::checkSettingsFile()
|
||||
{
|
||||
QFile settingsFile(QDir::homePath() + "/" + NOTIFICATION_SETTINGS_FILE_PATH + NOTIFICATION_SETTINGS_FILE_NAME);
|
||||
if (!settingsFile.exists()) {
|
||||
createSettingsFile();
|
||||
}
|
||||
|
||||
if (!settingsFile.open(QFile::ReadOnly)) {
|
||||
qWarning() << "NotificationSettingsPrivate: configuration file " << settingsFile.fileName() << "open failed !";
|
||||
return;
|
||||
}
|
||||
// 读取json数据
|
||||
QByteArray byteArray = settingsFile.readAll();
|
||||
settingsFile.close();
|
||||
QJsonParseError errRpt;
|
||||
QJsonDocument jsonDocument(QJsonDocument::fromJson(byteArray, &errRpt));
|
||||
if (errRpt.error != QJsonParseError::NoError) {
|
||||
qWarning() << "NotificationSettingsPrivate: Incorrect configuration files. JSON parse error";
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取到Json字符串的根节点
|
||||
QJsonObject rootObject = jsonDocument.object();
|
||||
QString version = rootObject.find("VERSION").value().toString();
|
||||
if (version != QString(NOTIFICATION_SETTINGS_VERSION)) {
|
||||
qDebug() << "Notification settings version is diffrent, need update! configFile:" << version << " new:" << NOTIFICATION_SETTINGS_VERSION;
|
||||
updateSettingsFile();
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::createSettingsFile()
|
||||
{
|
||||
QDir dir;
|
||||
QString configFileDir(QDir::homePath() + "/" + NOTIFICATION_SETTINGS_FILE_PATH);
|
||||
if (!dir.exists(configFileDir)) {
|
||||
if (!dir.mkdir(configFileDir)) {
|
||||
qWarning() << "Unable to create notification settings config file.";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QFile settingsFile(QDir::homePath() + "/" + NOTIFICATION_SETTINGS_FILE_PATH + NOTIFICATION_SETTINGS_FILE_NAME);
|
||||
settingsFile.open(QFile::WriteOnly);
|
||||
QJsonDocument configData;
|
||||
getInitConfigData(configData);
|
||||
if (settingsFile.write(configData.toJson()) == -1) {
|
||||
qWarning() << "NotificationSettingsPrivate: Error saving configuration file.";
|
||||
}
|
||||
settingsFile.flush();
|
||||
settingsFile.close();
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::updateSettingsFile()
|
||||
{
|
||||
//TODO 考虑不同版本设置项名称修改或扩展,考虑高低版本互相切换逻辑保留用户配置
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::getAppInfo(QMap<QString, QStringList> appInfoMap)
|
||||
{
|
||||
QVector<AppInfoResult> appInfoResults;
|
||||
if (!m_appDataServiceClient->getAppInfoResults(appInfoResults)) {
|
||||
qWarning() << "NotificationSettingsPrivate: Error getAppInfoResults." << m_appDataServiceClient->lastError();
|
||||
return;
|
||||
}
|
||||
for (AppInfoResult &appInfo : appInfoResults) {
|
||||
appInfoMap.insert(appInfo.desktopPath, QStringList() << appInfo.appLocalName << appInfo.iconName);
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::getInitConfigData(QJsonDocument &jsonDocData)
|
||||
{
|
||||
QJsonArray settingsDataArray;
|
||||
QJsonObject rootObject;
|
||||
rootObject.insert("VERSION", QString(NOTIFICATION_SETTINGS_VERSION));
|
||||
rootObject.insert(NotificationSettingsInfo(Property::AutoStartDisturb).name(), "false");
|
||||
rootObject.insert(NotificationSettingsInfo(Property::AutoStartStartTime).name(), "00:00");
|
||||
rootObject.insert(NotificationSettingsInfo(Property::AutoStartEndTime).name(), "00:00");
|
||||
rootObject.insert(NotificationSettingsInfo(Property::ProjectionScreenDisturb).name(), "false");
|
||||
rootObject.insert(NotificationSettingsInfo(Property::FullScreenDisturb).name(), "false");
|
||||
rootObject.insert(NotificationSettingsInfo(Property::AlarmClockDisturb).name(), "false");
|
||||
rootObject.insert(NotificationSettingsInfo(Property::AppNotificationDisturb).name(), "true");
|
||||
|
||||
QMap<QString, QStringList> appInfoMap;
|
||||
getAppInfo(appInfoMap);
|
||||
for (auto &appInfoPair : appInfoMap) {
|
||||
QJsonObject appObject;
|
||||
appObject.insert(NotificationSettingsInfo(Property::OnOff).name(), "true");
|
||||
appObject.insert(NotificationSettingsInfo(Property::voiceOn).name(), "true");
|
||||
appObject.insert(NotificationSettingsInfo(Property::voiceFilePath).name(), "");
|
||||
appObject.insert(NotificationSettingsInfo(Property::ShowContentOnScreenlock).name(), "false");
|
||||
appObject.insert(NotificationSettingsInfo(Property::ShowOnScreenlock).name(), "false");
|
||||
appObject.insert(NotificationSettingsInfo(Property::Style).name(), NotificationSettingsInfo(Property::Mutative).name());
|
||||
rootObject.insert(appInfoPair.first(), appObject);
|
||||
}
|
||||
settingsDataArray.append(rootObject);
|
||||
jsonDocData.setArray(settingsDataArray);
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::initAppDataServiceConnection()
|
||||
{
|
||||
connect(m_appDataServiceClient, &AppInfoTable::DBOpenFailed, this, [&] (){
|
||||
qWarning() << "NotificationSettingsPrivate: app database server open failed! " << m_appDataServiceClient->lastError();
|
||||
});
|
||||
connect(m_appDataServiceClient, &AppInfoTable::appDBItems2BAdd, this, &NotificationSettingsPrivate::desktopFileAdd);
|
||||
connect(m_appDataServiceClient, &AppInfoTable::appDBItems2BUpdate, this, &NotificationSettingsPrivate::desktopFileUpdate);
|
||||
connect(m_appDataServiceClient, &AppInfoTable::appDBItems2BDelete, this, &NotificationSettingsPrivate::desktopFileDelete);
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::desktopFileAdd(QVector<AppInfoResult> data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::desktopFileUpdate(QVector<AppInfoResult> data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::desktopFileDelete(QStringList data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::initSettingsFileWatchConnections()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::loadSettingsData()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::save2SettingsFile(QString fileName, QJsonDocument &jsonDocData)
|
||||
{
|
||||
QFile file(fileName);
|
||||
if(!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
qWarning() << QString("NotificationSettings: Fail to open JSON file: %1, %2, %3").arg(__FILE__).arg(__LINE__).arg(__FUNCTION__);
|
||||
return;
|
||||
}
|
||||
QTextStream out(&file);
|
||||
out << jsonDocData.toJson(QJsonDocument::Indented);
|
||||
file.close();
|
||||
}
|
||||
|
||||
void NotificationSettingsPrivate::settingsFileChanged()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
NotificationSettings::NotificationSettings(NotificationSettings::RoleType role)
|
||||
{
|
||||
d = new NotificationSettingsPrivate(role, this);
|
||||
}
|
||||
|
||||
void NotificationSettings::getDisturbSettings(QVariantMap &disturbSettingsMap)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NotificationSettings::getAllAppSettings(QMap<QString, QVariantMap> &allAppSettingsMap)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NotificationSettings::getAppSettings(QString appDesktopName, QVariantMap &appSettingsMap)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NotificationSettings::setDisturbSettings(QString settingsName, QVariant value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NotificationSettings::setAppNotificationSettings(QString appDesktopPath, QString settingsName, QVariant value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
//
|
||||
//
|
||||
|
||||
#ifndef UKUI_NOTIFICATION_NOTIFICATION_SETTINGS_H
|
||||
#define UKUI_NOTIFICATION_NOTIFICATION_SETTINGS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QMap>
|
||||
#include <QVariantMap>
|
||||
namespace UkuiNotification {
|
||||
|
||||
class NotificationSettingsPrivate;
|
||||
class NotificationSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
enum RoleType {
|
||||
SERVICE = 0,
|
||||
CLIENT
|
||||
};
|
||||
Q_ENUM(RoleType)
|
||||
|
||||
public:
|
||||
NotificationSettings(NotificationSettings::RoleType role);
|
||||
~NotificationSettings() = default;
|
||||
|
||||
/**
|
||||
* @brief getDisturbSettings
|
||||
* 获取当前用户的勿扰模式配置信息。
|
||||
* @param disturbSettingsMap
|
||||
* disturbSettingsMap中的key为qstring类型的disturbSettingsName中的全部项目,例如:"AutoStartDisturb",
|
||||
* value为disturbSettingsName中每一项对应的类型数据,例如AutoStartDisturb对应的bool类型数据。
|
||||
*/
|
||||
void getDisturbSettings(QVariantMap &disturbSettingsMap);
|
||||
|
||||
/**
|
||||
* @brief getAllAppSettings
|
||||
* 获取当前用户全部应用通知相关配置信息。
|
||||
* @param allAppSettingsMap
|
||||
* allAppSettingsMap中的key为qstring类型的应用desktop文件路径内容,value为当前应用的配置项存储在QVariantMap中。
|
||||
* QVariantMap中的key为qstring类型的appNotificationSettingsName中的全部项目,例如:"OnOff",
|
||||
* value为appNotificationSettingsName中每一项对应的类型数据,例如OnOff对应的bool类型数据。
|
||||
*/
|
||||
void getAllAppSettings(QMap<QString, QVariantMap> &allAppSettingsMap);
|
||||
|
||||
/**
|
||||
* @brief getAppSettings
|
||||
* 获取当前用户某个应用通知相关配置信息。
|
||||
* @param appDesktopName
|
||||
* 指定查询的app,qstring类型的应用desktop文件路径内容
|
||||
* @param appSettingsMap
|
||||
* QVariantMap中的key为qstring类型的appNotificationSettingsName中的全部项目,例如:"OnOff",
|
||||
* value为appNotificationSettingsName中每一项对应的类型数据,例如OnOff对应的bool类型数据。
|
||||
*/
|
||||
void getAppSettings(QString appDesktopName, QVariantMap &appSettingsMap);
|
||||
|
||||
/**
|
||||
* @brief setSettings
|
||||
* 设置当前用户的某个勿扰相关配置信息
|
||||
* @param settingsName
|
||||
* disturbSettingsName中的各项内容
|
||||
* @param value
|
||||
* disturbSettingsName中的各项内容对应的类型数据
|
||||
*/
|
||||
void setDisturbSettings(QString settingsName, QVariant value);
|
||||
|
||||
/**
|
||||
* @brief setAppNotificationSettings
|
||||
* 设置当前用户的某个应用通知相关配置信息
|
||||
* @param appDesktopPath
|
||||
* 应用desktop文件路径信息
|
||||
* @param settingsName
|
||||
* 需要修改的应用配置项,包括appNotificationSettingsName中的各项配置名称
|
||||
* @param value
|
||||
* appNotificationSettingsName中的各项配置名称对应的类型数据
|
||||
*/
|
||||
void setAppNotificationSettings(QString appDesktopPath, QString settingsName, QVariant value);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
void settingsDataChanged();
|
||||
|
||||
private:
|
||||
|
||||
NotificationSettingsPrivate * d = nullptr;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,73 @@
|
|||
//
|
||||
//
|
||||
//
|
||||
#ifndef NotificationSettingsPrivate_H
|
||||
#define NotificationSettingsPrivate_H
|
||||
|
||||
#include "settings-manager.h"
|
||||
#include <UkuiSearchAppInfoTable>
|
||||
#include <QJsonObject>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QList>
|
||||
#include "settings-properties.h"
|
||||
|
||||
namespace UkuiNotification {
|
||||
|
||||
|
||||
#define NOTIFICATION_SETTINGS_VERSION "1.0"
|
||||
|
||||
class SettingsManagerPrivate : public QObject
|
||||
{
|
||||
friend class SettingsManager;
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SettingsManagerPrivate(QObject* parent = nullptr);
|
||||
~SettingsManagerPrivate();
|
||||
void init();
|
||||
|
||||
private Q_SLOTS:
|
||||
/**
|
||||
* @brief checkAndLoad
|
||||
* 检查通知配置文件,不存在则初始化生成默认配置文件,存在则根据配置文件版本判断是否更新配置文件。
|
||||
*/
|
||||
void checkAndLoad();
|
||||
private:
|
||||
/**
|
||||
* @brief createSettingsFile
|
||||
* 初始化创建通知配置文件。
|
||||
*/
|
||||
void createSettingsFile();
|
||||
|
||||
/**
|
||||
* @brief updateSettingsFile
|
||||
* 更新通知配置文件。
|
||||
*/
|
||||
void updateSettingsFile();
|
||||
|
||||
/**
|
||||
* @brief getAppInfo
|
||||
* 从搜索应用数据库服务中获取desktop信息。
|
||||
* @param appInfo
|
||||
* appInfo中的key为QString类型的desktop文件路径,value为QStringList类型的数据集,目前依次包括local_name、icon,可扩展
|
||||
*/
|
||||
void getAppInfo(QMap<QString, QStringList> appInfoMap);
|
||||
|
||||
void initSettingsData(QJsonObject &data);
|
||||
|
||||
public Q_SLOTS:
|
||||
void desktopFileAdd(const QVector<UkuiSearch::AppInfoResult> &data);
|
||||
void desktopFileDelete(const QStringList &data);
|
||||
Q_SIGNALS:
|
||||
void settingsUpdateFinished();
|
||||
void appUninstalled(const QString &desktopEntry);
|
||||
|
||||
private:
|
||||
void save2SettingsFile(const QJsonObject &jsonDocData);
|
||||
QJsonObject m_settingsData;
|
||||
QFileSystemWatcher *m_watcher = nullptr;
|
||||
UkuiSearch::AppInfoTable * m_appDataServiceClient = nullptr;
|
||||
QJsonObject m_applicationDefaultSettings;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // NotificationSettingsPrivate_H
|
|
@ -0,0 +1,323 @@
|
|||
//
|
||||
//
|
||||
//
|
||||
#include "settings-manager.h"
|
||||
#include "settings-manager-private.h"
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QDebug>
|
||||
#include <QList>
|
||||
#include <QLockFile>
|
||||
#include <QCoreApplication>
|
||||
#include <mutex>
|
||||
#include "settings-properties-info.h"
|
||||
|
||||
using namespace UkuiNotification;
|
||||
|
||||
static const QString SETTINGS_FILE_PATH = QDir::homePath() + QStringLiteral("/.config/org.ukui/ukui-notification");
|
||||
static const QString SETTINGS_FILE_PATH_NAME = SETTINGS_FILE_PATH + QStringLiteral("/ukui-notification-settings.json");
|
||||
static std::once_flag flag;
|
||||
static SettingsManager *s_self;
|
||||
SettingsManagerPrivate::SettingsManagerPrivate(QObject* parent) : QObject(parent)
|
||||
{
|
||||
for(SettingsProperty::Property property : SINGLE_APPLICATION_SETTINGS) {
|
||||
SettingsPropertiesInfo info(property);
|
||||
m_applicationDefaultSettings.insert(info.name(), info.defaultValue());
|
||||
}
|
||||
}
|
||||
|
||||
SettingsManagerPrivate::~SettingsManagerPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void SettingsManagerPrivate::init()
|
||||
{
|
||||
m_watcher = new QFileSystemWatcher(this);
|
||||
connect(m_watcher, &QFileSystemWatcher::fileChanged, this, &SettingsManagerPrivate::checkAndLoad);
|
||||
//TODO 应用数据服务接口更新中
|
||||
m_appDataServiceClient = new UkuiSearch::AppInfoTable(this);
|
||||
connect(m_appDataServiceClient, &UkuiSearch::AppInfoTable::DBOpenFailed, this, [&](){
|
||||
qWarning() << "SettingsManagerPrivate: app database server open failed! " << m_appDataServiceClient->lastError();
|
||||
});
|
||||
if (qApp->property("IS_UKUI_NOTIFICATION_SERVICE").toBool()) {
|
||||
connect(m_appDataServiceClient, &UkuiSearch::AppInfoTable::appDBItems2BAdd, this,
|
||||
&SettingsManagerPrivate::desktopFileAdd);
|
||||
}
|
||||
connect(m_appDataServiceClient, &UkuiSearch::AppInfoTable::appDBItems2BDelete, this, &SettingsManagerPrivate::desktopFileDelete);
|
||||
checkAndLoad();
|
||||
}
|
||||
void SettingsManagerPrivate::checkAndLoad()
|
||||
{
|
||||
QLockFile lockFile(SETTINGS_FILE_PATH + QStringLiteral("ukui-notification-settings.json.lock"));
|
||||
lockFile.lock();
|
||||
QFile settingsFile(SETTINGS_FILE_PATH_NAME);
|
||||
if (!settingsFile.exists()) {
|
||||
createSettingsFile();
|
||||
lockFile.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!settingsFile.open(QFile::ReadOnly)) {
|
||||
qWarning() << "SettingsManagerPrivate: configuration file " << settingsFile.fileName() << "open failed !";
|
||||
m_watcher->addPath(SETTINGS_FILE_PATH_NAME);
|
||||
lockFile.unlock();
|
||||
return;
|
||||
}
|
||||
// 读取json数据
|
||||
QByteArray byteArray = settingsFile.readAll();
|
||||
settingsFile.close();
|
||||
QJsonParseError errRpt;
|
||||
QJsonDocument jsonDocument(QJsonDocument::fromJson(byteArray, &errRpt));
|
||||
if (errRpt.error != QJsonParseError::NoError) {
|
||||
qWarning() << "SettingsManagerPrivate: Incorrect configuration files. JSON parse error";
|
||||
createSettingsFile();
|
||||
lockFile.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
// 读取配置文件
|
||||
QJsonObject settingsData = jsonDocument.object();
|
||||
QString version = settingsData.find("VERSION").value().toString();
|
||||
if (version != QString(NOTIFICATION_SETTINGS_VERSION)) {
|
||||
qDebug() << "Notification settings version is different, need update! configFile:" << version << " new:" << NOTIFICATION_SETTINGS_VERSION;
|
||||
updateSettingsFile();
|
||||
} else {
|
||||
m_settingsData.swap(settingsData);
|
||||
Q_EMIT settingsUpdateFinished();
|
||||
}
|
||||
lockFile.unlock();
|
||||
}
|
||||
|
||||
void SettingsManagerPrivate::createSettingsFile()
|
||||
{
|
||||
initSettingsData(m_settingsData);
|
||||
save2SettingsFile(m_settingsData);
|
||||
Q_EMIT settingsUpdateFinished();
|
||||
m_watcher->addPath(SETTINGS_FILE_PATH_NAME);
|
||||
}
|
||||
|
||||
void SettingsManagerPrivate::updateSettingsFile()
|
||||
{
|
||||
m_watcher->removePath(SETTINGS_FILE_PATH_NAME);
|
||||
//初始化当前版本默认值
|
||||
QJsonObject newData;
|
||||
initSettingsData(newData);
|
||||
//同步全局配置
|
||||
QJsonObject newGlobalData = newData.value(QStringLiteral("Global")).toObject();
|
||||
QJsonObject oldGlobalData = m_settingsData.value(QStringLiteral("Global")).toObject();
|
||||
for(const QString &key : newGlobalData.keys()) {
|
||||
QJsonValue oldValue = oldGlobalData.value(key);
|
||||
if(!oldValue.isUndefined()) {
|
||||
newGlobalData.insert(key, oldValue);
|
||||
}
|
||||
}
|
||||
newData.insert(QStringLiteral("Global"), newGlobalData);
|
||||
//同步所有应用配置
|
||||
QJsonObject newApplicationsData = newData.value(QStringLiteral("Applications")).toObject();
|
||||
QJsonObject oldApplicationsData = m_settingsData.value(QStringLiteral("Applications")).toObject();
|
||||
for(const QString &desktopEntry : newApplicationsData.keys()) {
|
||||
if(oldApplicationsData.contains(desktopEntry)) {
|
||||
QJsonObject oldSingleAppData = oldApplicationsData.value(desktopEntry).toObject();
|
||||
QJsonObject newSingleAppData = newApplicationsData.value(desktopEntry).toObject();
|
||||
for(const QString &key : newSingleAppData.keys()) {
|
||||
QJsonValue oldValue = oldSingleAppData.value(key);
|
||||
if(!oldValue.isUndefined()) {
|
||||
newSingleAppData.insert(key, oldValue);
|
||||
}
|
||||
}
|
||||
newApplicationsData.insert(desktopEntry, newSingleAppData);
|
||||
}
|
||||
}
|
||||
newData.insert(QStringLiteral("Applications"), newApplicationsData);
|
||||
//写入数据
|
||||
m_settingsData.swap(newData);
|
||||
save2SettingsFile(m_settingsData);
|
||||
m_watcher->addPath(SETTINGS_FILE_PATH_NAME);
|
||||
Q_EMIT settingsUpdateFinished();
|
||||
}
|
||||
|
||||
void SettingsManagerPrivate::getAppInfo(QMap<QString, QStringList> appInfoMap)
|
||||
{
|
||||
QVector<UkuiSearch::AppInfoResult> appInfoResults;
|
||||
if (!m_appDataServiceClient->getAppInfoResults(appInfoResults)) {
|
||||
qWarning() << "SettingsManagerPrivate: Error getAppInfoResults." << m_appDataServiceClient->lastError();
|
||||
return;
|
||||
}
|
||||
for (UkuiSearch::AppInfoResult &appInfo : appInfoResults) {
|
||||
appInfoMap.insert(appInfo.desktopPath, QStringList() << appInfo.appLocalName << appInfo.iconName);
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsManagerPrivate::initSettingsData(QJsonObject &data)
|
||||
{
|
||||
data.insert("VERSION", QString(NOTIFICATION_SETTINGS_VERSION));
|
||||
|
||||
//全局设置
|
||||
QJsonObject globalSettings;
|
||||
for(SettingsProperty::Property property : GLOBAL_SETTINGS) {
|
||||
SettingsPropertiesInfo info(property);
|
||||
globalSettings.insert(info.name(), info.defaultValue());
|
||||
}
|
||||
data.insert(QStringLiteral("Global"), globalSettings);
|
||||
|
||||
//应用设置
|
||||
QJsonObject applicationsSettings;
|
||||
QMap<QString, QStringList> appInfoMap;
|
||||
getAppInfo(appInfoMap);
|
||||
for (auto &appInfoPair : appInfoMap) {
|
||||
applicationsSettings.insert(appInfoPair.first(), m_applicationDefaultSettings);
|
||||
}
|
||||
data.insert(QStringLiteral("Applications"), applicationsSettings);
|
||||
//TODO: 配置文件中增加应用local Name?
|
||||
}
|
||||
|
||||
void SettingsManagerPrivate::desktopFileAdd(const QVector<UkuiSearch::AppInfoResult> &data)
|
||||
{
|
||||
QJsonObject applicationsSettings = m_settingsData.value(QStringLiteral("Applications")).toObject();
|
||||
for (const UkuiSearch::AppInfoResult &ri : data) {
|
||||
applicationsSettings.insert(ri.desktopPath, m_applicationDefaultSettings);
|
||||
}
|
||||
m_settingsData.insert(QStringLiteral("Applications"), applicationsSettings);
|
||||
|
||||
QLockFile lockFile(SETTINGS_FILE_PATH + QStringLiteral("ukui-notification-settings.json.lock"));
|
||||
lockFile.lock();
|
||||
m_watcher->removePath(SETTINGS_FILE_PATH_NAME);
|
||||
save2SettingsFile(m_settingsData);
|
||||
m_watcher->addPath(SETTINGS_FILE_PATH_NAME);
|
||||
lockFile.unlock();
|
||||
Q_EMIT settingsUpdateFinished();
|
||||
}
|
||||
|
||||
void SettingsManagerPrivate::desktopFileDelete(const QStringList &data)
|
||||
{
|
||||
if (qApp->property("IS_UKUI_NOTIFICATION_SERVICE").toBool()) {
|
||||
QJsonObject applicationsSettings = m_settingsData.value(QStringLiteral("Applications")).toObject();
|
||||
for (const QString &app : data) {
|
||||
applicationsSettings.remove(app);
|
||||
}
|
||||
m_settingsData.insert(QStringLiteral("Applications"), applicationsSettings);
|
||||
QLockFile lockFile(SETTINGS_FILE_PATH + QStringLiteral("ukui-notification-settings.json.lock"));
|
||||
lockFile.lock();
|
||||
m_watcher->removePath(SETTINGS_FILE_PATH_NAME);
|
||||
save2SettingsFile(m_settingsData);
|
||||
m_watcher->addPath(SETTINGS_FILE_PATH_NAME);
|
||||
lockFile.unlock();
|
||||
Q_EMIT settingsUpdateFinished();
|
||||
}
|
||||
for(const QString &app : data) {
|
||||
Q_EMIT appUninstalled(app);
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsManagerPrivate::save2SettingsFile(const QJsonObject &jsonDocData)
|
||||
{
|
||||
QDir dir;
|
||||
QString configFileDir(SETTINGS_FILE_PATH);
|
||||
if (!dir.exists(configFileDir)) {
|
||||
if (!dir.mkdir(configFileDir)) {
|
||||
qWarning() << "Unable to create notification settings config file.";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QFile settingsFile(SETTINGS_FILE_PATH_NAME);
|
||||
settingsFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
||||
|
||||
if (settingsFile.write(QJsonDocument(jsonDocData).toJson()) == -1) {
|
||||
qWarning() << "SettingsManagerPrivate: Error saving configuration file.";
|
||||
}
|
||||
settingsFile.flush();
|
||||
settingsFile.close();
|
||||
}
|
||||
|
||||
SettingsManager::SettingsManager(QObject *parent) : QObject(parent), d(new SettingsManagerPrivate(this))
|
||||
{
|
||||
connect(d, &SettingsManagerPrivate::settingsUpdateFinished, this, &SettingsManager::settingsDataChanged);
|
||||
connect(d, &SettingsManagerPrivate::appUninstalled, this, &SettingsManager::appUninstalled);
|
||||
d->init();
|
||||
}
|
||||
|
||||
QJsonObject SettingsManager::getGlobalSettings()
|
||||
{
|
||||
return d->m_settingsData.value(QStringLiteral("Global")).toObject();
|
||||
}
|
||||
|
||||
QJsonObject SettingsManager::getAllAppSettings()
|
||||
{
|
||||
return d->m_settingsData.value(QStringLiteral("Applications")).toObject();
|
||||
}
|
||||
|
||||
QJsonObject SettingsManager::getAppSettings(const QString &appDesktopName)
|
||||
{
|
||||
if(appDesktopName == QStringLiteral("default") || appDesktopName.isEmpty()) {
|
||||
return d->m_applicationDefaultSettings;
|
||||
}
|
||||
QJsonValue value = d->m_settingsData.value(QStringLiteral("Applications")).toObject().value(appDesktopName);
|
||||
if(value.isUndefined()) {
|
||||
return {};
|
||||
}
|
||||
return value.toObject();
|
||||
}
|
||||
|
||||
|
||||
QJsonObject SettingsManager::getAppDefaultSettings()
|
||||
{
|
||||
return d->m_applicationDefaultSettings;
|
||||
}
|
||||
|
||||
SettingsManager *SettingsManager::self()
|
||||
{
|
||||
std::call_once(flag, [ & ] {
|
||||
s_self = new SettingsManager();
|
||||
});
|
||||
return s_self;
|
||||
}
|
||||
|
||||
bool SettingsManager::setGlobalSettings(SettingsProperty::Property key, const QVariant &value)
|
||||
{
|
||||
if(!GLOBAL_SETTINGS.contains(key)) {
|
||||
return false;
|
||||
}
|
||||
auto info = SettingsPropertiesInfo(key);
|
||||
QString valueToSet = info.valueToString(value);
|
||||
|
||||
QJsonObject data = d->m_settingsData.value(QStringLiteral("Global")).toObject();
|
||||
data.insert(info.name(), valueToSet);
|
||||
d->m_settingsData.insert(QStringLiteral("Global"), data);
|
||||
QLockFile lockFile(SETTINGS_FILE_PATH + QStringLiteral("ukui-notification-settings.json.lock"));
|
||||
lockFile.lock();
|
||||
d->save2SettingsFile(d->m_settingsData);
|
||||
lockFile.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SettingsManager::setAppSettings(const QString &appDesktopName, SettingsProperty::Property key, const QVariant &value)
|
||||
{
|
||||
if(!SINGLE_APPLICATION_SETTINGS.contains(key)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QJsonObject appsData = d->m_settingsData.value(QStringLiteral("Applications")).toObject();
|
||||
QJsonValue dataValue = appsData.value(appDesktopName);
|
||||
if(dataValue.isUndefined()) {
|
||||
return false;
|
||||
}
|
||||
QJsonObject oneAppData = dataValue.toObject();
|
||||
auto info = SettingsPropertiesInfo(key);
|
||||
QString valueToSet = info.valueToString(value);
|
||||
oneAppData.insert(info.name(), valueToSet);
|
||||
appsData.insert(appDesktopName, oneAppData);
|
||||
d->m_settingsData.insert(QStringLiteral("Applications"), appsData);
|
||||
|
||||
QLockFile lockFile(SETTINGS_FILE_PATH + QStringLiteral("ukui-notification-settings.json.lock"));
|
||||
lockFile.lock();
|
||||
d->save2SettingsFile(d->m_settingsData);
|
||||
lockFile.unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
//
|
||||
//
|
||||
|
||||
#ifndef SETTINGS_MANAGER_H
|
||||
#define SETTINGS_MANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include "settings-properties.h"
|
||||
|
||||
namespace UkuiNotification {
|
||||
|
||||
class SettingsManagerPrivate;
|
||||
class SettingsManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static SettingsManager *self();
|
||||
|
||||
~SettingsManager() = default;
|
||||
|
||||
/**
|
||||
* 获取全局配置
|
||||
*/
|
||||
QJsonObject getGlobalSettings();
|
||||
|
||||
/**
|
||||
* @brief getAllAppSettings
|
||||
* 获取当前用户全部应用通知相关配置信息。
|
||||
*/
|
||||
QJsonObject getAllAppSettings();
|
||||
|
||||
/**
|
||||
* @brief getAppSettings
|
||||
* 获取当前用户某个应用通知相关配置信息。
|
||||
* @param appDesktopName 传"default"获取配置默认值
|
||||
*/
|
||||
QJsonObject getAppSettings(const QString &appDesktopName);
|
||||
|
||||
/**
|
||||
* 获取应用通知设置默认值
|
||||
* @return
|
||||
*/
|
||||
QJsonObject getAppDefaultSettings();
|
||||
|
||||
bool setGlobalSettings(SettingsProperty::Property key, const QVariant &value);
|
||||
bool setAppSettings(const QString &appDesktopName, SettingsProperty::Property key, const QVariant &value);
|
||||
|
||||
Q_SIGNALS:
|
||||
void settingsDataChanged();
|
||||
void newAppInstalled(const QString &desktopEntry);
|
||||
void appUninstalled(const QString &desktopEntry);
|
||||
|
||||
private:
|
||||
SettingsManager(QObject *parent = nullptr);
|
||||
SettingsManagerPrivate * d = nullptr;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,221 @@
|
|||
//
|
||||
//
|
||||
//
|
||||
#include "settings-properties-info.h"
|
||||
#include <QLocale>
|
||||
#include <QTime>
|
||||
|
||||
using namespace UkuiNotification;
|
||||
|
||||
class UkuiNotification::SettingsPropertiesInfoPrivate
|
||||
{
|
||||
public:
|
||||
SettingsProperty::Property m_property;
|
||||
QString m_name;
|
||||
QString m_displayName;
|
||||
QMetaType::Type m_valueType;
|
||||
QString m_defaultValue;
|
||||
QMetaType::Type m_settingsPropertyMetaType;
|
||||
};
|
||||
|
||||
SettingsPropertiesInfo::SettingsPropertiesInfo(): d(new SettingsPropertiesInfoPrivate)
|
||||
{
|
||||
d->m_property = SettingsProperty::Invalid;
|
||||
d->m_name = QStringLiteral("Invalid");
|
||||
d->m_valueType = QMetaType::UnknownType;
|
||||
d->m_settingsPropertyMetaType = static_cast<QMetaType::Type>(QMetaType::type("UkuiNotification::SettingsProperty::Property"));
|
||||
}
|
||||
|
||||
SettingsPropertiesInfo::SettingsPropertiesInfo(SettingsProperty::Property property)
|
||||
: d(new SettingsPropertiesInfoPrivate)
|
||||
{
|
||||
d->m_property = property;
|
||||
|
||||
switch (property) {
|
||||
case SettingsProperty::ScheduleTurnOnDND:
|
||||
d->m_name = QStringLiteral("ScheduleTurnOnDND");
|
||||
d->m_displayName = tr("Schedule turn on");
|
||||
d->m_valueType = QMetaType::Bool;
|
||||
d->m_defaultValue = "false";
|
||||
break;
|
||||
|
||||
case SettingsProperty::ScheduleTurnOnDNDTime:
|
||||
d->m_name = QStringLiteral("ScheduleTurnOnDNDTime");
|
||||
d->m_displayName = tr("Schedule turn on time");
|
||||
d->m_valueType = QMetaType::QTime;
|
||||
d->m_defaultValue = "00:00";
|
||||
break;
|
||||
|
||||
case SettingsProperty::ScheduleTurnOffDNDTime:
|
||||
d->m_name = QStringLiteral("ScheduleTurnOffDNDTime");
|
||||
d->m_displayName = tr("Schedule turn off time");
|
||||
d->m_valueType = QMetaType::QTime;
|
||||
d->m_defaultValue = "00:00";
|
||||
break;
|
||||
|
||||
case SettingsProperty::DNDWhileMultiScreen:
|
||||
d->m_name = QStringLiteral("DNDWhileMultiScreen");
|
||||
d->m_displayName = tr("Turn on while multi-screen connected");
|
||||
d->m_valueType = QMetaType::Bool;
|
||||
d->m_defaultValue = "false";
|
||||
break;
|
||||
|
||||
case SettingsProperty::DNDWhileFullScreen:
|
||||
d->m_name = QStringLiteral("DNDWhileFullScreen");
|
||||
d->m_displayName = tr("Turn on in full screen mode");
|
||||
d->m_valueType = QMetaType::Bool;
|
||||
d->m_defaultValue = "false";
|
||||
break;
|
||||
|
||||
case SettingsProperty::NotifyAlarmWhileDND:
|
||||
d->m_name = QStringLiteral("NotifyAlarmWhileDND");
|
||||
d->m_displayName = tr("Allow alarm to notify in do not disturb mode");
|
||||
d->m_valueType = QMetaType::Bool;
|
||||
d->m_defaultValue = "false";
|
||||
break;
|
||||
|
||||
case SettingsProperty::ReceiveNotificationsFromApps:
|
||||
d->m_name = QStringLiteral("ReceiveNotificationsFromApps");
|
||||
d->m_displayName = tr("Get notifications from applications");
|
||||
d->m_valueType = QMetaType::Bool;
|
||||
d->m_defaultValue = "false";
|
||||
break;
|
||||
|
||||
case SettingsProperty::AllowNotify:
|
||||
d->m_name = QStringLiteral("AllowNotify");
|
||||
d->m_displayName = tr("Allow notify");
|
||||
d->m_valueType = QMetaType::Bool;
|
||||
d->m_defaultValue = "true";
|
||||
break;
|
||||
|
||||
case SettingsProperty::AllowSound:
|
||||
d->m_name = QStringLiteral("AllowSound");
|
||||
d->m_displayName = tr("Allow sound for notifications");
|
||||
d->m_valueType = QMetaType::Bool;
|
||||
d->m_defaultValue = "true";
|
||||
break;
|
||||
|
||||
case SettingsProperty::ShowContentOnLockScreen:
|
||||
d->m_name = QStringLiteral("ShowContentOnLockScreen");
|
||||
d->m_displayName = tr("Show notification content on lock screen");
|
||||
d->m_valueType = QMetaType::Bool;
|
||||
d->m_defaultValue = "false";
|
||||
break;
|
||||
|
||||
case SettingsProperty::ShowNotificationOnLockScreen:
|
||||
d->m_name = QStringLiteral("ShowNotificationOnLockScreen");
|
||||
d->m_displayName = tr("Show notifications on lock screen");
|
||||
d->m_valueType = QMetaType::Bool;
|
||||
d->m_defaultValue = "false";
|
||||
break;
|
||||
|
||||
case SettingsProperty::PopupStyle:
|
||||
d->m_name = QStringLiteral("popupStyle");
|
||||
d->m_displayName = tr("Style of popup notification");
|
||||
d->m_valueType = d->m_settingsPropertyMetaType;
|
||||
d->m_defaultValue = "TransientPopup";
|
||||
break;
|
||||
|
||||
case SettingsProperty::TransientPopup:
|
||||
d->m_name = QStringLiteral("TransientPopup");
|
||||
d->m_displayName = tr("Popup: displayed in the upper right corner of the screen, will automatically disappear");
|
||||
d->m_valueType = QMetaType::Int;
|
||||
break;
|
||||
|
||||
case SettingsProperty::ResidentPopup:
|
||||
d->m_name = QStringLiteral("ResidentPopup");
|
||||
d->m_displayName = tr("Notice: will remain on the screen until it is closed");
|
||||
d->m_valueType = QMetaType::Int;
|
||||
break;
|
||||
|
||||
case SettingsProperty::NoPopup:
|
||||
d->m_name = QStringLiteral("NoPopup");
|
||||
d->m_displayName = tr("None: notifications will not be displayed on the screen, only be put into notification center");
|
||||
d->m_valueType = QMetaType::Int;
|
||||
break;
|
||||
|
||||
case SettingsProperty::Invalid:
|
||||
d->m_name = QStringLiteral("Invalid");
|
||||
d->m_valueType = QMetaType::UnknownType;
|
||||
break;
|
||||
// NOTE: new properties must also be added to ::fromName()
|
||||
}
|
||||
}
|
||||
|
||||
SettingsPropertiesInfo::SettingsPropertiesInfo(const SettingsPropertiesInfo& pi)
|
||||
: d(new SettingsPropertiesInfoPrivate(*pi.d))
|
||||
{
|
||||
}
|
||||
|
||||
SettingsPropertiesInfo::~SettingsPropertiesInfo() = default;
|
||||
|
||||
SettingsPropertiesInfo& SettingsPropertiesInfo::operator=(const SettingsPropertiesInfo& rhs)
|
||||
{
|
||||
*d = *rhs.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool SettingsPropertiesInfo::operator==(const SettingsPropertiesInfo& rhs) const
|
||||
{
|
||||
return d->m_name == rhs.d->m_name && d->m_displayName == rhs.d->m_displayName &&
|
||||
d->m_property == rhs.d->m_property && d->m_valueType == rhs.d->m_valueType;
|
||||
}
|
||||
|
||||
QString SettingsPropertiesInfo::displayName() const
|
||||
{
|
||||
return d->m_displayName;
|
||||
}
|
||||
|
||||
QString SettingsPropertiesInfo::name() const
|
||||
{
|
||||
return d->m_name;
|
||||
}
|
||||
|
||||
SettingsProperty::Property SettingsPropertiesInfo::property() const
|
||||
{
|
||||
return d->m_property;
|
||||
}
|
||||
|
||||
QMetaType::Type SettingsPropertiesInfo::valueType() const
|
||||
{
|
||||
return d->m_valueType;
|
||||
}
|
||||
|
||||
SettingsPropertiesInfo SettingsPropertiesInfo::fromName(const QString& name)
|
||||
{
|
||||
static QHash<QString, SettingsProperty::Property> propertyHash = {
|
||||
{ QStringLiteral("ScheduleTurnOnDND"), SettingsProperty::ScheduleTurnOnDND },
|
||||
{ QStringLiteral("ScheduleTurnOnDNDTime"), SettingsProperty::ScheduleTurnOnDNDTime },
|
||||
{ QStringLiteral("ScheduleTurnOffDNDTime"), SettingsProperty::ScheduleTurnOffDNDTime },
|
||||
{ QStringLiteral("DNDWhileMultiScreen"), SettingsProperty::DNDWhileMultiScreen },
|
||||
{ QStringLiteral("DNDWhileFullScreen"), SettingsProperty::DNDWhileFullScreen },
|
||||
{ QStringLiteral("NotifyAlarmWhileDND"), SettingsProperty::NotifyAlarmWhileDND },
|
||||
{ QStringLiteral("ReceiveNotificationsFromApps"), SettingsProperty::ReceiveNotificationsFromApps },
|
||||
{ QStringLiteral("AllowNotify"), SettingsProperty::AllowNotify },
|
||||
{ QStringLiteral("AllowSound"), SettingsProperty::AllowSound },
|
||||
{ QStringLiteral("ShowContentOnLockScreen"), SettingsProperty::ShowContentOnLockScreen },
|
||||
{ QStringLiteral("ShowNotificationOnLockScreen"), SettingsProperty::ShowNotificationOnLockScreen },
|
||||
{ QStringLiteral("popupStyle"), SettingsProperty::PopupStyle },
|
||||
{ QStringLiteral("TransientPopup"), SettingsProperty::TransientPopup },
|
||||
{ QStringLiteral("ResidentPopup"), SettingsProperty::ResidentPopup },
|
||||
{ QStringLiteral("NoPopup"), SettingsProperty::NoPopup }
|
||||
};
|
||||
|
||||
return {propertyHash.value(name)};
|
||||
}
|
||||
|
||||
QString SettingsPropertiesInfo::defaultValue() const
|
||||
{
|
||||
return d->m_defaultValue;
|
||||
}
|
||||
|
||||
QString SettingsPropertiesInfo::valueToString(const QVariant &value) const
|
||||
{
|
||||
if(d->m_valueType == d->m_settingsPropertyMetaType) {
|
||||
return SettingsPropertiesInfo(static_cast<SettingsProperty::Property>(value.toInt())).name();
|
||||
} else if(d->m_valueType == QMetaType::QTime) {
|
||||
return value.toTime().toString("HHmm");
|
||||
} else {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
//
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef SETTINGS_PROPERTIES_INFO_H
|
||||
#define SETTINGS_PROPERTIES_INFO_H
|
||||
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
#include <QObject>
|
||||
#include "settings-properties.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace UkuiNotification {
|
||||
|
||||
class SettingsPropertiesInfoPrivate;
|
||||
/**
|
||||
* \class SettingsPropertiesInfo SettingsPropertiesInfo.h
|
||||
*/
|
||||
class Q_DECL_IMPORT SettingsPropertiesInfo : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SettingsPropertiesInfo();
|
||||
SettingsPropertiesInfo(SettingsProperty::Property property);
|
||||
SettingsPropertiesInfo(const SettingsPropertiesInfo& pi);
|
||||
~SettingsPropertiesInfo();
|
||||
|
||||
SettingsPropertiesInfo& operator=(const SettingsPropertiesInfo& rhs);
|
||||
bool operator==(const SettingsPropertiesInfo& rhs) const;
|
||||
|
||||
/**
|
||||
* The enumeration which represents this property
|
||||
*/
|
||||
SettingsProperty::Property property() const;
|
||||
|
||||
/**
|
||||
* The internal unique name used to refer to the property
|
||||
*/
|
||||
QString name() const;
|
||||
|
||||
/**
|
||||
* A user visible name of the property
|
||||
*/
|
||||
QString displayName() const;
|
||||
|
||||
/**
|
||||
* The type the value of this property should be.
|
||||
* Eg - Property::Height should be an integer
|
||||
*/
|
||||
QMetaType::Type valueType() const;
|
||||
QString defaultValue() const;
|
||||
QString valueToString(const QVariant &value) const;
|
||||
|
||||
/**
|
||||
* Construct a SettingsPropertiesInfo from the internal property name.
|
||||
* The internal property name is case insensitive
|
||||
*/
|
||||
static SettingsPropertiesInfo fromName(const QString& name);
|
||||
|
||||
private:
|
||||
const std::unique_ptr<SettingsPropertiesInfoPrivate> d;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
Q_DECLARE_METATYPE(UkuiNotification::SettingsPropertiesInfo)
|
||||
|
||||
|
||||
#endif // SETTINGS_PROPERTIES_INFO_H
|
|
@ -0,0 +1,65 @@
|
|||
//
|
||||
//
|
||||
//
|
||||
#ifndef SETTINGS_PROPERTIES
|
||||
#define SETTINGS_PROPERTIES
|
||||
#include <QMap>
|
||||
#include <QVariant>
|
||||
|
||||
namespace UkuiNotification {
|
||||
namespace SettingsProperty {
|
||||
Q_NAMESPACE
|
||||
/**
|
||||
* @brief The Property enum contains all settings property types
|
||||
*
|
||||
*/
|
||||
enum Property {
|
||||
Invalid = 0,
|
||||
|
||||
//Global settings about DND mode
|
||||
ScheduleTurnOnDND, //是否在时间段内自动开启勿扰模式,bool类型,默认值false
|
||||
ScheduleTurnOnDNDTime, //勿扰模式开启时间,QDateTime类型,默认值00:00
|
||||
ScheduleTurnOffDNDTime, //勿扰模式结束时间,QDateTime类型,默认值00:00
|
||||
DNDWhileMultiScreen, //多屏启动时是否启动勿扰模式,bool类型,默认值false
|
||||
DNDWhileFullScreen, //全屏状态下是否启动勿扰模式,bool类型,默认值false
|
||||
NotifyAlarmWhileDND, //勿扰模式下是否允许闹钟提示,bool类型,默认值false
|
||||
|
||||
//Show notifications from applications
|
||||
ReceiveNotificationsFromApps, //是否获取来自应用程序的通知,bool类型,默认值true
|
||||
|
||||
//single app notification settings
|
||||
AllowNotify = ReceiveNotificationsFromApps + 1, //是否接收当前应用通知,bool类型,默认值true
|
||||
AllowSound, //是否打开通知提示声,bool类型,默认值true
|
||||
ShowContentOnLockScreen, //锁屏界面是否显示通知内容信息,bool类型,默认值false
|
||||
ShowNotificationOnLockScreen, //锁屏界面是否显示通知,bool类型,默认值false
|
||||
PopupStyle, //通知样式,appNotificationStyle类型,默认值Mutative
|
||||
|
||||
//single app notification settings中的 popupStyle 类型取值范围
|
||||
TransientPopup = PopupStyle +1, //横幅模式,显示在右上角,会自动消失
|
||||
ResidentPopup, //提示模式,会保留在屏幕上,直到被关闭
|
||||
NoPopup //无,通知不会显示在屏幕上,但是会进入通知中心
|
||||
};
|
||||
typedef QMap<Property, QVariant> PropertyMap;
|
||||
}
|
||||
|
||||
static const QList<SettingsProperty::Property> GLOBAL_SETTINGS {
|
||||
SettingsProperty::ScheduleTurnOnDND,
|
||||
SettingsProperty::ScheduleTurnOnDNDTime,
|
||||
SettingsProperty::ScheduleTurnOffDNDTime,
|
||||
SettingsProperty::DNDWhileMultiScreen,
|
||||
SettingsProperty::DNDWhileFullScreen,
|
||||
SettingsProperty::NotifyAlarmWhileDND,
|
||||
SettingsProperty::ReceiveNotificationsFromApps
|
||||
};
|
||||
static const QList<SettingsProperty::Property> SINGLE_APPLICATION_SETTINGS {
|
||||
SettingsProperty::AllowNotify,
|
||||
SettingsProperty::AllowSound,
|
||||
SettingsProperty::ShowContentOnLockScreen,
|
||||
SettingsProperty::ShowNotificationOnLockScreen,
|
||||
SettingsProperty::PopupStyle,
|
||||
};
|
||||
} // namespace UkuiNotification
|
||||
|
||||
Q_DECLARE_METATYPE(UkuiNotification::SettingsProperty::Property)
|
||||
|
||||
#endif
|
|
@ -0,0 +1,158 @@
|
|||
//
|
||||
// Created by zpf on 2023/2/22.
|
||||
//
|
||||
|
||||
#include "single-application-settings.h"
|
||||
#include <QJsonObject>
|
||||
#include "settings-properties-info.h"
|
||||
#include "applications-settings.h"
|
||||
|
||||
namespace UkuiNotification{
|
||||
class SingleApplicationSettingsPrivate
|
||||
{
|
||||
friend class SingleApplicationSettings;
|
||||
public:
|
||||
SingleApplicationSettingsPrivate();
|
||||
~SingleApplicationSettingsPrivate();
|
||||
private:
|
||||
QJsonObject m_settings;
|
||||
QString m_desktopEntry;
|
||||
};
|
||||
}
|
||||
using namespace UkuiNotification;
|
||||
|
||||
SingleApplicationSettingsPrivate::SingleApplicationSettingsPrivate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SingleApplicationSettingsPrivate::~SingleApplicationSettingsPrivate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SingleApplicationSettings::SingleApplicationSettings(const QString &desktopEntry, QObject *parent)
|
||||
: QObject(parent)
|
||||
, d(new SingleApplicationSettingsPrivate)
|
||||
{
|
||||
d->m_desktopEntry = desktopEntry;
|
||||
d->m_settings = ApplicationsSettings::self()->getAppSettings(desktopEntry);
|
||||
if(d->m_desktopEntry != QStringLiteral("default") && !d->m_desktopEntry.isEmpty()) {
|
||||
connect(ApplicationsSettings::self(), &ApplicationsSettings::applicationUninstalled, this, &SingleApplicationSettings::appUninstalled);
|
||||
connect(ApplicationsSettings::self(), &ApplicationsSettings::settingsUpdated, this, &SingleApplicationSettings::settingsDataChanged);
|
||||
}
|
||||
}
|
||||
|
||||
SingleApplicationSettings::SingleApplicationSettings(const SingleApplicationSettings &other)
|
||||
: d(new SingleApplicationSettingsPrivate(*other.d))
|
||||
{
|
||||
}
|
||||
|
||||
SingleApplicationSettings &SingleApplicationSettings::operator=(const SingleApplicationSettings &other)
|
||||
{
|
||||
*d = *other.d;
|
||||
return *this;
|
||||
}
|
||||
SingleApplicationSettings &SingleApplicationSettings::operator=(SingleApplicationSettings &&other) Q_DECL_NOEXCEPT
|
||||
{
|
||||
d = other.d;
|
||||
other.d = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SingleApplicationSettings::~SingleApplicationSettings()
|
||||
{
|
||||
if(d) {
|
||||
delete d;
|
||||
d = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool SingleApplicationSettings::allowNotify()
|
||||
{
|
||||
return d->m_settings.value(SettingsPropertiesInfo(SettingsProperty::AllowNotify).name()).toBool();
|
||||
}
|
||||
|
||||
bool SingleApplicationSettings::allowSound()
|
||||
{
|
||||
return d->m_settings.value(SettingsPropertiesInfo(SettingsProperty::AllowSound).name()).toBool();
|
||||
}
|
||||
|
||||
bool SingleApplicationSettings::showContentOnLockScreen()
|
||||
{
|
||||
return d->m_settings.value(SettingsPropertiesInfo(SettingsProperty::ShowContentOnLockScreen).name()).toBool();
|
||||
}
|
||||
|
||||
bool SingleApplicationSettings::showNotificationOnLockScreen()
|
||||
{
|
||||
return d->m_settings.value(SettingsPropertiesInfo(SettingsProperty::ShowNotificationOnLockScreen).name()).toBool();
|
||||
}
|
||||
|
||||
SettingsProperty::Property UkuiNotification::SingleApplicationSettings::popupStyle()
|
||||
{
|
||||
return SettingsPropertiesInfo::fromName(d->m_settings.value(SettingsPropertiesInfo(SettingsProperty::PopupStyle).name()).toString()).property();
|
||||
}
|
||||
|
||||
void SingleApplicationSettings::settingsDataChanged()
|
||||
{
|
||||
QJsonObject data = ApplicationsSettings::self()->getAppSettings(d->m_desktopEntry);
|
||||
if(data.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for(SettingsProperty::Property property : SINGLE_APPLICATION_SETTINGS) {
|
||||
QString name = SettingsPropertiesInfo(property).name();
|
||||
QJsonValue value = data.value(name);
|
||||
if(d->m_settings.value(name) != value) {
|
||||
d->m_settings.insert(name, value);
|
||||
}
|
||||
switch (property) {
|
||||
case SettingsProperty::AllowNotify:
|
||||
Q_EMIT allowNotifyChanged(value.toBool());
|
||||
case SettingsProperty::AllowSound:
|
||||
Q_EMIT allowSoundChanged(value.toBool());
|
||||
case SettingsProperty::ShowContentOnLockScreen:
|
||||
Q_EMIT showContentOnLockScreenChanged(value.toBool());
|
||||
case SettingsProperty::ShowNotificationOnLockScreen:
|
||||
Q_EMIT showNotificationOnLockScreenChanged(value.toBool());
|
||||
case SettingsProperty::PopupStyle:
|
||||
Q_EMIT popupStyleChanged(SettingsPropertiesInfo::fromName(value.toString()).property());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SingleApplicationSettings::appUninstalled(const QString &desktopEntry)
|
||||
{
|
||||
if(d->m_desktopEntry == desktopEntry) {
|
||||
Q_EMIT uninstalled();
|
||||
}
|
||||
}
|
||||
|
||||
void SingleApplicationSettings::setAllowNotify(bool enable)
|
||||
{
|
||||
ApplicationsSettings::self()->setAppSetting(d->m_desktopEntry, SettingsProperty::AllowNotify, enable);
|
||||
}
|
||||
|
||||
void SingleApplicationSettings::setAllowSound(bool enable)
|
||||
{
|
||||
ApplicationsSettings::self()->setAppSetting(d->m_desktopEntry, SettingsProperty::AllowSound, enable);
|
||||
}
|
||||
|
||||
void SingleApplicationSettings::setShowContentOnLockScreen(bool enable)
|
||||
{
|
||||
ApplicationsSettings::self()->setAppSetting(d->m_desktopEntry, SettingsProperty::ShowContentOnLockScreen, enable);
|
||||
}
|
||||
|
||||
void SingleApplicationSettings::setShowNotificationOnLockScreen(bool enable)
|
||||
{
|
||||
ApplicationsSettings::self()->setAppSetting(d->m_desktopEntry, SettingsProperty::ShowNotificationOnLockScreen, enable);
|
||||
}
|
||||
|
||||
void SingleApplicationSettings::setPopupStyle(SettingsProperty::Property style)
|
||||
{
|
||||
ApplicationsSettings::self()->setAppSetting(d->m_desktopEntry, SettingsProperty::PopupStyle, style);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
//
|
||||
// Created by zpf on 2023/2/22.
|
||||
//
|
||||
|
||||
#ifndef UKUI_NOTIFICATION_SINGLE_APPLICATION_SETTINGS_H
|
||||
#define UKUI_NOTIFICATION_SINGLE_APPLICATION_SETTINGS_H
|
||||
#include <QObject>
|
||||
#include <settings-properties.h>
|
||||
#include <QJsonObject>
|
||||
namespace UkuiNotification {
|
||||
class SingleApplicationSettingsPrivate;
|
||||
/**
|
||||
* 一个应用的设置項
|
||||
*/
|
||||
class SingleApplicationSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool allowNotify READ allowNotify WRITE setAllowNotify NOTIFY allowNotifyChanged)
|
||||
Q_PROPERTY(bool allowSound READ allowSound WRITE setAllowSound NOTIFY allowSoundChanged)
|
||||
Q_PROPERTY(bool showContentOnLockScreen READ showContentOnLockScreen WRITE setShowContentOnLockScreen NOTIFY showContentOnLockScreenChanged)
|
||||
Q_PROPERTY(bool showNotificationOnLockScreen READ showNotificationOnLockScreen WRITE setShowNotificationOnLockScreen NOTIFY showNotificationOnLockScreenChanged)
|
||||
Q_PROPERTY(SettingsProperty::Property PopupStyle READ popupStyle WRITE setPopupStyle NOTIFY popupStyleChanged)
|
||||
public:
|
||||
explicit SingleApplicationSettings(const QString &desktopEntry = QString(), QObject *parent = nullptr);
|
||||
SingleApplicationSettings(const SingleApplicationSettings &other);
|
||||
SingleApplicationSettings &operator=(const SingleApplicationSettings &other);
|
||||
SingleApplicationSettings &operator=(SingleApplicationSettings &&other) Q_DECL_NOEXCEPT;
|
||||
~SingleApplicationSettings();
|
||||
|
||||
bool allowNotify();
|
||||
void setAllowNotify(bool enable);
|
||||
|
||||
bool allowSound();
|
||||
void setAllowSound(bool enable);
|
||||
|
||||
bool showContentOnLockScreen();
|
||||
void setShowContentOnLockScreen(bool enable);
|
||||
|
||||
bool showNotificationOnLockScreen();
|
||||
void setShowNotificationOnLockScreen(bool enable);
|
||||
|
||||
SettingsProperty::Property popupStyle();
|
||||
void setPopupStyle(SettingsProperty::Property style);
|
||||
|
||||
Q_SIGNALS:
|
||||
void allowNotifyChanged(bool);
|
||||
void allowSoundChanged(bool);
|
||||
void showContentOnLockScreenChanged(bool);
|
||||
void showNotificationOnLockScreenChanged(bool);
|
||||
void popupStyleChanged(SettingsProperty::Property);
|
||||
void uninstalled();
|
||||
|
||||
private Q_SLOTS:
|
||||
void settingsDataChanged();
|
||||
void appUninstalled(const QString &desktopEntry);
|
||||
|
||||
private:
|
||||
SingleApplicationSettingsPrivate *d = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //UKUI_NOTIFICATION_SINGLE_APPLICATION_SETTINGS_H
|
|
@ -12,6 +12,7 @@ NotificationServerApplication::NotificationServerApplication(int &argc, char **a
|
|||
: QtSingleCoreApplication(applicationName, argc, argv)
|
||||
{
|
||||
setApplicationVersion(NOTIFICATION_SERVER_VERSION);
|
||||
qApp->setProperty("IS_UKUI_NOTIFICATION_SERVICE", true);
|
||||
if (!this->isRunning()) {
|
||||
connect(this, &QtSingleCoreApplication::messageReceived, [=](QString msg) {
|
||||
this->parseCmd(msg, true);
|
||||
|
|
Loading…
Reference in New Issue