[knuckles] refactor API about notifications so we do not dup code allover

This commit is contained in:
Nikos Kouremenos 2006-01-20 17:40:45 +00:00
parent 818d2471fc
commit bbc42cc115
4 changed files with 137 additions and 188 deletions

View File

@ -269,6 +269,23 @@ def get_first_event(account, jid, typ = None):
if ev[0] == typ: if ev[0] == typ:
return ev return ev
return None return None
def get_notification_image_prefix(jid):
'''returns the prefix for the notification images'''
transport_name = get_transport_name_from_jid(jid)
if transport_name in ('aim', 'icq', 'msn', 'yahoo'):
prefix = transport_name
else:
prefix = 'jabber'
return prefix
def get_actor(account, jid):
contact = contacts.get_first_contact_from_jid(account, jid)
if contact:
actor = contact.get_shown_name()
else:
actor = jid
return actor
def popup_window(account): def popup_window(account):
autopopup = config.get('autopopup') autopopup = config.get('autopopup')

View File

@ -867,11 +867,10 @@ _('Without a connection, you can not change your password.')).get_response()
class PopupNotificationWindow: class PopupNotificationWindow:
def __init__(self, event_type, jid, account, msg_type = '', file_props = None, gmail_new_messages = None): def __init__(self, event_type, jid, account, msg_type = '', path_to_image = None, text = None):
self.account = account self.account = account
self.jid = jid self.jid = jid
self.msg_type = msg_type self.msg_type = msg_type
self.file_props = file_props
xml = gtk.glade.XML(GTKGUI_GLADE, 'popup_notification_window', APP) xml = gtk.glade.XML(GTKGUI_GLADE, 'popup_notification_window', APP)
self.window = xml.get_widget('popup_notification_window') self.window = xml.get_widget('popup_notification_window')
@ -884,121 +883,64 @@ class PopupNotificationWindow:
event_type_label.set_markup( event_type_label.set_markup(
'<span foreground="black" weight="bold">%s</span>' % event_type) '<span foreground="black" weight="bold">%s</span>' % event_type)
if self.jid in gajim.contacts.get_jid_list(account): if not text:
txt = gajim.contacts.get_first_contact_from_jid(account, text = gajim.get_actor(account, jid) # default value of text
self.jid).get_shown_name()
else:
txt = self.jid
# 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'))
# prefix for images
transport_name = gajim.get_transport_name_from_jid(jid)
if transport_name in ('aim', 'icq', 'msn', 'yahoo'):
prefix = transport_name
else:
prefix = 'jabber'
# default image # default image
img = 'chat_msg_recv.png' 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
if event_type == _('Contact Signed In'): if event_type == _('Contact Signed In'):
limegreen = gtk.gdk.color_parse('limegreen') limegreen = gtk.gdk.color_parse('limegreen')
close_button.modify_bg(gtk.STATE_NORMAL, limegreen) close_button.modify_bg(gtk.STATE_NORMAL, limegreen)
eventbox.modify_bg(gtk.STATE_NORMAL, limegreen) eventbox.modify_bg(gtk.STATE_NORMAL, limegreen)
event_description_label.set_markup( event_description_label.set_markup(
'<span foreground="black">%s</span>' % txt) '<span foreground="black">%s</span>' % text)
path_to_file = os.path.join(gajim.AVATAR_PATH, jid) + '_notif_size_colored.png'
if not os.path.exists(path_to_file):
img = prefix + '_online.png'
else:
img = path_to_file
elif event_type == _('Contact Signed Out'): elif event_type == _('Contact Signed Out'):
red = gtk.gdk.color_parse('red') red = gtk.gdk.color_parse('red')
close_button.modify_bg(gtk.STATE_NORMAL, red) close_button.modify_bg(gtk.STATE_NORMAL, red)
eventbox.modify_bg(gtk.STATE_NORMAL, red) eventbox.modify_bg(gtk.STATE_NORMAL, red)
event_description_label.set_markup( event_description_label.set_markup(
'<span foreground="black">%s</span>' % txt) '<span foreground="black">%s</span>' % text)
path_to_file = os.path.join(gajim.AVATAR_PATH, jid) + '_notif_size_bw.png'
if not os.path.exists(path_to_file):
img = prefix + '_offline.png'
else:
img = path_to_file
elif event_type in (_('New Message'), _('New Single Message'), elif event_type in (_('New Message'), _('New Single Message'),
_('New Private Message')): _('New Private Message')):
dodgerblue = gtk.gdk.color_parse('dodgerblue') dodgerblue = gtk.gdk.color_parse('dodgerblue')
close_button.modify_bg(gtk.STATE_NORMAL, dodgerblue) close_button.modify_bg(gtk.STATE_NORMAL, dodgerblue)
eventbox.modify_bg(gtk.STATE_NORMAL, dodgerblue) eventbox.modify_bg(gtk.STATE_NORMAL, dodgerblue)
if event_type == _('New Private Message'): event_description_label.set_markup(
room_jid, nick = gajim.get_room_and_nick_from_fjid(jid) '<span foreground="black">%s</span>' % text)
room_name,t = gajim.get_room_name_and_server_from_room_jid(room_jid)
txt = _('From %s in room %s') % (nick, room_name)
img = 'priv_msg_recv.png'
else:
txt = _('From %s') % txt
if event_type == _('New Message'):
img = 'chat_msg_recv.png'
else: # New Single Message
img = 'single_msg_recv.png'
event_description_label.set_markup('<span foreground="black">%s</span>' % txt)
elif event_type == _('File Transfer Request'): elif event_type == _('File Transfer Request'):
bg_color = gtk.gdk.color_parse('khaki') bg_color = gtk.gdk.color_parse('khaki')
close_button.modify_bg(gtk.STATE_NORMAL, bg_color) close_button.modify_bg(gtk.STATE_NORMAL, bg_color)
eventbox.modify_bg(gtk.STATE_NORMAL, bg_color) eventbox.modify_bg(gtk.STATE_NORMAL, bg_color)
txt = _('From %s') % txt event_description_label.set_markup(
event_description_label.set_markup('<span foreground="black">%s</span>' % txt) '<span foreground="black">%s</span>' % text)
img = 'ft_request.png'
elif event_type == _('File Transfer Error'): elif event_type == _('File Transfer Error'):
bg_color = gtk.gdk.color_parse('firebrick') bg_color = gtk.gdk.color_parse('firebrick')
close_button.modify_bg(gtk.STATE_NORMAL, bg_color) close_button.modify_bg(gtk.STATE_NORMAL, bg_color)
eventbox.modify_bg(gtk.STATE_NORMAL, bg_color) eventbox.modify_bg(gtk.STATE_NORMAL, bg_color)
event_description_label.set_markup('<span foreground="black">%s</span>' % txt) event_description_label.set_markup(
img = 'ft_stopped.png' '<span foreground="black">%s</span>' % text)
elif event_type in (_('File Transfer Completed'), elif event_type in (_('File Transfer Completed'),
_('File Transfer Stopped')): _('File Transfer Stopped')):
bg_color = gtk.gdk.color_parse('yellowgreen') bg_color = gtk.gdk.color_parse('yellowgreen')
close_button.modify_bg(gtk.STATE_NORMAL, bg_color) close_button.modify_bg(gtk.STATE_NORMAL, bg_color)
eventbox.modify_bg(gtk.STATE_NORMAL, bg_color) eventbox.modify_bg(gtk.STATE_NORMAL, bg_color)
if file_props is not None: event_description_label.set_markup(
if file_props['type'] == 'r': '<span foreground="black">%s</span>' % text)
# get the name of the sender, as it is in the roster
sender = unicode(file_props['sender']).split('/')[0]
name = gajim.contacts.get_first_contact_from_jid(account,
sender).get_shown_name()
txt = _('From %s') % name
if event_type == _('File Transfer Completed'):
img = 'ft_done.png'
else: # ft stopped
img = 'ft_stopped.png'
else:
receiver = file_props['receiver']
if hasattr(receiver, 'jid'):
receiver = receiver.jid
receiver = receiver.split('/')[0]
# get the name of the contact, as it is in the roster
name = gajim.contacts.get_first_contact_from_jid(account,
receiver).get_shown_name()
txt = _('To %s') % name
if event_type == _('File Transfer Completed'):
img = 'ft_done.png'
else: # ft stopped
img = 'ft_stopped.png'
else:
txt = ''
event_description_label.set_markup('<span foreground="black">%s</span>' % txt)
elif event_type == _('New E-mail'): elif event_type == _('New E-mail'):
dodgerblue = gtk.gdk.color_parse('dodgerblue') dodgerblue = gtk.gdk.color_parse('dodgerblue')
close_button.modify_bg(gtk.STATE_NORMAL, dodgerblue) close_button.modify_bg(gtk.STATE_NORMAL, dodgerblue)
eventbox.modify_bg(gtk.STATE_NORMAL, dodgerblue) eventbox.modify_bg(gtk.STATE_NORMAL, dodgerblue)
text = i18n.ngettext('You have %d new E-mail message', 'You have %d new E-mail messages', gmail_new_messages, gmail_new_messages, gmail_new_messages) event_description_label.set_markup(
txt = _('%(new_mail_gajim_ui_msg)s on %(gmail_mail_address)s') % {'new_mail_gajim_ui_msg': text, 'gmail_mail_address': jid} '<span foreground="black">%s</span>' % text)
event_description_label.set_markup('<span foreground="black">%s</span>' % txt)
img = 'single_msg_recv.png' #FIXME: find a better image
# set the image # set the image
path = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', img) image.set_from_file(path_to_image)
path = os.path.abspath(path)
image.set_from_file(path)
# position the window to bottom-right of screen # position the window to bottom-right of screen
window_width, self.window_height = self.window.get_size() window_width, self.window_height = self.window.get_size()

