Contact class is easier to use now

This commit is contained in:
Yann Leboulanger 2005-06-25 09:18:39 +00:00
parent f0547ba13d
commit 7cd28d5e2d
5 changed files with 53 additions and 54 deletions

View File

@ -1620,8 +1620,9 @@ class ServiceRegistrationWindow:
if self.infos.has_key('registered'): if self.infos.has_key('registered'):
del self.infos['registered'] del self.infos['registered']
else: else:
user1 = Contact(self.service, self.service, ['Transports'], 'offline', user1 = Contact(jid = self.service, name = self.service,
'offline', 'from', '', '', 0, '') groups = ['Transports'], show = 'offline', status = 'offline',
sub = 'from')
self.plugin.roster.contacts[self.account][self.service] = [user1] self.plugin.roster.contacts[self.account][self.service] = [user1]
self.plugin.roster.add_user_to_roster(self.service, self.account) self.plugin.roster.add_user_to_roster(self.service, self.account)
gajim.connections[self.account].register_agent(self.service, self.infos) gajim.connections[self.account].register_agent(self.service, self.infos)

View File

@ -670,8 +670,9 @@ class NewMessageDialog:
'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]
user = Contact(jid, jid, ['not in the roster'], 'not in the roster', user = Contact(jid = jid, name = jid.split('@')[0],
'not in the roster', 'none', None, '', 0, keyID) groups = ['not in the roster'], show = 'not in the roster',
status = 'not in the roster', sub = 'none', keyID = keyID)
self.plugin.roster.contacts[self.account][jid] = [user] self.plugin.roster.contacts[self.account][jid] = [user]
self.plugin.roster.add_user_to_roster(user.jid, self.account) self.plugin.roster.add_user_to_roster(user.jid, self.account)
@ -798,9 +799,9 @@ class PopupNotificationWindow:
'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]
user = Contact(self.jid, self.jid, ['not in the roster'], user = Contact(jid = self.jid, name = self.jid.split('@')[0],
'not in the roster', 'not in the roster', 'none', None, '', 0, groups = ['not in the roster'], show = 'not in the roster',
keyID) status = 'not in the roster', sub = 'none', keyID = keyID)
self.plugin.roster.contacts[self.account][self.jid] = [user] self.plugin.roster.contacts[self.account][self.jid] = [user]
self.plugin.roster.add_user_to_roster(user.self.jid, self.account) self.plugin.roster.add_user_to_roster(user.self.jid, self.account)

View File

