diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e91ba0..aa7ff15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/libukui-notification/CMakeLists.txt b/libukui-notification/CMakeLists.txt index 1e27e07..f3e6766 100644 --- a/libukui-notification/CMakeLists.txt +++ b/libukui-notification/CMakeLists.txt @@ -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} ) diff --git a/libukui-notification/notification-client-private.h b/libukui-notification/notification-client-private.h index 57ef56d..8f88157 100644 --- a/libukui-notification/notification-client-private.h +++ b/libukui-notification/notification-client-private.h @@ -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: diff --git a/libukui-notification/notification-client.cpp b/libukui-notification/notification-client.cpp index 48a4e8f..cad7131 100644 --- a/libukui-notification/notification-client.cpp +++ b/libukui-notification/notification-client.cpp @@ -5,6 +5,7 @@ #include "notification-client.h" #include "notification-client-private.h" #include +#include #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"); + qRegisterMetaType("UkuiNotification::PopupNotification"); + qmlRegisterUncreatableType("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); } diff --git a/libukui-notification/notification-client.h b/libukui-notification/notification-client.h index 11e0d88..8a96f5a 100644 --- a/libukui-notification/notification-client.h +++ b/libukui-notification/notification-client.h @@ -7,22 +7,13 @@ #include "ukui-notification_global.h" #include #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 ¬ification); - void notificationClosed(uint id, CloseReason closeReason); + void newNotification(const UkuiNotification::PopupNotification ¬ification); + void notificationClosed(uint id, UkuiNotification::NotificationCloseReason::CloseReason closeReason); private: NotificationClientPrivate *d = nullptr; }; diff --git a/libukui-notification/notification-close-reason.h b/libukui-notification/notification-close-reason.h new file mode 100644 index 0000000..781b2ec --- /dev/null +++ b/libukui-notification/notification-close-reason.h @@ -0,0 +1,29 @@ +// +// Created by zpf on 2023/3/8. +// + +#ifndef UKUI_NOTIFICATION_NOTIFICATIONCLOSEREASON_H +#define UKUI_NOTIFICATION_NOTIFICATIONCLOSEREASON_H + + +#include +#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 \ No newline at end of file diff --git a/libukui-notification/notification-settings/applications-settings.cpp b/libukui-notification/notification-settings/applications-settings.cpp index a85e566..63644dd 100644 --- a/libukui-notification/notification-settings/applications-settings.cpp +++ b/libukui-notification/notification-settings/applications-settings.cpp @@ -4,6 +4,7 @@ #include "applications-settings.h" #include +#include #include "settings-manager.h" #include @@ -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("org.ukui.notification.client", 1, 0, "SingleApplicationSettings", ""); } ApplicationsSettings::~ApplicationsSettings() @@ -42,7 +44,7 @@ ApplicationsSettings::~ApplicationsSettings() d = nullptr; } } -SingleApplicationSettings ApplicationsSettings::creatSettings(PopupNotification ¬ification) +SingleApplicationSettings ApplicationsSettings::creatSettings(const PopupNotification ¬ification) { QString desktopEntry = notification.desktopEntry(); if(desktopEntry.isEmpty()) { diff --git a/libukui-notification/notification-settings/applications-settings.h b/libukui-notification/notification-settings/applications-settings.h index 408906f..752a616 100644 --- a/libukui-notification/notification-settings/applications-settings.h +++ b/libukui-notification/notification-settings/applications-settings.h @@ -25,7 +25,7 @@ public: * @param notification * @return SingleApplicationSettings */ - SingleApplicationSettings creatSettings(PopupNotification ¬ification); + SingleApplicationSettings creatSettings(const PopupNotification ¬ification); ApplicationsSettingsHash &getAllApplicationsSettings(); /** * @brief getAppSettings diff --git a/libukui-notification/notification-settings/notification-global-settings.cpp b/libukui-notification/notification-settings/notification-global-settings.cpp index e0e66b8..34dc1d5 100644 --- a/libukui-notification/notification-settings/notification-global-settings.cpp +++ b/libukui-notification/notification-settings/notification-global-settings.cpp @@ -4,6 +4,7 @@ #include "notification-global-settings.h" #include +#include #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("org.ukui.notification.client", 1, 0, "NotificationGlobalSettings", ""); connect(SettingsManager::self(), &SettingsManager::settingsDataChanged, this, &NotificationGlobalSettings::settingsDataChanged); d->m_settings = SettingsManager::self()->getGlobalSettings(); } diff --git a/libukui-notification/notification-settings/notification-global-settings.h b/libukui-notification/notification-settings/notification-global-settings.h index 448f33a..9c5313d 100644 --- a/libukui-notification/notification-settings/notification-global-settings.h +++ b/libukui-notification/notification-settings/notification-global-settings.h @@ -5,6 +5,7 @@ #ifndef UKUI_NOTIFICATION_NOTIFICATION_GLOBAL_SETTINGS_H #define UKUI_NOTIFICATION_NOTIFICATION_GLOBAL_SETTINGS_H #include +#include #include "settings-properties.h" namespace UkuiNotification { class NotificationGlobalSettingsPrivate; diff --git a/notification-server/server-private.h b/notification-server/server-private.h index d7558bf..ac9980d 100644 --- a/notification-server/server-private.h +++ b/notification-server/server-private.h @@ -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, diff --git a/notification-server/server.cpp b/notification-server/server.cpp index 16bd398..b59b333 100644 --- a/notification-server/server.cpp +++ b/notification-server/server.cpp @@ -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); } }