View File

@ -360,8 +360,13 @@ class Interface:
# we're online or chat # we're online or chat
show_notification = True show_notification = True
if show_notification: if show_notification:
notify.notify(_('Contact Signed In'), jid, account, path_to_file = os.path.join(gajim.AVATAR_PATH, jid) + '_notif_size_colored.png'
path_to_image = None) if not os.path.exists(path_to_file):
img = gajim.get_notification_image_prefix(jid) + '_online.png'
else:
img = path_to_file
path = os.path.abspath(os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', img))
notify.notify(_('Contact Signed In'), jid, account, path_to_image = path)
if self.remote_ctrl: if self.remote_ctrl:
self.remote_ctrl.raise_signal('ContactPresence', self.remote_ctrl.raise_signal('ContactPresence',
@ -381,8 +386,14 @@ class Interface:
elif gajim.connections[account].connected in (2, 3): # we're online or chat elif gajim.connections[account].connected in (2, 3): # we're online or chat
show_notification = True show_notification = True
if show_notification: if show_notification:
notify.notify(_('Contact Signed Out'), jid, account, path_to_file = os.path.join(gajim.AVATAR_PATH, jid) + '_notif_size_bw.png'
path_to_image = None) if not os.path.exists(path_to_file):
img = gajim.get_notification_image_prefix(jid) + '_offline.png'
else:
img = path_to_file
path = os.path.abspath(os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', img))
notify.notify(_('Contact Signed Out'), jid, account, path_to_image = path)
if self.remote_ctrl: if self.remote_ctrl:
self.remote_ctrl.raise_signal('ContactAbsence', (account, array)) self.remote_ctrl.raise_signal('ContactAbsence', (account, array))
# FIXME: stop non active file transfers # FIXME: stop non active file transfers
@ -419,7 +430,13 @@ class Interface:
if not gajim.interface.msg_win_mgr.has_window(fjid) and \ if not gajim.interface.msg_win_mgr.has_window(fjid) and \
not gajim.awaiting_events[account].has_key(fjid): not gajim.awaiting_events[account].has_key(fjid):
if show_notification: if show_notification:
notify.notify(_('New Private Message'), fjid, account, 'pm') room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
room_name,t = gajim.get_room_name_and_server_from_room_jid(room_jid)
txt = _('%(nickname)s in room %(room_name)s has sent you a new message.')\
% {'nickname': nick, 'room_name': room_name}
img = 'priv_msg_recv.png'
path = os.path.abspath(os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', img))
notify.notify(_('New Private Message'), fjid, account, 'pm', path_to_image = path, text = txt)
chat_control.on_private_message(nick, array[1], array[2]) chat_control.on_private_message(nick, array[1], array[2])
return return
@ -461,10 +478,17 @@ class Interface:
elif gajim.connections[account].connected in (2, 3): # we're online or chat elif gajim.connections[account].connected in (2, 3): # we're online or chat
show_notification = True show_notification = True
if show_notification: if show_notification:
txt = _('%s has sent you a new message.') % gajim.get_actor(account, jid)
if msg_type == 'normal': # single message if msg_type == 'normal': # single message
notify.notify(_('New Single Message'), jid, account, msg_type) img = 'single_msg_recv.png'
path = os.path.abspath(os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', img))
notify.notify(_('New Single Message'), jid, account, msg_type,
path_to_image = path, text = txt)
else: # chat message else: # chat message
notify.notify(_('New Message'), jid, account, msg_type) img = 'chat_msg_recv.png'
path = os.path.abspath(os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', img))
notify.notify(_('New Message'), jid, account, msg_type,
path_to_image = path, text = txt)
# array : (contact, msg, time, encrypted, msg_type, subject) # array : (contact, msg, time, encrypted, msg_type, subject)
self.roster.on_message(jid, array[1], array[2], account, array[3], self.roster.on_message(jid, array[1], array[2], account, array[3],
@ -831,14 +855,20 @@ class Interface:
self.add_event(account, jid, 'file-send-error', file_props) self.add_event(account, jid, 'file-send-error', file_props)
if gajim.show_notification(account): if gajim.show_notification(account):
img = 'ft_stopped.png'
path = os.path.abspath(os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', img))
notify.notify(_('File Transfer Error'), notify.notify(_('File Transfer Error'),
jid, account, 'file-send-error', file_props) jid, account, 'file-send-error', file_props, path_to_image = path)
def handle_event_gmail_notify(self, account, array): def handle_event_gmail_notify(self, account, array):
jid = array[0] jid = array[0]
newmsgs = array[1] gmail_new_messages = int(array[1])
if gajim.config.get('notify_on_new_gmail_email'): if gajim.config.get('notify_on_new_gmail_email'):
notify.notify(_('New E-mail'), jid, account, 'gmail', gmail_new_messages = int(newmsgs)) img = 'single_msg_recv.png' #FIXME: find a better image
path = os.path.abspath(os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', img))
txt = i18n.ngettext('You have %d new E-mail message', 'You have %d new E-mail messages', gmail_new_messages, gmail_new_messages, gmail_new_messages)
txt = _('%(new_mail_gajim_ui_msg)s on %(gmail_mail_address)s') % {'new_mail_gajim_ui_msg': txt, 'gmail_mail_address': jid}
notify.notify(_('New E-mail'), jid, account, 'gmail', path_to_image = path, text = txt)
def save_avatar_files(self, jid, photo_decoded): def save_avatar_files(self, jid, photo_decoded):
'''Save the decoded avatar to a separate file, and generate files for dbus notifications''' '''Save the decoded avatar to a separate file, and generate files for dbus notifications'''
@ -933,8 +963,10 @@ class Interface:
self.add_event(account, jid, 'file-request', file_props) self.add_event(account, jid, 'file-request', file_props)
if gajim.show_notification(account): if gajim.show_notification(account):
notify.notify(_('File Transfer Request'), img = 'ft_request.png'
jid, account, 'file-request') path = os.path.abspath(os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', img))
txt = _('%s wants to send you a file.') % gajim.get_actor(account, jid)
notify.notify(_('File Transfer Request'), jid, account, 'file-request', path_to_image = path, text = txt)
def handle_event_file_progress(self, account, file_props): def handle_event_file_progress(self, account, file_props):
self.instances['file_transfers'].set_progress(file_props['type'], self.instances['file_transfers'].set_progress(file_props['type'],
@ -978,13 +1010,49 @@ class Interface:
if msg_type: if msg_type:
self.add_event(account, jid, msg_type, file_props) self.add_event(account, jid, msg_type, file_props)
if file_props is not None:
if file_props['type'] == 'r':
# get the name of the sender, as it is in the roster
sender = unicode(file_props['sender']).split('/')[0]
name = gajim.contacts.get_first_contact_from_jid(account,
sender).get_shown_name()
filename = os.path.basename(file_props['file-name'])
if event_type == _('File Transfer Completed'):
txt = _('You successfully received %(filename)s from %(name)s.')\
% {'filename': filename, 'name': name}
img = 'ft_done.png'
else: # ft stopped
txt = _('File transfer of %(filename)s from %(name)s stopped.')\
% {'filename': filename, 'name': name}
img = 'ft_stopped.png'
else:
receiver = file_props['receiver']
if hasattr(receiver, 'jid'):
receiver = receiver.jid
receiver = receiver.split('/')[0]
# get the name of the contact, as it is in the roster
name = gajim.contacts.get_first_contact_from_jid(account,
receiver).get_shown_name()
filename = os.path.basename(file_props['file-name'])
if event_type == _('File Transfer Completed'):
txt = _('You successfully sent %(filename)s to %(name)s.')\
% {'filename': filename, 'name': name}
img = 'ft_done.png'
else: # ft stopped
txt = _('File transfer of %(filename)s to %(name)s stopped.')\
% {'filename': filename, 'name': name}
img = 'ft_stopped.png'
path = os.path.abspath(os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', img))
else:
txt = ''
if gajim.config.get('notify_on_file_complete') and \ if gajim.config.get('notify_on_file_complete') and \
(gajim.config.get('autopopupaway') or \ (gajim.config.get('autopopupaway') or \
gajim.connections[account].connected in (2, 3)): gajim.connections[account].connected in (2, 3)):
# we want to be notified and we are online/chat or we don't mind # we want to be notified and we are online/chat or we don't mind
# bugged when away/na/busy # bugged when away/na/busy
notify.notify(event_type, jid, account, msg_type, file_props) notify.notify(event_type, jid, account, msg_type, path_to_image = path, text = txt)
def handle_event_stanza_arrived(self, account, stanza): def handle_event_stanza_arrived(self, account, stanza):
if not self.instances.has_key(account): if not self.instances.has_key(account):

View File

@ -47,15 +47,15 @@ if dbus_support.supported:
import dbus.glib import dbus.glib
import dbus.service import dbus.service
def notify(event_type, jid, account, msg_type = '', file_props = None, def notify(event_type, jid, account, msg_type = '', path_to_image = None,
path_to_image = None, gmail_new_messages = None): text = 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.'''
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, file_props, DesktopNotification(event_type, jid, account, msg_type, path_to_image,
path_to_image, gmail_new_messages) text)
return return
except dbus.dbus_bindings.DBusException, e: except dbus.dbus_bindings.DBusException, e:
# Connection to D-Bus failed, try popup # Connection to D-Bus failed, try popup
@ -63,8 +63,7 @@ def notify(event_type, jid, account, msg_type = '', file_props = 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))
instance = dialogs.PopupNotificationWindow(event_type, jid, account, instance = dialogs.PopupNotificationWindow(event_type, jid, account, msg_type, path_to_image, text)
msg_type, file_props, gmail_new_messages)
gajim.interface.roster.popup_notification_windows.append(instance) gajim.interface.roster.popup_notification_windows.append(instance)
class NotificationResponseManager: class NotificationResponseManager:
@ -102,112 +101,35 @@ class DesktopNotification:
'''A DesktopNotification that interfaces with DBus via the Desktop '''A DesktopNotification that interfaces with DBus via the Desktop
Notification specification''' Notification specification'''
def __init__(self, event_type, jid, account, msg_type = '', def __init__(self, event_type, jid, account, msg_type = '',
file_props = None, path_to_image = None, gmail_new_messages = None): path_to_image = None, text = None):
self.account = account self.account = account
self.jid = jid self.jid = jid
self.msg_type = msg_type self.msg_type = msg_type
self.file_props = file_props
contact = gajim.contacts.get_first_contact_from_jid(account, jid)
if contact:
actor = contact.get_shown_name()
else:
actor = jid
txt = actor # default value of txt
transport_name = gajim.get_transport_name_from_jid(jid)
if transport_name in ('aim', 'icq', 'msn', 'yahoo'):
prefix = transport_name
else:
prefix = 'jabber'
if not text:
text = gajim.get_actor(account, jid) # default value of text
if event_type == _('Contact Signed In'): if event_type == _('Contact Signed In'):
path_to_file = os.path.join(gajim.AVATAR_PATH, jid) + '_notif_size_colored.png'
if not os.path.exists(path_to_file):
img = prefix + '_online.png'
else:
img = path_to_file
ntype = 'presence.online' ntype = 'presence.online'
elif event_type == _('Contact Signed Out'): elif event_type == _('Contact Signed Out'):
path_to_file = os.path.join(gajim.AVATAR_PATH, jid) + '_notif_size_bw.png'
if not os.path.exists(path_to_file):
img = prefix + '_offline.png'
else:
img = path_to_file
ntype = 'presence.offline' ntype = 'presence.offline'
elif event_type in (_('New Message'), _('New Single Message'), elif event_type in (_('New Message'), _('New Single Message'),
_('New Private Message')): _('New Private Message')):
ntype = 'im.received' ntype = 'im.received'
if event_type == _('New Private Message'):
room_jid, nick = gajim.get_room_and_nick_from_fjid(jid)
room_name,t = gajim.get_room_name_and_server_from_room_jid(room_jid)
txt = _('%(nickname)s in room %(room_name)s has sent you a new message.')\
% {'nickname': nick, 'room_name': room_name}
img = 'priv_msg_recv.png'
else:
#we talk about a name here
txt = _('%s has sent you a new message.') % actor
if event_type == _('New Message'):
img = 'chat_msg_recv.png'
else: # New Single Message
img = 'single_msg_recv.png'
elif event_type == _('File Transfer Request'): elif event_type == _('File Transfer Request'):
img = 'ft_request.png'
ntype = 'transfer' ntype = 'transfer'
#we talk about a name here
txt = _('%s wants to send you a file.') % actor
elif event_type == _('File Transfer Error'): elif event_type == _('File Transfer Error'):
img = 'ft_stopped.png'
ntype = 'transfer.error' ntype = 'transfer.error'
elif event_type in (_('File Transfer Completed'), _('File Transfer Stopped')): elif event_type in (_('File Transfer Completed'), _('File Transfer Stopped')):
ntype = 'transfer.complete' ntype = 'transfer.complete'
if file_props is not None:
if file_props['type'] == 'r':
# get the name of the sender, as it is in the roster
sender = unicode(file_props['sender']).split('/')[0]
name = gajim.contacts.get_first_contact_from_jid(account,
sender).get_shown_name()
filename = os.path.basename(file_props['file-name'])
if event_type == _('File Transfer Completed'):
txt = _('You successfully received %(filename)s from %(name)s.')\
% {'filename': filename, 'name': name}
img = 'ft_done.png'
else: # ft stopped
txt = _('File transfer of %(filename)s from %(name)s stopped.')\
% {'filename': filename, 'name': name}
img = 'ft_stopped.png'
else:
receiver = file_props['receiver']
if hasattr(receiver, 'jid'):
receiver = receiver.jid
receiver = receiver.split('/')[0]
# get the name of the contact, as it is in the roster
name = gajim.contacts.get_first_contact_from_jid(account,
receiver).get_shown_name()
filename = os.path.basename(file_props['file-name'])
if event_type == _('File Transfer Completed'):
txt = _('You successfully sent %(filename)s to %(name)s.')\
% {'filename': filename, 'name': name}
img = 'ft_done.png'
else: # ft stopped
txt = _('File transfer of %(filename)s to %(name)s stopped.')\
% {'filename': filename, 'name': name}
img = 'ft_stopped.png'
else:
txt = ''
elif event_type == _('New E-mail'): elif event_type == _('New E-mail'):
text = i18n.ngettext('You have %d new E-mail message', 'You have %d new E-mail messages', gmail_new_messages, gmail_new_messages, gmail_new_messages)
txt = _('%(new_mail_gajim_ui_msg)s on %(gmail_mail_address)s') % {'new_mail_gajim_ui_msg': text, 'gmail_mail_address': jid}
ntype = 'gmail.notify' ntype = 'gmail.notify'
img = 'single_msg_recv.png' #FIXME: find a better image
else: else:
# defaul failsafe values # default failsafe values
img = 'chat_msg_recv.png' # img to display path_to_image = os.path.abspath(
ntype = 'im' # Notification Type os.path.join(gajim.DATA_DIR, 'pixmaps', 'events',
'chat_msg_recv.png')) # img to display
path = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', img) ntype = 'im' # Notification Type
path = os.path.abspath(path)
self.notif = dbus_support.get_notifications_interface() self.notif = dbus_support.get_notifications_interface()
if self.notif is None: if self.notif is None:
@ -225,16 +147,16 @@ class DesktopNotification:
if version.startswith('0.2'): if version.startswith('0.2'):
try: try:
self.id = self.notif.Notify(dbus.String(_('Gajim')), self.id = self.notif.Notify(dbus.String(_('Gajim')),
dbus.String(path), dbus.UInt32(0), ntype, dbus.Byte(0), dbus.String(path_to_image), dbus.UInt32(0), ntype, dbus.Byte(0),
dbus.String(event_type), dbus.String(txt), dbus.String(event_type), dbus.String(text),
[dbus.String(path)], {'default': 0}, [''], True, dbus.UInt32( [dbus.String(path_to_image)], {'default': 0}, [''], True,
timeout)) dbus.UInt32(timeout))
except AttributeError: except AttributeError:
version = '0.3.1' # we're actually dealing with the newer version version = '0.3.1' # we're actually dealing with the newer version
if version.startswith('0.3'): if version.startswith('0.3'):
self.id = self.notif.Notify(dbus.String(_('Gajim')), self.id = self.notif.Notify(dbus.String(_('Gajim')),
dbus.String(path), dbus.UInt32(0), dbus.String(event_type), dbus.String(path_to_image), dbus.UInt32(0), dbus.String(event_type),
dbus.String(txt), dbus.String(''), {}, dbus.UInt32(timeout*1000)) dbus.String(text), dbus.String(''), {}, dbus.UInt32(timeout*1000))
notification_response_manager.attach_to_interface() notification_response_manager.attach_to_interface()
notification_response_manager.pending[self.id] = self notification_response_manager.pending[self.id] = self