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'):
del self.infos['registered']
else:
user1 = Contact(self.service, self.service, ['Transports'], 'offline',
'offline', 'from', '', '', 0, '')
user1 = Contact(jid = self.service, name = self.service,
groups = ['Transports'], show = 'offline', status = 'offline',
sub = 'from')
self.plugin.roster.contacts[self.account][self.service] = [user1]
self.plugin.roster.add_user_to_roster(self.service, self.account)
gajim.connections[self.account].register_agent(self.service, self.infos)

View File

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

View File

@ -91,30 +91,20 @@ except ImportError:
class Contact:
'''Information concerning each contact'''
def __init__(self, *args):
if len(args) == 0:
self.jid = ''
self.name = ''
self.groups = []
self.show = ''
self.status = ''
self.sub = ''
self.ask = ''
self.resource = ''
self.priority = 1
self.keyID = ''
elif len(args) == 10:
self.jid = args[0]
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')
def __init__(self, jid='', name='', groups=[], show='', status='', sub='',
ask='', resource='', priority=5, keyID='', role='', affiliation=''):
self.jid = jid
self.name = name
self.groups = groups
self.show = show
self.status = status
self.sub = sub
self.ask = ask
self.resource = resource
self.priority = priority
self.keyID = keyID
self.role = role
self.affiliation = affiliation
import roster_window
import systray
@ -248,9 +238,11 @@ class Interface:
if (resources != [''] and (len(luser) != 1 or
luser[0].show != 'offline')) and not jid.find('@') <= 0:
old_show = 0
user1 = Contact(user1.jid, user1.name, user1.groups, user1.show, \
user1.status, user1.sub, user1.ask, user1.resource, \
user1.priority, user1.keyID)
user1 = Contact(jid = user1.jid, name = user1.name,
groups = user1.groups, show = user1.show,
status = user1.status, sub = user1.sub, ask = user1.ask,
resource = user1.resource, priority = user1.priority,
keyID = user1.keyID)
luser.append(user1)
user1.resource = resource
if user1.jid.find('@') > 0 and len(luser) == 1: # It's not an agent
@ -344,8 +336,8 @@ class Interface:
model = tv.get_model()
iter = gc.get_user_iter(jid, nick)
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)
chat_win = self.windows[account]['chats'][fjid]
chat_win.print_conversation(array[1], fjid, tim = array[2])
@ -397,8 +389,8 @@ class Interface:
show = model.get_value(iter, 3)
else:
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.windows[account]['chats'][fjid].print_conversation(
'Error %s: %s' % (array[1], array[2]), fjid, 'status')
@ -442,8 +434,9 @@ class Interface:
'attached_gpg_keys').split()
if jid in attached_keys:
keyID = attached_keys[attached_keys.index(jid) + 1]
user1 = Contact(jid, jid, ['General'], 'online', \
'online', 'to', '', array[1], 0, keyID)
user1 = Contact(jid = jid, name = jid.split('@')[0],
groups = ['General'], show = 'online', status = 'online',
ask = 'to', resource = array[1], keyID = keyID)
self.roster.contacts[account][jid] = [user1]
self.roster.add_user_to_roster(jid, account)
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):
#show = model.get_value(iter, 3) #FIXME: be able to get show from nick
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)
if msg:
self.plugin.windows[self.account]['chats'][fjid].send_message(msg)
@ -979,7 +980,8 @@ class GroupchatWindow(chat.Chat):
fjid = room_jid + '/' + nick
if not self.plugin.windows[self.account]['chats'].has_key(fjid):
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.windows[self.account]['chats'][fjid].set_active_tab(fjid)
self.plugin.windows[self.account]['chats'][fjid].window.present()
@ -1024,8 +1026,8 @@ class GroupchatWindow(chat.Chat):
fjid = room_jid + '/' + nick
if not self.plugin.windows[self.account]['chats'].has_key(fjid):
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.windows[self.account]['chats'][fjid].set_active_tab(fjid)
self.plugin.windows[self.account]['chats'][fjid].window.present()

View File

@ -432,9 +432,9 @@ class RosterWindow:
'attached_gpg_keys').split()
if jid in attached_keys:
keyID = attached_keys[attached_keys.index(jid) + 1]
user1 = Contact(ji, name, array[jid]['groups'], show, status,\
array[jid]['subscription'], array[jid]['ask'], resource, 0,
keyID)
user1 = Contact(jid = ji, name = name, groups = array[jid]['groups'],
show = show, status = status, sub = array[jid]['subscription'],
ask = array[jid]['ask'], resource = resource, keyID = keyID)
# when we draw the roster, we avoid having the same contact
# more than once (eg. we avoid showing it twice with 2 resources)
@ -949,8 +949,9 @@ class RosterWindow:
'attached_gpg_keys').split()
if jid in attached_keys:
keyID = attached_keys[attached_keys.index(jid) + 1]
user1 = Contact(jid, pseudo, [group], 'requested', 'requested',
'none', 'subscribe', '', 0, keyID)
user1 = Contact(jid = jid, name = pseudo, groups = [group],
show = 'requested', status = 'requested', ask = 'none',
sub = 'subscribe', keyOD = keyID)
self.contacts[account][jid] = [user1]
else:
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)
del self.contacts[account][u.jid]
if user.jid in self.plugin.windows[account]['chats']:
user1 = Contact(user.jid, user.name, ['not in the roster'],
'not in the roster', 'not in the roster', 'none', None, '', 0,
user.keyID)
user1 = Contact(jid = user.jid, name = user.name,
groups = ['not in the roster'], show = 'not in the roster',
status = 'not in the roster', ask = 'none', keyID = user.keyID)
self.contacts[account][user.jid] = [user1]
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()
if jid in attached_keys:
keyID = attached_keys[attached_keys.index(jid) + 1]
user1 = Contact(jid, jid, ['not in the roster'], 'not in the roster',
'not in the roster', 'none', None, '', 0, keyID)
user1 = Contact(jid = jid, name = jid.split('@')[0],
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.add_user_to_roster(jid, account)
iters = self.get_user_iter(jid, account)