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
This commit is contained in:
Nicolas Fella 2021-03-08 21:25:47 +01:00
parent 31ca3cbf4f
commit 2fef3b925d
4 changed files with 22 additions and 0 deletions

View file

@ -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")

View file

@ -8,6 +8,10 @@
#include "plugin_notification_debug.h"
#include <KNotification>
#include "knotifications_version.h"
#if KNOTIFICATIONS_VERSION >= QT_VERSION_CHECK(5, 81, 0)
#include <KNotificationReplyAction>
#endif
#include <QtGlobal>
#include <QIcon>
#include <QString>
@ -45,10 +49,13 @@ Notification::Notification(const NetworkPacket& np, const Device* device, QObjec
createKNotification(np);
connect(m_notification, QOverload<unsigned int>::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<KNotificationReplyAction>(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);

View file

@ -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;

View file

@ -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;