#1005 preparation : move popups and sound code for incomming new messages to notify.py
This commit is contained in:
parent
1a7fbe727f
commit
e96724224d
60
src/gajim.py
60
src/gajim.py
|
@ -511,63 +511,25 @@ class Interface:
|
|||
not gajim.contacts.get_contact(account, jid) and not pm:
|
||||
return
|
||||
|
||||
# Is it a first or next message received ?
|
||||
first = False
|
||||
if not chat_control and not gajim.awaiting_events[account].has_key(
|
||||
jid_of_control):
|
||||
# It's a first message and not a Private Message
|
||||
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:
|
||||
room_jid = jid
|
||||
nick = resource
|
||||
if first:
|
||||
if gajim.config.get('notify_on_new_message') and \
|
||||
helpers.allow_showing_notification(account):
|
||||
room_name, t = gajim.get_room_name_and_server_from_room_jid(
|
||||
room_jid)
|
||||
img = os.path.join(gajim.DATA_DIR, 'pixmaps', 'events',
|
||||
'priv_msg_recv.png')
|
||||
path = gtkgui_helpers.get_path_to_generic_or_avatar(img)
|
||||
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)
|
||||
nickname = resource
|
||||
msg_type = 'pm'
|
||||
groupchat_control.on_private_message(nickname, message, array[2])
|
||||
else:
|
||||
# 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)
|
||||
nickname = gajim.get_name_from_jid(account, jid)
|
||||
# Check and do wanted notifications
|
||||
notify.notify('new_message', jid, account, [msg_type, first, nickname, message])
|
||||
|
||||
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:
|
||||
self.remote_ctrl.raise_signal('NewMessage', (account, array))
|
||||
|
||||
|
|
|
@ -62,7 +62,23 @@ def notify(event, jid, account, parameters):
|
|||
if gajim.config.get_per('soundevents', 'contact_disconnected',
|
||||
'enabled'):
|
||||
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
|
||||
if (do_popup):
|
||||
if (event == 'contact_connected' or event == 'contact_disconnected' or \
|
||||
|
@ -112,10 +128,42 @@ def notify(event, jid, account, parameters):
|
|||
text = status_message
|
||||
popup(_('Contact Signed Out'), jid, account,
|
||||
path_to_image = path, title = title, text = text)
|
||||
else:
|
||||
print 'Event not implemeted yet'
|
||||
elif (event == 'new_message'):
|
||||
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):
|
||||
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,
|
||||
|
|
Loading…
Reference in New Issue