客户端和设置接口客户端注册机制

This commit is contained in:
iaom 2023-03-08 16:57:51 +08:00
parent fd2b80a585
commit 293715a9c7
12 changed files with 75 additions and 45 deletions

View File

@ -10,8 +10,8 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(GNUInstallDirs)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core LinguistTools DBus Network Gui REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core LinguistTools DBus Network Gui REQUIRED)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core LinguistTools DBus Network Gui Qml REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core LinguistTools DBus Network Gui Qml REQUIRED)
set(REQUIRED_QT_VERSION 5.12.8)
add_subdirectory(notification-server)

View File

@ -2,7 +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)
find_package(PkgConfig REQUIRED)
set(UKUI_NOTIFICATION_EXTERNAL_LIBS "")
@ -26,17 +26,28 @@ set(ukui-notification_LIB_SRCS
notification-client-private.h
utils.h
utils.cpp
${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)
notification-close-reason.h
notification-settings/settings-properties.h
notification-settings/settings-properties-info.h
notification-settings/settings-properties-info.cpp
notification-settings/settings-manager-private.h
notification-settings/settings-manager.h
notification-settings/settings-manager.cpp
notification-settings/notification-global-settings.cpp
notification-settings/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
notification-close-reason.h
notification-settings/settings-properties.h
notification-settings/settings-properties-info.h
notification-settings/notification-global-settings.h
notification-settings/single-application-settings.h
notification-settings/applications-settings.h
ukui-notification_global.h
utils.h)
if(COMMAND qt_add_dbus_interface)
@ -52,6 +63,7 @@ target_link_libraries(ukui-notification
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::DBus
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Qml
KF5::WindowSystem
${UKUI_NOTIFICATION_EXTERNAL_LIBS}
)

View File

@ -36,7 +36,7 @@ public:
const QStringList &actions,
const QVariantMap &hints,
int timeout);
bool closeNotification(uint id, NotificationClient::CloseReason reason);
bool closeNotification(uint id, NotificationCloseReason::CloseReason reason);
bool invokeAction(uint id, const QString &action_key);
private Q_SLOTS:

View File

