don't fail when notification-daemon doesn't follow specifications. Fixes #5638

This commit is contained in:
Yann Leboulanger 2010-03-14 00:12:18 +01:00
parent 6b36b6729d
commit 2cdca091fc
1 changed files with 40 additions and 26 deletions

View File

@ -553,7 +553,8 @@ class DesktopNotification:
'%(title)s<br/>%(text)s</html>') % {'title': self.title,
'text': self.text, 'image': self.path_to_image}
gajim_icon = gtkgui_helpers.get_icon_path('gajim', 48)
self.notif.Notify(
try:
self.notif.Notify(
dbus.String(_('Gajim')), # app_name (string)
dbus.UInt32(0), # replaces_id (uint)
ntype, # event_id (string)
@ -567,7 +568,9 @@ class DesktopNotification:
dbus.UInt32(timeout*1000), # timeout (int), in ms
reply_handler=self.attach_by_id,
error_handler=self.notify_another_way)
return
return
except Exception:
pass
version = self.version
if version[:2] == [0, 2]:
actions = {}
@ -614,29 +617,36 @@ class DesktopNotification:
if 'actions' in self.capabilities:
actions = (dbus.String('default'), dbus.String(
self.event_type))
self.notif.Notify(
dbus.String(_('Gajim')),
dbus.UInt32(0), # this notification does not replace other
dbus.String(self.path_to_image),
dbus.String(self.title),
dbus.String(text),
actions,
hints,
dbus.UInt32(timeout*1000),
reply_handler=self.attach_by_id,
error_handler=self.notify_another_way)
try:
self.notif.Notify(
dbus.String(_('Gajim')),
# this notification does not replace other
dbus.UInt32(0),
dbus.String(self.path_to_image),
dbus.String(self.title),
dbus.String(text),
actions,
hints,
dbus.UInt32(timeout*1000),
reply_handler=self.attach_by_id,
error_handler=self.notify_another_way)
except Exception:
self.notify_another_way()
else:
self.notif.Notify(
dbus.String(_('Gajim')),
dbus.String(self.path_to_image),
dbus.UInt32(0),
dbus.String(self.title),
dbus.String(self.text),
dbus.String(''),
hints,
dbus.UInt32(timeout*1000),
reply_handler=self.attach_by_id,
error_handler=self.notify_another_way)
try:
self.notif.Notify(
dbus.String(_('Gajim')),
dbus.String(self.path_to_image),
dbus.UInt32(0),
dbus.String(self.title),
dbus.String(self.text),
dbus.String(''),
hints,
dbus.UInt32(timeout*1000),
reply_handler=self.attach_by_id,
error_handler=self.notify_another_way)
except Exception:
self.notify_another_way()
def attach_by_id(self, id_):
self.id = id_
@ -644,8 +654,12 @@ class DesktopNotification:
notification_response_manager.add_pending(self.id, self)
def notify_another_way(self, e):
gajim.log.debug(str(e))
gajim.log.debug('Need to implement a new way of falling back')
gajim.log.debug('Error when trying to use notification daemon: %s' % \
str(e))
instance = dialogs.PopupNotificationWindow(self.event_type, self.jid,
self.account, self.msg_type, self.path_to_image, self.title,
self.text)
gajim.interface.roster.popup_notification_windows.append(instance)
def on_action_invoked(self, id_, reason):
if self.notif is None: