[Notifications] Send reply text as targeted signal

Avoids waking up non-interested parties.

Differential Revision: https://phabricator.kde.org/D26803
wilder-5.18
Kai Uwe Broulik 6 years ago
parent ea66bff2af
commit 5369cf775c
  1. 10
      libnotificationmanager/notification.cpp
  2. 3
      libnotificationmanager/notification.h
  3. 2
      libnotificationmanager/notification_p.h
  4. 2
      libnotificationmanager/notificationsmodel.cpp
  5. 4
      libnotificationmanager/server.cpp
  6. 3
      libnotificationmanager/server.h
  7. 31
      libnotificationmanager/server_p.cpp
  8. 4
      libnotificationmanager/server_p.h

@ -479,6 +479,16 @@ uint Notification::id() const
return d->id;
}
QString Notification::dBusService() const
{
return d->dBusService;
}
void Notification::setDBusService(const QString &dBusService)
{
d->dBusService = dBusService;
}
QDateTime Notification::created() const
{
return d->created;

@ -53,6 +53,9 @@ public:
uint id() const;
QString dBusService() const;
void setDBusService(const QString &dBusService);
QDateTime created() const;
QDateTime updated() const;

@ -58,6 +58,8 @@ public:
void setUrgency(Notifications::Urgency urgency);
uint id = 0;
// Bus name of the creator/sender
QString dBusService;
QDateTime created;
QDateTime updated;
bool read = false;

@ -458,7 +458,7 @@ void NotificationsModel::reply(uint notificationId, const QString &text)
return;
}
Server::self().reply(notificationId, text);
Server::self().reply(notification.dBusService(), notificationId, text);
}
void NotificationsModel::startTimeout(uint notificationId)

@ -80,9 +80,9 @@ void Server::invokeAction(uint notificationId, const QString &actionName)
emit d->ActionInvoked(notificationId, actionName);
}
void Server::reply(uint notificationId, const QString &text)
void Server::reply(const QString &dbusService, uint notificationId, const QString &text)
{
emit d->NotificationReplied(notificationId, text);
d->sendReplyText(dbusService, notificationId, text);
}
uint Server::add(const Notification &notification)

@ -151,11 +151,12 @@ public:
/**
* Sends a notification reply text
*
* @param dbusService The bus name of the receiving application
* @param id The notification ID
* @param text The reply message text
* @since 5.18
*/
void reply(uint id, const QString &text);
void reply(const QString &dbusService, uint id, const QString &text);
/**
* Adds a notification

@ -58,6 +58,16 @@ QString ServerPrivate::notificationServiceName()
return QStringLiteral("org.freedesktop.Notifications");
}
QString ServerPrivate::notificationServicePath()
{
return QStringLiteral("/org/freedesktop/Notifications");
}
QString ServerPrivate::notificationServiceInterface()
{
return notificationServiceName();
}
ServerInfo *ServerPrivate::currentOwner() const
{
if (!m_currentOwner) {
@ -76,7 +86,7 @@ bool ServerPrivate::init()
new NotificationsAdaptor(this);
if (!m_dbusObjectValid) { // if already registered, don't fail here
m_dbusObjectValid = QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/freedesktop/Notifications"), this);
m_dbusObjectValid = QDBusConnection::sessionBus().registerObject(notificationServicePath(), this);
}
if (!m_dbusObjectValid) {
@ -142,6 +152,7 @@ uint ServerPrivate::Notify(const QString &app_name, uint replaces_id, const QStr
}
Notification notification(notificationId);
notification.setDBusService(message().service());
notification.setSummary(summary);
notification.setBody(body);
notification.setApplicationName(app_name);
@ -303,6 +314,20 @@ uint ServerPrivate::add(const Notification &notification)
return notification.id();
}
void ServerPrivate::sendReplyText(const QString &dbusService, uint notificationId, const QString &text)
{
if (dbusService.isEmpty()) {
qCWarning(NOTIFICATIONMANAGER) << "Sending notification reply text for notification" << notificationId << "untargeted";
}
QDBusMessage msg = QDBusMessage::createTargetedSignal(dbusService,
notificationServicePath(),
notificationServiceName(),
QStringLiteral("NotificationReplied"));
msg.setArguments({notificationId, text});
QDBusConnection::sessionBus().send(msg);
}
uint ServerPrivate::Inhibit(const QString &desktop_entry, const QString &reason, const QVariantMap &hints)
{
const QString dbusService = message().service();
@ -384,13 +409,13 @@ void ServerPrivate::onInhibitedChanged()
{
// emit DBus change signal...
QDBusMessage signal = QDBusMessage::createSignal(
QStringLiteral("/org/freedesktop/Notifications"),
notificationServicePath(),
QStringLiteral("org.freedesktop.DBus.Properties"),
QStringLiteral("PropertiesChanged")
);
signal.setArguments({
QStringLiteral("org.freedesktop.Notifications"),
notificationServiceInterface(),
QVariantMap{ // updated
{QStringLiteral("Inhibited"), inhibited()},
},

@ -73,6 +73,7 @@ Q_SIGNALS:
void NotificationClosed(uint id, uint reason);
void ActionInvoked(uint id, const QString &actionKey);
// non-standard
// This is manually emitted as targeted signal in sendReplyText()
void NotificationReplied(uint id, const QString &text);
void validChanged();
@ -87,9 +88,12 @@ Q_SIGNALS:
public: // stuff used by public class
friend class ServerInfo;
static QString notificationServiceName();
static QString notificationServicePath();
static QString notificationServiceInterface();
bool init();
uint add(const Notification &notification);
void sendReplyText(const QString &dbusService, uint notificationId, const QString &text);
ServerInfo *currentOwner() const;

Loading…
Cancel
Save