From 5a054fd790a8c719fb006e0b279026c666124570 Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Sun, 7 Aug 2005 20:58:44 +0000 Subject: [PATCH] chatstate by default only are about composing. chatstates ready for 0.8 --- src/common/config.py | 2 +- src/common/gajim.py | 2 +- src/config.py | 26 +++++++++------ src/gtkgui.glade | 66 ++++++++++++++++++++++++++++++--------- src/tabbed_chat_window.py | 32 ++++++++++++++----- 5 files changed, 95 insertions(+), 33 deletions(-) diff --git a/src/common/config.py b/src/common/config.py index 1bf412882..a43d84382 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -120,7 +120,7 @@ class Config: 'always_english_wikipedia': [opt_bool, False], 'always_english_wiktionary': [opt_bool, False], 'use_dbus': [opt_bool, True], # allow control via dbus service - 'send_receive_chat_state_notifications': [opt_bool, True], + 'chat_state_notifications': [opt_str, 'composing_only'], # 'all', 'all', 'disabled' 'autodetect_browser_mailer': [opt_bool, True], 'print_ichat_every_foo_minutes': [opt_int, 5], 'confirm_close_muc': [opt_bool, True], # confirm closing MUC window diff --git a/src/common/gajim.py b/src/common/gajim.py index c7cd4c40f..0ce06dd83 100644 --- a/src/common/gajim.py +++ b/src/common/gajim.py @@ -88,7 +88,7 @@ def get_contact_instances_from_jid(account, jid): return contacts_instances def get_first_contact_instance_from_jid(account, jid): - contact = None # if not found skip TB + contact = None if jid in contacts[account]: contact = contacts[account][jid][0] else: # it's fake jid diff --git a/src/config.py b/src/config.py index 05b37e48c..a110448e5 100644 --- a/src/config.py +++ b/src/config.py @@ -269,12 +269,14 @@ class PreferencesWindow: set_active(gajim.config.get('ignore_unknown_contacts')) # send chat state notifications - st = gajim.config.get('send_receive_chat_state_notifications') - btn = self.xml.get_widget('send_receive_chat_state_checkbutton') - if st: - btn.set_active(True) - else: - btn.set_active(False) + st = gajim.config.get('chat_state_notifications') + combo = self.xml.get_widget('chat_states_combobox') + if st == 'composing_only': + combo.set_active(0) + elif st == 'all': + combo.set_active(1) + else: # disabled + btn.set_active(2) #sounds if os.name == 'nt': # if windows, player must not become visible on show_all @@ -765,9 +767,15 @@ class PreferencesWindow: def on_ignore_events_from_unknown_contacts_checkbutton_toggled(self, widget): self.on_checkbutton_toggled(widget, 'ignore_unknown_contacts') - def on_send_receive_chat_state_checkbutton_toggled(self, widget): - self.on_checkbutton_toggled(widget, - 'send_receive_chat_state_notifications') + def on_chat_states_combobox_changed(self, widget): + active = widget.get_active() + if active == 0: # only composing + gajim.config.set('chat_state_notifications', 'composing_only') + elif active == 1: # all + gajim.config.set('chat_state_notifications', 'all') + else: # disabled + gajim.config.set('chat_state_notifications', 'disabled') + def on_play_sounds_checkbutton_toggled(self, widget): self.on_checkbutton_toggled(widget, 'sounds_on', diff --git a/src/gtkgui.glade b/src/gtkgui.glade index 3a2ce0997..9f98525a8 100644 --- a/src/gtkgui.glade +++ b/src/gtkgui.glade @@ -4386,18 +4386,56 @@ - + True - If checked, Gajim will broadcast capability to send and receive meta-information related to a conversation you may have with a contact such as composing a message - True - Send & receive chat state noti_fications - True - GTK_RELIEF_NORMAL - True - False - False - True - + False + 12 + + + + True + If checked, Gajim will broadcast capability to send and receive meta-information related to a conversation you may have with a contact such as composing a message + True + False + + + + True + Chat state noti_fications: + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + chat_states_combobox + + + + + 0 + False + False + + + + + + True + Composing only +All +Disabled + + + + 0 + False + True + + 0 @@ -5303,7 +5341,7 @@ True - Autodetect + Autodetect at every application startup Always use GNOME default applications Always use KDE default applications Custom @@ -11133,7 +11171,7 @@ Status message True - + Event Type False True GTK_JUSTIFY_LEFT @@ -11187,7 +11225,7 @@ Status message True - + Event desc False False GTK_JUSTIFY_LEFT diff --git a/src/tabbed_chat_window.py b/src/tabbed_chat_window.py index 9d5166a16..1b55f601d 100644 --- a/src/tabbed_chat_window.py +++ b/src/tabbed_chat_window.py @@ -133,7 +133,7 @@ class TabbedChatWindow(chat.Chat): #FIXME: when gtk2.4 is OOOOLD do it via glade2.10+ if gtk.pygtk_version >= (2, 6, 0) and gtk.gtk_version >= (2, 6, 0): banner_name_label.set_ellipsize(pango.ELLIPSIZE_END) - #FIXME: do me with pango ellipseEND when gtk24 is OLD + #FIXME: remove me when gtk24 is OLD elif status is not None and len(status) > 50: status = status[:47] + '...' status = gtkgui_helpers.escape_for_pango_markup(status) @@ -146,8 +146,18 @@ class TabbedChatWindow(chat.Chat): #label_text = '%s\n%s' \ # % (name, fulljid) - if chatstate: - chatstate = helpers.get_uf_chatstate(chatstate) + + st = gajim.config.get('chat_state_notifications') + if chatstate and st in ('composing_only', 'all'): + if st == 'all': + chatstate = helpers.get_uf_chatstate(chatstate) + else: # 'composing_only' + if chatstate in ('composing', 'paused'): + # only print composing, paused + chatstate = helpers.get_uf_chatstate(chatstate) + else: + chatstate = '' + print chatstate label_text = \ '%s %s' % (name, chatstate) else: @@ -200,10 +210,12 @@ class TabbedChatWindow(chat.Chat): contacts_list = gajim.contacts[self.account][jid] else: contacts_list = [self.contacts[jid]] + user = contacts_list[0] show = user.show jid = user.jid keyID = user.keyID + for u in contacts_list: if u.priority > prio: prio = u.priority @@ -215,10 +227,12 @@ class TabbedChatWindow(chat.Chat): state_images = self.plugin.roster.get_appropriate_state_images(jid) image = state_images[show] banner_status_image = self.xmls[jid].get_widget('banner_status_image') + if keyID: self.xmls[jid].get_widget('gpg_togglebutton').set_sensitive(True) else: self.xmls[jid].get_widget('gpg_togglebutton').set_sensitive(False) + if image.get_storage_type() == gtk.IMAGE_ANIMATION: banner_status_image.set_from_animation(image.get_animation()) status_image.set_from_animation(image.get_animation()) @@ -475,10 +489,10 @@ class TabbedChatWindow(chat.Chat): # in an workaround way (we could also get somehow the listed shortcuts # but I don't know if it's possible) chars_no = len(message) - gobject.timeout_add(1000, self.on_timeout_for_check_composing, + gobject.timeout_add(1000, self.check_for_possible_composing, message_buffer, jid, chars_no) - def on_timeout_for_check_composing(self, message_buffer, jid, chars_no): + def check_for_possible_composing(self, message_buffer, jid, chars_no): start_iter, end_iter = message_buffer.get_bounds() message = message_buffer.get_text(start_iter, end_iter, False) chars_no_after_one_sec = len(message) @@ -486,7 +500,7 @@ class TabbedChatWindow(chat.Chat): # so GTK+ decided key_press was for writing.. self.kbd_activity_in_last_5_secs = True self.kbd_activity_in_last_30_secs = True - self.send_chatstate('composing') + self.send_chatstate('composing', jid) def send_chatstate(self, state, jid = None): ''' sends our chatstate as STANDLONE chat state message (eg. no body) @@ -503,7 +517,7 @@ class TabbedChatWindow(chat.Chat): # do not send nothing if we have chat state notifications disabled # that means we won't reply to the from other peer # so we do not broadcast jep85 capabalities - if not gajim.config.get('send_receive_chat_state_notifications'): + if gajim.config.get('chat_state_notifications') == 'disabled': return if jid is None: @@ -585,7 +599,7 @@ class TabbedChatWindow(chat.Chat): encrypted = True chatstates_on = gajim.config.get( - 'send_receive_chat_state_notifications') + 'chat_state_notifications') != 'disabled' chatstate_to_send = None @@ -606,6 +620,8 @@ class TabbedChatWindow(chat.Chat): gajim.connections[self.account].send_message(jid, message, keyID, chatstate = chatstate_to_send) + + contact.chatstate = chatstate_to_send message_buffer.set_text('') self.print_conversation(message, jid, jid, encrypted = encrypted)