diff --git a/src/common/helpers.py b/src/common/helpers.py index a3fd5f5a513b4c6a7b431ee935def487a80095bb..a5574cc96debb494bb9540798138ef8476d60f4c 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -179,6 +179,25 @@ def convert_bytes(string): suffix = _('%s B') return suffix % unicode(bytes) + +def get_contact_dict_for_account(account): + ''' create a dict of jid, nick -> contact with all contacts of account. + Can be used for completion lists''' + contacts_dict = {} + for jid in gajim.contacts.get_jid_list(account): + contact = gajim.contacts.get_contact_with_highest_priority(account, + jid) + contacts_dict[jid] = contact + name = contact.name + if contacts_dict.has_key(name): + contact1 = contacts_dict[name] + del contacts_dict[name] + contacts_dict['%s (%s)' % (name, contact1.jid)] = contact1 + contacts_dict['%s (%s)' % (name, jid)] = contact + else: + contacts_dict[name] = contact + return contacts_dict + def get_uf_show(show, use_mnemonic = False): '''returns a userfriendly string for dnd/xa/chat and makes all strings translatable diff --git a/src/dialogs.py b/src/dialogs.py index e33c0c43abb3b2b41d7ce21ed19e5090188bf5c6..0a5f56f3960bcab8c42570b02c5fb6682278fda1 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -1000,18 +1000,8 @@ class NewChatDialog(InputDialog): self.completion_dict = {} liststore = gtkgui_helpers.get_completion_liststore(self.input_entry) + self.completion_dict = helpers.get_contact_dict_for_account(account) # add all contacts to the model - for jid in gajim.contacts.get_jid_list(account): - contact = gajim.contacts.get_contact_with_highest_priority(account, jid) - self.completion_dict[jid] = contact - name = contact.name - if self.completion_dict.has_key(name): - contact1 = self.completion_dict[name] - del self.completion_dict[name] - self.completion_dict['%s (%s)' % (name, contact1.jid)] = contact1 - self.completion_dict['%s (%s)' % (name, jid)] = contact - else: - self.completion_dict[name] = contact for jid in self.completion_dict.keys(): contact = self.completion_dict[jid] img = gajim.interface.roster.jabber_state_images['16'][contact.show] @@ -1252,29 +1242,17 @@ class SingleMessageWindow: self.subject = '' self.subject_entry.set_text(self.subject) - self.completion_dict = {} + if to == '': liststore = gtkgui_helpers.get_completion_liststore(self.to_entry) - # add all contacts to the model - for jid in gajim.contacts.get_jid_list(account): - contact = gajim.contacts.get_contact_with_highest_priority( - account, jid) - self.completion_dict[jid] = contact - name = contact.name - if self.completion_dict.has_key(name): - contact1 = self.completion_dict[name] - del self.completion_dict[name] - self.completion_dict['%s (%s)' % (name, contact1.jid)] = \ - contact1 - self.completion_dict['%s (%s)' % (name, jid)] = contact - else: - self.completion_dict[name] = contact + self.completion_dict = helpers.get_contact_dict_for_account(account) for jid in self.completion_dict.keys(): contact = self.completion_dict[jid] img = gajim.interface.roster.jabber_state_images['16'][ contact.show] liststore.append((img.get_pixbuf(), jid)) - + else: + self.completion_dict = {} self.xml.signal_autoconnect(self) if gajim.config.get('saveposition'):