Author: js
Date: 2008-07-01 12:26:50 +0200 (Tue, 01 Jul 2008)
New Revision: 9871
Modified:
trunk/src/chat_control.py
trunk/src/roster_window.py
Log:
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?)
Modified: trunk/src/chat_control.py
===================================================================
--- trunk/src/chat_control.py 2008-06-30 23:02:12 UTC (rev 9870)
+++ trunk/src/chat_control.py 2008-07-01 10:26:50 UTC (rev 9871)
@@ -45,7 +45,7 @@
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 @@
# 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:
+ if NS_FILE in gajim.capscache[(contact.caps_hash_method,
+ contact.caps_hash)].features:
send_file_button.set_sensitive(True)
- elif contact.resource and contact.jid.find('@') != -1:
- 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 @@
# 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:
+ if NS_FILE in gajim.capscache[(contact.caps_hash_method,
+ contact.caps_hash)].features:
send_file_menuitem.set_sensitive(True)
- elif contact.resource and contact.jid.find('@') != -1:
- 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
Modified: trunk/src/roster_window.py
===================================================================
--- trunk/src/roster_window.py 2008-06-30 23:02:12 UTC (rev 9870)
+++ trunk/src/roster_window.py 2008-07-01 10:26:50 UTC (rev 9871)
@@ -61,6 +61,8 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 = {}