2008-08-15 19:31:51 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/message_window.py
|
2005-12-28 00:55:34 +01:00
|
|
|
##
|
2014-01-02 09:33:54 +01:00
|
|
|
## Copyright (C) 2003-2014 Yann Leboulanger <asterix AT lagaule.org>
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2005-2008 Travis Shirk <travis AT pobox.com>
|
|
|
|
## Nikos Kouremenos <kourem AT gmail.com>
|
|
|
|
## Copyright (C) 2006 Geobert Quach <geobert AT gmail.com>
|
|
|
|
## Dimitur Kirov <dkirov AT gmail.com>
|
|
|
|
## Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
|
|
|
|
## Copyright (C) 2007 Julien Pivotto <roidelapluie AT gmail.com>
|
|
|
|
## Stephan Erb <steve-e AT h3c.de>
|
|
|
|
## Copyright (C) 2008 Brendan Taylor <whateley AT gmail.com>
|
|
|
|
## Jonathan Schleifer <js-gajim AT webkeks.org>
|
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
|
2008-08-15 05:20:23 +02:00
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-12-28 00:55:34 +01:00
|
|
|
## 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
|
2008-08-15 05:20:23 +02:00
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-22 13:13:13 +02:00
|
|
|
##
|
2005-12-28 00:55:34 +01:00
|
|
|
|
2017-10-08 18:09:15 +02:00
|
|
|
import time
|
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
from gi.repository import Gtk
|
|
|
|
from gi.repository import Gdk
|
2016-04-12 22:53:41 +02:00
|
|
|
from gi.repository import GdkPixbuf
|
2012-12-23 16:23:43 +01:00
|
|
|
from gi.repository import GObject
|
2013-07-28 20:50:30 +02:00
|
|
|
from gi.repository import GLib
|
2005-12-28 00:55:34 +01:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim import common
|
|
|
|
from gajim import gtkgui_helpers
|
|
|
|
from gajim import message_control
|
|
|
|
from gajim import dialogs
|
|
|
|
from gajim.chat_control_base import ChatControlBase
|
|
|
|
from gajim.chat_control import ChatControl
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2017-08-18 22:05:16 +02:00
|
|
|
from gajim.common.i18n import Q_
|
2005-12-28 00:55:34 +01:00
|
|
|
|
|
|
|
####################
|
|
|
|
|
Merge one_window branch
Merged revisions 9143,9145-9155,9157-9162,9164-9169,9171-9177 via svnmerge from
svn://88.191.11.156/gajim/branches/one_window
........
r9145 | nicfit | 2007-12-13 21:49:09 -0700 (Thu, 13 Dec 2007) | 2 lines
Implemented the original Nikos patch with an HPaned instead of a HBox and only do this mode when one_message_window == 'always'
........
r9152 | nicfit | 2007-12-15 13:33:56 -0700 (Sat, 15 Dec 2007) | 2 lines
Added config and GUI for one_message_window_with_roster
........
r9153 | nicfit | 2007-12-15 13:41:46 -0700 (Sat, 15 Dec 2007) | 2 lines
Use one_message_window_with_roster and some whitespace cleanup
........
r9154 | nicfit | 2007-12-15 14:04:49 -0700 (Sat, 15 Dec 2007) | 2 lines
Scratch the chckbox for with roster mode, use one_message_window opt and combo
........
r9155 | nicfit | 2007-12-15 17:01:13 -0700 (Sat, 15 Dec 2007) | 2 lines
MessageWindowMgr knows about ONE_MESSAGE_WINDOW_ALWAYS_WITH_ROSTER and MessageWindow can reparent itself rather then the roster having to do so.
........
r9157 | nicfit | 2007-12-15 17:47:20 -0700 (Sat, 15 Dec 2007) | 2 lines
Resizing fixes and make the roster window shrink when last tab is removed
........
r9158 | nicfit | 2007-12-15 19:15:11 -0700 (Sat, 15 Dec 2007) | 2 lines
Added "Show roster" (CTRL+R) to view menu when using always_with_roster to quickly hide/show the roster.
........
r9159 | nicfit | 2007-12-15 19:49:30 -0700 (Sat, 15 Dec 2007) | 2 lines
Handle window title setting in always_with_roster mode.
........
r9160 | nicfit | 2007-12-15 20:13:57 -0700 (Sat, 15 Dec 2007) | 2 lines
Removed FIXME
........
r9167 | nicfit | 2007-12-17 18:40:59 -0700 (Mon, 17 Dec 2007) | 2 lines
When roster is hidden, show it when the number of MessageWindow controls == 0
........
r9168 | nicfit | 2007-12-17 19:07:49 -0700 (Mon, 17 Dec 2007) | 2 lines
Disable hiding roster when there are no message controls open
........
r9169 | nicfit | 2007-12-17 20:41:11 -0700 (Mon, 17 Dec 2007) | 2 lines
Bunch of saved size bugs fixed
........
2007-12-19 00:42:22 +01:00
|
|
|
class MessageWindow(object):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Class for windows which contain message like things; chats, groupchats, etc
|
|
|
|
"""
|
|
|
|
|
|
|
|
# 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
|
|
|
|
(
|
|
|
|
CLOSE_TAB_MIDDLE_CLICK,
|
|
|
|
CLOSE_ESC,
|
|
|
|
CLOSE_CLOSE_BUTTON,
|
|
|
|
CLOSE_COMMAND,
|
|
|
|
CLOSE_CTRL_KEY
|
|
|
|
) = range(5)
|
|
|
|
|
|
|
|
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
|
|
|
|
self.account = acct
|
|
|
|
# If None, the window is not tied to any specific type
|
|
|
|
self.type_ = type_
|
|
|
|
# dict { handler id: widget}. Keeps callbacks, which
|
|
|
|
# lead to cylcular references
|
|
|
|
self.handlers = {}
|
|
|
|
# Don't show warning dialogs when we want to delete the window
|
|
|
|
self.dont_warn_on_delete = False
|
|
|
|
|
|
|
|
self.widget_name = 'message_window'
|
|
|
|
self.xml = gtkgui_helpers.get_gtk_builder('%s.ui' % self.widget_name)
|
|
|
|
self.window = self.xml.get_object(self.widget_name)
|
2017-10-08 18:08:13 +02:00
|
|
|
self.window.set_application(app.app)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.notebook = self.xml.get_object('notebook')
|
|
|
|
self.parent_paned = None
|
|
|
|
|
|
|
|
if parent_window:
|
|
|
|
orig_window = self.window
|
|
|
|
self.window = parent_window
|
|
|
|
self.parent_paned = parent_paned
|
2015-07-18 16:00:57 +02:00
|
|
|
old_parent = self.notebook.get_parent()
|
|
|
|
old_parent.remove(self.notebook)
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.config.get('roster_on_the_right'):
|
2016-02-21 11:07:04 +01:00
|
|
|
child1 = self.parent_paned.get_child1()
|
|
|
|
self.parent_paned.remove(child1)
|
2017-10-03 13:08:06 +02:00
|
|
|
self.parent_paned.pack1(self.notebook, resize=False)
|
|
|
|
self.parent_paned.pack2(child1)
|
2016-02-21 11:07:04 +01:00
|
|
|
else:
|
2017-10-03 13:08:06 +02:00
|
|
|
self.parent_paned.pack2(self.notebook)
|
2017-02-28 16:49:01 +01:00
|
|
|
self.window.lookup_action('show-roster').set_enabled(True)
|
2010-02-08 15:08:40 +01:00
|
|
|
orig_window.destroy()
|
|
|
|
del orig_window
|
|
|
|
|
2017-10-03 13:08:06 +02:00
|
|
|
# Set headermenu
|
|
|
|
# single-window mode: show the header menu on the roster window
|
|
|
|
# all other modes: add the headerbar to the new window
|
|
|
|
# A headerbar has to be set before the window calls show()
|
|
|
|
if parent_window:
|
|
|
|
self.header_menu = app.interface.roster.header_menu
|
|
|
|
self.header_menu.show()
|
|
|
|
else:
|
|
|
|
self.header_menu = self.xml.get_object('header_menu')
|
|
|
|
headerbar = self.xml.get_object('headerbar')
|
|
|
|
self.window.set_titlebar(headerbar)
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
# NOTE: we use 'connect_after' here because in
|
|
|
|
# MessageWindowMgr._new_window we register handler that saves window
|
|
|
|
# state when closing it, and it should be called before
|
|
|
|
# MessageWindow._on_window_delete, which manually destroys window
|
|
|
|
# through win.destroy() - this means no additional handlers for
|
|
|
|
# 'delete-event' are called.
|
|
|
|
id_ = self.window.connect_after('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
|
|
|
|
|
|
|
|
keys=['<Control>f', '<Control>g', '<Control>h', '<Control>i',
|
|
|
|
'<Control>l', '<Control>L', '<Control><Shift>n', '<Control>u',
|
|
|
|
'<Control>b', '<Control>F4',
|
|
|
|
'<Control>w', '<Control>Page_Up', '<Control>Page_Down', '<Alt>Right',
|
|
|
|
'<Alt>Left', '<Alt>d', '<Alt>c', '<Alt>m', '<Alt>t', 'Escape'] + \
|
2017-02-07 21:05:27 +01:00
|
|
|
['<Alt>'+str(i) for i in range(10)]
|
2012-12-23 16:23:43 +01:00
|
|
|
accel_group = Gtk.AccelGroup()
|
2010-02-08 15:08:40 +01:00
|
|
|
for key in keys:
|
2012-12-23 16:23:43 +01:00
|
|
|
keyval, mod = Gtk.accelerator_parse(key)
|
|
|
|
accel_group.connect(keyval, mod, Gtk.AccelFlags.VISIBLE,
|
2012-09-30 21:31:45 +02:00
|
|
|
self.accel_group_func)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.window.add_accel_group(accel_group)
|
|
|
|
|
|
|
|
# gtk+ doesn't make use of the motion notify on gtkwindow by default
|
|
|
|
# so this line adds that
|
2012-12-23 16:23:43 +01:00
|
|
|
self.window.add_events(Gdk.EventMask.POINTER_MOTION_MASK)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
id_ = self.notebook.connect('switch-page',
|
2012-09-30 21:31:45 +02:00
|
|
|
self._on_notebook_switch_page)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.handlers[id_] = self.notebook
|
|
|
|
id_ = self.notebook.connect('key-press-event',
|
2012-09-30 21:31:45 +02:00
|
|
|
self._on_notebook_key_press)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.handlers[id_] = self.notebook
|
|
|
|
|
|
|
|
# Tab customizations
|
2017-08-13 13:18:56 +02:00
|
|
|
pref_pos = app.config.get('tabs_position')
|
2010-02-08 15:08:40 +01:00
|
|
|
if pref_pos == 'bottom':
|
2012-12-23 16:23:43 +01:00
|
|
|
nb_pos = Gtk.PositionType.BOTTOM
|
2010-02-08 15:08:40 +01:00
|
|
|
elif pref_pos == 'left':
|
2012-12-23 16:23:43 +01:00
|
|
|
nb_pos = Gtk.PositionType.LEFT
|
2010-02-08 15:08:40 +01:00
|
|
|
elif pref_pos == 'right':
|
2012-12-23 16:23:43 +01:00
|
|
|
nb_pos = Gtk.PositionType.RIGHT
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2012-12-23 16:23:43 +01:00
|
|
|
nb_pos = Gtk.PositionType.TOP
|
2010-02-08 15:08:40 +01:00
|
|
|
self.notebook.set_tab_pos(nb_pos)
|
2017-08-13 13:18:56 +02:00
|
|
|
window_mode = app.interface.msg_win_mgr.mode
|
|
|
|
if app.config.get('tabs_always_visible') or \
|
2010-02-08 15:08:40 +01:00
|
|
|
window_mode == MessageWindowMgr.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER:
|
|
|
|
self.notebook.set_show_tabs(True)
|
|
|
|
else:
|
|
|
|
self.notebook.set_show_tabs(False)
|
2017-08-13 13:18:56 +02:00
|
|
|
self.notebook.set_show_border(app.config.get('tabs_border'))
|
2010-02-08 15:08:40 +01:00
|
|
|
self.show_icon()
|
|
|
|
|
2017-10-03 13:08:06 +02:00
|
|
|
def set_header_menu(self, menu):
|
|
|
|
self.header_menu.set_menu_model(menu)
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def change_account_name(self, old_name, new_name):
|
|
|
|
if old_name in self._controls:
|
|
|
|
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
|
|
|
|
|
|
|
|
def change_jid(self, account, old_jid, new_jid):
|
|
|
|
"""
|
|
|
|
Called when the full jid of the control is changed
|
|
|
|
"""
|
|
|
|
if account not in self._controls:
|
|
|
|
return
|
|
|
|
if old_jid not in self._controls[account]:
|
|
|
|
return
|
|
|
|
if old_jid == new_jid:
|
|
|
|
return
|
|
|
|
self._controls[account][new_jid] = self._controls[account][old_jid]
|
|
|
|
del self._controls[account][old_jid]
|
|
|
|
|
|
|
|
def get_num_controls(self):
|
|
|
|
return sum(len(d) for d in self._controls.values())
|
|
|
|
|
|
|
|
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)
|
|
|
|
# to remove urgency hint so this functions does that
|
|
|
|
gtkgui_helpers.set_unset_urgency_hint(self.window, False)
|
|
|
|
|
|
|
|
ctrl = self.get_active_control()
|
|
|
|
if ctrl:
|
|
|
|
ctrl.set_control_active(True)
|
|
|
|
# Undo "unread" state display, etc.
|
|
|
|
if ctrl.type_id == message_control.TYPE_GC:
|
|
|
|
self.redraw_tab(ctrl, 'active')
|
|
|
|
else:
|
|
|
|
# NOTE: we do not send any chatstate to preserve
|
|
|
|
# inactive, gone, etc.
|
|
|
|
self.redraw_tab(ctrl)
|
|
|
|
|
|
|
|
def _on_window_delete(self, win, event):
|
|
|
|
if self.dont_warn_on_delete:
|
|
|
|
# Destroy the window
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Number of controls that will be closed and for which we'll loose data:
|
|
|
|
# chat, pm, gc that won't go in roster
|
|
|
|
number_of_closed_control = 0
|
|
|
|
for ctrl in self.controls():
|
|
|
|
if not ctrl.safe_shutdown():
|
|
|
|
number_of_closed_control += 1
|
|
|
|
|
|
|
|
if number_of_closed_control > 1:
|
|
|
|
def on_yes1(checked):
|
|
|
|
if checked:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.set('confirm_close_multiple_tabs', False)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.dont_warn_on_delete = True
|
|
|
|
for ctrl in self.controls():
|
|
|
|
if ctrl.minimizable():
|
|
|
|
ctrl.minimize()
|
|
|
|
win.destroy()
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
if not app.config.get('confirm_close_multiple_tabs'):
|
2014-03-29 17:52:22 +01:00
|
|
|
for ctrl in self.controls():
|
|
|
|
if ctrl.minimizable():
|
|
|
|
ctrl.minimize()
|
2010-02-08 15:08:40 +01:00
|
|
|
# destroy window
|
|
|
|
return False
|
|
|
|
dialogs.YesNoDialog(
|
2010-12-11 10:15:55 +01:00
|
|
|
_('You are going to close several tabs'),
|
|
|
|
_('Do you really want to close them all?'),
|
2013-09-09 17:36:21 +02:00
|
|
|
checktext=_('_Do not ask me again'), on_response_yes=on_yes1,
|
|
|
|
transient_for=self.window)
|
2010-02-08 15:08:40 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
def on_yes(ctrl):
|
|
|
|
if self.on_delete_ok == 1:
|
|
|
|
self.dont_warn_on_delete = True
|
|
|
|
win.destroy()
|
|
|
|
self.on_delete_ok -= 1
|
|
|
|
|
|
|
|
def on_no(ctrl):
|
|
|
|
return
|
|
|
|
|
|
|
|
def on_minimize(ctrl):
|
|
|
|
ctrl.minimize()
|
|
|
|
if self.on_delete_ok == 1:
|
|
|
|
self.dont_warn_on_delete = True
|
|
|
|
win.destroy()
|
|
|
|
self.on_delete_ok -= 1
|
|
|
|
|
|
|
|
# Make sure all controls are okay with being deleted
|
|
|
|
self.on_delete_ok = self.get_nb_controls()
|
|
|
|
for ctrl in self.controls():
|
|
|
|
ctrl.allow_shutdown(self.CLOSE_CLOSE_BUTTON, on_yes, on_no,
|
|
|
|
on_minimize)
|
|
|
|
return True # halt the delete for the moment
|
|
|
|
|
|
|
|
def _on_window_destroy(self, win):
|
|
|
|
for ctrl in self.controls():
|
|
|
|
ctrl.shutdown()
|
|
|
|
self._controls.clear()
|
|
|
|
# Clean up handlers connected to the parent window, this is important since
|
|
|
|
# self.window may be the RosterWindow
|
2013-01-03 17:09:40 +01:00
|
|
|
for i in list(self.handlers.keys()):
|
2010-02-08 15:08:40 +01:00
|
|
|
if self.handlers[i].handler_is_connected(i):
|
|
|
|
self.handlers[i].disconnect(i)
|
|
|
|
del self.handlers[i]
|
|
|
|
del self.handlers
|
|
|
|
|
|
|
|
def new_tab(self, control):
|
|
|
|
fjid = control.get_full_jid()
|
|
|
|
|
|
|
|
if control.account not in self._controls:
|
|
|
|
self._controls[control.account] = {}
|
|
|
|
|
|
|
|
self._controls[control.account][fjid] = control
|
|
|
|
|
|
|
|
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
|
|
|
|
self.notebook.set_show_tabs(True)
|
|
|
|
if scrolled:
|
2013-07-28 20:50:30 +02:00
|
|
|
GLib.idle_add(conv_textview.scroll_to_end_iter)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
# Add notebook page and connect up to the tab's close button
|
|
|
|
xml = gtkgui_helpers.get_gtk_builder('message_window.ui', 'chat_tab_ebox')
|
|
|
|
tab_label_box = xml.get_object('chat_tab_ebox')
|
|
|
|
widget = xml.get_object('tab_close_button')
|
2012-12-23 16:23:43 +01:00
|
|
|
# this reduces the size of the button
|
|
|
|
# style = Gtk.RcStyle()
|
|
|
|
# style.xthickness = 0
|
|
|
|
# style.ythickness = 0
|
|
|
|
# widget.modify_style(style)
|
2010-12-09 13:55:58 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
id_ = widget.connect('clicked', self._on_close_button_clicked, control)
|
|
|
|
control.handlers[id_] = widget
|
|
|
|
|
2010-12-11 10:15:55 +01:00
|
|
|
id_ = tab_label_box.connect('button-press-event',
|
|
|
|
self.on_tab_eventbox_button_press_event, control.widget)
|
2010-02-08 15:08:40 +01:00
|
|
|
control.handlers[id_] = tab_label_box
|
|
|
|
self.notebook.append_page(control.widget, tab_label_box)
|
|
|
|
|
|
|
|
self.notebook.set_tab_reorderable(control.widget, True)
|
|
|
|
|
|
|
|
self.redraw_tab(control)
|
|
|
|
if self.parent_paned:
|
|
|
|
self.notebook.show_all()
|
|
|
|
else:
|
|
|
|
self.window.show_all()
|
2017-10-03 13:08:06 +02:00
|
|
|
|
2010-07-30 14:38:19 +02:00
|
|
|
# NOTE: we do not call set_control_active(True) since we don't know
|
|
|
|
# whether the tab is the active one.
|
2010-02-08 15:08:40 +01:00
|
|
|
self.show_title()
|
2015-11-23 22:05:19 +01:00
|
|
|
if self.get_num_controls() == 1:
|
|
|
|
GLib.timeout_add(500, control.msg_textview.grab_focus)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_tab_eventbox_button_press_event(self, widget, event, child):
|
|
|
|
if event.button == 3: # right click
|
|
|
|
n = self.notebook.page_num(child)
|
|
|
|
self.notebook.set_current_page(n)
|
|
|
|
self.popup_menu(event)
|
|
|
|
elif event.button == 2: # middle click
|
|
|
|
ctrl = self._widget_to_control(child)
|
|
|
|
self.remove_tab(ctrl, self.CLOSE_TAB_MIDDLE_CLICK)
|
2010-12-11 10:15:55 +01:00
|
|
|
else:
|
|
|
|
ctrl = self._widget_to_control(child)
|
2013-07-28 20:50:30 +02:00
|
|
|
GLib.idle_add(ctrl.msg_textview.grab_focus)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def accel_group_func(self, accel_group, acceleratable, keyval, modifier):
|
|
|
|
st = '1234567890' # alt+1 means the first tab (tab 0)
|
|
|
|
control = self.get_active_control()
|
|
|
|
if not control:
|
|
|
|
# No more control in this window
|
|
|
|
return
|
|
|
|
|
|
|
|
# CTRL mask
|
2012-12-23 16:23:43 +01:00
|
|
|
if modifier & Gdk.ModifierType.CONTROL_MASK:
|
|
|
|
if keyval == Gdk.KEY_h: # CTRL + h
|
|
|
|
if Gtk.Settings.get_default().get_property(
|
2012-11-08 12:09:13 +01:00
|
|
|
'gtk-key-theme-name') != 'Emacs':
|
|
|
|
control._on_history_menuitem_activate()
|
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
elif control.type_id == message_control.TYPE_CHAT and \
|
2012-12-23 16:23:43 +01:00
|
|
|
keyval == Gdk.KEY_f: # CTRL + f
|
2011-05-26 19:39:03 +02:00
|
|
|
# CTRL + f moves cursor one char forward when user uses Emacs
|
|
|
|
# theme
|
2012-12-23 16:23:43 +01:00
|
|
|
if not Gtk.Settings.get_default().get_property(
|
2011-05-26 19:39:03 +02:00
|
|
|
'gtk-key-theme-name') == 'Emacs':
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.interface.msg_win_mgr.mode == \
|
|
|
|
app.interface.msg_win_mgr.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER:
|
|
|
|
app.interface.roster.tree.grab_focus()
|
2015-07-14 14:11:06 +02:00
|
|
|
return False
|
2011-05-26 19:39:03 +02:00
|
|
|
control._on_send_file_menuitem_activate(None)
|
2012-09-30 21:31:45 +02:00
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
elif control.type_id == message_control.TYPE_CHAT and \
|
2012-12-23 16:23:43 +01:00
|
|
|
keyval == Gdk.KEY_g: # CTRL + g
|
2010-02-08 15:08:40 +01:00
|
|
|
control._on_convert_to_gc_menuitem_activate(None)
|
2012-09-30 21:31:45 +02:00
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
elif control.type_id in (message_control.TYPE_CHAT,
|
2012-12-23 16:23:43 +01:00
|
|
|
message_control.TYPE_PM) and keyval == Gdk.KEY_i: # CTRL + i
|
2010-02-08 15:08:40 +01:00
|
|
|
control._on_contact_information_menuitem_activate(None)
|
2012-09-30 21:31:45 +02:00
|
|
|
return True
|
2012-12-23 16:23:43 +01:00
|
|
|
elif keyval == Gdk.KEY_l or keyval == Gdk.KEY_L: # CTRL + l|L
|
2010-02-08 15:08:40 +01:00
|
|
|
control.conv_textview.clear()
|
2012-09-30 21:31:45 +02:00
|
|
|
return True
|
2012-12-23 16:23:43 +01:00
|
|
|
elif keyval == Gdk.KEY_u: # CTRL + u: emacs style clear line
|
2010-02-08 15:08:40 +01:00
|
|
|
control.clear(control.msg_textview)
|
2012-09-30 21:31:45 +02:00
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
elif control.type_id == message_control.TYPE_GC and \
|
2012-12-23 16:23:43 +01:00
|
|
|
keyval == Gdk.KEY_b: # CTRL + b
|
2015-07-13 10:14:34 +02:00
|
|
|
# CTRL + b moves cursor one char backward when user uses Emacs
|
|
|
|
# theme
|
|
|
|
if not Gtk.Settings.get_default().get_property(
|
|
|
|
'gtk-key-theme-name') == 'Emacs':
|
|
|
|
control._on_bookmark_room_menuitem_activate(None)
|
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
# Tab switch bindings
|
2012-12-23 16:23:43 +01:00
|
|
|
elif keyval == Gdk.KEY_F4: # CTRL + F4
|
2010-02-08 15:08:40 +01:00
|
|
|
self.remove_tab(control, self.CLOSE_CTRL_KEY)
|
2012-09-30 21:31:45 +02:00
|
|
|
return True
|
2012-12-23 16:23:43 +01:00
|
|
|
elif keyval == Gdk.KEY_w: # CTRL + w
|
2010-02-08 15:08:40 +01:00
|
|
|
# CTRL + w removes latest word before sursor when User uses emacs
|
|
|
|
# theme
|
2012-12-23 16:23:43 +01:00
|
|
|
if not Gtk.Settings.get_default().get_property(
|
2010-02-08 15:08:40 +01:00
|
|
|
'gtk-key-theme-name') == 'Emacs':
|
|
|
|
self.remove_tab(control, self.CLOSE_CTRL_KEY)
|
2012-09-30 21:31:45 +02:00
|
|
|
return True
|
2012-12-23 16:23:43 +01:00
|
|
|
elif keyval in (Gdk.KEY_Page_Up, Gdk.KEY_Page_Down):
|
2010-02-08 15:08:40 +01:00
|
|
|
# CTRL + PageUp | PageDown
|
|
|
|
# Create event and send it to notebook
|
2017-01-24 12:41:10 +01:00
|
|
|
event = Gdk.Event.new(Gdk.EventType.KEY_PRESS)
|
2013-01-21 20:50:52 +01:00
|
|
|
event.window = self.window.get_window()
|
2010-02-08 15:08:40 +01:00
|
|
|
event.time = int(time.time())
|
2012-12-23 16:23:43 +01:00
|
|
|
event.state = Gdk.ModifierType.CONTROL_MASK
|
2010-02-08 15:08:40 +01:00
|
|
|
event.keyval = int(keyval)
|
2013-01-08 21:56:36 +01:00
|
|
|
self.notebook.event(event)
|
2012-09-30 21:31:45 +02:00
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
if modifier & Gdk.ModifierType.SHIFT_MASK:
|
2010-02-08 15:08:40 +01:00
|
|
|
# CTRL + SHIFT
|
|
|
|
if control.type_id == message_control.TYPE_GC and \
|
2012-12-23 16:23:43 +01:00
|
|
|
keyval == Gdk.KEY_n: # CTRL + SHIFT + n
|
2010-02-08 15:08:40 +01:00
|
|
|
control._on_change_nick_menuitem_activate(None)
|
2012-09-30 21:31:45 +02:00
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
# MOD1 (ALT) mask
|
2012-12-23 16:23:43 +01:00
|
|
|
elif modifier & Gdk.ModifierType.MOD1_MASK:
|
2010-02-08 15:08:40 +01:00
|
|
|
# Tab switch bindings
|
2012-12-23 16:23:43 +01:00
|
|
|
if keyval == Gdk.KEY_Right: # ALT + RIGHT
|
2010-02-08 15:08:40 +01:00
|
|
|
new = self.notebook.get_current_page() + 1
|
|
|
|
if new >= self.notebook.get_n_pages():
|
|
|
|
new = 0
|
|
|
|
self.notebook.set_current_page(new)
|
2012-09-30 21:31:45 +02:00
|
|
|
return True
|
2012-12-23 16:23:43 +01:00
|
|
|
elif keyval == Gdk.KEY_Left: # ALT + LEFT
|
2010-02-08 15:08:40 +01:00
|
|
|
new = self.notebook.get_current_page() - 1
|
|
|
|
if new < 0:
|
|
|
|
new = self.notebook.get_n_pages() - 1
|
|
|
|
self.notebook.set_current_page(new)
|
2012-09-30 21:31:45 +02:00
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
elif chr(keyval) in st: # ALT + 1,2,3..
|
|
|
|
self.notebook.set_current_page(st.index(chr(keyval)))
|
2012-09-30 21:31:45 +02:00
|
|
|
return True
|
2012-12-23 16:23:43 +01:00
|
|
|
elif keyval == Gdk.KEY_m: # ALT + M show emoticons menu
|
2017-06-16 19:36:32 +02:00
|
|
|
control.emoticons_button.get_popover().show()
|
2012-09-30 21:31:45 +02:00
|
|
|
return True
|
2012-12-23 16:23:43 +01:00
|
|
|
elif keyval == Gdk.KEY_d: # ALT + D show actions menu
|
|
|
|
if Gtk.Settings.get_default().get_property(
|
2012-11-08 12:09:13 +01:00
|
|
|
'gtk-key-theme-name') != 'Emacs':
|
|
|
|
control.on_actions_button_clicked(control.actions_button)
|
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
elif control.type_id == message_control.TYPE_GC and \
|
2012-12-23 16:23:43 +01:00
|
|
|
keyval == Gdk.KEY_t: # ALT + t
|
2010-02-08 15:08:40 +01:00
|
|
|
control._on_change_subject_menuitem_activate(None)
|
2012-09-30 21:31:45 +02:00
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
# Close tab bindings
|
2012-12-23 16:23:43 +01:00
|
|
|
elif keyval == Gdk.KEY_Escape and \
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.get('escape_key_closes'): # Escape
|
2010-02-08 15:08:40 +01:00
|
|
|
self.remove_tab(control, self.CLOSE_ESC)
|
2012-09-30 21:31:45 +02:00
|
|
|
return True
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _on_close_button_clicked(self, button, control):
|
|
|
|
"""
|
|
|
|
When close button is pressed: close a tab
|
|
|
|
"""
|
|
|
|
self.remove_tab(control, self.CLOSE_CLOSE_BUTTON)
|
|
|
|
|
|
|
|
def show_icon(self):
|
2017-08-13 13:18:56 +02:00
|
|
|
window_mode = app.interface.msg_win_mgr.mode
|
2010-02-08 15:08:40 +01:00
|
|
|
icon = None
|
|
|
|
if window_mode == MessageWindowMgr.ONE_MSG_WINDOW_NEVER:
|
|
|
|
ctrl = self.get_active_control()
|
|
|
|
if not ctrl:
|
|
|
|
return
|
|
|
|
icon = ctrl.get_tab_image(count_unread=False)
|
|
|
|
elif window_mode == MessageWindowMgr.ONE_MSG_WINDOW_ALWAYS:
|
|
|
|
pass # keep default icon
|
|
|
|
elif window_mode == MessageWindowMgr.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER:
|
|
|
|
pass # keep default icon
|
|
|
|
elif window_mode == MessageWindowMgr.ONE_MSG_WINDOW_PERACCT:
|
|
|
|
pass # keep default icon
|
|
|
|
elif window_mode == MessageWindowMgr.ONE_MSG_WINDOW_PERTYPE:
|
|
|
|
if self.type_ == 'gc':
|
|
|
|
icon = gtkgui_helpers.load_icon('muc_active')
|
|
|
|
else:
|
|
|
|
# chat, pm
|
|
|
|
icon = gtkgui_helpers.load_icon('online')
|
|
|
|
if icon:
|
2016-04-12 22:53:41 +02:00
|
|
|
if isinstance(icon, GdkPixbuf.Pixbuf):
|
|
|
|
self.window.set_icon(icon)
|
|
|
|
else:
|
|
|
|
self.window.set_icon(icon.get_pixbuf())
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def show_title(self, urgent=True, control=None):
|
|
|
|
"""
|
|
|
|
Redraw the window's title
|
|
|
|
"""
|
|
|
|
if not control:
|
|
|
|
control = self.get_active_control()
|
|
|
|
if not control:
|
|
|
|
# No more control in this window
|
|
|
|
return
|
|
|
|
unread = 0
|
|
|
|
for ctrl in self.controls():
|
|
|
|
if ctrl.type_id == message_control.TYPE_GC and not \
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.get('notify_on_all_muc_messages') and not \
|
2017-08-20 23:07:58 +02:00
|
|
|
app.config.get_per('rooms', ctrl.room_jid,
|
|
|
|
'notify_on_all_messages') and not ctrl.attention_flag:
|
2010-02-08 15:08:40 +01:00
|
|
|
# count only pm messages
|
|
|
|
unread += ctrl.get_nb_unread_pm()
|
|
|
|
continue
|
|
|
|
unread += ctrl.get_nb_unread()
|
|
|
|
|
|
|
|
unread_str = ''
|
|
|
|
if unread > 1:
|
2013-01-01 21:06:16 +01:00
|
|
|
unread_str = '[' + str(unread) + '] '
|
2010-02-08 15:08:40 +01:00
|
|
|
elif unread == 1:
|
|
|
|
unread_str = '* '
|
|
|
|
else:
|
|
|
|
urgent = False
|
|
|
|
|
|
|
|
if control.type_id == message_control.TYPE_GC:
|
|
|
|
name = control.room_jid.split('@')[0]
|
2015-07-26 14:25:21 +02:00
|
|
|
urgent = control.attention_flag or \
|
2017-08-20 23:07:58 +02:00
|
|
|
app.config.get('notify_on_all_muc_messages') or \
|
|
|
|
app.config.get_per('rooms', control.room_jid,
|
|
|
|
'notify_on_all_messages')
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
name = control.contact.get_shown_name()
|
|
|
|
if control.resource:
|
|
|
|
name += '/' + control.resource
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
window_mode = app.interface.msg_win_mgr.mode
|
2010-02-08 15:08:40 +01:00
|
|
|
if window_mode == MessageWindowMgr.ONE_MSG_WINDOW_PERTYPE:
|
|
|
|
# Show the plural form since number of tabs > 1
|
|
|
|
if self.type_ == 'chat':
|
2017-08-18 22:05:16 +02:00
|
|
|
label = Q_('?Noun:Chats')
|
2010-02-08 15:08:40 +01:00
|
|
|
elif self.type_ == 'gc':
|
2017-02-04 23:29:45 +01:00
|
|
|
label = _('Groupchats')
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
label = _('Private Chats')
|
|
|
|
elif window_mode == MessageWindowMgr.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER:
|
|
|
|
label = None
|
|
|
|
elif self.get_num_controls() == 1:
|
|
|
|
label = name
|
|
|
|
else:
|
|
|
|
label = _('Messages')
|
|
|
|
|
|
|
|
title = 'Gajim'
|
|
|
|
if label:
|
|
|
|
title = '%s - %s' % (label, title)
|
|
|
|
|
|
|
|
if window_mode == MessageWindowMgr.ONE_MSG_WINDOW_PERACCT:
|
|
|
|
title = title + ": " + control.account
|
|
|
|
|
|
|
|
self.window.set_title(unread_str + title)
|
|
|
|
|
|
|
|
if urgent:
|
|
|
|
gtkgui_helpers.set_unset_urgency_hint(self.window, unread)
|
|
|
|
else:
|
|
|
|
gtkgui_helpers.set_unset_urgency_hint(self.window, False)
|
|
|
|
|
|
|
|
def set_active_tab(self, ctrl):
|
|
|
|
ctrl_page = self.notebook.page_num(ctrl.widget)
|
|
|
|
self.notebook.set_current_page(ctrl_page)
|
|
|
|
self.window.present()
|
2013-07-28 20:50:30 +02:00
|
|
|
GLib.idle_add(ctrl.msg_textview.grab_focus)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
"""
|
|
|
|
def close(ctrl):
|
2017-10-03 13:08:06 +02:00
|
|
|
self.remove_headermenu(self.notebook, ctrl)
|
2010-02-08 15:08:40 +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()
|
|
|
|
# Update external state
|
2017-08-13 13:18:56 +02:00
|
|
|
app.events.remove_events(ctrl.account, ctrl.get_full_jid,
|
2010-02-08 15:08:40 +01:00
|
|
|
types = ['printed_msg', 'chat', 'gc_msg'])
|
|
|
|
|
|
|
|
fjid = ctrl.get_full_jid()
|
2017-08-13 13:18:56 +02:00
|
|
|
jid = app.get_jid_without_resource(fjid)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
fctrl = self.get_control(fjid, ctrl.account)
|
|
|
|
bctrl = self.get_control(jid, ctrl.account)
|
|
|
|
# keep last_message_time around unless this was our last control with
|
|
|
|
# that jid
|
|
|
|
if not fctrl and not bctrl and \
|
2017-08-13 13:18:56 +02:00
|
|
|
fjid in app.last_message_time[ctrl.account]:
|
|
|
|
del app.last_message_time[ctrl.account][fjid]
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self.notebook.remove_page(self.notebook.page_num(ctrl.widget))
|
|
|
|
|
|
|
|
del self._controls[ctrl.account][fjid]
|
|
|
|
|
|
|
|
if len(self._controls[ctrl.account]) == 0:
|
|
|
|
del self._controls[ctrl.account]
|
|
|
|
|
|
|
|
self.check_tabs()
|
|
|
|
self.show_title()
|
|
|
|
|
|
|
|
def on_yes(ctrl):
|
|
|
|
close(ctrl)
|
|
|
|
|
|
|
|
def on_no(ctrl):
|
|
|
|
return
|
|
|
|
|
|
|
|
def on_minimize(ctrl):
|
|
|
|
if method != self.CLOSE_COMMAND:
|
2017-10-03 13:08:06 +02:00
|
|
|
self.remove_headermenu(self.notebook, ctrl)
|
2010-02-08 15:08:40 +01:00
|
|
|
ctrl.minimize()
|
|
|
|
self.check_tabs()
|
|
|
|
return
|
|
|
|
close(ctrl)
|
|
|
|
|
|
|
|
# Shutdown the MessageControl
|
|
|
|
if force:
|
|
|
|
close(ctrl)
|
|
|
|
else:
|
|
|
|
ctrl.allow_shutdown(method, on_yes, on_no, on_minimize)
|
|
|
|
|
2017-10-03 13:08:06 +02:00
|
|
|
def remove_headermenu(self, notebook, ctrl):
|
|
|
|
page_num = notebook.page_num(ctrl.widget)
|
|
|
|
if page_num == notebook.get_current_page():
|
|
|
|
self.set_header_menu(None)
|
|
|
|
elif notebook.get_n_pages() == 1:
|
|
|
|
self.set_header_menu(None)
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def check_tabs(self):
|
2016-02-21 10:32:55 +01:00
|
|
|
if self.parent_paned:
|
|
|
|
# Do nothing in single window mode
|
|
|
|
pass
|
|
|
|
elif self.get_num_controls() == 0:
|
2010-02-08 15:08:40 +01:00
|
|
|
# These are not called when the window is destroyed like this, fake it
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.msg_win_mgr._on_window_delete(self.window, None)
|
|
|
|
app.interface.msg_win_mgr._on_window_destroy(self.window)
|
2010-02-08 15:08:40 +01:00
|
|
|
# dnd clean up
|
|
|
|
self.notebook.drag_dest_unset()
|
|
|
|
if self.parent_paned:
|
|
|
|
# Don't close parent window, just remove the child
|
|
|
|
child = self.parent_paned.get_child2()
|
|
|
|
self.parent_paned.remove(child)
|
2017-02-28 16:49:01 +01:00
|
|
|
self.window.lookup_action('show-roster').set_enabled(False)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
self.window.destroy()
|
|
|
|
return # don't show_title, we are dead
|
|
|
|
elif self.get_num_controls() == 1: # we are going from two tabs to one
|
2017-08-13 13:18:56 +02:00
|
|
|
window_mode = app.interface.msg_win_mgr.mode
|
|
|
|
show_tabs_if_one_tab = app.config.get('tabs_always_visible') or \
|
2010-12-11 10:15:55 +01:00
|
|
|
window_mode == MessageWindowMgr.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER
|
2010-02-08 15:08:40 +01:00
|
|
|
self.notebook.set_show_tabs(show_tabs_if_one_tab)
|
|
|
|
|
2017-03-02 22:59:44 +01:00
|
|
|
def redraw_tab(self, ctrl, chatstate=None):
|
2011-07-22 12:05:38 +02:00
|
|
|
tab = self.notebook.get_tab_label(ctrl.widget)
|
|
|
|
if not tab:
|
|
|
|
return
|
|
|
|
hbox = tab.get_children()[0]
|
2010-02-08 15:08:40 +01:00
|
|
|
status_img = hbox.get_children()[0]
|
|
|
|
nick_label = hbox.get_children()[1]
|
|
|
|
|
|
|
|
# Optionally hide close button
|
|
|
|
close_button = hbox.get_children()[2]
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.config.get('tabs_close_button'):
|
2010-02-08 15:08:40 +01:00
|
|
|
close_button.show()
|
|
|
|
else:
|
|
|
|
close_button.hide()
|
|
|
|
|
|
|
|
# Update nick
|
|
|
|
nick_label.set_max_width_chars(10)
|
2017-03-02 22:59:44 +01:00
|
|
|
if isinstance(ctrl, ChatControl):
|
|
|
|
tab_label_str = ctrl.get_tab_label()
|
|
|
|
# Set Label Color
|
|
|
|
class_name = 'state_{}_color'.format(chatstate)
|
|
|
|
gtkgui_helpers.add_css_class(nick_label, class_name)
|
|
|
|
else:
|
|
|
|
tab_label_str, color = ctrl.get_tab_label(chatstate)
|
|
|
|
# Set Label Color
|
|
|
|
if color == 'active':
|
|
|
|
gtkgui_helpers.add_css_class(nick_label, None)
|
|
|
|
elif color is not None:
|
|
|
|
gtkgui_helpers.add_css_class(nick_label, color)
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
nick_label.set_markup(tab_label_str)
|
|
|
|
|
|
|
|
tab_img = ctrl.get_tab_image()
|
|
|
|
if tab_img:
|
2016-04-12 22:53:41 +02:00
|
|
|
if isinstance(tab_img, GdkPixbuf.Pixbuf):
|
|
|
|
status_img.set_from_pixbuf(tab_img)
|
|
|
|
elif tab_img.get_storage_type() == Gtk.ImageType.ANIMATION:
|
2010-02-08 15:08:40 +01:00
|
|
|
status_img.set_from_animation(tab_img.get_animation())
|
|
|
|
else:
|
|
|
|
status_img.set_from_pixbuf(tab_img.get_pixbuf())
|
|
|
|
|
|
|
|
self.show_icon()
|
|
|
|
|
|
|
|
def repaint_themed_widgets(self):
|
|
|
|
"""
|
|
|
|
Repaint controls in the window with theme color
|
|
|
|
"""
|
|
|
|
# iterate through controls and repaint
|
|
|
|
for ctrl in self.controls():
|
|
|
|
ctrl.repaint_themed_widgets()
|
|
|
|
|
|
|
|
def _widget_to_control(self, widget):
|
|
|
|
for ctrl in self.controls():
|
|
|
|
if ctrl.widget == widget:
|
|
|
|
return ctrl
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_active_control(self):
|
|
|
|
notebook = self.notebook
|
|
|
|
active_widget = notebook.get_nth_page(notebook.get_current_page())
|
|
|
|
return self._widget_to_control(active_widget)
|
|
|
|
|
|
|
|
def get_active_contact(self):
|
|
|
|
ctrl = self.get_active_control()
|
|
|
|
if ctrl:
|
|
|
|
return ctrl.contact
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_active_jid(self):
|
|
|
|
contact = self.get_active_contact()
|
|
|
|
if contact:
|
|
|
|
return contact.jid
|
|
|
|
return None
|
|
|
|
|
|
|
|
def is_active(self):
|
|
|
|
return self.window.is_active()
|
|
|
|
|
|
|
|
def get_origin(self):
|
2012-12-27 21:58:52 +01:00
|
|
|
return self.window.get_window().get_origin()
|
2010-02-08 15:08:40 +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
|
|
|
|
"""
|
|
|
|
|
2013-01-01 21:06:16 +01:00
|
|
|
if isinstance(key, str):
|
2010-02-08 15:08:40 +01:00
|
|
|
jid = key
|
|
|
|
try:
|
|
|
|
return self._controls[acct][jid]
|
|
|
|
except Exception:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
page_num = key
|
|
|
|
notebook = self.notebook
|
|
|
|
if page_num is None:
|
|
|
|
page_num = notebook.get_current_page()
|
|
|
|
nth_child = notebook.get_nth_page(page_num)
|
|
|
|
return self._widget_to_control(nth_child)
|
|
|
|
|
|
|
|
def has_control(self, jid, acct):
|
|
|
|
return (acct in self._controls and jid in self._controls[acct])
|
|
|
|
|
|
|
|
def change_key(self, old_jid, new_jid, acct):
|
|
|
|
"""
|
|
|
|
Change the JID key of a control
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
# Check if controls exists
|
|
|
|
ctrl = self._controls[acct][old_jid]
|
|
|
|
except KeyError:
|
|
|
|
return
|
|
|
|
|
2010-06-10 10:26:15 +02:00
|
|
|
if new_jid in self._controls[acct]:
|
|
|
|
self.remove_tab(self._controls[acct][new_jid],
|
|
|
|
self.CLOSE_CLOSE_BUTTON, force=True)
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self._controls[acct][new_jid] = ctrl
|
|
|
|
del self._controls[acct][old_jid]
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
if old_jid in app.last_message_time[acct]:
|
|
|
|
app.last_message_time[acct][new_jid] = \
|
|
|
|
app.last_message_time[acct][old_jid]
|
|
|
|
del app.last_message_time[acct][old_jid]
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def controls(self):
|
2013-01-06 23:07:39 +01:00
|
|
|
for jid_dict in list(self._controls.values()):
|
2013-02-17 21:12:09 +01:00
|
|
|
for ctrl in list(jid_dict.values()):
|
2010-02-08 15:08:40 +01:00
|
|
|
yield ctrl
|
|
|
|
|
|
|
|
def get_nb_controls(self):
|
|
|
|
return sum(len(jid_dict) for jid_dict in self._controls.values())
|
|
|
|
|
|
|
|
def move_to_next_unread_tab(self, forward):
|
|
|
|
ind = self.notebook.get_current_page()
|
|
|
|
current = ind
|
|
|
|
found = False
|
2010-12-11 10:15:55 +01:00
|
|
|
first_composing_ind = -1 # id of first composing ctrl to switch to
|
|
|
|
# if no others controls have awaiting events
|
2010-02-08 15:08:40 +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
|
|
|
|
ctrl = self.get_control(ind, None)
|
|
|
|
if ctrl.get_nb_unread() > 0:
|
|
|
|
found = True
|
|
|
|
break # found
|
2017-08-13 13:18:56 +02:00
|
|
|
elif app.config.get('ctrl_tab_go_to_next_composing') :
|
2010-12-11 10:15:55 +01:00
|
|
|
# Search for a composing contact
|
2010-02-08 15:08:40 +01: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
|
|
|
|
if found:
|
|
|
|
self.notebook.set_current_page(ind)
|
|
|
|
elif first_composing_ind != -1:
|
|
|
|
self.notebook.set_current_page(first_composing_ind)
|
|
|
|
else: # not found and nobody composing
|
|
|
|
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)
|
|
|
|
|
|
|
|
def popup_menu(self, event):
|
|
|
|
menu = self.get_active_control().prepare_context_menu()
|
2017-10-03 13:08:06 +02:00
|
|
|
if menu is None:
|
|
|
|
return
|
2010-02-08 15:08:40 +01:00
|
|
|
# show the menu
|
2017-08-13 13:18:56 +02:00
|
|
|
menu.attach_to_widget(app.interface.roster.window, None)
|
2010-02-08 15:08:40 +01:00
|
|
|
menu.show_all()
|
2013-01-06 21:20:18 +01:00
|
|
|
menu.popup(None, None, None, None, event.button, event.time)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _on_notebook_switch_page(self, notebook, page, page_num):
|
|
|
|
old_no = notebook.get_current_page()
|
|
|
|
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)
|
2017-10-03 13:08:06 +02:00
|
|
|
self.set_header_menu(new_ctrl.control_menu)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
control = self.get_active_control()
|
|
|
|
if isinstance(control, ChatControlBase):
|
|
|
|
control.msg_textview.grab_focus()
|
|
|
|
|
|
|
|
def _on_notebook_key_press(self, widget, event):
|
2010-12-11 10:15:55 +01:00
|
|
|
# when tab itself is selected,
|
|
|
|
# make sure <- and -> are allowed for navigating between tabs
|
2012-12-23 16:23:43 +01:00
|
|
|
if event.keyval in (Gdk.KEY_Left, Gdk.KEY_Right):
|
2010-02-08 15:08:40 +01:00
|
|
|
return False
|
|
|
|
|
|
|
|
control = self.get_active_control()
|
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
if event.get_state() & Gdk.ModifierType.SHIFT_MASK:
|
2010-02-08 15:08:40 +01:00
|
|
|
# CTRL + SHIFT + TAB
|
2012-12-23 16:23:43 +01:00
|
|
|
if event.get_state() & Gdk.ModifierType.CONTROL_MASK and \
|
|
|
|
event.keyval == Gdk.KEY_ISO_Left_Tab:
|
2010-02-08 15:08:40 +01:00
|
|
|
self.move_to_next_unread_tab(False)
|
|
|
|
return True
|
|
|
|
# SHIFT + PAGE_[UP|DOWN]: send to conv_textview
|
2012-12-23 16:23:43 +01:00
|
|
|
elif event.keyval in (Gdk.KEY_Page_Down, Gdk.KEY_Page_Up):
|
2013-01-08 21:56:36 +01:00
|
|
|
control.conv_textview.tv.event(event)
|
2010-02-08 15:08:40 +01:00
|
|
|
return True
|
2012-12-23 16:23:43 +01:00
|
|
|
elif event.get_state() & Gdk.ModifierType.CONTROL_MASK:
|
|
|
|
if event.keyval == Gdk.KEY_Tab: # CTRL + TAB
|
2010-02-08 15:08:40 +01:00
|
|
|
self.move_to_next_unread_tab(True)
|
|
|
|
return True
|
|
|
|
# Ctrl+PageUP / DOWN has to be handled by notebook
|
2012-12-23 16:23:43 +01:00
|
|
|
elif event.keyval == Gdk.KEY_Page_Down:
|
2010-02-08 15:08:40 +01:00
|
|
|
self.move_to_next_unread_tab(True)
|
|
|
|
return True
|
2012-12-23 16:23:43 +01:00
|
|
|
elif event.keyval == Gdk.KEY_Page_Up:
|
2010-02-08 15:08:40 +01:00
|
|
|
self.move_to_next_unread_tab(False)
|
|
|
|
return True
|
2012-12-23 16:23:43 +01:00
|
|
|
if event.keyval in (Gdk.KEY_Shift_L, Gdk.KEY_Shift_R,
|
|
|
|
Gdk.KEY_Control_L, Gdk.KEY_Control_R, Gdk.KEY_Caps_Lock,
|
|
|
|
Gdk.KEY_Shift_Lock, Gdk.KEY_Meta_L, Gdk.KEY_Meta_R,
|
|
|
|
Gdk.KEY_Alt_L, Gdk.KEY_Alt_R, Gdk.KEY_Super_L,
|
|
|
|
Gdk.KEY_Super_R, Gdk.KEY_Hyper_L, Gdk.KEY_Hyper_R):
|
2010-02-08 15:08:40 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
if isinstance(control, ChatControlBase):
|
|
|
|
# we forwarded it to message textview
|
2017-10-03 13:08:06 +02:00
|
|
|
control.msg_textview.remove_placeholder()
|
2013-01-08 21:56:36 +01:00
|
|
|
control.msg_textview.event(event)
|
2010-02-08 15:08:40 +01:00
|
|
|
control.msg_textview.grab_focus()
|
|
|
|
|
|
|
|
def get_tab_at_xy(self, x, y):
|
|
|
|
"""
|
|
|
|
Return the tab under xy and if its nearer from left or right side of the
|
|
|
|
tab
|
|
|
|
"""
|
|
|
|
page_num = -1
|
|
|
|
to_right = False
|
2012-12-23 16:23:43 +01:00
|
|
|
horiz = self.notebook.get_tab_pos() == Gtk.PositionType.TOP or \
|
|
|
|
self.notebook.get_tab_pos() == Gtk.PositionType.BOTTOM
|
2017-02-07 21:05:27 +01:00
|
|
|
for i in range(self.notebook.get_n_pages()):
|
2010-02-08 15:08:40 +01:00
|
|
|
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 \
|
|
|
|
(x <= (tab_alloc.x + tab_alloc.width)):
|
|
|
|
page_num = i
|
|
|
|
if x >= tab_alloc.x + (tab_alloc.width / 2.0):
|
|
|
|
to_right = True
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
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
|
|
|
|
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
|
2017-02-07 21:05:27 +01:00
|
|
|
for i in range(self.notebook.get_n_pages()):
|
2010-02-08 15:08:40 +01:00
|
|
|
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
|
2006-01-12 04:09:33 +01:00
|
|
|
|
2006-01-02 03:12:34 +01:00
|
|
|
################################################################################
|
2012-12-23 16:23:43 +01:00
|
|
|
class MessageWindowMgr(GObject.GObject):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
A manager and factory for MessageWindow objects
|
|
|
|
"""
|
|
|
|
|
|
|
|
__gsignals__ = {
|
2012-12-23 16:23:43 +01:00
|
|
|
'window-delete': (GObject.SignalFlags.RUN_LAST, None, (object,)),
|
2010-02-08 15:08:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# These constants map to common.config.opt_one_window_types indices
|
|
|
|
(
|
|
|
|
ONE_MSG_WINDOW_NEVER,
|
|
|
|
ONE_MSG_WINDOW_ALWAYS,
|
|
|
|
ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER,
|
|
|
|
ONE_MSG_WINDOW_PERACCT,
|
|
|
|
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, parent_window, parent_paned):
|
|
|
|
"""
|
|
|
|
A dictionary of windows; the key depends on the config:
|
2010-12-11 10:15:55 +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_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
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
2012-12-23 16:23:43 +01:00
|
|
|
GObject.GObject.__init__(self)
|
2010-02-08 15:08:40 +01:00
|
|
|
self._windows = {}
|
|
|
|
|
|
|
|
# Map the mode to a int constant for frequent compares
|
2017-08-13 13:18:56 +02:00
|
|
|
mode = app.config.get('one_message_window')
|
2010-02-08 15:08:40 +01:00
|
|
|
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_):
|
|
|
|
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)
|
|
|
|
# we track the lifetime of this window
|
|
|
|
win.window.connect('delete-event', self._on_window_delete)
|
|
|
|
win.window.connect('destroy', self._on_window_destroy)
|
|
|
|
return win
|
|
|
|
|
|
|
|
def _gtk_win_to_msg_win(self, gtk_win):
|
|
|
|
for w in self.windows():
|
|
|
|
if w.window == gtk_win:
|
|
|
|
return w
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_window(self, jid, acct):
|
|
|
|
for win in self.windows():
|
|
|
|
if win.has_control(jid, acct):
|
|
|
|
return win
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
def has_window(self, jid, acct):
|
|
|
|
return self.get_window(jid, acct) is not None
|
|
|
|
|
|
|
|
def one_window_opened(self, contact=None, acct=None, type_=None):
|
|
|
|
try:
|
|
|
|
return \
|
2010-12-11 10:15:55 +01:00
|
|
|
self._windows[self._mode_to_key(contact, acct, type_)] is not None
|
2010-02-08 15:08:40 +01:00
|
|
|
except KeyError:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def _resize_window(self, win, acct, type_):
|
|
|
|
"""
|
|
|
|
Resizes window according to config settings
|
|
|
|
"""
|
2017-08-13 13:18:56 +02:00
|
|
|
hpaned = app.config.get('roster_hpaned_position')
|
2010-02-08 15:08:40 +01:00
|
|
|
if self.mode in (self.ONE_MSG_WINDOW_ALWAYS,
|
2016-10-03 22:43:17 +02:00
|
|
|
self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER):
|
2017-08-13 13:18:56 +02:00
|
|
|
size = (app.config.get('msgwin-width'),
|
|
|
|
app.config.get('msgwin-height'))
|
2010-02-08 15:08:40 +01:00
|
|
|
if self.mode == self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER:
|
|
|
|
# Need to add the size of the now visible paned handle, otherwise
|
|
|
|
# the saved width of the message window decreases by this amount
|
2016-10-03 22:43:17 +02:00
|
|
|
handle_size = win.parent_paned.style_get_property('handle-size')
|
|
|
|
size = (hpaned + size[0] + handle_size, size[1])
|
2010-02-08 15:08:40 +01:00
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_PERACCT:
|
2017-08-13 13:18:56 +02:00
|
|
|
size = (app.config.get_per('accounts', acct, 'msgwin-width'),
|
|
|
|
app.config.get_per('accounts', acct, 'msgwin-height'))
|
2010-02-08 15:08:40 +01:00
|
|
|
elif self.mode in (self.ONE_MSG_WINDOW_NEVER, self.ONE_MSG_WINDOW_PERTYPE):
|
|
|
|
opt_width = type_ + '-msgwin-width'
|
|
|
|
opt_height = type_ + '-msgwin-height'
|
2017-08-13 13:18:56 +02:00
|
|
|
size = (app.config.get(opt_width), app.config.get(opt_height))
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
return
|
|
|
|
win.resize(size[0], size[1])
|
|
|
|
if win.parent_paned:
|
2016-10-03 22:43:17 +02:00
|
|
|
win.parent_paned.set_position(hpaned)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def _position_window(self, win, acct, type_):
|
|
|
|
"""
|
|
|
|
Moves window according to config settings
|
|
|
|
"""
|
|
|
|
if (self.mode in [self.ONE_MSG_WINDOW_NEVER,
|
|
|
|
self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER]):
|
|
|
|
return
|
|
|
|
|
|
|
|
if self.mode == self.ONE_MSG_WINDOW_ALWAYS:
|
2017-08-13 13:18:56 +02:00
|
|
|
pos = (app.config.get('msgwin-x-position'),
|
|
|
|
app.config.get('msgwin-y-position'))
|
2010-02-08 15:08:40 +01:00
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_PERACCT:
|
2017-08-13 13:18:56 +02:00
|
|
|
pos = (app.config.get_per('accounts', acct, 'msgwin-x-position'),
|
|
|
|
app.config.get_per('accounts', acct, 'msgwin-y-position'))
|
2010-02-08 15:08:40 +01:00
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_PERTYPE:
|
2017-08-13 13:18:56 +02:00
|
|
|
pos = (app.config.get(type_ + '-msgwin-x-position'),
|
|
|
|
app.config.get(type_ + '-msgwin-y-position'))
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
return
|
|
|
|
|
|
|
|
gtkgui_helpers.move_window(win.window, pos[0], pos[1])
|
|
|
|
|
|
|
|
def _mode_to_key(self, contact, acct, type_, resource = None):
|
|
|
|
if self.mode == self.ONE_MSG_WINDOW_NEVER:
|
|
|
|
key = acct + contact.jid
|
|
|
|
if resource:
|
|
|
|
key += '/' + resource
|
|
|
|
return key
|
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_ALWAYS:
|
|
|
|
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:
|
|
|
|
return acct
|
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_PERTYPE:
|
|
|
|
return type_
|
|
|
|
|
|
|
|
def create_window(self, contact, acct, type_, resource = None):
|
|
|
|
win_acct = None
|
|
|
|
win_type = None
|
|
|
|
win_role = None # X11 window role
|
|
|
|
|
|
|
|
win_key = self._mode_to_key(contact, acct, type_, resource)
|
|
|
|
if self.mode == self.ONE_MSG_WINDOW_PERACCT:
|
|
|
|
win_acct = acct
|
|
|
|
win_role = acct
|
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_PERTYPE:
|
|
|
|
win_type = type_
|
|
|
|
win_role = type_
|
|
|
|
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[win_key]
|
|
|
|
except KeyError:
|
|
|
|
win = self._new_window(win_acct, win_type)
|
|
|
|
|
|
|
|
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_):
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.config.get('msgwin-max-state'):
|
2010-02-08 15:08:40 +01:00
|
|
|
win.window.maximize()
|
|
|
|
else:
|
|
|
|
self._resize_window(win, acct, type_)
|
|
|
|
self._position_window(win, acct, type_)
|
|
|
|
|
|
|
|
self._windows[win_key] = win
|
|
|
|
return win
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
def _on_window_delete(self, win, event):
|
|
|
|
self.save_state(self._gtk_win_to_msg_win(win))
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.save_config()
|
2010-02-08 15:08:40 +01:00
|
|
|
return False
|
|
|
|
|
|
|
|
def _on_window_destroy(self, win):
|
|
|
|
for k in self._windows.keys():
|
|
|
|
if self._windows[k].window == win:
|
|
|
|
self.emit('window-delete', self._windows[k])
|
|
|
|
del self._windows[k]
|
|
|
|
return
|
|
|
|
|
|
|
|
def get_control(self, jid, acct):
|
|
|
|
"""
|
|
|
|
Amongst all windows, return the MessageControl for jid
|
|
|
|
"""
|
|
|
|
win = self.get_window(jid, acct)
|
|
|
|
if win:
|
|
|
|
return win.get_control(jid, acct)
|
|
|
|
return None
|
|
|
|
|
2011-08-21 09:51:57 +02:00
|
|
|
def search_control(self, jid, account, resource=None):
|
|
|
|
"""
|
|
|
|
Search windows with this policy:
|
|
|
|
1. try to find already opened tab for resource
|
|
|
|
2. find the tab for this jid with ctrl.resource not set
|
|
|
|
3. there is none
|
|
|
|
"""
|
|
|
|
fjid = jid
|
|
|
|
if resource:
|
2011-08-22 12:31:24 +02:00
|
|
|
fjid += '/' + resource
|
2011-08-21 09:51:57 +02:00
|
|
|
ctrl = self.get_control(fjid, account)
|
|
|
|
if ctrl:
|
|
|
|
return ctrl
|
|
|
|
win = self.get_window(jid, account)
|
|
|
|
if win:
|
|
|
|
ctrl = win.get_control(jid, account)
|
2011-08-22 12:31:24 +02:00
|
|
|
if not ctrl.resource and ctrl.type_id != message_control.TYPE_GC:
|
2011-08-21 09:51:57 +02:00
|
|
|
return ctrl
|
|
|
|
return None
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def get_gc_control(self, jid, acct):
|
|
|
|
"""
|
|
|
|
Same as get_control. Was briefly required, is not any more. May be useful
|
|
|
|
some day in the future?
|
|
|
|
"""
|
|
|
|
ctrl = self.get_control(jid, acct)
|
|
|
|
if ctrl and ctrl.type_id == message_control.TYPE_GC:
|
|
|
|
return ctrl
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_controls(self, type_=None, acct=None):
|
|
|
|
ctrls = []
|
|
|
|
for c in self.controls():
|
|
|
|
if acct and c.account != acct:
|
|
|
|
continue
|
|
|
|
if not type_ or c.type_id == type_:
|
|
|
|
ctrls.append(c)
|
|
|
|
return ctrls
|
|
|
|
|
|
|
|
def windows(self):
|
2013-01-03 17:09:40 +01:00
|
|
|
for w in list(self._windows.values()):
|
2010-02-08 15:08:40 +01:00
|
|
|
yield w
|
|
|
|
|
|
|
|
def controls(self):
|
|
|
|
for w in self._windows.values():
|
|
|
|
for c in w.controls():
|
|
|
|
yield c
|
|
|
|
|
|
|
|
def shutdown(self, width_adjust=0):
|
|
|
|
for w in self.windows():
|
|
|
|
self.save_state(w, width_adjust)
|
|
|
|
if not w.parent_paned:
|
|
|
|
w.window.hide()
|
|
|
|
w.window.destroy()
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.save_config()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def save_state(self, msg_win, width_adjust=0):
|
|
|
|
# Save window size and position
|
|
|
|
max_win_key = 'msgwin-max-state'
|
|
|
|
pos_x_key = 'msgwin-x-position'
|
|
|
|
pos_y_key = 'msgwin-y-position'
|
|
|
|
size_width_key = 'msgwin-width'
|
|
|
|
size_height_key = 'msgwin-height'
|
|
|
|
|
|
|
|
acct = None
|
|
|
|
x, y = msg_win.window.get_position()
|
|
|
|
width, height = msg_win.window.get_size()
|
|
|
|
|
|
|
|
# If any of these values seem bogus don't update.
|
|
|
|
if x < 0 or y < 0 or width < 0 or height < 0:
|
|
|
|
return
|
|
|
|
|
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_PERACCT:
|
|
|
|
acct = msg_win.account
|
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_PERTYPE:
|
|
|
|
type_ = msg_win.type_
|
|
|
|
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'
|
|
|
|
elif self.mode == self.ONE_MSG_WINDOW_NEVER:
|
|
|
|
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:
|
|
|
|
# Ignore any hpaned width
|
2012-12-23 16:23:43 +01:00
|
|
|
width = msg_win.notebook.get_allocation().width
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
if acct:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.set_per('accounts', acct, size_width_key, width)
|
|
|
|
app.config.set_per('accounts', acct, size_height_key, height)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
if self.mode != self.ONE_MSG_WINDOW_NEVER:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.set_per('accounts', acct, pos_x_key, x)
|
|
|
|
app.config.set_per('accounts', acct, pos_y_key, y)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
else:
|
2012-12-23 16:23:43 +01:00
|
|
|
win_maximized = msg_win.window.get_window().get_state() == \
|
|
|
|
Gdk.WindowState.MAXIMIZED
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.set(max_win_key, win_maximized)
|
2010-02-08 15:08:40 +01:00
|
|
|
width += width_adjust
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.set(size_width_key, width)
|
|
|
|
app.config.set(size_height_key, height)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
if self.mode != self.ONE_MSG_WINDOW_NEVER:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.set(pos_x_key, x)
|
|
|
|
app.config.set(pos_y_key, y)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def reconfig(self):
|
|
|
|
for w in self.windows():
|
|
|
|
self.save_state(w)
|
2017-08-13 13:18:56 +02:00
|
|
|
mode = app.config.get('one_message_window')
|
2010-02-08 15:08:40 +01:00
|
|
|
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 = []
|
|
|
|
for w in self.windows():
|
|
|
|
# Note, we are taking care not to hide/delete the roster window when the
|
|
|
|
# MessageWindow is embedded.
|
|
|
|
if not w.parent_paned:
|
|
|
|
w.window.hide()
|
|
|
|
else:
|
|
|
|
# Stash current size so it can be restored if the MessageWindow
|
|
|
|
# is not longer embedded
|
2013-01-03 17:09:40 +01:00
|
|
|
roster_width = w.parent_paned.get_position()
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.set('roster_width', roster_width)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
# Must clear _controls to prevent MessageControl.shutdown calls
|
|
|
|
w._controls = {}
|
|
|
|
if not w.parent_paned:
|
|
|
|
w.window.destroy()
|
|
|
|
else:
|
|
|
|
# Don't close parent window, just remove the child
|
|
|
|
child = w.parent_paned.get_child2()
|
|
|
|
w.parent_paned.remove(child)
|
2017-02-28 16:49:01 +01:00
|
|
|
self.parent_win.lookup_action('show-roster').set_enabled(False)
|
2010-02-08 15:08:40 +01:00
|
|
|
gtkgui_helpers.resize_window(w.window,
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.get('roster_width'),
|
|
|
|
app.config.get('roster_height'))
|
2017-10-03 13:08:06 +02:00
|
|
|
self.hide_header_bar(self.parent_win)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self._windows = {}
|
|
|
|
|
|
|
|
for ctrl in controls:
|
|
|
|
mw = self.get_window(ctrl.contact.jid, ctrl.account)
|
|
|
|
if not mw:
|
|
|
|
mw = self.create_window(ctrl.contact, ctrl.account,
|
|
|
|
ctrl.type_id)
|
|
|
|
ctrl.parent_win = mw
|
2017-10-03 13:08:06 +02:00
|
|
|
ctrl.add_actions()
|
|
|
|
ctrl.update_actions()
|
2010-02-08 15:08:40 +01:00
|
|
|
mw.new_tab(ctrl)
|
2012-04-20 14:34:24 +02:00
|
|
|
|
2017-10-03 13:08:06 +02:00
|
|
|
@staticmethod
|
|
|
|
def hide_header_bar(parent_win):
|
|
|
|
header_bar = parent_win.get_titlebar()
|
|
|
|
for child in header_bar.get_children():
|
|
|
|
child.hide()
|
|
|
|
|
2012-04-20 14:34:24 +02:00
|
|
|
def save_opened_controls(self):
|
2017-08-13 13:18:56 +02:00
|
|
|
if not app.config.get('remember_opened_chat_controls'):
|
2012-08-05 13:34:35 +02:00
|
|
|
return
|
2012-04-20 14:34:24 +02:00
|
|
|
chat_controls = {}
|
2017-08-13 13:18:56 +02:00
|
|
|
for acct in app.connections:
|
2012-04-20 14:34:24 +02:00
|
|
|
chat_controls[acct] = []
|
|
|
|
for ctrl in self.get_controls(type_=message_control.TYPE_CHAT):
|
|
|
|
acct = ctrl.account
|
|
|
|
if ctrl.contact.jid not in chat_controls[acct]:
|
|
|
|
chat_controls[acct].append(ctrl.contact.jid)
|
2017-08-13 13:18:56 +02:00
|
|
|
for acct in app.connections:
|
|
|
|
app.config.set_per('accounts', acct, 'opened_chat_controls',
|
2012-04-20 14:34:24 +02:00
|
|
|
','.join(chat_controls[acct]))
|