From 5e6f9d011839d7d79c9284772ab6a8272b241f21 Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Sun, 26 Nov 2006 09:06:47 +0000
Subject: [PATCH] add an option to define the chatstate we want to show in char
 window. fixes #2706

---
 src/chat_control.py     | 12 +++++---
 src/common/config.py    |  3 +-
 src/common/defs.py      |  2 +-
 src/common/optparser.py | 11 +++++++-
 src/config.py           | 61 +++++++++++++++++++++++++++--------------
 5 files changed, 61 insertions(+), 28 deletions(-)

diff --git a/src/chat_control.py b/src/chat_control.py
index 274d5b72df..5de4dcc34f 100644
--- a/src/chat_control.py
+++ b/src/chat_control.py
@@ -1049,13 +1049,16 @@ def draw_banner(self, chatstate = None):
 		status_escaped = gtkgui_helpers.escape_for_pango_markup(status)
 
 		font_attrs, font_attrs_small = self.get_font_attrs()
-		st = gajim.config.get('chat_state_notifications')
+		st = gajim.config.get('displayed_chat_state_notifications')
 		cs = contact.chatstate
 		if cs and st in ('composing_only', 'all'):
 			if contact.show == 'offline':
 				chatstate = ''
 			elif contact.composing_jep == 'JEP-0085':
-				chatstate = helpers.get_uf_chatstate(cs)
+				if st == 'all' or cs == 'composing':
+					chatstate = helpers.get_uf_chatstate(cs)
+				else:
+					chatstate = ''
 			elif contact.composing_jep == 'JEP-0022':
 				if cs in ('composing', 'paused'):
 					# only print composing, paused
@@ -1128,7 +1131,8 @@ def send_message(self, message, keyID = '', chatstate = None):
 			encrypted = True
 
 
-		chatstates_on = gajim.config.get('chat_state_notifications') != 'disabled'
+		chatstates_on = gajim.config.get('outgoing_chat_state_notifications') != \
+			'disabled'
 		chatstate_to_send = None
 		if chatstates_on and contact is not None:
 			if contact.composing_jep is None:
@@ -1424,7 +1428,7 @@ def send_chatstate(self, state, contact = None):
 		# do not send nothing if we have chat state notifications disabled
 		# that means we won't reply to the <active/> from other peer
 		# so we do not broadcast jep85 capabalities
-		chatstate_setting = gajim.config.get('chat_state_notifications')
+		chatstate_setting = gajim.config.get('outgoing_chat_state_notifications')
 		if chatstate_setting == 'disabled':
 			return
 		elif chatstate_setting == 'composing_only' and state != 'active' and\
diff --git a/src/common/config.py b/src/common/config.py
index 7f05f5264a..412024df50 100644
--- a/src/common/config.py
+++ b/src/common/config.py
@@ -152,7 +152,8 @@ class Config:
 		'always_english_wiktionary': [opt_bool, True],
 		'remote_control': [opt_bool, True, _('If checked, Gajim can be controlled remotely using gajim-remote.'), True],
 		'networkmanager_support': [opt_bool, True, _('If True, listen to D-Bus signals from NetworkManager and change the status of accounts (provided they do not have listen_to_network_manager set to False and they sync with global status) based upon the status of the network connection.'), True],
-		'chat_state_notifications': [opt_str, 'all'], # 'all', 'composing_only', 'disabled'
+		'outgoing_chat_state_notifications': [opt_str, 'all', _('Sent chat state notifications. Can be one of all, composing_only, disabled.')],
+		'displayed_chat_state_notifications': [opt_str, 'all', _('Displayed chat state notifications in chat windows. Can be one of all, composing_only, disabled.')],
 		'autodetect_browser_mailer': [opt_bool, False, '', True],
 		'print_ichat_every_foo_minutes': [opt_int, 5, _('When not printing time for every message (print_time==sometimes), print it every x minutes.')],
 		'confirm_close_muc': [opt_bool, True, _('Ask before closing a group chat tab/window.')],
