Changeset 9123 for branches/pep/src/common/contacts.py
- Timestamp:
- 12/12/07 09:44:46 (12 months ago)
- Files:
-
- 1 modified
-
branches/pep/src/common/contacts.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pep/src/common/contacts.py
r8478 r9123 1 1 ## common/contacts.py 2 2 ## 3 ## Copyright (C) 2006 Yann Le Boulanger <asterix@lagaule.org>4 ## Copyright (C) 2006Nikos Kouremenos <kourem@gmail.com>3 ## Copyright (C) 2006 Yann Leboulanger <asterix@lagaule.org> 4 ## Nikos Kouremenos <kourem@gmail.com> 5 5 ## Copyright (C) 2007 Lukas Petrovicky <lukas@petrovicky.net> 6 ## Copyright (C) 2007 Julien Pivotto <roidelapluie@gmail.com> 6 ## Julien Pivotto <roidelapluie@gmail.com> 7 ## Stephan Erb <steve-e@h3c.de> 7 8 ## 9 ## This file is part of Gajim. 8 10 ## 9 ## This program is free software; you can redistribute it and/or modify11 ## Gajim is free software; you can redistribute it and/or modify 10 12 ## it under the terms of the GNU General Public License as published 11 ## by the Free Software Foundation; version 2only.13 ## by the Free Software Foundation; version 3 only. 12 14 ## 13 ## This program is distributed in the hope that it will be useful,15 ## Gajim is distributed in the hope that it will be useful, 14 16 ## but WITHOUT ANY WARRANTY; without even the implied warranty of 15 17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 18 ## GNU General Public License for more details. 19 ## 20 ## You should have received a copy of the GNU General Public License 21 ## along with Gajim. If not, see <http://www.gnu.org/licenses/>. 17 22 ## 18 23 … … 42 47 # Capabilities; filled by caps.py/ConnectionCaps object 43 48 # every time it gets these from presence stanzas 44 self.caps_node =None45 self.caps_ver =None46 self.caps_exts =None49 self.caps_node = None 50 self.caps_ver = None 51 self.caps_exts = None 47 52 48 53 # please read jep-85 http://www.jabber.org/jeps/jep-0085.html … … 206 211 if len(self._contacts[account][contact.jid]) == 0: 207 212 del self._contacts[account][contact.jid] 213 214 def clear_contacts(self, account): 215 self._contacts[account] = {} 208 216 209 217 def remove_jid(self, account, jid): … … 282 290 our_jid = common.gajim.get_jid_from_account(account) 283 291 for jid in self.get_jid_list(account): 292 if self.has_brother(account, jid) and not \ 293 self.is_big_brother(account, jid): 294 # count metacontacts only once 295 continue 284 296 if jid == our_jid: 285 297 continue … … 301 313 if common.gajim.jid_is_transport(jid): 302 314 contact_groups = [_('Transports')] 315 if contact.is_observer(): 316 contact_groups = [_('Observers')] 303 317 else: 304 318 contact_groups = [_('General')] … … 363 377 break 364 378 if found: 365 self._metacontacts_tags[account][tag].remove( data)379 self._metacontacts_tags[account][tag].remove(found) 366 380 break 367 381 common.gajim.connections[account].store_metacontacts( … … 372 386 tag = self.get_metacontacts_tag(account, jid) 373 387 if tag and len(self._metacontacts_tags[account][tag]) > 1: 388 return True 389 return False 390 391 def is_big_brother(self, account, jid): 392 tag = self.get_metacontacts_tag(account, jid) 393 if tag: 394 family = self.get_metacontacts_family(account, jid) 395 bb_data = self.get_metacontacts_big_brother(family) 396 bb_jid = bb_data['jid'] 397 bb_account = bb_data['account'] 398 if bb_jid == jid and bb_account == account: 374 399 return True 375 400 return False … … 400 425 return answers 401 426 402 def _get_data_score(self, data): 403 '''compute thescore of a gived data 404 data is {'jid': jid, 'account': account, 'order': order} 405 order is optional 406 score = (max_order - order)*10000 + is_jabber*priority*10 + status''' 407 jid = data['jid'] 408 account = data['account'] 409 max_order = 0 410 order = 0 411 if data.has_key('order'): 412 order = data['order'] 413 if order: 414 family = self.get_metacontacts_family(account, jid) 415 for data_ in family: 416 if data_.has_key('order') and data_['order'] > max_order: 417 max_order = data_['order'] 418 contact = self.get_contact_with_highest_priority(account, jid) 419 score = (max_order - order)*10000 420 421 if common.gajim.get_transport_name_from_jid(jid) is None and \ 422 contact.show not in ('error', 'offline'): 423 score += 10 424 if contact.priority > 0: 425 score += contact.priority * 10 426 score += ['not in roster', 'error', 'offline', 'invisible', 'dnd', 'xa', 427 'away', 'chat', 'online', 'requested', 'message'].index(contact.show) 428 if contact.show == 'offline' and contact.status: 429 # Offline contacts with a status message have highest score 430 score += 1 431 return score 427 def compare_metacontacts(self, data1, data2): 428 '''compare 2 metacontacts. 429 Data is {'jid': jid, 'account': account, 'order': order} 430 order is optional''' 431 jid1 = data1['jid'] 432 jid2 = data2['jid'] 433 account1 = data1['account'] 434 account2 = data2['account'] 435 contact1 = self.get_contact_with_highest_priority(account1, jid1) 436 contact2 = self.get_contact_with_highest_priority(account2, jid2) 437 show_list = ['not in roster', 'error', 'offline', 'invisible', 'dnd', 438 'xa', 'away', 'chat', 'online', 'requested', 'message'] 439 # contact can be null when we fill the roster on connection 440 if not contact1: 441 show1 = 0 442 priority1 = 0 443 else: 444 show1 = show_list.index(contact1.show) 445 priority1 = contact1.priority 446 if not contact2: 447 show2 = 0 448 priority2 = 0 449 else: 450 show2 = show_list.index(contact2.show) 451 priority2 = contact2.priority 452 # If only one is offline, it's always second 453 if show1 > 2 and show2 < 3: 454 return 1 455 if show2 > 2 and show1 < 3: 456 return -1 457 if 'order' in data1 and 'order' in data2: 458 if data1['order'] > data2['order']: 459 return 1 460 if data1['order'] < data2['order']: 461 return -1 462 transport1 = common.gajim.get_transport_name_from_jid(jid1) 463 transport2 = common.gajim.get_transport_name_from_jid(jid2) 464 if transport2 and not transport1: 465 return 1 466 if transport1 and not transport2: 467 return -1 468 if priority1 > priority2: 469 return 1 470 if priority2 > priority1: 471 return -1 472 if show1 > show2: 473 return 1 474 if show2 > show1: 475 return -1 476 if jid1 > jid2: 477 return 1 478 if jid2 > jid1: 479 return -1 480 # If all is the same, compare accounts, they can't be the same 481 if account1 > account2: 482 return 1 483 if account2 > account1: 484 return -1 485 return 0 432 486 433 487 def get_metacontacts_big_brother(self, family): 434 488 '''which of the family will be the big brother under wich all 435 489 others will be ?''' 436 max_score = 0 437 max_data = family[0] 438 for data in family: 439 score = self._get_data_score(data) 440 if score > max_score: 441 max_score = score 442 max_data = data 443 return max_data 490 family.sort(cmp=self.compare_metacontacts) 491 return family[-1] 444 492 445 493 def is_pm_from_jid(self, account, jid):
