From 2fef3b925d2ae298427cec26df33545fa5fc8168 Mon Sep 17 00:00:00 2001 From: Nicolas Fella Date: Mon, 8 Mar 2021 21:25:47 +0100 Subject: [PATCH] Make use of KNotification's quick reply feature It can make use of Plasma's native quick reply. If that is not available then it get's turned into a regular action that we hook up with --- CMakeLists.txt | 2 ++ plugins/notifications/notification.cpp | 16 ++++++++++++++++ plugins/notifications/notification.h | 1 + plugins/notifications/notificationsplugin.cpp | 3 +++ 4 files changed, 22 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index da34e187a..2412bc99a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,8 @@ set (RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE project(kdeconnect VERSION ${RELEASE_SERVICE_VERSION}) +set(CMAKE_CXX_STANDARD 17) + if (SAILFISHOS) set(KF5_MIN_VERSION "5.36.0") set(QT_MIN_VERSION "5.6.0") diff --git a/plugins/notifications/notification.cpp b/plugins/notifications/notification.cpp index 0baf00018..86bc6e0e5 100644 --- a/plugins/notifications/notification.cpp +++ b/plugins/notifications/notification.cpp @@ -8,6 +8,10 @@ #include "plugin_notification_debug.h" #include +#include "knotifications_version.h" +#if KNOTIFICATIONS_VERSION >= QT_VERSION_CHECK(5, 81, 0) +#include +#endif #include #include #include @@ -45,10 +49,13 @@ Notification::Notification(const NetworkPacket& np, const Device* device, QObjec createKNotification(np); connect(m_notification, QOverload::of(&KNotification::activated), this, [this] (unsigned int actionIndex) { +// Since 5.81 we use KNotification's inline reply instead of our own action +#if KNOTIFICATIONS_VERSION < QT_VERSION_CHECK(5, 81, 0) // Do nothing for our own reply action if(!m_requestReplyId.isEmpty() && actionIndex == 1) { return; } +#endif // Notification action indices start at 1 Q_EMIT actionTriggered(m_internalId, m_actions[actionIndex - 1]); }); @@ -115,8 +122,17 @@ void Notification::createKNotification(const NetworkPacket& np) m_notification->setHint(QStringLiteral("x-kde-origin-name"), m_device->name()); if (!m_requestReplyId.isEmpty()) { +#if KNOTIFICATIONS_VERSION >= QT_VERSION_CHECK(5, 81, 0) + auto replyAction = std::make_unique(i18nc("@action:button", "Reply")); + replyAction->setPlaceholderText(i18nc("@info:placeholder", "Reply to %1...", m_appName)); + replyAction->setFallbackBehavior(KNotificationReplyAction::FallbackBehavior::UseRegularAction); + QObject::connect(replyAction.get(), &KNotificationReplyAction::replied, this, &Notification::replied); + QObject::connect(replyAction.get(), &KNotificationReplyAction::activated, this, &Notification::reply); + m_notification->setReplyAction(std::move(replyAction)); +#else m_actions.prepend(i18n("Reply")); connect(m_notification, &KNotification::action1Activated, this, &Notification::reply, Qt::UniqueConnection); +#endif } m_notification->setActions(m_actions); diff --git a/plugins/notifications/notification.h b/plugins/notifications/notification.h index db6d189b6..7a923b876 100644 --- a/plugins/notifications/notification.h +++ b/plugins/notifications/notification.h @@ -60,6 +60,7 @@ Q_SIGNALS: void replyRequested(); Q_SCRIPTABLE void ready(); void actionTriggered(const QString& key, const QString& action); + void replied(const QString& message); private: QString m_internalId; diff --git a/plugins/notifications/notificationsplugin.cpp b/plugins/notifications/notificationsplugin.cpp index 774f53bed..296e9e378 100644 --- a/plugins/notifications/notificationsplugin.cpp +++ b/plugins/notifications/notificationsplugin.cpp @@ -96,6 +96,9 @@ void NotificationsPlugin::addNotification(Notification* noti) }); connect(noti, &Notification::actionTriggered, this, &NotificationsPlugin::sendAction); + connect(noti, &Notification::replied, this, [this, noti](const QString& message){ + sendReply(noti->replyId(), message); + }); const QString& publicId = newId(); m_notifications[publicId] = noti;