Changeset 9846 for trunk/src/message_window.py
- Timestamp:
- 06/27/08 01:36:58 (5 months ago)
- Files:
-
- 1 modified
-
trunk/src/message_window.py (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/message_window.py
r9830 r9846 55 55 56 56 def __init__(self, acct, type, parent_window=None, parent_paned=None): 57 # A dictionary of dictionaries of dictionaries58 # where _contacts[account][jid] [thread_id]== A MessageControl57 # A dictionary of dictionaries 58 # where _contacts[account][jid] == A MessageControl 59 59 self._controls = {} 60 61 # a dictionary of dictionaries where62 # sessionless_ctrls[account][jid] = a list of MessageControls that don't have63 # sessions attached64 self.sessionless_ctrls = {}65 60 66 61 # If None, the window is not tied to any specific account … … 155 150 del self._controls[old_name] 156 151 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 161 152 for ctrl in self.controls(): 162 153 if ctrl.account == old_name: … … 167 158 def get_num_controls(self): 168 159 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) 177 162 return n 178 163 … … 215 200 ctrl.shutdown() 216 201 self._controls.clear() 217 self.sessionless_ctrls.clear()218 202 # Clean up handlers connected to the parent window, this is important since 219 203 # self.window may be the RosterWindow … … 227 211 fjid = control.get_full_jid() 228 212 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 245 217 246 218 if self.get_num_controls() == 2: … … 487 459 self.notebook.remove_page(self.notebook.page_num(ctrl.widget)) 488 460 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] 503 465 504 466 self.check_tabs() … … 602 564 ctrl.update_tags() 603 565 604 def get_control(self, key, acct , thread_id):566 def get_control(self, key, acct): 605 567 '''Return the MessageControl for jid or n, where n is a notebook page index. 606 When key is an int index acct and thread_idmay be None'''568 When key is an int index acct may be None''' 607 569 if isinstance(key, str): 608 570 key = unicode(key, 'utf-8') … … 611 573 jid = key 612 574 try: 613 return self._controls[acct][jid] [thread_id]575 return self._controls[acct][jid] 614 576 except: 615 577 return None … … 623 585 624 586 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]) 632 588 633 589 def get_controls(self, jid, acct): 634 590 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] 645 592 except KeyError: 646 593 return [] … … 650 597 try: 651 598 # Check if controls exists 652 ctrl s= self._controls[acct][old_jid]599 ctrl = self._controls[acct][old_jid] 653 600 except KeyError: 654 601 return 655 self._controls[acct][new_jid] = ctrls 602 603 self._controls[acct][new_jid] = ctrl 656 604 del self._controls[acct][old_jid] 657 658 try:659 ctrls = self.sessionless_ctrls[acct][old_jid]660 except KeyError:661 return662 663 self.sessionless_ctrls[acct][new_jid] = ctrls664 del self.sessionless_ctrls[acct][new_jid]665 605 666 606 if old_jid in gajim.last_message_time[acct]: … … 669 609 del gajim.last_message_time[acct][old_jid] 670 610 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] = ctrl684 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.account696 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_id712 713 self._controls[acct][jid][thread_id] = ctrl714 715 611 def controls(self): 716 612 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 724 615 725 616 def move_to_next_unread_tab(self, forward): … … 936 827 return None 937 828 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 None945 946 def get_sessionless_ctrl(self, acct, jid):947 '''returns a ChatControl associated with jid, that doesn't have a948 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 957 829 def has_window(self, jid, acct): 958 830 return self.get_window(jid, acct) is not None … … 1085 957 return 1086 958 1087 def get_control(self, jid, acct , session):959 def get_control(self, jid, acct): 1088 960 '''Amongst all windows, return the MessageControl for jid''' 1089 961 win = self.get_window(jid, acct) 1090 962 if win: 1091 return win.get_control(jid, acct , session)963 return win.get_control(jid, acct) 1092 964 return None 965 966 def get_gc_control(self, jid, acct): 967 '''Same as get_control. Was briefly required, is not any more. 968 May be useful some day in the future?''' 969 return self.get_control(jid, acct) 1093 970 1094 971 def get_controls(self, type = None, acct = None): … … 1100 977 ctrls.append(c) 1101 978 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 []1110 979 1111 980 def windows(self):
