Small roster API cleanups.

This commit is contained in:
Stephan Erb 2008-04-23 22:34:10 +00:00
parent f4f38e3738
commit 29d2e00803
3 changed files with 46 additions and 31 deletions

View file

@ -2326,8 +2326,8 @@ class Interface:
if no_queue: # We didn't have a queue: we change icons if no_queue: # We didn't have a queue: we change icons
if not gajim.contacts.get_contact_with_highest_priority(account, jid): if not gajim.contacts.get_contact_with_highest_priority(account, jid):
if type_ == 'gc-invitation': if type_ == 'gc-invitation':
self.roster.add_groupchat(account, jid, self.roster.add_groupchat(jid, account,
status='offline') status = 'offline')
else: else:
# add contact to roster ("Not In The Roster") if he is not # add contact to roster ("Not In The Roster") if he is not
self.roster.add_to_not_in_the_roster(account, jid) self.roster.add_to_not_in_the_roster(account, jid)
@ -2694,7 +2694,7 @@ class Interface:
gajim.connections[account].join_gc(nick, room_jid, password) gajim.connections[account].join_gc(nick, room_jid, password)
if password: if password:
gajim.gc_passwords[room_jid] = password gajim.gc_passwords[room_jid] = password
self.roster.add_groupchat(account, room_jid) self.roster.add_groupchat(room_jid, account)
return return
if not minimized_control_exists and \ if not minimized_control_exists and \
not self.msg_win_mgr.has_window(room_jid, account): not self.msg_win_mgr.has_window(room_jid, account):
@ -2709,7 +2709,7 @@ class Interface:
contact = gajim.contacts.get_contact_with_highest_priority(account, \ contact = gajim.contacts.get_contact_with_highest_priority(account, \
room_jid) room_jid)
if contact or minimized_control_exists: if contact or minimized_control_exists:
self.roster.add_groupchat(account, room_jid) self.roster.add_groupchat(room_jid, account)
def new_room(self, room_jid, nick, account, is_continued=False): def new_room(self, room_jid, nick, account, is_continued=False):
# Get target window, create a control, and associate it with the window # Get target window, create a control, and associate it with the window

View file

@ -1587,8 +1587,8 @@ class GroupchatControl(ChatControlBase):
del win._controls[self.account][self.contact.jid] del win._controls[self.account][self.contact.jid]
gajim.interface.roster.add_groupchat(self.account, gajim.interface.roster.add_groupchat(self.contact.jid, self.account,
self.contact.jid, status = self.subject) status = self.subject)
def shutdown(self, status='offline'): def shutdown(self, status='offline'):
# destroy banner tooltip - bug #pygtk for that! # destroy banner tooltip - bug #pygtk for that!

View file

