[knuckles] KDE notifications. Fixes #4749

This commit is contained in:
Yann Leboulanger 2009-02-01 10:28:48 +00:00
parent 5678bcb3e6
commit 25f0ee832f
2 changed files with 52 additions and 10 deletions

View File

@ -113,7 +113,7 @@ class SessionBus:
session_bus = 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 '''Returns an interface on the current SessionBus. If the interface isn\'t
running, it tries to start it first.''' running, it tries to start it first.'''
if not supported: if not supported:
@ -129,7 +129,7 @@ def get_interface(interface, path):
started = True started = True
if interface not in running_services: if interface not in running_services:
# try to start the service # 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 started = True
else: else:
started = False started = False
@ -142,10 +142,24 @@ def get_interface(interface, path):
return None return None
def get_notifications_interface(): def get_notifications_interface(notif=None):
'''Returns the notifications interface.''' '''Returns the notifications interface.
return get_interface('org.freedesktop.Notifications',
'/org/freedesktop/Notifications') :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: if supported:
class MissingArgument(dbus.DBusException): class MissingArgument(dbus.DBusException):

View File

@ -481,7 +481,8 @@ class DesktopNotification:
ntype = 'transfer' ntype = 'transfer'
elif event_type == _('File Transfer Error'): elif event_type == _('File Transfer Error'):
ntype = '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' ntype = 'transfer.complete'
elif event_type == _('New E-mail'): elif event_type == _('New E-mail'):
ntype = 'email.arrived' ntype = 'email.arrived'
@ -498,17 +499,41 @@ class DesktopNotification:
'chat_msg_recv.png')) # img to display 'chat_msg_recv.png')) # img to display
ntype = 'im' # Notification Type ntype = 'im' # Notification Type
self.notif = dbus_support.get_notifications_interface() self.notif = dbus_support.get_notifications_interface(self)
if self.notif is None: if self.notif is None:
raise dbus.DBusException('unable to get notifications interface') raise dbus.DBusException('unable to get notifications interface')
self.ntype = ntype self.ntype = ntype
self.get_version() if self.kde_notifications:
self.attempt_notify()
else:
self.get_version()
def attempt_notify(self): def attempt_notify(self):
version = self.version
timeout = gajim.config.get('notification_timeout') # in seconds timeout = gajim.config.get('notification_timeout') # in seconds
ntype = self.ntype ntype = self.ntype
if self.kde_notifications:
notification_text = '<html><img src="%(image)s" align=left />' + \
'%(title)s<br/>%(text)s</html>' % {'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]: if version[:2] == [0, 2]:
try: try:
self.notif.Notify( self.notif.Notify(
@ -586,6 +611,9 @@ class DesktopNotification:
self.notif.CloseNotification(dbus.UInt32(id_)) self.notif.CloseNotification(dbus.UInt32(id_))
self.notif = None self.notif = None
if reason == 'ignore':
return
gajim.interface.handle_event(self.account, self.jid, self.msg_type) gajim.interface.handle_event(self.account, self.jid, self.msg_type)
def version_reply_handler(self, name, vendor, version, spec_version=None): def version_reply_handler(self, name, vendor, version, spec_version=None):