Author: nicfit
Date: 2007-12-16 01:01:13 +0100 (Sun, 16 Dec 2007)
New Revision: 9155
Modified:
branches/one_window/src/message_window.py
branches/one_window/src/remote_control.py
branches/one_window/src/roster_window.py
Log:
MessageWindowMgr knows about ONE_MESSAGE_WINDOW_ALWAYS_WITH_ROSTER and MessageWindow can reparent itself rather then the roster having to do so.
Modified: branches/one_window/src/message_window.py
===================================================================
--- branches/one_window/src/message_window.py 2007-12-15 21:04:49 UTC (rev 9154)
+++ branches/one_window/src/message_window.py 2007-12-16 00:01:13 UTC (rev 9155)
@@ -6,10 +6,9 @@
## Vincent Hanquez <tab(a)snarc.org>
## Nikos Kouremenos <kourem(a)gmail.com>
## Dimitur Kirov <dkirov(a)gmail.com>
-## Travis Shirk <travis(a)pobox.com>
## Norman Rasmussen <norman(a)rasmussen.co.za>
-## Copyright (C) 2006 Travis Shirk <travis(a)pobox.com>
-## Geobert Quach <geobert(a)gmail.com>
+## Copyright (C) 2005-2007 Travis Shirk <travis(a)pobox.com>
+## Copyright (C) 2006 Geobert Quach <geobert(a)gmail.com>
## Copyright (C) 2007 Stephan Erb <steve-e(a)h3c.de>
##
## This file is part of Gajim.
@@ -39,7 +38,7 @@
####################
-class MessageWindow:
+class MessageWindow(object):
'''Class for windows which contain message like things; chats,
groupchats, etc.'''
@@ -53,8 +52,8 @@
CLOSE_COMMAND,
CLOSE_CTRL_KEY
) = range(5)
-
- def __init__(self, acct, type):
+
+ def __init__(self, acct, type, parent_window=None, parent_paned=None):
# A dictionary of dictionaries where _contacts[account][jid] == A MessageControl
self._controls = {}
# If None, the window is not tied to any specific account
@@ -68,6 +67,18 @@
self.widget_name = 'message_window'
self.xml = gtkgui_helpers.get_glade('%s.glade' % self.widget_name)
self.window = self.xml.get_widget(self.widget_name)
+ self.notebook = self.xml.get_widget('notebook')
+ self.parent_paned = None
+
+ if parent_window:
+ orig_window = self.window
+ self.window = parent_window
+ self.parent_paned = parent_paned
+ self.notebook.reparent(self.parent_paned)
+ self.parent_paned.pack2(self.notebook, resize=True, shrink=True)
+ orig_window.destroy()
+ del orig_window
+
id = self.window.connect('delete-event', self._on_window_delete)
self.handlers[id] = self.window
id = self.window.connect('destroy', self._on_window_destroy)
@@ -91,7 +102,6 @@
self.window.add_events(gtk.gdk.POINTER_MOTION_MASK)
self.alignment = self.xml.get_widget('alignment')
- self.notebook = self.xml.get_widget('notebook')
id = self.notebook.connect('switch-page',
self._on_notebook_switch_page)
self.handlers[id] = self.notebook
@@ -144,6 +154,9 @@
n += len(dict)
return n
+ def resize(self, width, height):
+ gtkgui_helpers.resize_window(self.window, width, height)
+
def _on_window_focus(self, widget, event):
# window received focus, so if we had urgency REMOVE IT
# NOTE: we do not have to read the message (it maybe in a bg tab)
@@ -210,8 +223,9 @@
widget = xml.get_widget('tab_close_button')
id = widget.connect('clicked', self._on_close_button_clicked, control)
control.handlers[id] = widget
-
- id = tab_label_box.connect('button-press-event', self.on_tab_eventbox_button_press_event, control.widget)
+
+ id = tab_label_box.connect('button-press-event', self.on_tab_eventbox_button_press_event,
+ control.widget)
control.handlers[id] = tab_label_box
self.notebook.append_page(control.widget, tab_label_box)
@@ -263,7 +277,7 @@
if not control:
# No more control in this window
return
-
+
# CTRL mask
if modifier & gtk.gdk.CONTROL_MASK:
if keyval == gtk.keysyms.h:
@@ -286,7 +300,7 @@
# Tab switch bindings
if keyval == gtk.keysyms.Right: # ALT + RIGHT
new = self.notebook.get_current_page() + 1
- if new >= self.notebook.get_n_pages():
+ if new >= self.notebook.get_n_pages():
new = 0
self.notebook.set_current_page(new)
elif keyval == gtk.keysyms.Left: # ALT + LEFT
@@ -370,7 +384,7 @@
ctrl = self._controls[acct][jid]
ctrl_page = self.notebook.page_num(ctrl.widget)
self.notebook.set_current_page(ctrl_page)
-
+
def remove_tab(self, ctrl, method, reason = None, force = False):
'''reason is only for gc (offline status message)
if force is True, do not ask any confirmation'''
@@ -542,7 +556,7 @@
first_composing_ind = -1 # id of first composing ctrl to switch to
# if no others controls have awaiting events
# loop until finding an unread tab or having done a complete cycle
- while True:
+ while True:
if forward == True: # look for the first unread tab on the right
ind = ind + 1
if ind >= self.notebook.get_n_pages():
@@ -590,7 +604,7 @@
if old_no >= 0:
old_ctrl = self._widget_to_control(notebook.get_nth_page(old_no))
old_ctrl.set_control_active(False)
-
+
new_ctrl = self._widget_to_control(notebook.get_nth_page(page_num))
new_ctrl.set_control_active(True)
self.show_title(control = new_ctrl)
@@ -598,8 +612,8 @@
def _on_notebook_key_press(self, widget, event):
control = self.get_active_control()
# Ctrl+PageUP / DOWN has to be handled by notebook
- if event.state & gtk.gdk.CONTROL_MASK and event.keyval in (
- gtk.keysyms.Page_Down, gtk.keysyms.Page_Up):
+ if (event.state & gtk.gdk.CONTROL_MASK and
+ event.keyval in (gtk.keysyms.Page_Down, gtk.keysyms.Page_Up)):
return False
if isinstance(control, ChatControlBase):
# we forwarded it to message textview
@@ -609,7 +623,7 @@
def setup_tab_dnd(self, child):
'''Set tab label as drag source and connect the drag_data_get signal'''
tab_label = self.notebook.get_tab_label(child)
- tab_label.dnd_handler = tab_label.connect('drag_data_get',
+ tab_label.dnd_handler = tab_label.connect('drag_data_get',
self.on_tab_label_drag_data_get_cb)
self.handlers[tab_label.dnd_handler] = tab_label
tab_label.drag_source_set(gtk.gdk.BUTTON1_MASK, self.DND_TARGETS,
@@ -630,11 +644,11 @@
source_child = self.notebook.get_nth_page(source_page_num)
if dest_page_num != source_page_num:
self.notebook.reorder_child(source_child, dest_page_num)
-
+
def get_tab_at_xy(self, x, y):
'''Thanks to Gaim
Return the tab under xy and
- if its nearer from left or right side of the tab
+ if its nearer from left or right side of the tab
'''
page_num = -1
to_right = False
@@ -655,7 +669,7 @@
if (y >= tab_alloc.y) and \
(y <= (tab_alloc.y + tab_alloc.height)):
page_num = i
-
+
if y > tab_alloc.y + (tab_alloc.height / 2.0):
to_right = True
break
@@ -686,29 +700,43 @@
(
ONE_MSG_WINDOW_NEVER,
ONE_MSG_WINDOW_ALWAYS,
+ ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER,
ONE_MSG_WINDOW_PERACCT,
- ONE_MSG_WINDOW_PERTYPE
- ) = range(4)
- # A key constant for the main window for all messages
+ ONE_MSG_WINDOW_PERTYPE,
+ ) = range(5)
+ # A key constant for the main window in ONE_MSG_WINDOW_ALWAYS mode
MAIN_WIN = 'main'
+ # A key constant for the main window in ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER mode
+ ROSTER_MAIN_WIN = 'roster'
- def __init__(self):
+ def __init__(self, parent_window, parent_paned):
''' A dictionary of windows; the key depends on the config:
ONE_MSG_WINDOW_NEVER: The key is the contact JID
- ONE_MSG_WINDOW_ALWAYS: The key is MessageWindowMgr.MAIN_WIN
+ ONE_MSG_WINDOW_ALWAYS: The key is MessageWindowMgr.MAIN_WIN
+ ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER: The key is MessageWindowMgr.MAIN_WIN
ONE_MSG_WINDOW_PERACCT: The key is the account name
ONE_MSG_WINDOW_PERTYPE: The key is a message type constant'''
self._windows = {}
+
# Map the mode to a int constant for frequent compares
mode = gajim.config.get('one_message_window')
self.mode = common.config.opt_one_window_types.index(mode)
+ self.parent_win = parent_window
+ self.parent_paned = parent_paned
+
def change_account_name(self, old_name, new_name):
for win in self.windows():
win.change_account_name(old_name, new_name)
def _new_window(self, acct, type):
- win = MessageWindow(acct, type)
+ parent_win = None
+ parent_paned = None
+ if self.mode == self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER:
+ parent_win = self.parent_win
+ parent_paned = self.parent_paned
+ win = MessageWindow(acct, type, parent_win, parent_paned)
+ # FIXME: how are these done for roster combo
# we track the lifetime of this window
win.window.connect('delete-event', self._on_window_delete)
win.window.connect('destroy', self._on_window_destroy)
@@ -739,10 +767,14 @@
'''Resizes window according to config settings'''
if not gajim.config.get('saveposition'):
return
-
- if self.mode == self.ONE_MSG_WINDOW_ALWAYS:
+
+ if self.mode in (self.ONE_MSG_WINDOW_ALWAYS,
+ self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER):
size = (gajim.config.get('msgwin-width'),
gajim.config.get('msgwin-height'))
+ if self.mode == self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER:
+ parent_size = win.window.get_size()
+ size = (parent_size[0] + size[0], size[1])
elif self.mode == self.ONE_MSG_WINDOW_PERACCT:
size = (gajim.config.get_per('accounts', acct, 'msgwin-width'),
gajim.config.get_per('accounts', acct, 'msgwin-height'))
@@ -754,13 +786,13 @@
size = (gajim.config.get(opt_width), gajim.config.get(opt_height))
else:
return
+ win.resize(size[0], size[1])
- gtkgui_helpers.resize_window(win.window, size[0], size[1])
-
def _position_window(self, win, acct, type):
'''Moves window according to config settings'''
- if not gajim.config.get('saveposition') or\
- self.mode == self.ONE_MSG_WINDOW_NEVER:
+ if (not gajim.config.get('saveposition') or
+ self.mode in [self.ONE_MSG_WINDOW_NEVER,
+ self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER]):
return
if self.mode == self.ONE_MSG_WINDOW_ALWAYS:
@@ -782,21 +814,22 @@
key = acct + contact.jid
if resource:
key += '/' + resource
+ return key
elif self.mode == self.ONE_MSG_WINDOW_ALWAYS:
- key = self.MAIN_WIN
+ return self.MAIN_WIN
+ elif self.mode == self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER:
+ return self.ROSTER_MAIN_WIN
elif self.mode == self.ONE_MSG_WINDOW_PERACCT:
- key = acct
+ return acct
elif self.mode == self.ONE_MSG_WINDOW_PERTYPE:
- key = type
- return key
+ return type
def create_window(self, contact, acct, type, resource = None):
- key = None
win_acct = None
win_type = None
- win_role = 'messages'
+ win_role = None # X11 window role
- key = self._mode_to_key(contact, acct, type, resource)
+ win_key = self._mode_to_key(contact, acct, type, resource)
if self.mode == self.ONE_MSG_WINDOW_PERACCT:
win_acct = acct
win_role = acct
@@ -806,21 +839,24 @@
elif self.mode == self.ONE_MSG_WINDOW_NEVER:
win_type = type
win_role = contact.jid
+ elif self.mode == self.ONE_MSG_WINDOW_ALWAYS:
+ win_role = 'messages'
win = None
try:
- win = self._windows[key]
+ win = self._windows[win_key]
except KeyError:
win = self._new_window(win_acct, win_type)
- win.window.set_role(win_role)
+ if win_role:
+ win.window.set_role(win_role)
# Position and size window based on saved state and window mode
if not self.one_window_opened(contact, acct, type):
self._position_window(win, acct, type)
self._resize_window(win, acct, type)
- self._windows[key] = win
+ self._windows[win_key] = win
return win
def change_key(self, old_jid, new_jid, acct):
@@ -880,7 +916,7 @@
def save_state(self, msg_win):
if not gajim.config.get('saveposition'):
return
-
+
# Save window size and position
pos_x_key = 'msgwin-x-position'
pos_y_key = 'msgwin-y-position'
@@ -907,6 +943,8 @@
type = msg_win.type
size_width_key = type + '-msgwin-width'
size_height_key = type + '-msgwin-height'
+ elif self.mode == self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER:
+ width -= msg_win.parent_paned.get_position()
if acct:
gajim.config.set_per('accounts', acct, size_width_key, width)
@@ -915,11 +953,11 @@
if self.mode != self.ONE_MSG_WINDOW_NEVER:
gajim.config.set_per('accounts', acct, pos_x_key, x)
gajim.config.set_per('accounts', acct, pos_y_key, y)
-
+
else:
gajim.config.set(size_width_key, width)
gajim.config.set(size_height_key, height)
-
+
if self.mode != self.ONE_MSG_WINDOW_NEVER:
gajim.config.set(pos_x_key, x)
gajim.config.set(pos_y_key, y)
@@ -944,8 +982,7 @@
w.notebook.remove_page(0)
page.unparent()
controls.append(ctrl)
- # Must clear _controls from window to prevent
- # MessageControl.shutdown calls
+ # Must clear _controls from window to prevent MessageControl.shutdown calls
w._controls = {}
w.window.destroy()
Modified: branches/one_window/src/remote_control.py
===================================================================
--- branches/one_window/src/remote_control.py 2007-12-15 21:04:49 UTC (rev 9154)
+++ branches/one_window/src/remote_control.py 2007-12-16 00:01:13 UTC (rev 9155)
@@ -6,6 +6,7 @@
## Copyright (C) 2005-2006 Andrew Sayman <lorien420(a)myrealbox.com>
## Copyright (C) 2007 Lukas Petrovicky <lukas(a)petrovicky.net>
## Copyright (C) 2007 Julien Pivotto <roidelapluie(a)gmail.com>
+## Copyright (C) 2007 Travis Shirk <travis(a)pobox.com>
##
## This file is part of Gajim.
##
Modified: branches/one_window/src/roster_window.py
===================================================================
--- branches/one_window/src/roster_window.py 2007-12-15 21:04:49 UTC (rev 9154)
+++ branches/one_window/src/roster_window.py 2007-12-16 00:01:13 UTC (rev 9155)
@@ -1379,8 +1379,7 @@
if contact.resource != '':
name += '/' + contact.resource
jid_with_resource = contact.jid + '/' + contact.resource
- if gajim.interface.msg_win_mgr.has_window(jid_with_resource,
- account):
+ if gajim.interface.msg_win_mgr.has_window(jid_with_resource, account):
win = gajim.interface.msg_win_mgr.get_window(jid_with_resource,
account)
ctrl = win.get_control(jid_with_resource, account)
@@ -2662,7 +2661,7 @@
ctrl = gajim.interface.minimized_controls[account][jid]
mw = gajim.interface.msg_win_mgr.get_window(ctrl.contact.jid, ctrl.account)
if not mw:
- mw = gajim.interface.msg_win_mgr.create_window(ctrl.contact, \
+ mw = gajim.interface.msg_win_mgr.create_window(ctrl.contact,
ctrl.account, ctrl.type_id)
ctrl.parent_win = mw
mw.new_tab(ctrl)
@@ -4261,6 +4260,9 @@
gajim.config.set('roster_x-position', x)
gajim.config.set('roster_y-position', y)
width, height = self.window.get_size()
+ # For the width use the size of the vbox containing the tree and
+ # status combo, this will cancel out any hpaned width
+ width = self.xml.get_widget('roster_vbox2').allocation.width
gajim.config.set('roster_width', width)
gajim.config.set('roster_height', height)
@@ -4398,17 +4400,7 @@
gajim.connections[account].status in ('offline', 'invisible'):
win.get_control(fjid, account).got_disconnected()
- # FIXME: This is probably not the right place for this code.
- if (gajim.config.get('one_message_window') == 'always' and
- gajim.config.get('one_message_window_with_roster')):
- win.window.hide()
- hpaned = self.xml.get_widget('roster_hpaned')
- notebook = win.xml.get_widget('notebook')
- notebook.reparent(hpaned)
- hpaned.pack2(notebook, resize=True, shrink=True)
- notebook.show_all()
- else:
- win.window.present()
+ win.window.present()
def on_row_activated(self, widget, path):
'''When an iter is activated (dubblick or single click if gnome is set
@@ -5336,8 +5328,9 @@
def __init__(self):
self.xml = gtkgui_helpers.get_glade('roster_window.glade')
self.window = self.xml.get_widget('roster_window')
+ self.hpaned = self.xml.get_widget('roster_hpaned')
self._music_track_changed_signal = None
- gajim.interface.msg_win_mgr = MessageWindowMgr()
+ gajim.interface.msg_win_mgr = MessageWindowMgr(self.window, self.hpaned)
self.advanced_menus = [] # We keep them to destroy them
if gajim.config.get('roster_window_skip_taskbar'):
self.window.set_property('skip-taskbar-hint', True)