Handle properly closeing of notifications

Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>
feat/with_dbus-1-tqt
Emanoil Kotsev 4 years ago
parent b670a6ae13
commit 2da6bb1dc4

@ -27,8 +27,7 @@
#define NOTIFICATIONS_DBUS_PATH "/org/freedesktop/Notifications" #define NOTIFICATIONS_DBUS_PATH "/org/freedesktop/Notifications"
#define NOTIFICATIONS_DBUS_SRVC "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_TIMEOUT 4000
#define DBUS_CONNECTION_RETRY 3 #define DBUS_CONNECTION_RETRY 3

@ -25,8 +25,8 @@
#define NOTIFICATIONS_DBUS_PATH "/org/freedesktop/Notifications" #define NOTIFICATIONS_DBUS_PATH "/org/freedesktop/Notifications"
#define IMAGE_SIZE 48 #define IMAGE_SIZE 48
#define TDE_VERSION "R14.1.0" #define SRV_VERSION "1.1"
#define VERSION "0.1" #define SPEC_VERSION "1.1"
NotificationsService::NotificationsService(TQT_DBusConnection &conn) NotificationsService::NotificationsService(TQT_DBusConnection &conn)
: org::freedesktop::NotificationsInterface(), mConnection(&conn) : org::freedesktop::NotificationsInterface(), mConnection(&conn)
@ -39,8 +39,22 @@ NotificationsService::~NotificationsService()
// TODO Auto-generated destructor stub // 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) { bool NotificationsService::handleSignalSend(const TQT_DBusMessage& reply) {
mConnection->send(reply);
return true; return true;
} }
@ -59,6 +73,7 @@ bool NotificationsService::GetCapabilities(TQStringList& return_caps, TQT_DBusEr
void NotificationsService::CloseNotificationAsync(int asyncCallId, TQ_UINT32 id) { void NotificationsService::CloseNotificationAsync(int asyncCallId, TQ_UINT32 id) {
closeNotifyWidget(id, 3); // The notification was closed by a call to CloseNotification.
CloseNotificationAsyncReply(asyncCallId); CloseNotificationAsyncReply(asyncCallId);
} }
@ -71,8 +86,8 @@ bool NotificationsService::GetServerInformation(TQString& return_name, TQString&
return_name = TQString("Notification Daemon"); return_name = TQString("Notification Daemon");
return_vendor = TQString("Trinity Desktop Project"); return_vendor = TQString("Trinity Desktop Project");
return_version = TQString(TDE_VERSION); return_version = TQString(SRV_VERSION);
return_spec_version = TQString(VERSION); return_spec_version = TQString(SPEC_VERSION);
return true; return true;
} }
@ -84,7 +99,7 @@ void NotificationsService::NotifyAsync(
const TQMap<TQString, TQT_DBusVariant>& hints, TQ_INT32 timeout) 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]->setFrameStyle( TQFrame::NoFrame );
notificationMap[id]->setIcon(icon); notificationMap[id]->setIcon(icon);
notificationMap[id]->setPaletteBackgroundColor(TQt::black); notificationMap[id]->setPaletteBackgroundColor(TQt::black);
@ -92,7 +107,7 @@ void NotificationsService::NotifyAsync(
// FXIME: handle hypertext in the body // FXIME: handle hypertext in the body
notificationMap[id]->setText(app_name + ": " + summary + "\n" + body); notificationMap[id]->setText(app_name + ": " + summary + "\n" + body);
notificationMap[id]->setActions(actions); notificationMap[id]->setActions(actions);
// notificationMap[id]->setHints(hints); notificationMap[id]->setHints(hints);
notificationMap[id]->setTimeout(timeout); notificationMap[id]->setTimeout(timeout);
notificationMap[id]->show(); notificationMap[id]->show();
notificationMap[id]->raise(); notificationMap[id]->raise();

@ -37,6 +37,8 @@ public:
NotificationsService(TQT_DBusConnection&); NotificationsService(TQT_DBusConnection&);
virtual ~NotificationsService(); virtual ~NotificationsService();
void closeNotifyWidget(TQ_UINT32 id, TQ_UINT32 reason);
protected: // implement sending signals protected: // implement sending signals
virtual bool handleSignalSend(const TQT_DBusMessage& reply); virtual bool handleSignalSend(const TQT_DBusMessage& reply);
virtual TQString objectPath() const; virtual TQString objectPath() const;

@ -23,10 +23,11 @@
#include <tqtimer.h> #include <tqtimer.h>
#include "NotifyWidget.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), : TQLabel( parent, name, WStyle_Customize | WStyle_Splash),
mName(TQString(name)), mId(id) mName(TQString(name)), notificationService(ns), mId(id)
{ {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
@ -40,12 +41,16 @@ NotifyWidget::~NotifyWidget()
void NotifyWidget::mousePressEvent( TQMouseEvent *e ) 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() void NotifyWidget::timeout()
{ {
this->close(); notificationService->closeNotifyWidget(mId, 1); // The notification expired.
} }
void NotifyWidget::setAutoMask(bool b) void NotifyWidget::setAutoMask(bool b)

@ -25,12 +25,14 @@
#include <tqlabel.h> #include <tqlabel.h>
#include <tqdbusvariant.h> #include <tqdbusvariant.h>
class NotificationsService;
class NotifyWidget: public TQLabel class NotifyWidget: public TQLabel
{ {
TQ_OBJECT TQ_OBJECT
public: 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(); virtual ~NotifyWidget();
void setAutoMask(bool b); void setAutoMask(bool b);
@ -47,6 +49,7 @@ private slots:
void timeout(); void timeout();
private: private:
NotificationsService *notificationService;
TQString mName; TQString mName;
TQ_INT32 mId; TQ_INT32 mId;
TQString mIcon; TQString mIcon;

Loading…
Cancel
Save