summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmanoil Kotsev <deloptes@gmail.com>2021-05-14 20:01:28 +0200
committerEmanoil Kotsev <deloptes@gmail.com>2024-11-09 18:49:26 +0000
commit2da6bb1dc4d5e5b9f0801c102869c2fb4d98b5b2 (patch)
treedd2155bc6a67be519fd3bf5ddbdd45da289d1ea8
parentb670a6ae130fdc45b942a864046b9dda17feb2a1 (diff)
downloadkdbusnotification-2da6bb1dc4d5e5b9f0801c102869c2fb4d98b5b2.tar.gz
kdbusnotification-2da6bb1dc4d5e5b9f0801c102869c2fb4d98b5b2.zip
Handle properly closeing of notifications
Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>
-rw-r--r--src/daemon/NotificationDaemon.cpp3
-rw-r--r--src/daemon/NotificationsService.cpp27
-rw-r--r--src/daemon/NotificationsService.h2
-rw-r--r--src/daemon/NotifyWidget.cpp13
-rw-r--r--src/daemon/NotifyWidget.h5
5 files changed, 37 insertions, 13 deletions
diff --git a/src/daemon/NotificationDaemon.cpp b/src/daemon/NotificationDaemon.cpp
index 81e5d08..1c9aa56 100644
--- a/src/daemon/NotificationDaemon.cpp
+++ b/src/daemon/NotificationDaemon.cpp
@@ -27,8 +27,7 @@
#define NOTIFICATIONS_DBUS_PATH "/org/freedesktop/Notifications"
#define NOTIFICATIONS_DBUS_SRVC "org.freedesktop.Notifications"
-#define DBUS_PATH "/org/freedesktop/DBus"
-#define DBUS_SRVC "org.freedesktop.DBus"
+
#define DBUS_CONNECTION_TIMEOUT 4000
#define DBUS_CONNECTION_RETRY 3
diff --git a/src/daemon/NotificationsService.cpp b/src/daemon/NotificationsService.cpp
index 297068f..b5bd0ad 100644
--- a/src/daemon/NotificationsService.cpp
+++ b/src/daemon/NotificationsService.cpp
@@ -25,8 +25,8 @@
#define NOTIFICATIONS_DBUS_PATH "/org/freedesktop/Notifications"
#define IMAGE_SIZE 48
-#define TDE_VERSION "R14.1.0"
-#define VERSION "0.1"
+#define SRV_VERSION "1.1"
+#define SPEC_VERSION "1.1"
NotificationsService::NotificationsService(TQT_DBusConnection &conn)
: org::freedesktop::NotificationsInterface(), mConnection(&conn)
@@ -39,8 +39,22 @@ NotificationsService::~NotificationsService()
// TODO Auto-generated destructor stub
}
+void NotificationsService::closeNotifyWidget(TQ_UINT32 id, TQ_UINT32 reason) {
+
+ if (notificationMap[id]) {
+ notificationMap[id]->close();
+ delete notificationMap[id];
+ notificationMap.remove(id);
+ }
+
+ if ( !emitNotificationClosed(id, reason) ) {
+ tqWarning("Failed to emit DBus signal NotificationClosed");
+ }
+}
+
bool NotificationsService::handleSignalSend(const TQT_DBusMessage& reply) {
+ mConnection->send(reply);
return true;
}
@@ -59,6 +73,7 @@ bool NotificationsService::GetCapabilities(TQStringList& return_caps, TQT_DBusEr
void NotificationsService::CloseNotificationAsync(int asyncCallId, TQ_UINT32 id) {
+ closeNotifyWidget(id, 3); // The notification was closed by a call to CloseNotification.
CloseNotificationAsyncReply(asyncCallId);
}
@@ -71,8 +86,8 @@ bool NotificationsService::GetServerInformation(TQString& return_name, TQString&
return_name = TQString("Notification Daemon");
return_vendor = TQString("Trinity Desktop Project");
- return_version = TQString(TDE_VERSION);
- return_spec_version = TQString(VERSION);
+ return_version = TQString(SRV_VERSION);
+ return_spec_version = TQString(SPEC_VERSION);
return true;
}
@@ -84,7 +99,7 @@ void NotificationsService::NotifyAsync(
const TQMap<TQString, TQT_DBusVariant>& hints, TQ_INT32 timeout)
{
- notificationMap[id] = new NotifyWidget(0, app_name.ascii(), id );
+ notificationMap[id] = new NotifyWidget(0, app_name.ascii(), this, id );
notificationMap[id]->setFrameStyle( TQFrame::NoFrame );
notificationMap[id]->setIcon(icon);
notificationMap[id]->setPaletteBackgroundColor(TQt::black);
@@ -92,7 +107,7 @@ void NotificationsService::NotifyAsync(
// FXIME: handle hypertext in the body
notificationMap[id]->setText(app_name + ": " + summary + "\n" + body);
notificationMap[id]->setActions(actions);
-// notificationMap[id]->setHints(hints);
+ notificationMap[id]->setHints(hints);
notificationMap[id]->setTimeout(timeout);
notificationMap[id]->show();
notificationMap[id]->raise();
diff --git a/src/daemon/NotificationsService.h b/src/daemon/NotificationsService.h
index ac885c1..5e96a05 100644
--- a/src/daemon/NotificationsService.h
+++ b/src/daemon/NotificationsService.h
@@ -37,6 +37,8 @@ public:
NotificationsService(TQT_DBusConnection&);
virtual ~NotificationsService();
+ void closeNotifyWidget(TQ_UINT32 id, TQ_UINT32 reason);
+
protected: // implement sending signals
virtual bool handleSignalSend(const TQT_DBusMessage& reply);
virtual TQString objectPath() const;
diff --git a/src/daemon/NotifyWidget.cpp b/src/daemon/NotifyWidget.cpp
index 0cc9d5d..0b304af 100644
--- a/src/daemon/NotifyWidget.cpp
+++ b/src/daemon/NotifyWidget.cpp
@@ -23,10 +23,11 @@
#include <tqtimer.h>
#include "NotifyWidget.h"
+#include "NotificationsService.h"
-NotifyWidget::NotifyWidget( TQWidget *parent, const char *name, TQ_INT32 id )
+NotifyWidget::NotifyWidget(TQWidget *parent, const char *name, NotificationsService *ns, TQ_INT32 id )
: TQLabel( parent, name, WStyle_Customize | WStyle_Splash),
- mName(TQString(name)), mId(id)
+ mName(TQString(name)), notificationService(ns), mId(id)
{
// TODO Auto-generated constructor stub
@@ -40,12 +41,16 @@ NotifyWidget::~NotifyWidget()
void NotifyWidget::mousePressEvent( TQMouseEvent *e )
{
- this->close();
+ if (e->button() == TQMouseEvent::LeftButton)
+ {
+ // The notification was dismissed by the user.
+ notificationService->closeNotifyWidget(mId, 2);
+ }
}
void NotifyWidget::timeout()
{
- this->close();
+ notificationService->closeNotifyWidget(mId, 1); // The notification expired.
}
void NotifyWidget::setAutoMask(bool b)
diff --git a/src/daemon/NotifyWidget.h b/src/daemon/NotifyWidget.h
index c28bcd5..563f3f2 100644
--- a/src/daemon/NotifyWidget.h
+++ b/src/daemon/NotifyWidget.h
@@ -25,12 +25,14 @@
#include <tqlabel.h>
#include <tqdbusvariant.h>
+class NotificationsService;
+
class NotifyWidget: public TQLabel
{
TQ_OBJECT
public:
- NotifyWidget( TQWidget *parent=0, const char *name=0, TQ_INT32 id=0 );
+ NotifyWidget(TQWidget *parent=0, const char *name=0, NotificationsService *ns=0, TQ_INT32 id=0 );
virtual ~NotifyWidget();
void setAutoMask(bool b);
@@ -47,6 +49,7 @@ private slots:
void timeout();
private:
+ NotificationsService *notificationService;
TQString mName;
TQ_INT32 mId;
TQString mIcon;