Changeset 9536

Show
Ignore:
Timestamp:
04/26/08 12:18:33 (7 months ago)
Author:
steve-e
Message:

Fixing a few modelfilter bugs.

  • Show all groups in merged accounts view that have online contacts. Fixes #3890
  • Allow metacontacts over several accounts. Fixes #3889
  • Fix on_drop_in_group when two accounts in merged view have the same contact
  • Fix potential traceback when receiving a message
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/roster_window.py

    r9531 r9536  
    299299 
    300300         
    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): 
    302303                '''Add the given contact to roster data model. 
    303304                 
     
    317318 
    318319                        parent_iters = self._get_contact_iter(big_brother_contact.jid, 
    319                                 account, self.model) 
     320                                big_brother_account, self.model) 
    320321                        assert len(parent_iters) > 0,\ 
    321322                                "Big brother is not yet in roster!" 
     
    357358                                        typestr, contact.jid, account, None, None)) 
    358359                                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} 
    359365                 
    360366                assert len(added_iters), "%s has not been added to roster!" % contact.jid  
     
    407413 
    408414 
    409         def _add_metacontact_family(self, family): 
     415        def _add_metacontact_family(self, family, account): 
    410416                '''Add the give Metacontact family to roster data model. 
    411417                 
     
    417423                family -- the family, see Contacts.get_metacontacts_family() 
    418424                ''' 
    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) 
    420435                big_brother_jid = big_brother_data['jid'] 
    421436                big_brother_account = big_brother_data['account'] 
     
    423438 
    424439                assert len(self._get_contact_iter(big_brother_jid, big_brother_account, self.model)) == 0,\ 
    425                         "Big brother %s already in roster" % big_brother_jid 
     440                        "Big brother %s already in roster  \n Family: %s" % (big_brother_jid, family) 
    426441                self._add_entity(big_brother_contact, big_brother_account) 
    427442                 
    428443                brothers = [] 
    429                 for data in family: 
     444                # Filter family members 
     445                for data in nearby_family: 
    430446                        if data == big_brother_data: 
    431447                                continue # already added 
     
    438454                                # Corresponding account is not connected 
    439455                                continue 
    440  
     456                         
    441457                        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) 
    444461                        brothers.append((_contact, _account)) 
    445462 
     
    448465 
    449466 
    450         def _remove_metacontact_family(self, family): 
     467        def _remove_metacontact_family(self, family, account): 
    451468                '''Remove the give Metacontact family from roster data model. 
    452469                 
    453470                See Contacts.get_metacontacts_family() and RosterWindow._remove_entity() 
    454471                ''' 
     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 
    455480                # 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: 
    458484                        _account = data['account'] 
    459485                        _jid = data['jid'] 
    460486                        _contact = gajim.contacts.get_first_contact_from_jid(_account, _jid) 
    461487                         
    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 
    464492                                continue 
    465                          
    466                         iters = self._get_contact_iter(_jid, _account, self.model) 
    467                         assert iters, "%s shall be removed but is not in roster" % _jid 
     493                        assert iters, "%s shall be removed but is not in roster \n Family: %s" % (_jid, family) 
     494 
     495                        family_in_roster = True 
    468496 
    469497                        parent_iter = self.model.iter_parent(iters[0]) 
     
    481509                        assert len(self._get_contact_iter(_jid, _account, self.model)) == 0,\ 
    482510                                "%s is removed but still in roster" % _jid 
    483                  
     511         
     512                if not family_in_roster: 
     513                        return False 
     514 
    484515                iters = self._get_contact_iter(old_big_jid, old_big_account, self.model) 
    485516                assert len(iters) > 0, "Old Big Brother %s is not in roster anymore" % old_big_jid 
     
    559590                if family: 
    560591                        # 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) 
    563597                else: 
    564598                        # We are a normal contact 
     
    566600                        self._add_entity(contact, account) 
    567601 
    568                 # Draw all groups of the contact 
     602                # Draw the contact and its groups contact 
    569603                if contact.is_transport(): 
    570604                        contact.groups = [_('Transports')] 
     
    574608                if not groups: 
    575609                        groups = [_('General')] 
    576                 for group in groups:                     
    577                         # Restore the group expand state 
    578                         if group not in gajim.groups[account]: 
    579                                 #if account + group in self.collapsed_rows: 
    580                                 #ishidden = False 
    581                                 #else: 
    582                                 ishidden = True 
    583                                 gajim.groups[account][group] = {'expand': ishidden} 
    584  
    585                         if not self.starting:                    
    586                                 self.draw_group(group, account) 
    587                  
    588610                if not self.starting:    
    589611                        for c, acc in contacts: 
    590612                                self.draw_contact(c.jid, acc) 
    591613                                self.draw_avatar(c.jid, acc) 
     614                        for group in groups:                     
     615                                self.draw_group(group, account) 
    592616                        self.draw_account(account) 
    593                          
     617 
    594618                return contacts[0][0] # it's contact/big brother with highest priority 
    595619 
     
    618642                if family: 
    619643                        # We have a family. So we are a metacontact. 
    620                         self._remove_metacontact_family(family) 
     644                        self._remove_metacontact_family(family, account) 
    621645                else:  
    622646                        self._remove_entity(contact, account) 
     
    731755                        for group in groups: 
    732756                                if group not in contact.groups: 
    733                                         # statement needed for drap from meta to group 
     757                                        # we might be dropped from meta to group 
    734758                                        contact.groups.append(group) 
    735759                        gajim.connections[account].update_contact(jid, contact.name, 
     
    962986                family = gajim.contacts.get_metacontacts_family(account, jid) 
    963987                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) 
    965998                        big_brother_jid = big_brother_data['jid'] 
    966999                        big_brother_account = big_brother_data['account'] 
     
    9761009                                        # We are the new big brother but haven't been before 
    9771010                                        # 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) 
    9801013                                        big_brother_c, big_brother_acc = brothers[0] 
    9811014                                        brothers = brothers[1:] 
     
    11781211                        return False 
    11791212                if type_ == 'account': 
     1213                        # Always show account 
    11801214                        return True 
     1215 
    11811216                account = model[iter][C_ACCOUNT] 
    11821217                if not account: 
    11831218                        return False 
     1219 
    11841220                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 
    11851229                jid = model[iter][C_JID] 
    11861230                if not jid: 
     
    11921236                        if group == _('Transports'): 
    11931237                                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 
    12001245                        return False 
    12011246                if type_ == 'contact': 
     
    19041949                 
    19051950                # If visible, try to get first line of contact in roster 
     1951                path = None 
    19061952                iters = self._get_contact_iter(jid, account) 
    19071953                if iters: 
     
    35273573                                        gajim.config.set('confirm_metacontacts', 'yes') 
    35283574                         
    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 
    35303577                        dest_family = gajim.contacts.get_metacontacts_family(account_dest, 
    35313578                                c_dest.jid) 
    35323579                        if dest_family: 
    3533                                 self._remove_metacontact_family(dest_family) 
     3580                                self._remove_metacontact_family(dest_family, account_dest) 
    35343581                        else: 
    35353582                                self._remove_entity(c_dest, account_dest) 
     
    35423589                        if was_big_brother: 
    35433590                                # We have got little brothers. Readd them all 
    3544                                 self._remove_metacontact_family(old_family) 
     3591                                self._remove_metacontact_family(old_family, account_source) 
    35453592                        else:    
    35463593                                # 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] 
    35533604                         
    35543605                        # Apply new tag and update contact 
    35553606                        for data in old_family: 
     3607                                if account_source != data['account'] and not self.regroup: 
     3608                                        continue 
     3609 
    35563610                                _account = data['account'] 
    35573611                                _jid = data['jid'] 
     
    35673621                        new_family = gajim.contacts.get_metacontacts_family(account_source, 
    35683622                                c_source.jid) 
    3569                         brothers = self._add_metacontact_family(new_family) 
     3623                        brothers = self._add_metacontact_family(new_family, account_source) 
    35703624                         
    35713625                        for c, acc in brothers: 
     
    36093663                                # Remove whole family. Remove us from the family. 
    36103664                                # Then re-add other family members. 
    3611                                 self._remove_metacontact_family(family) 
     3665                                self._remove_metacontact_family(family, account) 
    36123666                                gajim.contacts.remove_metacontact(account, c_source.jid) 
    36133667                                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: 
    36153672                                                continue 
    36163673                                        self.add_contact(data['jid'], data['account']) 
     
    36203677 
    36213678                        else: 
    3622                                 # Simple contact 
     3679                                # Normal contact 
    36233680                                self.remove_contact_from_groups(c_source.jid, account, [grp_source,]) 
    36243681                                self.add_contact_to_groups(c_source.jid, account, [grp_dest,]) 
     
    56575714                sel = self.tree.get_selection() 
    56585715                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) 
    56615718 
    56625719                self._last_selected_contact = [] # holds a list of (jid, account) tupples