Shrink public interface of the MetacontactManager.

This commit is contained in:
Stephan Erb 2009-11-12 22:58:45 +01:00
parent ee5eb8b546
commit 36fb5def4b
4 changed files with 36 additions and 39 deletions

View File

@ -581,11 +581,10 @@ class MetacontactManager():
#FIXME: can this append ? #FIXME: can this append ?
assert False assert False
def get_metacontacts_tags(self, account): def iter_metacontacts_families(self, account):
'''return a list of tags for a given account''' for tag in self._metacontacts_tags[account]:
if not account in self._metacontacts_tags: family = self._get_metacontacts_family_from_tag(account, tag)
return [] yield family
return self._metacontacts_tags[account].keys()
def _get_metacontacts_tag(self, account, jid): def _get_metacontacts_tag(self, account, jid):
'''Returns the tag of a jid''' '''Returns the tag of a jid'''
@ -643,7 +642,7 @@ class MetacontactManager():
tag = self._get_metacontacts_tag(account, jid) tag = self._get_metacontacts_tag(account, jid)
if not tag: if not tag:
return False return False
meta_jids = self.get_metacontacts_jids(tag, accounts) meta_jids = self._get_metacontacts_jids(tag, accounts)
return len(meta_jids) > 1 or len(meta_jids[account]) > 1 return len(meta_jids) > 1 or len(meta_jids[account]) > 1
def is_big_brother(self, account, jid, accounts): def is_big_brother(self, account, jid, accounts):
@ -651,12 +650,12 @@ class MetacontactManager():
if family: if family:
nearby_family = [data for data in family nearby_family = [data for data in family
if account in accounts] if account in accounts]
bb_data = self.get_metacontacts_big_brother(nearby_family) bb_data = self._get_metacontacts_big_brother(nearby_family)
if bb_data['jid'] == jid and bb_data['account'] == account: if bb_data['jid'] == jid and bb_data['account'] == account:
return True return True
return False return False
def get_metacontacts_jids(self, tag, accounts): def _get_metacontacts_jids(self, tag, accounts):
'''Returns all jid for the given tag in the form {acct: [jid1, jid2],.}''' '''Returns all jid for the given tag in the form {acct: [jid1, jid2],.}'''
answers = {} answers = {}
for account in self._metacontacts_tags: for account in self._metacontacts_tags:
@ -673,9 +672,9 @@ class MetacontactManager():
[{'account': acct, 'jid': jid, 'order': order}, ] [{'account': acct, 'jid': jid, 'order': order}, ]
'order' is optional''' 'order' is optional'''
tag = self._get_metacontacts_tag(account, jid) tag = self._get_metacontacts_tag(account, jid)
return self.get_metacontacts_family_from_tag(account, tag) return self._get_metacontacts_family_from_tag(account, tag)
def get_metacontacts_family_from_tag(self, account, tag): def _get_metacontacts_family_from_tag(self, account, tag):
if not tag: if not tag:
return [] return []
answers = [] answers = []
@ -766,7 +765,29 @@ class MetacontactManager():
return -1 return -1
return 0 return 0
def get_metacontacts_big_brother(self, family): def get_nearby_family_and_big_brother(self, family, account):
'''Return the nearby family and its Big Brother
Nearby family is the part of the family that is grouped with the metacontact.
A metacontact may be over different accounts. If accounts are not merged
then the given family is split account wise.
(nearby_family, big_brother_jid, big_brother_account)
'''
if common.gajim.config.get('mergeaccounts'):
# group all together
nearby_family = family
else:
# we want one nearby_family per account
nearby_family = [data for data in family if account == data['account']]
big_brother_data = self._get_metacontacts_big_brother(nearby_family)
big_brother_jid = big_brother_data['jid']
big_brother_account = big_brother_data['account']
return (nearby_family, big_brother_jid, big_brother_account)
def _get_metacontacts_big_brother(self, family):
'''which of the family will be the big brother under wich all '''which of the family will be the big brother under wich all
others will be ?''' others will be ?'''
family.sort(cmp=self._compare_metacontacts) family.sort(cmp=self._compare_metacontacts)

View File

@ -2145,7 +2145,7 @@ class Interface:
family = gajim.contacts.get_metacontacts_family(account, jid) family = gajim.contacts.get_metacontacts_family(account, jid)
if family: if family:
nearby_family, bb_jid, bb_account = \ nearby_family, bb_jid, bb_account = \
self.roster._get_nearby_family_and_big_brother(family, account) gajim.contacts.get_nearby_family_and_big_brother(family, account)
else: else:
bb_jid, bb_account = jid, account bb_jid, bb_account = jid, account
self.roster.select_contact(bb_jid, bb_account) self.roster.select_contact(bb_jid, bb_account)

View File

@ -604,29 +604,7 @@ class RosterWindow:
big_brother_account=big_brother_account) big_brother_account=big_brother_account)
def _get_nearby_family_and_big_brother(self, family, account): def _get_nearby_family_and_big_brother(self, family, account):
'''Return the nearby family and its Big Brother return gajim.contacts.get_nearby_family_and_big_brother(family, account)
Nearby family is the part of the family that is grouped with the metacontact.
A metacontact may be over different accounts. If regroup is s False the
given family is split account wise.
(nearby_family, big_brother_jid, big_brother_account)
'''
if self.regroup:
# group all together
nearby_family = family
else:
# we want one nearby_family per account
nearby_family = [data for data in family
if account == data['account']]
big_brother_data = gajim.contacts.get_metacontacts_big_brother(
nearby_family)
big_brother_jid = big_brother_data['jid']
big_brother_account = big_brother_data['account']
return (nearby_family, big_brother_jid, big_brother_account)
def _add_self_contact(self, account): def _add_self_contact(self, account):
'''Add account's SelfContact to roster and draw it and the account. '''Add account's SelfContact to roster and draw it and the account.
@ -649,10 +627,8 @@ class RosterWindow:
return contact return contact
def redraw_metacontacts(self, account): def redraw_metacontacts(self, account):
for tag in gajim.contacts.get_metacontacts_tags(account): for family in gajim.contacts.iter_metacontacts_families(account):
family = gajim.contacts.get_metacontacts_family_from_tag(account, tag)
self._recalibrate_metacontact_family(family, account) self._recalibrate_metacontact_family(family, account)
def add_contact(self, jid, account): def add_contact(self, jid, account):

View File

@ -382,7 +382,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
family = gajim.contacts.get_metacontacts_family(self.conn.name, jid) family = gajim.contacts.get_metacontacts_family(self.conn.name, jid)
if family: if family:
nearby_family, bb_jid, bb_account = \ nearby_family, bb_jid, bb_account = \
gajim.interface.roster._get_nearby_family_and_big_brother(family, gajim.contacts.get_nearby_family_and_big_brother(family,
self.conn.name) self.conn.name)
else: else:
bb_jid, bb_account = jid, self.conn.name bb_jid, bb_account = jid, self.conn.name