@ -5,6 +5,7 @@
#include "notification-client.h"
#include "notification-client-private.h"
#include <QDBusConnection>
#include <QQmlEngine>
#include "notificationclientadaptor.h"
using namespace UkuiNotification;
@ -122,22 +123,22 @@ void NotificationClientPrivate::Notify(const QString &app_name, uint replaces_id
void NotificationClientPrivate::notificationClosed(uint id, uint reason)
{
NotificationClient::CloseReason closeReason = NotificationClient::Undefined;
auto closeReason = NotificationCloseReason::CloseReason::Undefined;
switch (reason) {
case 1:
closeReason = NotificationClient::Expired;
closeReason = NotificationCloseReason::CloseReason::Expired;
break;
case 2:
closeReason = NotificationClient::DismissedByUser;
closeReason = NotificationCloseReason::CloseReason::DismissedByUser;
break;
case 3:
closeReason = NotificationClient::Revoked;
closeReason = NotificationCloseReason::CloseReason::Revoked;
break;
}
Q_EMIT q->notificationClosed(id, closeReason);
}
bool NotificationClientPrivate::closeNotification(uint id, NotificationClient::CloseReason reason)
bool NotificationClientPrivate::closeNotification(uint id, NotificationCloseReason::CloseReason reason)
{
if(!m_serverInterface) {
return false;
@ -177,6 +178,8 @@ bool NotificationClientPrivate::invokeAction(uint id, const QString &action_key)
NotificationClient::NotificationClient(QObject *parent) : QObject(parent), d(new NotificationClientPrivate(this))
{
qRegisterMetaType<PopupNotification>("PopupNotification");
qRegisterMetaType<UkuiNotification::PopupNotification>("UkuiNotification::PopupNotification");
qmlRegisterUncreatableType<UkuiNotification::NotificationCloseReason>("org.ukui.notification.client", 1, 0, "NotificationCloseReason", "");
}
NotificationClient::~NotificationClient() = default;
@ -186,7 +189,7 @@ bool NotificationClient::registerClient()
return d->init();
}
bool NotificationClient::closeNotification(uint id, NotificationClient::CloseReason reason)
bool NotificationClient::closeNotification(uint id, NotificationCloseReason::CloseReason reason)
{
return d->closeNotification(id, reason);
}

View File

@ -7,22 +7,13 @@
#include "ukui-notification_global.h"
#include <QObject>
#include "popup-notification.h"
#include "notification-close-reason.h"
namespace UkuiNotification {
class NotificationClientPrivate;
class UKUINOTIFICATION_EXPORT NotificationClient : public QObject
{
Q_OBJECT
public:
/**
* The reason a notification was closed
*/
enum CloseReason {
Expired = 1, // The notification expired(timed out).
DismissedByUser = 2, // The notification was dismissed by the user.
Revoked = 3, //< The notification was closed by sender by a call to CloseNotification.
Undefined = 4, //Undefined/reserved reasons.
};
Q_ENUM(CloseReason)
explicit NotificationClient(QObject *parent = nullptr);
~NotificationClient();
/**
@ -31,11 +22,11 @@ public:
*/
bool registerClient();
void unregisterClient();
bool closeNotification(uint id, CloseReason reason);
bool closeNotification(uint id, NotificationCloseReason::CloseReason reason);
bool invokeAction(uint id, const QString &action_key);
Q_SIGNALS:
void newNotification(const PopupNotification &notification);
void notificationClosed(uint id, CloseReason closeReason);
void newNotification(const UkuiNotification::PopupNotification &notification);
void notificationClosed(uint id, UkuiNotification::NotificationCloseReason::CloseReason closeReason);
private:
NotificationClientPrivate *d = nullptr;
};

View File

@ -0,0 +1,29 @@
//
// Created by zpf on 2023/3/8.
//
#ifndef UKUI_NOTIFICATION_NOTIFICATIONCLOSEREASON_H
#define UKUI_NOTIFICATION_NOTIFICATIONCLOSEREASON_H
#include <QObject>
#include "ukui-notification_global.h"
namespace UkuiNotification {
class UKUINOTIFICATION_EXPORT NotificationCloseReason
{
Q_GADGET
public:
/**
* The reason a notification was closed
*/
enum CloseReason {
Expired = 1, // The notification expired(timed out).
DismissedByUser = 2, // The notification was dismissed by the user.
Revoked = 3, //< The notification was closed by sender by a call to CloseNotification.
Undefined = 4, //Undefined/reserved reasons.
};
Q_ENUM(CloseReason)
};
}
#endif //UKUI_NOTIFICATION_NOTIFICATIONCLOSEREASON_H

View File

@ -4,6 +4,7 @@
#include "applications-settings.h"
#include <mutex>
#include <QQmlEngine>
#include "settings-manager.h"
#include <QJsonObject>
@ -33,6 +34,7 @@ UkuiNotification::ApplicationsSettings::ApplicationsSettings(QObject *parent) :
d->m_settingsData = SettingsManager::self()->getAllAppSettings();
connect(SettingsManager::self(), &SettingsManager::appUninstalled, this, &ApplicationsSettings::applicationUninstalled);
connect(SettingsManager::self(), &SettingsManager::settingsDataChanged, this, &ApplicationsSettings::settingsDataChanged);
qmlRegisterUncreatableType<UkuiNotification::SingleApplicationSettings>("org.ukui.notification.client", 1, 0, "SingleApplicationSettings", "");
}
ApplicationsSettings::~ApplicationsSettings()
@ -42,7 +44,7 @@ ApplicationsSettings::~ApplicationsSettings()
d = nullptr;
}
}
SingleApplicationSettings ApplicationsSettings::creatSettings(PopupNotification &notification)
SingleApplicationSettings ApplicationsSettings::creatSettings(const PopupNotification &notification)
{
QString desktopEntry = notification.desktopEntry();
if(desktopEntry.isEmpty()) {

View File

@ -25,7 +25,7 @@ public:
* @param notification
* @return SingleApplicationSettings
*/
SingleApplicationSettings creatSettings(PopupNotification &notification);
SingleApplicationSettings creatSettings(const PopupNotification &notification);
ApplicationsSettingsHash &getAllApplicationsSettings();
/**
* @brief getAppSettings

View File

@ -4,6 +4,7 @@
#include "notification-global-settings.h"
#include <QJsonObject>
#include <QQmlEngine>
#include "settings-manager.h"
#include "settings-properties.h"
#include "settings-properties-info.h"
@ -21,6 +22,7 @@ using namespace UkuiNotification;// UkuiNotification
NotificationGlobalSettings::NotificationGlobalSettings(QObject *parent) : QObject(parent), d(new NotificationGlobalSettingsPrivate())
{
qmlRegisterUncreatableType<UkuiNotification::NotificationGlobalSettings>("org.ukui.notification.client", 1, 0, "NotificationGlobalSettings", "");
connect(SettingsManager::self(), &SettingsManager::settingsDataChanged, this, &NotificationGlobalSettings::settingsDataChanged);
d->m_settings = SettingsManager::self()->getGlobalSettings();
}

View File

@ -5,6 +5,7 @@
#ifndef UKUI_NOTIFICATION_NOTIFICATION_GLOBAL_SETTINGS_H
#define UKUI_NOTIFICATION_NOTIFICATION_GLOBAL_SETTINGS_H
#include <QObject>
#include <QTime>
#include "settings-properties.h"
namespace UkuiNotification {
class NotificationGlobalSettingsPrivate;

View File

@ -25,17 +25,6 @@ class ServerPrivate : public QObject, protected QDBusContext
Q_OBJECT
//dbus interface
public:
/**
* The reason a notification was closed
*/
enum CloseReason {
Expired = 1, // The notification expired(timed out).
DismissedByUser = 2, // The notification was dismissed by the user.
Revoked = 3, //< The notification was closed by sender by a call to CloseNotification.
Undefined = 4, //Undefined/reserved reasons.
};
Q_ENUM(CloseReason)
QStringList GetCapabilities() const;
uint Notify(const QString &app_name,
uint replaces_id,

View File

@ -9,6 +9,7 @@
#include "notificationserveradaptor.h"
#include "notification-server-config.h"
#include "utils.h"
#include "notification-close-reason.h"
using namespace NotificationServer;
@ -93,7 +94,7 @@ void ServerPrivate::CloseNotification(uint id)
QStringLiteral("/NotificationClient"),
QStringLiteral("org.ukui.NotificationClient"),
QStringLiteral("CloseNotification"));
msg.setArguments({id, CloseReason::Revoked});
msg.setArguments({id, UkuiNotification::NotificationCloseReason::Revoked});
QDBusConnection::sessionBus().call(msg, QDBus::NoBlock);
}
}