Changeset 9846
- Timestamp:
- 06/27/08 01:36:58 (2 months ago)
- Location:
- trunk
- Files:
-
- 10 modified
-
src/common/helpers.py (modified) (1 diff)
-
src/common/pep.py (modified) (1 diff)
-
src/gajim.py (modified) (7 diffs)
-
src/groupchat_control.py (modified) (3 diffs)
-
src/message_control.py (modified) (1 diff)
-
src/message_window.py (modified) (14 diffs)
-
src/roster_window.py (modified) (3 diffs)
-
src/session.py (modified) (1 diff)
-
src/vcard.py (modified) (1 diff)
-
test/test_sessions.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/common/helpers.py
r9815 r9846 959 959 highest_contact = gajim.contacts.get_contact_with_highest_priority( 960 960 account, contact.jid) 961 961 962 # Look for a chat control that has the given resource, or default to 962 963 # one without resource 963 ctrl s = gajim.interface.msg_win_mgr.get_chat_controls(full_jid_with_resource,964 ctrl = gajim.interface.msg_win_mgr.get_control(full_jid_with_resource, 964 965 account) 965 if ctrls: 966 return ctrls[0] 967 elif not highest_contact or not highest_contact.resource: 968 # unknow contact or offline message 969 pass # fall through, handle this at the end 970 elif highest_contact and contact.resource != \ 971 highest_contact.resource: 966 967 if ctrl: 968 return ctrl 969 elif highest_contact and highest_contact.resource and \ 970 contact.resource != highest_contact.resource: 972 971 return None 973 974 ctrls = gajim.interface.msg_win_mgr.get_chat_controls(contact.jid, account) 975 if ctrls: 976 return ctrls[0] 977 else: 978 return None 972 else: 973 # unknown contact or offline message 974 return gajim.interface.msg_win_mgr.get_control(contact.jid, account) 979 975 980 976 def reduce_chars_newlines(text, max_chars = 0, max_lines = 0): -
trunk/src/common/pep.py
r9715 r9846 246 246 contact.contact_name = nick 247 247 gajim.interface.roster.draw_contact(user, name) 248 for ctrl in gajim.interface.msg_win_mgr.get_chat_controls(user, name): 248 249 ctrl = gajim.interface.msg_win_mgr.get_control(user, name) 250 if ctrl: 249 251 ctrl.update_ui() 250 252 win = ctrl.parent_win -
trunk/src/gajim.py
r9845 r9846 539 539 return 540 540 541 for ctrl in self.msg_win_mgr.get_chat_controls(jid_from, account):542 ifctrl.type_id == message_control.TYPE_GC:543 ctrl.print_conversation('Error %s: %s' % (array[2], array[1]))541 ctrl = self.msg_win_mgr.get_control(jid_from, account) 542 if ctrl and ctrl.type_id == message_control.TYPE_GC: 543 ctrl.print_conversation('Error %s: %s' % (array[2], array[1])) 544 544 545 545 def handle_event_con_type(self, account, con_type): … … 662 662 # don't have to open a new tab if a new session comes in 663 663 664 for ctrl in self.msg_win_mgr.get_chat_controls(jid, account): 664 ctrl = self.msg_win_mgr.get_control(jid, account) 665 if ctrl: 665 666 ctrl.set_session(None) 666 667 … … 813 814 nick = jids[1] 814 815 815 ctrl = None816 816 if session: 817 817 ctrl = session.control 818 819 if not ctrl: 820 ctrls = self.msg_win_mgr.get_chat_controls(full_jid_with_resource, account) 821 if ctrls: 822 ctrl = ctrls[0] 818 else: 819 ctrl = self.msg_win_mgr.get_control(full_jid_with_resource, account) 823 820 824 821 if not ctrl: … … 1125 1122 self.roster.draw_contact(room_jid, account) 1126 1123 1127 # print status in chat windows and update status/GPG image 1128 for ctrl in self.msg_win_mgr.get_chat_controls(fjid, account): 1124 # print status in chat window and update status/GPG image 1125 ctrl = self.msg_win_mgr.get_control(fjid, account) 1126 if ctrl: 1129 1127 statusCode = array[9] 1130 1128 if '303' in statusCode: … … 1818 1816 1819 1817 def handle_event_ping_sent(self, account, contact): 1820 for ctrl in self.msg_win_mgr.get_chat_controls(contact.jid, account):1821 ctrl .print_conversation(_('Ping?'), 'status')1822 for ctrl in self.msg_win_mgr.get_chat_controls(contact.get_full_jid(), account):1823 ctrl.print_conversation(_('Ping?'), 'status')1818 for jid in [contact.jid, contact.get_full_jid()]: 1819 ctrl = self.msg_win_mgr.get_control(jid, account) 1820 if ctrl: 1821 ctrl.print_conversation(_('Ping?'), 'status') 1824 1822 1825 1823 def handle_event_ping_reply(self, account, data): 1826 1824 contact = data[0] 1827 1825 seconds = data[1] 1828 for ctrl in self.msg_win_mgr.get_chat_controls(contact.jid, account): 1829 ctrl.print_conversation(_('Pong! (%s s.)') % seconds, 'status') 1830 for ctrl in self.msg_win_mgr.get_chat_controls(contact.get_full_jid(), account): 1831 ctrl.print_conversation(_('Pong! (%s s.)') % seconds, 'status') 1826 1827 for jid in [contact.jid, contact.get_full_jid()]: 1828 ctrl = self.msg_win_mgr.get_control(jid, account) 1829 if ctrl: 1830 ctrl.print_conversation(_('Pong! (%s s.)') % seconds, 'status') 1832 1831 1833 1832 def handle_event_ping_error(self, account, contact): 1834 for ctrl in self.msg_win_mgr.get_chat_controls(contact.jid, account):1835 ctrl .print_conversation(_('Error.'), 'status')1836 for ctrl in self.msg_win_mgr.get_chat_controls(contact.get_full_jid(), account):1837 ctrl.print_conversation(_('Error.'), 'status')1833 for jid in [contact.jid, contact.get_full_jid()]: 1834 ctrl = self.msg_win_mgr.get_control(jid, account) 1835 if ctrl: 1836 ctrl.print_conversation(_('Error.'), 'status') 1838 1837 1839 1838 def handle_event_search_form(self, account, data): … … 2127 2126 ctrl = session.control 2128 2127 elif type_ == '': 2129 ctrls = self.msg_win_mgr.get_chat_controls(fjid, account) 2130 2131 if ctrls: 2132 ctrl = ctrls[0] 2128 ctrl = self.msg_win_mgr.get_control(fjid, account) 2133 2129 2134 2130 if not ctrl: … … 2579 2575 resource=resource) 2580 2576 2581 ctrls = self.msg_win_mgr.get_chat_controls(fjid, account) 2582 if ctrls: 2583 ctrl = ctrls[0] 2584 else: 2577 ctrl = self.msg_win_mgr.get_control(fjid, account) 2578 2579 if not ctrl: 2585 2580 ctrl = self.new_chat(contact, account, 2586 2581 resource=resource) -
trunk/src/groupchat_control.py
r9761 r9846 908 908 gc_contact = gajim.contacts.get_gc_contact(self.account, self.room_jid, 909 909 nick) 910 for ctrl in gajim.interface.msg_win_mgr.get_chat_controls(fjid, self.account): 910 911 ctrl = gajim.interface.msg_win_mgr.get_control(fjid, self.account) 912 if ctrl: 911 913 gc_contact.show = 'offline' 912 914 gc_contact.status = '' … … 914 916 if ctrl.parent_win: 915 917 ctrl.parent_win.redraw_tab(ctrl) 918 916 919 gajim.contacts.remove_gc_contact(self.account, gc_contact) 917 920 gajim.gc_connected[self.account][self.room_jid] = False … … 1621 1624 win = gajim.interface.msg_win_mgr.get_window(self.contact.jid, 1622 1625 self.account) 1623 ctrl = win.get_ gc_control(self.contact.jid, self.account)1626 ctrl = win.get_control(self.contact.jid, self.account) 1624 1627 1625 1628 ctrl_page = win.notebook.page_num(ctrl.widget) -
trunk/src/message_control.py
r9783 r9846 141 141 jid += '/' + self.resource 142 142 143 self.parent_win.change_thread_key(jid, self.account,144 oldsession.thread_id, new_key)145 146 143 if oldsession.enable_encryption: 147 144 self.print_esession_details() 148 elif session:149 self.parent_win.move_from_sessionless(self)150 145 151 146 def send_message(self, message, keyID = '', type = 'chat', -
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): -
trunk/src/roster_window.py
r9843 r9846 1518 1518 # If we already have chat windows opened, update them with new contact 1519 1519 # instance 1520 for chat_control in gajim.interface.msg_win_mgr.get_chat_controls(ji,1521 account):1520 chat_control = gajim.interface.msg_win_mgr.get_control(ji, account) 1521 if chat_control: 1522 1522 chat_control.contact = contact1 1523 1523 … … 2582 2582 keys[contact.jid] = keyID 2583 2583 2584 for ctrl in gajim.interface.msg_win_mgr.get_chat_controls(contact.jid,2585 account):2584 ctrl = gajim.interface.msg_win_mgr.get_control(contact.jid, account) 2585 if ctrl: 2586 2586 ctrl.update_ui() 2587 2587 2588 keys_str = '' 2588 2589 for jid in keys: … … 3940 3941 self.draw_avatar(jid, account) 3941 3942 # Update chat window 3942 if gajim.interface.msg_win_mgr.has_window(jid, account): 3943 win = gajim.interface.msg_win_mgr.get_window(jid, account) 3944 for ctrl in win.get_chat_controls(jid, account): 3945 if win and ctrl.type_id != message_control.TYPE_GC: 3946 ctrl.show_avatar() 3943 3944 ctrl = gajim.interface.msg_win_mgr.get_control(jid, account) 3945 if ctrl and ctrl.type_id != message_control.TYPE_GC: 3946 ctrl.show_avatar() 3947 3947 3948 3948 def on_roster_treeview_style_set(self, treeview, style): -
trunk/src/session.py
r9844 r9846 180 180 if not self.control: 181 181 # look for an existing chat control without a session 182 ctrl = gajim.interface.msg_win_mgr.get_ sessionless_ctrl(self.conn.name, jid)182 ctrl = gajim.interface.msg_win_mgr.get_control(jid, self.conn.name) 183 183 if ctrl: 184 184 self.control = ctrl -
trunk/src/vcard.py
r9625 r9846 124 124 gajim.interface.roster.draw_avatar(jid, self.account) 125 125 # Update chat windows 126 for ctrl in gajim.interface.msg_win_mgr.get_chat_controls(jid, self.account):127 ifctrl.type_id != message_control.TYPE_GC:128 ctrl.show_avatar()126 ctrl = gajim.interface.msg_win_mgr.get_control(jid, self.account) 127 if ctrl and ctrl.type_id != message_control.TYPE_GC: 128 ctrl.show_avatar() 129 129 130 130 def on_vcard_information_window_destroy(self, widget): -
trunk/test/test_session
