From 7d5602c4b1b3f7e3c385941b9dc67ee0986f5e1d Mon Sep 17 00:00:00 2001 From: Yann Leboulanger <asterix@lagaule.org> Date: Sun, 27 Jan 2008 20:15:17 +0000 Subject: [PATCH] add a new event to allow not playing sound when chat window is focused. fixes #2907 --- configure.ac | 2 +- src/common/config.py | 3 ++- src/common/defs.py | 2 +- src/common/optparser.py | 17 +++++++++++++++++ src/config.py | 5 ++++- src/gajim.py | 8 +++++++- src/notify.py | 14 +++++++++++--- 7 files changed, 43 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 4f313330c0..d06f128205 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_INIT([Gajim - A Jabber Instant Messager], - [0.11.4.1-svn],[http://trac.gajim.org/],[gajim]) + [0.11.4.2-svn],[http://trac.gajim.org/],[gajim]) AC_PREREQ([2.59]) AM_INIT_AUTOMAKE([1.8]) AC_CONFIG_HEADER(config.h) diff --git a/src/common/config.py b/src/common/config.py index 913b94b9eb..e7cedb5cf9 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -408,7 +408,8 @@ class Config: soundevents_default = { 'first_message_received': [ True, '../data/sounds/message1.wav' ], - 'next_message_received': [ True, '../data/sounds/message2.wav' ], + 'next_message_received_focused': [ True, '../data/sounds/message2.wav' ], + 'next_message_received_unfocused': [ True, '../data/sounds/message2.wav' ], 'contact_connected': [ True, '../data/sounds/connected.wav' ], 'contact_disconnected': [ True, '../data/sounds/disconnected.wav' ], 'message_sent': [ True, '../data/sounds/sent.wav' ], diff --git a/src/common/defs.py b/src/common/defs.py index b30457a31c..7cdfe01116 100644 --- a/src/common/defs.py +++ b/src/common/defs.py @@ -2,7 +2,7 @@ docdir = '../' datadir = '../' -version = '0.11.4.1-svn' +version = '0.11.4.2-svn' import sys, os.path for base in ('.', 'common'): diff --git a/src/common/optparser.py b/src/common/optparser.py index e50206420a..72b6fe6e72 100644 --- a/src/common/optparser.py +++ b/src/common/optparser.py @@ -176,6 +176,8 @@ class OptionsParser: self.update_config_to_01121() if old < [0, 11, 4, 1] and new >= [0, 11, 4, 1]: self.update_config_to_01141() + if old < [0, 11, 4, 2] and new >= [0, 11, 4, 2]: + self.update_config_to_01142() gajim.logger.init_vars() gajim.config.set('version', new_version) @@ -526,3 +528,18 @@ class OptionsParser: con.close() gajim.config.set('version', '0.11.4.1') + def update_config_to_01142(self): + '''next_message_received sound event is splittedin 2 events''' + gajim.config.add_per('soundevents', 'next_message_received_focused') + gajim.config.add_per('soundevents', 'next_message_received_unfocused') + if gajim.config.get_per('soundevents', 'next_message_received'): + enabled = gajim.config.get_per('soundevents', 'next_message_received', + 'enabled') + path = gajim.config.get_per('soundevents', 'next_message_received', + 'path') + gajim.config.del_per('soundevents', 'next_message_received') + gajim.config.set_per('soundevents', 'next_message_received_focused', + 'enabled', enabled) + gajim.config.set_per('soundevents', 'next_message_received_focused', + 'path', path) + gajim.config.set('version', '0.11.1.2') diff --git a/src/config.py b/src/config.py index b70ff264de..d766c61ae9 100644 --- a/src/config.py +++ b/src/config.py @@ -1089,12 +1089,15 @@ class PreferencesWindow: def fill_sound_treeview(self): model = self.sound_tree.get_model() model.clear() + model.set_sort_column_id(1, gtk.SORT_ASCENDING) # NOTE: sounds_ui_names MUST have all items of # sounds = gajim.config.get_per('soundevents') as keys sounds_dict = { 'first_message_received': _('First Message Received'), - 'next_message_received': _('Next Message Received'), + 'next_message_received_focused': _('Next Message Received Focused'), + 'next_message_received_unfocused': + _('Next Message Received Unfocused'), 'contact_connected': _('Contact Connected'), 'contact_disconnected': _('Contact Disconnected'), 'message_sent': _('Message Sent'), diff --git a/src/gajim.py b/src/gajim.py index dde618e658..1561a819ab 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -847,8 +847,14 @@ class Interface: msg = message if subject: msg = _('Subject: %s') % subject + '\n' + msg + focused = False + if chat_control: + parent_win = chat_control.parent_win + if chat_control == parent_win.get_active_control() and \ + parent_win.window.has_focus: + focused = True notify.notify('new_message', jid_of_control, account, [msg_type, - first, nickname, msg], advanced_notif_num) + first, nickname, msg, focused], advanced_notif_num) if self.remote_ctrl: self.remote_ctrl.raise_signal('NewMessage', (account, array)) diff --git a/src/notify.py b/src/notify.py index ab2f0d20b4..6106227c39 100644 --- a/src/notify.py +++ b/src/notify.py @@ -175,14 +175,20 @@ def notify(event, jid, account, parameters, advanced_notif_num = None): else: # We don't want message preview, do_preview = False message = '' + focused = parameters[4] if helpers.allow_showing_notification(account, 'notify_on_new_message', advanced_notif_num, is_first_message): do_popup = True if is_first_message and helpers.allow_sound_notification( 'first_message_received', advanced_notif_num): do_sound = True - elif not is_first_message and helpers.allow_sound_notification( - 'next_message_received', advanced_notif_num): + elif not is_first_message and focused and \ + helpers.allow_sound_notification('next_message_received_focused', + advanced_notif_num): + do_sound = True + elif not is_first_message and not focused and \ + helpers.allow_sound_notification('next_message_received_unfocused', + advanced_notif_num): do_sound = True else: print '*Event not implemeted yet*' @@ -285,8 +291,10 @@ def notify(event, jid, account, parameters, advanced_notif_num = None): pass # do not set snd_event elif is_first_message: snd_event = 'first_message_received' + elif focused: + snd_event = 'next_message_received_focused' else: - snd_event = 'next_message_received' + snd_event = 'next_message_received_unfocused' elif event in ('contact_connected', 'contact_disconnected'): snd_event = event if snd_file: -- GitLab