From 89b1c6a7df3558b1575245f30168e2222a8e5411 Mon Sep 17 00:00:00 2001 From: Stephan Erb Date: Thu, 5 Nov 2009 16:25:13 +0100 Subject: [PATCH] Move method close to data. gajim.contacts.contact_from_gc_contact(gc_contact) is now gc_contact.as_contact() --- src/chat_control.py | 2 +- src/common/contacts.py | 13 ++++++------- src/groupchat_control.py | 14 +++++++------- src/gui_interface.py | 10 +++++----- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/chat_control.py b/src/chat_control.py index 93aa01576..da028f618 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -2750,7 +2750,7 @@ class ChatControl(ChatControlBase): contact = gajim.contacts.get_contact_with_highest_priority( self.account, self.contact.jid) if isinstance(contact, GC_Contact): - contact = gajim.contacts.contact_from_gc_contact(contact) + contact = contact.as_contact() if contact: self.contact = contact self.draw_banner() diff --git a/src/common/contacts.py b/src/common/contacts.py index ff42163a3..35a9f39b5 100644 --- a/src/common/contacts.py +++ b/src/common/contacts.py @@ -208,6 +208,12 @@ class GC_Contact(CommonContact): def get_shown_name(self): return self.name + def as_contact(self): + '''Create a Contact instance from this GC_Contact instance''' + return Contact(jid=self.get_full_jid(), account=self.account, + resource=self.resource, name=self.name, groups=[], show=self.show, + status=self.status, sub='none', client_caps=self.client_caps) + class Contacts: '''Information concerning all contacts and groupchat contacts''' @@ -629,13 +635,6 @@ class Contacts: 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''' - jid = gc_contact.get_full_jid() - return Contact(jid=jid, account=gc_contact.account, resource=gc_contact.resource, - name=gc_contact.name, groups=[], show=gc_contact.show, - status=gc_contact.status, sub='none', client_caps=gc_contact.client_caps) - def create_gc_contact(self, room_jid, account, name='', show='', status='', role='', affiliation='', jid='', resource=''): return GC_Contact(room_jid, name, show, status, role, affiliation, jid, diff --git a/src/groupchat_control.py b/src/groupchat_control.py index 24097300f..e71eefe32 100644 --- a/src/groupchat_control.py +++ b/src/groupchat_control.py @@ -176,7 +176,7 @@ class PrivateChatControl(ChatControl): ChatControl.update_ui(self) def update_contact(self): - self.contact = gajim.contacts.contact_from_gc_contact(self.gc_contact) + self.contact = self.gc_contact.as_contact() def begin_e2e_negotiation(self): self.no_autonegotiation = True @@ -2254,14 +2254,14 @@ class GroupchatControl(ChatControlBase): def on_info(self, widget, nick): '''Call vcard_information_window class to display user's information''' - c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick) - c2 = gajim.contacts.contact_from_gc_contact(c) - if c2.jid in gajim.interface.instances[self.account]['infos']: - gajim.interface.instances[self.account]['infos'][c2.jid].window.\ + gc_contact = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick) + contact = gc_contact.as_contact() + if contact.jid in gajim.interface.instances[self.account]['infos']: + gajim.interface.instances[self.account]['infos'][contact.jid].window.\ present() else: - gajim.interface.instances[self.account]['infos'][c2.jid] = \ - vcard.VcardWindow(c2, self.account, c) + gajim.interface.instances[self.account]['infos'][contact.jid] = \ + vcard.VcardWindow(contact, self.account, gc_contact) def on_history(self, widget, nick): jid = gajim.construct_fjid(self.room_jid, nick) diff --git a/src/gui_interface.py b/src/gui_interface.py index 8a153405d..179a9c02b 100644 --- a/src/gui_interface.py +++ b/src/gui_interface.py @@ -533,8 +533,8 @@ class Interface: show = model[iter_][3] else: show = 'offline' - gc_c = gajim.contacts.create_gc_contact(room_jid = jid, - name = nick, show = show) + gc_c = gajim.contacts.create_gc_contact(room_jid=jid, account=account, + name=nick, show=show) ctrl = self.new_private_chat(gc_c, account, session) ctrl.print_conversation(_('Error %(code)s: %(msg)s') % { @@ -890,7 +890,7 @@ class Interface: ctrl.print_conversation(_('%(nick)s is now known as %(new_nick)s') \ % {'nick': nick, 'new_nick': new_nick}, 'status') gc_c = gajim.contacts.get_gc_contact(account, room_jid, new_nick) - c = gajim.contacts.contact_from_gc_contact(gc_c) + c = gc_c.as_contact() ctrl.gc_contact = gc_c ctrl.contact = c if ctrl.session: @@ -2223,7 +2223,7 @@ class Interface: else: show = 'offline' gc_contact = gajim.contacts.create_gc_contact( - room_jid = room_jid, name = nick, show = show) + room_jid=room_jid, account=account, name=nick, show=show) if not session: session = gajim.connections[account].make_new_session( @@ -2600,7 +2600,7 @@ class Interface: mw.new_tab(gc_control) def new_private_chat(self, gc_contact, account, session=None): - contact = gajim.contacts.contact_from_gc_contact(gc_contact) + contact = gc_contact.as_contact() type_ = message_control.TYPE_PM fjid = gc_contact.room_jid + '/' + gc_contact.name