Author: asterix Date: 2009-03-13 22:51:49 +0100 (Fri, 13 Mar 2009) New Revision: 11163
Modified: trunk/src/notify.py Log: [James Westby] Don't use actions in notifications if the server doesn't support them. Fixes #4862
Modified: trunk/src/notify.py =================================================================== --- trunk/src/notify.py 2009-03-13 09:53:50 UTC (rev 11162) +++ trunk/src/notify.py 2009-03-13 21:51:49 UTC (rev 11163) @@ -372,8 +372,9 @@ notification.set_data('account', account) notification.set_data('msg_type', msg_type) notification.set_property('icon-name', path_to_image) - notification.add_action('default', 'Default Action', - on_pynotify_notification_clicked) + if 'actions' in pynotify.get_server_caps(): + notification.add_action('default', 'Default Action', + on_pynotify_notification_clicked)
try: notification.show() @@ -507,6 +508,7 @@ if self.notif is None: raise dbus.DBusException('unable to get notifications interface') self.ntype = ntype + self.capabilities = self.notif.GetCapabilities()
if self.kde_notifications: self.attempt_notify() @@ -522,6 +524,10 @@ 'text': self.text, 'image': self.path_to_image} gajim_icon = os.path.abspath(os.path.join(gajim.DATA_DIR, 'pixmaps', 'gajim.png')) + actions = () + if 'actions' in self.capabilities: + actions = (dbus.String('default'), dbus.String(self.event_type), + dbus.String('ignore'), dbus.String(_('Ignore'))) self.notif.Notify( dbus.String(_('Gajim')), # app_name (string) dbus.UInt32(0), # replaces_id (uint) @@ -529,9 +535,7 @@ 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'))), + actions, # actions (stringlist) [], # hints (not used in KDE yet) dbus.UInt32(timeout*1000), # timeout (int), in ms reply_handler=self.attach_by_id, @@ -539,6 +543,9 @@ return version = self.version if version[:2] == [0, 2]: + actions = {} + if 'actions' in self.capabilities: + actions = {'default': 0} try: self.notif.Notify( dbus.String(_('Gajim')), @@ -549,7 +556,7 @@ dbus.String(self.title), dbus.String(self.text), [dbus.String(self.path_to_image)], - {'default': 0}, + actions, [''], True, dbus.UInt32(timeout), @@ -576,13 +583,16 @@ text = self.text else: text = ' ' + actions = () + 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), - ( dbus.String('default'), dbus.String(self.event_type) ), + actions, hints, dbus.UInt32(timeout*1000), reply_handler=self.attach_by_id,