新增通知服务相关设置项功能;

This commit is contained in:
jixiaoxu 2023-02-20 09:24:12 +08:00
parent a88fb43214
commit 8dc1ed86a0
9 changed files with 852 additions and 3 deletions

View File

@ -2,6 +2,7 @@ set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_MICRO 0)
set(UKUI_NOTIFICATION_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO})
set(settings_DIR notification-settings/)
find_package(KF5WindowSystem)
set(ukui-notification_LIB_SRCS
notification-client.cpp
@ -11,7 +12,13 @@ set(ukui-notification_LIB_SRCS
ukui-notification_global.h
notification-client-private.h
utils.h
utils.cpp)
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)
set(HEADERS
notification-client.h
popup-notification.h
@ -31,6 +38,7 @@ target_link_libraries(ukui-notification
Qt${QT_VERSION_MAJOR}::DBus
Qt${QT_VERSION_MAJOR}::Gui
KF5::WindowSystem
ukui-search
)
include(CMakePackageConfigHelpers)
@ -71,4 +79,4 @@ install(FILES ${HEADERS} DESTINATION ${HEADERS_INSTALL_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ukui-notification.pc DESTINATION ${PC_INSTALL_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ukui-notification-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/ukui-notification-config-version.cmake
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
DESTINATION ${CMAKECONFIG_INSTALL_DIR})

View File

@ -0,0 +1,178 @@
//
//
//
#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));
}

View File

@ -0,0 +1,73 @@
//
//
//
#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

View File

@ -0,0 +1,83 @@
//
//
//
#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_nameicon
*/
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

View File

@ -0,0 +1,48 @@
//
//
//
#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

View File

@ -0,0 +1,147 @@
//
//
//
#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)
{
}

View File

@ -0,0 +1,220 @@
//
//
//
#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)
{
}

View File

@ -0,0 +1,92 @@
//
//
#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
* appqstring类型的应用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

View File

@ -43,4 +43,4 @@ else()
endif()
set(DBUS_SERVICE_FILE data/org.freedesktop.Notifications.service)
install(TARGETS ukui-notification-server DESTINATION /usr/bin)
install(FILES ${DBUS_SERVICE_FILE} DESTINATION /usr/share/dbus-1/services)
install(FILES ${DBUS_SERVICE_FILE} DESTINATION /usr/share/dbus-1/services)