From 57cc6a332473dc1415a6dde39728ffe8b1179293 Mon Sep 17 00:00:00 2001 From: iaom Date: Tue, 14 Feb 2023 17:21:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84Action=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbus/org.ukui.NotificationServer.xml | 2 -- libukui-notification/CMakeLists.txt | 8 +++--- .../notification-client-private.h | 2 +- libukui-notification/notification-client.cpp | 9 +++---- libukui-notification/notification-client.h | 2 +- libukui-notification/popup-notification.cpp | 26 +++++++++++++------ libukui-notification/popup-notification.h | 26 ++++++++++++++++++- libukui-notification/ukui-notification.pc.in | 2 +- notification-server/server-private.h | 2 +- notification-server/server.cpp | 3 +-- 10 files changed, 57 insertions(+), 25 deletions(-) diff --git a/dbus/org.ukui.NotificationServer.xml b/dbus/org.ukui.NotificationServer.xml index d250743..9da7df5 100644 --- a/dbus/org.ukui.NotificationServer.xml +++ b/dbus/org.ukui.NotificationServer.xml @@ -10,8 +10,6 @@ - - \ No newline at end of file diff --git a/libukui-notification/CMakeLists.txt b/libukui-notification/CMakeLists.txt index c4b68c5..8ac3282 100644 --- a/libukui-notification/CMakeLists.txt +++ b/libukui-notification/CMakeLists.txt @@ -34,7 +34,7 @@ target_link_libraries(ukui-notification ) target_compile_definitions(ukui-notification PRIVATE UKUINOTIFICATION_LIBRARY) include(CMakePackageConfigHelpers) -set(CMAKECONFIG_INSTALL_DIR "/usr/lib/ukui-notification") +set(CMAKECONFIG_INSTALL_DIR "/usr/include/ukui-notification") configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/ukui-notification-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/ukui-notification-config.cmake" @@ -42,7 +42,7 @@ configure_package_config_file( set(PC_INSTALL_DIR "/usr/lib/pkgconfig") configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/ukui-notification.pc.in" - "${CMAKE_CURRENT_BINARY_DIR}/ukui-notification.pc.in" + "${CMAKE_CURRENT_BINARY_DIR}/ukui-notification.pc" INSTALL_DESTINATION ${PC_INSTALL_DIR}) set_target_properties(ukui-notification PROPERTIES VERSION ${UKUI_NOTIFICATION_VERSION} @@ -50,4 +50,6 @@ set_target_properties(ukui-notification PROPERTIES OUTPUT_NAME ukui-notification ) install(TARGETS ukui-notification DESTINATION /usr/lib) -install(FILES ${HEADERS} DESTINATION /usr/include/ukui-notification) \ No newline at end of file +install(FILES ${HEADERS} DESTINATION /usr/include/ukui-notification) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ukui-notification.pc DESTINATION ${PC_INSTALL_DIR}) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ukui-notification-config.cmake DESTINATION ${CMAKECONFIG_INSTALL_DIR}) \ No newline at end of file diff --git a/libukui-notification/notification-client-private.h b/libukui-notification/notification-client-private.h index b53f2f4..9037a82 100644 --- a/libukui-notification/notification-client-private.h +++ b/libukui-notification/notification-client-private.h @@ -28,7 +28,7 @@ public: const QVariantMap &hints, int timeout); void closeNotification(uint id, NotificationClient::CloseReason reason); - void invokeAction(uint id, const QString &action_key, const QString &action, const QString &display); + void invokeAction(uint id, const QString &action_key); private Q_SLOTS: void notificationClosed(uint id, uint reason); diff --git a/libukui-notification/notification-client.cpp b/libukui-notification/notification-client.cpp index 483e629..9db8a6c 100644 --- a/libukui-notification/notification-client.cpp +++ b/libukui-notification/notification-client.cpp @@ -147,15 +147,14 @@ void NotificationClientPrivate::serviceChange(const QString &service, const QStr } } -void NotificationClientPrivate::invokeAction(uint id, const QString &action_key, const QString &action, - const QString &display) +void NotificationClientPrivate::invokeAction(uint id, const QString &action_key) { if(!m_notificationsInterface) { return; } QDBusMessage reply = m_notificationsInterface->callWithArgumentList(QDBus::NoBlock, QStringLiteral("InvokedAction"), - {id, action_key, action, display}); + {id, action_key}); if (reply.type() == QDBusMessage::ErrorMessage) { qWarning() << "Failed to call InvokedAction!" << QDBusConnection::sessionBus().lastError(); } @@ -178,7 +177,7 @@ void NotificationClient::closeNotification(uint id, NotificationClient::CloseRea d->closeNotification(id, reason); } -void NotificationClient::invokeAction(uint id, const QString &action_key, const QString &action, const QString &display) +void NotificationClient::invokeAction(uint id, const QString &action_key) { - d->invokeAction(id, action_key, action, display); + d->invokeAction(id, action_key); } diff --git a/libukui-notification/notification-client.h b/libukui-notification/notification-client.h index e6e8334..1677d2c 100644 --- a/libukui-notification/notification-client.h +++ b/libukui-notification/notification-client.h @@ -31,7 +31,7 @@ public: */ bool registerClient(); void closeNotification(uint id, CloseReason reason); - void invokeAction(uint id, const QString &action_key, const QString &action, const QString &display); + void invokeAction(uint id, const QString &action_key); Q_SIGNALS: void newNotification(const PopupNotification ¬ification); void notificationClosed(uint id, CloseReason closeReason); diff --git a/libukui-notification/popup-notification.cpp b/libukui-notification/popup-notification.cpp index 1ee7add..4190575 100644 --- a/libukui-notification/popup-notification.cpp +++ b/libukui-notification/popup-notification.cpp @@ -23,7 +23,7 @@ public: QString m_body; QList> m_actions; bool m_hasDefaultAction = false; - QString m_defaultActionInfo; + QString m_defaultActionLabel; QVariantMap m_hints = QVariantMap(); QString m_category; QImage m_image; @@ -171,6 +171,11 @@ PopupNotification::~PopupNotification() } } +uint PopupNotification::id() const +{ + return d->m_id; +} + QString PopupNotification::applicationName() const { return d->m_applicationName; @@ -218,7 +223,7 @@ bool PopupNotification::hasDefaultAction() const QString PopupNotification::defauleActionLable() { - return d->m_defaultActionInfo; + return d->m_defaultActionLabel; } void PopupNotification::setActions(const QStringList &actions) @@ -231,15 +236,15 @@ void PopupNotification::setActions(const QStringList &actions) d->m_hasDefaultAction = false; for (int i = 0; i < actions.count(); i += 2) { - const QString &name = actions.at(i); - const QString &info = actions.at(i + 1); + const QString &key = actions.at(i); + const QString &label = actions.at(i + 1); - if (!d->m_hasDefaultAction && name == QLatin1String("default")) { + if (!d->m_hasDefaultAction && key == QLatin1String("default")) { d->m_hasDefaultAction = true; - d->m_defaultActionInfo = info; + d->m_defaultActionLabel = label; continue; } - d->m_actions.append({name, info}); + d->m_actions.append({key, label}); } } @@ -370,4 +375,9 @@ QString PopupNotification::display() const void PopupNotification::setUrgency(PopupNotification::Urgency urgency) { d->m_urgency = urgency; -} \ No newline at end of file +} + +PopupNotification::Urgency PopupNotification::urgency() const +{ + return d->m_urgency; +} diff --git a/libukui-notification/popup-notification.h b/libukui-notification/popup-notification.h index bffc910..f75d4ef 100644 --- a/libukui-notification/popup-notification.h +++ b/libukui-notification/popup-notification.h @@ -17,9 +17,30 @@ namespace UkuiNotification { class PopupNotificationPrivate; //TODO 可以增加通知基类,实现多种类型通知 +typedef QList> ActionList; class UKUINOTIFICATION_EXPORT PopupNotification : public QObject { Q_OBJECT + Q_PROPERTY(uint id READ id) + Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName) + Q_PROPERTY(QString applicationIconName READ applicationIconName WRITE setAplicationIconName) + Q_PROPERTY(QString summary READ summary WRITE setSummary) + Q_PROPERTY(QString body READ body WRITE setBody) + Q_PROPERTY(QDateTime createdTime READ createdTime) + Q_PROPERTY(bool hasDefaultAction READ hasDefaultAction) + Q_PROPERTY(ActionList actions READ actions) + Q_PROPERTY(uint timeout READ timeout WRITE setTimeout) + Q_PROPERTY(bool enableActionIcons READ enableActionIcons) + Q_PROPERTY(QImage image READ image) + Q_PROPERTY(QString icon READ icon) + Q_PROPERTY(bool resident READ resident) + Q_PROPERTY(bool transient READ transient) + Q_PROPERTY(QString soundFile READ soundFile) + Q_PROPERTY(bool suppressSound READ suppressSound) + Q_PROPERTY(QString category READ category) + Q_PROPERTY(Urgency urgency READ urgency WRITE setUrgency) + Q_PROPERTY(QString display READ display) + public: /** * The notification urgency. @@ -37,6 +58,7 @@ public: PopupNotification &operator=(PopupNotification &&other) Q_DECL_NOEXCEPT; ~PopupNotification(); + uint id() const; QString applicationName() const; void setApplicationName(const QString &applicationName); @@ -52,7 +74,7 @@ public: bool hasDefaultAction() const; QString defauleActionLable(); void setActions(const QStringList &actions); - QList> actions() const; + ActionList actions() const; QVariantMap hints() const; void setHints(const QVariantMap &hints); @@ -107,6 +129,8 @@ public: * @return */ bool transient() const; + + Urgency urgency() const; void setUrgency(Urgency urgency); /** * 通知发送者所在的display diff --git a/libukui-notification/ukui-notification.pc.in b/libukui-notification/ukui-notification.pc.in index 98464b0..48d641f 100644 --- a/libukui-notification/ukui-notification.pc.in +++ b/libukui-notification/ukui-notification.pc.in @@ -1,4 +1,4 @@ -prefix=@CMAKE_INSTALL_PREFIX@ +prefix=/usr exec_prefix=${prefix} libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ includedir=${prefix}/include/ukui-notification diff --git a/notification-server/server-private.h b/notification-server/server-private.h index 9c36ef0..4794119 100644 --- a/notification-server/server-private.h +++ b/notification-server/server-private.h @@ -51,7 +51,7 @@ public: * @param reason 关闭原因 */ void CloseNotification(uint id, uint); - void InvokedAction(uint id, const QString &action_key, const QString &action, const QString &display); + void InvokedAction(uint id, const QString &action_key); Q_SIGNALS: void NotificationClosed(uint id, uint reason); void ActionInvoked(uint id, const QString &actionKey); diff --git a/notification-server/server.cpp b/notification-server/server.cpp index e30f54b..dc627fd 100644 --- a/notification-server/server.cpp +++ b/notification-server/server.cpp @@ -133,9 +133,8 @@ void ServerPrivate::CloseNotification(uint id, uint reason) Q_EMIT NotificationClosed(id, reason); } -void ServerPrivate::InvokedAction(uint id, const QString &action_key, const QString &action, const QString &display) +void ServerPrivate::InvokedAction(uint id, const QString &action_key) { - //TODO: 异步执行action Q_EMIT ActionInvoked(id, action_key); }