Move method close to data.

gajim.contacts.contact_from_gc_contact(gc_contact) is now gc_contact.as_contact()
This commit is contained in:
Stephan Erb 2009-11-05 16:25:13 +01:00
parent dec25246df
commit 89b1c6a7df
4 changed files with 19 additions and 20 deletions

View File

@ -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()

View File

@ -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,

View File

@ -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)

View File

@ -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