Changeset 9155

Show
Ignore:
Timestamp:
12/16/07 01:01:13 (9 months ago)
Author:
nicfit
Message:

MessageWindowMgr? knows about ONE_MESSAGE_WINDOW_ALWAYS_WITH_ROSTER and MessageWindow? can reparent itself rather then the roster having to do so.

Location:
branches/one_window/src
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/one_window/src/message_window.py

    r8965 r9155  
    77##                    Nikos Kouremenos <kourem@gmail.com> 
    88##                    Dimitur Kirov <dkirov@gmail.com> 
    9 ##                    Travis Shirk <travis@pobox.com> 
    109##                    Norman Rasmussen <norman@rasmussen.co.za> 
    11 ## Copyright (C) 2006 Travis Shirk <travis@pobox.com> 
    12 ##                   Geobert Quach <geobert@gmail.com> 
     10## Copyright (C) 2005-2007 Travis Shirk <travis@pobox.com> 
     11## Copyright (C) 2006 Geobert Quach <geobert@gmail.com> 
    1312## Copyright (C) 2007 Stephan Erb <steve-e@h3c.de>  
    1413## 
     
    4039#################### 
    4140 
    42 class MessageWindow: 
     41class MessageWindow(object): 
    4342        '''Class for windows which contain message like things; chats, 
    4443        groupchats, etc.''' 
     
    5453                CLOSE_CTRL_KEY 
    5554        ) = range(5) 
    56          
    57         def __init__(self, acct, type): 
     55 
     56        def __init__(self, acct, type, parent_window=None, parent_paned=None): 
    5857                # A dictionary of dictionaries where _contacts[account][jid] == A MessageControl 
    5958                self._controls = {} 
     
    6968                self.xml = gtkgui_helpers.get_glade('%s.glade' % self.widget_name) 
    7069                self.window = self.xml.get_widget(self.widget_name) 
     70                self.notebook = self.xml.get_widget('notebook') 
     71                self.parent_paned = None 
     72 
     73                if parent_window: 
     74                        orig_window = self.window 
     75                        self.window = parent_window 
     76                        self.parent_paned = parent_paned 
     77                        self.notebook.reparent(self.parent_paned) 
     78                        self.parent_paned.pack2(self.notebook, resize=True, shrink=True) 
     79                        orig_window.destroy() 
     80                        del orig_window 
     81 
    7182                id = self.window.connect('delete-event', self._on_window_delete) 
    7283                self.handlers[id] = self.window 
     
    92103                self.alignment = self.xml.get_widget('alignment') 
    93104 
    94                 self.notebook = self.xml.get_widget('notebook') 
    95105                id = self.notebook.connect('switch-page', 
    96106                        self._on_notebook_switch_page) 
     
    144154                        n += len(dict) 
    145155                return n 
     156 
     157        def resize(self, width, height): 
     158                gtkgui_helpers.resize_window(self.window, width, height) 
    146159 
    147160        def _on_window_focus(self, widget, event): 
     
    211224                id = widget.connect('clicked', self._on_close_button_clicked, control) 
    212225                control.handlers[id] = widget 
    213                  
    214                 id = tab_label_box.connect('button-press-event', self.on_tab_eventbox_button_press_event, control.widget) 
     226 
     227                id = tab_label_box.connect('button-press-event', self.on_tab_eventbox_button_press_event, 
     228                                        control.widget) 
    215229                control.handlers[id] = tab_label_box 
    216230                self.notebook.append_page(control.widget, tab_label_box) 
     
    264278                        # No more control in this window 
    265279                        return 
    266                  
     280 
    267281                # CTRL mask 
    268282                if modifier & gtk.gdk.CONTROL_MASK: 
     
    287301                        if keyval == gtk.keysyms.Right: # ALT + RIGHT 
    288302                                new = self.notebook.get_current_page() + 1 
    289                                 if new >= self.notebook.get_n_pages():  
     303                                if new >= self.notebook.get_n_pages(): 
    290304                                        new = 0 
    291305                                self.notebook.set_current_page(new) 
     
    371385                ctrl_page = self.notebook.page_num(ctrl.widget) 
    372386                self.notebook.set_current_page(ctrl_page) 
    373          
     387 
    374388        def remove_tab(self, ctrl, method, reason = None, force = False): 
    375389                '''reason is only for gc (offline status message) 
     
    543557                                                                                # if no others controls have awaiting events 
    544558                # loop until finding an unread tab or having done a complete cycle 
    545                 while True:  
     559                while True: 
    546560                        if forward == True: # look for the first unread tab on the right 
    547561                                ind = ind + 1 
     
    591605                        old_ctrl = self._widget_to_control(notebook.get_nth_page(old_no)) 
    592606                        old_ctrl.set_control_active(False) 
    593                  
     607 
    594608                new_ctrl = self._widget_to_control(notebook.get_nth_page(page_num)) 
    595609                new_ctrl.set_control_active(True) 
     
    599613                control = self.get_active_control() 
    600614                # Ctrl+PageUP / DOWN has to be handled by notebook 
    601                 if event.state & gtk.gdk.CONTROL_MASK and event.keyval in ( 
    602                 gtk.keysyms.Page_Down, gtk.keysyms.Page_Up): 
     615                if (event.state & gtk.gdk.CONTROL_MASK and 
     616                                event.keyval in (gtk.keysyms.Page_Down, gtk.keysyms.Page_Up)): 
    603617                        return False 
    604618                if isinstance(control, ChatControlBase): 
     
    610624                '''Set tab label as drag source and connect the drag_data_get signal''' 
    611625                tab_label = self.notebook.get_tab_label(child) 
    612                 tab_label.dnd_handler = tab_label.connect('drag_data_get',  
     626                tab_label.dnd_handler = tab_label.connect('drag_data_get', 
    613627                        self.on_tab_label_drag_data_get_cb) 
    614628                self.handlers[tab_label.dnd_handler] = tab_label 
     
    631645                if dest_page_num != source_page_num: 
    632646                        self.notebook.reorder_child(source_child, dest_page_num) 
    633                  
     647 
    634648        def get_tab_at_xy(self, x, y): 
    635649                '''Thanks to Gaim 
    636650                Return the tab under xy and 
    637                 if its nearer from left or right side of the tab         
     651                if its nearer from left or right side of the tab 
    638652                ''' 
    639653                page_num = -1 
     
    656670                                (y <= (tab_alloc.y + tab_alloc.height)): 
    657671                                        page_num = i 
    658                                  
     672 
    659673                                        if y > tab_alloc.y + (tab_alloc.height / 2.0): 
    660674                                                to_right = True 
     
    687701        ONE_MSG_WINDOW_NEVER, 
    688702        ONE_MSG_WINDOW_ALWAYS, 
     703        ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER, 
    689704        ONE_MSG_WINDOW_PERACCT, 
    690         ONE_MSG_WINDOW_PERTYPE 
    691         ) = range(4) 
    692         # A key constant for the main window for all messages 
     705        ONE_MSG_WINDOW_PERTYPE, 
     706        ) = range(5) 
     707        # A key constant for the main window in ONE_MSG_WINDOW_ALWAYS mode 
    693708        MAIN_WIN = 'main' 
    694  
    695         def __init__(self): 
     709        # A key constant for the main window in ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER mode 
     710        ROSTER_MAIN_WIN = 'roster' 
     711 
     712        def __init__(self, parent_window, parent_paned): 
    696713                ''' A dictionary of windows; the key depends on the config: 
    697714                ONE_MSG_WINDOW_NEVER: The key is the contact JID 
    698                 ONE_MSG_WINDOW_ALWAYS: The key is MessageWindowMgr.MAIN_WIN  
     715                ONE_MSG_WINDOW_ALWAYS: The key is MessageWindowMgr.MAIN_WIN 
     716                ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER: The key is MessageWindowMgr.MAIN_WIN 
    699717                ONE_MSG_WINDOW_PERACCT: The key is the account name 
    700718                ONE_MSG_WINDOW_PERTYPE: The key is a message type constant''' 
    701719                self._windows = {} 
     720 
    702721                # Map the mode to a int constant for frequent compares 
    703722                mode = gajim.config.get('one_message_window') 
    704723                self.mode = common.config.opt_one_window_types.index(mode) 
    705724 
     725                self.parent_win = parent_window 
     726                self.parent_paned = parent_paned 
     727 
    706728        def change_account_name(self, old_name, new_name): 
    707729                for win in self.windows(): 
     
    709731 
    710732        def _new_window(self, acct, type): 
    711                 win = MessageWindow(acct, type) 
     733                parent_win = None 
     734                parent_paned = None 
     735                if self.mode == self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER: 
     736                        parent_win = self.parent_win 
     737                        parent_paned = self.parent_paned 
     738                win = MessageWindow(acct, type, parent_win, parent_paned) 
     739                # FIXME: how are these done for roster combo 
    712740                # we track the lifetime of this window 
    713741                win.window.connect('delete-event', self._on_window_delete) 
     
    740768                if not gajim.config.get('saveposition'): 
    741769                        return 
    742                          
    743                 if self.mode == self.ONE_MSG_WINDOW_ALWAYS: 
     770 
     771                if self.mode in (self.ONE_MSG_WINDOW_ALWAYS, 
     772                                self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER): 
    744773                        size = (gajim.config.get('msgwin-width'), 
    745774                                gajim.config.get('msgwin-height')) 
     775                        if self.mode == self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER: 
     776                                parent_size = win.window.get_size() 
     777                                size = (parent_size[0] + size[0], size[1]) 
    746778                elif self.mode == self.ONE_MSG_WINDOW_PERACCT: 
    747779                        size = (gajim.config.get_per('accounts', acct, 'msgwin-width'), 
     
    755787                else: 
    756788                        return 
    757  
    758                 gtkgui_helpers.resize_window(win.window, size[0], size[1]) 
    759          
     789                win.resize(size[0], size[1]) 
     790 
    760791        def _position_window(self, win, acct, type): 
    761792                '''Moves window according to config settings''' 
    762                 if not gajim.config.get('saveposition') or\ 
    763                 self.mode == self.ONE_MSG_WINDOW_NEVER: 
     793                if (not gajim.config.get('saveposition') or 
     794                self.mode in [self.ONE_MSG_WINDOW_NEVER, 
     795                                self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER]): 
    764796                        return 
    765797 
     
    783815                        if resource: 
    784816                                key += '/' + resource 
     817                        return key 
    785818                elif self.mode == self.ONE_MSG_WINDOW_ALWAYS: 
    786                         key = self.MAIN_WIN 
     819                        return self.MAIN_WIN 
     820                elif self.mode == self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER: 
     821                        return self.ROSTER_MAIN_WIN 
    787822                elif self.mode == self.ONE_MSG_WINDOW_PERACCT: 
    788                         key = acct 
     823                        return acct 
    789824                elif self.mode == self.ONE_MSG_WINDOW_PERTYPE: 
    790                         key = type 
    791                 return key 
     825                        return type 
    792826 
    793827        def create_window(self, contact, acct, type, resource = None): 
    794                 key = None 
    795828                win_acct = None 
    796829                win_type = None 
    797                 win_role = 'messages' 
    798  
    799                 key = self._mode_to_key(contact, acct, type, resource) 
     830                win_role = None  # X11 window role 
     831 
     832                win_key = self._mode_to_key(contact, acct, type, resource) 
    800833                if self.mode == self.ONE_MSG_WINDOW_PERACCT: 
    801834                        win_acct = acct 
     
    807840                        win_type = type 
    808841                        win_role = contact.jid 
     842                elif self.mode == self.ONE_MSG_WINDOW_ALWAYS: 
     843                        win_role = 'messages' 
    809844 
    810845                win = None 
    811846                try: 
    812                         win = self._windows[key] 
     847                        win = self._windows[win_key] 
    813848                except KeyError: 
    814849                        win = self._new_window(win_acct, win_type) 
    815850 
    816                 win.window.set_role(win_role) 
     851                if win_role: 
     852                        win.window.set_role(win_role) 
    817853 
    818854                # Position and size window based on saved state and window mode 
     
    821857                        self._resize_window(win, acct, type) 
    822858 
    823                 self._windows[key] = win 
     859                self._windows[win_key] = win 
    824860                return win 
    825861 
     
    881917                if not gajim.config.get('saveposition'): 
    882918                        return 
    883                  
     919 
    884920                # Save window size and position 
    885921                pos_x_key = 'msgwin-x-position' 
     
    908944                        size_width_key = type + '-msgwin-width' 
    909945                        size_height_key = type + '-msgwin-height' 
     946                elif self.mode == self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER: 
     947                        width -= msg_win.parent_paned.get_position() 
    910948 
    911949                if acct: 
     
    916954                                gajim.config.set_per('accounts', acct, pos_x_key, x) 
    917955                                gajim.config.set_per('accounts', acct, pos_y_key, y) 
    918                  
     956 
    919957                else: 
    920958                        gajim.config.set(size_width_key, width) 
    921959                        gajim.config.set(size_height_key, height) 
    922                          
     960 
    923961                        if self.mode != self.ONE_MSG_WINDOW_NEVER: 
    924962                                gajim.config.set(pos_x_key, x) 
     
    945983                                page.unparent() 
    946984                                controls.append(ctrl) 
    947                         # Must clear _controls from window to prevent 
    948                         # MessageControl.shutdown calls 
     985                        # Must clear _controls from window to prevent MessageControl.shutdown calls 
    949986                        w._controls = {} 
    950987                        w.window.destroy() 
  • branches/one_window/src/remote_control.py

    r9140 r9155  
    77## Copyright (C) 2007 Lukas Petrovicky <lukas@petrovicky.net> 
    88## Copyright (C) 2007 Julien Pivotto <roidelapluie@gmail.com> 
     9## Copyright (C) 2007 Travis Shirk <travis@pobox.com>  
    910## 
    1011## This file is part of Gajim. 
  • branches/one_window/src/roster_window.py

    r9153 r9155  
    13801380                                        name += '/' + contact.resource 
    13811381                                jid_with_resource = contact.jid + '/' + contact.resource 
    1382                                 if gajim.interface.msg_win_mgr.has_window(jid_with_resource, 
    1383                                 account): 
     1382                                if gajim.interface.msg_win_mgr.has_window(jid_with_resource, account): 
    13841383                                        win = gajim.interface.msg_win_mgr.get_window(jid_with_resource, 
    13851384                                                account) 
     
    26632662                mw = gajim.interface.msg_win_mgr.get_window(ctrl.contact.jid, ctrl.account) 
    26642663                if not mw: 
    2665                         mw = gajim.interface.msg_win_mgr.create_window(ctrl.contact, \ 
     2664                        mw = gajim.interface.msg_win_mgr.create_window(ctrl.contact, 
    26662665                                ctrl.account, ctrl.type_id) 
    26672666                ctrl.parent_win = mw 
     
    42624261                                gajim.config.set('roster_y-position', y) 
    42634262                                width, height = self.window.get_size() 
     4263                                # For the width use the size of the vbox containing the tree and 
     4264                                # status combo, this will cancel out any hpaned width  
     4265                                width = self.xml.get_widget('roster_vbox2').allocation.width 
    42644266                                gajim.config.set('roster_width', width) 
    42654267                                gajim.config.set('roster_height', height) 
     
    43994401                        win.get_control(fjid, account).got_disconnected() 
    44004402 
    4401                 # FIXME: This is probably not the right place for this code. 
    4402                 if (gajim.config.get('one_message_window') == 'always' and 
    4403                                 gajim.config.get('one_message_window_with_roster')): 
    4404                         win.window.hide() 
    4405                         hpaned = self.xml.get_widget('roster_hpaned') 
    4406                         notebook = win.xml.get_widget('notebook') 
    4407                         notebook.reparent(hpaned) 
    4408                         hpaned.pack2(notebook, resize=True, shrink=True) 
    4409                         notebook.show_all() 
    4410                 else: 
    4411                         win.window.present() 
     4403                win.window.present() 
    44124404 
    44134405        def on_row_activated(self, widget, path): 
     
    53375329                self.xml = gtkgui_helpers.get_glade('roster_window.glade') 
    53385330                self.window = self.xml.get_widget('roster_window') 
     5331                self.hpaned = self.xml.get_widget('roster_hpaned') 
    53395332                self._music_track_changed_signal = None 
    5340                 gajim.interface.msg_win_mgr = MessageWindowMgr() 
     5333                gajim.interface.msg_win_mgr = MessageWindowMgr(self.window, self.hpaned) 
    53415334                self.advanced_menus = [] # We keep them to destroy them 
    53425335                if gajim.config.get('roster_window_skip_taskbar'):