create Contact instances with the new functions

This commit is contained in:
Yann Leboulanger 2005-12-21 13:00:56 +00:00
parent f67351a263
commit 0af7e48bf1
3 changed files with 46 additions and 58 deletions

View File

@ -39,7 +39,6 @@ import gtkgui_helpers
import history_window import history_window
import tooltips import tooltips
from gajim import Contact
from common import gajim from common import gajim
from common import helpers from common import helpers
from gettext import ngettext from gettext import ngettext
@ -370,12 +369,9 @@ class GroupchatWindow(chat.Chat):
role_name = helpers.get_uf_role(role, plural = True) role_name = helpers.get_uf_role(role, plural = True)
if jid: if jid:
jids = jid.split('/', 1) jid = jid.split('/', 1)[0]
j = jids[0]
if len(jids) > 1:
resource = jids[1]
else: else:
j = '' jid = ''
name = nick name = nick
@ -387,8 +383,9 @@ class GroupchatWindow(chat.Chat):
iter = model.append(role_iter, (None, 'contact', nick, name)) iter = model.append(role_iter, (None, 'contact', nick, name))
if not gajim.gc_contacts[self.account][room_jid].has_key(nick): if not gajim.gc_contacts[self.account][room_jid].has_key(nick):
gajim.gc_contacts[self.account][room_jid][nick] = \ gajim.gc_contacts[self.account][room_jid][nick] = \
Contact(jid = j, name = nick, show = show, resource = resource, gajim.contacts.create_gc_contact(room_jid = room_jid, nick = nick,
role = role, affiliation = affiliation, status = status) show = show, status = status, role = role,
affiliation = affiliation, jid = jid)
self.draw_contact(room_jid, nick) self.draw_contact(room_jid, nick)
if nick == self.nicks[room_jid]: # we became online if nick == self.nicks[room_jid]: # we became online
self.got_connected(room_jid) self.got_connected(room_jid)
@ -1174,9 +1171,7 @@ current room topic.') % command, room_jid)
gajim.interface.instances[self.account]['infos'][jid].window.present() gajim.interface.instances[self.account]['infos'][jid].window.present()
else: else:
# we copy contact because c.jid must contain the fakeJid for vcard # we copy contact because c.jid must contain the fakeJid for vcard
c2 = Contact(jid = jid, name = c.name, groups = c.groups, c2 = gajim.contacts.contact_from_gc_contact(c)
show = c.show, status = c.status, sub = c.sub,
resource = c.resource, role = c.role, affiliation = c.affiliation)
gajim.interface.instances[self.account]['infos'][jid] = \ gajim.interface.instances[self.account]['infos'][jid] = \
vcard.VcardWindow(c2, self.account, False) vcard.VcardWindow(c2, self.account, False)
@ -1195,10 +1190,8 @@ current room topic.') % command, room_jid)
room_jid = self.get_active_jid() room_jid = self.get_active_jid()
fjid = gajim.construct_fjid(room_jid, nick) # 'fake' jid fjid = gajim.construct_fjid(room_jid, nick) # 'fake' jid
if not gajim.interface.instances[self.account]['chats'].has_key(fjid): if not gajim.interface.instances[self.account]['chats'].has_key(fjid):
show = gajim.gc_contacts[self.account][room_jid][nick].show gc_c = gajim.gc_contacts[self.account][room_jid][nick]
u = Contact(jid = fjid, name = nick, groups = ['none'], show = show, gajim.interface.roster.new_chat(gc_c, self.account)
sub = 'none')
gajim.interface.roster.new_chat(u, self.account)
#make active here in case we need to send a message #make active here in case we need to send a message
gajim.interface.instances[self.account]['chats'][fjid].set_active_tab(fjid) gajim.interface.instances[self.account]['chats'][fjid].set_active_tab(fjid)
@ -1525,10 +1518,8 @@ current room topic.') % command, room_jid)
gajim.interface.systray.add_jid(fjid, self.account, 'pm') gajim.interface.systray.add_jid(fjid, self.account, 'pm')
self.show_title() self.show_title()
else: else:
show = gajim.gc_contacts[self.account][room_jid][nick].show gc_c = gajim.gc_contacts[self.account][room_jid][nick]
c = Contact(jid = fjid, name = nick, groups = ['none'], show = show, gajim.interface.roster.new_chat(gc_c, self.account)
ask = 'none')
gajim.interface.roster.new_chat(c, self.account)
# Scroll to line # Scroll to line
self.list_treeview[room_jid].expand_row(path[0:1], False) self.list_treeview[room_jid].expand_row(path[0:1], False)
self.list_treeview[room_jid].scroll_to_cell(path) self.list_treeview[room_jid].scroll_to_cell(path)
@ -1636,10 +1627,8 @@ current room topic.') % command, room_jid)
nick = model[iter][C_NICK].decode('utf-8') nick = model[iter][C_NICK].decode('utf-8')
fjid = gajim.construct_fjid(room_jid, nick) fjid = gajim.construct_fjid(room_jid, nick)
if not gajim.interface.instances[self.account]['chats'].has_key(fjid): if not gajim.interface.instances[self.account]['chats'].has_key(fjid):
show = gajim.gc_contacts[self.account][room_jid][nick].show gc_c = gajim.gc_contacts[self.account][room_jid][nick]
u = Contact(jid = fjid, name = nick, groups = ['none'], gajim.interface.roster.new_chat(gc_c, self.account)
show = show, sub = 'none')
gajim.interface.roster.new_chat(u, self.account)
gajim.interface.instances[self.account]['chats'][fjid].set_active_tab(fjid) gajim.interface.instances[self.account]['chats'][fjid].set_active_tab(fjid)
gajim.interface.instances[self.account]['chats'][fjid].window.present() gajim.interface.instances[self.account]['chats'][fjid].window.present()
return True return True
@ -1680,10 +1669,8 @@ current room topic.') % command, room_jid)
nick = model[iter][C_NICK].decode('utf-8') nick = model[iter][C_NICK].decode('utf-8')
jid = gajim.construct_fjid(room_jid, nick) jid = gajim.construct_fjid(room_jid, nick)
if not gajim.interface.instances[self.account]['chats'].has_key(jid): if not gajim.interface.instances[self.account]['chats'].has_key(jid):
show = gajim.gc_contacts[self.account][room_jid][nick].show gc_c = gajim.gc_contacts[self.account][room_jid][nick]
contact = Contact(jid = jid, name = nick, groups = ['none'], gajim.interface.roster.new_chat(gc_c, self.account)
show = show, sub = 'none')
gajim.interface.roster.new_chat(contact, self.account)
jid = contact.jid jid = contact.jid
gajim.interface.instances[self.account]['chats'][jid].set_active_tab(jid) gajim.interface.instances[self.account]['chats'][jid].set_active_tab(jid)
gajim.interface.instances[self.account]['chats'][jid].window.present() gajim.interface.instances[self.account]['chats'][jid].window.present()

