diff options
author | js <js-gajim@webkeks.org> | 2008-07-01 14:26:50 +0400 |
---|---|---|
committer | js <js-gajim@webkeks.org> | 2008-07-01 14:26:50 +0400 |
commit | 62fe1c72e3cab628ad4ee6ba051cef4103b89518 (patch) | |
tree | 43eb4f6a6e6dd30da03316c52c10636f6bd2e167 /src | |
parent | a836c7eca9d4e065be286a4f65e8a9efb044330c (diff) |
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?)
Diffstat (limited to 'src')
-rw-r--r-- | src/chat_control.py | 26 | ||||
-rw-r--r-- | src/roster_window.py | 45 |
2 files changed, 46 insertions, 25 deletions
diff --git a/src/chat_control.py b/src/chat_control.py index 64a906af4..7cb6a17a8 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -45,7 +45,7 @@ from common.contacts import GC_Contact from common.logger import Constants constants = Constants() from common.rst_xhtml_generator import create_xhtml -from common.xmpp.protocol import NS_XHTML +from common.xmpp.protocol import NS_XHTML, NS_FILE, NS_MUC try: import gtkspell @@ -1074,17 +1074,17 @@ class ChatControl(ChatControlBase): # If we don't have resource, we can't do file transfer # in transports, contact holds our info we need to disable it too - if self.TYPE_ID == message_control.TYPE_PM and self.gc_contact.jid and \ - self.gc_contact.resource: - send_file_button.set_sensitive(True) - elif contact.resource and contact.jid.find('@') != -1: + if NS_FILE in gajim.capscache[(contact.caps_hash_method, + contact.caps_hash)].features: send_file_button.set_sensitive(True) else: send_file_button.set_sensitive(False) # check if it's possible to convert to groupchat - if gajim.get_transport_name_from_jid(self.contact.jid) or \ - gajim.connections[self.account].is_zeroconf: + if NS_MUC in gajim.capscache[(contact.caps_hash_method, + contact.caps_hash)].features: + convert_to_gc_button.set_sensitive(True) + else: convert_to_gc_button.set_sensitive(False) # keep timeout id and window obj for possible big avatar @@ -1821,17 +1821,17 @@ class ChatControl(ChatControlBase): # If we don't have resource, we can't do file transfer # in transports, contact holds our info we need to disable it too - if self.TYPE_ID == message_control.TYPE_PM and self.gc_contact.jid and \ - self.gc_contact.resource: - send_file_menuitem.set_sensitive(True) - elif contact.resource and contact.jid.find('@') != -1: + if NS_FILE in gajim.capscache[(contact.caps_hash_method, + contact.caps_hash)].features: send_file_menuitem.set_sensitive(True) else: send_file_menuitem.set_sensitive(False) # check if it's possible to convert to groupchat - if gajim.get_transport_name_from_jid(jid) or \ - gajim.connections[self.account].is_zeroconf: + if NS_MUC in gajim.capscache[(contact.caps_hash_method, + contact.caps_hash)].features: + convert_to_gc_menuitem.set_sensitive(True) + else: convert_to_gc_menuitem.set_sensitive(False) # connect signals diff --git a/src/roster_window.py b/src/roster_window.py index df3bee1a3..60bd1b0f7 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -61,6 +61,8 @@ if dbus_support.supported: import dbus from lastfm_track_listener import LastFMTrackListener +from common.xmpp.protocol import NS_COMMANDS, NS_FILE, NS_MUC + try: from osx import syncmenu except ImportError: @@ -4882,10 +4884,12 @@ class RosterWindow: start_chat_menuitem.connect('activate', self.on_roster_treeview_row_activated, tree_path) - if contact.resource: + if contact.resource and NS_FILE in gajim.capscache[ + (contact.caps_hash_method, contact.caps_hash)].features: + send_file_menuitem.set_sensitive(True) send_file_menuitem.connect('activate', self.on_send_file_menuitem_activate, contact, account) - else: # if we do no have resource we cannot do much + else: send_file_menuitem.set_sensitive(False) rename_menuitem.connect('activate', self.on_rename, titer, tree_path) @@ -5035,15 +5039,22 @@ class RosterWindow: start_chat_menuitem.set_submenu(self.build_resources_submenu(contacts, account, gajim.interface.on_open_chat_window)) send_file_menuitem.set_submenu(self.build_resources_submenu(contacts, - account, self.on_send_file_menuitem_activate)) + account, self.on_send_file_menuitem_activate, + cap=NS_FILE)) execute_command_menuitem.set_submenu(self.build_resources_submenu( - contacts, account, self.on_execute_command)) + contacts, account, self.on_execute_command, + cap=NS_COMMANDS)) else: # one resource start_chat_menuitem.connect('activate', gajim.interface.on_open_chat_window, contact, account) - execute_command_menuitem.connect('activate', self.on_execute_command, - contact, account, contact.resource) + if contact.resource and NS_FILE in gajim.capscache[ + (contact.caps_hash_method, contact.caps_hash)].features: + execute_command_menuitem.set_sensitive(True) + execute_command_menuitem.connect('activate', self.on_execute_command, + contact, account, contact.resource) + else: + execute_command_menuitem.set_sensitive(False) our_jid_other_resource = None if our_jid: @@ -5051,10 +5062,12 @@ class RosterWindow: our_jid_other_resource = contact.resource # Else this var is useless but harmless in next connect calls - if contact.resource: + if contact.resource and NS_FILE in gajim.capscache[ + (contact.caps_hash_method, contact.caps_hash)].features: + send_file_menuitem.set_sensitive(True) send_file_menuitem.connect('activate', self.on_send_file_menuitem_activate, contact, account) - else: # if we do not have resource we cannot send file + else: send_file_menuitem.set_sensitive(False) send_single_message_menuitem.connect('activate', @@ -5442,7 +5455,7 @@ class RosterWindow: menu.popup(None, None, None, event_button, event.time) def build_resources_submenu(self, contacts, account, action, room_jid=None, - room_account=None): + room_account=None, cap=None): ''' Build a submenu with contact's resources. room_jid and room_account are for action self.on_invite_to_room ''' sub_menu = gtk.Menu() @@ -5466,6 +5479,9 @@ class RosterWindow: item.connect('activate', action, [(c, account)], c.resource) else: # start_chat, execute_command, send_file item.connect('activate', action, c, account, c.resource) + if cap and cap not in gajim.capscache[ + (c.caps_hash_method, c.caps_hash)].features: + item.set_sensitive(False) return sub_menu def build_invite_submenu(self, invite_menuitem, list_): @@ -5498,10 +5514,15 @@ class RosterWindow: invite_to_new_room_menuitem.set_image(icon) if len(contact_list) > 1: # several resources invite_to_new_room_menuitem.set_submenu(self.build_resources_submenu( - contact_list, account, self.on_invite_to_new_room)) + contact_list, account, self.on_invite_to_new_room, cap=NS_MUC)) else: - invite_to_new_room_menuitem.connect('activate', - self.on_invite_to_new_room, list_) + if NS_MUC in gajim.capscache[(contact.caps_hash_method, + contact.caps_hash)].features: + invite_menuitem.set_sensitive(True) + invite_to_new_room_menuitem.connect('activate', + self.on_invite_to_new_room, list_) + else: + invite_menuitem.set_sensitive(False) # transform None in 'jabber' c_t = contacts_transport or 'jabber' muc_jid = {} |