@ -232,7 +232,7 @@ class RosterWindow:
################################################################################ ################################################################################
def add_account(self, account): def add_account(self, account):
'''Add account to roster but do nothing if it is already in.''' '''Add account to roster and draw it. Do nothing if it is already in.'''
# no redraw, add only # no redraw, add only
if self._get_account_iter(account): if self._get_account_iter(account):
# Will happen on reconnect or for merged accounts # Will happen on reconnect or for merged accounts
@ -256,6 +256,9 @@ class RosterWindow:
gobject.markup_escape_text(account), gobject.markup_escape_text(account),
'account', our_jid, account, None, tls_pixbuf]) 'account', our_jid, account, None, tls_pixbuf])
if not self.starting:
self.draw_account(account)
def add_account_contacts(self, account): def add_account_contacts(self, account):
'''Add all contacts and groups of the given account to roster '''Add all contacts and groups of the given account to roster
@ -264,14 +267,17 @@ class RosterWindow:
c1 = time.clock() c1 = time.clock()
jids = gajim.contacts.get_jid_list(account) jids = gajim.contacts.get_jid_list(account)
self.starting = True # don't draw contacts
self.tree.freeze_child_notify() self.tree.freeze_child_notify()
c5 = time.clock() c5 = time.clock()
for jid in jids: for jid in jids:
self.add_contact(jid, account) self.add_contact(jid, account)
c6 = time.clock() c6 = time.clock()
self.tree.thaw_child_notify() self.tree.thaw_child_notify()
self.starting = False
# Do not freeze the GUI when drawing the contacts
if jids:
# Overhead is big, only invoke when needed
self._idle_draw_jids_of_account(jids, account)
c9 = time.clock() c9 = time.clock()
# Draw all known groups # Draw all known groups
@ -280,15 +286,11 @@ class RosterWindow:
self.draw_account(account) self.draw_account(account)
c10 = time.clock() c10 = time.clock()
# Do not freeze the GUI when drawing the contacts
if jids: if jids:
# Overhead is big, only invoke when needed
self._idle_draw_jids_of_account(jids, account)
c4 = time.clock() c4 = time.clock()
print "" print ""
print "--- Add account contacts -----------------------------" print "--- Add account contacts of %s ---------" % account
print "Total Time", c4-c1 print "Total Time", c4-c1
print "Add contact without draw", c6-c5 print "Add contact without draw", c6-c5
print "Draw groups and account", c10-c9 print "Draw groups and account", c10-c9
@ -542,11 +544,10 @@ class RosterWindow:
if jid == gajim.get_jid_from_account(account): if jid == gajim.get_jid_from_account(account):
if contact.resource != gajim.connections[account].server_resource: if contact.resource != gajim.connections[account].server_resource:
return self._add_self_contact(account) return self._add_self_contact(account)
#FIXME When does this happen?
assert False
return return
if contact.is_observer(): is_observer = contact.is_observer()
if is_observer:
# if he has a tag, remove it # if he has a tag, remove it
tag = gajim.contacts.get_metacontacts_tag(account, jid) tag = gajim.contacts.get_metacontacts_tag(account, jid)
if tag: if tag:
@ -567,7 +568,7 @@ class RosterWindow:
# Draw all groups of the contact # Draw all groups of the contact
if contact.is_transport(): if contact.is_transport():
contact.groups = [_('Transports')] contact.groups = [_('Transports')]
if contact.is_observer(): if is_observer:
contact.groups = [_('Observers')] contact.groups = [_('Observers')]
groups = contact.groups groups = contact.groups
if not groups: if not groups:
@ -581,8 +582,8 @@ class RosterWindow:
ishidden = True ishidden = True
gajim.groups[account][group] = {'expand': ishidden} gajim.groups[account][group] = {'expand': ishidden}
#if not self.starting: if not self.starting:
self.draw_group(group, account) self.draw_group(group, account)
if not self.starting: if not self.starting:
for c, acc in contacts: for c, acc in contacts:
@ -636,7 +637,7 @@ class RosterWindow:
return True return True
def add_groupchat(self, account, jid, resource = '', status = ''): def add_groupchat(self, jid, account, status = ''):
'''Add groupchat to roster and draw it. '''Add groupchat to roster and draw it.
Return the added contact instance. Return the added contact instance.
''' '''
@ -647,9 +648,10 @@ class RosterWindow:
status = status, sub = 'none', status = status, sub = 'none',
resource = resource) resource = resource)
gajim.contacts.add_contact(account, contact) gajim.contacts.add_contact(account, contact)
self.add_contact(jid, account)
else: else:
contact.show = 'online' contact.show = 'online'
self.add_contact(jid, account) self.draw_contact(jid, account)
return contact return contact
@ -658,27 +660,35 @@ class RosterWindow:
contact = gajim.contacts.get_contact_with_highest_priority(account, jid) contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
self.remove_contact(jid, account) self.remove_contact(jid, account)
gajim.contacts.remove_contact(account, contact) gajim.contacts.remove_contact(account, contact)
#FIXME: stupid hack.
# When we redraw the group in remove_contact the # When we redraw the group in remove_contact the
# contact does still exist and so the group is still showing # contact does still exist and so the group is still showing
# the old numbers. # the old numbers.
# Maybe use timeout to draw groups so that there is enough time
# to remove the contact instance.
self.draw_group(_('Groupchats'), account) self.draw_group(_('Groupchats'), account)
return True return True
def add_transport(self, account, transport): def add_transport(self, jid, account):
'''Add transport to roster and draw it. '''Add transport to roster and draw it.
Return the added contact instance.''' Return the added contact instance.'''
contact = gajim.contacts.create_contact(jid = transport, name = transport, contact = gajim.contacts.create_contact(jid = jid, name = jid,
groups = [_('Transports')], show = 'offline', groups = [_('Transports')], show = 'offline',
status = 'offline', sub = 'from') status = 'offline', sub = 'from')
gajim.contacts.add_contact(account, contact) gajim.contacts.add_contact(account, contact)
self.add_contact(transport, account) self.add_contact(transport, account)
return contact return contact
# FIXME: remove_transport method is missing
def remove_transport(self, jid, account):
'''Remove transport from roster and redraw account and group.'''
contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
self.remove_contact(jid, account)
gajim.contacts.remove_contact(account, contact)
# When we redraw the group in remove_contact the
# contact does still exist and so the group is still showing
# the old numbers.
self.draw_group(_('Transports'), account)
return True
#FIXME: Better never even remove.... #FIXME: Better never even remove....
def _readd_contact_to_roster_if_needed(self, contact, account): def _readd_contact_to_roster_if_needed(self, contact, account):
@ -857,6 +867,7 @@ class RosterWindow:
parent_jid = self.model[parent_iter][C_JID].decode('utf-8') parent_jid = self.model[parent_iter][C_JID].decode('utf-8')
parent_account = self.model[parent_iter][C_ACCOUNT].decode('utf-8') parent_account = self.model[parent_iter][C_ACCOUNT].decode('utf-8')
self.draw_contact(parent_jid, parent_account) self.draw_contact(parent_jid, parent_account)
return False
def draw_contact(self, jid, account, selected = False, focus = False): def draw_contact(self, jid, account, selected = False, focus = False):
'''draw the correct state image, name BUT not avatar''' '''draw the correct state image, name BUT not avatar'''
@ -968,7 +979,9 @@ class RosterWindow:
else: else:
# We are a simple brother # We are a simple brother
# Let our big brother know of our existence (and possible events) # Let our big brother know of our existence (and possible events)
self.draw_contact(big_brother_jid, big_brother_account) if not self.starting:
# Our account is currently added. Parent will be drawn anyway.
self.draw_contact(big_brother_jid, big_brother_account)
icon_name = helpers.get_icon_name_to_show(contact, account) icon_name = helpers.get_icon_name_to_show(contact, account)
# look if another resource has awaiting events # look if another resource has awaiting events
@ -1084,7 +1097,7 @@ class RosterWindow:
self.draw_contact(jid, account) self.draw_contact(jid, account)
self.draw_avatar(jid, account) self.draw_avatar(jid, account)
yield True yield True
print "--- Idle draw -----------------" print "--- Idle draw of %s -----------" % account
print "Draw contact and avatar", time.clock() - t print "Draw contact and avatar", time.clock() - t
print "-------------------------------" print "-------------------------------"
yield False yield False
@ -1098,9 +1111,11 @@ class RosterWindow:
# clear the model, only if it is not empty # clear the model, only if it is not empty
if self.model: if self.model:
self.model.clear() self.model.clear()
self.starting = True
for acct in gajim.connections: for acct in gajim.connections:
self.add_account(acct) self.add_account(acct)
self.add_account_contacts(acct) self.add_account_contacts(acct)
self.starting = False
# Recalculate column width for ellipsizing # Recalculate column width for ellipsizing
self.tree.columns_autosize() self.tree.columns_autosize()