#1005 preparation : move popups and sound code for incomming new messages to notify.py

This commit is contained in:
Jean-Marie Traissard 2006-05-22 20:14:54 +00:00
parent 1a7fbe727f
commit e96724224d
2 changed files with 63 additions and 53 deletions

View File

@ -511,63 +511,25 @@ class Interface:
not gajim.contacts.get_contact(account, jid) and not pm: not gajim.contacts.get_contact(account, jid) and not pm:
return return
# Is it a first or next message received ?
first = False first = False
if not chat_control and not gajim.awaiting_events[account].has_key( if not chat_control and not gajim.awaiting_events[account].has_key(
jid_of_control): jid_of_control):
# It's a first message and not a Private Message # It's a first message and not a Private Message
first = True first = True
if gajim.config.get_per('soundevents', 'first_message_received',
'enabled') and first:
helpers.play_sound('first_message_received')
elif gajim.config.get_per('soundevents', 'next_message_received',
'enabled'):
helpers.play_sound('next_message_received')
if pm: if pm:
room_jid = jid nickname = resource
nick = resource msg_type = 'pm'
if first: groupchat_control.on_private_message(nickname, message, array[2])
if gajim.config.get('notify_on_new_message') and \ else:
helpers.allow_showing_notification(account): # array: (jid, msg, time, encrypted, msg_type, subject)
room_name, t = gajim.get_room_name_and_server_from_room_jid( self.roster.on_message(jid, message, array[2], account, array[3],
room_jid) msg_type, array[5], resource, msg_id)
img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events', nickname = gajim.get_name_from_jid(account, jid)
'priv_msg_recv.png') # Check and do wanted notifications
path = gtkgui_helpers.get_path_to_generic_or_avatar(img) notify.notify('new_message', jid, account, [msg_type, first, nickname, message])
title = _('New Private Message from room %s') % room_name
text = _('%(nickname)s: %(message)s') % {'nickname': nick,
'message': message}
notify.popup(_('New Private Message'), full_jid_with_resource,
account, 'pm', path_to_image = path, title = title,
text = text)
groupchat_control.on_private_message(nick, message, array[2])
return
if first:
if gajim.config.get('notify_on_new_message') and \
helpers.allow_showing_notification(account):
text = message
if msg_type == 'normal': # single message
event_type = _('New Single Message')
img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events',
'single_msg_recv.png')
title = _('New Single Message from %(nickname)s') % \
{'nickname': gajim.get_name_from_jid(account, jid)}
else: # chat message
event_type = _('New Message')
img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events',
'chat_msg_recv.png')
title = _('New Message from %(nickname)s') % \
{'nickname': gajim.get_name_from_jid(account, jid)}
path = gtkgui_helpers.get_path_to_generic_or_avatar(img)
notify.popup(event_type, jid_of_control, account, msg_type,
path_to_image = path, title = title, text = text)
# array: (jid, msg, time, encrypted, msg_type, subject)
self.roster.on_message(jid, message, array[2], account, array[3],
msg_type, array[5], resource, msg_id)
if self.remote_ctrl: if self.remote_ctrl:
self.remote_ctrl.raise_signal('NewMessage', (account, array)) self.remote_ctrl.raise_signal('NewMessage', (account, array))

View File

@ -62,7 +62,23 @@ def notify(event, jid, account, parameters):
if gajim.config.get_per('soundevents', 'contact_disconnected', if gajim.config.get_per('soundevents', 'contact_disconnected',
'enabled'): 'enabled'):
do_sound = True do_sound = True
elif (event == 'new_message'):
message_type = parameters[0]
first = parameters[1]
nickname = parameters[2]
message = parameters[3]
if gajim.config.get('notify_on_new_message') and \
helpers.allow_showing_notification(account) and first:
do_popup = True
if first and gajim.config.get_per('soundevents', 'first_message_received',
'enabled'):
do_sound = True
elif not first and gajim.config.get_per('soundevents', 'next_message_received',
'enabled'):
do_sound = True
else:
print '*Event not implemeted yet*'
# Do the wanted notifications # Do the wanted notifications
if (do_popup): if (do_popup):
if (event == 'contact_connected' or event == 'contact_disconnected' or \ if (event == 'contact_connected' or event == 'contact_disconnected' or \
@ -112,10 +128,42 @@ def notify(event, jid, account, parameters):
text = status_message text = status_message
popup(_('Contact Signed Out'), jid, account, popup(_('Contact Signed Out'), jid, account,
path_to_image = path, title = title, text = text) path_to_image = path, title = title, text = text)
else: elif (event == 'new_message'):
print 'Event not implemeted yet' if message_type == 'normal': # single message
event_type = _('New Single Message')
img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events',
'single_msg_recv.png')
title = _('New Single Message from %(nickname)s') % \
{'nickname': nickname}
text = message
elif message_type == 'pm': # private message
event_type = _('New Private Message')
room_name, t = gajim.get_room_name_and_server_from_room_jid(
jid)
img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events',
'priv_msg_recv.png')
title = _('New Private Message from room %s') % room_name
text = _('%(nickname)s: %(message)s') % {'nickname': nickname,
'message': message}
else: # chat message
event_type = _('New Message')
img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events',
'chat_msg_recv.png')
title = _('New Message from %(nickname)s') % \
{'nickname': nickname}
text = message
path = gtkgui_helpers.get_path_to_generic_or_avatar(img)
popup(event_type, jid, account, message_type,
path_to_image = path, title = title, text = text)
if (do_sound): if (do_sound):
helpers.play_sound(event) if (event == 'new_message'):
if first:
helpers.play_sound('first_message_received')
else:
helpers.play_sound('next_message_received')
elif (event == 'contact_connected' or event == 'contact_disconnected'):
helpers.play_sound(event)
def popup(event_type, jid, account, msg_type = '', path_to_image = None, def popup(event_type, jid, account, msg_type = '', path_to_image = None,