@ -91,30 +91,20 @@ except ImportError:
class Contact: class Contact:
'''Information concerning each contact''' '''Information concerning each contact'''
def __init__(self, *args): def __init__(self, jid='', name='', groups=[], show='', status='', sub='',
if len(args) == 0: ask='', resource='', priority=5, keyID='', role='', affiliation=''):
self.jid = '' self.jid = jid
self.name = '' self.name = name
self.groups = [] self.groups = groups
self.show = '' self.show = show
self.status = '' self.status = status
self.sub = '' self.sub = sub
self.ask = '' self.ask = ask
self.resource = '' self.resource = resource
self.priority = 1 self.priority = priority
self.keyID = '' self.keyID = keyID
elif len(args) == 10: self.role = role
self.jid = args[0] self.affiliation = affiliation
self.name = args[1]
self.groups = args[2]
self.show = args[3]
self.status = args[4]
self.sub = args[5]
self.ask = args[6]
self.resource = args[7]
self.priority = args[8]
self.keyID = args[9]
else: raise TypeError, _('bad arguments')
import roster_window import roster_window
import systray import systray
@ -248,9 +238,11 @@ class Interface:
if (resources != [''] and (len(luser) != 1 or if (resources != [''] and (len(luser) != 1 or
luser[0].show != 'offline')) and not jid.find('@') <= 0: luser[0].show != 'offline')) and not jid.find('@') <= 0:
old_show = 0 old_show = 0
user1 = Contact(user1.jid, user1.name, user1.groups, user1.show, \ user1 = Contact(jid = user1.jid, name = user1.name,
user1.status, user1.sub, user1.ask, user1.resource, \ groups = user1.groups, show = user1.show,
user1.priority, user1.keyID) status = user1.status, sub = user1.sub, ask = user1.ask,
resource = user1.resource, priority = user1.priority,
keyID = user1.keyID)
luser.append(user1) luser.append(user1)
user1.resource = resource user1.resource = resource
if user1.jid.find('@') > 0 and len(luser) == 1: # It's not an agent if user1.jid.find('@') > 0 and len(luser) == 1: # It's not an agent
@ -344,8 +336,8 @@ class Interface:
model = tv.get_model() model = tv.get_model()
iter = gc.get_user_iter(jid, nick) iter = gc.get_user_iter(jid, nick)
show = model.get_value(iter, 3) show = model.get_value(iter, 3)
u = Contact(fjid, nick, ['none'], show, '', 'none', None, '', 0, u = Contact(jid = fjid, name = nick, groups = ['none'], show = show,
'') ask = 'none')
self.roster.new_chat(u, account) self.roster.new_chat(u, account)
chat_win = self.windows[account]['chats'][fjid] chat_win = self.windows[account]['chats'][fjid]
chat_win.print_conversation(array[1], fjid, tim = array[2]) chat_win.print_conversation(array[1], fjid, tim = array[2])
@ -397,8 +389,8 @@ class Interface:
show = model.get_value(iter, 3) show = model.get_value(iter, 3)
else: else:
show = 'offline' show = 'offline'
u = Contact(fjid, nick, ['none'], show, '', 'none', None, '', 0, u = Contact(jid = fjid, name = nick, groups = ['none'],
'') show = show, ask = 'none')
self.roster.new_chat(u, account) self.roster.new_chat(u, account)
self.windows[account]['chats'][fjid].print_conversation( self.windows[account]['chats'][fjid].print_conversation(
'Error %s: %s' % (array[1], array[2]), fjid, 'status') 'Error %s: %s' % (array[1], array[2]), fjid, 'status')
@ -442,8 +434,9 @@ class Interface:
'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, ['General'], 'online', \ user1 = Contact(jid = jid, name = jid.split('@')[0],
'online', 'to', '', array[1], 0, keyID) groups = ['General'], show = 'online', status = 'online',
ask = 'to', resource = array[1], keyID = keyID)
self.roster.contacts[account][jid] = [user1] self.roster.contacts[account][jid] = [user1]
self.roster.add_user_to_roster(jid, account) self.roster.add_user_to_roster(jid, account)
dialogs.InformationDialog(_('Authorization accepted'), dialogs.InformationDialog(_('Authorization accepted'),

View File

@ -662,7 +662,8 @@ class GroupchatWindow(chat.Chat):
if not self.plugin.windows[self.account]['chats'].has_key(fjid): if not self.plugin.windows[self.account]['chats'].has_key(fjid):
#show = model.get_value(iter, 3) #FIXME: be able to get show from nick #show = model.get_value(iter, 3) #FIXME: be able to get show from nick
show = 'chat' show = 'chat'
u = Contact(fjid, nick, ['none'], show, '', 'none', None, '', 0, '') u = Contact(jid = fjid, name = nick, groups = ['none'], show = show,
sub = 'none')
self.plugin.roster.new_chat(u, self.account) self.plugin.roster.new_chat(u, self.account)
if msg: if msg:
self.plugin.windows[self.account]['chats'][fjid].send_message(msg) self.plugin.windows[self.account]['chats'][fjid].send_message(msg)
@ -979,7 +980,8 @@ class GroupchatWindow(chat.Chat):
fjid = room_jid + '/' + nick fjid = room_jid + '/' + nick
if not self.plugin.windows[self.account]['chats'].has_key(fjid): if not self.plugin.windows[self.account]['chats'].has_key(fjid):
show = model.get_value(iter, 3) show = model.get_value(iter, 3)
u = Contact(fjid, nick, ['none'], show, '', 'none', None, '', 0,'') u = Contact(jid = fjid, name = nick, groups = ['none'],
show = show, sub = 'none')
self.plugin.roster.new_chat(u, self.account) self.plugin.roster.new_chat(u, self.account)
self.plugin.windows[self.account]['chats'][fjid].set_active_tab(fjid) self.plugin.windows[self.account]['chats'][fjid].set_active_tab(fjid)
self.plugin.windows[self.account]['chats'][fjid].window.present() self.plugin.windows[self.account]['chats'][fjid].window.present()
@ -1024,8 +1026,8 @@ class GroupchatWindow(chat.Chat):
fjid = room_jid + '/' + nick fjid = room_jid + '/' + nick
if not self.plugin.windows[self.account]['chats'].has_key(fjid): if not self.plugin.windows[self.account]['chats'].has_key(fjid):
show = model.get_value(iter, 3) show = model.get_value(iter, 3)
u = Contact(fjid, nick, ['none'], show, '', 'none', None, '', 0, u = Contact(jid = fjid, name = nick, groups = ['none'],
'') show = show, sub = 'none')
self.plugin.roster.new_chat(u, self.account) self.plugin.roster.new_chat(u, self.account)
self.plugin.windows[self.account]['chats'][fjid].set_active_tab(fjid) self.plugin.windows[self.account]['chats'][fjid].set_active_tab(fjid)
self.plugin.windows[self.account]['chats'][fjid].window.present() self.plugin.windows[self.account]['chats'][fjid].window.present()

View File

@ -432,9 +432,9 @@ 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(ji, name, array[jid]['groups'], show, status,\ user1 = Contact(jid = ji, name = name, groups = array[jid]['groups'],
array[jid]['subscription'], array[jid]['ask'], resource, 0, show = show, status = status, sub = array[jid]['subscription'],
keyID) 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 (eg. we avoid showing it twice with 2 resources) # more than once (eg. we avoid showing it twice with 2 resources)
@ -949,8 +949,9 @@ 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, pseudo, [group], 'requested', 'requested', user1 = Contact(jid = jid, name = pseudo, groups = [group],
'none', 'subscribe', '', 0, keyID) show = 'requested', status = 'requested', ask = 'none',
sub = 'subscribe', keyOD = keyID)
self.contacts[account][jid] = [user1] self.contacts[account][jid] = [user1]
else: else:
user1 = self.contacts[account][jid][0] user1 = self.contacts[account][jid][0]
@ -1063,9 +1064,9 @@ _('If "%s" accepts this request you will know his status.') %jid).get_response()
self.remove_user(u, account) self.remove_user(u, account)
del self.contacts[account][u.jid] del self.contacts[account][u.jid]
if user.jid in self.plugin.windows[account]['chats']: if user.jid in self.plugin.windows[account]['chats']:
user1 = Contact(user.jid, user.name, ['not in the roster'], user1 = Contact(jid = user.jid, name = user.name,
'not in the roster', 'not in the roster', 'none', None, '', 0, groups = ['not in the roster'], show = 'not in the roster',
user.keyID) status = 'not in the roster', ask = 'none', keyID = user.keyID)
self.contacts[account][user.jid] = [user1] self.contacts[account][user.jid] = [user1]
self.add_user_to_roster(user.jid, account) self.add_user_to_roster(user.jid, account)
@ -1263,8 +1264,9 @@ _('If "%s" accepts this request you will know his status.') %jid).get_response()
'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, ['not in the roster'], 'not in the roster', user1 = Contact(jid = jid, name = jid.split('@')[0],
'not in the roster', 'none', None, '', 0, keyID) groups = ['not in the roster'], show = 'not in the roster',
status = 'not in the roster', ask = 'none', keyID = keyID)
self.contacts[account][jid] = [user1] self.contacts[account][jid] = [user1]
self.add_user_to_roster(jid, account) self.add_user_to_roster(jid, account)
iters = self.get_user_iter(jid, account) iters = self.get_user_iter(jid, account)