Show
Ignore:
Timestamp:
06/27/08 01:36:58 (5 months ago)
Author:
bct
Message:

first pass at stripping out the one-tab-per-session code

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/message_window.py

    r9830 r9846  
    5555 
    5656        def __init__(self, acct, type, parent_window=None, parent_paned=None): 
    57                 # A dictionary of dictionaries of dictionaries 
    58                 # where _contacts[account][jid][thread_id] == A MessageControl 
     57                # A dictionary of dictionaries 
     58                # where _contacts[account][jid] == A MessageControl 
    5959                self._controls = {} 
    60  
    61                 # a dictionary of dictionaries where 
    62                 # sessionless_ctrls[account][jid] = a list of MessageControls that don't have 
    63                 # sessions attached 
    64                 self.sessionless_ctrls = {} 
    6560 
    6661                # If None, the window is not tied to any specific account 
     
    155150                        del self._controls[old_name] 
    156151 
    157                 if self.sessionless_ctrls.has_key(old_name): 
    158                         self.sessionless_ctrls[new_name] = self.sessionless_ctrls[old_name] 
    159                         del self.sessionless_ctrls[old_name] 
    160  
    161152                for ctrl in self.controls(): 
    162153                        if ctrl.account == old_name: 
     
    167158        def get_num_controls(self): 
    168159                n = 0 
    169                 for jid_dict in self._controls.values(): 
    170                         for dict in jid_dict.values(): 
    171                                 n += len(dict) 
    172  
    173                 for jid_dict in self.sessionless_ctrls.values(): 
    174                         for ctrls in jid_dict.values(): 
    175                                 n += len(ctrls) 
    176  
     160                for dict in self._controls.values(): 
     161                        n += len(dict) 
    177162                return n 
    178163 
     
    215200                        ctrl.shutdown() 
    216201                self._controls.clear() 
    217                 self.sessionless_ctrls.clear() 
    218202                # Clean up handlers connected to the parent window, this is important since 
    219203                # self.window may be the RosterWindow 
     
    227211                fjid = control.get_full_jid() 
    228212 
    229                 if control.session: 
    230                         if not self._controls.has_key(control.account): 
    231                                 self._controls[control.account] = {} 
    232  
    233                         if not self._controls[control.account].has_key(fjid): 
    234                                 self._controls[control.account][fjid] = {} 
    235  
    236                         self._controls[control.account][fjid][control.session.thread_id] = control 
    237                 else: 
    238                         if not self.sessionless_ctrls.has_key(control.account): 
    239                                 self.sessionless_ctrls[control.account] = {} 
    240  
    241                         if not self.sessionless_ctrls[control.account].has_key(fjid): 
    242                                 self.sessionless_ctrls[control.account][fjid] = [] 
    243  
    244                         self.sessionless_ctrls[control.account][fjid].append(control) 
     213                if not self._controls.has_key(control.account): 
     214                        self._controls[control.account] = {} 
     215 
     216                self._controls[control.account][fjid] = control 
    245217 
    246218                if self.get_num_controls() == 2: 
     
    487459                self.notebook.remove_page(self.notebook.page_num(ctrl.widget)) 
    488460 
    489                 if ctrl.session: 
    490                         dict = self._controls 
    491                         idx = ctrl.session.thread_id 
    492                 else: 
    493                         dict = self.sessionless_ctrls 
    494                         idx = dict[ctrl.account][fjid].index(ctrl) 
    495  
    496                 del dict[ctrl.account][fjid][idx] 
    497  
    498                 if len(dict[ctrl.account][fjid]) == 0: 
    499                         del dict[ctrl.account][fjid] 
    500  
    501                 if len(dict[ctrl.account]) == 0: 
    502                         del dict[ctrl.account] 
     461                del self._controls[ctrl.account][fjid] 
     462 
     463                if len(self._controls[ctrl.account]) == 0: 
     464                        del self._controls[ctrl.account] 
    503465 
    504466                self.check_tabs() 
     
    602564                        ctrl.update_tags() 
    603565 
    604         def get_control(self, key, acct, thread_id): 
     566        def get_control(self, key, acct): 
    605567                '''Return the MessageControl for jid or n, where n is a notebook page index. 
    606                 When key is an int index acct and thread_id may be None''' 
     568                When key is an int index acct may be None''' 
    607569                if isinstance(key, str): 
    608570                        key = unicode(key, 'utf-8') 
     
    611573                        jid = key 
    612574                        try: 
    613                                 return self._controls[acct][jid][thread_id] 
     575                                return self._controls[acct][jid] 
    614576                        except: 
    615577                                return None 
     
    623585 
    624586        def has_control(self, jid, acct): 
    625                 sessioned = (acct in self._controls and jid in self._controls[acct] \ 
    626                         and self._controls[acct][jid]) 
    627  
    628                 return sessioned or self.sessionless_controls(acct, jid) 
    629  
    630         def get_gc_control(self, jid, acct): 
    631                 return self.get_control(jid, acct, 'gc') 
     587                return (acct in self._controls and jid in self._controls[acct]) 
    632588 
    633589        def get_controls(self, jid, acct): 
    634590                try: 
    635                         sessioned = self._controls[acct][jid].values() 
    636                 except KeyError: 
    637                         sessioned = [] 
    638  
    639                 sessionless = self.sessionless_controls(acct, jid) 
    640                 return sessioned + sessionless 
    641  
    642         def sessionless_controls(self, acct, jid): 
    643                 try: 
    644                         return self.sessionless_ctrls[acct][jid] 
     591                        return self._controls[acct][jid] 
    645592                except KeyError: 
    646593                        return [] 
     
    650597                try: 
    651598                        # Check if controls exists 
    652                         ctrls = self._controls[acct][old_jid] 
     599                        ctrl = self._controls[acct][old_jid] 
    653600                except KeyError: 
    654601                        return 
    655                 self._controls[acct][new_jid] = ctrls 
     602 
     603                self._controls[acct][new_jid] = ctrl 
    656604                del self._controls[acct][old_jid] 
    657  
    658                 try: 
    659                         ctrls = self.sessionless_ctrls[acct][old_jid] 
    660                 except KeyError: 
    661                         return 
    662  
    663                 self.sessionless_ctrls[acct][new_jid] = ctrls 
    664                 del self.sessionless_ctrls[acct][new_jid] 
    665605 
    666606                if old_jid in gajim.last_message_time[acct]: 
     
    669609                        del gajim.last_message_time[acct][old_jid] 
    670610 
    671         def change_thread_key(self, jid, acct, old_thread_id, new_thread_id): 
    672                 '''Change the thread_id key of a control''' 
    673  
    674                 if jid in self._controls[acct]: 
    675                         ctrl = self._controls[acct][jid][old_thread_id] 
    676                 else: 
    677                         jid = gajim.get_jid_without_resource(jid) 
    678                         ctrl = self._controls[acct][jid][old_thread_id] 
    679  
    680                 del self._controls[acct][jid][old_thread_id] 
    681  
    682                 if new_thread_id: 
    683                         self._controls[acct][jid][new_thread_id] = ctrl 
    684                 else: 
    685                         if acct not in self.sessionless_ctrls: 
    686                                 self.sessionless_ctrls[acct] = {} 
    687  
    688                         if jid not in self.sessionless_ctrls[acct]: 
    689                                 self.sessionless_ctrls[acct][jid] = [] 
    690  
    691                         self.sessionless_ctrls[acct][jid].append(ctrl) 
    692  
    693         def move_from_sessionless(self, ctrl): 
    694                 '''a control just got a session, move it to the proper holding cell''' 
    695                 acct = ctrl.account 
    696                 jid = ctrl.get_full_jid() 
    697  
    698                 idx = self.sessionless_ctrls[acct][jid].index(ctrl) 
    699  
    700                 del self.sessionless_ctrls[acct][jid][idx] 
    701  
    702                 if len(self.sessionless_ctrls[acct][jid]) == 0: 
    703                         del self.sessionless_ctrls[acct][jid] 
    704  
    705                 if not self._controls.has_key(acct): 
    706                         self._controls[acct] = {} 
    707  
    708                 if not self._controls[acct].has_key(jid): 
    709                         self._controls[acct][jid] = {} 
    710  
    711                 thread_id = ctrl.session.thread_id 
    712  
    713                 self._controls[acct][jid][thread_id] = ctrl 
    714  
    715611        def controls(self): 
    716612                for jid_dict in self._controls.values(): 
    717                         for ctrl_dict in jid_dict.values(): 
    718                                 for ctrl in ctrl_dict.values(): 
    719                                         yield ctrl 
    720                 for jid_dict in self.sessionless_ctrls.values(): 
    721                         for ctrl_dict in jid_dict.values(): 
    722                                 for ctrl in ctrl_dict: 
    723                                         yield ctrl 
     613                        for ctrl in jid_dict.values(): 
     614                                yield ctrl 
    724615 
    725616        def move_to_next_unread_tab(self, forward): 
     
    936827                return None 
    937828 
    938         def get_gc_control(self, jid, acct): 
    939                 win = self.get_window(jid, acct) 
    940  
    941                 if win: 
    942                         return win.get_gc_control(jid, acct) 
    943  
    944                 return None 
    945  
    946         def get_sessionless_ctrl(self, acct, jid): 
    947                 '''returns a ChatControl associated with jid, that doesn't have a 
    948                 session attached''' 
    949                 mw = self.get_window(jid, acct) 
    950  
    951                 if mw: 
    952                         ctrls = mw.sessionless_controls(acct, jid) 
    953  
    954                         if len(ctrls): 
    955                                 return ctrls[0] 
    956  
    957829        def has_window(self, jid, acct): 
    958830                return self.get_window(jid, acct) is not None 
     
    1085957                                return 
    1086958 
    1087         def get_control(self, jid, acct, session): 
     959        def get_control(self, jid, acct): 
    1088960                '''Amongst all windows, return the MessageControl for jid''' 
    1089961                win = self.get_window(jid, acct) 
    1090962                if win: 
    1091                         return win.get_control(jid, acct, session) 
     963                        return win.get_control(jid, acct) 
    1092964                return None 
     965 
     966        def get_gc_control(self, jid, acct): 
     967                '''Same as get_control. Was briefly required, is not any more. 
     968May be useful some day in the future?''' 
     969                return self.get_control(jid, acct) 
    1093970 
    1094971        def get_controls(self, type = None, acct = None): 
     
    1100977                                ctrls.append(c) 
    1101978                return ctrls 
    1102  
    1103         def get_chat_controls(self, jid, acct): 
    1104                 win = self.get_window(jid, acct) 
    1105  
    1106                 if win: 
    1107                         return win.get_controls(jid, acct) 
    1108                 else: 
    1109                         return [] 
    1110979 
    1111980        def windows(self):