From 25f0ee832ffe9b950e2241c9ef5baf94cab0b2ab Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sun, 1 Feb 2009 10:28:48 +0000 Subject: [PATCH] [knuckles] KDE notifications. Fixes #4749 --- src/common/dbus_support.py | 26 ++++++++++++++++++++------ src/notify.py | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/common/dbus_support.py b/src/common/dbus_support.py index be69564ac..fd9f8111d 100644 --- a/src/common/dbus_support.py +++ b/src/common/dbus_support.py @@ -113,7 +113,7 @@ class SessionBus: session_bus = SessionBus() -def get_interface(interface, path): +def get_interface(interface, path, start_service=True): '''Returns an interface on the current SessionBus. If the interface isn\'t running, it tries to start it first.''' if not supported: @@ -129,7 +129,7 @@ def get_interface(interface, path): started = True if interface not in running_services: # try to start the service - if dbus_iface.StartServiceByName(interface, dbus.UInt32(0)) == 1: + if start_service and dbus_iface.StartServiceByName(interface, dbus.UInt32(0)) == 1: started = True else: started = False @@ -142,10 +142,24 @@ def get_interface(interface, path): return None -def get_notifications_interface(): - '''Returns the notifications interface.''' - return get_interface('org.freedesktop.Notifications', - '/org/freedesktop/Notifications') +def get_notifications_interface(notif=None): + '''Returns the notifications interface. + + :param notif: DesktopNotification instance''' + # try to see if KDE notifications are available + iface = get_interface('org.kde.VisualNotifications', '/VisualNotifications', + start_service=False) + if iface != None: + if notif != None: + notif.kde_notifications = True + return iface + # KDE notifications don't seem to be available, falling back to + # notification-daemon + else: + if notif != None: + notif.kde_notifications = False + return get_interface('org.freedesktop.Notifications', + '/org/freedesktop/Notifications') if supported: class MissingArgument(dbus.DBusException): diff --git a/src/notify.py b/src/notify.py index 3473375f2..55d62ef3c 100644 --- a/src/notify.py +++ b/src/notify.py @@ -481,7 +481,8 @@ class DesktopNotification: ntype = 'transfer' elif event_type == _('File Transfer Error'): ntype = 'transfer.error' - elif event_type in (_('File Transfer Completed'), _('File Transfer Stopped')): + elif event_type in (_('File Transfer Completed'), + _('File Transfer Stopped')): ntype = 'transfer.complete' elif event_type == _('New E-mail'): ntype = 'email.arrived' @@ -498,17 +499,41 @@ class DesktopNotification: 'chat_msg_recv.png')) # img to display ntype = 'im' # Notification Type - self.notif = dbus_support.get_notifications_interface() + self.notif = dbus_support.get_notifications_interface(self) if self.notif is None: raise dbus.DBusException('unable to get notifications interface') self.ntype = ntype - self.get_version() + if self.kde_notifications: + self.attempt_notify() + else: + self.get_version() def attempt_notify(self): - version = self.version timeout = gajim.config.get('notification_timeout') # in seconds ntype = self.ntype + if self.kde_notifications: + notification_text = '' + \ + '%(title)s
%(text)s' % {'title': self.title, + 'text': self.text, 'image': self.path_to_image} + gajim_icon = os.path.abspath(os.path.join(gajim.DATA_DIR, 'pixmaps', + 'gajim.png')) + self.notif.Notify( + dbus.String(_('Gajim')), # app_name (string) + dbus.UInt32(0), # replaces_id (uint) + ntype, # event_id (string) + dbus.String(gajim_icon), # app_icon (string) + dbus.String(_('')), # summary (string) + dbus.String(notification_text), # body (string) + # actions (stringlist) + (dbus.String('default'), dbus.String(self.event_type), + dbus.String('ignore'), dbus.String(_('Ignore'))), + [], # hints (not used in KDE yet) + dbus.UInt32(timeout*1000), # timeout (int), in ms + reply_handler=self.attach_by_id, + error_handler=self.notify_another_way) + return + version = self.version if version[:2] == [0, 2]: try: self.notif.Notify( @@ -586,6 +611,9 @@ class DesktopNotification: self.notif.CloseNotification(dbus.UInt32(id_)) self.notif = None + if reason == 'ignore': + return + gajim.interface.handle_event(self.account, self.jid, self.msg_type) def version_reply_handler(self, name, vendor, version, spec_version=None):