Changeset 9536
- Timestamp:
- 04/26/08 12:18:33 (7 months ago)
- Files:
-
- 1 modified
-
trunk/src/roster_window.py (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/roster_window.py
r9531 r9536 299 299 300 300 301 def _add_entity(self, contact, account, groups = None, big_brother_contact = None): 301 def _add_entity(self, contact, account, groups = None, big_brother_contact = None, 302 big_brother_account = None): 302 303 '''Add the given contact to roster data model. 303 304 … … 317 318 318 319 parent_iters = self._get_contact_iter(big_brother_contact.jid, 319 account, self.model)320 big_brother_account, self.model) 320 321 assert len(parent_iters) > 0,\ 321 322 "Big brother is not yet in roster!" … … 357 358 typestr, contact.jid, account, None, None)) 358 359 added_iters.append(i_) 360 361 # Restore the group expand state 362 if group not in gajim.groups[account]: 363 # FIXME: care about expand/collapse state 364 gajim.groups[account][group] = {'expand': True} 359 365 360 366 assert len(added_iters), "%s has not been added to roster!" % contact.jid … … 407 413 408 414 409 def _add_metacontact_family(self, family ):415 def _add_metacontact_family(self, family, account): 410 416 '''Add the give Metacontact family to roster data model. 411 417 … … 417 423 family -- the family, see Contacts.get_metacontacts_family() 418 424 ''' 419 big_brother_data = gajim.contacts.get_metacontacts_big_brother(family) 425 426 if self.regroup: 427 # group all together 428 nearby_family = family 429 else: 430 # we want one nearby_family per account 431 nearby_family = [data for data in family 432 if account == data['account']] 433 434 big_brother_data = gajim.contacts.get_metacontacts_big_brother(nearby_family) 420 435 big_brother_jid = big_brother_data['jid'] 421 436 big_brother_account = big_brother_data['account'] … … 423 438 424 439 assert len(self._get_contact_iter(big_brother_jid, big_brother_account, self.model)) == 0,\ 425 "Big brother %s already in roster " % big_brother_jid440 "Big brother %s already in roster \n Family: %s" % (big_brother_jid, family) 426 441 self._add_entity(big_brother_contact, big_brother_account) 427 442 428 443 brothers = [] 429 for data in family: 444 # Filter family members 445 for data in nearby_family: 430 446 if data == big_brother_data: 431 447 continue # already added … … 438 454 # Corresponding account is not connected 439 455 continue 440 456 441 457 assert len(self._get_contact_iter(_jid, _account, self.model)) == 0,\ 442 "%s already in roster" % _jid 443 self._add_entity(_contact, _account, big_brother_contact = big_brother_contact) 458 "%s already in roster. \n Family: " % (_jid, nearby_family) 459 self._add_entity(_contact, _account, big_brother_contact = big_brother_contact, 460 big_brother_account = big_brother_account) 444 461 brothers.append((_contact, _account)) 445 462 … … 448 465 449 466 450 def _remove_metacontact_family(self, family ):467 def _remove_metacontact_family(self, family, account): 451 468 '''Remove the give Metacontact family from roster data model. 452 469 453 470 See Contacts.get_metacontacts_family() and RosterWindow._remove_entity() 454 471 ''' 472 if self.regroup: 473 # remove all 474 nearby_family = family 475 else: 476 # remove nearby_family per account 477 nearby_family = [data for data in family 478 if account == data['account']] 479 455 480 # Family might has changed (actual big brother not on top). 456 # Remove in correct order: Childs first 457 for data in family: 481 # Remove childs first then big brother 482 family_in_roster = False 483 for data in nearby_family: 458 484 _account = data['account'] 459 485 _jid = data['jid'] 460 486 _contact = gajim.contacts.get_first_contact_from_jid(_account, _jid) 461 487 462 if not _contact: 463 # Corresponding account is not online 488 iters = self._get_contact_iter(_jid, _account, self.model) 489 if not iters or not _contact: 490 # Family might not be up to date. 491 # Only try to remove what is actually in the roster 464 492 continue 465 466 iters = self._get_contact_iter(_jid, _account, self.model) 467 assert iters, "%s shall be removed but is not in roster" % _jid493 assert iters, "%s shall be removed but is not in roster \n Family: %s" % (_jid, family) 494 495 family_in_roster = True 468 496 469 497 parent_iter = self.model.iter_parent(iters[0]) … … 481 509 assert len(self._get_contact_iter(_jid, _account, self.model)) == 0,\ 482 510 "%s is removed but still in roster" % _jid 483 511 512 if not family_in_roster: 513 return False 514 484 515 iters = self._get_contact_iter(old_big_jid, old_big_account, self.model) 485 516 assert len(iters) > 0, "Old Big Brother %s is not in roster anymore" % old_big_jid … … 559 590 if family: 560 591 # We have a family. So we are a metacontact. 561 # Add our whole family 562 contacts = self._add_metacontact_family(family) 592 # Add all family members that we shall be grouped with 593 if self.regroup: 594 # remove existing family members to regroup them 595 self._remove_metacontact_family(family, account) 596 contacts = self._add_metacontact_family(family, account) 563 597 else: 564 598 # We are a normal contact … … 566 600 self._add_entity(contact, account) 567 601 568 # Draw all groups of thecontact602 # Draw the contact and its groups contact 569 603 if contact.is_transport(): 570 604 contact.groups = [_('Transports')] … … 574 608 if not groups: 575 609 groups = [_('General')] 576 for group in groups:577 # Restore the group expand state578 if group not in gajim.groups[account]:579 #if account + group in self.collapsed_rows:580 #ishidden = False581 #else:582 ishidden = True583 gajim.groups[account][group] = {'expand': ishidden}584 585 if not self.starting:586 self.draw_group(group, account)587 588 610 if not self.starting: 589 611 for c, acc in contacts: 590 612 self.draw_contact(c.jid, acc) 591 613 self.draw_avatar(c.jid, acc) 614 for group in groups: 615 self.draw_group(group, account) 592 616 self.draw_account(account) 593 617 594 618 return contacts[0][0] # it's contact/big brother with highest priority 595 619 … … 618 642 if family: 619 643 # We have a family. So we are a metacontact. 620 self._remove_metacontact_family(family )644 self._remove_metacontact_family(family, account) 621 645 else: 622 646 self._remove_entity(contact, account) … … 731 755 for group in groups: 732 756 if group not in contact.groups: 733 # statement needed for drapfrom meta to group757 # we might be dropped from meta to group 734 758 contact.groups.append(group) 735 759 gajim.connections[account].update_contact(jid, contact.name, … … 962 986 family = gajim.contacts.get_metacontacts_family(account, jid) 963 987 if family: # Are we a metacontact (have a familiy) 964 big_brother_data = gajim.contacts.get_metacontacts_big_brother(family) 988 989 if self.regroup: 990 # group all together 991 nearby_family = family 992 else: 993 # we want one nearby_family per account 994 nearby_family = [data for data in family 995 if account == data['account']] 996 997 big_brother_data = gajim.contacts.get_metacontacts_big_brother(nearby_family) 965 998 big_brother_jid = big_brother_data['jid'] 966 999 big_brother_account = big_brother_data['account'] … … 976 1009 # We are the new big brother but haven't been before 977 1010 # Remove us and all our brothers and then re-add us so that 978 self._remove_metacontact_family(family )979 brothers = self._add_metacontact_family(family )1011 self._remove_metacontact_family(family, account) 1012 brothers = self._add_metacontact_family(family, account) 980 1013 big_brother_c, big_brother_acc = brothers[0] 981 1014 brothers = brothers[1:] … … 1178 1211 return False 1179 1212 if type_ == 'account': 1213 # Always show account 1180 1214 return True 1215 1181 1216 account = model[iter][C_ACCOUNT] 1182 1217 if not account: 1183 1218 return False 1219 1184 1220 account = account.decode('utf-8') 1221 if self.regroup: 1222 # C_ACCOUNT for groups depends on the order 1223 # accounts were connected 1224 # Check all accounts for online group contacts 1225 accounts = gajim.contacts.get_accounts() 1226 else: 1227 accounts = [account] 1228 1185 1229 jid = model[iter][C_JID] 1186 1230 if not jid: … … 1192 1236 if group == _('Transports'): 1193 1237 return gajim.config.get('show_transports_group') 1194 for contact in gajim.contacts.iter_contacts(account): 1195 # Is this contact in this group ? 1196 if group in contact.groups or (group == _('General') and not \ 1197 contact.groups): 1198 if self.contact_is_visible(contact, account): 1199 return True 1238 for _acc in accounts: 1239 for contact in gajim.contacts.iter_contacts(_acc): 1240 # Is this contact in this group ? 1241 if group in contact.groups or (group == _('General') and not \ 1242 contact.groups): 1243 if self.contact_is_visible(contact, _acc): 1244 return True 1200 1245 return False 1201 1246 if type_ == 'contact': … … 1904 1949 1905 1950 # If visible, try to get first line of contact in roster 1951 path = None 1906 1952 iters = self._get_contact_iter(jid, account) 1907 1953 if iters: … … 3527 3573 gajim.config.set('confirm_metacontacts', 'yes') 3528 3574 3529 # We might have dropped on a metacontact. Readd it. 3575 # We might have dropped on a metacontact. 3576 # Remove it and readd later with updated family info 3530 3577 dest_family = gajim.contacts.get_metacontacts_family(account_dest, 3531 3578 c_dest.jid) 3532 3579 if dest_family: 3533 self._remove_metacontact_family(dest_family )3580 self._remove_metacontact_family(dest_family, account_dest) 3534 3581 else: 3535 3582 self._remove_entity(c_dest, account_dest) … … 3542 3589 if was_big_brother: 3543 3590 # We have got little brothers. Readd them all 3544 self._remove_metacontact_family(old_family )3591 self._remove_metacontact_family(old_family, account_source) 3545 3592 else: 3546 3593 # We are only a litle brother. Simply remove us from our big brother 3547 self._remove_entity(c_source, account_source) 3548 3549 own_data = {} 3550 own_data['jid'] = c_source.jid 3551 own_data['account'] = account_source 3552 old_family.append(own_data) 3594 if self._get_contact_iter(c_source.jid, account_source): 3595 # When we have been in the group before. 3596 # Do not try to remove us again 3597 self._remove_entity(c_source, account_source) 3598 3599 own_data = {} 3600 own_data['jid'] = c_source.jid 3601 own_data['account'] = account_source 3602 # Don't touch the rest of the family 3603 old_family = [own_data] 3553 3604 3554 3605 # Apply new tag and update contact 3555 3606 for data in old_family: 3607 if account_source != data['account'] and not self.regroup: 3608 continue 3609 3556 3610 _account = data['account'] 3557 3611 _jid = data['jid'] … … 3567 3621 new_family = gajim.contacts.get_metacontacts_family(account_source, 3568 3622 c_source.jid) 3569 brothers = self._add_metacontact_family(new_family )3623 brothers = self._add_metacontact_family(new_family, account_source) 3570 3624 3571 3625 for c, acc in brothers: … … 3609 3663 # Remove whole family. Remove us from the family. 3610 3664 # Then re-add other family members. 3611 self._remove_metacontact_family(family )3665 self._remove_metacontact_family(family, account) 3612 3666 gajim.contacts.remove_metacontact(account, c_source.jid) 3613 3667 for data in family: 3614 if data['jid'] == c_source.jid: 3668 if account != data['account'] and not self.regroup: 3669 continue 3670 if data['jid'] == c_source.jid and\ 3671 data['account'] == account: 3615 3672 continue 3616 3673 self.add_contact(data['jid'], data['account']) … … 3620 3677 3621 3678 else: 3622 # Simplecontact3679 # Normal contact 3623 3680 self.remove_contact_from_groups(c_source.jid, account, [grp_source,]) 3624 3681 self.add_contact_to_groups(c_source.jid, account, [grp_dest,]) … … 5657 5714 sel = self.tree.get_selection() 5658 5715 sel.set_mode(gtk.SELECTION_MULTIPLE) 5659 sel.connect('changed',5660 self.on_treeview_selection_changed)5716 #sel.connect('changed', 5717 # self.on_treeview_selection_changed) 5661 5718 5662 5719 self._last_selected_contact = [] # holds a list of (jid, account) tupples
