From e3ba73be7497f072416916a30583d4a1b29e0d80 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 26 Jul 2006 12:01:14 +0000 Subject: [PATCH] if server doesn't support vcard, don't allow user to modify it. Fixes #2182 --- src/common/connection.py | 1 + src/common/connection_handlers.py | 14 +++++-- src/config.py | 5 +++ src/roster_window.py | 63 +++++++++++++++++++------------ 4 files changed, 54 insertions(+), 29 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 2cca81f59..59d843581 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -85,6 +85,7 @@ class Connection(ConnectionHandlers): self.retrycount = 0 self.jids_for_auto_auth = [] # list of jid to auto-authorize self.muc_jid = None + self.vcard_supported = True # END __init__ def build_user_nick(self, user_nick): diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 54435b6a0..07c7d647c 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -855,7 +855,10 @@ class ConnectionVcard: id = self.connection.getAnID() iq.setID(id) - self.awaiting_answers[id] = (VCARD_ARRIVED, jid) + j = jid + if not j: + j = gajim.get_jid_from_account(self.name) + self.awaiting_answers[id] = (VCARD_ARRIVED, j) if is_fake_jid: room_jid, nick = gajim.get_room_and_nick_from_fjid(jid) if not room_jid in self.room_jids: @@ -943,9 +946,12 @@ class ConnectionVcard: elif self.awaiting_answers[id][0] == VCARD_ARRIVED: # If vcard is empty, we send to the interface an empty vcard so that # it knows it arrived - if not iq_obj.getTag('vCard'): - jid = self.awaiting_answers[id][1] - our_jid = gajim.get_jid_from_account(self.name) + jid = self.awaiting_answers[id][1] + our_jid = gajim.get_jid_from_account(self.name) + if iq_obj.getType() == 'error' and jid == our_jid: + # our server doesn't support vcard + self.vcard_supported = False + if not iq_obj.getTag('vCard') or iq_obj.getType() == 'error': if jid and jid != our_jid: # Write an empty file self.save_vcard_to_hd(jid, '') diff --git a/src/config.py b/src/config.py index 3d0718466..ea6f7b065 100644 --- a/src/config.py +++ b/src/config.py @@ -1415,6 +1415,11 @@ class AccountModificationWindow: _('Without a connection, you can not edit your personal information.')) return + if not gajim.connections[self.account].vcard_supported: + dialogs.ErrorDialog(_("Your server doesn't support Vcard"), + _("Your server can't save your personal information.")) + return + gajim.interface.edit_own_details(self.account) def on_manage_proxies_button_clicked(self, widget): diff --git a/src/roster_window.py b/src/roster_window.py index 15e77a030..a93072dc2 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -767,8 +767,7 @@ class RosterWindow: add_sub_menu = gtk.Menu() disco_sub_menu = gtk.Menu() new_chat_sub_menu = gtk.Menu() - profile_avatar_sub_menu = gtk.Menu() - + for account in gajim.connections: if gajim.connections[account].connected <= 1: # if offline or connecting @@ -792,16 +791,12 @@ class RosterWindow: add_item = gtk.MenuItem(_('to %s account') % account, False) add_sub_menu.append(add_item) add_item.connect('activate', self.on_add_new_contact, account) - add_new_contact_menuitem.set_submenu(add_sub_menu) - add_sub_menu.show_all() # disco disco_item = gtk.MenuItem(_('using %s account') % account, False) disco_sub_menu.append(disco_item) disco_item.connect('activate', self.on_service_disco_menuitem_activate, account) - service_disco_menuitem.set_submenu(disco_sub_menu) - disco_sub_menu.show_all() # new chat new_chat_item = gtk.MenuItem(_('using account %s') % account, @@ -809,17 +804,13 @@ class RosterWindow: new_chat_sub_menu.append(new_chat_item) new_chat_item.connect('activate', self.on_new_chat_menuitem_activate, account) - new_chat_menuitem.set_submenu(new_chat_sub_menu) - new_chat_sub_menu.show_all() - - # profile, avatar - profile_avatar_item = gtk.MenuItem(_('of account %s') % account, - False) - profile_avatar_sub_menu.append(profile_avatar_item) - profile_avatar_item.connect('activate', - self.on_profile_avatar_menuitem_activate, account) - profile_avatar_menuitem.set_submenu(profile_avatar_sub_menu) - profile_avatar_sub_menu.show_all() + + add_new_contact_menuitem.set_submenu(add_sub_menu) + add_sub_menu.show_all() + service_disco_menuitem.set_submenu(disco_sub_menu) + disco_sub_menu.show_all() + new_chat_menuitem.set_submenu(new_chat_sub_menu) + new_chat_sub_menu.show_all() elif connected_accounts == 1: # user has only one account for account in gajim.connections: @@ -847,12 +838,6 @@ class RosterWindow: gtk.keysyms.n, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE) self.have_new_chat_accel = True - # profile, avatar - if not self.profile_avatar_menuitem_handler_id: - self.profile_avatar_menuitem_handler_id = \ - profile_avatar_menuitem.connect('activate', self.\ - on_profile_avatar_menuitem_activate, account) - break # No other account connected if connected_accounts == 0: @@ -861,17 +846,45 @@ class RosterWindow: join_gc_menuitem.set_sensitive(False) add_new_contact_menuitem.set_sensitive(False) service_disco_menuitem.set_sensitive(False) - profile_avatar_menuitem.set_sensitive(False) else: # we have one or more connected accounts new_chat_menuitem.set_sensitive(True) join_gc_menuitem.set_sensitive(True) add_new_contact_menuitem.set_sensitive(True) service_disco_menuitem.set_sensitive(True) - profile_avatar_menuitem.set_sensitive(True) # show the 'manage gc bookmarks' item newitem = gtk.SeparatorMenuItem() # separator gc_sub_menu.append(newitem) + connected_accounts_with_vcard = [] + for account in gajim.connections: + if gajim.connections[account].connected > 1 and \ + gajim.connections[account].vcard_supported: + connected_accounts_with_vcard.append(account) + if len(connected_accounts_with_vcard) > 1: + # 2 or more accounts? make submenus + profile_avatar_sub_menu = gtk.Menu() + for account in connected_accounts_with_vcard: + # profile, avatar + profile_avatar_item = gtk.MenuItem(_('of account %s') % account, + False) + profile_avatar_sub_menu.append(profile_avatar_item) + profile_avatar_item.connect('activate', + self.on_profile_avatar_menuitem_activate, account) + profile_avatar_menuitem.set_submenu(profile_avatar_sub_menu) + profile_avatar_sub_menu.show_all() + elif len(connected_accounts_with_vcard) == 1: # user has only one account + account = connected_accounts_with_vcard[0] + # profile, avatar + if not self.profile_avatar_menuitem_handler_id: + self.profile_avatar_menuitem_handler_id = \ + profile_avatar_menuitem.connect('activate', self.\ + on_profile_avatar_menuitem_activate, account) + + if len(connected_accounts_with_vcard) == 0: + profile_avatar_menuitem.set_sensitive(False) + else: + profile_avatar_menuitem.set_sensitive(True) + newitem = gtk.ImageMenuItem(_('Manage Bookmarks...')) img = gtk.image_new_from_stock(gtk.STOCK_PREFERENCES, gtk.ICON_SIZE_MENU)