Added a function to check for specific features. This makes
implementing a later coming fallback to disco rather easy.
This commit is contained in:
parent
38760989d1
commit
0405981b15
|
@ -1074,15 +1074,13 @@ class ChatControl(ChatControlBase):
|
||||||
|
|
||||||
# If we don't have resource, we can't do file transfer
|
# If we don't have resource, we can't do file transfer
|
||||||
# in transports, contact holds our info we need to disable it too
|
# in transports, contact holds our info we need to disable it too
|
||||||
if NS_FILE in gajim.capscache[(contact.caps_hash_method,
|
if gajim.capscache.is_supported(contact, NS_FILE):
|
||||||
contact.caps_hash)].features:
|
|
||||||
send_file_button.set_sensitive(True)
|
send_file_button.set_sensitive(True)
|
||||||
else:
|
else:
|
||||||
send_file_button.set_sensitive(False)
|
send_file_button.set_sensitive(False)
|
||||||
|
|
||||||
# check if it's possible to convert to groupchat
|
# check if it's possible to convert to groupchat
|
||||||
if NS_MUC in gajim.capscache[(contact.caps_hash_method,
|
if gajim.capscache.is_supported(contact, NS_MUC):
|
||||||
contact.caps_hash)].features:
|
|
||||||
convert_to_gc_button.set_sensitive(True)
|
convert_to_gc_button.set_sensitive(True)
|
||||||
else:
|
else:
|
||||||
convert_to_gc_button.set_sensitive(False)
|
convert_to_gc_button.set_sensitive(False)
|
||||||
|
@ -1821,15 +1819,13 @@ class ChatControl(ChatControlBase):
|
||||||
|
|
||||||
# If we don't have resource, we can't do file transfer
|
# If we don't have resource, we can't do file transfer
|
||||||
# in transports, contact holds our info we need to disable it too
|
# in transports, contact holds our info we need to disable it too
|
||||||
if NS_FILE in gajim.capscache[(contact.caps_hash_method,
|
if gajim.capscache.is_supported(contact, NS_FILE):
|
||||||
contact.caps_hash)].features:
|
|
||||||
send_file_menuitem.set_sensitive(True)
|
send_file_menuitem.set_sensitive(True)
|
||||||
else:
|
else:
|
||||||
send_file_menuitem.set_sensitive(False)
|
send_file_menuitem.set_sensitive(False)
|
||||||
|
|
||||||
# check if it's possible to convert to groupchat
|
# check if it's possible to convert to groupchat
|
||||||
if NS_MUC in gajim.capscache[(contact.caps_hash_method,
|
if gajim.capscache.is_supported(contact, NS_MUC):
|
||||||
contact.caps_hash)].features:
|
|
||||||
convert_to_gc_menuitem.set_sensitive(True)
|
convert_to_gc_menuitem.set_sensitive(True)
|
||||||
else:
|
else:
|
||||||
convert_to_gc_menuitem.set_sensitive(False)
|
convert_to_gc_menuitem.set_sensitive(False)
|
||||||
|
|
|
@ -178,6 +178,21 @@ class CapsCache(object):
|
||||||
# this will create proper object
|
# this will create proper object
|
||||||
q.queried=1
|
q.queried=1
|
||||||
con.discoverInfo(jid, '%s#%s' % (node, hash))
|
con.discoverInfo(jid, '%s#%s' % (node, hash))
|
||||||
|
|
||||||
|
def is_supported(self, contact, feature):
|
||||||
|
if not contact.resource:
|
||||||
|
return False
|
||||||
|
|
||||||
|
# FIXME: We assume everything is supported if we got no caps.
|
||||||
|
# This is the "Asterix way", after 0.12 release, I will
|
||||||
|
# likely implement a fallback to disco (could be disabled
|
||||||
|
# for mobile users who pay for traffic)
|
||||||
|
features = self[(contact.caps_hash_method,
|
||||||
|
contact.caps_hash)].features
|
||||||
|
if feature in features or features == []:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
gajim.capscache = CapsCache(gajim.logger)
|
gajim.capscache = CapsCache(gajim.logger)
|
||||||
|
|
||||||
|
|
|
@ -4884,8 +4884,7 @@ class RosterWindow:
|
||||||
start_chat_menuitem.connect('activate',
|
start_chat_menuitem.connect('activate',
|
||||||
self.on_roster_treeview_row_activated, tree_path)
|
self.on_roster_treeview_row_activated, tree_path)
|
||||||
|
|
||||||
if contact.resource and NS_FILE in gajim.capscache[
|
if gajim.capscache.is_supported(contact, NS_FILE):
|
||||||
(contact.caps_hash_method, contact.caps_hash)].features:
|
|
||||||
send_file_menuitem.set_sensitive(True)
|
send_file_menuitem.set_sensitive(True)
|
||||||
send_file_menuitem.connect('activate',
|
send_file_menuitem.connect('activate',
|
||||||
self.on_send_file_menuitem_activate, contact, account)
|
self.on_send_file_menuitem_activate, contact, account)
|
||||||
|
@ -5048,8 +5047,7 @@ class RosterWindow:
|
||||||
else: # one resource
|
else: # one resource
|
||||||
start_chat_menuitem.connect('activate',
|
start_chat_menuitem.connect('activate',
|
||||||
gajim.interface.on_open_chat_window, contact, account)
|
gajim.interface.on_open_chat_window, contact, account)
|
||||||
if contact.resource and NS_COMMANDS in gajim.capscache[
|
if gajim.capscache.is_supported(contact, NS_COMMANDS):
|
||||||
(contact.caps_hash_method, contact.caps_hash)].features:
|
|
||||||
execute_command_menuitem.set_sensitive(True)
|
execute_command_menuitem.set_sensitive(True)
|
||||||
execute_command_menuitem.connect('activate', self.on_execute_command,
|
execute_command_menuitem.connect('activate', self.on_execute_command,
|
||||||
contact, account, contact.resource)
|
contact, account, contact.resource)
|
||||||
|
@ -5062,8 +5060,7 @@ class RosterWindow:
|
||||||
our_jid_other_resource = contact.resource
|
our_jid_other_resource = contact.resource
|
||||||
# Else this var is useless but harmless in next connect calls
|
# Else this var is useless but harmless in next connect calls
|
||||||
|
|
||||||
if contact.resource and NS_FILE in gajim.capscache[
|
if gajim.capscache.is_supported(contact, NS_FILE):
|
||||||
(contact.caps_hash_method, contact.caps_hash)].features:
|
|
||||||
send_file_menuitem.set_sensitive(True)
|
send_file_menuitem.set_sensitive(True)
|
||||||
send_file_menuitem.connect('activate',
|
send_file_menuitem.connect('activate',
|
||||||
self.on_send_file_menuitem_activate, contact, account)
|
self.on_send_file_menuitem_activate, contact, account)
|
||||||
|
@ -5479,8 +5476,8 @@ class RosterWindow:
|
||||||
item.connect('activate', action, [(c, account)], c.resource)
|
item.connect('activate', action, [(c, account)], c.resource)
|
||||||
else: # start_chat, execute_command, send_file
|
else: # start_chat, execute_command, send_file
|
||||||
item.connect('activate', action, c, account, c.resource)
|
item.connect('activate', action, c, account, c.resource)
|
||||||
if cap and cap not in gajim.capscache[
|
if cap and \
|
||||||
(c.caps_hash_method, c.caps_hash)].features:
|
not gajim.capscache.is_supported(c, cap):
|
||||||
item.set_sensitive(False)
|
item.set_sensitive(False)
|
||||||
return sub_menu
|
return sub_menu
|
||||||
|
|
||||||
|
@ -5516,8 +5513,7 @@ class RosterWindow:
|
||||||
invite_to_new_room_menuitem.set_submenu(self.build_resources_submenu(
|
invite_to_new_room_menuitem.set_submenu(self.build_resources_submenu(
|
||||||
contact_list, account, self.on_invite_to_new_room, cap=NS_MUC))
|
contact_list, account, self.on_invite_to_new_room, cap=NS_MUC))
|
||||||
else:
|
else:
|
||||||
if NS_MUC in gajim.capscache[(contact.caps_hash_method,
|
if gajim.capscache.is_supported(contact, NS_MUC):
|
||||||
contact.caps_hash)].features:
|
|
||||||
invite_menuitem.set_sensitive(True)
|
invite_menuitem.set_sensitive(True)
|
||||||
invite_to_new_room_menuitem.connect('activate',
|
invite_to_new_room_menuitem.connect('activate',
|
||||||
self.on_invite_to_new_room, list_)
|
self.on_invite_to_new_room, list_)
|
||||||
|
|
Loading…
Reference in New Issue