Update and clean up

Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>
feat/with_dbus-1-tqt
Emanoil Kotsev 5 months ago
parent fddb929456
commit 7ea09f3f10

@ -26,16 +26,16 @@
#include "NotificationDaemon.h" #include "NotificationDaemon.h"
#define NOTIFICATIONS_DBUS_PATH "/org/freedesktop/Notifications" // path /org/freedesktop/Notifications
#define NOTIFICATIONS_DBUS_SRVC "org.freedesktop.Notifications" #define NOTIFICATIONS_DBUS_SRVC "org.freedesktop.Notifications"
#define DBUS_CONNECTION_TIMEOUT 4000 #define DBUS_CONNECTION_TIMEOUT 4000
#define DBUS_CONNECTION_RETRY 3 #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 // init session connection to dbus
if (!initDBUS()) { if (!initDBUS()) {
tqDebug("Failed to initialize the connection to DBus"); tqDebug("Failed to initialize the connection to DBus");
@ -47,16 +47,7 @@ NotificationDaemon::NotificationDaemon() : KUniqueApplication()
NotificationDaemon::~NotificationDaemon() NotificationDaemon::~NotificationDaemon()
{ {
// close D-Bus connection // close D-Bus connection
close(); dbusConnectionClose();
delete notificationNodeService;
delete freedesktopService;
delete orgService;
delete rootService;
}
bool NotificationDaemon::isConnectedToDBUS(){
return mConnection.isConnected();
} }
bool NotificationDaemon::initDBUS(){ bool NotificationDaemon::initDBUS(){
@ -67,29 +58,51 @@ bool NotificationDaemon::initDBUS(){
+ mConnection.lastError().message()); + mConnection.lastError().message());
return false; return false;
} }
mConnection.connect(this, TQ_SLOT(slotDbusSignal(const TQT_DBusMessage&)));
// try to get a specific service name // try to get a specific service name
if (!mConnection.requestName(NOTIFICATIONS_DBUS_SRVC, TQT_DBusConnection::NoReplace)) if (!mConnection.requestName(NOTIFICATIONS_DBUS_SRVC, TQT_DBusConnection::NoReplace))
return false; return false;
// make sure we get a reply
mConnection.scheduleDispatch(); mConnection.scheduleDispatch();
mConnection.connect(this, TQ_SLOT(slotDbusSignal(const TQT_DBusMessage&)));
TQTimer::singleShot(10, this, TQ_SLOT(slotConnectionCheck()));
return true; 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()) { if(mConnection.isConnected()) {
mConnection.disconnect(this, TQ_SLOT(slotDbusSignal(const TQT_DBusMessage&))); mConnection.disconnect(this, TQ_SLOT(slotDbusSignal(const TQT_DBusMessage&)));
mConnection.closeConnection(NOTIFICATIONS_DBUS_SRVC); mConnection.closeConnection(NOTIFICATIONS_DBUS_SRVC);
} }
retryCount=0;
} }
void NotificationDaemon::slotReconnect() { void NotificationDaemon::slotReconnect() {
close(); dbusConnectionClose();
if (!initDBUS()) { if (!initDBUS()) {
if (DBUS_CONNECTION_RETRY > retryCount) { if (DBUS_CONNECTION_RETRY > retryCount) {
@ -101,26 +114,18 @@ void NotificationDaemon::slotReconnect() {
} }
void NotificationDaemon::slotDbusSignal(const TQT_DBusMessage& message) { void NotificationDaemon::slotDbusSignal(const TQT_DBusMessage& message) {
if (message.interface() != TQString("org.freedesktop.DBus")) TQString serviceName = message[0].toString();
return; if ( message.interface() == TQString("org.freedesktop.DBus") &&
if (message.member() != TQString("NameAcquired")) message.member() == TQString("NameAcquired") &&
return; serviceName == NOTIFICATIONS_DBUS_SRVC )
tqDebug("Name acquired: " + message[0].toString()); {
serviceName = message[0].toString(); tqDebug("TDENotification unique DBus name acquired: " + serviceName);
} rootService = new RootNodeService(mConnection);
orgService = new OrgNodeService(mConnection);
void NotificationDaemon::slotConnectionCheck() { freedesktopService = new FreeDesktopNodeService(mConnection);
notificationNodeService = new NotificationsNodeService(mConnection);
if (serviceName != NOTIFICATIONS_DBUS_SRVC) { tqDebug("TDENotification service setup done.");
tqFatal("TDE Notification service already running or no unique name possible.");
} }
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" #include "NotificationDaemon.moc"

@ -37,32 +37,6 @@ public:
NotificationDaemon(); NotificationDaemon();
virtual ~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: private:
/*! /*!
* This function initialise the connection to the D-Bus daemon. * This function initialise the connection to the D-Bus daemon.
@ -72,7 +46,7 @@ private:
*/ */
bool initDBUS(); bool initDBUS();
//! to close the connection to D-Bus //! to close the connection to D-Bus
void close(); void dbusConnectionClose();
private: private:
RootNodeService *rootService; RootNodeService *rootService;
@ -82,8 +56,18 @@ private:
TQT_DBusConnection mConnection; TQT_DBusConnection mConnection;
int retryCount; 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_ */ #endif /* SRC_DAEMON_NOTIFICATIONDAEMON_H_ */

@ -30,6 +30,8 @@
#define SRV_VERSION "1.1" #define SRV_VERSION "1.1"
#define SPEC_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) NotificationsService::NotificationsService(TQT_DBusConnection &conn)
: org::freedesktop::NotificationsInterface(), mConnection(&conn) : org::freedesktop::NotificationsInterface(), mConnection(&conn)
@ -46,7 +48,6 @@ void NotificationsService::closeNotifyWidget(TQ_UINT32 id, TQ_UINT32 reason) {
if (notificationMap[id]) { if (notificationMap[id]) {
notificationMap[id]->close(); notificationMap[id]->close();
delete notificationMap[id];
notificationMap.remove(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) { 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_name = TQString(NOTIFICATIONS_NAME);
return_vendor = TQString("Trinity Desktop Project"); return_vendor = TQString(TRINITY_DESKTOP_PROJECT);
return_version = TQString(SRV_VERSION); return_version = TQString(SRV_VERSION);
return_spec_version = TQString(SPEC_VERSION); return_spec_version = TQString(SPEC_VERSION);
return true; return true;

@ -45,25 +45,21 @@ public:
protected: // implement sending signals protected: // implement sending signals
virtual bool handleSignalSend(const TQT_DBusMessage& reply); virtual bool handleSignalSend(const TQT_DBusMessage& reply);
// return the object path
virtual TQString objectPath() const; virtual TQString objectPath() const;
protected: protected:
// implement DBus calls
virtual bool GetCapabilities(TQStringList& return_caps, TQT_DBusError& error); virtual bool GetCapabilities(TQStringList& return_caps, TQT_DBusError& error);
virtual void CloseNotificationAsync(int asyncCallId, TQ_UINT32 id); virtual void CloseNotificationAsync(int asyncCallId, TQ_UINT32 id);
virtual bool ReloadSettings(TQT_DBusError& error); 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 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); 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);
// implement sending replies
protected: // implement sending replies
virtual void handleMethodReply(const TQT_DBusMessage& reply); virtual void handleMethodReply(const TQT_DBusMessage& reply);
private: private:
TQT_DBusConnection *mConnection; TQT_DBusConnection *mConnection;
TQMap<TQ_UINT32, NotifyWidget*> notificationMap; TQMap<TQ_UINT32, NotifyWidget*> notificationMap;
}; };

@ -38,12 +38,15 @@ NotifyWidget::NotifyWidget(TQWidget *parent, const char *name, NotificationsServ
TQDesktopWidget *d = TQApplication::desktop(); TQDesktopWidget *d = TQApplication::desktop();
mPosition=TQPoint(d->width()-50, d->height()-20); mPosition=TQPoint(d->width()-50, d->height()-20);
move(mPosition); 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() NotifyWidget::~NotifyWidget()
{ {
// TODO Auto-generated destructor stub if(notificationService)
delete notificationService;
} }
void NotifyWidget::mousePressEvent( TQMouseEvent *e ) void NotifyWidget::mousePressEvent( TQMouseEvent *e )

@ -54,16 +54,5 @@ main(int argc, char **argv)
NotificationDaemon app; NotificationDaemon app;
app.disableSessionManagement(); app.disableSessionManagement();
if (!app.isConnectedToDBUS()) return app.exec();
{
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();
}
} }

@ -41,9 +41,11 @@ class RootNodeService : public DBusBaseNode
{ {
public: public:
RootNodeService(TQT_DBusConnection&); RootNodeService(TQT_DBusConnection&);
~RootNodeService(); virtual ~RootNodeService();
protected: protected:
virtual TQT_DBusObjectBase* createInterface(const TQString&); virtual TQT_DBusObjectBase* createInterface(const TQString&);
private: private:
TQMap<TQString, TQT_DBusObjectBase*> mInterfaces; TQMap<TQString, TQT_DBusObjectBase*> mInterfaces;
TQT_DBusConnection mConnection; TQT_DBusConnection mConnection;
@ -59,9 +61,11 @@ class OrgNodeService : public DBusBaseNode
{ {
public: public:
OrgNodeService(TQT_DBusConnection&); OrgNodeService(TQT_DBusConnection&);
~OrgNodeService(); virtual ~OrgNodeService();
protected: protected:
virtual TQT_DBusObjectBase* createInterface(const TQString&); virtual TQT_DBusObjectBase* createInterface(const TQString&);
private: private:
TQMap<TQString, TQT_DBusObjectBase*> mInterfaces; TQMap<TQString, TQT_DBusObjectBase*> mInterfaces;
TQT_DBusConnection mConnection; TQT_DBusConnection mConnection;
@ -77,9 +81,11 @@ class FreeDesktopNodeService : public DBusBaseNode
{ {
public: public:
FreeDesktopNodeService(TQT_DBusConnection&); FreeDesktopNodeService(TQT_DBusConnection&);
~FreeDesktopNodeService(); virtual ~FreeDesktopNodeService();
protected: protected:
virtual TQT_DBusObjectBase* createInterface(const TQString&); virtual TQT_DBusObjectBase* createInterface(const TQString&);
private: private:
TQMap<TQString, TQT_DBusObjectBase*> mInterfaces; TQMap<TQString, TQT_DBusObjectBase*> mInterfaces;
TQT_DBusConnection mConnection; TQT_DBusConnection mConnection;
@ -95,7 +101,7 @@ class NotificationsNodeService : public org::freedesktop::NotificationsNode
{ {
public: public:
NotificationsNodeService(TQT_DBusConnection&); NotificationsNodeService(TQT_DBusConnection&);
~NotificationsNodeService(); virtual ~NotificationsNodeService();
protected: protected:
virtual TQT_DBusObjectBase* createInterface(const TQString&); virtual TQT_DBusObjectBase* createInterface(const TQString&);

Loading…
Cancel
Save