2005-12-28 00:55:34 +01:00
|
|
|
## message_window.py
|
|
|
|
##
|
2007-10-22 13:33:50 +02:00
|
|
|
## Copyright (C) 2003-2004 Yann Leboulanger <asterix@lagaule.org>
|
2006-02-03 08:48:10 +01:00
|
|
|
## Vincent Hanquez <tab@snarc.org>
|
2007-10-22 13:33:50 +02:00
|
|
|
## Copyright (C) 2005 Yann Leboulanger <asterix@lagaule.org>
|
2006-02-03 08:48:10 +01:00
|
|
|
## Vincent Hanquez <tab@snarc.org>
|
2006-09-28 13:31:25 +02:00
|
|
|
## Nikos Kouremenos <kourem@gmail.com>
|
2006-02-03 08:48:10 +01:00
|
|
|
## Dimitur Kirov <dkirov@gmail.com>
|
|
|
|
## Travis Shirk <travis@pobox.com>
|
|
|
|
## Norman Rasmussen <norman@rasmussen.co.za>
|
|
|
|
## Copyright (C) 2006 Travis Shirk <travis@pobox.com>
|
2007-09-01 01:19:23 +02:00
|
|
|
## Geobert Quach <geobert@gmail.com>
|
|
|
|
## Copyright (C) 2007 Stephan Erb <steve-e@h3c.de>
|
2005-12-28 00:55:34 +01:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2005-12-28 00:55:34 +01:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 13:13:13 +02:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2005-12-28 00:55:34 +01:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2005-12-28 00:55:34 +01:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
##
|
2005-12-28 00:55:34 +01:00
|
|
|
|
|
|
|
import gtk
|
2006-07-28 08:40:37 +02:00
|
|
|
import gobject
|
2005-12-28 00:55:34 +01:00
|
|
|
|
2005-12-29 04:20:06 +01:00
|
|
|
import common
|
2005-12-31 07:27:22 +01:00
|
|
|
import gtkgui_helpers
|
2006-01-02 03:12:34 +01:00
|
|
|
import message_control
|
2006-01-03 04:34:32 +01:00
|
|
|
from chat_control import ChatControlBase
|
2005-12-31 07:27:22 +01:00
|
|
|
|
2005-12-28 00:55:34 +01:00
|
|
|
from common import gajim
|
|
|
|
|
|
|
|
####################
|
|
|
|
|
|
|
|
class MessageWindow:
|
|
|
|
'''Class for windows which contain message like things; chats,
|
|
|
|
groupchats, etc.'''
|
|
|
|
|
2006-01-12 04:09:33 +01:00
|
|
|
# DND_TARGETS is the targets needed by drag_source_set and drag_dest_set
|
|
|
|
DND_TARGETS = [('GAJIM_TAB', 0, 81)]
|
|
|
|
hid = 0 # drag_data_received handler id
|
2006-10-10 17:53:42 +02:00
|
|
|
(
|
|
|
|
CLOSE_TAB_MIDDLE_CLICK,
|
|
|
|
CLOSE_ESC,
|
|
|
|
CLOSE_CLOSE_BUTTON,
|
|
|
|
CLOSE_COMMAND,
|
|
|
|
CLOSE_CTRL_KEY
|
|
|
|
) = range(5)
|
2006-01-12 04:09:33 +01:00
|
|
|
|
2006-01-08 05:31:02 +01:00
|
|
|
def __init__(self, acct, type):
|
2006-01-25 06:39:07 +01:00
|
|
|
# A dictionary of dictionaries where _contacts[account][jid] == A MessageControl
|
2005-12-28 00:55:34 +01:00
|
|
|
self._controls = {}
|
2006-01-08 05:31:02 +01:00
|
|
|
# If None, the window is not tied to any specific account
|
|
|
|
self.account = acct
|
|
|
|
# If None, the window is not tied to any specific type
|
|
|
|
self.type = type
|
2006-04-18 17:36:16 +02:00
|
|
|
# dict { handler id: widget}. Keeps callbacks, which
|
|
|
|
# lead to cylcular references
|
|
|
|
self.handlers = {}
|
2005-12-28 00:55:34 +01:00
|
|
|
|
|
|
|
self.widget_name = 'message_window'
|
2006-05-02 17:53:25 +02:00
|
|
|
self.xml = gtkgui_helpers.get_glade('%s.glade' % self.widget_name)
|
2005-12-28 00:55:34 +01:00
|
|
|
self.window = self.xml.get_widget(self.widget_name)
|
2006-04-18 17:36:16 +02:00
|
|
|
id = self.window.connect('delete-event', self._on_window_delete)
|
|
|
|
self.handlers[id] = self.window
|
|
|
|
id = self.window.connect('destroy', self._on_window_destroy)
|
|
|
|
self.handlers[id] = self.window
|
|
|
|
id = self.window.connect('focus-in-event', self._on_window_focus)
|
|
|
|
self.handlers[id] = self.window
|
2006-01-27 05:22:06 +01:00
|
|
|
|
2007-10-10 18:13:16 +02:00
|
|
|
keys=['<Control>h', '<Control>i', '<Control><Shift>Tab',
|
|
|
|
'<Control>Tab', '<Control>F4', '<Control>w',
|
|
|
|
'<Alt>Right', '<Alt>Left', '<Alt>c', 'Escape'] +\
|
|
|
|
['<Alt>'+str(i) for i in xrange(10)]
|
2007-09-15 12:11:46 +02:00
|
|
|
accel_group = gtk.AccelGroup()
|
2007-10-10 18:13:16 +02:00
|
|
|
for key in keys:
|
|
|
|
keyval, mod = gtk.accelerator_parse(key)
|
|
|
|
accel_group.connect_group(keyval, mod, gtk.ACCEL_VISIBLE,
|
|
|
|
self.accel_group_func)
|
2007-09-15 12:11:46 +02:00
|
|
|
self.window.add_accel_group(accel_group)
|
|
|
|
|
2006-01-02 23:08:50 +01:00
|
|
|
# gtk+ doesn't make use of the motion notify on gtkwindow by default
|
|
|
|
# so this line adds that
|
2006-01-07 04:09:51 +01:00
|
|
|
self.window.add_events(gtk.gdk.POINTER_MOTION_MASK)
|
2005-12-28 00:55:34 +01:00
|
|
|
self.alignment = self.xml.get_widget('alignment')
|
2006-01-03 04:34:32 +01:00
|
|
|
|
2005-12-28 00:55:34 +01:00
|
|
|
self.notebook = self.xml.get_widget('notebook')
|
2006-04-18 17:36:16 +02:00
|
|
|
id = self.notebook.connect('switch-page',
|
2006-03-28 14:01:27 +02:00
|
|
|
self._on_notebook_switch_page)
|
2006-04-18 17:36:16 +02:00
|
|
|
self.handlers[id] = self.notebook
|
|
|
|
id = self.notebook.connect('key-press-event',
|
2006-03-28 14:01:27 +02:00
|
|
|
self._on_notebook_key_press)
|
2006-04-18 17:36:16 +02:00
|
|
|
self.handlers[id] = self.notebook
|
2005-12-28 00:55:34 +01:00
|
|
|
|
2005-12-29 04:20:06 +01:00
|
|
|
# Remove the glade pages
|
|
|
|
while self.notebook.get_n_pages():
|
|
|
|
self.notebook.remove_page(0)
|
|
|
|
# Tab customizations
|
|
|
|
pref_pos = gajim.config.get('tabs_position')
|
2006-01-12 07:59:59 +01:00
|
|
|
if pref_pos == 'bottom':
|
|
|
|
nb_pos = gtk.POS_BOTTOM
|
|
|
|
elif pref_pos == 'left':
|
|
|
|
nb_pos = gtk.POS_LEFT
|
|
|
|
elif pref_pos == 'right':
|
|
|
|
nb_pos = gtk.POS_RIGHT
|
2005-12-29 04:20:06 +01:00
|
|
|
else:
|
|
|
|
nb_pos = gtk.POS_TOP
|
|
|
|
self.notebook.set_tab_pos(nb_pos)
|
|
|
|
if gajim.config.get('tabs_always_visible'):
|
|
|
|
self.notebook.set_show_tabs(True)
|
|
|
|
self.alignment.set_property('top-padding', 2)
|
|
|
|
else:
|
|
|
|
self.notebook.set_show_tabs(False)
|
|
|
|
self.notebook.set_show_border(gajim.config.get('tabs_border'))
|
|
|
|
|
2007-06-26 12:36:00 +02:00
|
|
|
# if GTK+ version < 2.10, use OUR way to reorder tabs (set up DnD)
|
2007-06-25 23:46:08 +02:00
|
|
|
if gtk.pygtk_version < (2, 10, 0) or gtk.gtk_version < (2, 10, 0):
|
|
|
|
self.hid = self.notebook.connect('drag_data_received',
|
|
|
|
self.on_tab_label_drag_data_received_cb)
|
|
|
|
self.handlers[self.hid] = self.notebook
|
|
|
|
self.notebook.drag_dest_set(gtk.DEST_DEFAULT_ALL, self.DND_TARGETS,
|
|
|
|
gtk.gdk.ACTION_MOVE)
|
2006-01-12 04:09:33 +01:00
|
|
|
|
2006-09-15 11:22:52 +02:00
|
|
|
def change_account_name(self, old_name, new_name):
|
|
|
|
if self._controls.has_key(old_name):
|
|
|
|
self._controls[new_name] = self._controls[old_name]
|
|
|
|
del self._controls[old_name]
|
|
|
|
for ctrl in self.controls():
|
|
|
|
if ctrl.account == old_name:
|
|
|
|
ctrl.account = new_name
|
|
|
|
if self.account == old_name:
|
|
|
|
self.account = new_name
|
|
|
|
|
2006-01-25 06:39:07 +01:00
|
|
|
def get_num_controls(self):
|
|
|
|
n = 0
|
|
|
|
for dict in self._controls.values():
|
|
|
|
n += len(dict)
|
|
|
|
return n
|
|
|
|
|
2006-01-02 03:12:34 +01:00
|
|
|
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)
|
|
|
|
# to remove urgency hint so this functions does that
|
2006-01-23 01:03:28 +01:00
|
|
|
gtkgui_helpers.set_unset_urgency_hint(self.window, False)
|
2006-01-02 03:12:34 +01:00
|
|
|
|
2006-01-11 23:30:49 +01:00
|
|
|
ctrl = self.get_active_control()
|
|
|
|
if ctrl:
|
|
|
|
ctrl.set_control_active(True)
|
2006-01-02 10:04:30 +01:00
|
|
|
# Undo "unread" state display, etc.
|
2006-01-11 23:30:49 +01:00
|
|
|
if ctrl.type_id == message_control.TYPE_GC:
|
2006-01-25 06:39:07 +01:00
|
|
|
self.redraw_tab(ctrl, 'active')
|
2006-01-02 10:04:30 +01:00
|
|
|
else:
|
|
|
|
# NOTE: we do not send any chatstate to preserve
|
|
|
|
# inactive, gone, etc.
|
2006-01-25 06:39:07 +01:00
|
|
|
self.redraw_tab(ctrl)
|
2006-01-02 03:12:34 +01:00
|
|
|
|
2005-12-30 21:47:59 +01:00
|
|
|
def _on_window_delete(self, win, event):
|
2006-01-01 20:40:05 +01:00
|
|
|
# Make sure all controls are okay with being deleted
|
2007-06-17 17:59:46 +02:00
|
|
|
ctrl_to_minimize = []
|
2006-01-24 03:57:26 +01:00
|
|
|
for ctrl in self.controls():
|
2007-06-17 17:59:46 +02:00
|
|
|
allow_shutdown = ctrl.allow_shutdown(self.CLOSE_CLOSE_BUTTON)
|
|
|
|
if allow_shutdown == 'no':
|
2006-01-01 20:40:05 +01:00
|
|
|
return True # halt the delete
|
2007-06-17 17:59:46 +02:00
|
|
|
elif allow_shutdown == 'minimize':
|
|
|
|
ctrl_to_minimize.append(ctrl)
|
2007-06-15 20:30:48 +02:00
|
|
|
# If all are ok, minimize the one that need to be minimized
|
2007-06-17 17:59:46 +02:00
|
|
|
for ctrl in ctrl_to_minimize:
|
|
|
|
ctrl.minimize()
|
2005-12-31 07:27:22 +01:00
|
|
|
return False
|
2006-01-01 20:40:05 +01:00
|
|
|
|
2005-12-30 21:47:59 +01:00
|
|
|
def _on_window_destroy(self, win):
|
2006-01-24 03:57:26 +01:00
|
|
|
for ctrl in self.controls():
|
2006-01-11 23:30:49 +01:00
|
|
|
ctrl.shutdown()
|
2006-01-01 20:40:05 +01:00
|
|
|
self._controls.clear()
|
2006-04-18 17:36:16 +02:00
|
|
|
for i in self.handlers.keys():
|
|
|
|
if self.handlers[i].handler_is_connected(i):
|
|
|
|
self.handlers[i].disconnect(i)
|
|
|
|
del self.handlers[i]
|
|
|
|
del self.handlers
|
2005-12-30 21:47:59 +01:00
|
|
|
|
|
|
|
def new_tab(self, control):
|
2006-01-25 06:39:07 +01:00
|
|
|
if not self._controls.has_key(control.account):
|
|
|
|
self._controls[control.account] = {}
|
2006-03-14 17:35:17 +01:00
|
|
|
fjid = control.get_full_jid()
|
2006-03-14 14:10:09 +01:00
|
|
|
self._controls[control.account][fjid] = control
|
2006-01-25 06:39:07 +01:00
|
|
|
|
2006-07-28 08:40:37 +02:00
|
|
|
if self.get_num_controls() == 2:
|
|
|
|
# is first conversation_textview scrolled down ?
|
|
|
|
scrolled = False
|
|
|
|
first_widget = self.notebook.get_nth_page(0)
|
|
|
|
ctrl = self._widget_to_control(first_widget)
|
|
|
|
conv_textview = ctrl.conv_textview
|
|
|
|
if conv_textview.at_the_end():
|
|
|
|
scrolled = True
|
2006-01-02 10:04:30 +01:00
|
|
|
self.notebook.set_show_tabs(True)
|
2006-07-28 08:40:37 +02:00
|
|
|
if scrolled:
|
|
|
|
gobject.idle_add(conv_textview.scroll_to_end_iter)
|
2006-01-02 10:04:30 +01:00
|
|
|
self.alignment.set_property('top-padding', 2)
|
2005-12-30 21:47:59 +01:00
|
|
|
|
|
|
|
# Add notebook page and connect up to the tab's close button
|
2006-05-02 17:53:25 +02:00
|
|
|
xml = gtkgui_helpers.get_glade('message_window.glade', 'chat_tab_ebox')
|
2005-12-30 21:47:59 +01:00
|
|
|
tab_label_box = xml.get_widget('chat_tab_ebox')
|
2006-04-17 23:59:04 +02:00
|
|
|
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)
|
|
|
|
control.handlers[id] = tab_label_box
|
2005-12-30 21:47:59 +01:00
|
|
|
self.notebook.append_page(control.widget, tab_label_box)
|
|
|
|
|
2007-06-25 23:46:08 +02:00
|
|
|
# If GTK+ version >= 2.10, use gtk native way to reorder tabs
|
|
|
|
if gtk.pygtk_version >= (2, 10, 0) and gtk.gtk_version >= (2, 10, 0):
|
|
|
|
self.notebook.set_tab_reorderable(control.widget, True)
|
|
|
|
else:
|
|
|
|
self.setup_tab_dnd(control.widget)
|
2006-01-02 10:04:30 +01:00
|
|
|
|
2006-01-25 06:39:07 +01:00
|
|
|
self.redraw_tab(control)
|
2005-12-30 21:47:59 +01:00
|
|
|
self.window.show_all()
|
2006-01-02 10:04:30 +01:00
|
|
|
# NOTE: we do not call set_control_active(True) since we don't know whether
|
|
|
|
# the tab is the active one.
|
2006-01-03 04:34:32 +01:00
|
|
|
self.show_title()
|
2006-01-02 10:04:30 +01:00
|
|
|
|
|
|
|
def on_tab_eventbox_button_press_event(self, widget, event, child):
|
2006-02-10 17:01:47 +01:00
|
|
|
if event.button == 3: # right click
|
2006-01-02 10:04:30 +01:00
|
|
|
n = self.notebook.page_num(child)
|
|
|
|
self.notebook.set_current_page(n)
|
|
|
|
self.popup_menu(event)
|
2006-03-01 18:01:25 +01:00
|
|
|
elif event.button == 2: # middle click
|
|
|
|
ctrl = self._widget_to_control(child)
|
2006-10-10 17:53:42 +02:00
|
|
|
self.remove_tab(ctrl, self.CLOSE_TAB_MIDDLE_CLICK)
|
2005-12-31 01:50:33 +01:00
|
|
|
|
2006-01-03 04:34:32 +01:00
|
|
|
def _on_message_textview_mykeypress_event(self, widget, event_keyval,
|
2006-03-28 14:01:27 +02:00
|
|
|
event_keymod):
|
2005-12-31 01:50:33 +01:00
|
|
|
# NOTE: handles mykeypress which is custom signal; see message_textview.py
|
|
|
|
|
|
|
|
# construct event instance from binding
|
|
|
|
event = gtk.gdk.Event(gtk.gdk.KEY_PRESS) # it's always a key-press here
|
|
|
|
event.keyval = event_keyval
|
|
|
|
event.state = event_keymod
|
|
|
|
event.time = 0 # assign current time
|
|
|
|
|
|
|
|
if event.state & gtk.gdk.CONTROL_MASK:
|
2006-01-03 04:34:32 +01:00
|
|
|
# Tab switch bindings
|
2005-12-31 01:50:33 +01:00
|
|
|
if event.keyval == gtk.keysyms.Tab: # CTRL + TAB
|
2006-01-19 02:30:18 +01:00
|
|
|
self.move_to_next_unread_tab(True)
|
2005-12-31 01:50:33 +01:00
|
|
|
elif event.keyval == gtk.keysyms.ISO_Left_Tab: # CTRL + SHIFT + TAB
|
2006-01-19 02:30:18 +01:00
|
|
|
self.move_to_next_unread_tab(False)
|
2005-12-31 01:50:33 +01:00
|
|
|
elif event.keyval == gtk.keysyms.Page_Down: # CTRL + PAGE DOWN
|
|
|
|
self.notebook.emit('key_press_event', event)
|
|
|
|
elif event.keyval == gtk.keysyms.Page_Up: # CTRL + PAGE UP
|
|
|
|
self.notebook.emit('key_press_event', event)
|
|
|
|
|
2007-09-16 11:02:04 +02:00
|
|
|
def accel_group_func(self, accel_group, acceleratable, keyval, modifier):
|
2007-10-10 18:13:16 +02:00
|
|
|
st = '1234567890' # alt+1 means the first tab (tab 0)
|
2007-09-16 11:02:04 +02:00
|
|
|
control = self.get_active_control()
|
|
|
|
if not control:
|
|
|
|
# No more control in this window
|
|
|
|
return
|
2007-10-10 18:13:16 +02:00
|
|
|
|
|
|
|
# CTRL mask
|
2007-09-16 11:02:04 +02:00
|
|
|
if modifier & gtk.gdk.CONTROL_MASK:
|
|
|
|
if keyval == gtk.keysyms.h:
|
|
|
|
control._on_history_menuitem_activate()
|
2007-10-10 18:13:16 +02:00
|
|
|
elif control.type_id == message_control.TYPE_CHAT and \
|
2007-09-16 11:02:04 +02:00
|
|
|
keyval == gtk.keysyms.i:
|
|
|
|
control._on_contact_information_menuitem_activate(None)
|
2007-10-10 18:13:16 +02:00
|
|
|
# Tab switch bindings
|
|
|
|
elif keyval == gtk.keysyms.ISO_Left_Tab: # CTRL + SHIFT + TAB
|
|
|
|
self.move_to_next_unread_tab(False)
|
|
|
|
elif keyval == gtk.keysyms.Tab: # CTRL + TAB
|
|
|
|
self.move_to_next_unread_tab(True)
|
|
|
|
elif keyval == gtk.keysyms.F4: # CTRL + F4
|
|
|
|
self.remove_tab(control, self.CLOSE_CTRL_KEY)
|
|
|
|
elif keyval == gtk.keysyms.w: # CTRL + W
|
|
|
|
self.remove_tab(control, self.CLOSE_CTRL_KEY)
|
|
|
|
|
|
|
|
# MOD1 (ALT) mask
|
|
|
|
elif modifier & gtk.gdk.MOD1_MASK:
|
|
|
|
# Tab switch bindings
|
|
|
|
if keyval == gtk.keysyms.Right: # ALT + RIGHT
|
|
|
|
new = self.notebook.get_current_page() + 1
|
|
|
|
if new >= self.notebook.get_n_pages():
|
|
|
|
new = 0
|
|
|
|
self.notebook.set_current_page(new)
|
|
|
|
elif keyval == gtk.keysyms.Left: # ALT + LEFT
|
|
|
|
new = self.notebook.get_current_page() - 1
|
|
|
|
if new < 0:
|
|
|
|
new = self.notebook.get_n_pages() - 1
|
|
|
|
self.notebook.set_current_page(new)
|
|
|
|
elif chr(keyval) in st: # ALT + 1,2,3..
|
|
|
|
self.notebook.set_current_page(st.index(chr(keyval)))
|
|
|
|
elif keyval == gtk.keysyms.c: # ALT + C toggles chat buttons
|
|
|
|
control.chat_buttons_set_visible(not control.hide_chat_buttons)
|
|
|
|
# Close tab bindings
|
|
|
|
elif keyval == gtk.keysyms.Escape and \
|
|
|
|
gajim.config.get('escape_key_closes'): # Escape
|
|
|
|
self.remove_tab(control, self.CLOSE_ESC)
|
2007-09-16 11:02:04 +02:00
|
|
|
|
2006-01-25 03:43:55 +01:00
|
|
|
def _on_close_button_clicked(self, button, control):
|
2005-12-30 21:47:59 +01:00
|
|
|
'''When close button is pressed: close a tab'''
|
2006-10-10 17:53:42 +02:00
|
|
|
self.remove_tab(control, self.CLOSE_CLOSE_BUTTON)
|
2005-12-31 07:27:22 +01:00
|
|
|
|
2006-01-08 00:40:37 +01:00
|
|
|
def show_title(self, urgent = True, control = None):
|
2005-12-31 07:27:22 +01:00
|
|
|
'''redraw the window's title'''
|
2007-05-07 22:18:22 +02:00
|
|
|
if not control:
|
|
|
|
control = self.get_active_control()
|
|
|
|
if not control:
|
|
|
|
# No more control in this window
|
|
|
|
return
|
2005-12-31 07:27:22 +01:00
|
|
|
unread = 0
|
2006-01-24 03:57:26 +01:00
|
|
|
for ctrl in self.controls():
|
2006-01-20 00:05:37 +01:00
|
|
|
if ctrl.type_id == message_control.TYPE_GC and not \
|
2006-11-11 00:17:52 +01:00
|
|
|
gajim.config.get('notify_on_all_muc_messages') and not \
|
|
|
|
ctrl.attention_flag:
|
|
|
|
# count only pm messages
|
|
|
|
unread += ctrl.get_nb_unread_pm()
|
2006-01-20 00:05:37 +01:00
|
|
|
continue
|
2006-09-02 23:01:11 +02:00
|
|
|
unread += ctrl.get_nb_unread()
|
2006-01-27 05:59:05 +01:00
|
|
|
|
2006-01-08 00:40:37 +01:00
|
|
|
unread_str = ''
|
2005-12-31 07:27:22 +01:00
|
|
|
if unread > 1:
|
2006-01-08 00:40:37 +01:00
|
|
|
unread_str = '[' + unicode(unread) + '] '
|
2005-12-31 07:27:22 +01:00
|
|
|
elif unread == 1:
|
2006-01-08 00:40:37 +01:00
|
|
|
unread_str = '* '
|
2006-01-20 00:05:37 +01:00
|
|
|
else:
|
|
|
|
urgent = False
|
2006-01-08 00:40:37 +01:00
|
|
|
|
|
|
|
if control.type_id == message_control.TYPE_GC:
|
2006-01-27 05:59:05 +01:00
|
|
|
name = control.room_jid.split('@')[0]
|
2006-01-13 05:36:42 +01:00
|
|
|
urgent = control.attention_flag
|
2006-01-03 05:44:56 +01:00
|
|
|
else:
|
2006-01-27 05:59:05 +01:00
|
|
|
name = control.contact.get_shown_name()
|
2006-03-15 09:46:44 +01:00
|
|
|
if control.resource:
|
|
|
|
name += '/' + control.resource
|
2006-01-27 05:59:05 +01:00
|
|
|
|
2006-02-10 05:21:41 +01:00
|
|
|
window_mode = gajim.interface.msg_win_mgr.mode
|
2007-02-08 19:32:10 +01:00
|
|
|
|
2006-02-12 22:22:49 +01:00
|
|
|
if self.get_num_controls() == 1:
|
2006-02-10 05:21:41 +01:00
|
|
|
label = name
|
2006-02-12 22:22:49 +01:00
|
|
|
elif window_mode == MessageWindowMgr.ONE_MSG_WINDOW_PERTYPE:
|
|
|
|
# Show the plural form since number of tabs > 1
|
2007-02-08 19:32:10 +01:00
|
|
|
if self.type == 'chat':
|
2007-02-08 19:33:42 +01:00
|
|
|
label = _('Chats')
|
2007-02-08 19:32:10 +01:00
|
|
|
elif self.type == 'gc':
|
2007-02-08 19:33:42 +01:00
|
|
|
label = _('Group Chats')
|
2007-02-08 19:32:10 +01:00
|
|
|
else:
|
2007-02-08 19:33:42 +01:00
|
|
|
label = _('Private Chats')
|
2006-02-10 05:21:41 +01:00
|
|
|
else:
|
|
|
|
label = _('Messages')
|
|
|
|
title = _('%s - Gajim') % label
|
|
|
|
|
|
|
|
if window_mode == MessageWindowMgr.ONE_MSG_WINDOW_PERACCT:
|
|
|
|
title = title + ": " + control.account
|
2005-12-31 07:27:22 +01:00
|
|
|
|
2006-02-08 05:11:42 +01:00
|
|
|
self.window.set_title(unread_str + title)
|
2006-01-08 00:40:37 +01:00
|
|
|
|
2005-12-31 07:27:22 +01:00
|
|
|
if urgent:
|
|
|
|
gtkgui_helpers.set_unset_urgency_hint(self.window, unread)
|
2006-01-23 01:03:28 +01:00
|
|
|
else:
|
|
|
|
gtkgui_helpers.set_unset_urgency_hint(self.window, False)
|
2005-12-31 18:00:04 +01:00
|
|
|
|
2006-01-25 03:43:55 +01:00
|
|
|
def set_active_tab(self, jid, acct):
|
2006-01-25 06:39:07 +01:00
|
|
|
ctrl = self._controls[acct][jid]
|
2006-01-11 23:30:49 +01:00
|
|
|
ctrl_page = self.notebook.page_num(ctrl.widget)
|
|
|
|
self.notebook.set_current_page(ctrl_page)
|
2005-12-30 21:47:59 +01:00
|
|
|
|
2007-01-14 22:45:43 +01:00
|
|
|
def remove_tab(self, ctrl, method, reason = None, force = False):
|
2006-10-03 10:54:14 +02:00
|
|
|
'''reason is only for gc (offline status message)
|
|
|
|
if force is True, do not ask any confirmation'''
|
2006-01-02 23:08:50 +01:00
|
|
|
# Shutdown the MessageControl
|
2007-06-15 20:30:48 +02:00
|
|
|
allow_shutdown = ctrl.allow_shutdown(method)
|
|
|
|
if not force and allow_shutdown == 'no':
|
|
|
|
return
|
|
|
|
if allow_shutdown == 'minimize' and method != self.CLOSE_COMMAND:
|
|
|
|
ctrl.minimize()
|
|
|
|
self.check_tabs()
|
2006-01-02 10:04:30 +01:00
|
|
|
return
|
2006-03-03 14:58:52 +01:00
|
|
|
if reason is not None: # We are leaving gc with a status message
|
|
|
|
ctrl.shutdown(reason)
|
|
|
|
else: # We are leaving gc without status message or it's a chat
|
|
|
|
ctrl.shutdown()
|
2006-01-02 10:04:30 +01:00
|
|
|
|
2006-01-02 23:08:50 +01:00
|
|
|
# Update external state
|
2006-09-02 23:01:11 +02:00
|
|
|
gajim.events.remove_events(ctrl.account, ctrl.get_full_jid,
|
|
|
|
types = ['printed_msg', 'chat', 'gc_msg'])
|
2006-03-14 18:13:34 +01:00
|
|
|
del gajim.last_message_time[ctrl.account][ctrl.get_full_jid()]
|
2006-01-02 10:04:30 +01:00
|
|
|
|
2007-06-26 12:33:51 +02:00
|
|
|
# Disconnect tab DnD only if GTK version < 2.10
|
|
|
|
if gtk.pygtk_version < (2, 10, 0) or gtk.gtk_version < (2, 10, 0):
|
|
|
|
self.disconnect_tab_dnd(ctrl.widget)
|
|
|
|
|
2006-01-11 23:30:49 +01:00
|
|
|
self.notebook.remove_page(self.notebook.page_num(ctrl.widget))
|
2006-01-02 10:04:30 +01:00
|
|
|
|
2006-03-14 18:13:34 +01:00
|
|
|
fjid = ctrl.get_full_jid()
|
2006-03-14 17:35:17 +01:00
|
|
|
del self._controls[ctrl.account][fjid]
|
2006-01-25 06:39:07 +01:00
|
|
|
if len(self._controls[ctrl.account]) == 0:
|
|
|
|
del self._controls[ctrl.account]
|
|
|
|
|
2007-05-03 23:02:50 +02:00
|
|
|
self.check_tabs()
|
|
|
|
self.show_title()
|
|
|
|
|
|
|
|
def check_tabs(self):
|
2006-11-09 01:06:03 +01:00
|
|
|
if self.get_num_controls() == 0:
|
2006-01-25 06:39:07 +01:00
|
|
|
# These are not called when the window is destroyed like this, fake it
|
2006-01-08 05:31:02 +01:00
|
|
|
gajim.interface.msg_win_mgr._on_window_delete(self.window, None)
|
|
|
|
gajim.interface.msg_win_mgr._on_window_destroy(self.window)
|
2006-01-12 04:09:33 +01:00
|
|
|
# dnd clean up
|
|
|
|
self.notebook.drag_dest_unset()
|
|
|
|
self.window.destroy()
|
2006-11-09 01:06:03 +01:00
|
|
|
return # don't show_title, we are dead
|
|
|
|
elif self.get_num_controls() == 1: # we are going from two tabs to one
|
|
|
|
show_tabs_if_one_tab = gajim.config.get('tabs_always_visible')
|
|
|
|
self.notebook.set_show_tabs(show_tabs_if_one_tab)
|
|
|
|
if not show_tabs_if_one_tab:
|
|
|
|
self.alignment.set_property('top-padding', 0)
|
|
|
|
|
2007-05-03 23:02:50 +02:00
|
|
|
|
2006-01-25 06:39:07 +01:00
|
|
|
def redraw_tab(self, ctrl, chatstate = None):
|
2006-01-11 23:30:49 +01:00
|
|
|
hbox = self.notebook.get_tab_label(ctrl.widget).get_children()[0]
|
2005-12-31 01:50:33 +01:00
|
|
|
status_img = hbox.get_children()[0]
|
|
|
|
nick_label = hbox.get_children()[1]
|
|
|
|
|
|
|
|
# Optionally hide close button
|
|
|
|
close_button = hbox.get_children()[2]
|
|
|
|
if gajim.config.get('tabs_close_button'):
|
|
|
|
close_button.show()
|
|
|
|
else:
|
|
|
|
close_button.hide()
|
|
|
|
|
|
|
|
# Update nick
|
2005-12-31 08:19:43 +01:00
|
|
|
nick_label.set_max_width_chars(10)
|
2006-01-11 23:30:49 +01:00
|
|
|
(tab_label_str, tab_label_color) = ctrl.get_tab_label(chatstate)
|
2005-12-31 07:27:22 +01:00
|
|
|
nick_label.set_markup(tab_label_str)
|
|
|
|
if tab_label_color:
|
|
|
|
nick_label.modify_fg(gtk.STATE_NORMAL, tab_label_color)
|
|
|
|
nick_label.modify_fg(gtk.STATE_ACTIVE, tab_label_color)
|
|
|
|
|
2006-01-11 23:30:49 +01:00
|
|
|
tab_img = ctrl.get_tab_image()
|
2006-01-03 08:34:18 +01:00
|
|
|
if tab_img:
|
|
|
|
if tab_img.get_storage_type() == gtk.IMAGE_ANIMATION:
|
|
|
|
status_img.set_from_animation(tab_img.get_animation())
|
|
|
|
else:
|
|
|
|
status_img.set_from_pixbuf(tab_img.get_pixbuf())
|
2005-12-31 01:50:33 +01:00
|
|
|
|
|
|
|
def repaint_themed_widgets(self):
|
|
|
|
'''Repaint controls in the window with theme color'''
|
|
|
|
# iterate through controls and repaint
|
2006-01-24 03:57:26 +01:00
|
|
|
for ctrl in self.controls():
|
2006-01-11 23:30:49 +01:00
|
|
|
ctrl.repaint_themed_widgets()
|
2005-12-28 00:55:34 +01:00
|
|
|
|
2006-01-02 10:04:30 +01:00
|
|
|
def _widget_to_control(self, widget):
|
2006-01-24 03:57:26 +01:00
|
|
|
for ctrl in self.controls():
|
2006-01-11 23:30:49 +01:00
|
|
|
if ctrl.widget == widget:
|
|
|
|
return ctrl
|
2005-12-31 04:53:48 +01:00
|
|
|
return None
|
|
|
|
|
2005-12-31 07:27:22 +01:00
|
|
|
def get_active_control(self):
|
2005-12-31 04:53:48 +01:00
|
|
|
notebook = self.notebook
|
|
|
|
active_widget = notebook.get_nth_page(notebook.get_current_page())
|
2006-01-02 10:04:30 +01:00
|
|
|
return self._widget_to_control(active_widget)
|
2006-02-21 21:23:16 +01:00
|
|
|
|
2005-12-31 07:27:22 +01:00
|
|
|
def get_active_contact(self):
|
2006-01-11 23:30:49 +01:00
|
|
|
ctrl = self.get_active_control()
|
|
|
|
if ctrl:
|
|
|
|
return ctrl.contact
|
2006-01-03 05:44:56 +01:00
|
|
|
return None
|
2006-02-21 21:23:16 +01:00
|
|
|
|
2005-12-31 04:53:48 +01:00
|
|
|
def get_active_jid(self):
|
2006-01-03 05:44:56 +01:00
|
|
|
contact = self.get_active_contact()
|
|
|
|
if contact:
|
|
|
|
return contact.jid
|
|
|
|
return None
|
2005-12-31 04:53:48 +01:00
|
|
|
|
|
|
|
def is_active(self):
|
|
|
|
return self.window.is_active()
|
2006-02-21 21:23:16 +01:00
|
|
|
|
2005-12-31 05:53:14 +01:00
|
|
|
def get_origin(self):
|
|
|
|
return self.window.window.get_origin()
|
2005-12-31 04:53:48 +01:00
|
|
|
|
2005-12-31 05:53:14 +01:00
|
|
|
def toggle_emoticons(self):
|
2006-01-24 03:57:26 +01:00
|
|
|
for ctrl in self.controls():
|
2006-01-11 23:30:49 +01:00
|
|
|
ctrl.toggle_emoticons()
|
2006-02-21 21:23:16 +01:00
|
|
|
|
2005-12-31 07:27:22 +01:00
|
|
|
def update_font(self):
|
2006-01-24 03:57:26 +01:00
|
|
|
for ctrl in self.controls():
|
2006-01-11 23:30:49 +01:00
|
|
|
ctrl.update_font()
|
2006-02-21 21:23:16 +01:00
|
|
|
|
2005-12-31 07:27:22 +01:00
|
|
|
def update_tags(self):
|
2006-01-24 03:57:26 +01:00
|
|
|
for ctrl in self.controls():
|
2006-01-11 23:30:49 +01:00
|
|
|
ctrl.update_tags()
|
2005-12-31 04:53:48 +01:00
|
|
|
|
2006-01-25 03:43:55 +01:00
|
|
|
def get_control(self, key, acct):
|
|
|
|
'''Return the MessageControl for jid or n, where n is a notebook page index.
|
|
|
|
When key is an int index acct may be None'''
|
2006-01-10 20:24:06 +01:00
|
|
|
if isinstance(key, str):
|
|
|
|
key = unicode(key, 'utf-8')
|
|
|
|
|
2006-01-05 06:51:28 +01:00
|
|
|
if isinstance(key, unicode):
|
|
|
|
jid = key
|
2006-01-25 06:39:07 +01:00
|
|
|
try:
|
|
|
|
return self._controls[acct][jid]
|
|
|
|
except:
|
|
|
|
return None
|
2006-01-01 20:40:05 +01:00
|
|
|
else:
|
2006-01-05 06:51:28 +01:00
|
|
|
page_num = key
|
2006-01-01 20:40:05 +01:00
|
|
|
notebook = self.notebook
|
|
|
|
if page_num == None:
|
|
|
|
page_num = notebook.get_current_page()
|
|
|
|
nth_child = notebook.get_nth_page(page_num)
|
2006-01-02 10:04:30 +01:00
|
|
|
return self._widget_to_control(nth_child)
|
2005-12-31 18:00:04 +01:00
|
|
|
|
2007-10-13 16:37:22 +02:00
|
|
|
def change_key(self, old_jid, new_jid, acct):
|
|
|
|
'''Change the key of a control'''
|
|
|
|
try:
|
|
|
|
# Check if control exists
|
|
|
|
ctrl = self._controls[acct][old_jid]
|
|
|
|
except:
|
|
|
|
return
|
|
|
|
self._controls[acct][new_jid] = self._controls[acct][old_jid]
|
|
|
|
del self._controls[acct][old_jid]
|
2007-11-13 22:59:13 +01:00
|
|
|
if old_jid in gajim.last_message_time[acct]:
|
|
|
|
gajim.last_message_time[acct][new_jid] = \
|
|
|
|
gajim.last_message_time[acct][old_jid]
|
|
|
|
del gajim.last_message_time[acct][old_jid]
|
2007-10-13 16:37:22 +02:00
|
|
|
|
2005-12-31 22:55:44 +01:00
|
|
|
def controls(self):
|
2006-01-25 06:39:07 +01:00
|
|
|
for ctrl_dict in self._controls.values():
|
|
|
|
for ctrl in ctrl_dict.values():
|
|
|
|
yield ctrl
|
2005-12-31 22:55:44 +01:00
|
|
|
|
2006-01-01 20:40:05 +01:00
|
|
|
def move_to_next_unread_tab(self, forward):
|
|
|
|
ind = self.notebook.get_current_page()
|
|
|
|
current = ind
|
|
|
|
found = False
|
2006-06-04 19:10:20 +02:00
|
|
|
first_composing_ind = -1 # id of first composing ctrl to switch to
|
|
|
|
# if no others controls have awaiting events
|
2006-01-01 20:40:05 +01:00
|
|
|
# loop until finding an unread tab or having done a complete cycle
|
|
|
|
while True:
|
|
|
|
if forward == True: # look for the first unread tab on the right
|
|
|
|
ind = ind + 1
|
|
|
|
if ind >= self.notebook.get_n_pages():
|
|
|
|
ind = 0
|
|
|
|
else: # look for the first unread tab on the right
|
|
|
|
ind = ind - 1
|
|
|
|
if ind < 0:
|
|
|
|
ind = self.notebook.get_n_pages() - 1
|
2006-01-25 03:43:55 +01:00
|
|
|
ctrl = self.get_control(ind, None)
|
2006-09-02 23:01:11 +02:00
|
|
|
if ctrl.get_nb_unread() > 0:
|
2006-01-01 20:40:05 +01:00
|
|
|
found = True
|
|
|
|
break # found
|
2006-08-02 22:38:09 +02:00
|
|
|
elif gajim.config.get('ctrl_tab_go_to_next_composing') : # Search for a composing contact
|
2006-06-04 19:10:20 +02:00
|
|
|
contact = ctrl.contact
|
|
|
|
if first_composing_ind == -1 and contact.chatstate == 'composing':
|
|
|
|
# If no composing contact found yet, check if this one is composing
|
|
|
|
first_composing_ind = ind
|
|
|
|
if ind == current:
|
|
|
|
break # a complete cycle without finding an unread tab
|
2006-01-01 20:40:05 +01:00
|
|
|
if found:
|
|
|
|
self.notebook.set_current_page(ind)
|
2006-06-04 19:10:20 +02:00
|
|
|
elif first_composing_ind != -1:
|
|
|
|
self.notebook.set_current_page(first_composing_ind)
|
|
|
|
else: # not found and nobody composing
|
2006-01-01 20:40:05 +01:00
|
|
|
if forward: # CTRL + TAB
|
|
|
|
if current < (self.notebook.get_n_pages() - 1):
|
|
|
|
self.notebook.next_page()
|
|
|
|
else: # traverse for ever (eg. don't stop at last tab)
|
|
|
|
self.notebook.set_current_page(0)
|
|
|
|
else: # CTRL + SHIFT + TAB
|
|
|
|
if current > 0:
|
|
|
|
self.notebook.prev_page()
|
|
|
|
else: # traverse for ever (eg. don't stop at first tab)
|
|
|
|
self.notebook.set_current_page(
|
|
|
|
self.notebook.get_n_pages() - 1)
|
2006-02-21 21:23:16 +01:00
|
|
|
|
2006-01-02 10:04:30 +01:00
|
|
|
def popup_menu(self, event):
|
|
|
|
menu = self.get_active_control().prepare_context_menu()
|
|
|
|
# show the menu
|
|
|
|
menu.popup(None, None, None, event.button, event.time)
|
|
|
|
menu.show_all()
|
|
|
|
|
|
|
|
def _on_notebook_switch_page(self, notebook, page, page_num):
|
|
|
|
old_no = notebook.get_current_page()
|
2006-01-15 03:39:02 +01:00
|
|
|
if old_no >= 0:
|
|
|
|
old_ctrl = self._widget_to_control(notebook.get_nth_page(old_no))
|
|
|
|
old_ctrl.set_control_active(False)
|
2006-01-02 10:04:30 +01:00
|
|
|
|
2006-01-11 23:30:49 +01:00
|
|
|
new_ctrl = self._widget_to_control(notebook.get_nth_page(page_num))
|
|
|
|
new_ctrl.set_control_active(True)
|
|
|
|
self.show_title(control = new_ctrl)
|
2005-12-31 22:55:44 +01:00
|
|
|
|
2006-01-02 23:08:50 +01:00
|
|
|
def _on_notebook_key_press(self, widget, event):
|
2007-10-10 18:13:16 +02:00
|
|
|
control = self.get_active_control()
|
2007-10-17 16:31:26 +02:00
|
|
|
# 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):
|
|
|
|
return False
|
2007-10-10 18:13:16 +02:00
|
|
|
if isinstance(control, ChatControlBase):
|
2007-10-17 16:31:26 +02:00
|
|
|
# we forwarded it to message textview
|
2007-10-10 18:13:16 +02:00
|
|
|
control.msg_textview.emit('key_press_event', event)
|
|
|
|
control.msg_textview.grab_focus()
|
2006-01-03 04:34:32 +01:00
|
|
|
|
2006-01-12 04:09:33 +01:00
|
|
|
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',
|
2007-02-04 14:01:04 +01:00
|
|
|
self.on_tab_label_drag_data_get_cb)
|
2006-04-18 17:36:16 +02:00
|
|
|
self.handlers[tab_label.dnd_handler] = tab_label
|
2006-01-12 04:09:33 +01:00
|
|
|
tab_label.drag_source_set(gtk.gdk.BUTTON1_MASK, self.DND_TARGETS,
|
2007-02-04 14:01:04 +01:00
|
|
|
gtk.gdk.ACTION_MOVE)
|
2006-01-12 04:09:33 +01:00
|
|
|
tab_label.page_num = self.notebook.page_num(child)
|
|
|
|
|
2006-03-28 14:01:27 +02:00
|
|
|
def on_tab_label_drag_data_get_cb(self, widget, drag_context, selection,
|
|
|
|
info, time):
|
2006-01-12 04:09:33 +01:00
|
|
|
source_page_num = self.find_page_num_according_to_tab_label(widget)
|
|
|
|
# 8 is the data size for the string
|
|
|
|
selection.set(selection.target, 8, str(source_page_num))
|
|
|
|
|
2006-01-26 13:20:49 +01:00
|
|
|
def on_tab_label_drag_data_received_cb(self, widget, drag_context, x, y,
|
2006-03-28 14:01:27 +02:00
|
|
|
selection, type, time):
|
2006-01-12 04:09:33 +01:00
|
|
|
'''Reorder the tabs according to the drop position'''
|
|
|
|
source_page_num = int(selection.data)
|
|
|
|
dest_page_num, to_right = self.get_tab_at_xy(x, y)
|
|
|
|
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
|
|
|
|
'''
|
|
|
|
page_num = -1
|
|
|
|
to_right = False
|
|
|
|
horiz = self.notebook.get_tab_pos() == gtk.POS_TOP or \
|
|
|
|
self.notebook.get_tab_pos() == gtk.POS_BOTTOM
|
|
|
|
for i in xrange(self.notebook.get_n_pages()):
|
|
|
|
page = self.notebook.get_nth_page(i)
|
|
|
|
tab = self.notebook.get_tab_label(page)
|
|
|
|
tab_alloc = tab.get_allocation()
|
|
|
|
if horiz:
|
|
|
|
if (x >= tab_alloc.x) and \
|
2007-02-04 14:01:04 +01:00
|
|
|
(x <= (tab_alloc.x + tab_alloc.width)):
|
2006-01-12 04:09:33 +01:00
|
|
|
page_num = i
|
|
|
|
if x >= tab_alloc.x + (tab_alloc.width / 2.0):
|
|
|
|
to_right = True
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
if (y >= tab_alloc.y) and \
|
2007-02-04 14:01:04 +01:00
|
|
|
(y <= (tab_alloc.y + tab_alloc.height)):
|
2006-01-12 04:09:33 +01:00
|
|
|
page_num = i
|
|
|
|
|
|
|
|
if y > tab_alloc.y + (tab_alloc.height / 2.0):
|
|
|
|
to_right = True
|
|
|
|
break
|
|
|
|
return (page_num, to_right)
|
|
|
|
|
|
|
|
def find_page_num_according_to_tab_label(self, tab_label):
|
|
|
|
'''Find the page num of the tab label'''
|
|
|
|
page_num = -1
|
|
|
|
for i in xrange(self.notebook.get_n_pages()):
|
|
|
|
page = self.notebook.get_nth_page(i)
|
|
|
|
tab = self.notebook.get_tab_label(page)
|
|
|
|
if tab == tab_label:
|
|
|
|
page_num = i
|
|
|
|
break
|
|
|
|
return page_num
|
|
|
|
|
|
|
|
def disconnect_tab_dnd(self, child):
|
|
|
|
'''Clean up DnD signals, source and dest'''
|
|
|
|
tab_label = self.notebook.get_tab_label(child)
|
|
|
|
tab_label.drag_source_unset()
|
|
|
|
tab_label.disconnect(tab_label.dnd_handler)
|
|
|
|
|
2006-01-02 03:12:34 +01:00
|
|
|
################################################################################
|
2005-12-28 00:55:34 +01:00
|
|
|
class MessageWindowMgr:
|
|
|
|
'''A manager and factory for MessageWindow objects'''
|
|
|
|
|
2005-12-29 04:20:06 +01:00
|
|
|
# These constants map to common.config.opt_one_window_types indices
|
2006-01-25 14:34:02 +01:00
|
|
|
(
|
|
|
|
ONE_MSG_WINDOW_NEVER,
|
|
|
|
ONE_MSG_WINDOW_ALWAYS,
|
|
|
|
ONE_MSG_WINDOW_PERACCT,
|
|
|
|
ONE_MSG_WINDOW_PERTYPE
|
|
|
|
) = range(4)
|
2005-12-29 04:20:06 +01:00
|
|
|
# A key constant for the main window for all messages
|
|
|
|
MAIN_WIN = 'main'
|
|
|
|
|
2005-12-28 00:55:34 +01:00
|
|
|
def __init__(self):
|
2005-12-29 04:20:06 +01:00
|
|
|
''' A dictionary of windows; the key depends on the config:
|
2007-02-04 14:01:04 +01:00
|
|
|
ONE_MSG_WINDOW_NEVER: The key is the contact JID
|
|
|
|
ONE_MSG_WINDOW_ALWAYS: 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'''
|
2005-12-31 22:55:44 +01:00
|
|
|
self._windows = {}
|
2005-12-29 04:20:06 +01:00
|
|
|
# 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)
|
2006-09-15 11:22:52 +02:00
|
|
|
|
|
|
|
def change_account_name(self, old_name, new_name):
|
|
|
|
for win in self.windows():
|
|
|
|
win.change_account_name(old_name, new_name)
|
|
|
|
|
2006-01-08 05:31:02 +01:00
|
|
|
def _new_window(self, acct, type):
|
|
|
|
win = MessageWindow(acct, type)
|
2005-12-29 04:20:06 +01:00
|
|
|
# we track the lifetime of this window
|
2006-01-03 06:49:09 +01:00
|
|
|
win.window.connect('delete-event', self._on_window_delete)
|
2005-12-29 04:20:06 +01:00
|
|
|
win.window.connect('destroy', self._on_window_destroy)
|
|
|
|
return win
|
|
|
|
|
2006-01-08 05:31:02 +01:00
|
|
|
def _gtk_win_to_msg_win(self, gtk_win):
|
2006-01-24 03:57:26 +01:00
|
|
|
for w in self.windows():
|
2005-12-31 01:50:33 +01:00
|
|
|
if w.window == gtk_win:
|
2005-12-29 04:20:06 +01:00
|
|
|
return w
|
|
|
|
return None
|
|
|
|
|
2006-01-25 03:43:55 +01:00
|
|
|
def get_window(self, jid, acct):
|
2006-01-24 03:57:26 +01:00
|
|
|
for win in self.windows():
|
2006-01-25 03:43:55 +01:00
|
|
|
if win.get_control(jid, acct):
|
2005-12-31 18:00:04 +01:00
|
|
|
return win
|
|
|
|
return None
|
2006-01-12 09:28:43 +01:00
|
|
|
|
2006-01-25 03:43:55 +01:00
|
|
|
def has_window(self, jid, acct):
|
2006-01-25 06:39:07 +01:00
|
|
|
return self.get_window(jid, acct) != None
|
2005-12-31 18:00:04 +01:00
|
|
|
|
2006-01-08 05:31:02 +01:00
|
|
|
def one_window_opened(self, contact, acct, type):
|
2006-01-09 01:47:54 +01:00
|
|
|
try:
|
|
|
|
return self._windows[self._mode_to_key(contact, acct, type)] != None
|
|
|
|
except KeyError:
|
|
|
|
return False
|
2006-01-08 05:31:02 +01:00
|
|
|
|
2006-01-25 14:37:22 +01:00
|
|
|
def _resize_window(self, win, acct, type):
|
2006-01-25 14:34:02 +01:00
|
|
|
'''Resizes window according to config settings'''
|
2006-01-08 05:31:02 +01:00
|
|
|
if not gajim.config.get('saveposition'):
|
2006-01-25 14:27:23 +01:00
|
|
|
return
|
|
|
|
|
2006-06-02 23:49:13 +02:00
|
|
|
if self.mode == self.ONE_MSG_WINDOW_ALWAYS:
|
2006-01-12 07:59:59 +01:00
|
|
|
size = (gajim.config.get('msgwin-width'),
|
|
|
|
gajim.config.get('msgwin-height'))
|
2006-01-25 14:34:02 +01:00
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_PERACCT:
|
2006-01-12 07:59:59 +01:00
|
|
|
size = (gajim.config.get_per('accounts', acct, 'msgwin-width'),
|
|
|
|
gajim.config.get_per('accounts', acct, 'msgwin-height'))
|
2006-06-02 23:49:13 +02:00
|
|
|
elif self.mode in (self.ONE_MSG_WINDOW_NEVER, self.ONE_MSG_WINDOW_PERTYPE):
|
2006-01-12 07:59:59 +01:00
|
|
|
if type == message_control.TYPE_PM:
|
|
|
|
type = message_control.TYPE_CHAT
|
|
|
|
opt_width = type + '-msgwin-width'
|
|
|
|
opt_height = type + '-msgwin-height'
|
2006-01-25 14:37:22 +01:00
|
|
|
size = (gajim.config.get(opt_width), gajim.config.get(opt_height))
|
2006-01-25 14:27:23 +01:00
|
|
|
else:
|
|
|
|
return
|
2006-01-25 14:24:38 +01:00
|
|
|
|
2006-01-25 14:27:23 +01:00
|
|
|
gtkgui_helpers.resize_window(win.window, size[0], size[1])
|
2006-01-08 05:31:02 +01:00
|
|
|
|
|
|
|
def _position_window(self, win, acct, type):
|
2006-01-25 14:34:02 +01:00
|
|
|
'''Moves window according to config settings'''
|
2006-01-26 13:20:49 +01:00
|
|
|
if not gajim.config.get('saveposition') or\
|
|
|
|
self.mode == self.ONE_MSG_WINDOW_NEVER:
|
2006-01-08 05:31:02 +01:00
|
|
|
return
|
|
|
|
|
2006-01-25 14:34:02 +01:00
|
|
|
if self.mode == self.ONE_MSG_WINDOW_ALWAYS:
|
2006-01-08 05:31:02 +01:00
|
|
|
pos = (gajim.config.get('msgwin-x-position'),
|
|
|
|
gajim.config.get('msgwin-y-position'))
|
2006-01-25 14:34:02 +01:00
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_PERACCT:
|
2006-01-12 06:45:30 +01:00
|
|
|
pos = (gajim.config.get_per('accounts', acct, 'msgwin-x-position'),
|
|
|
|
gajim.config.get_per('accounts', acct, 'msgwin-y-position'))
|
2006-01-25 14:34:02 +01:00
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_PERTYPE:
|
2006-01-08 05:31:02 +01:00
|
|
|
pos = (gajim.config.get(type + '-msgwin-x-position'),
|
|
|
|
gajim.config.get(type + '-msgwin-y-position'))
|
2006-01-25 14:39:22 +01:00
|
|
|
else:
|
|
|
|
return
|
2006-01-08 05:31:02 +01:00
|
|
|
|
2006-01-25 15:01:59 +01:00
|
|
|
gtkgui_helpers.move_window(win.window, pos[0], pos[1])
|
2006-01-08 05:31:02 +01:00
|
|
|
|
2006-03-14 14:10:09 +01:00
|
|
|
def _mode_to_key(self, contact, acct, type, resource = None):
|
2006-01-25 14:34:02 +01:00
|
|
|
if self.mode == self.ONE_MSG_WINDOW_NEVER:
|
2006-01-25 06:39:07 +01:00
|
|
|
key = acct + contact.jid
|
2006-03-14 14:10:09 +01:00
|
|
|
if resource:
|
|
|
|
key += '/' + resource
|
2006-01-25 14:34:02 +01:00
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_ALWAYS:
|
2005-12-29 04:20:06 +01:00
|
|
|
key = self.MAIN_WIN
|
2006-01-25 14:34:02 +01:00
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_PERACCT:
|
2005-12-29 04:20:06 +01:00
|
|
|
key = acct
|
2006-01-25 14:34:02 +01:00
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_PERTYPE:
|
2005-12-29 04:20:06 +01:00
|
|
|
key = type
|
2006-01-11 04:48:28 +01:00
|
|
|
return key
|
2005-12-29 04:20:06 +01:00
|
|
|
|
2006-03-14 14:10:09 +01:00
|
|
|
def create_window(self, contact, acct, type, resource = None):
|
2006-01-08 05:31:02 +01:00
|
|
|
key = None
|
|
|
|
win_acct = None
|
|
|
|
win_type = None
|
2006-02-12 22:04:15 +01:00
|
|
|
win_role = 'messages'
|
2006-01-08 05:31:02 +01:00
|
|
|
|
2006-03-14 14:10:09 +01:00
|
|
|
key = self._mode_to_key(contact, acct, type, resource)
|
2006-01-25 14:34:02 +01:00
|
|
|
if self.mode == self.ONE_MSG_WINDOW_PERACCT:
|
2006-01-08 05:31:02 +01:00
|
|
|
win_acct = acct
|
2006-02-12 22:04:15 +01:00
|
|
|
win_role = acct
|
2006-01-25 14:34:02 +01:00
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_PERTYPE:
|
2006-01-08 05:31:02 +01:00
|
|
|
win_type = type
|
2006-02-12 22:04:15 +01:00
|
|
|
win_role = type
|
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_NEVER:
|
2006-06-02 23:49:13 +02:00
|
|
|
win_type = type
|
2006-02-12 22:04:15 +01:00
|
|
|
win_role = contact.jid
|
2006-01-08 05:31:02 +01:00
|
|
|
|
2005-12-29 04:20:06 +01:00
|
|
|
win = None
|
|
|
|
try:
|
2005-12-31 22:55:44 +01:00
|
|
|
win = self._windows[key]
|
2005-12-29 04:20:06 +01:00
|
|
|
except KeyError:
|
2006-01-08 05:31:02 +01:00
|
|
|
win = self._new_window(win_acct, win_type)
|
2006-01-03 06:49:09 +01:00
|
|
|
|
2006-02-12 22:04:15 +01:00
|
|
|
win.window.set_role(win_role)
|
|
|
|
|
2006-01-25 14:24:38 +01:00
|
|
|
# Position and size window based on saved state and window mode
|
2006-01-09 01:47:54 +01:00
|
|
|
if not self.one_window_opened(contact, acct, type):
|
|
|
|
self._position_window(win, acct, type)
|
2006-01-25 14:37:22 +01:00
|
|
|
self._resize_window(win, acct, type)
|
2006-01-09 01:47:54 +01:00
|
|
|
|
|
|
|
self._windows[key] = win
|
2005-12-29 04:20:06 +01:00
|
|
|
return win
|
|
|
|
|
2007-10-13 16:37:22 +02:00
|
|
|
def change_key(self, old_jid, new_jid, acct):
|
|
|
|
win = self.get_window(old_jid, acct)
|
|
|
|
if self.mode == self.ONE_MSG_WINDOW_NEVER:
|
|
|
|
old_key = acct + old_jid
|
|
|
|
if old_jid not in self._windows:
|
|
|
|
return
|
|
|
|
new_key = acct + new_jid
|
|
|
|
self._windows[new_key] = self._windows[old_key]
|
|
|
|
del self._windows[old_key]
|
|
|
|
win.change_key(old_jid, new_jid, acct)
|
|
|
|
|
2006-01-08 05:31:02 +01:00
|
|
|
def _on_window_delete(self, win, event):
|
2006-01-12 06:45:30 +01:00
|
|
|
self.save_state(self._gtk_win_to_msg_win(win))
|
2006-01-20 04:37:41 +01:00
|
|
|
gajim.interface.save_config()
|
2006-01-12 06:45:30 +01:00
|
|
|
return False
|
|
|
|
|
|
|
|
def _on_window_destroy(self, win):
|
|
|
|
for k in self._windows.keys():
|
|
|
|
if self._windows[k].window == win:
|
|
|
|
del self._windows[k]
|
|
|
|
return
|
|
|
|
|
2006-01-25 03:43:55 +01:00
|
|
|
def get_control(self, jid, acct):
|
2006-01-12 06:45:30 +01:00
|
|
|
'''Amongst all windows, return the MessageControl for jid'''
|
2006-01-25 03:43:55 +01:00
|
|
|
win = self.get_window(jid, acct)
|
2006-01-12 06:45:30 +01:00
|
|
|
if win:
|
2006-01-25 03:43:55 +01:00
|
|
|
return win.get_control(jid, acct)
|
2006-01-12 06:45:30 +01:00
|
|
|
return None
|
|
|
|
|
2006-02-05 00:47:40 +01:00
|
|
|
def get_controls(self, type = None, acct = None):
|
2006-01-12 06:45:30 +01:00
|
|
|
ctrls = []
|
|
|
|
for c in self.controls():
|
2006-01-31 05:03:34 +01:00
|
|
|
if acct and c.account != acct:
|
|
|
|
continue
|
2006-02-05 00:47:40 +01:00
|
|
|
if not type or c.type_id == type:
|
2006-01-12 06:45:30 +01:00
|
|
|
ctrls.append(c)
|
|
|
|
return ctrls
|
|
|
|
|
|
|
|
def windows(self):
|
|
|
|
for w in self._windows.values():
|
|
|
|
yield w
|
2006-01-25 15:01:59 +01:00
|
|
|
|
2006-01-12 06:45:30 +01:00
|
|
|
def controls(self):
|
|
|
|
for w in self._windows.values():
|
|
|
|
for c in w.controls():
|
|
|
|
yield c
|
|
|
|
|
|
|
|
def shutdown(self):
|
|
|
|
for w in self.windows():
|
|
|
|
self.save_state(w)
|
|
|
|
w.window.hide()
|
2006-01-15 03:39:02 +01:00
|
|
|
w.window.destroy()
|
2006-01-20 04:37:41 +01:00
|
|
|
gajim.interface.save_config()
|
2006-01-12 06:45:30 +01:00
|
|
|
|
|
|
|
def save_state(self, msg_win):
|
2006-01-08 05:31:02 +01:00
|
|
|
if not gajim.config.get('saveposition'):
|
2006-01-14 21:46:20 +01:00
|
|
|
return
|
2006-01-08 05:31:02 +01:00
|
|
|
|
2006-01-25 15:01:59 +01:00
|
|
|
# Save window size and position
|
2006-01-08 05:31:02 +01:00
|
|
|
pos_x_key = 'msgwin-x-position'
|
|
|
|
pos_y_key = 'msgwin-y-position'
|
|
|
|
size_width_key = 'msgwin-width'
|
|
|
|
size_height_key = 'msgwin-height'
|
|
|
|
|
|
|
|
acct = None
|
2006-01-12 06:45:30 +01:00
|
|
|
x, y = msg_win.window.get_position()
|
|
|
|
width, height = msg_win.window.get_size()
|
2006-01-08 05:31:02 +01:00
|
|
|
|
2006-01-14 21:46:20 +01:00
|
|
|
# If any of these values seem bogus don't update.
|
|
|
|
if x < 0 or y < 0 or width < 0 or height < 0:
|
|
|
|
return
|
|
|
|
|
2006-01-25 14:34:02 +01:00
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_PERACCT:
|
2006-01-08 05:31:02 +01:00
|
|
|
acct = msg_win.account
|
2006-01-25 14:34:02 +01:00
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_PERTYPE:
|
2006-01-12 03:20:59 +01:00
|
|
|
type = msg_win.type
|
2006-01-25 15:01:59 +01:00
|
|
|
pos_x_key = type + '-msgwin-x-position'
|
|
|
|
pos_y_key = type + '-msgwin-y-position'
|
|
|
|
size_width_key = type + '-msgwin-width'
|
|
|
|
size_height_key = type + '-msgwin-height'
|
2006-06-02 23:49:13 +02:00
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_NEVER:
|
|
|
|
type = msg_win.type
|
|
|
|
size_width_key = type + '-msgwin-width'
|
|
|
|
size_height_key = type + '-msgwin-height'
|
2006-01-08 05:31:02 +01:00
|
|
|
|
|
|
|
if acct:
|
2006-01-10 20:24:06 +01:00
|
|
|
gajim.config.set_per('accounts', acct, size_width_key, width)
|
|
|
|
gajim.config.set_per('accounts', acct, size_height_key, height)
|
2006-01-25 15:01:59 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2006-01-08 05:31:02 +01:00
|
|
|
else:
|
|
|
|
gajim.config.set(size_width_key, width)
|
|
|
|
gajim.config.set(size_height_key, height)
|
2006-01-25 15:01:59 +01:00
|
|
|
|
|
|
|
if self.mode != self.ONE_MSG_WINDOW_NEVER:
|
|
|
|
gajim.config.set(pos_x_key, x)
|
|
|
|
gajim.config.set(pos_y_key, y)
|
2006-01-15 03:39:02 +01:00
|
|
|
|
|
|
|
def reconfig(self):
|
2006-01-24 03:57:26 +01:00
|
|
|
for w in self.windows():
|
2006-01-15 03:39:02 +01:00
|
|
|
self.save_state(w)
|
2006-01-20 04:37:41 +01:00
|
|
|
gajim.interface.save_config()
|
2006-01-15 03:39:02 +01:00
|
|
|
# Map the mode to a int constant for frequent compares
|
|
|
|
mode = gajim.config.get('one_message_window')
|
|
|
|
if self.mode == common.config.opt_one_window_types.index(mode):
|
|
|
|
# No change
|
|
|
|
return
|
|
|
|
self.mode = common.config.opt_one_window_types.index(mode)
|
|
|
|
|
|
|
|
controls = []
|
2006-01-24 03:57:26 +01:00
|
|
|
for w in self.windows():
|
2006-01-15 03:39:02 +01:00
|
|
|
w.window.hide()
|
|
|
|
while w.notebook.get_n_pages():
|
|
|
|
page = w.notebook.get_nth_page(0)
|
|
|
|
ctrl = w._widget_to_control(page)
|
|
|
|
w.notebook.remove_page(0)
|
|
|
|
page.unparent()
|
|
|
|
controls.append(ctrl)
|
2006-02-10 05:21:41 +01:00
|
|
|
# Must clear _controls from window to prevent
|
|
|
|
# MessageControl.shutdown calls
|
2006-01-25 06:39:07 +01:00
|
|
|
w._controls = {}
|
2006-01-15 03:39:02 +01:00
|
|
|
w.window.destroy()
|
|
|
|
|
|
|
|
self._windows = {}
|
|
|
|
|
|
|
|
for ctrl in controls:
|
2006-01-25 06:39:07 +01:00
|
|
|
mw = self.get_window(ctrl.contact.jid, ctrl.account)
|
2006-01-15 03:39:02 +01:00
|
|
|
if not mw:
|
2006-02-10 05:21:41 +01:00
|
|
|
mw = self.create_window(ctrl.contact, ctrl.account,
|
|
|
|
ctrl.type_id)
|
2006-01-15 03:39:02 +01:00
|
|
|
ctrl.parent_win = mw
|
|
|
|
mw.new_tab(ctrl)
|