diff --git a/src/common/defs.py b/src/common/defs.py
index 82d11b301f..fab2b18363 100644
--- a/src/common/defs.py
+++ b/src/common/defs.py
@@ -2,7 +2,7 @@
 
 datadir = '../'
 
-version = '0.10.1.7'
+version = '0.10.1.8'
 
 import sys, os.path
 for base in ('.', 'common'):
diff --git a/src/common/optparser.py b/src/common/optparser.py
index c64446f904..53146de05c 100644
--- a/src/common/optparser.py
+++ b/src/common/optparser.py
@@ -153,6 +153,8 @@ def update_config(self, old_version, new_version):
 			self.update_config_to_01016()
 		if old < [0, 10, 1, 7] and new >= [0, 10, 1, 7]:
 			self.update_config_to_01017()
+		if old < [0, 10, 1, 8] and new >= [0, 10, 1, 8]:
+			self.update_config_to_01018()
 
 		gajim.logger.init_vars()
 		gajim.config.set('version', new_version)
@@ -345,5 +347,12 @@ def update_config_to_01017(self):
 		trayicon_notification_on_events '''
 		if self.old_values.has_key('trayicon_notification_on_new_messages'):
 			gajim.config.set('trayicon_notification_on_events',
-				 self.old_values['trayicon_notification_on_new_messages']) 
+				 self.old_values['trayicon_notification_on_new_messages'])
 		gajim.config.set('version', '0.10.1.7')
+
+	def update_config_to_01018(self):
+		'''chat_state_notifications -> outgoing_chat_state_notifications'''
+		if self.old_values.has_key('chat_state_notifications'):
+			gajim.config.set('outgoing_chat_state_notifications',
+				 self.old_values['chat_state_notifications'])
+		gajim.config.set('version', '0.10.1.8')
diff --git a/src/config.py b/src/config.py
index 557efbed91..67ef76e6d5 100644
--- a/src/config.py
+++ b/src/config.py
@@ -224,47 +224,47 @@ def __init__(self):
 		else:
 			self.xml.get_widget('time_always_radiobutton').set_active(True)
 
-		#before time
+		# before time
 		st = gajim.config.get('before_time')
 		st = helpers.from_one_line(st)
 		self.xml.get_widget('before_time_textview').get_buffer().set_text(st)
 
-		#after time
+		# after time
 		st = gajim.config.get('after_time')
 		st = helpers.from_one_line(st)
 		self.xml.get_widget('after_time_textview').get_buffer().set_text(st)
 
-		#before nickname
+		# before nickname
 		st = gajim.config.get('before_nickname')
 		st = helpers.from_one_line(st)
 		self.xml.get_widget('before_nickname_textview').get_buffer().set_text(st)
 
-		#after nickanme
+		# after nickanme
 		st = gajim.config.get('after_nickname')
 		st = helpers.from_one_line(st)
 		self.xml.get_widget('after_nickname_textview').get_buffer().set_text(st)
 
-		#Color for incomming messages
+		# Color for incomming messages
 		colSt = gajim.config.get('inmsgcolor')
 		self.xml.get_widget('incoming_msg_colorbutton').set_color(
 			gtk.gdk.color_parse(colSt))
 
-		#Color for outgoing messages
+		# Color for outgoing messages
 		colSt = gajim.config.get('outmsgcolor')
 		self.xml.get_widget('outgoing_msg_colorbutton').set_color(
 			gtk.gdk.color_parse(colSt))
 
-		#Color for status messages
+		# Color for status messages
 		colSt = gajim.config.get('statusmsgcolor')
 		self.xml.get_widget('status_msg_colorbutton').set_color(
 			gtk.gdk.color_parse(colSt))
 		
-		#Color for hyperlinks
+		# Color for hyperlinks
 		colSt = gajim.config.get('urlmsgcolor')
 		self.xml.get_widget('url_msg_colorbutton').set_color(
 			gtk.gdk.color_parse(colSt))
 
-		#Font for messages
+		# Font for messages
 		font = gajim.config.get('conversation_font')
 		# try to set default font for the current desktop env
 		fontbutton = self.xml.get_widget('conversation_fontbutton')
@@ -286,25 +286,25 @@ def __init__(self):
 		if only_in_roster:
 			self.xml.get_widget('only_in_roster_radiobutton').set_active(True)
 
-		#notify on online statuses
+		# notify on online statuses
 		st = gajim.config.get('notify_on_signin')
 		self.notify_on_signin_checkbutton.set_active(st)
 
-		#notify on offline statuses
+		# notify on offline statuses
 		st = gajim.config.get('notify_on_signout')
 		self.notify_on_signout_checkbutton.set_active(st)
 
-		#autopopupaway
+		# autopopupaway
 		st = gajim.config.get('autopopupaway')
 		self.auto_popup_away_checkbutton.set_active(st)
 
-		#Ignore messages from unknown contacts
+		# Ignore messages from unknown contacts
 		self.xml.get_widget('ignore_events_from_unknown_contacts_checkbutton').\
 			set_active(gajim.config.get('ignore_unknown_contacts'))
 
-		# send chat state notifications
-		st = gajim.config.get('chat_state_notifications')
-		combo = self.xml.get_widget('chat_states_combobox')
+		# outgoing send chat state notifications
+		st = gajim.config.get('outgoing_chat_state_notifications')
+		combo = self.xml.get_widget('outgoing_chat_states_combobox')
 		if st == 'all':
 			combo.set_active(0)
 		elif st == 'composing_only':
@@ -312,7 +312,17 @@ def __init__(self):
 		else: # disabled
 			combo.set_active(2)
 
-		#sounds
+		# displayed send chat state notifications
+		st = gajim.config.get('displayed_chat_state_notifications')
+		combo = self.xml.get_widget('displayed_chat_states_combobox')
+		if st == 'all':
+			combo.set_active(0)
+		elif st == 'composing_only':
+			combo.set_active(1)
+		else: # disabled
+			combo.set_active(2)
+
+		# sounds
 		if os.name == 'nt':
 			# if windows, player must not become visible on show_all
 			soundplayer_hbox = self.xml.get_widget('soundplayer_hbox')
@@ -822,15 +832,24 @@ def on_auto_popup_away_checkbutton_toggled(self, widget):
 	def on_ignore_events_from_unknown_contacts_checkbutton_toggled(self, widget):
 		self.on_checkbutton_toggled(widget, 'ignore_unknown_contacts')
 
-	def on_chat_states_combobox_changed(self, widget):
+	def on_outgoing_chat_states_combobox_changed(self, widget):
 		active = widget.get_active()
 		if active == 0: # all
-			gajim.config.set('chat_state_notifications', 'all')
+			gajim.config.set('outgoing_chat_state_notifications', 'all')
 		elif active == 1: # only composing
-			gajim.config.set('chat_state_notifications', 'composing_only')
+			gajim.config.set('outgoing_chat_state_notifications', 'composing_only')
 		else: # disabled
-			gajim.config.set('chat_state_notifications', 'disabled')
+			gajim.config.set('outgoing_chat_state_notifications', 'disabled')
 
+	def on_displayed_chat_states_combobox_changed(self, widget):
+		active = widget.get_active()
+		if active == 0: # all
+			gajim.config.set('displayed_chat_state_notifications', 'all')
+		elif active == 1: # only composing
+			gajim.config.set('displayed_chat_state_notifications',
+				'composing_only')
+		else: # disabled
+			gajim.config.set('displayed_chat_state_notifications', 'disabled')
 
 	def on_play_sounds_checkbutton_toggled(self, widget):
 		self.on_checkbutton_toggled(widget, 'sounds_on',
-- 
GitLab