完善Action执行处理逻辑

This commit is contained in:
iaom 2023-02-14 17:21:09 +08:00
parent 39bd53a95a
commit 57cc6a3324
10 changed files with 57 additions and 25 deletions

View File

@ -10,8 +10,6 @@
<method name="InvokedAction"> <method name="InvokedAction">
<arg name="id" type="u" direction="in"/> <arg name="id" type="u" direction="in"/>
<arg name="action_key" type="s" direction="in"/> <arg name="action_key" type="s" direction="in"/>
<arg name="action" type="s" direction="in"/>
<arg name="display" type="s" direction="in"/>
</method> </method>
</interface> </interface>
</node> </node>

View File

@ -34,7 +34,7 @@ target_link_libraries(ukui-notification
) )
target_compile_definitions(ukui-notification PRIVATE UKUINOTIFICATION_LIBRARY) target_compile_definitions(ukui-notification PRIVATE UKUINOTIFICATION_LIBRARY)
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
set(CMAKECONFIG_INSTALL_DIR "/usr/lib/ukui-notification") set(CMAKECONFIG_INSTALL_DIR "/usr/include/ukui-notification")
configure_package_config_file( configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/ukui-notification-config.cmake.in" "${CMAKE_CURRENT_SOURCE_DIR}/ukui-notification-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/ukui-notification-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/ukui-notification-config.cmake"
@ -42,7 +42,7 @@ configure_package_config_file(
set(PC_INSTALL_DIR "/usr/lib/pkgconfig") set(PC_INSTALL_DIR "/usr/lib/pkgconfig")
configure_package_config_file( configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/ukui-notification.pc.in" "${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}) INSTALL_DESTINATION ${PC_INSTALL_DIR})
set_target_properties(ukui-notification PROPERTIES set_target_properties(ukui-notification PROPERTIES
VERSION ${UKUI_NOTIFICATION_VERSION} VERSION ${UKUI_NOTIFICATION_VERSION}
@ -50,4 +50,6 @@ set_target_properties(ukui-notification PROPERTIES
OUTPUT_NAME ukui-notification OUTPUT_NAME ukui-notification
) )
install(TARGETS ukui-notification DESTINATION /usr/lib) install(TARGETS ukui-notification DESTINATION /usr/lib)
install(FILES ${HEADERS} DESTINATION /usr/include/ukui-notification) 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})

View File

@ -28,7 +28,7 @@ public:
const QVariantMap &hints, const QVariantMap &hints,
int timeout); int timeout);
void closeNotification(uint id, NotificationClient::CloseReason reason); 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: private Q_SLOTS:
void notificationClosed(uint id, uint reason); void notificationClosed(uint id, uint reason);

View File

@ -147,15 +147,14 @@ void NotificationClientPrivate::serviceChange(const QString &service, const QStr
} }
} }
void NotificationClientPrivate::invokeAction(uint id, const QString &action_key, const QString &action, void NotificationClientPrivate::invokeAction(uint id, const QString &action_key)
const QString &display)
{ {
if(!m_notificationsInterface) { if(!m_notificationsInterface) {
return; return;
} }
QDBusMessage reply = m_notificationsInterface->callWithArgumentList(QDBus::NoBlock, QDBusMessage reply = m_notificationsInterface->callWithArgumentList(QDBus::NoBlock,
QStringLiteral("InvokedAction"), QStringLiteral("InvokedAction"),
{id, action_key, action, display}); {id, action_key});
if (reply.type() == QDBusMessage::ErrorMessage) { if (reply.type() == QDBusMessage::ErrorMessage) {
qWarning() << "Failed to call InvokedAction!" << QDBusConnection::sessionBus().lastError(); qWarning() << "Failed to call InvokedAction!" << QDBusConnection::sessionBus().lastError();
} }
@ -178,7 +177,7 @@ void NotificationClient::closeNotification(uint id, NotificationClient::CloseRea
d->closeNotification(id, reason); 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);
} }

View File

@ -31,7 +31,7 @@ public:
*/ */
bool registerClient(); bool registerClient();
void closeNotification(uint id, CloseReason reason); 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: Q_SIGNALS:
void newNotification(const PopupNotification &notification); void newNotification(const PopupNotification &notification);
void notificationClosed(uint id, CloseReason closeReason); void notificationClosed(uint id, CloseReason closeReason);

View File

