Changeset 9727

Show
Ignore:
Timestamp:
05/31/08 21:41:42 (6 months ago)
Author:
jim++
Message:

Use idle_add for history_win._fill_completion_dict (LOT faster)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/history_window.py

    r9564 r9727  
    118118                self.accounts_seen_online = [] # Update dict when new accounts connect 
    119119                self.jids_to_search = [] 
    120                 self._fill_completion_dict() 
     120 
     121                # This will load history too 
     122                gobject.idle_add(self._fill_completion_dict().next) 
    121123 
    122124                if jid: 
     
    124126 
    125127                xml.signal_autoconnect(self) 
    126                 self._load_history(jid, account) 
    127128                self.window.show_all() 
    128129 
    129130        def _fill_completion_dict(self): 
    130                 '''Fill completion_dict for key auto completion.  
     131                '''Fill completion_dict for key auto completion. Then load history for  
     132                current jid (by calling another function). 
    131133 
    132134                Key will be either jid or full_completion_name   
     
    134136                 
    135137                {key : (jid, account, nick_name, full_completion_name} 
     138                this is a generator and does pseudo-threading via idle_add() 
    136139                ''' 
    137140                liststore = gtkgui_helpers.get_completion_liststore(self.jid_entry) 
     
    151154                contact_img = gajim.interface.jabber_state_images['16']['online'] 
    152155                muc_active_pix = muc_active_img.get_pixbuf() 
    153                 contact_pix = contact_img.get_pixbuf()                   
     156                contact_pix = contact_img.get_pixbuf() 
     157                 
    154158                keys = self.completion_dict.keys() 
     159                # Move the actual jid at first so we load history faster 
     160                actual_jid = self.jid_entry.get_text().decode('utf-8') 
     161                keys.remove(actual_jid) 
     162                keys.insert(0, actual_jid) 
    155163                # Map jid to info tuple 
    156164                # Warning : This for is time critical with big DB  
     
    181189                        else: 
    182190                                pix = contact_pix 
    183                          
     191 
    184192                        liststore.append((pix, completed)) 
    185193                        self.completion_dict[key] = (info_jid, info_acc, info_name, 
     
    187195                        self.completion_dict[completed] = (info_jid, info_acc, 
    188196                                info_name, info_completion) 
     197                        if key == actual_jid: 
     198                                self._load_history(info_jid, info_acc) 
     199                        yield True 
    189200                keys.sort() 
     201                yield False 
    190202         
    191203        def _get_account_for_jid(self, jid): 
     
    481493                                local_time = time.localtime(tim) 
    482494                                date = time.strftime('%x', local_time) 
    483                                 #  jid (to which log is assigned to), name, date, message, time (full unix time) 
     495                                #  jid (to which log is assigned to), name, date, message,  
     496                                # time (full unix time) 
    484497                                model.append((jid, contact_name, date, message, tim)) 
    485498 
     
    574587        def open_history(self, jid, account): 
    575588                '''Load chat history of the specified jid''' 
     589                self.jid_entry.set_text(jid) 
    576590                if account and account not in self.accounts_seen_online: 
    577591                        # Update dict to not only show bare jid 
    578                         self._fill_completion_dict 
    579                 self.jid_entry.set_text(jid) 
    580                 self._load_history(jid, account) 
     592                        gobject.idle_add(self._fill_completion_dict().next) 
     593                else: 
     594                        # Only in that case because it's called by self._fill_completion_dict() 
     595                        # otherwise  
     596                        self._load_history(jid, account) 
    581597                self.results_window.set_property('visible', False)