Show
Ignore:
Timestamp:
07/19/05 16:38:58 (3 years ago)
Author:
nk
Message:

[peralta] Chat State Notifications inital patch. I assume that every wm will focus-out before iconify. If that is not the case I am going to use window-state-changed too [to be tested]

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/tabbed_chat_window.py

    r2393 r2399  
    4545                chat.Chat.__init__(self, plugin, account, 'tabbed_chat_window') 
    4646                self.users = {} 
     47                self.chatstates = {} 
    4748                self.new_user(user) 
    4849                self.show_title() 
     
    5354                self.xml.signal_connect('on_tabbed_chat_window_focus_in_event', 
    5455                        self.on_tabbed_chat_window_focus_in_event) 
     56                self.xml.signal_connect('on_tabbed_chat_window_focus_out_event', 
     57                        self.on_tabbed_chat_window_focus_out_event) 
    5558                self.xml.signal_connect('on_tabbed_chat_window_button_press_event', 
    5659                        self.on_chat_window_button_press_event) 
     
    6164 
    6265                if gajim.config.get('saveposition'): 
    63                 # get window position and size from config 
     66                        # get window position and size from config 
    6467                        self.window.move(gajim.config.get('chat-x-position'), 
    6568                                        gajim.config.get('chat-y-position')) 
     
    198201 
    199202                if gajim.config.get('saveposition'): 
    200                 # save the window size and position 
     203                        # save the window size and position 
    201204                        x, y = self.window.get_position() 
    202205                        gajim.config.set('chat-x-position', x) 
     
    208211        def on_tabbed_chat_window_destroy(self, widget): 
    209212                #clean self.plugin.windows[self.account]['chats'] 
     213                # on window destroy, send 'gone' chatstate 
     214                self.send_chatstate('gone') 
    210215                chat.Chat.on_window_destroy(self, widget, 'chats') 
    211216 
    212217        def on_tabbed_chat_window_focus_in_event(self, widget, event): 
    213218                chat.Chat.on_chat_window_focus_in_event(self, widget, event) 
     219                # on focus in, send 'active' chatstate 
     220                self.send_chatstate('active') 
     221 
     222        def on_tabbed_chat_window_focus_out_event(self, widget, event): 
     223                gobject.timeout_add(500, self.check_window_state, widget) 
     224 
     225        def check_window_state(self, widget): 
     226                ''' we want: "minimized" or "focus-out" 
     227      not "focus-out, minimized" or "focus-out" ''' 
     228                new_state = widget.window.get_state() 
     229                if new_state & gtk.gdk.WINDOW_STATE_ICONIFIED: 
     230                        print 'iconify' 
     231                        self.send_chatstate('inactive') 
     232                else: 
     233                        print 'just focus-out' 
     234                        self.send_chatstate('paused') 
    214235 
    215236        def on_chat_notebook_key_press_event(self, widget, event): 
     
    238259                                return 
    239260 
     261                # chatstates - window is destroyed, send gone 
     262                self.send_chatstate('gone') 
     263                 
    240264                chat.Chat.remove_tab(self, jid, 'chats') 
    241265                if len(self.xmls) > 0: 
     
    275299                gajim.connections[self.account].request_vcard(user.jid) 
    276300                self.childs[user.jid].show_all() 
     301 
     302                # chatstates 
     303                self.chatstates[user.jid] = None 
    277304 
    278305        def on_message_textview_key_press_event(self, widget, event): 
     
    327354                                self.sent_messages_scroll(jid, 'down', widget.get_buffer()) 
    328355                                return True # override the default gtk+ thing for ctrl+down 
    329  
     356                         
     357                else: 
     358                        # chatstates 
     359                        # if composing, send chatstate 
     360                        self.send_chatstate('composing') 
     361 
     362        def send_chatstate(self, state): 
     363                # please read jep-85 to get an idea of this 
     364                # we keep track of jep85 support by the peer by three extra states: None, -1 and 'ask' 
     365                # None if no info about peer 
     366                # -1 if peer does not support jep85 
     367                # 'ask' if we sent 'active' chatstate and are waiting for reply 
     368 
     369                jid = self.get_active_jid() 
     370 
     371                # print jid, self.chatstates[jid], state 
     372                if self.chatstates[jid] == -1: 
     373                        return 
     374 
     375                # if current state equals last state, return 
     376                if self.chatstates[jid] == state: 
     377                        return 
     378 
     379                if self.chatstates[jid] is None: 
     380                        # state = 'ask' 
     381                        # send and return 
     382                        return 
     383 
     384                if self.chatstates[jid] == 'ask': 
     385                        return 
     386                 
     387                # if last state was composing, don't send active 
     388                if self.chatstates[jid] == 'composing' and state == 'active': 
     389                        return 
     390 
     391                self.chatstates[jid] = state 
     392                gajim.connections[self.account].send_message(jid, None, None, chatstate = state) 
     393                 
     394                 
    330395        def send_message(self, message): 
    331396                """Send the message given to the active tab""" 
     
    351416                                keyID = self.users[jid].keyID 
    352417                                encrypted = True 
    353                         gajim.connections[self.account].send_message(jid, message, keyID) 
     418 
     419                        # chatstates - if no info about peer, discover 
     420                        if self.chatstates[jid] is None: 
     421                                 
     422                                gajim.connections[self.account].send_message(jid, message, keyID, chatstate = 'active') 
     423                                self.chatstates[jid] = 'ask' 
     424                        # if peer supports jep85, send 'active' 
     425                        elif self.chatstates[jid] != -1: 
     426                                gajim.connections[self.account].send_message(jid, message, keyID, chatstate = 'active') 
     427                        else: 
     428                                gajim.connections[self.account].send_message(jid, message, keyID) 
     429                                print self.chatstates[jid] 
    354430                        message_buffer.set_text('', -1) 
    355431                        self.print_conversation(message, jid, jid, encrypted = encrypted)