View File

@ -42,7 +42,6 @@ import gtkgui_helpers
import cell_renderer_image import cell_renderer_image
import tooltips import tooltips
from gajim import Contact
from common import gajim from common import gajim
from common import helpers from common import helpers
from common import i18n from common import i18n
@ -204,10 +203,10 @@ class RosterWindow:
self.draw_avatar(jid, account) self.draw_avatar(jid, account)
def add_transport_to_roster(self, account, transport): def add_transport_to_roster(self, account, transport):
user1 = Contact(jid = transport, name = transport, c = gajim.contacts.create_contact(jid = transport, name = transport,
groups = [_('Transports')], show = 'offline', status = 'offline', groups = [_('Transports')], show = 'offline', status = 'offline',
sub = 'from') sub = 'from')
gajim.contacts[account][transport] = [user1] gajim.contacts[account][transport] = [c]
gajim.interface.roster.add_contact_to_roster(transport, account) gajim.interface.roster.add_contact_to_roster(transport, account)
def really_remove_contact(self, user, account): def really_remove_contact(self, user, account):
@ -668,9 +667,10 @@ class RosterWindow:
'attached_gpg_keys').split() 'attached_gpg_keys').split()
if jid in attached_keys: if jid in attached_keys:
keyID = attached_keys[attached_keys.index(jid) + 1] keyID = attached_keys[attached_keys.index(jid) + 1]
contact1 = Contact(jid = ji, name = name, groups = array[jid]['groups'], contact1 = gajim.contacts.create_contact(jid = ji, name = name,
show = show, status = status, sub = array[jid]['subscription'], groups = array[jid]['groups'], show = show, status = status,
ask = array[jid]['ask'], resource = resource, keyID = keyID) sub = array[jid]['subscription'], ask = array[jid]['ask'],
resource = resource, keyID = keyID)
# when we draw the roster, we avoid having the same contact # when we draw the roster, we avoid having the same contact
# more than once (f.e. we avoid showing it twice when 2 resources) # more than once (f.e. we avoid showing it twice when 2 resources)
@ -790,9 +790,8 @@ class RosterWindow:
contacts = [] contacts = []
connection = gajim.connections[account] connection = gajim.connections[account]
# get our current contact info # get our current contact info
contact = Contact(jid = jid, name = account, contact = gajim.contacts.create_contact(jid = jid, name = account,
show = connection.get_status(), show = connection.get_status(), sub = 'both',
sub = 'both',
status = connection.status, status = connection.status,
resource = gajim.config.get_per('accounts', connection.name, resource = gajim.config.get_per('accounts', connection.name,
'resource'), 'resource'),
@ -811,10 +810,11 @@ class RosterWindow:
show = roster.getShow(jid+'/'+resource) show = roster.getShow(jid+'/'+resource)
if not show: if not show:
show = 'online' show = 'online'
contact = Contact(jid=jid, name=account, contact = gajim.contacts.create_contact(jid = jid,
show=show, name = account, show = show,
status=roster.getStatus(jid+'/'+resource), resource=resource, status = roster.getStatus(jid+'/'+resource),
priority=roster.getPriority(jid+'/'+resource)) resource = resource,
priority = roster.getPriority(jid+'/'+resource))
contacts.append(contact) contacts.append(contact)
if self.tooltip.timeout == 0 or self.tooltip.id != props[0]: if self.tooltip.timeout == 0 or self.tooltip.id != props[0]:
self.tooltip.id = row self.tooltip.id = row
@ -1248,19 +1248,19 @@ class RosterWindow:
'attached_gpg_keys').split() 'attached_gpg_keys').split()
if jid in attached_keys: if jid in attached_keys:
keyID = attached_keys[attached_keys.index(jid) + 1] keyID = attached_keys[attached_keys.index(jid) + 1]
user1 = Contact(jid = jid, name = pseudo, groups = [group], c = gajim.contacts.create_contact(jid = jid, name = pseudo,
show = 'requested', status = '', ask = 'none', groups = [group], show = 'requested', status = '', ask = 'none',
sub = 'subscribe', keyID = keyID) sub = 'subscribe', keyID = keyID)
gajim.contacts[account][jid] = [user1] gajim.contacts[account][jid] = [c]
else: else:
user1 = gajim.get_contact_instance_with_highest_priority(account, jid) c = gajim.get_contact_instance_with_highest_priority(account, jid)
if not _('not in the roster') in user1.groups: if not _('not in the roster') in c.groups:
dialogs.InformationDialog(_('Subscription request has been sent'), dialogs.InformationDialog(_('Subscription request has been sent'),
_('If "%s" accepts this request you will know his or her status.') %jid) _('If "%s" accepts this request you will know his or her status.') %jid)
return return
user1.groups = [group] c.groups = [group]
user1.name = pseudo c.name = pseudo
self.remove_contact(user1, account) self.remove_contact(c, account)
self.add_contact_to_roster(jid, account) self.add_contact_to_roster(jid, account)
def revoke_auth(self, widget, jid, account): def revoke_auth(self, widget, jid, account):
@ -1425,10 +1425,10 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
self.remove_contact(u, account) self.remove_contact(u, account)
del gajim.contacts[account][u.jid] del gajim.contacts[account][u.jid]
if user.jid in gajim.interface.instances[account]['chats']: if user.jid in gajim.interface.instances[account]['chats']:
user1 = Contact(jid = user.jid, name = user.name, c = gajim.contacts.create_contact(jid = user.jid, name = user.name,
groups = [_('not in the roster')], show = 'not in the roster', groups = [_('not in the roster')], show = 'not in the roster',
status = '', ask = 'none', keyID = user.keyID) status = '', ask = 'none', keyID = user.keyID)
gajim.contacts[account][user.jid] = [user1] gajim.contacts[account][user.jid] = [c]
self.add_contact_to_roster(user.jid, account) self.add_contact_to_roster(user.jid, account)
def forget_gpg_passphrase(self, keyid): def forget_gpg_passphrase(self, keyid):
@ -1674,9 +1674,10 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
'attached_gpg_keys').split() 'attached_gpg_keys').split()
if jid in attached_keys: if jid in attached_keys:
keyID = attached_keys[attached_keys.index(jid) + 1] keyID = attached_keys[attached_keys.index(jid) + 1]
contact = Contact(jid = jid, name = jid.split('@')[0], contact = gajim.contacts.create_contact(jid = jid,
groups = [_('not in the roster')], show = 'not in the roster', name = jid.split('@')[0], groups = [_('not in the roster')],
status = '', sub = 'none', keyID = keyID) show = 'not in the roster', status = '', sub = 'none',
keyID = keyID)
gajim.contacts[account][jid] = [contact] gajim.contacts[account][jid] = [contact]
self.add_contact_to_roster(contact.jid, account) self.add_contact_to_roster(contact.jid, account)
@ -1707,10 +1708,11 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
'attached_gpg_keys').split() 'attached_gpg_keys').split()
if jid in attached_keys: if jid in attached_keys:
keyID = attached_keys[attached_keys.index(jid) + 1] keyID = attached_keys[attached_keys.index(jid) + 1]
user1 = Contact(jid = jid, name = jid.split('@')[0], c = gajim.contacts.create_contact(jid = jid,
groups = [_('not in the roster')], show = 'not in the roster', name = jid.split('@')[0], groups = [_('not in the roster')],
status = '', ask = 'none', keyID = keyID, resource = resource) show = 'not in the roster', status = '', ask = 'none',
gajim.contacts[account][jid] = [user1] keyID = keyID, resource = resource)
gajim.contacts[account][jid] = [c]
self.add_contact_to_roster(jid, account) self.add_contact_to_roster(jid, account)
iters = self.get_contact_iter(jid, account) iters = self.get_contact_iter(jid, account)

View File

@ -33,7 +33,6 @@ import os
import tooltips import tooltips
import gtkgui_helpers import gtkgui_helpers
from gajim import Contact
from common import gajim from common import gajim
from common import helpers from common import helpers
from common import i18n from common import i18n