Changeset 2399

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]

Location:
trunk/src
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/common/connection.py

    r2386 r2399  
    219219                tim = time.localtime(timegm(tim)) 
    220220                encrypted = False 
     221                chatstate_tag = None 
    221222                xtags = msg.getTags('x') 
    222223                encTag = None 
     
    226227                                encTag = xtag 
    227228                                break 
     229 
     230                # chatstates - look for chatstate tags in a message 
     231                children = msg.getChildren() 
     232                for child in children: 
     233                        if child.getNamespace() == 'http://jabber.org/protocol/chatstates': 
     234                                chatstate_tag = child.getName() 
     235                                break 
     236                         
    228237                if encTag and USE_GPG: 
    229238                        #decrypt 
     
    254263                                tim = tim) 
    255264                        self.dispatch('MSG', (str(msg.getFrom()), msgtxt, tim, encrypted, 
    256                                 mtype, subject)) 
     265                                mtype, subject, None)) 
    257266                else: # it's type 'chat' 
    258                         if not msg.getTag('body'): #no <body> 
     267                        if not msg.getTag('body') and chatstate_tag is None: #no <body> 
    259268                                return 
    260269                        log_msgtxt = msgtxt 
     
    264273                                tim = tim) 
    265274                        self.dispatch('MSG', (str(msg.getFrom()), msgtxt, tim, encrypted, 
    266                                 mtype, subject)) 
     275                                mtype, subject, chatstate_tag)) 
    267276        # END messageCB 
    268277 
     
    860869                        self.dispatch('STATUS', show) 
    861870 
    862         def send_message(self, jid, msg, keyID, type = 'chat', subject=''): 
    863                 if not self.connection: 
    864                         return 
    865                 if not msg: 
     871        def send_message(self, jid, msg, keyID, type = 'chat', subject='', chatstate = None): 
     872                if not self.connection: 
     873                        return 
     874                if not msg and chatstate is None: 
    866875                        return 
    867876                msgtxt = msg 
     
    887896                if msgenc: 
    888897                        msg_iq.setTag(common.xmpp.NS_ENCRYPTED + ' x').setData(msgenc) 
     898 
     899                # chatstates - if peer supports jep85, send chatstates 
     900                # please note that the only valid tag inside a message containing a <body> tag is the active event 
     901                if chatstate != None: 
     902                        msg_iq.setTag(chatstate, {}, namespace='http://jabber.org/protocol/chatstates') 
     903                 
    889904                self.to_be_sent.append(msg_iq) 
    890905                gajim.logger.write('outgoing', msg, jid) 
     
    940955                return 
    941956 
    942         def update_user(self, jid, name, groups): 
     957        def update_contact(self, jid, name, groups): 
    943958                if self.connection: 
    944959                        self.connection.getRoster().setItem(jid = jid, name = name, 
     
    11511166 
    11521167        def gc_set_role(self, room_jid, nick, role, reason = ''): 
     1168                '''role is for all the life of the room so it's based on nick''' 
    11531169                if not self.connection: 
    11541170                        return 
     
    11631179 
    11641180        def gc_set_affiliation(self, room_jid, jid, affiliation, reason = ''): 
     1181                '''affiliation is for all the life of the room so it's based on jid''' 
    11651182                if not self.connection: 
    11661183                        return 
  • trunk/src/gajim.py

    r2391 r2399  
    345345 
    346346        def handle_event_msg(self, account, array): 
    347                 #('MSG', account, (contact, msg, time, encrypted, msg_type, subject)) 
     347                #('MSG', account, (contact, msg, time, encrypted, msg_type, subject, chatstate_tag)) 
    348348                jid = array[0].split('/')[0] 
    349349                msg_type = array[4] 
     350                chatstate_tag = array[6] 
    350351                if jid.find('@') <= 0: 
    351352                        jid = jid.replace('@', '') 
     
    407408                if self.remote: 
    408409                        self.remote.raise_signal('NewMessage', (account, array)) 
     410                if self.windows[account]['chats'].has_key(jid): 
     411                        chat_win = self.windows[account]['chats'][jid] 
     412                        # chatstates - display jep85 events in window 
     413                        if chatstate_tag != None: 
     414                                if chat_win.chatstates[jid] == 'ask': 
     415                                        chat_win.chatstates[jid] = 'active' 
     416                                chat_win.print_conversation(jid + ' is now ' + chatstate_tag, jid, 'status', tim = array[2]) 
     417                        else: 
     418                                # got no valid jep85 answer, peer does not support it 
     419                                chat_win.chatstates[jid] = -1 
     420                                 
    409421                 
    410422        def handle_event_msgerror(self, account, array): 
  • trunk/src/gtkgui.glade

    r2390 r2399  
    99339933  <signal name="button_press_event" handler="on_tabbed_chat_window_button_press_event" last_modification_time="Fri, 24 Jun 2005 23:54:20 GMT"/> 
    99349934  <signal name="focus_out_event" handler="on_tabbed_chat_window_focus_out_event" last_modification_time="Mon, 18 Jul 2005 22:07:30 GMT"/> 
    9935   <signal name="window_state_event" handler="on_tabbed_chat_window_state_changed" last_modification_time="Mon, 18 Jul 2005 22:21:37 GMT"/> 
    99369935 
    99379936  <child> 
  • trunk/src/roster_window.py

    r2385 r2399  
    310310                profile_avatar_menuitem = self.xml.get_widget('profile_avatar_menuitem') 
    311311                 
    312                  
    313                 xm = gtk.glade.XML(GTKGUI_GLADE, 'advanced_menuitem_menu', APP) 
    314                 advanced_menuitem_menu = xm.get_widget('advanced_menuitem_menu') 
     312 
     313                ui_description = """ 
     314<ui> 
     315        <menu action='advanced_menuitem_menu'> 
     316                <menu action='A'> 
     317                        %(menu)s 
     318                </menu> 
     319                <menu action='B'> 
     320                        %(menu)s 
     321                </menu> 
     322                <menu action='C'> 
     323                        %(menu)s 
     324                </menu> 
     325                <menuitem action="Quit" /> 
     326        </menu> 
     327</ui>""" 
     328 
     329                menu_description = """ 
     330                        <menuitem action='Send Single Message' /> 
     331                        <menuitem action='XML Console' /> 
     332                        <separator /> 
     333                        <menuitem action='Administrator' /> 
     334                        <menuitem action='Test5' /> 
     335""" 
    315336 
    316337                if self.add_new_contact_handler_id: 
  • 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)