@ -23,7 +23,7 @@ public:
QString m_body; QString m_body;
QList<QPair<QString, QString>> m_actions; QList<QPair<QString, QString>> m_actions;
bool m_hasDefaultAction = false; bool m_hasDefaultAction = false;
QString m_defaultActionInfo; QString m_defaultActionLabel;
QVariantMap m_hints = QVariantMap(); QVariantMap m_hints = QVariantMap();
QString m_category; QString m_category;
QImage m_image; QImage m_image;
@ -171,6 +171,11 @@ PopupNotification::~PopupNotification()
} }
} }
uint PopupNotification::id() const
{
return d->m_id;
}
QString PopupNotification::applicationName() const QString PopupNotification::applicationName() const
{ {
return d->m_applicationName; return d->m_applicationName;
@ -218,7 +223,7 @@ bool PopupNotification::hasDefaultAction() const
QString PopupNotification::defauleActionLable() QString PopupNotification::defauleActionLable()
{ {
return d->m_defaultActionInfo; return d->m_defaultActionLabel;
} }
void PopupNotification::setActions(const QStringList &actions) void PopupNotification::setActions(const QStringList &actions)
@ -231,15 +236,15 @@ void PopupNotification::setActions(const QStringList &actions)
d->m_hasDefaultAction = false; d->m_hasDefaultAction = false;
for (int i = 0; i < actions.count(); i += 2) { for (int i = 0; i < actions.count(); i += 2) {
const QString &name = actions.at(i); const QString &key = actions.at(i);
const QString &info = actions.at(i + 1); 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_hasDefaultAction = true;
d->m_defaultActionInfo = info; d->m_defaultActionLabel = label;
continue; 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) void PopupNotification::setUrgency(PopupNotification::Urgency urgency)
{ {
d->m_urgency = urgency; d->m_urgency = urgency;
} }
PopupNotification::Urgency PopupNotification::urgency() const
{
return d->m_urgency;
}

View File

@ -17,9 +17,30 @@
namespace UkuiNotification { namespace UkuiNotification {
class PopupNotificationPrivate; class PopupNotificationPrivate;
//TODO 可以增加通知基类,实现多种类型通知 //TODO 可以增加通知基类,实现多种类型通知
typedef QList<QPair<QString, QString>> ActionList;
class UKUINOTIFICATION_EXPORT PopupNotification : public QObject class UKUINOTIFICATION_EXPORT PopupNotification : public QObject
{ {
Q_OBJECT 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: public:
/** /**
* The notification urgency. * The notification urgency.
@ -37,6 +58,7 @@ public:
PopupNotification &operator=(PopupNotification &&other) Q_DECL_NOEXCEPT; PopupNotification &operator=(PopupNotification &&other) Q_DECL_NOEXCEPT;
~PopupNotification(); ~PopupNotification();
uint id() const;
QString applicationName() const; QString applicationName() const;
void setApplicationName(const QString &applicationName); void setApplicationName(const QString &applicationName);
@ -52,7 +74,7 @@ public:
bool hasDefaultAction() const; bool hasDefaultAction() const;
QString defauleActionLable(); QString defauleActionLable();
void setActions(const QStringList &actions); void setActions(const QStringList &actions);
QList<QPair<QString, QString>> actions() const; ActionList actions() const;
QVariantMap hints() const; QVariantMap hints() const;
void setHints(const QVariantMap &hints); void setHints(const QVariantMap &hints);
@ -107,6 +129,8 @@ public:
* @return * @return
*/ */
bool transient() const; bool transient() const;
Urgency urgency() const;
void setUrgency(Urgency urgency); void setUrgency(Urgency urgency);
/** /**
* display * display

View File

@ -1,4 +1,4 @@
prefix=@CMAKE_INSTALL_PREFIX@ prefix=/usr
exec_prefix=${prefix} exec_prefix=${prefix}
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/include/ukui-notification includedir=${prefix}/include/ukui-notification

View File

@ -51,7 +51,7 @@ public:
* @param reason * @param reason
*/ */
void CloseNotification(uint id, uint); 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: Q_SIGNALS:
void NotificationClosed(uint id, uint reason); void NotificationClosed(uint id, uint reason);
void ActionInvoked(uint id, const QString &actionKey); void ActionInvoked(uint id, const QString &actionKey);

View File

@ -133,9 +133,8 @@ void ServerPrivate::CloseNotification(uint id, uint reason)
Q_EMIT NotificationClosed(id, 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); Q_EMIT ActionInvoked(id, action_key);
} }