This commit is contained in:
js 2008-11-29 13:37:06 +00:00
parent d310ce1dde
commit 5a5937d96d
2 changed files with 36 additions and 25 deletions

View File

@ -2038,10 +2038,11 @@ class PopupNotificationWindow:
if not text: if not text:
text = gajim.get_name_from_jid(account, jid) # default value of text text = gajim.get_name_from_jid(account, jid) # default value of text
if not title: if not title:
title = event_type title = ''
event_type_label.set_markup( event_type_label.set_markup(
'<span foreground="black" weight="bold">%s</span>' % title) '<span foreground="black" weight="bold">%s</span>' %
gobject.markup_escape_text(title))
# set colors [ http://www.pitt.edu/~nisg/cis/web/cgi/rgb.html ] # set colors [ http://www.pitt.edu/~nisg/cis/web/cgi/rgb.html ]
self.window.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('black')) self.window.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('black'))
@ -2075,8 +2076,8 @@ class PopupNotificationWindow:
popup_bg_color = gtk.gdk.color_parse(bg_color) popup_bg_color = gtk.gdk.color_parse(bg_color)
close_button.modify_bg(gtk.STATE_NORMAL, popup_bg_color) close_button.modify_bg(gtk.STATE_NORMAL, popup_bg_color)
eventbox.modify_bg(gtk.STATE_NORMAL, popup_bg_color) eventbox.modify_bg(gtk.STATE_NORMAL, popup_bg_color)
event_description_label.set_markup( event_description_label.set_markup('<span foreground="black">%s</span>' %
'<span foreground="black">%s</span>' % text) gobject.markup_escape_text(text))
# set the image # set the image
image.set_from_file(path_to_image) image.set_from_file(path_to_image)

View File

@ -320,13 +320,26 @@ def popup(event_type, jid, account, msg_type='', path_to_image=None,
'''Notifies a user of an event. It first tries to a valid implementation of '''Notifies a user of an event. It first tries to a valid implementation of
the Desktop Notification Specification. If that fails, then we fall back to the Desktop Notification Specification. If that fails, then we fall back to
the older style PopupNotificationWindow method.''' the older style PopupNotificationWindow method.'''
# escape text like <3
text = gobject.markup_escape_text(text) # default image
title = gobject.markup_escape_text(title) if not path_to_image:
path_to_image = os.path.abspath(
os.path.join(gajim.DATA_DIR, 'pixmaps', 'events',
'chat_msg_recv.png')) # img to display
# Try Growl first, as we might have D-Bus and notification daemon running
# on OS X for some reason.
if USER_HAS_GROWL:
osx.growler.notify(event_type, jid, account, msg_type, path_to_image,
title, text)
return
# Try to show our popup via D-Bus and notification daemon
if gajim.config.get('use_notif_daemon') and dbus_support.supported: if gajim.config.get('use_notif_daemon') and dbus_support.supported:
try: try:
DesktopNotification(event_type, jid, account, msg_type, DesktopNotification(event_type, jid, account, msg_type,
path_to_image, title, text) path_to_image, gobject.markup_escape_text(title),
gobject.markup_escape_text(text))
return # sucessfully did D-Bus Notification procedure! return # sucessfully did D-Bus Notification procedure!
except dbus.DBusException, e: except dbus.DBusException, e:
# Connection to D-Bus failed # Connection to D-Bus failed
@ -334,21 +347,23 @@ def popup(event_type, jid, account, msg_type='', path_to_image=None,
except TypeError, e: except TypeError, e:
# This means that we sent the message incorrectly # This means that we sent the message incorrectly
gajim.log.debug(str(e)) gajim.log.debug(str(e))
# we failed to speak to notification daemon via D-Bus
if USER_HAS_PYNOTIFY: # try via libnotify # Ok, that failed. Let's try pynotify, which also uses notification daemon
if gajim.config.get('use_notif_daemon') and USER_HAS_PYNOTIFY:
if not text and event_type == 'new_message': if not text and event_type == 'new_message':
# empty text for new_message means do_preview = False # empty text for new_message means do_preview = False
text = gajim.get_name_from_jid(account, jid) # default value of text # -> default value for text
_text = gobject.markup_escape_text(
gajim.get_name_from_jid(account, jid))
else:
_text = gobject.markup_escape_text(text)
if not title: if not title:
title = event_type _title = ''
# default image else:
if not path_to_image: _title = gobject.markup_escape_text(title)
path_to_image = os.path.abspath(
os.path.join(gajim.DATA_DIR, 'pixmaps', 'events',
'chat_msg_recv.png')) # img to display
notification = pynotify.Notification(_title, _text)
notification = pynotify.Notification(title, text)
timeout = gajim.config.get('notification_timeout') * 1000 # make it ms timeout = gajim.config.get('notification_timeout') * 1000 # make it ms
notification.set_timeout(timeout) notification.set_timeout(timeout)
@ -367,13 +382,8 @@ def popup(event_type, jid, account, msg_type='', path_to_image=None,
except gobject.GError, e: except gobject.GError, e:
# Connection to notification-daemon failed, see #2893 # Connection to notification-daemon failed, see #2893
gajim.log.debug(str(e)) gajim.log.debug(str(e))
# try os/x growl
if USER_HAS_GROWL:
osx.growler.notify(event_type, jid, account, msg_type, path_to_image,
title, text)
return
# go old style # Either nothing succeeded or the user wants old-style notifications
instance = dialogs.PopupNotificationWindow(event_type, jid, account, instance = dialogs.PopupNotificationWindow(event_type, jid, account,
msg_type, path_to_image, title, text) msg_type, path_to_image, title, text)
gajim.interface.roster.popup_notification_windows.append(instance) gajim.interface.roster.popup_notification_windows.append(instance)