From e96724224d22a4b9145804e00dca37078ba14ef3 Mon Sep 17 00:00:00 2001 From: Jean-Marie Traissard Date: Mon, 22 May 2006 20:14:54 +0000 Subject: [PATCH] #1005 preparation : move popups and sound code for incomming new messages to notify.py --- src/gajim.py | 60 ++++++++++----------------------------------------- src/notify.py | 56 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 53 deletions(-) diff --git a/src/gajim.py b/src/gajim.py index 4e4827776..ff68d6a2c 100755 --- a/src/gajim.py +++ b/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)) diff --git a/src/notify.py b/src/notify.py index 99de2d5bb..201392899 100644 --- a/src/notify.py +++ b/src/notify.py @@ -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,