Coding style

This commit is contained in:
Stephan Erb 2008-08-06 20:19:16 +00:00
parent d1150f4d02
commit f5be05a14a
4 changed files with 48 additions and 71 deletions

View File

@ -615,4 +615,4 @@ class Contacts:
return None return None
return self._gc_contacts[account][room_jid][nick] return self._gc_contacts[account][room_jid][nick]
# vim: se ts=3: # vim: se ts=3:

View File

@ -389,4 +389,4 @@ def get_priority(account, show):
return config.get_per('accounts', account, 'autopriority_' + show) return config.get_per('accounts', account, 'autopriority_' + show)
return config.get_per('accounts', account, 'priority') return config.get_per('accounts', account, 'priority')
# vim: se ts=3: # vim: se ts=3:

View File

@ -980,4 +980,4 @@ def reload_jabber_state_images():
make_jabber_state_images() make_jabber_state_images()
gajim.interface.roster.update_jabber_state_images() gajim.interface.roster.update_jabber_state_images()
# vim: se ts=3: # vim: se ts=3:

View File

@ -162,7 +162,7 @@ class RosterWindow:
return None return None
def _get_contact_iter(self, jid, account, contact = None, model = None): def _get_contact_iter(self, jid, account, contact=None, model=None):
''' Return a list of gtk.TreeIter of the given contact. ''' Return a list of gtk.TreeIter of the given contact.
Keyword arguments: Keyword arguments:
@ -179,59 +179,48 @@ class RosterWindow:
return [] return []
if jid == gajim.get_jid_from_account(account): if jid == gajim.get_jid_from_account(account):
contact_iter = self._get_self_contact_iter(jid, contact_iter = self._get_self_contact_iter(jid, account, model)
account, model)
if contact_iter: if contact_iter:
return [contact_iter] return [contact_iter]
else: else:
return [] return []
if not contact: if not contact:
contact = gajim.contacts.get_first_contact_from_jid( contact = gajim.contacts.get_first_contact_from_jid(account, jid)
account, jid)
if not contact: if not contact:
# We don't know this contact # We don't know this contact
return return []
acct = self._get_account_iter(account, model) acct = self._get_account_iter(account, model)
found = [] # the contact iters. One per group found = [] # the contact iters. One per group
for group in contact.get_shown_groups(): for group in contact.get_shown_groups():
group_iter = self._get_group_iter(group, account, group_iter = self._get_group_iter(group, account, acct, model)
acct, model)
contact_iter = model.iter_children(group_iter) contact_iter = model.iter_children(group_iter)
while contact_iter: while contact_iter:
# Loop over all contacts in this group # Loop over all contacts in this group
iter_jid = model[contact_iter][C_JID] iter_jid = model[contact_iter][C_JID]
if iter_jid and \ if iter_jid and jid == iter_jid.decode('utf-8') and \
jid == iter_jid.decode('utf-8') and account == \ account == model[contact_iter][C_ACCOUNT].decode('utf-8'):
model[contact_iter][C_ACCOUNT].decode('utf-8'):
# only one iter per group # only one iter per group
found.append(contact_iter) found.append(contact_iter)
contact_iter = None contact_iter = None
elif model.iter_has_child(contact_iter): elif model.iter_has_child(contact_iter):
# it's a big brother and has children # it's a big brother and has children
contact_iter = model.iter_children( contact_iter = model.iter_children(contact_iter)
contact_iter)
else: else:
# try to find next contact: # try to find next contact:
# other contact in this group or # other contact in this group or
# brother contact # brother contact
next_contact_iter = model.iter_next( next_contact_iter = model.iter_next(contact_iter)
contact_iter)
if next_contact_iter: if next_contact_iter:
contact_iter = next_contact_iter contact_iter = next_contact_iter
else: else:
# It's the last one. # It's the last one.
# Go up if we are big brother # Go up if we are big brother
parent_iter = model.iter_parent( parent_iter = model.iter_parent(contact_iter)
contact_iter) if parent_iter and model[parent_iter][C_TYPE] == 'contact':
if parent_iter and \ contact_iter = model.iter_next(parent_iter)
model[parent_iter][C_TYPE] == \
'contact':
contact_iter = \
model.iter_next(
parent_iter)
else: else:
# we tested all # we tested all
# contacts in this group # contacts in this group
@ -293,8 +282,7 @@ class RosterWindow:
_('Merged accounts'), 'account', '', 'all', _('Merged accounts'), 'account', '', 'all',
None, None, None, None, None]) None, None, None, None, None])
else: else:
show = gajim.SHOW_LIST[gajim.connections[account]. \ show = gajim.SHOW_LIST[gajim.connections[account].connected]
connected]
our_jid = gajim.get_jid_from_account(account) our_jid = gajim.get_jid_from_account(account)
tls_pixbuf = None tls_pixbuf = None
@ -331,7 +319,7 @@ class RosterWindow:
self._idle_draw_jids_of_account(jids, account) self._idle_draw_jids_of_account(jids, account)
# Draw all known groups # Draw all known groups
for group in gajim.groups[account].keys(): for group in gajim.groups[account]:
self.draw_group(group, account) self.draw_group(group, account)
self.draw_account(account) self.draw_account(account)
self.starting = False self.starting = False
@ -363,35 +351,27 @@ class RosterWindow:
assert len(parent_iters) > 0,\ assert len(parent_iters) > 0,\
'Big brother is not yet in roster!' 'Big brother is not yet in roster!'
# Do not confuse get_contact_iter # Do not confuse get_contact_iter: Sync groups of family members
# Sync groups of family members contact.groups = big_brother_contact.get_shown_groups()[:]
contact.groups = \
big_brother_contact.get_shown_groups()[:]
for child_iter in parent_iters: for child_iter in parent_iters:
it = self.model.append(child_iter, (None, it = self.model.append(child_iter, (None, contact.get_shown_name(),
contact.get_shown_name(), 'contact', 'contact', contact.jid, account, None, None, None, None, None))
contact.jid, account, None, None, None,
None, None))
added_iters.append(it) added_iters.append(it)
else: else:
# We are a normal contact. Add us to our groups. # We are a normal contact. Add us to our groups.
if not groups: if not groups:
groups = contact.get_shown_groups() groups = contact.get_shown_groups()
for group in groups: for group in groups:
child_iterG = self._get_group_iter(group, child_iterG = self._get_group_iter(group, account,
account, model = self.model) model = self.model)
if not child_iterG: if not child_iterG:
# Group is not yet in roster, add it! # Group is not yet in roster, add it!
child_iterA = self._get_account_iter( child_iterA = self._get_account_iter(account, self.model)
account, self.model) child_iterG = self.model.append(child_iterA,
child_iterG = self.model.append( [gajim.interface.jabber_state_images['16']['closed'],
child_iterA, [gajim.interface. \ gobject.markup_escape_text(group),
jabber_state_images['16'] \ 'group', group, account, None, None, None, None, None])
['closed'], gobject. \
markup_escape_text(group),
'group', group, account, None,
None, None, None, None])
self.draw_group(group, account) self.draw_group(group, account)
if contact.is_transport(): if contact.is_transport():
@ -415,15 +395,12 @@ class RosterWindow:
else: else:
is_expanded = True is_expanded = True
if group not in gajim.groups[account]: if group not in gajim.groups[account]:
gajim.groups[account][group] = \ gajim.groups[account][group] = {'expand': is_expanded}
{'expand': is_expanded}
assert len(added_iters), '%s has not been added to roster!' % \ assert len(added_iters), '%s has not been added to roster!' % contact.jid
contact.jid assert all(self.model[titer][C_JID] == contact.jid and \
for titer in added_iters: self.model[titer][C_ACCOUNT] == account for titer in added_iters), \
assert self.model[titer][C_JID] == contact.jid and \ "Iters invalidated for %s" % contact.jid
self.model[titer][C_ACCOUNT] == account, \
"Iters invalidated for %s" % contact.jid
return added_iters return added_iters
def _remove_entity(self, contact, account, groups = None): def _remove_entity(self, contact, account, groups = None):
@ -439,10 +416,8 @@ class RosterWindow:
account -- the contacts account account -- the contacts account
groups -- list of groups to remove the contact from. groups -- list of groups to remove the contact from.
''' '''
iters = self._get_contact_iter(contact.jid, account, contact, iters = self._get_contact_iter(contact.jid, account, contact, self.model)
self.model) assert iters, '%s shall be removed but is not in roster' % contact.jid
assert iters, '%s shall be removed but is not in roster' % \
contact.jid
parent_iter = self.model.iter_parent(iters[0]) parent_iter = self.model.iter_parent(iters[0])
parent_type = self.model[parent_iter][C_TYPE] parent_type = self.model[parent_iter][C_TYPE]
@ -450,7 +425,7 @@ class RosterWindow:
if groups: if groups:
# Only remove from specified groups # Only remove from specified groups
all_iters = iters[:] all_iters = iters[:]
group_iters = [self._get_group_iter(group, account) \ group_iters = [self._get_group_iter(group, account)
for group in groups] for group in groups]
iters = [titer for titer in all_iters iters = [titer for titer in all_iters
if self.model.iter_parent(titer) in group_iters] if self.model.iter_parent(titer) in group_iters]
@ -466,11 +441,12 @@ class RosterWindow:
assert self.model[i][C_JID] == contact.jid and \ assert self.model[i][C_JID] == contact.jid and \
self.model[i][C_ACCOUNT] == account, \ self.model[i][C_ACCOUNT] == account, \
"Invalidated iters of %s" % contact.jid "Invalidated iters of %s" % contact.jid
parent_i = self.model.iter_parent(i) parent_i = self.model.iter_parent(i)
if parent_type == 'group' and \ if parent_type == 'group' and \
self.model.iter_n_children(parent_i) == 1: self.model.iter_n_children(parent_i) == 1:
group = self.model[parent_i][C_JID]. \ group = self.model[parent_i][C_JID].decode('utf-8')
decode('utf-8')
if gajim.groups[account].has_key(group): if gajim.groups[account].has_key(group):
del gajim.groups[account][group] del gajim.groups[account][group]
self.model.remove(parent_i) self.model.remove(parent_i)
@ -496,8 +472,8 @@ class RosterWindow:
big_brother_account, big_brother_jid) big_brother_account, big_brother_jid)
assert len(self._get_contact_iter(big_brother_jid, assert len(self._get_contact_iter(big_brother_jid,
big_brother_account, big_brother_contact, self.model)) \ big_brother_account, big_brother_contact, self.model)) == 0, \
== 0, 'Big brother %s already in roster\n Family: %s' \ 'Big brother %s already in roster\n Family: %s' \
% (big_brother_jid, family) % (big_brother_jid, family)
self._add_entity(big_brother_contact, big_brother_account) self._add_entity(big_brother_contact, big_brother_account)
@ -515,8 +491,8 @@ class RosterWindow:
continue continue
assert len(self._get_contact_iter(_jid, _account, assert len(self._get_contact_iter(_jid, _account,
_contact, self.model)) == 0, "%s already in " \ _contact, self.model)) == 0, \
"roster.\n Family: %s" % (_jid, nearby_family) "%s already in roster.\n Family: %s" % (_jid, nearby_family)
self._add_entity(_contact, _account, self._add_entity(_contact, _account,
big_brother_contact = big_brother_contact, big_brother_contact = big_brother_contact,
big_brother_account = big_brother_account) big_brother_account = big_brother_account)
@ -732,7 +708,6 @@ class RosterWindow:
return contacts[0][0] # it's contact/big brother with highest priority return contacts[0][0] # it's contact/big brother with highest priority
def remove_contact(self, jid, account, force=False, backend=False): def remove_contact(self, jid, account, force=False, backend=False):
'''Remove contact from roster. '''Remove contact from roster.
@ -989,8 +964,9 @@ class RosterWindow:
self.model[child_iter][C_NAME] = account_name self.model[child_iter][C_NAME] = account_name
if gajim.config.get('show_mood_in_roster') \ if gajim.config.get('show_mood_in_roster') \
and gajim.connections[account].mood.has_key('mood') \ and 'mood' in gajim.connections[account].mood \
and gajim.connections[account].mood['mood'].strip() in MOODS: and gajim.connections[account].mood['mood'].strip() in MOODS:
self.model[child_iter][C_MOOD_PIXBUF] = \ self.model[child_iter][C_MOOD_PIXBUF] = \
gtkgui_helpers.load_mood_icon( gtkgui_helpers.load_mood_icon(
gajim.connections[account].mood['mood']. \ gajim.connections[account].mood['mood']. \
@ -1656,7 +1632,7 @@ class RosterWindow:
gajim.contacts.add_account(account) gajim.contacts.add_account(account)
if account not in gajim.groups: if account not in gajim.groups:
gajim.groups[account] = {} gajim.groups[account] = {}
for jid in array.keys(): for jid in array:
# Remove the contact in roster. It might has changed # Remove the contact in roster. It might has changed
self.remove_contact(jid, account, force = True) self.remove_contact(jid, account, force = True)
# Remove old Contact instances # Remove old Contact instances
@ -6342,7 +6318,8 @@ class RosterWindow:
config.AccountCreationWizardWindow() config.AccountCreationWizardWindow()
if not gajim.ZEROCONF_ACC_NAME in gajim.config.get_per('accounts'): if not gajim.ZEROCONF_ACC_NAME in gajim.config.get_per('accounts'):
# Create zeroconf in config file # Create zeroconf in config file
zeroconf = common.zeroconf.connection_zeroconf.ConnectionZeroconf( from common.zeroconf import connection_zeroconf
zeroconf = connection_zeroconf.ConnectionZeroconf(
gajim.ZEROCONF_ACC_NAME) gajim.ZEROCONF_ACC_NAME)
if sys.platform == 'darwin': if sys.platform == 'darwin':