diff options
author | Emanoil Kotsev <deloptes@gmail.com> | 2024-06-26 20:21:35 +0000 |
---|---|---|
committer | Emanoil Kotsev <deloptes@gmail.com> | 2024-11-09 18:49:26 +0000 |
commit | 7ea09f3f10350e44b8b41566f50449219cf6a4bf (patch) | |
tree | 13f43bb3f49078d63cdc992a5f50301bcba6e10d /src/daemon | |
parent | fddb92945609b0b1f69967a9729f030b712ebdca (diff) | |
download | kdbusnotification-7ea09f3f10350e44b8b41566f50449219cf6a4bf.tar.gz kdbusnotification-7ea09f3f10350e44b8b41566f50449219cf6a4bf.zip |
Update and clean up
Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>
Diffstat (limited to 'src/daemon')
-rw-r--r-- | src/daemon/NotificationDaemon.cpp | 81 | ||||
-rw-r--r-- | src/daemon/NotificationDaemon.h | 40 | ||||
-rw-r--r-- | src/daemon/NotificationsService.cpp | 7 | ||||
-rw-r--r-- | src/daemon/NotificationsService.h | 10 | ||||
-rw-r--r-- | src/daemon/NotifyWidget.cpp | 7 | ||||
-rw-r--r-- | src/daemon/main.cpp | 13 | ||||
-rw-r--r-- | src/daemon/notificationNodeService.h | 14 |
7 files changed, 78 insertions, 94 deletions
diff --git a/src/daemon/NotificationDaemon.cpp b/src/daemon/NotificationDaemon.cpp index 2b3979d..c982883 100644 --- a/src/daemon/NotificationDaemon.cpp +++ b/src/daemon/NotificationDaemon.cpp @@ -26,16 +26,16 @@ #include "NotificationDaemon.h" -#define NOTIFICATIONS_DBUS_PATH "/org/freedesktop/Notifications" +// path /org/freedesktop/Notifications #define NOTIFICATIONS_DBUS_SRVC "org.freedesktop.Notifications" #define DBUS_CONNECTION_TIMEOUT 4000 #define DBUS_CONNECTION_RETRY 3 -NotificationDaemon::NotificationDaemon() : KUniqueApplication() +NotificationDaemon::NotificationDaemon() + : KUniqueApplication(), + retryCount(0) { - // TODO Auto-generated constructor stub - retryCount=0; // init session connection to dbus if (!initDBUS()) { tqDebug("Failed to initialize the connection to DBus"); @@ -47,16 +47,7 @@ NotificationDaemon::NotificationDaemon() : KUniqueApplication() NotificationDaemon::~NotificationDaemon() { // close D-Bus connection - close(); - - delete notificationNodeService; - delete freedesktopService; - delete orgService; - delete rootService; -} - -bool NotificationDaemon::isConnectedToDBUS(){ - return mConnection.isConnected(); + dbusConnectionClose(); } bool NotificationDaemon::initDBUS(){ @@ -67,29 +58,51 @@ bool NotificationDaemon::initDBUS(){ + mConnection.lastError().message()); return false; } + mConnection.connect(this, TQ_SLOT(slotDbusSignal(const TQT_DBusMessage&))); // try to get a specific service name if (!mConnection.requestName(NOTIFICATIONS_DBUS_SRVC, TQT_DBusConnection::NoReplace)) return false; + // make sure we get a reply mConnection.scheduleDispatch(); - mConnection.connect(this, TQ_SLOT(slotDbusSignal(const TQT_DBusMessage&))); - - TQTimer::singleShot(10, this, TQ_SLOT(slotConnectionCheck())); return true; } -void NotificationDaemon::close() { +void NotificationDaemon::dbusConnectionClose() { + + if(rootService) + { + delete rootService; + rootService=0; + } + if(orgService) + { + delete orgService; + orgService=0; + } + if(freedesktopService) + { + delete freedesktopService; + freedesktopService=0; + } + if(notificationNodeService) + { + delete notificationNodeService; + notificationNodeService=0; + } + if(mConnection.isConnected()) { mConnection.disconnect(this, TQ_SLOT(slotDbusSignal(const TQT_DBusMessage&))); mConnection.closeConnection(NOTIFICATIONS_DBUS_SRVC); } + retryCount=0; } void NotificationDaemon::slotReconnect() { - close(); + dbusConnectionClose(); if (!initDBUS()) { if (DBUS_CONNECTION_RETRY > retryCount) { @@ -101,26 +114,18 @@ void NotificationDaemon::slotReconnect() { } void NotificationDaemon::slotDbusSignal(const TQT_DBusMessage& message) { - if (message.interface() != TQString("org.freedesktop.DBus")) - return; - if (message.member() != TQString("NameAcquired")) - return; - tqDebug("Name acquired: " + message[0].toString()); - serviceName = message[0].toString(); -} - -void NotificationDaemon::slotConnectionCheck() { - - if (serviceName != NOTIFICATIONS_DBUS_SRVC) { - tqFatal("TDE Notification service already running or no unique name possible."); + TQString serviceName = message[0].toString(); + if ( message.interface() == TQString("org.freedesktop.DBus") && + message.member() == TQString("NameAcquired") && + serviceName == NOTIFICATIONS_DBUS_SRVC ) + { + tqDebug("TDENotification unique DBus name acquired: " + serviceName); + rootService = new RootNodeService(mConnection); + orgService = new OrgNodeService(mConnection); + freedesktopService = new FreeDesktopNodeService(mConnection); + notificationNodeService = new NotificationsNodeService(mConnection); + tqDebug("TDENotification service setup done."); } - - rootService = new RootNodeService(mConnection); - orgService = new OrgNodeService(mConnection); - freedesktopService = new FreeDesktopNodeService(mConnection); - notificationNodeService = new NotificationsNodeService(mConnection); - - tqDebug("TDE Notification service setup done."); } #include "NotificationDaemon.moc" diff --git a/src/daemon/NotificationDaemon.h b/src/daemon/NotificationDaemon.h index 3aa8983..c655f98 100644 --- a/src/daemon/NotificationDaemon.h +++ b/src/daemon/NotificationDaemon.h @@ -37,32 +37,6 @@ public: NotificationDaemon(); virtual ~NotificationDaemon(); - bool isConnectedToDBUS(); - -private slots: - /*! - * This function does a reconnect to D-Bus. - * \return void - */ - void slotReconnect(); - /*! - * This function is to process D-Bus signals. - * \return void - */ - void slotDbusSignal(const TQT_DBusMessage&); - /*! - * This function is to check D-Bus connection. - * and if the name is the unique name prepare the receivers - * If the name is not the unique name it mans the service - * is already running or unique name can not be obtained from - * DBus. In this latter case the application will terminate. - * - * \return void - */ - void slotConnectionCheck(); - -// void slotCloseNotification(const TQ_UINT32); - private: /*! * This function initialise the connection to the D-Bus daemon. @@ -72,7 +46,7 @@ private: */ bool initDBUS(); //! to close the connection to D-Bus - void close(); + void dbusConnectionClose(); private: RootNodeService *rootService; @@ -82,8 +56,18 @@ private: TQT_DBusConnection mConnection; int retryCount; - TQString serviceName; +private slots: + /*! + * This function does a reconnect to D-Bus. + * \return void + */ + void slotReconnect(); + /*! + * This function is to process D-Bus signals. + * \return void + */ + void slotDbusSignal(const TQT_DBusMessage&); }; #endif /* SRC_DAEMON_NOTIFICATIONDAEMON_H_ */ diff --git a/src/daemon/NotificationsService.cpp b/src/daemon/NotificationsService.cpp index f2992c7..9ee757b 100644 --- a/src/daemon/NotificationsService.cpp +++ b/src/daemon/NotificationsService.cpp @@ -30,6 +30,8 @@ #define SRV_VERSION "1.1" #define SPEC_VERSION "1.1" +#define NOTIFICATIONS_NAME "Notification Daemon" +#define TRINITY_DESKTOP_PROJECT "Trinity Desktop Project" NotificationsService::NotificationsService(TQT_DBusConnection &conn) : org::freedesktop::NotificationsInterface(), mConnection(&conn) @@ -46,7 +48,6 @@ void NotificationsService::closeNotifyWidget(TQ_UINT32 id, TQ_UINT32 reason) { if (notificationMap[id]) { notificationMap[id]->close(); - delete notificationMap[id]; notificationMap.remove(id); } @@ -87,8 +88,8 @@ bool NotificationsService::ReloadSettings(TQT_DBusError& error) { bool NotificationsService::GetServerInformation(TQString& return_name, TQString& return_vendor, TQString& return_version, TQString& return_spec_version, TQT_DBusError& error) { - return_name = TQString("Notification Daemon"); - return_vendor = TQString("Trinity Desktop Project"); + return_name = TQString(NOTIFICATIONS_NAME); + return_vendor = TQString(TRINITY_DESKTOP_PROJECT); return_version = TQString(SRV_VERSION); return_spec_version = TQString(SPEC_VERSION); return true; diff --git a/src/daemon/NotificationsService.h b/src/daemon/NotificationsService.h index 524d00e..c461b34 100644 --- a/src/daemon/NotificationsService.h +++ b/src/daemon/NotificationsService.h @@ -45,25 +45,21 @@ public: protected: // implement sending signals virtual bool handleSignalSend(const TQT_DBusMessage& reply); + // return the object path virtual TQString objectPath() const; protected: + // implement DBus calls virtual bool GetCapabilities(TQStringList& return_caps, TQT_DBusError& error); - virtual void CloseNotificationAsync(int asyncCallId, TQ_UINT32 id); - virtual bool ReloadSettings(TQT_DBusError& error); - virtual bool GetServerInformation(TQString& return_name, TQString& return_vendor, TQString& return_version, TQString& return_spec_version, TQT_DBusError& error); - virtual void NotifyAsync(int asyncCallId, const TQString& app_name, TQ_UINT32 id, const TQString& icon, const TQString& summary, const TQString& body, const TQStringList& actions, const TQMap< TQString, TQT_DBusVariant >& hints, TQ_INT32 timeout); - -protected: // implement sending replies + // implement sending replies virtual void handleMethodReply(const TQT_DBusMessage& reply); private: TQT_DBusConnection *mConnection; - TQMap<TQ_UINT32, NotifyWidget*> notificationMap; }; diff --git a/src/daemon/NotifyWidget.cpp b/src/daemon/NotifyWidget.cpp index 558a80c..482fe84 100644 --- a/src/daemon/NotifyWidget.cpp +++ b/src/daemon/NotifyWidget.cpp @@ -38,12 +38,15 @@ NotifyWidget::NotifyWidget(TQWidget *parent, const char *name, NotificationsServ TQDesktopWidget *d = TQApplication::desktop(); mPosition=TQPoint(d->width()-50, d->height()-20); move(mPosition); - TQTimer::singleShot(100, this, TQ_SLOT(fadeAway())); +// TODO: give the user an option to configure if he/she wants to have +// the notification fading away from down to top +// TQTimer::singleShot(100, this, TQ_SLOT(fadeAway())); } NotifyWidget::~NotifyWidget() { - // TODO Auto-generated destructor stub + if(notificationService) + delete notificationService; } void NotifyWidget::mousePressEvent( TQMouseEvent *e ) diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp index 8719153..bda9aa5 100644 --- a/src/daemon/main.cpp +++ b/src/daemon/main.cpp @@ -54,16 +54,5 @@ main(int argc, char **argv) NotificationDaemon app; app.disableSessionManagement(); - if (!app.isConnectedToDBUS()) - { - KMessageBox::error(NULL,i18n("Can't connect to DBus!")); - // debug message for testing - tqDebug(i18n("Can't connect to DBus!\n").local8Bit()); - KUniqueApplication::kApplication()->quit(); - return -1; - } - else - { - return app.exec(); - } + return app.exec(); } diff --git a/src/daemon/notificationNodeService.h b/src/daemon/notificationNodeService.h index c87f080..5cee767 100644 --- a/src/daemon/notificationNodeService.h +++ b/src/daemon/notificationNodeService.h @@ -41,9 +41,11 @@ class RootNodeService : public DBusBaseNode { public: RootNodeService(TQT_DBusConnection&); - ~RootNodeService(); + virtual ~RootNodeService(); + protected: virtual TQT_DBusObjectBase* createInterface(const TQString&); + private: TQMap<TQString, TQT_DBusObjectBase*> mInterfaces; TQT_DBusConnection mConnection; @@ -59,9 +61,11 @@ class OrgNodeService : public DBusBaseNode { public: OrgNodeService(TQT_DBusConnection&); - ~OrgNodeService(); + virtual ~OrgNodeService(); + protected: virtual TQT_DBusObjectBase* createInterface(const TQString&); + private: TQMap<TQString, TQT_DBusObjectBase*> mInterfaces; TQT_DBusConnection mConnection; @@ -77,9 +81,11 @@ class FreeDesktopNodeService : public DBusBaseNode { public: FreeDesktopNodeService(TQT_DBusConnection&); - ~FreeDesktopNodeService(); + virtual ~FreeDesktopNodeService(); + protected: virtual TQT_DBusObjectBase* createInterface(const TQString&); + private: TQMap<TQString, TQT_DBusObjectBase*> mInterfaces; TQT_DBusConnection mConnection; @@ -95,7 +101,7 @@ class NotificationsNodeService : public org::freedesktop::NotificationsNode { public: NotificationsNodeService(TQT_DBusConnection&); - ~NotificationsNodeService(); + virtual ~NotificationsNodeService(); protected: virtual TQT_DBusObjectBase* createInterface(const TQString&); |