Show
Ignore:
Timestamp:
07/25/08 01:53:56 (4 months ago)
Author:
js
Message:

Show mood in roster & coding style.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/roster_window.py

    r9985 r10022  
    6363 
    6464from common.xmpp.protocol import NS_COMMANDS, NS_FILE, NS_MUC 
     65from common.pep import MOODS 
    6566 
    6667try: 
     
    7677C_JID, # the jid of the row 
    7778C_ACCOUNT, # cellrenderer text that holds account name 
     79C_MOOD, 
    7880C_AVATAR_PIXBUF, # avatar_pixbuf 
    7981C_PADLOCK_PIXBUF, # use for account row only 
    80 ) = range(7) 
     82) = range(8) 
    8183 
    8284class RosterWindow: 
     
    8486 
    8587        def _get_account_iter(self, name, model = None): 
    86                 ''' Return the gtk.TreeIter of the given account or None if not found. 
     88                ''' 
     89                Return the gtk.TreeIter of the given account or None 
     90                if not found. 
    8791 
    8892                Keyword arguments: 
    8993                name -- the account name 
    9094                model -- the data model (default TreeFilterModel) 
    91  
    9295                ''' 
    9396                if not model: 
     
    106109 
    107110 
    108         def _get_group_iter(self, name, account, account_iter = None, model = None): 
    109                 ''' Return the gtk.TreeIter of the given group or None if not found. 
     111        def _get_group_iter(self, name, account, account_iter = None, 
     112        model = None): 
     113                ''' 
     114                Return the gtk.TreeIter of the given group or None if not found. 
    110115 
    111116                Keyword arguments: 
     
    168173                if not model: 
    169174                        model = self.modelfilter 
    170                         if model is None: # when closing Gajim model can be none (async pbs?) 
     175                        # when closing Gajim model can be none (async pbs?) 
     176                        if model is None: 
    171177                                return [] 
    172178 
    173179                if jid == gajim.get_jid_from_account(account): 
    174                         contact_iter = self._get_self_contact_iter(jid, account, model) 
     180                        contact_iter = self._get_self_contact_iter(jid, 
     181                                account, model) 
    175182                        if contact_iter: 
    176183                                return [contact_iter] 
     
    179186 
    180187                if not contact: 
    181                         contact = gajim.contacts.get_first_contact_from_jid(account, jid) 
     188                        contact = gajim.contacts.get_first_contact_from_jid( 
     189                                account, jid) 
    182190                        if not contact: 
    183191                                # We don't know this contact 
     
    187195                found = [] # the contact iters. One per group 
    188196                for group in contact.get_shown_groups(): 
    189                         group_iter = self._get_group_iter(group, account, acct,  model) 
     197                        group_iter = self._get_group_iter(group, account, 
     198                                acct,  model) 
    190199                        contact_iter = model.iter_children(group_iter) 
    191200 
     
    193202                                # Loop over all contacts in this group 
    194203                                iter_jid = model[contact_iter][C_JID] 
    195                                 if iter_jid and jid == iter_jid.decode('utf-8') and \ 
    196                                 account == model[contact_iter][C_ACCOUNT].decode('utf-8'): 
     204                                if iter_jid and \ 
     205                                jid == iter_jid.decode('utf-8') and account == \ 
     206                                model[contact_iter][C_ACCOUNT].decode('utf-8'): 
    197207                                        # only one iter per group 
    198208                                        found.append(contact_iter) 
     
    200210                                elif model.iter_has_child(contact_iter): 
    201211                                        # it's a big brother and has children 
    202                                         contact_iter = model.iter_children(contact_iter) 
     212                                        contact_iter = model.iter_children( 
     213                                                contact_iter) 
    203214                                else: 
    204215                                        # try to find next contact: 
    205                                         # other contact in this group or brother contact 
    206                                         next_contact_iter = model.iter_next(contact_iter) 
     216                                        # other contact in this group or 
     217                                        # brother contact 
     218                                        next_contact_iter = model.iter_next( 
     219                                                contact_iter) 
    207220                                        if next_contact_iter: 
    208221                                                contact_iter = next_contact_iter 
    209222                                        else: 
    210                                                 # It's the last one. Go up if we are big brother 
    211                                                 parent_iter = model.iter_parent(contact_iter) 
    212                                                 if parent_iter and model[parent_iter][C_TYPE] == 'contact': 
    213                                                         contact_iter = model.iter_next(parent_iter) 
     223                                                # It's the last one. 
     224                                                # Go up if we are big brother 
     225                                                parent_iter = model.iter_parent( 
     226                                                        contact_iter) 
     227                                                if parent_iter and \ 
     228                                                model[parent_iter][C_TYPE] == \ 
     229                                                'contact': 
     230                                                        contact_iter = \ 
     231                                                                model.iter_next( 
     232                                                                parent_iter) 
    214233                                                else: 
    215                                                         # we tested all contacts in this group 
     234                                                        # we tested all  
     235                                                        # contacts in this group 
    216236                                                        contact_iter = None 
    217237                return found 
     
    245265                                while contact_iter: 
    246266                                        yield model[contact_iter] 
    247                                         contact_iter = model.iter_next(contact_iter) 
     267                                        contact_iter = model.iter_next( 
     268                                                contact_iter) 
    248269                                group_iter = model.iter_next(group_iter) 
    249270                        account_iter = model.iter_next(account_iter) 
     
    255276 
    256277        def add_account(self, account): 
    257                 '''Add account to roster and draw it. Do nothing if it is already in.''' 
     278                ''' 
     279                Add account to roster and draw it. Do nothing if it is 
     280                already in. 
     281                ''' 
    258282                if self._get_account_iter(account): 
    259283                        # Will happen on reconnect or for merged accounts 
     
    263287                        # Merged accounts view 
    264288                        show = helpers.get_global_show() 
    265                         self.model.append(None, [gajim.interface.jabber_state_images['16'][ 
    266                                 show], _('Merged accounts'), 'account', '', 'all', None, None]) 
    267                 else: 
    268                         show = gajim.SHOW_LIST[gajim.connections[account].connected] 
     289                        self.model.append(None, [ 
     290                                gajim.interface.jabber_state_images['16'][show], 
     291                                _('Merged accounts'), 'account', '', 'all', 
     292                                None, None, None]) 
     293                else: 
     294                        show = gajim.SHOW_LIST[gajim.connections[account]. \ 
     295                                connected] 
    269296                        our_jid = gajim.get_jid_from_account(account) 
    270297 
     
    273300                                # the only way to create a pixbuf from stock 
    274301                                tls_pixbuf = self.window.render_icon( 
    275                                         gtk.STOCK_DIALOG_AUTHENTICATION, gtk.ICON_SIZE_MENU) 
    276  
    277                         self.model.append(None, [gajim.interface.jabber_state_images['16'][ 
    278                                 show], gobject.markup_escape_text(account), 'account', our_jid, 
    279                                 account, None, tls_pixbuf]) 
     302                                        gtk.STOCK_DIALOG_AUTHENTICATION, 
     303                                        gtk.ICON_SIZE_MENU) 
     304 
     305                        self.model.append(None, [ 
     306                                gajim.interface.jabber_state_images['16'][show], 
     307                                gobject.markup_escape_text(account), 'account', 
     308                                our_jid, account, None, None, tls_pixbuf]) 
    280309 
    281310                self.draw_account(account) 
     
    316345                contact -- the contact to add 
    317346                account -- the contacts account 
    318                 groups -- list of groups to add the contact to. (default groups in  
    319                                                 contact.get_shown_groups()). 
     347                groups -- list of groups to add the contact to. 
     348                          (default groups in contact.get_shown_groups()). 
    320349                        Parameter ignored when big_brother_contact is specified. 
    321                 big_brother_contact -- if specified contact is added as child  
    322                                                                                 big_brother_contact. (default None) 
     350                big_brother_contact -- if specified contact is added as child 
     351                          big_brother_contact. (default None) 
    323352                ''' 
    324353                added_iters = [] 
     
    326355                        # Add contact under big brother 
    327356 
    328                         parent_iters = self._get_contact_iter(big_brother_contact.jid, 
    329                                 big_brother_account, big_brother_contact, self.model) 
     357                        parent_iters = self._get_contact_iter( 
     358                                big_brother_contact.jid, big_brother_account, 
     359                                big_brother_contact, self.model) 
    330360                        assert len(parent_iters) > 0,\ 
    331361                                'Big brother is not yet in roster!' 
     
    333363                        # Do not confuse get_contact_iter 
    334364                        # Sync groups of family members 
    335                         contact.groups = big_brother_contact.get_shown_groups()[:] 
     365                        contact.groups = \ 
     366                                big_brother_contact.get_shown_groups()[:] 
    336367 
    337368                        for child_iter in parent_iters: 
    338                                 it = self.model.append(child_iter, (None, contact.get_shown_name(), 
    339                                         'contact', contact.jid, account, None, None)) 
     369                                it = self.model.append(child_iter, (None, 
     370                                        contact.get_shown_name(), 'contact', 
     371                                        contact.jid, account, None, None, None)) 
    340372                                added_iters.append(it) 
    341373                else: 
     
    344376                                groups = contact.get_shown_groups() 
    345377                        for group in groups: 
    346                                 child_iterG = self._get_group_iter(group, account, model=self.model) 
     378                                child_iterG = self._get_group_iter(group, 
     379                                        account, model = self.model) 
    347380                                if not child_iterG: 
    348381                                        # Group is not yet in roster, add it! 
    349                                         child_iterA = self._get_account_iter(account, self.model) 
    350                                         child_iterG = self.model.append(child_iterA, [ 
    351                                                 gajim.interface.jabber_state_images['16']['closed'], 
    352                                                 gobject.markup_escape_text(group), 'group', 
    353                                                 group, account, None, None]) 
     382                                        child_iterA = self._get_account_iter( 
     383                                                account, self.model) 
     384                                        child_iterG = self.model.append( 
     385                                                child_iterA, [gajim.interface. \ 
     386                                                jabber_state_images['16'] \ 
     387                                                ['closed'], gobject. \ 
     388                                                markup_escape_text(group), 
     389                                                'group', group, account, None, 
     390                                                None, None]) 
    354391                                        self.draw_group(group, account) 
    355392 
     
    361398                                        typestr = 'contact' 
    362399 
    363                                 # we add some values here. see draw_contact for more 
    364                                 i_ = self.model.append(child_iterG, (None, contact.get_shown_name(), 
    365                                         typestr, contact.jid, account, None, None)) 
     400                                # we add some values here. see draw_contact 
     401                                # for more 
     402                                i_ = self.model.append(child_iterG, (None, 
     403                                        contact.get_shown_name(), typestr, 
     404                                        contact.jid, account, None, None, None)) 
    366405                                added_iters.append(i_) 
    367406 
     
    372411                                        is_expanded = True 
    373412                                if group not in gajim.groups[account]: 
    374                                         gajim.groups[account][group] = {'expand': is_expanded} 
    375  
    376                 assert len(added_iters), '%s has not been added to roster!' % contact.jid 
     413                                        gajim.groups[account][group] = \ 
     414                                                {'expand': is_expanded} 
     415 
     416                assert len(added_iters), '%s has not been added to roster!' % \ 
     417                        contact.jid 
    377418                for titer in added_iters: 
    378419                        assert self.model[titer][C_JID] == contact.jid and \ 
     
    385426 
    386427                Empty groups after contact removal are removed too. 
    387                 Return False if contact still has children and deletion was not performed. 
     428                Return False if contact still has children and deletion was 
     429                not performed. 
    388430                Return True on success. 
    389431 
     
    393435                groups -- list of groups to remove the contact from. 
    394436                ''' 
    395                 iters = self._get_contact_iter(contact.jid, account, contact, self.model) 
    396                 assert iters, '%s shall be removed but is not in roster' % contact.jid 
     437                iters = self._get_contact_iter(contact.jid, account, contact, 
     438                        self.model) 
     439                assert iters, '%s shall be removed but is not in roster' % \ 
     440                        contact.jid 
    397441 
    398442                parent_iter = self.model.iter_parent(iters[0]) 
     
    402446                        # Only remove from specified groups 
    403447                        all_iters = iters[:] 
    404                         group_iters = [self._get_group_iter(group, account) for group in \ 
    405                                 groups] 
     448                        group_iters = [self._get_group_iter(group, account) \ 
     449                                for group in groups] 
    406450                        iters = [titer for titer in all_iters 
    407451                                if self.model.iter_parent(titer) in group_iters] 
     
    421465                                if parent_type == 'group' and \ 
    422466                                self.model.iter_n_children(parent_i) == 1: 
    423                                         group = self.model[parent_i][C_JID].decode('utf-8') 
     467                                        group = self.model[parent_i][C_JID]. \ 
     468                                                decode('utf-8') 
    424469                                        if gajim.groups[account].has_key(group): 
    425470                                                del gajim.groups[account][group] 
     
    430475 
    431476        def _add_metacontact_family(self, family, account): 
    432                 '''Add the give Metacontact family to roster data model. 
     477                ''' 
     478                Add the give Metacontact family to roster data model. 
    433479 
    434480                Add Big Brother to his groups and all others under him. 
    435                 Return list of all added (contact, account) tuples with Big Brother 
    436                 as first element. 
     481                Return list of all added (contact, account) tuples with 
     482                Big Brother as first element. 
    437483 
    438484                Keyword arguments: 
     
    445491                        big_brother_account, big_brother_jid) 
    446492 
    447                 assert len(self._get_contact_iter(big_brother_jid, big_brother_account, 
    448                         big_brother_contact, self.model)) == 0,\ 
    449                         'Big brother %s already in roster  \n Family: %s' % (big_brother_jid, 
    450                         family) 
     493                assert len(self._get_contact_iter(big_brother_jid, 
     494                        big_brother_account, big_brother_contact, self.model)) \ 
     495                        == 0, 'Big brother %s already in roster\n Family: %s' \ 
     496                        % (big_brother_jid, family) 
    451497                self._add_entity(big_brother_contact, big_brother_account) 
    452498 
     
    456502                        _account = data['account'] 
    457503                        _jid = data['jid'] 
    458                         _contact = gajim.contacts.get_first_contact_from_jid(_account, _jid) 
     504                        _contact = gajim.contacts.get_first_contact_from_jid( 
     505                                _account, _jid) 
    459506 
    460507                        if not _contact or _contact == big_brother_contact: 
     
    463510                                continue 
    464511 
    465                         assert len(self._get_contact_iter(_jid, _account, _contact, self.model) 
    466                                 ) == 0, "%s already in roster. \n Family: %s" % (_jid, nearby_family) 
    467                         self._add_entity(_contact, _account, big_brother_contact = \ 
    468                                 big_brother_contact, big_brother_account=big_brother_account) 
     512                        assert len(self._get_contact_iter(_jid, _account, 
     513                                _contact, self.model)) == 0, "%s already in " \ 
     514                                "roster.\n Family: %s" % (_jid, nearby_family) 
     515                        self._add_entity(_contact, _account, 
     516                                big_brother_contact = big_brother_contact, 
     517                                big_brother_account = big_brother_account) 
    469518                        brothers.append((_contact, _account)) 
    470519 
     
    473522 
    474523        def _remove_metacontact_family(self, family, account): 
    475                 '''Remove the given Metacontact family from roster data model. 
    476  
    477                 See Contacts.get_metacontacts_family() and RosterWindow._remove_entity() 
     524                ''' 
     525                Remove the given Metacontact family from roster data model. 
     526 
     527                See Contacts.get_metacontacts_family() and 
     528                RosterWindow._remove_entity() 
    478529                ''' 
    479530                nearby_family = self._get_nearby_family_and_big_brother( 
     
    599650                child_iterA = self._get_account_iter(account, self.model) 
    600651                self.model.append(child_iterA, (None, gajim.nicks[account], 
    601                         'self_contact', jid, account, None, None)) 
     652                        'self_contact', jid, account, None, None, None)) 
    602653 
    603654                self.draw_contact(jid, account) 
     
    9641015                        contact_instances) 
    9651016 
    966                 child_iters = self._get_contact_iter(jid, account, contact, self.model) 
     1017                child_iters = self._get_contact_iter(jid, account, 
     1018                        contact, self.model) 
    9671019                if not child_iters: 
    9681020                        return False 
     
    9751027                        nb_unread = len(gajim.events.get_events(account, jid, 
    9761028                                ['printed_marked_gc_msg'])) 
    977                         nb_unread += \ 
    978                                 gajim.interface.minimized_controls[account][jid].get_nb_unread_pm() 
     1029                        nb_unread += gajim.interface.minimized_controls \ 
     1030                                [account][jid].get_nb_unread_pm() 
    9791031 
    9801032                        if nb_unread == 1: 
     
    9891041                else: 
    9901042                        for group in contact.get_shown_groups(): 
    991                                 if group in gajim.connections[account].blocked_groups: 
     1043                                if group in \ 
     1044                                gajim.connections[account].blocked_groups: 
    9921045                                        strike = True 
    9931046                                        break 
     
    10031056                        name += ' (' + unicode(nb_connected_contact) + ')' 
    10041057 
    1005                 # show (account_name) if there are 2 contact with same jid in merged mode 
     1058                # show (account_name) if there are 2 contact with same jid 
     1059                # in merged mode 
    10061060                if self.regroup: 
    10071061                        add_acct = False 
    10081062                        # look through all contacts of all accounts 
    10091063                        for account_ in gajim.connections: 
    1010                                 if account_ == account: # useless to add accout name 
     1064                                # useless to add account name 
     1065                                if account_ == account: 
    10111066                                        continue 
    1012                                 for jid_ in gajim.contacts.get_jid_list(account_): 
    1013                                         contact_ = gajim.contacts.get_first_contact_from_jid(account_, 
    1014                                                 jid_) 
    1015                                         if contact_.get_shown_name() == contact.get_shown_name() and \ 
     1067                                for jid_ in \ 
     1068                                gajim.contacts.get_jid_list(account_): 
     1069                                        contact_ = gajim.contacts. \ 
     1070                                                get_first_contact_from_jid( 
     1071                                                account_, jid_) 
     1072                                        if contact_.get_shown_name() == \ 
     1073                                        contact.get_shown_name() and \ 
    10161074                                        (jid_, account_) != (jid, account): 
    10171075                                                add_acct = True 
    10181076                                                break 
    10191077                                if add_acct: 
    1020                                         # No need to continue in other account if we already found one 
     1078                                        # No need to continue in other account 
     1079                                        # if we already found one 
    10211080                                        break 
    10221081                        if add_acct: 
    10231082                                name += ' (' + account + ')' 
    10241083 
    1025                 # add status msg, if not empty, under contact name in the treeview 
    1026                 if contact.status and gajim.config.get('show_status_msgs_in_roster'): 
     1084                # add status msg, if not empty, under contact name in 
     1085                # the treeview 
     1086                if contact.status \ 
     1087                and gajim.config.get('show_status_msgs_in_roster'): 
    10271088                        status = contact.status.strip() 
    10281089                        if status != '': 
    1029                                 status = helpers.reduce_chars_newlines(status, max_lines = 1) 
    1030                                 # escape markup entities and make them small italic and fg color 
    1031                                 # color is calcuted to be always readable 
    1032                                 color = gtkgui_helpers._get_fade_color(self.tree, selected, focus) 
    1033                                 colorstring = '#%04x%04x%04x' % (color.red, color.green, color.blue) 
    1034                                 name += \ 
    1035                                         '\n<span size="small" style="italic" foreground="%s">%s</span>' \ 
    1036                                         % (colorstring, gobject.markup_escape_text(status)) 
     1090                                status = helpers.reduce_chars_newlines(status, 
     1091                                        max_lines = 1) 
     1092                                # escape markup entities and make them small 
     1093                                # italic and fg color color is calcuted to be 
     1094                                # always readable 
     1095                                color = gtkgui_helpers._get_fade_color( 
     1096                                        self.tree, selected, focus) 
     1097                                colorstring = '#%04x%04x%04x' % (color.red, 
     1098                                        color.green, color.blue) 
     1099                                name += '\n<span size="small" style="italic" ' \ 
     1100                                        'foreground="%s">%s</span>' % ( 
     1101                                        colorstring, 
     1102                                        gobject.markup_escape_text(status)) 
    10371103 
    10381104                icon_name = helpers.get_icon_name_to_show(contact, account) 
     
    10401106                for c in contact_instances: 
    10411107                        c_icon_name = helpers.get_icon_name_to_show(c, account) 
    1042                         if c_icon_name in ('event', 'muc_active', 'muc_inactive'): 
     1108                        if c_icon_name \ 
     1109                        in ('event', 'muc_active', 'muc_inactive'): 
    10431110                                icon_name = c_icon_name 
    10441111