From a3d6c3c43f20d7ee337e3f44bd58848a0396c1d4 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Thu, 22 Dec 2005 21:40:40 +0000 Subject: [PATCH] begin to use the new functions to handle contacts and gc_contacts --- src/chat.py | 10 +-- src/common/contacts.py | 128 ++++++++++++++++++++++++++--------- src/config.py | 16 ++--- src/conversation_textview.py | 4 +- src/dialogs.py | 34 +++++----- src/disco.py | 7 +- src/filetransfers_window.py | 4 +- src/gajim.py | 47 +++++++------ src/groupchat_window.py | 99 +++++++++++++-------------- 9 files changed, 208 insertions(+), 141 deletions(-) diff --git a/src/chat.py b/src/chat.py index f9ede73e0..6e8d8df01 100644 --- a/src/chat.py +++ b/src/chat.py @@ -298,9 +298,9 @@ class Chat: def get_message_type(self, jid): if self.widget_name == 'groupchat_window': return 'gc' - if gajim.contacts[self.account].has_key(jid): - return 'chat' - return 'pm' + if gajim.contacts.is_pm_from_jid(self.account, jid): + return 'pm' + return 'chat' def on_window_destroy(self, widget, kind): #kind is 'chats' or 'gc' '''clean gajim.interface.instances[self.account][kind]''' @@ -425,7 +425,7 @@ class Chat: if self.widget_name == 'tabbed_chat_window': jid = self.get_active_jid() - c = gajim.get_first_contact_instance_from_jid(self.account, jid) + c = gajim.contacts.get_first_contact_from_jid(self.account, jid) if _('not in the roster') in c.groups: # for add_to_roster_menuitem childs[5].show() childs[5].set_no_show_all(False) @@ -463,7 +463,7 @@ class Chat: childs[3].set_active(isactive) childs[3].set_property('sensitive', issensitive) # If we don't have resource, we can't do file transfert - c = gajim.get_first_contact_instance_from_jid(self.account, jid) + c = gajim.contacts.get_first_contact_from_jid(self.account, jid) if not c.resource: childs[2].set_sensitive(False) else: diff --git a/src/common/contacts.py b/src/common/contacts.py index 59fcce4ee..91cfb7ddb 100644 --- a/src/common/contacts.py +++ b/src/common/contacts.py @@ -129,37 +129,28 @@ class Contacts: # It was the last resource of this contact ? if not len(self._contacts[account][contact.jid]): self._contacts[account].remove(contact.jid) - - def create_gc_contact(self, room_jid='', nick='', show='', status='', - role='', affiliation='', jid=''): - return GC_Contact(room_jid, nick, show, status, role, affiliation, jid) - def add_gc_contact(self, account, gc_contact): - # No such account before ? - if not self._gc_contacts.has_key(account): - self._contacts[account] = {gc_contact.room_jid : {gc_contact.nick: \ - gc_contact}} + def remove_jid(self, account, jid): + '''Removes all contacts for a given jid''' + if not self._contacts.has_key(account): return - # No such room_jid before ? - if not self._gc_contacts[account].has_key(gc_contact.room_jid): - self._gc_contacts[account][gc_contact.room_jid] = {gc_contact.nick: \ - gc_contact} + if not self._contacts[account].has_key(contact.jid): return - self._gc_contacts[account][gc_contact.room_jid][gc_contact.nick] = \ - gc_contact + del self._contacts[account][jid] - def remove_gc_contact(self, account, gc_contact): - if not self._gc_contacts.has_key(account): - return - if not self._gc_contacts[account].has_key(gc_contact.room_jid): - return - if not self._gc_contacts[account][gc_contact.room_jid].has_key( - gc_contact.nick): - return - self._gc_contacts[account][gc_contact.room_jid].remove(gc_contact.nick) - # It was the last nick in room ? - if not len(self._gc_contacts[account][gc_contact.room_jid]): - self._gc_contacts[account].remove(gc_contact.room_jid) + def get_contact(self, account, jid, resource = None): + '''Returns the list of contact instances for this jid (one per resource) + if no resource is given + returns the contact instance for the given resource if it's given + or None if there is not''' + if jid in self._contacts[account]: + contacts = self._contacts[account][jid] + if not resource: + return contacts + for c in contacts: + if c.resource == resource: + return c + return None def is_subcontact(self, account, contact): if contact.jid in self._sub_contacts[account]: @@ -213,14 +204,87 @@ class Contacts: parrent_jid) return contact + def is_pm_from_jid(self, account, jid): + '''Returns True if the given jid is a private message jid''' + if jid in self._contacts[account]: + return False + return True + + def is_pm_from_contact(self, account, contact): + '''Returns True if the given contact is a private message contact''' + if isinstance(contact, Contcat): + return False + return True + + def get_jid_list(self, account): + return self._contacts[account].keys() + def contact_from_gc_contact(self, gc_contact): '''Create a Contact instance from a GC_Contact instance''' return Contact(jid = gc_contact.get_full_jid(), name = gc_contact.nick, groups = ['none'], show = gc_contact.show, status = gc_contact.status, sub = 'none') - def is_pm_from_jid(self, account, jid): - '''Returns True if the given jid is a private message jid''' - if jid in self._contacts[account]: - return False - return True + def create_gc_contact(self, room_jid='', nick='', show='', status='', + role='', affiliation='', jid=''): + return GC_Contact(room_jid, nick, show, status, role, affiliation, jid) + + def add_gc_contact(self, account, gc_contact): + # No such account before ? + if not self._gc_contacts.has_key(account): + self._contacts[account] = {gc_contact.room_jid : {gc_contact.nick: \ + gc_contact}} + return + # No such room_jid before ? + if not self._gc_contacts[account].has_key(gc_contact.room_jid): + self._gc_contacts[account][gc_contact.room_jid] = {gc_contact.nick: \ + gc_contact} + return + self._gc_contacts[account][gc_contact.room_jid][gc_contact.nick] = \ + gc_contact + + def remove_gc_contact(self, account, gc_contact): + if not self._gc_contacts.has_key(account): + return + if not self._gc_contacts[account].has_key(gc_contact.room_jid): + return + if not self._gc_contacts[account][gc_contact.room_jid].has_key( + gc_contact.nick): + return + self._gc_contacts[account][gc_contact.room_jid].remove(gc_contact.nick) + # It was the last nick in room ? + if not len(self._gc_contacts[account][gc_contact.room_jid]): + self._gc_contacts[account].remove(gc_contact.room_jid) + + def remove_room(self, account, room_jid): + if not self._gc_contacts.has_key(account): + return + if not self._gc_contacts[account].has_key(room_jid): + return + self._gc_contacts[account].remove(room_jid) + + def get_gc_contact(self, account, room_jid, nick): + if not self._gc_contacts.has_key(account): + return + if not self._gc_contacts[account].has_key(room_jid): + return + if not self._gc_contacts[account][room_jid].has_key(nick): + return + self._gc_contacts[account][room_jid].remove(nick) + + def get_gc_list(self, account): + if not self._gc_contacts.has_key(account): + return [] + return self._gc_contacts[account].keys() + + def get_nick_list(self, account, room_jid): + gc_list = self.get_gc_list(account) + if not room_jid in gc_list: + return [] + return self._gc_contacts[account][room_jid].keys() + + def get_gc_contact(self, account, room_jid, nick): + nick_list = self.get_nick_list(account, room_jid) + if not nick in nick_list: + return None + return self._gc_contacts[account][room_jid][nick] diff --git a/src/config.py b/src/config.py index 55fd883b6..13dfdc306 100644 --- a/src/config.py +++ b/src/config.py @@ -549,7 +549,7 @@ class PreferencesWindow: # open new tabbed chat windows for jid in jids: if kind == 'chats': - c = gajim.get_contact_instance_with_highest_priority(acct, jid) + c = gajim.contacts.get_contact_with_highest_priority(acct, jid) gajim.interface.roster.new_chat(c, acct) if kind == 'gc': gajim.interface.roster.new_room(jid, saved_var[jid]['nick'], acct) @@ -578,7 +578,7 @@ class PreferencesWindow: # open new tabbed chat windows for jid in jids: if kind == 'chats': - c = gajim.get_contact_instance_with_highest_priority(acct, jid) + c = gajim.contacts.get_contact_with_highest_priority(acct, jid) gajim.interface.roster.new_chat(c, acct) if kind == 'gc': gajim.interface.roster.new_room(jid, saved_var[jid]['nick'], acct) @@ -1268,8 +1268,6 @@ class AccountModificationWindow: gajim.allow_notifications[name] = \ gajim.allow_notifications[self.account] gajim.groups[name] = gajim.groups[self.account] - gajim.contacts[name] = gajim.contacts[self.account] - gajim.gc_contacts[name] = gajim.gc_contacts[self.account] gajim.gc_connected[name] = gajim.gc_connected[self.account] gajim.newly_added[name] = gajim.newly_added[self.account] gajim.to_be_removed[name] = gajim.to_be_removed[self.account] @@ -1281,6 +1279,8 @@ class AccountModificationWindow: gajim.status_before_autoaway[self.account] gajim.events_for_ui[name] = gajim.events_for_ui[self.account] + gajim.contacts.change_account_name(self.account, name) + #upgrade account variable in opened windows for kind in ('infos', 'disco', 'chats', 'gc', 'gc_config'): for j in gajim.interface.instances[name][kind]: @@ -1297,8 +1297,6 @@ class AccountModificationWindow: del gajim.nicks[self.account] del gajim.allow_notifications[self.account] del gajim.groups[self.account] - del gajim.contacts[self.account] - del gajim.gc_contacts[self.account] del gajim.gc_connected[self.account] del gajim.newly_added[self.account] del gajim.to_be_removed[self.account] @@ -2195,8 +2193,7 @@ class RemoveAccountWindow: del gajim.nicks[self.account] del gajim.allow_notifications[self.account] del gajim.groups[self.account] - del gajim.contacts[self.account] - del gajim.gc_contacts[self.account] + gajim.contacts.remove_account(self.account) del gajim.gc_connected[self.account] del gajim.to_be_removed[self.account] del gajim.newly_added[self.account] @@ -2737,8 +2734,7 @@ _('You can set advanced account options by pressing Advanced button, or later by gajim.awaiting_events[self.account] = {} gajim.connections[self.account].connected = 0 gajim.groups[self.account] = {} - gajim.contacts[self.account] = {} - gajim.gc_contacts[self.account] = {} + gajim.contacts.add_account(self.account) gajim.gc_connected[self.account] = {} gajim.newly_added[self.account] = [] gajim.to_be_removed[self.account] = [] diff --git a/src/conversation_textview.py b/src/conversation_textview.py index 8fe28418c..e2a14fe6a 100644 --- a/src/conversation_textview.py +++ b/src/conversation_textview.py @@ -370,8 +370,8 @@ class ConversationTextview(gtk.TextView): self.on_join_group_chat_menuitem_activate, text) allow_add = False - if gajim.contacts[self.account].has_key(text): - c = gajim.contacts[self.account][text][0] + c = gajim.contacts.get_first_contact_from_jid(self.account, text) + if c and not gajim.contacts.is_pm_from_contact(self.account, c): if _('not in the roster') in c.groups: allow_add = True else: # he or she's not at all in the account contacts diff --git a/src/dialogs.py b/src/dialogs.py index dc68f922c..19d49a42f 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -303,10 +303,10 @@ _('Please fill in the data of the contact you want to add in account %s') %accou liststore.append(['Jabber', '']) self.agents = ['Jabber'] jid_agents = [] - for j in gajim.contacts[account]: - user = gajim.contacts[account][j][0] - if _('Transports') in user.groups and user.show != 'offline' and \ - user.show != 'error': + for j in gajim.contacts.get_jid_list(account): + contact = gajim.contacts.get_first_contact_from_jid(account, j) + if _('Transports') in contact.groups and contact.show != 'offline' and\ + contact.show != 'error': jid_agents.append(j) for a in jid_agents: if a.find('aim') > -1: @@ -381,8 +381,9 @@ _('Please fill in the data of the contact you want to add in account %s') %accou return # Check if jid is already in roster - if jid in gajim.contacts[self.account] and _('not in the roster') not in \ - gajim.contacts[self.account][jid][0].groups: + if jid in gajim.contacts.get_jid_list(self.account) and \ + _('not in the roster') not in \ + gajim.contacts.get_first_contact_from_jid(self.account, jid).groups: ErrorDialog(_('Contact already in roster'), _('This contact is already listed in your roster.')).get_response() return @@ -628,7 +629,7 @@ class SubscriptionRequestWindow: '''accept the request''' gajim.connections[self.account].send_authorization(self.jid) self.window.destroy() - if not gajim.contacts[self.account].has_key(self.jid): + if self.jid not in gajim.contacts.get_jid_list(self.account): AddNewContactWindow(self.account, self.jid) def on_contact_info_button_clicked(self, widget): @@ -825,8 +826,8 @@ class PopupNotificationWindow: event_type_label.set_markup('' + event_type + '') - if self.jid in gajim.contacts[account]: - txt = gajim.contacts[account][self.jid][0].name + if self.jid in gajim.contacts.get_jid_list(account): + txt = gajim.contacts.get_first_contact_from_jid(account, self.jid).name else: txt = self.jid @@ -866,7 +867,8 @@ class PopupNotificationWindow: close_button.modify_bg(gtk.STATE_NORMAL, bg_color) eventbox.modify_bg(gtk.STATE_NORMAL, bg_color) event_description_label.set_text(txt) - elif event_type in (_('File Transfer Completed'), _('File Transfer Stopped')): + elif event_type in (_('File Transfer Completed'), + _('File Transfer Stopped')): bg_color = gtk.gdk.color_parse('yellowgreen') close_button.modify_bg(gtk.STATE_NORMAL, bg_color) eventbox.modify_bg(gtk.STATE_NORMAL, bg_color) @@ -874,8 +876,8 @@ class PopupNotificationWindow: if file_props['type'] == 'r': # get the name of the sender, as it is in the roster sender = unicode(file_props['sender']).split('/')[0] - name = gajim.get_first_contact_instance_from_jid( - account, sender).name + name = gajim.contacts.get_first_contact_from_jid(account, + sender).name txt = _('From %s') % name else: receiver = file_props['receiver'] @@ -883,8 +885,8 @@ class PopupNotificationWindow: receiver = receiver.jid receiver = receiver.split('/')[0] # get the name of the contact, as it is in the roster - name = gajim.get_first_contact_instance_from_jid( - account, receiver).name + name = gajim.contacts.get_first_contact_from_jid(account, + receiver).name txt = _('To %s') % name else: txt = '' @@ -928,8 +930,8 @@ class PopupNotificationWindow: return # use Contact class, new_chat expects it that way # is it in the roster? - if gajim.contacts[self.account].has_key(self.jid): - contact = gajim.get_contact_instance_with_highest_priority( + if self.jid in gajim.contacts.get_jid_list(self.account): + contact = gajim.contacts.get_contact_with_highest_priority( self.account, self.jid) else: keyID = '' diff --git a/src/disco.py b/src/disco.py index f21ab66c8..81823d254 100644 --- a/src/disco.py +++ b/src/disco.py @@ -1193,9 +1193,10 @@ class ToplevelAgentBrowser(AgentBrowser): if self.register_button and xmpp.NS_REGISTER in features: # We can register this agent registered_transports = [] - contacts = gajim.contacts[self.account] - for j in contacts: - if _('Transports') in contacts[j][0].groups: + jid_list = gajim.contacts.get_jid_list(self.account) + for j in jid_list: + contact = gajim.contacts.get_first_contact_from_jid(self.account, j) + if _('Transports') in contact.groups: registered_transports.append(j) if jid in registered_transports: self.register_button.set_label(_('_Edit')) diff --git a/src/filetransfers_window.py b/src/filetransfers_window.py index 152cadcb7..540c0f335 100644 --- a/src/filetransfers_window.py +++ b/src/filetransfers_window.py @@ -177,7 +177,7 @@ class FileTransfersWindow: helpers.convert_bytes(file_props['size']) if file_props['type'] == 'r': jid = unicode(file_props['sender']).split('/')[0] - sender_name = gajim.get_first_contact_instance_from_jid( + sender_name = gajim.contacts.get_first_contact_from_jid( file_props['tt_account'], jid).name sender = gtkgui_helpers.escape_for_pango_markup(sender_name) else: @@ -187,7 +187,7 @@ class FileTransfersWindow: sectext += '\n\t' +_('Recipient: ') if file_props['type'] == 's': jid = unicode(file_props['receiver']).split('/')[0] - receiver_name = gajim.get_first_contact_instance_from_jid( + receiver_name = gajim.contacts.get_first_contact_from_jid( file_props['tt_account'], jid).name recipient = gtkgui_helpers.escape_for_pango_markup(receiver_name) else: diff --git a/src/gajim.py b/src/gajim.py index f03b9ebeb..277cd536a 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -276,8 +276,10 @@ class Interface: else: ji = jid # Update contact - if gajim.contacts[account].has_key(ji): - lcontact = gajim.contacts[account][ji] + + jid_list = gajim.contacts.het_jid_list(account) + if ji in jid_list: + lcontact = gajim.contacts.get_contacts_from_jid(account, ji) contact1 = None resources = [] for c in lcontact: @@ -291,7 +293,7 @@ class Interface: if old_show == new_show and contact1.status == array[2]: #no change return else: - contact1 = gajim.contacts[account][ji][0] + contact1 = gajim.contacts.get_first_contact_from_jid(account, ji) if contact1.show in statuss: old_show = statuss.index(contact1.show) if (resources != [''] and (len(lcontact) != 1 or @@ -324,13 +326,13 @@ class Interface: contact1.keyID = keyID if jid.find('@') <= 0: # It must be an agent - if gajim.contacts[account].has_key(ji): + if ji in jid_list: # Update existing iter self.roster.draw_contact(ji, account) elif jid == gajim.get_jid_from_account(account): # It's another of our resources. We don't need to see that! return - elif gajim.contacts[account].has_key(ji): + elif ji in jid_list: # It isn't an agent # reset chatstate if needed: # (when contact signs out or has errors) @@ -418,7 +420,7 @@ class Interface: return # Handle chat states - contact = gajim.get_first_contact_instance_from_jid(account, jid) + contact = gajim.contacts.get_first_contact_from_jid(account, jid) if self.instances[account]['chats'].has_key(jid): chat_win = self.instances[account]['chats'][jid] if chatstate is not None: # he or she sent us reply, so he supports jep85 @@ -520,8 +522,8 @@ class Interface: def handle_event_subscribed(self, account, array): #('SUBSCRIBED', account, (jid, resource)) jid = array[0] - if gajim.contacts[account].has_key(jid): - c = gajim.get_first_contact_instance_from_jid(account, jid) + if jid in gajim.contacts.get_jid_list(account): + c = gajim.contacts.get_first_contact_from_jid(account, jid) c.resource = array[1] self.roster.remove_contact(c, account) if _('not in the roster') in c.groups: @@ -541,7 +543,7 @@ class Interface: contact1 = gajim.contacts.create_contact(jid = jid, name = name, groups = [_('General')], show = 'online', status = 'online', ask = 'to', resource = array[1], keyID = keyID) - gajim.contacts[account][jid] = [contact1] + gajim.contacts.add_contact(account, contact1) self.roster.add_contact_to_roster(jid, account) dialogs.InformationDialog(_('Authorization accepted'), _('The contact "%s" has authorized you to see his or her status.') @@ -748,12 +750,12 @@ class Interface: def handle_event_roster_info(self, account, array): #('ROSTER_INFO', account, (jid, name, sub, ask, groups)) jid = array[0] - if not gajim.contacts[account].has_key(jid): + if not jid in gajim.contacts.get_jid_list(account): return - contacts = gajim.contacts[account][jid] + contacts = gajim.contacts.get_contacts_from_jid(account, jid) if not (array[2] or array[3]): self.roster.remove_contact(contacts[0], account) - del gajim.contacts[account][jid] + gajim.contacts.remove_jid(account, jid) #FIXME if it was the only one in its group, remove the group return for contact in contacts: @@ -860,10 +862,10 @@ class Interface: def handle_event_file_request(self, account, array): jid = array[0] - if not gajim.contacts[account].has_key(jid): + if jid not in gajim.contacts.get_jid_list(account): return file_props = array[1] - contact = gajim.contacts[account][jid][0] + contact = gajim.contacts.get_first_contact_from_jid(account, jid) if gajim.popup_window(account): self.instances['file_transfers'].show_file_request(account, contact, @@ -1244,20 +1246,22 @@ class Interface: if wins['chats'].has_key(jid): w = wins['chats'][jid] else: - self.roster.new_chat(gajim.contacts[account][jid][0], account) + contact = gajim.contacts.get_first_contact_from_jid(account, jid) + self.roster.new_chat(contact, account) w = wins['chats'][jid] elif typ == 'pm': if wins['chats'].has_key(jid): w = wins['chats'][jid] else: room_jid, nick = jid.split('/', 1) - if gajim.gc_contacts[account][room_jid].has_key(nick): - show = gajim.gc_contacts[account][room_jid][nick].show + gc_contact = gajim.contacts.get_gc_contact(account, room_jid, nick) + if gc_contact: + show = gc_contact.show else: show = 'offline' - gc_c = gajim.contacts.create_gc_contact(room_jid = room_jid, - nick = nick, show = show) - c = gajim.contacts.contact_from_gc_contct(c) + gc_contact = gajim.contacts.create_gc_contact(room_jid = room_jid, + nick = nick, show = show) + c = gajim.contacts.contact_from_gc_contct(gc_contact) self.roster.new_chat(c, account) w = wins['chats'][jid] elif typ in ('normal', 'file-request', 'file-request-error', @@ -1338,9 +1342,8 @@ class Interface: for a in gajim.connections: self.instances[a] = {'infos': {}, 'disco': {}, 'chats': {}, 'gc': {}, 'gc_config': {}} - gajim.contacts[a] = {} + gajim.contacts.add_account(a) gajim.groups[a] = {} - gajim.gc_contacts[a] = {} gajim.gc_connected[a] = {} gajim.newly_added[a] = [] gajim.to_be_removed[a] = [] diff --git a/src/groupchat_window.py b/src/groupchat_window.py index fe0247830..477f5cd62 100644 --- a/src/groupchat_window.py +++ b/src/groupchat_window.py @@ -120,8 +120,6 @@ class GroupchatWindow(chat.Chat): 'nick': self.nicks[room_jid], 'model': self.list_treeview[room_jid].get_model(), 'subject': self.subjects[room_jid], - 'contacts': gajim.gc_contacts[self.account][room_jid], - 'connected': gajim.gc_connected[self.account][room_jid], } def load_var(self, room_jid, var): @@ -131,8 +129,6 @@ class GroupchatWindow(chat.Chat): self.list_treeview[room_jid].expand_all() self.set_subject(room_jid, var['subject']) self.subjects[room_jid] = var['subject'] - gajim.gc_contacts[self.account][room_jid] = var['contacts'] - gajim.gc_connected[self.account][room_jid] = var['connected'] if gajim.gc_connected[self.account][room_jid]: self.got_connected(room_jid) @@ -193,7 +189,7 @@ class GroupchatWindow(chat.Chat): def on_groupchat_window_destroy(self, widget): chat.Chat.on_window_destroy(self, widget, 'gc') for room_jid in self.xmls: - del gajim.gc_contacts[self.account][room_jid] + gajim.contacts.remove_room(self.account, room_jid) del gajim.gc_connected[self.account][room_jid] def on_groupchat_window_focus_in_event(self, widget, event): @@ -346,18 +342,15 @@ class GroupchatWindow(chat.Chat): fin = True return None - def get_nick_list(self, room_jid): - '''get nicks of contacts in a room''' - return gajim.gc_contacts[self.account][room_jid].keys() - def remove_contact(self, room_jid, nick): '''Remove a user from the contacts_list''' model = self.list_treeview[room_jid].get_model() iter = self.get_contact_iter(room_jid, nick) if not iter: return - if gajim.gc_contacts[self.account][room_jid].has_key(nick): - del gajim.gc_contacts[self.account][room_jid][nick] + gc_contact = gajim.contacts.get_gc_contact(self.account, room_jid, nick) + if gc_contact: + gajim.contacts.remove_gc_contact(self.account, gc_contact) parent_iter = model.iter_parent(iter) model.remove(iter) if model.iter_n_children(parent_iter) == 0: @@ -365,7 +358,6 @@ class GroupchatWindow(chat.Chat): def add_contact_to_roster(self, room_jid, nick, show, role, jid, affiliation, status): model = self.list_treeview[room_jid].get_model() - resource = '' role_name = helpers.get_uf_role(role, plural = True) if jid: @@ -381,11 +373,11 @@ class GroupchatWindow(chat.Chat): (gajim.interface.roster.jabber_state_images['16']['closed'], 'role', role, '%s' % role_name)) iter = model.append(role_iter, (None, 'contact', nick, name)) - if not gajim.gc_contacts[self.account][room_jid].has_key(nick): - gajim.gc_contacts[self.account][room_jid][nick] = \ - gajim.contacts.create_gc_contact(room_jid = room_jid, nick = nick, - show = show, status = status, role = role, + if not nick in gajim.contacts.get_nick_list(self.account, room_jid, nick): + gc_contact = gajim.contacts.create_gc_contact(room_jid = room_jid, + nick = nick, show = show, status = status, role = role, affiliation = affiliation, jid = jid) + gajim.contacts.add_gc_contact(self.account, gc_contact) self.draw_contact(room_jid, nick) if nick == self.nicks[room_jid]: # we became online self.got_connected(room_jid) @@ -398,15 +390,15 @@ class GroupchatWindow(chat.Chat): if not iter: return model = self.list_treeview[room_jid].get_model() - contact = gajim.gc_contacts[self.account][room_jid][nick] + gc_contact = gajim.contacts.get_gc_contact(self.account, room_jid, nick) state_images = gajim.interface.roster.jabber_state_images['16'] if gajim.awaiting_events[self.account].has_key(room_jid + '/' + nick): image = state_images['message'] else: - image = state_images[contact.show] + image = state_images[gc_contact.show] - name = gtkgui_helpers.escape_for_pango_markup(contact.name) - status = contact.status + name = gtkgui_helpers.escape_for_pango_markup(gc_contact.name) + status = gc_contact.status # add status msg, if not empty, under contact name in the treeview if status and gajim.config.get('show_status_msgs_in_roster'): status = status.strip() @@ -425,13 +417,11 @@ class GroupchatWindow(chat.Chat): def draw_roster(self, room_jid): model = self.list_treeview[room_jid].get_model() model.clear() - for nick in gajim.gc_contacts[self.account][room_jid]: - contact = gajim.gc_contacts[self.account][room_jid][nick] - fjid = contact.jid - if contact.resource: - fjid += '/' + contact.resource - self.add_contact_to_roster(room_jid, nick, contact.show, contact.role, - fjid, contact.affiliation, contact.status) + for nick in gajim.contact.get_nick_list(self.account, room_jid)0: + gc_contact = gajim.contact.get_gc_contact(self.account, room_jid, nick) + self.add_contact_to_roster(room_jid, nick, gc_contact.show, + gc_contact.role, gc_contact.jid, gc_contact.affiliation, + gc_contact.status) def get_role(self, room_jid, nick): if gajim.gc_contacts[self.account][room_jid].has_key(nick): @@ -487,7 +477,7 @@ class GroupchatWindow(chat.Chat): room_jid + '/' + nick): self.remove_contact(room_jid, nick) else: - c = gajim.gc_contacts[self.account][room_jid][nick] + c = gajim.contacts.get_gc_contact(self.account, room_jid, nick) c.show = show c.status = status if nick == self.nicks[room_jid] and statusCode != '303': # We became offline @@ -504,7 +494,7 @@ class GroupchatWindow(chat.Chat): self.add_contact_to_roster(room_jid, nick, show, role, jid, affiliation, status) else: - c = gajim.gc_contacts[self.account][room_jid][nick] + c = gajim.contacts.get_gc_contact(self.account, room_jid, nick) if c.show == show and c.status == status and \ c.affiliation == affiliation: #no change return @@ -544,7 +534,7 @@ class GroupchatWindow(chat.Chat): # for room_jid & number of unread private msgs with each contact # that we have nb = 0 - for nick in self.get_nick_list(room_jid): + for nick in gajim.contacts.get_nick_list(self.account, room_jid): fjid = room_jid + '/' + nick if gajim.awaiting_events[self.account].has_key(fjid): # gc can only have messages as event @@ -686,7 +676,8 @@ class GroupchatWindow(chat.Chat): self.nick_hits[room_jid].pop(0) else: self.nick_hits[room_jid] = [] # clear the hit list - list_nick = self.get_nick_list(room_jid) + list_nick = gajim.contacts.get_nick_list(self.account, + room_jid) for nick in list_nick: if nick.lower().startswith(begin.lower()): # the word is the begining of a nick self.nick_hits[room_jid].append(nick) @@ -804,7 +795,7 @@ class GroupchatWindow(chat.Chat): # example: /query foo if len(message_array): nick = message_array.pop(0) - nicks = self.get_nick_list(room_jid) + nicks = gajim.contacts.get_nick_list(self.account, room_jid) if nick in nicks: self.on_send_pm(nick = nick) self.clear(message_textview) @@ -819,7 +810,8 @@ class GroupchatWindow(chat.Chat): if len(message_array): message_array = message_array[0].split() nick = message_array.pop(0) - room_nicks = self.get_nick_list(room_jid) + room_nicks = gajim.contacts.get_nick_list(self.account, + room_jid) if nick in room_nicks: privmsg = ' '.join(message_array) self.on_send_pm(nick=nick, msg=privmsg) @@ -901,7 +893,8 @@ class GroupchatWindow(chat.Chat): if len(message_array): message_array = message_array[0].split() nick = message_array.pop(0) - room_nicks = self.get_nick_list(room_jid) + room_nicks = gajim.contacts.get_nick_list(self.account, + room_jid) reason = ' '.join(message_array) if nick in room_nicks: ban_jid = gajim.construct_fjid(room_jid, nick) @@ -921,7 +914,8 @@ class GroupchatWindow(chat.Chat): if len(message_array): message_array = message_array[0].split() nick = message_array.pop(0) - room_nicks = self.get_nick_list(room_jid) + room_nicks = gajim.contacts.get_nick_list(self.account, + room_jid) reason = ' '.join(message_array) if nick in room_nicks: gajim.connections[self.account].gc_set_role(room_jid, nick, @@ -1159,7 +1153,7 @@ current room topic.') % command, room_jid) def on_info(self, widget, room_jid, nick): '''Call vcard_information_window class to display user's information''' - c = gajim.gc_contacts[self.account][room_jid][nick] + c = gajim.contacts.get_gc_contact(self.account, room_jid, nick) if c.jid and c.resource: # on GC, we know resource only if we're mod and up jid = c.jid @@ -1190,7 +1184,7 @@ current room topic.') % command, room_jid) room_jid = self.get_active_jid() fjid = gajim.construct_fjid(room_jid, nick) # 'fake' jid if not gajim.interface.instances[self.account]['chats'].has_key(fjid): - gc_c = gajim.gc_contacts[self.account][room_jid][nick] + gc_c = gajim.contacts.get_gc_contact(self.account, room_jid, nick) gajim.interface.roster.new_chat(gc_c, self.account) #make active here in case we need to send a message @@ -1234,15 +1228,15 @@ current room topic.') % command, room_jid) '''Make contact's popup menu''' model = self.list_treeview[room_jid].get_model() nick = model[iter][C_NICK].decode('utf-8') - c = gajim.gc_contacts[self.account][room_jid][nick] + c = gajim.contacts.get_gc_contact(self.account, room_jid, nick) jid = c.jid target_affiliation = c.affiliation target_role = c.role # looking for user's affiliation and role user_nick = self.nicks[room_jid] - user_affiliation = gajim.gc_contacts[self.account][room_jid][user_nick].\ - affiliation + user_affiliation = gajim.contacts.get_gc_contact(self.account, room_jid, + user_nick].affiliation user_role = self.get_role(room_jid, user_nick) # making menu from glade @@ -1333,8 +1327,8 @@ current room topic.') % command, room_jid) room_jid, show='offline', status=reason) del self.nicks[room_jid] # They can already be removed by the destroy function - if gajim.gc_contacts[self.account].has_key(room_jid): - del gajim.gc_contacts[self.account][room_jid] + if room_jid in gajim.contacts.get_room_list(self.account): + gajim.contacts.remove_room(self.account, room_jid) del gajim.gc_connected[self.account][room_jid] del self.list_treeview[room_jid] del self.subjects[room_jid] @@ -1350,7 +1344,11 @@ current room topic.') % command, room_jid) def got_disconnected(self, room_jid): model = self.list_treeview[room_jid].get_model() model.clear() - gajim.gc_contacts[self.account][room_jid] = {} + nick_list = gajim.contacts.get_nick_list(self.account, room_jid) + for nick in nick_list: + gc_contact = gajim.contacts.get_gc_contact(self.account, room_jid, + nick) + gajim.contacts.remove_gc_contact(self.account, gc_contact) gajim.gc_connected[self.account][room_jid] = False message_textview = self.message_textviews[room_jid] message_textview.set_sensitive(False) @@ -1518,7 +1516,7 @@ current room topic.') % command, room_jid) gajim.interface.systray.add_jid(fjid, self.account, 'pm') self.show_title() else: - gc_c = gajim.gc_contacts[self.account][room_jid][nick] + gc_c = gajim.contacts.get_gc_contact(self.account, room_jid, nick) gajim.interface.roster.new_chat(gc_c, self.account) # Scroll to line self.list_treeview[room_jid].expand_row(path[0:1], False) @@ -1553,7 +1551,8 @@ current room topic.') % command, room_jid) self.tooltip.id = row nick = model[iter][C_NICK].decode('utf-8') self.tooltip.timeout = gobject.timeout_add(500, - self.show_tooltip, gajim.gc_contacts[account][room_jid][nick]) + self.show_tooltip, gajim.contacts.get_gc_contact(account, + room_jid, nick)) def on_list_treeview_leave_notify_event(self, widget, event): model = widget.get_model() @@ -1627,7 +1626,8 @@ current room topic.') % command, room_jid) nick = model[iter][C_NICK].decode('utf-8') fjid = gajim.construct_fjid(room_jid, nick) if not gajim.interface.instances[self.account]['chats'].has_key(fjid): - gc_c = gajim.gc_contacts[self.account][room_jid][nick] + gc_c = gajim.contacts.get_gc_contact(self.account, room_jid, + nick) gajim.interface.roster.new_chat(gc_c, self.account) gajim.interface.instances[self.account]['chats'][fjid].set_active_tab(fjid) gajim.interface.instances[self.account]['chats'][fjid].window.present() @@ -1644,7 +1644,8 @@ current room topic.') % command, room_jid) model = widget.get_model() iter = model.get_iter(path) nick = model[iter][C_NICK].decode('utf-8') - if not nick in gajim.gc_contacts[self.account][room_jid]: #it's a group + if not nick in gajim.get_nick_list(self.account, room_jid): + #it's a group if x < 20: # first cell in 1st column (the arrow SINGLE clicked) if (widget.row_expanded(path)): widget.collapse_row(path) @@ -1669,9 +1670,9 @@ current room topic.') % command, room_jid) nick = model[iter][C_NICK].decode('utf-8') jid = gajim.construct_fjid(room_jid, nick) if not gajim.interface.instances[self.account]['chats'].has_key(jid): - gc_c = gajim.gc_contacts[self.account][room_jid][nick] + gc_c = gajim.contacts.get_gc_contact(self.account, room_jid, nick) gajim.interface.roster.new_chat(gc_c, self.account) - jid = contact.jid + jid = gc_c.jid gajim.interface.instances[self.account]['chats'][jid].set_active_tab(jid) gajim.interface.instances[self.account]['chats'][jid].window.present()