|
|
|
@ -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"
|
|
|
|
|