Changeset 9871

Show
Ignore:
Timestamp:
07/01/08 12:26:50 (5 months ago)
Author:
js
Message:

Use caps to determine remote clients' support for specific features.
Caps is now used for: File Transfers, MUC Invites, Ad-Hoc Commands.

TODO:

  • Also handle it this way for typing notifications (This might give some trouble / compatibility issues)
  • Fall back to service discovery if no caps are available. Otherwise, we break compatibility with a lot of clients. (Asterix?)
Location:
trunk/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/chat_control.py

    r9863 r9871  
    4646constants = Constants() 
    4747from common.rst_xhtml_generator import create_xhtml 
    48 from common.xmpp.protocol import NS_XHTML 
     48from common.xmpp.protocol import NS_XHTML, NS_FILE, NS_MUC 
    4949 
    5050try: 
     
    10751075                # If we don't have resource, we can't do file transfer 
    10761076                # in transports, contact holds our info we need to disable it too 
    1077                 if self.TYPE_ID == message_control.TYPE_PM and self.gc_contact.jid and \ 
    1078                 self.gc_contact.resource: 
     1077                if NS_FILE in gajim.capscache[(contact.caps_hash_method, 
     1078                contact.caps_hash)].features: 
    10791079                        send_file_button.set_sensitive(True) 
    1080                 elif contact.resource and contact.jid.find('@') != -1: 
    1081                         send_file_button.set_sensitive(True) 
    10821080                else: 
    10831081                        send_file_button.set_sensitive(False) 
    10841082 
    10851083                # check if it's possible to convert to groupchat 
    1086                 if gajim.get_transport_name_from_jid(self.contact.jid) or \ 
    1087                 gajim.connections[self.account].is_zeroconf: 
     1084                if NS_MUC in gajim.capscache[(contact.caps_hash_method, 
     1085                contact.caps_hash)].features: 
     1086                        convert_to_gc_button.set_sensitive(True) 
     1087                else: 
    10881088                        convert_to_gc_button.set_sensitive(False) 
    10891089 
     
    18221822                # If we don't have resource, we can't do file transfer 
    18231823                # in transports, contact holds our info we need to disable it too 
    1824                 if self.TYPE_ID == message_control.TYPE_PM and self.gc_contact.jid and \ 
    1825                 self.gc_contact.resource: 
     1824                if NS_FILE in gajim.capscache[(contact.caps_hash_method, 
     1825                contact.caps_hash)].features: 
    18261826                        send_file_menuitem.set_sensitive(True) 
    1827                 elif contact.resource and contact.jid.find('@') != -1: 
    1828                         send_file_menuitem.set_sensitive(True) 
    18291827                else: 
    18301828                        send_file_menuitem.set_sensitive(False) 
    18311829 
    18321830                # check if it's possible to convert to groupchat 
    1833                 if gajim.get_transport_name_from_jid(jid) or \ 
    1834                 gajim.connections[self.account].is_zeroconf: 
     1831                if NS_MUC in gajim.capscache[(contact.caps_hash_method, 
     1832                contact.caps_hash)].features: 
     1833                        convert_to_gc_menuitem.set_sensitive(True) 
     1834                else: 
    18351835                        convert_to_gc_menuitem.set_sensitive(False) 
    18361836 
  • trunk/src/roster_window.py

    r9869 r9871  
    6161        import dbus 
    6262from lastfm_track_listener import LastFMTrackListener 
     63 
     64from common.xmpp.protocol import NS_COMMANDS, NS_FILE, NS_MUC 
    6365 
    6466try: 
     
    48834885                                        self.on_roster_treeview_row_activated, tree_path) 
    48844886 
    4885                         if contact.resource: 
     4887                        if contact.resource and NS_FILE in gajim.capscache[ 
     4888                        (contact.caps_hash_method, contact.caps_hash)].features: 
     4889                                send_file_menuitem.set_sensitive(True) 
    48864890                                send_file_menuitem.connect('activate', 
    48874891                                        self.on_send_file_menuitem_activate, contact, account) 
    4888                         else: # if we do no have resource we cannot do much 
     4892                        else: 
    48894893                                send_file_menuitem.set_sensitive(False) 
    48904894 
     
    50365040                                account, gajim.interface.on_open_chat_window)) 
    50375041                        send_file_menuitem.set_submenu(self.build_resources_submenu(contacts, 
    5038                                 account, self.on_send_file_menuitem_activate)) 
     5042                                account, self.on_send_file_menuitem_activate, 
     5043                                cap=NS_FILE)) 
    50395044                        execute_command_menuitem.set_submenu(self.build_resources_submenu( 
    5040                                 contacts, account, self.on_execute_command)) 
     5045                                contacts, account, self.on_execute_command, 
     5046                                cap=NS_COMMANDS)) 
    50415047 
    50425048                else: # one resource 
    50435049                        start_chat_menuitem.connect('activate', 
    50445050                                gajim.interface.on_open_chat_window, contact, account) 
    5045                         execute_command_menuitem.connect('activate', self.on_execute_command, 
    5046                                 contact, account, contact.resource) 
     5051                        if contact.resource and NS_FILE in gajim.capscache[ 
     5052                        (contact.caps_hash_method, contact.caps_hash)].features: 
     5053                                execute_command_menuitem.set_sensitive(True) 
     5054                                execute_command_menuitem.connect('activate', self.on_execute_command, 
     5055                                        contact, account, contact.resource) 
     5056                        else: 
     5057                                execute_command_menuitem.set_sensitive(False) 
    50475058 
    50485059                        our_jid_other_resource = None 
     
    50525063                        # Else this var is useless but harmless in next connect calls 
    50535064 
    5054                         if contact.resource: 
     5065                        if contact.resource and NS_FILE in gajim.capscache[ 
     5066                        (contact.caps_hash_method, contact.caps_hash)].features: 
     5067                                send_file_menuitem.set_sensitive(True) 
    50555068                                send_file_menuitem.connect('activate', 
    50565069                                        self.on_send_file_menuitem_activate, contact, account) 
    5057                         else: # if we do not have resource we cannot send file 
     5070                        else: 
    50585071                                send_file_menuitem.set_sensitive(False) 
    50595072 
     
    54435456 
    54445457        def build_resources_submenu(self, contacts, account, action, room_jid=None, 
    5445         room_account=None): 
     5458        room_account=None, cap=None): 
    54465459                ''' Build a submenu with contact's resources. 
    54475460                room_jid and room_account are for action self.on_invite_to_room ''' 
     
    54675480                        else: # start_chat, execute_command, send_file 
    54685481                                item.connect('activate', action, c, account, c.resource) 
     5482                        if cap and cap not in gajim.capscache[ 
     5483                        (c.caps_hash_method, c.caps_hash)].features: 
     5484                                item.set_sensitive(False) 
    54695485                return sub_menu 
    54705486 
     
    54995515                if len(contact_list) > 1: # several resources 
    55005516                        invite_to_new_room_menuitem.set_submenu(self.build_resources_submenu( 
    5501                                 contact_list, account, self.on_invite_to_new_room)) 
    5502                 else: 
    5503                         invite_to_new_room_menuitem.connect('activate', 
    5504                                 self.on_invite_to_new_room, list_) 
     5517                                contact_list, account, self.on_invite_to_new_room, cap=NS_MUC)) 
     5518                else: 
     5519                        if NS_MUC in gajim.capscache[(contact.caps_hash_method, 
     5520                        contact.caps_hash)].features: 
     5521                                invite_menuitem.set_sensitive(True) 
     5522                                invite_to_new_room_menuitem.connect('activate', 
     5523                                        self.on_invite_to_new_room, list_) 
     5524                        else: 
     5525                                invite_menuitem.set_sensitive(False) 
    55055526                # transform None in 'jabber' 
    55065527                c_t = contacts_transport or 'jabber'