From 2cdca091fcd757ec4cc5aaae70758957badec6f7 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sun, 14 Mar 2010 00:12:18 +0100 Subject: [PATCH] don't fail when notification-daemon doesn't follow specifications. Fixes #5638 --- src/notify.py | 66 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/src/notify.py b/src/notify.py index efc71590f..bbd74463a 100644 --- a/src/notify.py +++ b/src/notify.py @@ -553,7 +553,8 @@ class DesktopNotification: '%(title)s
%(text)s') % {'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: