[James Westby] Don't use actions in notifications if the server doesn't support them. Fixes #4862

This commit is contained in:
Yann Leboulanger 2009-03-13 21:51:49 +00:00
parent dccf065418
commit 4b3206f043
1 changed files with 17 additions and 7 deletions

View File

@ -372,8 +372,9 @@ def popup(event_type, jid, account, msg_type='', path_to_image=None,
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 @@ class DesktopNotification:
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 @@ class DesktopNotification:
'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 @@ class DesktopNotification:
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 @@ class DesktopNotification:
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 @@ class DesktopNotification:
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 @@ class DesktopNotification:
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,