Make methods of MetacontactManager private if those are only used internally

This commit is contained in:
Stephan Erb 2009-11-05 20:09:26 +01:00
parent 0abb1dfd20
commit f297aa0a11
2 changed files with 29 additions and 36 deletions

View file

@ -219,7 +219,7 @@ class Contacts:
self._contacts = {} # list of contacts {acct: {jid1: [C1, C2]}, } one Contact per resource self._contacts = {} # list of contacts {acct: {jid1: [C1, C2]}, } one Contact per resource
self._gc_contacts = {} # list of contacts that are in gc {acct: {room_jid: {nick: C}}} self._gc_contacts = {} # list of contacts that are in gc {acct: {room_jid: {nick: C}}}
self._metacontact_manager = MetacontactManager(); self._metacontact_manager = MetacontactManager(self);
def change_account_name(self, old_name, new_name): def change_account_name(self, old_name, new_name):
self._contacts[new_name] = self._contacts[old_name] self._contacts[new_name] = self._contacts[old_name]
@ -421,43 +421,34 @@ class Contacts:
return nbr_online, nbr_total return nbr_online, nbr_total
def define_metacontacts(self, account, tags_list): def define_metacontacts(self, account, tags_list):
self._metacontact_manager.define_metacontacts(account, tags_list) return self._metacontact_manager.define_metacontacts(account, tags_list)
def get_new_metacontacts_tag(self, jid):
self._metacontact_manager.get_new_metacontacts_tag(jid)
def get_metacontacts_tags(self, account): def get_metacontacts_tags(self, account):
self._metacontact_manager.get_metacontacts_tags(account) return self._metacontact_manager.get_metacontacts_tags(account)
def get_metacontacts_tag(self, account, jid):
self._metacontact_manager.get_metacontacts_tag(account, jid)
def add_metacontact(self, brother_account, brother_jid, account, jid, order=None): def add_metacontact(self, brother_account, brother_jid, account, jid, order=None):
self._metacontact_manager.add_metacontact(brother_account, brother_jid, account, jid, order) return self._metacontact_manager.add_metacontact(brother_account, brother_jid, account, jid, order)
def remove_metacontact(self, account, jid): def remove_metacontact(self, account, jid):
self._metacontact_manager.remove_metacontact(account, jid) return self._metacontact_manager.remove_metacontact(account, jid)
def has_brother(self, account, jid, accounts): def has_brother(self, account, jid, accounts):
self._metacontact_manager.has_brother(account, jid, accounts) return self._metacontact_manager.has_brother(account, jid, accounts)
def is_big_brother(self, account, jid, accounts): def is_big_brother(self, account, jid, accounts):
self._metacontact_manager.is_big_brother(account, jid, accounts) return self._metacontact_manager.is_big_brother(account, jid, accounts)
def get_metacontacts_jids(self, tag, accounts): def get_metacontacts_jids(self, tag, accounts):
self._metacontact_manager.get_metacontacts_jids(tag, accounts) return self._metacontact_manager.get_metacontacts_jids(tag, accounts)
def get_metacontacts_family(self, account, jid): def get_metacontacts_family(self, account, jid):
self._metacontact_manager.get_metacontacts_family(account, jid) return self._metacontact_manager.get_metacontacts_family(account, jid)
def get_metacontacts_family_from_tag(self, account, tag): def get_metacontacts_family_from_tag(self, account, tag):
self._metacontact_manager.get_metacontacts_family_from_tag(account, tag) return self._metacontact_manager.get_metacontacts_family_from_tag(account, tag)
def compare_metacontacts(self, data1, data2):
self._metacontact_manager.compare_metacontacts(data1, data2)
def get_metacontacts_big_brother(self, family): def get_metacontacts_big_brother(self, family):
self._metacontact_manager.get_metacontacts_big_brother(family) return self._metacontact_manager.get_metacontacts_big_brother(family)
def is_pm_from_jid(self, account, jid): def is_pm_from_jid(self, account, jid):
'''Returns True if the given jid is a private message jid''' '''Returns True if the given jid is a private message jid'''
@ -549,8 +540,9 @@ class Contacts:
class MetacontactManager(): class MetacontactManager():
def __init__(self): def __init__(self, contacts):
self._metacontacts_tags = {} self._metacontacts_tags = {}
self._contacts = contacts
def change_account_name(self, old_name, new_name): def change_account_name(self, old_name, new_name):
self._metacontacts_tags[new_name] = self._metacontacts_tags[old_name] self._metacontacts_tags[new_name] = self._metacontacts_tags[old_name]
@ -566,7 +558,7 @@ class MetacontactManager():
def define_metacontacts(self, account, tags_list): def define_metacontacts(self, account, tags_list):
self._metacontacts_tags[account] = tags_list self._metacontacts_tags[account] = tags_list
def get_new_metacontacts_tag(self, jid): def _get_new_metacontacts_tag(self, jid):
if not jid in self._metacontacts_tags: if not jid in self._metacontacts_tags:
return jid return jid
#FIXME: can this append ? #FIXME: can this append ?
@ -578,7 +570,7 @@ class MetacontactManager():
return [] return []
return self._metacontacts_tags[account].keys() 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'''
if not account in self._metacontacts_tags: if not account in self._metacontacts_tags:
return None return None
@ -589,19 +581,19 @@ class MetacontactManager():
return None return None
def add_metacontact(self, brother_account, brother_jid, account, jid, order=None): def add_metacontact(self, brother_account, brother_jid, account, jid, order=None):
tag = self.get_metacontacts_tag(brother_account, brother_jid) tag = self._get_metacontacts_tag(brother_account, brother_jid)
if not tag: if not tag:
tag = self.get_new_metacontacts_tag(brother_jid) tag = self._get_new_metacontacts_tag(brother_jid)
self._metacontacts_tags[brother_account][tag] = [{'jid': brother_jid, self._metacontacts_tags[brother_account][tag] = [{'jid': brother_jid,
'tag': tag}] 'tag': tag}]
if brother_account != account: if brother_account != account:
common.gajim.connections[brother_account].store_metacontacts( common.gajim.connections[brother_account].store_metacontacts(
self._metacontacts_tags[brother_account]) self._metacontacts_tags[brother_account])
# be sure jid has no other tag # be sure jid has no other tag
old_tag = self.get_metacontacts_tag(account, jid) old_tag = self._get_metacontacts_tag(account, jid)
while old_tag: while old_tag:
self.remove_metacontact(account, jid) self.remove_metacontact(account, jid)
old_tag = self.get_metacontacts_tag(account, jid) old_tag = self._get_metacontacts_tag(account, jid)
if tag not in self._metacontacts_tags[account]: if tag not in self._metacontacts_tags[account]:
self._metacontacts_tags[account][tag] = [{'jid': jid, 'tag': tag}] self._metacontacts_tags[account][tag] = [{'jid': jid, 'tag': tag}]
else: else:
@ -615,6 +607,9 @@ class MetacontactManager():
self._metacontacts_tags[account]) self._metacontacts_tags[account])
def remove_metacontact(self, account, jid): def remove_metacontact(self, account, jid):
if not account in self._metacontacts_tags:
return None
found = None found = None
for tag in self._metacontacts_tags[account]: for tag in self._metacontacts_tags[account]:
for data in self._metacontacts_tags[account][tag]: for data in self._metacontacts_tags[account][tag]:
@ -628,7 +623,7 @@ class MetacontactManager():
break break
def has_brother(self, account, jid, accounts): def has_brother(self, account, jid, accounts):
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)
@ -660,7 +655,7 @@ class MetacontactManager():
'''return the family of the given jid, including jid in the form: '''return the family of the given jid, including jid in the form:
[{'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):
@ -674,7 +669,7 @@ class MetacontactManager():
answers.append(data) answers.append(data)
return answers return answers
def compare_metacontacts(self, data1, data2): def _compare_metacontacts(self, data1, data2):
'''compare 2 metacontacts. '''compare 2 metacontacts.
Data is {'jid': jid, 'account': account, 'order': order} Data is {'jid': jid, 'account': account, 'order': order}
order is optional''' order is optional'''
@ -682,8 +677,8 @@ class MetacontactManager():
jid2 = data2['jid'] jid2 = data2['jid']
account1 = data1['account'] account1 = data1['account']
account2 = data2['account'] account2 = data2['account']
contact1 = self.get_contact_with_highest_priority(account1, jid1) contact1 = self._contacts.get_contact_with_highest_priority(account1, jid1)
contact2 = self.get_contact_with_highest_priority(account2, jid2) contact2 = self._contacts.get_contact_with_highest_priority(account2, jid2)
show_list = ['not in roster', 'error', 'offline', 'invisible', 'dnd', show_list = ['not in roster', 'error', 'offline', 'invisible', 'dnd',
'xa', 'away', 'chat', 'online', 'requested', 'message'] 'xa', 'away', 'chat', 'online', 'requested', 'message']
# contact can be null when a jid listed in the metacontact data # contact can be null when a jid listed in the metacontact data
@ -757,7 +752,7 @@ class MetacontactManager():
def get_metacontacts_big_brother(self, family): 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)
return family[-1] return family[-1]
# vim: se ts=3: # vim: se ts=3:

View file

@ -689,8 +689,6 @@ class RosterWindow:
is_observer = contact.is_observer() is_observer = contact.is_observer()
if 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)
if tag:
gajim.contacts.remove_metacontact(account, jid) gajim.contacts.remove_metacontact(account, jid)
# Add contact to roster # Add contact to roster