2018-09-05 02:59:34 +02:00
|
|
|
# Copyright (C) 2006 Dimitur Kirov <dkirov AT gmail.com>
|
|
|
|
# Copyright (C) 2006-2014 Yann Leboulanger <asterix AT lagaule.org>
|
|
|
|
# Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
|
|
|
|
# Nikos Kouremenos <kourem AT gmail.com>
|
|
|
|
# Travis Shirk <travis AT pobox.com>
|
|
|
|
# Copyright (C) 2007 Lukas Petrovicky <lukas AT petrovicky.net>
|
|
|
|
# Julien Pivotto <roidelapluie AT gmail.com>
|
|
|
|
# Copyright (C) 2007-2008 Brendan Taylor <whateley AT gmail.com>
|
|
|
|
# Stephan Erb <steve-e AT h3c.de>
|
|
|
|
# Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
|
|
|
|
#
|
|
|
|
# This file is part of Gajim.
|
|
|
|
#
|
|
|
|
# Gajim is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published
|
|
|
|
# by the Free Software Foundation; version 3 only.
|
|
|
|
#
|
|
|
|
# Gajim is distributed in the hope that it will be useful,
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2017-01-04 23:54:16 +01:00
|
|
|
|
2017-12-27 13:17:13 +01:00
|
|
|
import os
|
2018-09-16 11:37:38 +02:00
|
|
|
import re
|
2017-01-04 23:54:16 +01:00
|
|
|
import time
|
2018-09-16 11:37:38 +02:00
|
|
|
|
2017-01-04 23:54:16 +01:00
|
|
|
from gi.repository import Gtk
|
|
|
|
from gi.repository import Gdk
|
|
|
|
from gi.repository import GLib
|
2017-04-13 22:58:51 +02:00
|
|
|
from gi.repository import Gio
|
2017-10-19 11:26:22 +02:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim import gtkgui_helpers
|
|
|
|
from gajim import message_control
|
2018-09-26 19:06:47 +02:00
|
|
|
from gajim.gtk.dialogs import NonModalConfirmationDialog
|
2018-03-01 22:47:01 +01:00
|
|
|
from gajim.gtk.util import convert_rgb_to_hex
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim import notify
|
2018-08-15 23:58:02 +02:00
|
|
|
from gajim.gtk.emoji_chooser import emoji_chooser
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import events
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.common import helpers
|
|
|
|
from gajim.common import ged
|
2018-05-02 22:37:45 +02:00
|
|
|
from gajim.common import i18n
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.message_control import MessageControl
|
|
|
|
from gajim.conversation_textview import ConversationTextview
|
|
|
|
from gajim.message_textview import MessageTextView
|
|
|
|
from gajim.common.contacts import GC_Contact
|
|
|
|
from gajim.common.connection_handlers_events import MessageOutgoingEvent
|
2018-03-01 22:47:01 +01:00
|
|
|
from gajim.common.const import StyleAttr
|
2018-09-29 21:48:21 +02:00
|
|
|
from gajim.common.const import Chatstate
|
2017-01-04 23:54:16 +01:00
|
|
|
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.command_system.implementation.middleware import ChatCommandProcessor
|
|
|
|
from gajim.command_system.implementation.middleware import CommandTools
|
2017-01-04 23:54:16 +01:00
|
|
|
|
2017-03-07 16:18:57 +01:00
|
|
|
# The members of these modules are not referenced directly anywhere in this
|
|
|
|
# module, but still they need to be kept around. Importing them automatically
|
|
|
|
# registers the contained CommandContainers with the command system, thereby
|
|
|
|
# populating the list of available commands.
|
2018-09-16 11:37:38 +02:00
|
|
|
# pylint: disable=unused-import
|
2017-06-13 23:58:06 +02:00
|
|
|
from gajim.command_system.implementation import standard
|
|
|
|
from gajim.command_system.implementation import execute
|
2018-09-16 11:37:38 +02:00
|
|
|
# pylint: enable=unused-import
|
2017-03-07 16:18:57 +01:00
|
|
|
|
2018-04-24 19:36:33 +02:00
|
|
|
if app.is_installed('GSPELL'):
|
2017-11-25 17:37:46 +01:00
|
|
|
from gi.repository import Gspell
|
|
|
|
|
2017-01-04 23:54:16 +01:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
|
|
|
"""
|
|
|
|
A base class containing a banner, ConversationTextview, MessageTextView
|
|
|
|
"""
|
|
|
|
|
2018-08-18 00:10:10 +02:00
|
|
|
keymap = Gdk.Keymap.get_for_display(Gdk.Display.get_default())
|
2017-01-04 23:54:16 +01:00
|
|
|
try:
|
|
|
|
keycode_c = keymap.get_entries_for_keyval(Gdk.KEY_c)[1][0].keycode
|
|
|
|
except TypeError:
|
|
|
|
keycode_c = 54
|
|
|
|
try:
|
|
|
|
keycode_ins = keymap.get_entries_for_keyval(Gdk.KEY_Insert)[1][0].keycode
|
|
|
|
except TypeError:
|
|
|
|
keycode_ins = 118
|
2017-01-05 01:14:18 +01:00
|
|
|
except IndexError:
|
|
|
|
# There is no KEY_Insert (MacOS)
|
|
|
|
keycode_ins = None
|
2017-01-04 23:54:16 +01:00
|
|
|
|
|
|
|
def make_href(self, match):
|
2018-03-01 22:47:01 +01:00
|
|
|
url_color = app.css_config.get_value('.gajim-url', StyleAttr.COLOR)
|
|
|
|
color = convert_rgb_to_hex(url_color)
|
2017-01-04 23:54:16 +01:00
|
|
|
url = match.group()
|
2018-03-01 22:47:01 +01:00
|
|
|
if '://' not in url:
|
2017-01-04 23:54:16 +01:00
|
|
|
url = 'http://' + url
|
2018-03-01 22:47:01 +01:00
|
|
|
return '<a href="%s"><span foreground="%s">%s</span></a>' % (
|
|
|
|
url, color, match.group())
|
2017-01-04 23:54:16 +01:00
|
|
|
|
|
|
|
def get_nb_unread(self):
|
|
|
|
jid = self.contact.jid
|
|
|
|
if self.resource:
|
|
|
|
jid += '/' + self.resource
|
|
|
|
type_ = self.type_id
|
2017-08-13 13:18:56 +02:00
|
|
|
return len(app.events.get_events(self.account, jid, ['printed_' + type_,
|
2017-01-04 23:54:16 +01:00
|
|
|
type_]))
|
|
|
|
|
|
|
|
def draw_banner(self):
|
|
|
|
"""
|
|
|
|
Draw the fat line at the top of the window that houses the icon, jid, etc
|
|
|
|
|
|
|
|
Derived types MAY implement this.
|
|
|
|
"""
|
|
|
|
self.draw_banner_text()
|
|
|
|
self._update_banner_state_image()
|
2017-08-13 13:18:56 +02:00
|
|
|
app.plugin_manager.gui_extension_point('chat_control_base_draw_banner',
|
2017-01-04 23:54:16 +01:00
|
|
|
self)
|
|
|
|
|
|
|
|
def update_toolbar(self):
|
|
|
|
"""
|
|
|
|
update state of buttons in toolbar
|
|
|
|
"""
|
|
|
|
self._update_toolbar()
|
2017-08-13 13:18:56 +02:00
|
|
|
app.plugin_manager.gui_extension_point(
|
2017-01-04 23:54:16 +01:00
|
|
|
'chat_control_base_update_toolbar', self)
|
|
|
|
|
|
|
|
def draw_banner_text(self):
|
|
|
|
"""
|
|
|
|
Derived types SHOULD implement this
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def update_ui(self):
|
|
|
|
"""
|
|
|
|
Derived types SHOULD implement this
|
|
|
|
"""
|
|
|
|
self.draw_banner()
|
|
|
|
|
|
|
|
def repaint_themed_widgets(self):
|
|
|
|
"""
|
|
|
|
Derived types MAY implement this
|
|
|
|
"""
|
|
|
|
self.draw_banner()
|
|
|
|
|
|
|
|
def _update_banner_state_image(self):
|
|
|
|
"""
|
|
|
|
Derived types MAY implement this
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _update_toolbar(self):
|
|
|
|
"""
|
|
|
|
Derived types MAY implement this
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _nec_our_status(self, obj):
|
|
|
|
if self.account != obj.conn.name:
|
|
|
|
return
|
|
|
|
if obj.show == 'offline' or (obj.show == 'invisible' and \
|
|
|
|
obj.conn.is_zeroconf):
|
|
|
|
self.got_disconnected()
|
|
|
|
else:
|
|
|
|
# Other code rejoins all GCs, so we don't do it here
|
|
|
|
if not self.type_id == message_control.TYPE_GC:
|
|
|
|
self.got_connected()
|
|
|
|
if self.parent_win:
|
|
|
|
self.parent_win.redraw_tab(self)
|
|
|
|
|
|
|
|
def status_url_clicked(self, widget, url):
|
|
|
|
helpers.launch_browser_mailer('url', url)
|
|
|
|
|
2018-09-29 18:29:59 +02:00
|
|
|
def setup_seclabel(self):
|
2017-01-04 23:54:16 +01:00
|
|
|
self.seclabel_combo.hide()
|
|
|
|
self.seclabel_combo.set_no_show_all(True)
|
|
|
|
lb = Gtk.ListStore(str)
|
|
|
|
self.seclabel_combo.set_model(lb)
|
|
|
|
cell = Gtk.CellRendererText()
|
|
|
|
cell.set_property('xpad', 5) # padding for status text
|
|
|
|
self.seclabel_combo.pack_start(cell, True)
|
|
|
|
# text to show is in in first column of liststore
|
|
|
|
self.seclabel_combo.add_attribute(cell, 'text', 0)
|
2018-07-21 13:19:01 +02:00
|
|
|
con = app.connections[self.account]
|
2018-10-04 14:27:45 +02:00
|
|
|
jid = self.contact.jid
|
|
|
|
if self.TYPE_ID == 'pm':
|
|
|
|
jid = self.gc_contact.room_jid
|
2018-07-21 13:19:01 +02:00
|
|
|
if con.get_module('SecLabels').supported:
|
2018-10-04 14:27:45 +02:00
|
|
|
con.get_module('SecLabels').request_catalog(jid)
|
2017-01-04 23:54:16 +01:00
|
|
|
|
2018-07-21 13:19:01 +02:00
|
|
|
def _sec_labels_received(self, event):
|
|
|
|
if event.account != self.account:
|
|
|
|
return
|
2018-10-04 14:27:45 +02:00
|
|
|
|
|
|
|
jid = self.contact.jid
|
|
|
|
if self.TYPE_ID == 'pm':
|
|
|
|
jid = self.gc_contact.room_jid
|
|
|
|
|
|
|
|
if event.jid != jid:
|
2018-07-21 13:19:01 +02:00
|
|
|
return
|
2018-09-30 00:15:00 +02:00
|
|
|
model = self.seclabel_combo.get_model()
|
|
|
|
model.clear()
|
|
|
|
|
2017-01-04 23:54:16 +01:00
|
|
|
sel = 0
|
2018-09-17 21:11:45 +02:00
|
|
|
_label, labellist, default = event.catalog
|
2018-09-30 00:15:00 +02:00
|
|
|
for index, label in enumerate(labellist):
|
|
|
|
model.append([label])
|
2018-07-21 13:19:01 +02:00
|
|
|
if label == default:
|
2018-09-30 00:15:00 +02:00
|
|
|
sel = index
|
|
|
|
|
2017-01-04 23:54:16 +01:00
|
|
|
self.seclabel_combo.set_active(sel)
|
|
|
|
self.seclabel_combo.set_no_show_all(False)
|
|
|
|
self.seclabel_combo.show_all()
|
|
|
|
|
|
|
|
def __init__(self, type_id, parent_win, widget_name, contact, acct,
|
|
|
|
resource=None):
|
|
|
|
# Undo needs this variable to know if space has been pressed.
|
|
|
|
# Initialize it to True so empty textview is saved in undo list
|
|
|
|
self.space_pressed = True
|
|
|
|
|
|
|
|
if resource is None:
|
|
|
|
# We very likely got a contact with a random resource.
|
|
|
|
# This is bad, we need the highest for caps etc.
|
2017-08-13 13:18:56 +02:00
|
|
|
c = app.contacts.get_contact_with_highest_priority(acct,
|
2017-01-04 23:54:16 +01:00
|
|
|
contact.jid)
|
|
|
|
if c and not isinstance(c, GC_Contact):
|
|
|
|
contact = c
|
|
|
|
|
|
|
|
MessageControl.__init__(self, type_id, parent_win, widget_name,
|
|
|
|
contact, acct, resource=resource)
|
|
|
|
|
2017-10-03 13:08:06 +02:00
|
|
|
if self.TYPE_ID != message_control.TYPE_GC:
|
|
|
|
# Create banner and connect signals
|
|
|
|
widget = self.xml.get_object('banner_eventbox')
|
|
|
|
id_ = widget.connect('button-press-event',
|
|
|
|
self._on_banner_eventbox_button_press_event)
|
|
|
|
self.handlers[id_] = widget
|
2017-01-04 23:54:16 +01:00
|
|
|
|
|
|
|
self.urlfinder = re.compile(
|
|
|
|
r"(www\.(?!\.)|[a-z][a-z0-9+.-]*://)[^\s<>'\"]+[^!,\.\s<>\)'\"\]]")
|
|
|
|
|
|
|
|
self.banner_status_label = self.xml.get_object('banner_label')
|
2017-10-03 13:08:06 +02:00
|
|
|
if self.banner_status_label is not None:
|
|
|
|
id_ = self.banner_status_label.connect('populate_popup',
|
|
|
|
self.on_banner_label_populate_popup)
|
|
|
|
self.handlers[id_] = self.banner_status_label
|
2017-01-04 23:54:16 +01:00
|
|
|
|
|
|
|
# Init DND
|
|
|
|
self.TARGET_TYPE_URI_LIST = 80
|
|
|
|
self.dnd_list = [Gtk.TargetEntry.new('text/uri-list', 0,
|
|
|
|
self.TARGET_TYPE_URI_LIST), Gtk.TargetEntry.new('MY_TREE_MODEL_ROW',
|
|
|
|
Gtk.TargetFlags.SAME_APP, 0)]
|
|
|
|
id_ = self.widget.connect('drag_data_received',
|
|
|
|
self._on_drag_data_received)
|
|
|
|
self.handlers[id_] = self.widget
|
|
|
|
self.widget.drag_dest_set(Gtk.DestDefaults.MOTION |
|
|
|
|
Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP,
|
|
|
|
self.dnd_list, Gdk.DragAction.COPY)
|
|
|
|
|
|
|
|
# Create textviews and connect signals
|
|
|
|
self.conv_textview = ConversationTextview(self.account)
|
|
|
|
id_ = self.conv_textview.connect('quote', self.on_quote)
|
|
|
|
self.handlers[id_] = self.conv_textview.tv
|
|
|
|
id_ = self.conv_textview.tv.connect('key_press_event',
|
|
|
|
self._conv_textview_key_press_event)
|
|
|
|
self.handlers[id_] = self.conv_textview.tv
|
|
|
|
# FIXME: DND on non editable TextView, find a better way
|
|
|
|
self.drag_entered = False
|
|
|
|
id_ = self.conv_textview.tv.connect('drag_data_received',
|
|
|
|
self._on_drag_data_received)
|
|
|
|
self.handlers[id_] = self.conv_textview.tv
|
|
|
|
id_ = self.conv_textview.tv.connect('drag_motion', self._on_drag_motion)
|
|
|
|
self.handlers[id_] = self.conv_textview.tv
|
|
|
|
id_ = self.conv_textview.tv.connect('drag_leave', self._on_drag_leave)
|
|
|
|
self.handlers[id_] = self.conv_textview.tv
|
|
|
|
self.conv_textview.tv.drag_dest_set(Gtk.DestDefaults.MOTION |
|
|
|
|
Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP,
|
|
|
|
self.dnd_list, Gdk.DragAction.COPY)
|
|
|
|
|
|
|
|
self.conv_scrolledwindow = self.xml.get_object(
|
|
|
|
'conversation_scrolledwindow')
|
|
|
|
self.conv_scrolledwindow.add(self.conv_textview.tv)
|
|
|
|
widget = self.conv_scrolledwindow.get_vadjustment()
|
|
|
|
id_ = widget.connect('changed',
|
|
|
|
self.on_conversation_vadjustment_changed)
|
|
|
|
self.handlers[id_] = widget
|
2018-03-25 01:16:20 +01:00
|
|
|
|
|
|
|
vscrollbar = self.conv_scrolledwindow.get_vscrollbar()
|
|
|
|
id_ = vscrollbar.connect('button-release-event',
|
|
|
|
self._on_scrollbar_button_release)
|
|
|
|
self.handlers[id_] = vscrollbar
|
|
|
|
|
2017-01-04 23:54:16 +01:00
|
|
|
self.correcting = False
|
|
|
|
self.last_sent_msg = None
|
|
|
|
|
|
|
|
# add MessageTextView to UI and connect signals
|
|
|
|
self.msg_textview = MessageTextView()
|
2017-07-18 00:53:50 +02:00
|
|
|
self.msg_scrolledwindow = ScrolledWindow()
|
2017-01-04 23:54:16 +01:00
|
|
|
self.msg_scrolledwindow.add(self.msg_textview)
|
2017-07-18 00:53:50 +02:00
|
|
|
|
|
|
|
hbox = self.xml.get_object('hbox')
|
2017-10-03 03:12:31 +02:00
|
|
|
hbox.pack_start(self.msg_scrolledwindow, True, True, 0)
|
2017-07-18 00:53:50 +02:00
|
|
|
|
2017-01-04 23:54:16 +01:00
|
|
|
id_ = self.msg_textview.connect('key_press_event',
|
|
|
|
self._on_message_textview_key_press_event)
|
|
|
|
self.handlers[id_] = self.msg_textview
|
|
|
|
id_ = self.msg_textview.connect('populate_popup',
|
|
|
|
self.on_msg_textview_populate_popup)
|
|
|
|
self.handlers[id_] = self.msg_textview
|
|
|
|
# Setup DND
|
|
|
|
id_ = self.msg_textview.connect('drag_data_received',
|
|
|
|
self._on_drag_data_received)
|
|
|
|
self.handlers[id_] = self.msg_textview
|
|
|
|
self.msg_textview.drag_dest_set(Gtk.DestDefaults.MOTION |
|
|
|
|
Gtk.DestDefaults.HIGHLIGHT, self.dnd_list, Gdk.DragAction.COPY)
|
|
|
|
|
|
|
|
# the following vars are used to keep history of user's messages
|
|
|
|
self.sent_history = []
|
|
|
|
self.sent_history_pos = 0
|
|
|
|
self.received_history = []
|
|
|
|
self.received_history_pos = 0
|
|
|
|
self.orig_msg = None
|
|
|
|
|
2017-06-16 19:36:32 +02:00
|
|
|
self.set_emoticon_popover()
|
2017-01-04 23:54:16 +01:00
|
|
|
|
|
|
|
# Attach speller
|
2017-11-25 17:37:46 +01:00
|
|
|
self.spell_checker = None
|
2017-10-19 11:26:22 +02:00
|
|
|
self.set_speller()
|
2017-01-04 23:54:16 +01:00
|
|
|
self.conv_textview.tv.show()
|
|
|
|
|
|
|
|
# For XEP-0172
|
|
|
|
self.user_nick = None
|
|
|
|
|
|
|
|
self.command_hits = []
|
|
|
|
self.last_key_tabs = False
|
|
|
|
|
2018-09-29 18:29:59 +02:00
|
|
|
# Security Labels
|
|
|
|
self.seclabel_combo = self.xml.get_object('label_selector')
|
|
|
|
|
2018-09-29 21:48:21 +02:00
|
|
|
con = app.connections[self.account]
|
|
|
|
con.get_module('Chatstate').set_active(self.contact.jid)
|
|
|
|
|
2016-12-24 04:36:21 +01:00
|
|
|
message_tv_buffer = self.msg_textview.get_buffer()
|
|
|
|
id_ = message_tv_buffer.connect('changed',
|
|
|
|
self._on_message_tv_buffer_changed)
|
|
|
|
self.handlers[id_] = message_tv_buffer
|
|
|
|
if parent_win is not None:
|
|
|
|
id_ = parent_win.window.connect('motion-notify-event',
|
|
|
|
self._on_window_motion_notify)
|
|
|
|
self.handlers[id_] = parent_win.window
|
|
|
|
|
2017-05-17 16:58:11 +02:00
|
|
|
self.encryption = self.get_encryption_state()
|
2018-09-15 10:24:28 +02:00
|
|
|
self.conv_textview.encryption_enabled = self.encryption is not None
|
2017-04-13 22:58:51 +02:00
|
|
|
|
2017-01-04 23:54:16 +01:00
|
|
|
# PluginSystem: adding GUI extension point for ChatControlBase
|
|
|
|
# instance object (also subclasses, eg. ChatControl or GroupchatControl)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.plugin_manager.gui_extension_point('chat_control_base', self)
|
2017-01-04 23:54:16 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('our-show', ged.GUI1,
|
2017-01-04 23:54:16 +01:00
|
|
|
self._nec_our_status)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('ping-sent', ged.GUI1,
|
2018-06-24 23:22:49 +02:00
|
|
|
self._nec_ping)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('ping-reply', ged.GUI1,
|
2018-06-24 23:22:49 +02:00
|
|
|
self._nec_ping)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.register_event_handler('ping-error', ged.GUI1,
|
2018-06-24 23:22:49 +02:00
|
|
|
self._nec_ping)
|
2018-09-29 18:29:59 +02:00
|
|
|
app.ged.register_event_handler('sec-catalog-received', ged.GUI1,
|
2018-07-21 13:19:01 +02:00
|
|
|
self._sec_labels_received)
|
2018-03-01 22:47:01 +01:00
|
|
|
app.ged.register_event_handler('style-changed', ged.GUI1,
|
|
|
|
self._style_changed)
|
2017-01-04 23:54:16 +01:00
|
|
|
|
2018-06-22 00:47:29 +02:00
|
|
|
# This is basically a very nasty hack to surpass the inability
|
2017-01-04 23:54:16 +01:00
|
|
|
# to properly use the super, because of the old code.
|
|
|
|
CommandTools.__init__(self)
|
|
|
|
|
2018-01-27 10:29:52 +01:00
|
|
|
def add_actions(self):
|
2017-04-13 22:58:51 +02:00
|
|
|
action = Gio.SimpleAction.new_stateful(
|
2017-08-18 18:52:04 +02:00
|
|
|
"set-encryption-%s" % self.control_id,
|
2017-04-13 22:58:51 +02:00
|
|
|
GLib.VariantType.new("s"),
|
2017-05-17 16:58:11 +02:00
|
|
|
GLib.Variant("s", self.encryption or 'disabled'))
|
2017-05-18 21:45:31 +02:00
|
|
|
action.connect("change-state", self.change_encryption)
|
2017-04-13 22:58:51 +02:00
|
|
|
self.parent_win.window.add_action(action)
|
|
|
|
|
2017-10-03 13:08:06 +02:00
|
|
|
action = Gio.SimpleAction.new(
|
|
|
|
'browse-history-%s' % self.control_id, GLib.VariantType.new('s'))
|
|
|
|
action.connect('activate', self._on_history)
|
|
|
|
self.parent_win.window.add_action(action)
|
|
|
|
|
2017-12-27 13:17:13 +01:00
|
|
|
action = Gio.SimpleAction.new(
|
|
|
|
'send-file-%s' % self.control_id, None)
|
|
|
|
action.connect('activate', self._on_send_file)
|
|
|
|
action.set_enabled(False)
|
|
|
|
self.parent_win.window.add_action(action)
|
|
|
|
|
|
|
|
action = Gio.SimpleAction.new(
|
|
|
|
'send-file-httpupload-%s' % self.control_id, None)
|
|
|
|
action.connect('activate', self._on_send_httpupload)
|
|
|
|
action.set_enabled(False)
|
|
|
|
self.parent_win.window.add_action(action)
|
|
|
|
|
|
|
|
action = Gio.SimpleAction.new(
|
|
|
|
'send-file-jingle-%s' % self.control_id, None)
|
|
|
|
action.connect('activate', self._on_send_jingle)
|
|
|
|
action.set_enabled(False)
|
|
|
|
self.parent_win.window.add_action(action)
|
|
|
|
|
2017-10-03 13:08:06 +02:00
|
|
|
# Actions
|
|
|
|
|
|
|
|
def _on_history(self, action, param):
|
|
|
|
"""
|
|
|
|
When history menuitem is pressed: call history window
|
|
|
|
"""
|
|
|
|
jid = param.get_string()
|
|
|
|
if jid == 'none':
|
|
|
|
jid = self.contact.jid
|
|
|
|
|
|
|
|
if 'logs' in app.interface.instances:
|
|
|
|
app.interface.instances['logs'].window.present()
|
|
|
|
app.interface.instances['logs'].open_history(jid, self.account)
|
|
|
|
else:
|
2018-09-26 19:06:47 +02:00
|
|
|
from gajim.gtk.history import HistoryWindow
|
2018-08-04 20:12:38 +02:00
|
|
|
app.interface.instances['logs'] = HistoryWindow(jid, self.account)
|
2017-10-03 13:08:06 +02:00
|
|
|
|
2017-05-18 21:45:31 +02:00
|
|
|
def change_encryption(self, action, param):
|
2017-04-13 22:58:51 +02:00
|
|
|
encryption = param.get_string()
|
2017-05-17 16:58:11 +02:00
|
|
|
if encryption == 'disabled':
|
|
|
|
encryption = None
|
|
|
|
|
2017-04-13 22:58:51 +02:00
|
|
|
if self.encryption == encryption:
|
|
|
|
return
|
|
|
|
|
2017-05-17 16:58:11 +02:00
|
|
|
if encryption:
|
2017-08-13 13:18:56 +02:00
|
|
|
plugin = app.plugin_manager.encryption_plugins[encryption]
|
2017-04-13 22:58:51 +02:00
|
|
|
if not plugin.activate_encryption(self):
|
|
|
|
return
|
2018-05-27 01:01:35 +02:00
|
|
|
|
2017-04-13 22:58:51 +02:00
|
|
|
action.set_state(param)
|
2017-05-17 16:58:11 +02:00
|
|
|
self.set_encryption_state(encryption)
|
2017-06-12 23:32:59 +02:00
|
|
|
self.set_encryption_menu_icon()
|
2017-04-13 22:58:51 +02:00
|
|
|
self.set_lock_image()
|
|
|
|
|
2017-05-17 16:58:11 +02:00
|
|
|
def set_encryption_state(self, encryption):
|
|
|
|
config_key = '%s-%s' % (self.account, self.contact.jid)
|
|
|
|
self.encryption = encryption
|
2018-09-15 10:24:28 +02:00
|
|
|
self.conv_textview.encryption_enabled = encryption is not None
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.set_per('encryption', config_key,
|
2018-09-15 10:24:28 +02:00
|
|
|
'encryption', self.encryption or '')
|
2017-05-17 16:58:11 +02:00
|
|
|
|
|
|
|
def get_encryption_state(self):
|
|
|
|
config_key = '%s-%s' % (self.account, self.contact.jid)
|
2017-08-13 13:18:56 +02:00
|
|
|
state = app.config.get_per('encryption', config_key, 'encryption')
|
2017-07-12 20:17:47 +02:00
|
|
|
if not state:
|
|
|
|
return None
|
2017-08-13 13:18:56 +02:00
|
|
|
if state not in app.plugin_manager.encryption_plugins:
|
2017-07-12 20:17:47 +02:00
|
|
|
self.set_encryption_state(None)
|
|
|
|
return None
|
|
|
|
return state
|
2017-04-13 22:58:51 +02:00
|
|
|
|
2017-06-12 23:32:59 +02:00
|
|
|
def set_encryption_menu_icon(self):
|
2017-10-27 20:46:48 +02:00
|
|
|
image = self.encryption_menu.get_image()
|
|
|
|
if image is None:
|
|
|
|
image = Gtk.Image()
|
|
|
|
self.encryption_menu.set_image(image)
|
2017-06-12 23:32:59 +02:00
|
|
|
if not self.encryption:
|
2017-10-27 20:46:48 +02:00
|
|
|
image.set_from_icon_name('channel-insecure-symbolic',
|
|
|
|
Gtk.IconSize.MENU)
|
2017-06-12 23:32:59 +02:00
|
|
|
else:
|
2017-10-27 20:46:48 +02:00
|
|
|
image.set_from_icon_name('channel-secure-symbolic',
|
|
|
|
Gtk.IconSize.MENU)
|
2017-06-12 23:32:59 +02:00
|
|
|
|
2017-01-04 23:54:16 +01:00
|
|
|
def set_speller(self):
|
2018-04-24 19:36:33 +02:00
|
|
|
if not app.is_installed('GSPELL') or not app.config.get('use_speller'):
|
2017-10-19 11:26:22 +02:00
|
|
|
return
|
|
|
|
|
2017-11-25 17:37:46 +01:00
|
|
|
gspell_lang = self.get_speller_language()
|
|
|
|
if gspell_lang is None:
|
|
|
|
return
|
2017-10-19 11:26:22 +02:00
|
|
|
|
2017-11-25 17:37:46 +01:00
|
|
|
self.spell_checker = Gspell.Checker.new(gspell_lang)
|
|
|
|
spell_buffer = Gspell.TextBuffer.get_from_gtk_text_buffer(
|
|
|
|
self.msg_textview.get_buffer())
|
|
|
|
spell_buffer.set_spell_checker(self.spell_checker)
|
|
|
|
spell_view = Gspell.TextView.get_from_gtk_text_view(self.msg_textview)
|
|
|
|
spell_view.set_inline_spell_checking(False)
|
|
|
|
spell_view.set_enable_language_menu(True)
|
2017-10-19 11:26:22 +02:00
|
|
|
|
2017-11-25 17:37:46 +01:00
|
|
|
self.spell_checker.connect('notify::language', self.on_language_changed)
|
2017-10-19 11:26:22 +02:00
|
|
|
|
|
|
|
def get_speller_language(self):
|
2017-01-04 23:54:16 +01:00
|
|
|
per_type = 'contacts'
|
2017-10-19 11:26:22 +02:00
|
|
|
if self.type_id == 'gc':
|
2017-01-04 23:54:16 +01:00
|
|
|
per_type = 'rooms'
|
2017-10-19 11:26:22 +02:00
|
|
|
lang = app.config.get_per(
|
|
|
|
per_type, self.contact.jid, 'speller_language')
|
2017-01-04 23:54:16 +01:00
|
|
|
if not lang:
|
|
|
|
# use the default one
|
2017-08-13 13:18:56 +02:00
|
|
|
lang = app.config.get('speller_language')
|
2017-01-04 23:54:16 +01:00
|
|
|
if not lang:
|
2018-05-02 22:37:45 +02:00
|
|
|
lang = i18n.LANG
|
2017-11-25 17:37:46 +01:00
|
|
|
gspell_lang = Gspell.language_lookup(lang)
|
|
|
|
if gspell_lang is None:
|
|
|
|
gspell_lang = Gspell.language_get_default()
|
|
|
|
return gspell_lang
|
2017-01-04 23:54:16 +01:00
|
|
|
|
2017-11-25 17:37:46 +01:00
|
|
|
def on_language_changed(self, checker, param):
|
|
|
|
gspell_lang = checker.get_language()
|
2017-01-04 23:54:16 +01:00
|
|
|
per_type = 'contacts'
|
|
|
|
if self.type_id == message_control.TYPE_GC:
|
|
|
|
per_type = 'rooms'
|
2017-08-13 13:18:56 +02:00
|
|
|
if not app.config.get_per(per_type, self.contact.jid):
|
|
|
|
app.config.add_per(per_type, self.contact.jid)
|
2017-11-25 17:37:46 +01:00
|
|
|
app.config.set_per(per_type, self.contact.jid,
|
|
|
|
'speller_language', gspell_lang.get_code())
|
2017-01-04 23:54:16 +01:00
|
|
|
|
|
|
|
def on_banner_label_populate_popup(self, label, menu):
|
|
|
|
"""
|
2018-06-22 00:47:29 +02:00
|
|
|
Override the default context menu and add our own menuitems
|
2017-01-04 23:54:16 +01:00
|
|
|
"""
|
|
|
|
item = Gtk.SeparatorMenuItem.new()
|
|
|
|
menu.prepend(item)
|
|
|
|
|
|
|
|
menu2 = self.prepare_context_menu()
|
|
|
|
i = 0
|
|
|
|
for item in menu2:
|
|
|
|
menu2.remove(item)
|
|
|
|
menu.prepend(item)
|
|
|
|
menu.reorder_child(item, i)
|
|
|
|
i += 1
|
|
|
|
menu.show_all()
|
|
|
|
|
|
|
|
def shutdown(self):
|
|
|
|
super(ChatControlBase, self).shutdown()
|
|
|
|
# PluginSystem: removing GUI extension points connected with ChatControlBase
|
|
|
|
# instance object
|
2017-08-13 13:18:56 +02:00
|
|
|
app.plugin_manager.remove_gui_extension_point('chat_control_base',
|
2017-01-04 23:54:16 +01:00
|
|
|
self)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.plugin_manager.remove_gui_extension_point(
|
2017-01-04 23:54:16 +01:00
|
|
|
'chat_control_base_draw_banner', self)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged.remove_event_handler('our-show', ged.GUI1,
|
2017-01-04 23:54:16 +01:00
|
|
|
self._nec_our_status)
|
2018-09-29 18:29:59 +02:00
|
|
|
app.ged.remove_event_handler('sec-catalog-received', ged.GUI1,
|
2018-07-21 13:19:01 +02:00
|
|
|
self._sec_labels_received)
|
2018-03-01 22:47:01 +01:00
|
|
|
app.ged.remove_event_handler('style-changed', ged.GUI1,
|
|
|
|
self._style_changed)
|
|
|
|
|
2017-01-04 23:54:16 +01:00
|
|
|
|
|
|
|
def on_msg_textview_populate_popup(self, textview, menu):
|
|
|
|
"""
|
|
|
|
Override the default context menu and we prepend an option to switch
|
|
|
|
languages
|
|
|
|
"""
|
|
|
|
item = Gtk.MenuItem.new_with_mnemonic(_('_Undo'))
|
|
|
|
menu.prepend(item)
|
|
|
|
id_ = item.connect('activate', self.msg_textview.undo)
|
|
|
|
self.handlers[id_] = item
|
|
|
|
|
|
|
|
item = Gtk.SeparatorMenuItem.new()
|
|
|
|
menu.prepend(item)
|
|
|
|
|
|
|
|
item = Gtk.MenuItem.new_with_mnemonic(_('_Clear'))
|
|
|
|
menu.prepend(item)
|
|
|
|
id_ = item.connect('activate', self.msg_textview.clear)
|
|
|
|
self.handlers[id_] = item
|
|
|
|
|
|
|
|
menu.show_all()
|
|
|
|
|
|
|
|
def on_quote(self, widget, text):
|
2017-10-03 13:08:06 +02:00
|
|
|
self.msg_textview.remove_placeholder()
|
2017-01-04 23:54:16 +01:00
|
|
|
text = '>' + text.replace('\n', '\n>') + '\n'
|
|
|
|
message_buffer = self.msg_textview.get_buffer()
|
|
|
|
message_buffer.insert_at_cursor(text)
|
|
|
|
|
|
|
|
# moved from ChatControl
|
|
|
|
def _on_banner_eventbox_button_press_event(self, widget, event):
|
|
|
|
"""
|
|
|
|
If right-clicked, show popup
|
|
|
|
"""
|
|
|
|
if event.button == 3: # right click
|
|
|
|
self.parent_win.popup_menu(event)
|
|
|
|
|
|
|
|
def _conv_textview_key_press_event(self, widget, event):
|
|
|
|
# translate any layout to latin_layout
|
2018-09-17 21:11:45 +02:00
|
|
|
_valid, entries = self.keymap.get_entries_for_keyval(event.keyval)
|
2017-01-04 23:54:16 +01:00
|
|
|
keycode = entries[0].keycode
|
|
|
|
if (event.get_state() & Gdk.ModifierType.CONTROL_MASK and keycode in (
|
2018-03-24 02:36:22 +01:00
|
|
|
self.keycode_c, self.keycode_ins)):
|
|
|
|
return False
|
2018-09-18 13:38:22 +02:00
|
|
|
|
2018-03-24 02:36:22 +01:00
|
|
|
if event.get_state() & Gdk.ModifierType.SHIFT_MASK and \
|
|
|
|
event.keyval in (Gdk.KEY_Page_Down, Gdk.KEY_Page_Up):
|
|
|
|
self._on_scroll(None, event.keyval)
|
2017-01-04 23:54:16 +01:00
|
|
|
return False
|
|
|
|
self.parent_win.notebook.event(event)
|
|
|
|
return True
|
|
|
|
|
|
|
|
def _on_message_textview_key_press_event(self, widget, event):
|
|
|
|
if event.keyval == Gdk.KEY_space:
|
|
|
|
self.space_pressed = True
|
|
|
|
|
|
|
|
elif (self.space_pressed or self.msg_textview.undo_pressed) and \
|
|
|
|
event.keyval not in (Gdk.KEY_Control_L, Gdk.KEY_Control_R) and \
|
|
|
|
not (event.keyval == Gdk.KEY_z and event.get_state() & Gdk.ModifierType.CONTROL_MASK):
|
2018-06-22 00:47:29 +02:00
|
|
|
# If the space key has been pressed and now it hasn't,
|
|
|
|
# we save the buffer into the undo list. But be careful we're not
|
|
|
|
# pressing Control again (as in ctrl+z)
|
2017-01-04 23:54:16 +01:00
|
|
|
_buffer = widget.get_buffer()
|
|
|
|
start_iter, end_iter = _buffer.get_bounds()
|
|
|
|
self.msg_textview.save_undo(_buffer.get_text(start_iter, end_iter, True))
|
|
|
|
self.space_pressed = False
|
|
|
|
|
|
|
|
# Ctrl [+ Shift] + Tab are not forwarded to notebook. We handle it here
|
|
|
|
if self.widget_name == 'groupchat_control':
|
|
|
|
if event.keyval not in (Gdk.KEY_ISO_Left_Tab, Gdk.KEY_Tab):
|
|
|
|
self.last_key_tabs = False
|
|
|
|
if event.get_state() & Gdk.ModifierType.SHIFT_MASK:
|
|
|
|
# CTRL + SHIFT + TAB
|
|
|
|
if event.get_state() & Gdk.ModifierType.CONTROL_MASK and \
|
|
|
|
event.keyval == Gdk.KEY_ISO_Left_Tab:
|
|
|
|
self.parent_win.move_to_next_unread_tab(False)
|
|
|
|
return True
|
|
|
|
# SHIFT + PAGE_[UP|DOWN]: send to conv_textview
|
2018-09-18 10:14:04 +02:00
|
|
|
if event.keyval == Gdk.KEY_Page_Down or \
|
2017-01-04 23:54:16 +01:00
|
|
|
event.keyval == Gdk.KEY_Page_Up:
|
|
|
|
self.conv_textview.tv.event(event)
|
|
|
|
return True
|
2018-09-18 10:14:04 +02:00
|
|
|
if event.get_state() & Gdk.ModifierType.CONTROL_MASK:
|
2017-01-04 23:54:16 +01:00
|
|
|
if event.keyval == Gdk.KEY_Tab: # CTRL + TAB
|
|
|
|
self.parent_win.move_to_next_unread_tab(True)
|
|
|
|
return True
|
|
|
|
|
|
|
|
message_buffer = self.msg_textview.get_buffer()
|
|
|
|
event_state = event.get_state()
|
|
|
|
if event.keyval == Gdk.KEY_Tab:
|
|
|
|
start, end = message_buffer.get_bounds()
|
|
|
|
position = message_buffer.get_insert()
|
|
|
|
end = message_buffer.get_iter_at_mark(position)
|
|
|
|
text = message_buffer.get_text(start, end, False)
|
|
|
|
splitted = text.split()
|
|
|
|
if (text.startswith(self.COMMAND_PREFIX) and not
|
|
|
|
text.startswith(self.COMMAND_PREFIX * 2) and len(splitted) == 1):
|
|
|
|
text = splitted[0]
|
|
|
|
bare = text.lstrip(self.COMMAND_PREFIX)
|
|
|
|
if len(text) == 1:
|
|
|
|
self.command_hits = []
|
|
|
|
for command in self.list_commands():
|
|
|
|
for name in command.names:
|
|
|
|
self.command_hits.append(name)
|
|
|
|
else:
|
|
|
|
if (self.last_key_tabs and self.command_hits and
|
|
|
|
self.command_hits[0].startswith(bare)):
|
|
|
|
self.command_hits.append(self.command_hits.pop(0))
|
|
|
|
else:
|
|
|
|
self.command_hits = []
|
|
|
|
for command in self.list_commands():
|
|
|
|
for name in command.names:
|
|
|
|
if name.startswith(bare):
|
|
|
|
self.command_hits.append(name)
|
|
|
|
|
|
|
|
if self.command_hits:
|
|
|
|
message_buffer.delete(start, end)
|
|
|
|
message_buffer.insert_at_cursor(self.COMMAND_PREFIX + \
|
|
|
|
self.command_hits[0] + ' ')
|
|
|
|
self.last_key_tabs = True
|
|
|
|
return True
|
|
|
|
if self.widget_name != 'groupchat_control':
|
|
|
|
self.last_key_tabs = False
|
|
|
|
if event.keyval == Gdk.KEY_Up:
|
|
|
|
if event_state & Gdk.ModifierType.CONTROL_MASK:
|
|
|
|
if event_state & Gdk.ModifierType.SHIFT_MASK: # Ctrl+Shift+UP
|
|
|
|
self.scroll_messages('up', message_buffer, 'received')
|
|
|
|
else: # Ctrl+UP
|
|
|
|
self.scroll_messages('up', message_buffer, 'sent')
|
2017-01-24 12:52:49 +01:00
|
|
|
return True
|
2017-01-04 23:54:16 +01:00
|
|
|
elif event.keyval == Gdk.KEY_Down:
|
|
|
|
if event_state & Gdk.ModifierType.CONTROL_MASK:
|
|
|
|
if event_state & Gdk.ModifierType.SHIFT_MASK: # Ctrl+Shift+Down
|
|
|
|
self.scroll_messages('down', message_buffer, 'received')
|
|
|
|
else: # Ctrl+Down
|
|
|
|
self.scroll_messages('down', message_buffer, 'sent')
|
2017-01-24 12:52:49 +01:00
|
|
|
return True
|
2017-01-04 23:54:16 +01:00
|
|
|
elif event.keyval == Gdk.KEY_Return or \
|
|
|
|
event.keyval == Gdk.KEY_KP_Enter: # ENTER
|
|
|
|
message_textview = widget
|
|
|
|
message_buffer = message_textview.get_buffer()
|
2018-08-15 23:58:02 +02:00
|
|
|
message_textview.replace_emojis()
|
2017-01-04 23:54:16 +01:00
|
|
|
start_iter, end_iter = message_buffer.get_bounds()
|
|
|
|
message = message_buffer.get_text(start_iter, end_iter, False)
|
|
|
|
xhtml = self.msg_textview.get_xhtml()
|
|
|
|
|
2017-01-25 17:13:41 +01:00
|
|
|
if event_state & Gdk.ModifierType.SHIFT_MASK:
|
|
|
|
send_message = False
|
|
|
|
else:
|
|
|
|
is_ctrl_enter = bool(event_state & Gdk.ModifierType.CONTROL_MASK)
|
2017-08-13 13:18:56 +02:00
|
|
|
send_message = is_ctrl_enter == app.config.get('send_on_ctrl_enter')
|
2017-01-24 12:28:55 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
if send_message and app.connections[self.account].connected < 2:
|
2017-01-04 23:54:16 +01:00
|
|
|
# we are not connected
|
2017-12-08 20:19:10 +01:00
|
|
|
app.interface.raise_dialog('not-connected-while-sending')
|
2017-01-24 12:28:55 +01:00
|
|
|
elif send_message:
|
|
|
|
self.send_message(message, xhtml=xhtml)
|
|
|
|
else:
|
|
|
|
message_buffer.insert_at_cursor('\n')
|
2017-07-18 00:53:50 +02:00
|
|
|
mark = message_buffer.get_insert()
|
|
|
|
iter_ = message_buffer.get_iter_at_mark(mark)
|
|
|
|
if message_buffer.get_end_iter().equal(iter_):
|
|
|
|
GLib.idle_add(gtkgui_helpers.scroll_to_end, self.msg_scrolledwindow)
|
2017-01-04 23:54:16 +01:00
|
|
|
|
|
|
|
return True
|
|
|
|
elif event.keyval == Gdk.KEY_z: # CTRL+z
|
|
|
|
if event_state & Gdk.ModifierType.CONTROL_MASK:
|
|
|
|
self.msg_textview.undo()
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def _on_drag_data_received(self, widget, context, x, y, selection,
|
|
|
|
target_type, timestamp):
|
|
|
|
"""
|
|
|
|
Derived types SHOULD implement this
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2018-09-16 17:11:52 +02:00
|
|
|
def _on_drag_leave(self, *args):
|
2017-01-04 23:54:16 +01:00
|
|
|
# FIXME: DND on non editable TextView, find a better way
|
|
|
|
self.drag_entered = False
|
|
|
|
self.conv_textview.tv.set_editable(False)
|
|
|
|
|
2018-09-16 17:11:52 +02:00
|
|
|
def _on_drag_motion(self, *args):
|
2017-01-04 23:54:16 +01:00
|
|
|
# FIXME: DND on non editable TextView, find a better way
|
|
|
|
if not self.drag_entered:
|
|
|
|
# We drag new data over the TextView, make it editable to catch dnd
|
|
|
|
self.drag_entered_conv = True
|
|
|
|
self.conv_textview.tv.set_editable(True)
|
|
|
|
|
2017-12-27 13:17:13 +01:00
|
|
|
def drag_data_file_transfer(self, contact, selection, widget):
|
|
|
|
# get file transfer preference
|
|
|
|
ft_pref = app.config.get_per('accounts', self.account,
|
|
|
|
'filetransfer_preference')
|
|
|
|
win = self.parent_win.window
|
|
|
|
con = app.connections[self.account]
|
|
|
|
httpupload = win.lookup_action(
|
|
|
|
'send-file-httpupload-%s' % self.control_id)
|
|
|
|
jingle = win.lookup_action('send-file-jingle-%s' % self.control_id)
|
|
|
|
|
|
|
|
# we may have more than one file dropped
|
|
|
|
uri_splitted = selection.get_uris()
|
|
|
|
for uri in uri_splitted:
|
|
|
|
path = helpers.get_file_path_from_dnd_dropped_uri(uri)
|
|
|
|
if not os.path.isfile(path): # is it a file?
|
|
|
|
continue
|
|
|
|
if self.type_id == message_control.TYPE_GC:
|
|
|
|
# groupchat only supports httpupload on drag and drop
|
|
|
|
if httpupload.get_enabled():
|
|
|
|
# use httpupload
|
2018-07-07 01:15:48 +02:00
|
|
|
con.get_module('HTTPUpload').check_file_before_transfer(
|
2017-12-27 13:17:13 +01:00
|
|
|
path, self.encryption, contact,
|
|
|
|
self.session, groupchat=True)
|
|
|
|
else:
|
|
|
|
if httpupload.get_enabled() and jingle.get_enabled():
|
|
|
|
if ft_pref == 'httpupload':
|
2018-07-07 01:15:48 +02:00
|
|
|
con.get_module('HTTPUpload').check_file_before_transfer(
|
2017-12-27 13:17:13 +01:00
|
|
|
path, self.encryption, contact, self.session)
|
|
|
|
else:
|
|
|
|
ft = app.interface.instances['file_transfers']
|
|
|
|
ft.send_file(self.account, contact, path)
|
|
|
|
elif httpupload.get_enabled():
|
2018-07-07 01:15:48 +02:00
|
|
|
con.get_module('HTTPUpload').check_file_before_transfer(
|
2017-12-27 13:17:13 +01:00
|
|
|
path, self.encryption, contact, self.session)
|
|
|
|
elif jingle.get_enabled():
|
|
|
|
ft = app.interface.instances['file_transfers']
|
|
|
|
ft.send_file(self.account, contact, path)
|
|
|
|
|
2017-01-04 23:54:16 +01:00
|
|
|
def get_seclabel(self):
|
2018-09-29 18:29:59 +02:00
|
|
|
idx = self.seclabel_combo.get_active()
|
|
|
|
if idx == -1:
|
|
|
|
return
|
|
|
|
|
|
|
|
con = app.connections[self.account]
|
2018-10-04 14:27:45 +02:00
|
|
|
jid = self.contact.jid
|
|
|
|
if self.TYPE_ID == 'pm':
|
|
|
|
jid = self.gc_contact.room_jid
|
|
|
|
catalog = con.get_module('SecLabels').get_catalog(jid)
|
2018-09-29 18:29:59 +02:00
|
|
|
labels, label_list, _ = catalog
|
|
|
|
lname = label_list[idx]
|
|
|
|
label = labels[lname]
|
2017-01-04 23:54:16 +01:00
|
|
|
return label
|
|
|
|
|
2018-09-29 21:48:21 +02:00
|
|
|
def send_message(self, message, keyID='', type_='chat',
|
2017-12-10 14:35:41 +01:00
|
|
|
resource=None, xhtml=None, process_commands=True, attention=False):
|
2017-01-04 23:54:16 +01:00
|
|
|
"""
|
|
|
|
Send the given message to the active tab. Doesn't return None if error
|
|
|
|
"""
|
|
|
|
if not message or message == '\n':
|
|
|
|
return None
|
|
|
|
|
|
|
|
if process_commands and self.process_as_command(message):
|
|
|
|
return
|
|
|
|
|
|
|
|
label = self.get_seclabel()
|
|
|
|
|
|
|
|
if self.correcting and self.last_sent_msg:
|
2017-06-02 01:29:41 +02:00
|
|
|
correct_id = self.last_sent_msg
|
2017-01-04 23:54:16 +01:00
|
|
|
else:
|
2017-06-02 01:29:41 +02:00
|
|
|
correct_id = None
|
2017-01-04 23:54:16 +01:00
|
|
|
|
2018-09-29 21:48:21 +02:00
|
|
|
con = app.connections[self.account]
|
|
|
|
chatstate = con.get_module('Chatstate').get_active_chatstate(
|
|
|
|
self.contact)
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
app.nec.push_outgoing_event(MessageOutgoingEvent(None,
|
2017-01-04 23:54:16 +01:00
|
|
|
account=self.account, jid=self.contact.jid, message=message,
|
2017-07-28 01:37:06 +02:00
|
|
|
keyID=keyID, type_=type_, chatstate=chatstate,
|
2017-01-04 23:54:16 +01:00
|
|
|
resource=resource, user_nick=self.user_nick, xhtml=xhtml,
|
2017-12-10 14:35:41 +01:00
|
|
|
label=label, control=self, attention=attention, correct_id=correct_id,
|
2017-04-13 22:58:51 +02:00
|
|
|
automatic_message=False, encryption=self.encryption))
|
2017-01-04 23:54:16 +01:00
|
|
|
|
|
|
|
# Record the history of sent messages
|
|
|
|
self.save_message(message, 'sent')
|
|
|
|
|
|
|
|
# Be sure to send user nickname only once according to JEP-0172
|
|
|
|
self.user_nick = None
|
|
|
|
|
|
|
|
# Clear msg input
|
|
|
|
message_buffer = self.msg_textview.get_buffer()
|
|
|
|
message_buffer.set_text('') # clear message buffer (and tv of course)
|
|
|
|
|
2018-09-29 21:48:21 +02:00
|
|
|
def _on_window_motion_notify(self, *args):
|
2016-12-24 04:36:21 +01:00
|
|
|
"""
|
|
|
|
It gets called no matter if it is the active window or not
|
|
|
|
"""
|
2017-05-06 11:29:23 +02:00
|
|
|
if not self.parent_win:
|
|
|
|
# when a groupchat is minimized there is no parent window
|
|
|
|
return
|
2016-12-24 04:36:21 +01:00
|
|
|
if self.parent_win.get_active_jid() == self.contact.jid:
|
2018-09-29 21:48:21 +02:00
|
|
|
# if window is the active one, set last interaction
|
|
|
|
con = app.connections[self.account]
|
|
|
|
con.get_module('Chatstate').set_mouse_activity(self.contact)
|
2016-12-24 04:36:21 +01:00
|
|
|
|
2018-09-29 21:48:21 +02:00
|
|
|
def _on_message_tv_buffer_changed(self, *args):
|
|
|
|
con = app.connections[self.account]
|
|
|
|
con.get_module('Chatstate').set_keyboard_activity(self.contact)
|
2017-12-15 23:00:15 +01:00
|
|
|
if not self.msg_textview.has_text():
|
2018-09-29 21:48:21 +02:00
|
|
|
con.get_module('Chatstate').set_chatstate(self.contact,
|
|
|
|
Chatstate.ACTIVE)
|
2017-12-15 23:00:15 +01:00
|
|
|
return
|
2018-09-29 21:48:21 +02:00
|
|
|
con.get_module('Chatstate').set_chatstate(self.contact,
|
|
|
|
Chatstate.COMPOSING)
|
2016-12-24 04:36:21 +01:00
|
|
|
|
2017-01-04 23:54:16 +01:00
|
|
|
def save_message(self, message, msg_type):
|
|
|
|
# save the message, so user can scroll though the list with key up/down
|
|
|
|
if msg_type == 'sent':
|
|
|
|
history = self.sent_history
|
|
|
|
pos = self.sent_history_pos
|
|
|
|
else:
|
|
|
|
history = self.received_history
|
|
|
|
pos = self.received_history_pos
|
|
|
|
size = len(history)
|
|
|
|
scroll = False if pos == size else True # are we scrolling?
|
2018-06-22 00:47:29 +02:00
|
|
|
# we don't want size of the buffer to grow indefinitely
|
2017-08-13 13:18:56 +02:00
|
|
|
max_size = app.config.get('key_up_lines')
|
2018-09-17 21:11:45 +02:00
|
|
|
for _i in range(size - max_size + 1):
|
2017-01-04 23:54:16 +01:00
|
|
|
if pos == 0:
|
|
|
|
break
|
|
|
|
history.pop(0)
|
|
|
|
pos -= 1
|
|
|
|
history.append(message)
|
|
|
|
if not scroll or msg_type == 'sent':
|
|
|
|
pos = len(history)
|
|
|
|
if msg_type == 'sent':
|
|
|
|
self.sent_history_pos = pos
|
|
|
|
self.orig_msg = None
|
|
|
|
else:
|
|
|
|
self.received_history_pos = pos
|
|
|
|
|
|
|
|
def print_conversation_line(self, text, kind, name, tim,
|
2017-12-03 15:34:33 +01:00
|
|
|
other_tags_for_name=None, other_tags_for_time=None, other_tags_for_text=None,
|
2017-01-04 23:54:16 +01:00
|
|
|
count_as_new=True, subject=None, old_kind=None, xhtml=None, simple=False,
|
|
|
|
xep0184_id=None, graphics=True, displaymarking=None, msg_log_id=None,
|
2017-06-11 01:58:27 +02:00
|
|
|
msg_stanza_id=None, correct_id=None, additional_data=None,
|
|
|
|
encrypted=None):
|
2017-01-04 23:54:16 +01:00
|
|
|
"""
|
|
|
|
Print 'chat' type messages
|
|
|
|
correct_id = (message_id, correct_id)
|
|
|
|
"""
|
|
|
|
jid = self.contact.jid
|
|
|
|
full_jid = self.get_full_jid()
|
|
|
|
textview = self.conv_textview
|
|
|
|
end = False
|
2018-03-20 22:19:30 +01:00
|
|
|
if self.conv_textview.autoscroll or kind == 'outgoing':
|
2017-01-04 23:54:16 +01:00
|
|
|
end = True
|
|
|
|
|
2017-02-08 03:12:41 +01:00
|
|
|
if other_tags_for_name is None:
|
|
|
|
other_tags_for_name = []
|
|
|
|
if other_tags_for_time is None:
|
|
|
|
other_tags_for_time = []
|
|
|
|
if other_tags_for_text is None:
|
|
|
|
other_tags_for_text = []
|
|
|
|
if additional_data is None:
|
|
|
|
additional_data = {}
|
|
|
|
|
2017-01-04 23:54:16 +01:00
|
|
|
textview.print_conversation_line(text, jid, kind, name, tim,
|
|
|
|
other_tags_for_name, other_tags_for_time, other_tags_for_text,
|
|
|
|
subject, old_kind, xhtml, simple=simple, graphics=graphics,
|
|
|
|
displaymarking=displaymarking, msg_stanza_id=msg_stanza_id,
|
2017-06-11 01:58:27 +02:00
|
|
|
correct_id=correct_id, additional_data=additional_data,
|
|
|
|
encrypted=encrypted)
|
2017-01-04 23:54:16 +01:00
|
|
|
|
|
|
|
if xep0184_id is not None:
|
2017-05-01 19:42:57 +02:00
|
|
|
textview.add_xep0184_mark(xep0184_id)
|
2017-01-04 23:54:16 +01:00
|
|
|
|
|
|
|
if not count_as_new:
|
|
|
|
return
|
|
|
|
if kind == 'incoming':
|
|
|
|
if not self.type_id == message_control.TYPE_GC or \
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.get('notify_on_all_muc_messages') or \
|
2017-08-20 23:07:58 +02:00
|
|
|
app.config.get_per('rooms', jid, 'notify_on_all_messages') or \
|
2017-01-04 23:54:16 +01:00
|
|
|
'marked' in other_tags_for_text:
|
|
|
|
# it's a normal message, or a muc message with want to be
|
|
|
|
# notified about if quitting just after
|
|
|
|
# other_tags_for_text == ['marked'] --> highlighted gc message
|
2017-08-13 13:18:56 +02:00
|
|
|
app.last_message_time[self.account][full_jid] = time.time()
|
2017-01-04 23:54:16 +01:00
|
|
|
|
|
|
|
if kind in ('incoming', 'incoming_queue'):
|
|
|
|
# Record the history of received messages
|
|
|
|
self.save_message(text, 'received')
|
|
|
|
|
|
|
|
if kind in ('incoming', 'incoming_queue', 'error'):
|
|
|
|
gc_message = False
|
|
|
|
if self.type_id == message_control.TYPE_GC:
|
|
|
|
gc_message = True
|
|
|
|
|
|
|
|
if ((self.parent_win and (not self.parent_win.get_active_control() or \
|
|
|
|
self != self.parent_win.get_active_control() or \
|
|
|
|
not self.parent_win.is_active() or not end)) or \
|
|
|
|
(gc_message and \
|
2017-08-13 13:18:56 +02:00
|
|
|
jid in app.interface.minimized_controls[self.account])) and \
|
2017-01-04 23:54:16 +01:00
|
|
|
kind in ('incoming', 'incoming_queue', 'error'):
|
|
|
|
# we want to have save this message in events list
|
|
|
|
# other_tags_for_text == ['marked'] --> highlighted gc message
|
|
|
|
if gc_message:
|
|
|
|
if 'marked' in other_tags_for_text:
|
|
|
|
event_type = events.PrintedMarkedGcMsgEvent
|
|
|
|
else:
|
|
|
|
event_type = events.PrintedGcMsgEvent
|
|
|
|
event = 'gc_message_received'
|
|
|
|
else:
|
|
|
|
if self.type_id == message_control.TYPE_CHAT:
|
|
|
|
event_type = events.PrintedChatEvent
|
|
|
|
else:
|
|
|
|
event_type = events.PrintedPmEvent
|
|
|
|
event = 'message_received'
|
|
|
|
show_in_roster = notify.get_show_in_roster(event,
|
2018-06-30 11:02:30 +02:00
|
|
|
self.account, self.contact.jid, self.session)
|
2017-01-04 23:54:16 +01:00
|
|
|
show_in_systray = notify.get_show_in_systray(event,
|
2018-06-30 11:02:30 +02:00
|
|
|
self.account, self.contact.jid, event_type.type_)
|
2017-01-04 23:54:16 +01:00
|
|
|
|
|
|
|
event = event_type(text, subject, self, msg_log_id,
|
|
|
|
show_in_roster=show_in_roster,
|
|
|
|
show_in_systray=show_in_systray)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.events.add_event(self.account, full_jid, event)
|
2017-01-04 23:54:16 +01:00
|
|
|
# We need to redraw contact if we show in roster
|
|
|
|
if show_in_roster:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.roster.draw_contact(self.contact.jid,
|
2017-01-04 23:54:16 +01:00
|
|
|
self.account)
|
|
|
|
|
|
|
|
if not self.parent_win:
|
|
|
|
return
|
|
|
|
|
|
|
|
if (not self.parent_win.get_active_control() or \
|
|
|
|
self != self.parent_win.get_active_control() or \
|
|
|
|
not self.parent_win.is_active() or not end) and \
|
|
|
|
kind in ('incoming', 'incoming_queue', 'error'):
|
|
|
|
self.parent_win.redraw_tab(self)
|
|
|
|
if not self.parent_win.is_active():
|
|
|
|
self.parent_win.show_title(True, self) # Enabled Urgent hint
|
|
|
|
else:
|
|
|
|
self.parent_win.show_title(False, self) # Disabled Urgent hint
|
|
|
|
|
|
|
|
def toggle_emoticons(self):
|
|
|
|
"""
|
2017-06-16 19:36:32 +02:00
|
|
|
Hide show emoticons_button
|
2017-01-04 23:54:16 +01:00
|
|
|
"""
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.config.get('emoticons_theme'):
|
2017-06-16 19:36:32 +02:00
|
|
|
self.emoticons_button.set_no_show_all(False)
|
|
|
|
self.emoticons_button.show()
|
2017-01-04 23:54:16 +01:00
|
|
|
else:
|
2017-06-16 19:36:32 +02:00
|
|
|
self.emoticons_button.set_no_show_all(True)
|
|
|
|
self.emoticons_button.hide()
|
|
|
|
|
|
|
|
def set_emoticon_popover(self):
|
2017-08-13 13:18:56 +02:00
|
|
|
if not app.config.get('emoticons_theme'):
|
2017-06-16 19:36:32 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
if not self.parent_win:
|
|
|
|
return
|
|
|
|
|
2018-08-15 23:58:02 +02:00
|
|
|
emoji_chooser.text_widget = self.msg_textview
|
2017-06-16 19:36:32 +02:00
|
|
|
emoticons_button = self.xml.get_object('emoticons_button')
|
2018-08-15 23:58:02 +02:00
|
|
|
emoticons_button.set_popover(emoji_chooser)
|
2017-01-04 23:54:16 +01:00
|
|
|
|
|
|
|
def on_color_menuitem_activate(self, widget):
|
|
|
|
color_dialog = Gtk.ColorChooserDialog(None, self.parent_win.window)
|
|
|
|
color_dialog.set_use_alpha(False)
|
|
|
|
color_dialog.connect('response', self.msg_textview.color_set)
|
|
|
|
color_dialog.show_all()
|
|
|
|
|
|
|
|
def on_font_menuitem_activate(self, widget):
|
|
|
|
font_dialog = Gtk.FontChooserDialog(None, self.parent_win.window)
|
|
|
|
start, finish = self.msg_textview.get_active_iters()
|
|
|
|
font_dialog.connect('response', self.msg_textview.font_set, start, finish)
|
|
|
|
font_dialog.show_all()
|
|
|
|
|
|
|
|
def on_formatting_menuitem_activate(self, widget):
|
|
|
|
tag = widget.get_name()
|
|
|
|
self.msg_textview.set_tag(tag)
|
|
|
|
|
|
|
|
def on_clear_formatting_menuitem_activate(self, widget):
|
|
|
|
self.msg_textview.clear_tags()
|
|
|
|
|
2018-03-01 22:47:01 +01:00
|
|
|
def _style_changed(self, *args):
|
|
|
|
self.update_tags()
|
|
|
|
|
2017-01-04 23:54:16 +01:00
|
|
|
def update_tags(self):
|
|
|
|
self.conv_textview.update_tags()
|
|
|
|
|
|
|
|
def clear(self, tv):
|
|
|
|
buffer_ = tv.get_buffer()
|
|
|
|
start, end = buffer_.get_bounds()
|
|
|
|
buffer_.delete(start, end)
|
|
|
|
|
|
|
|
def _on_history_menuitem_activate(self, widget=None, jid=None):
|
|
|
|
"""
|
|
|
|
When history menuitem is pressed: call history window
|
|
|
|
"""
|
|
|
|
if not jid:
|
|
|
|
jid = self.contact.jid
|
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
if 'logs' in app.interface.instances:
|
|
|
|
app.interface.instances['logs'].window.present()
|
|
|
|
app.interface.instances['logs'].open_history(jid, self.account)
|
2017-01-04 23:54:16 +01:00
|
|
|
else:
|
2018-09-26 19:06:47 +02:00
|
|
|
from gajim.gtk.history import HistoryWindow
|
2018-08-04 20:12:38 +02:00
|
|
|
app.interface.instances['logs'] = HistoryWindow(jid, self.account)
|
2017-01-04 23:54:16 +01:00
|
|
|
|
2017-12-27 13:17:13 +01:00
|
|
|
def _on_send_file(self, action, param):
|
|
|
|
# get file transfer preference
|
|
|
|
ft_pref = app.config.get_per('accounts', self.account,
|
|
|
|
'filetransfer_preference')
|
|
|
|
|
|
|
|
win = self.parent_win.window
|
|
|
|
httpupload = win.lookup_action(
|
|
|
|
'send-file-httpupload-%s' % self.control_id)
|
|
|
|
jingle = win.lookup_action('send-file-jingle-%s' % self.control_id)
|
|
|
|
|
|
|
|
if httpupload.get_enabled() and jingle.get_enabled():
|
|
|
|
if ft_pref == 'httpupload':
|
|
|
|
httpupload.activate()
|
|
|
|
else:
|
|
|
|
jingle.activate()
|
|
|
|
elif httpupload.get_enabled():
|
|
|
|
httpupload.activate()
|
|
|
|
elif jingle.get_enabled():
|
|
|
|
jingle.activate()
|
|
|
|
|
|
|
|
def _on_send_httpupload(self, action, param):
|
|
|
|
app.interface.send_httpupload(self)
|
|
|
|
|
|
|
|
def _on_send_jingle(self, action, param):
|
|
|
|
self._on_send_file_jingle()
|
|
|
|
|
|
|
|
def _on_send_file_jingle(self, gc_contact=None):
|
2017-01-04 23:54:16 +01:00
|
|
|
"""
|
|
|
|
gc_contact can be set when we are in a groupchat control
|
|
|
|
"""
|
|
|
|
def _on_ok(c):
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.instances['file_transfers'].show_file_send_request(
|
2017-01-04 23:54:16 +01:00
|
|
|
self.account, c)
|
2017-12-27 13:17:13 +01:00
|
|
|
if self.type_id == message_control.TYPE_PM:
|
2017-01-04 23:54:16 +01:00
|
|
|
gc_contact = self.gc_contact
|
|
|
|
if gc_contact:
|
|
|
|
# gc or pm
|
2017-08-13 13:18:56 +02:00
|
|
|
gc_control = app.interface.msg_win_mgr.get_gc_control(
|
2017-01-04 23:54:16 +01:00
|
|
|
gc_contact.room_jid, self.account)
|
2017-08-13 13:18:56 +02:00
|
|
|
self_contact = app.contacts.get_gc_contact(self.account,
|
2017-01-04 23:54:16 +01:00
|
|
|
gc_control.room_jid, gc_control.nick)
|
|
|
|
if gc_control.is_anonymous and gc_contact.affiliation not in ['admin',
|
|
|
|
'owner'] and self_contact.affiliation in ['admin', 'owner']:
|
2017-08-13 13:18:56 +02:00
|
|
|
contact = app.contacts.get_contact(self.account, gc_contact.jid)
|
2017-01-04 23:54:16 +01:00
|
|
|
if not contact or contact.sub not in ('both', 'to'):
|
|
|
|
prim_text = _('Really send file?')
|
2018-03-25 16:26:29 +02:00
|
|
|
sec_text = _('If you send a file to %s, your real JID will '
|
|
|
|
'be revealed.') % gc_contact.name
|
2018-07-16 23:22:33 +02:00
|
|
|
dialog = NonModalConfirmationDialog(prim_text,
|
2017-01-04 23:54:16 +01:00
|
|
|
sec_text, on_response_ok=(_on_ok, gc_contact))
|
|
|
|
dialog.popup()
|
|
|
|
return
|
|
|
|
_on_ok(gc_contact)
|
|
|
|
return
|
|
|
|
_on_ok(self.contact)
|
|
|
|
|
|
|
|
def on_minimize_menuitem_toggled(self, widget):
|
|
|
|
"""
|
2018-06-22 00:47:29 +02:00
|
|
|
When a groupchat is minimized, unparent the tab, put it in roster etc
|
2017-01-04 23:54:16 +01:00
|
|
|
"""
|
|
|
|
old_value = True
|
2017-08-13 13:18:56 +02:00
|
|
|
non_minimized_gc = app.config.get_per('accounts', self.account,
|
2017-01-04 23:54:16 +01:00
|
|
|
'non_minimized_gc').split()
|
|
|
|
if self.contact.jid in non_minimized_gc:
|
|
|
|
old_value = False
|
|
|
|
minimize = widget.get_active()
|
|
|
|
if not minimize and not self.contact.jid in non_minimized_gc:
|
|
|
|
non_minimized_gc.append(self.contact.jid)
|
|
|
|
if minimize and self.contact.jid in non_minimized_gc:
|
|
|
|
non_minimized_gc.remove(self.contact.jid)
|
|
|
|
if old_value != minimize:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.config.set_per('accounts', self.account, 'non_minimized_gc',
|
2017-01-04 23:54:16 +01:00
|
|
|
' '.join(non_minimized_gc))
|
|
|
|
|
2017-08-20 23:07:58 +02:00
|
|
|
def on_notify_menuitem_toggled(self, widget):
|
|
|
|
app.config.set_per('rooms', self.contact.jid, 'notify_on_all_messages',
|
|
|
|
widget.get_active())
|
|
|
|
|
2017-01-04 23:54:16 +01:00
|
|
|
def set_control_active(self, state):
|
2018-09-29 21:48:21 +02:00
|
|
|
con = app.connections[self.account]
|
2017-01-04 23:54:16 +01:00
|
|
|
if state:
|
2017-06-16 19:36:32 +02:00
|
|
|
self.set_emoticon_popover()
|
2017-01-04 23:54:16 +01:00
|
|
|
jid = self.contact.jid
|
2018-03-20 22:19:30 +01:00
|
|
|
if self.conv_textview.autoscroll:
|
2017-01-04 23:54:16 +01:00
|
|
|
# we are at the end
|
|
|
|
type_ = ['printed_' + self.type_id]
|
|
|
|
if self.type_id == message_control.TYPE_GC:
|
|
|
|
type_ = ['printed_gc_msg', 'printed_marked_gc_msg']
|
2017-08-13 13:18:56 +02:00
|
|
|
if not app.events.remove_events(self.account, self.get_full_jid(),
|
2017-01-04 23:54:16 +01:00
|
|
|
types=type_):
|
|
|
|
# There were events to remove
|
|
|
|
self.redraw_after_event_removed(jid)
|
2016-12-24 04:36:21 +01:00
|
|
|
# send chatstate inactive to the one we're leaving
|
|
|
|
# and active to the one we visit
|
2017-12-15 23:00:15 +01:00
|
|
|
if self.msg_textview.has_text():
|
2018-09-29 21:48:21 +02:00
|
|
|
con.get_module('Chatstate').set_chatstate(self.contact,
|
|
|
|
Chatstate.PAUSED)
|
2016-12-24 04:36:21 +01:00
|
|
|
else:
|
2018-09-29 21:48:21 +02:00
|
|
|
con.get_module('Chatstate').set_chatstate(self.contact,
|
|
|
|
Chatstate.ACTIVE)
|
2016-12-24 04:36:21 +01:00
|
|
|
else:
|
2018-09-29 21:48:21 +02:00
|
|
|
con.get_module('Chatstate').set_chatstate(self.contact,
|
|
|
|
Chatstate.INACTIVE)
|
2017-01-04 23:54:16 +01:00
|
|
|
|
2018-03-20 22:19:30 +01:00
|
|
|
def scroll_to_end(self, force=False):
|
|
|
|
self.conv_textview.scroll_to_end(force)
|
2017-01-04 23:54:16 +01:00
|
|
|
|
2018-03-20 22:19:30 +01:00
|
|
|
def _on_edge_reached(self, scrolledwindow, pos):
|
|
|
|
if pos != Gtk.PositionType.BOTTOM:
|
|
|
|
return
|
|
|
|
# Remove all events and set autoscroll True
|
2018-03-24 02:36:22 +01:00
|
|
|
app.log('autoscroll').info('Autoscroll enabled')
|
2018-03-20 22:19:30 +01:00
|
|
|
self.conv_textview.autoscroll = True
|
2017-01-04 23:54:16 +01:00
|
|
|
if self.resource:
|
|
|
|
jid = self.contact.get_full_jid()
|
|
|
|
else:
|
|
|
|
jid = self.contact.jid
|
|
|
|
types_list = []
|
|
|
|
type_ = self.type_id
|
|
|
|
if type_ == message_control.TYPE_GC:
|
|
|
|
type_ = 'gc_msg'
|
|
|
|
types_list = ['printed_' + type_, type_, 'printed_marked_gc_msg']
|
|
|
|
else: # Not a GC
|
|
|
|
types_list = ['printed_' + type_, type_]
|
|
|
|
|
2018-09-16 01:10:04 +02:00
|
|
|
if not app.events.get_events(self.account, jid, types_list):
|
2017-01-04 23:54:16 +01:00
|
|
|
return
|
|
|
|
if not self.parent_win:
|
|
|
|
return
|
2018-03-20 22:19:30 +01:00
|
|
|
if self.parent_win.get_active_control() == self and \
|
2017-01-04 23:54:16 +01:00
|
|
|
self.parent_win.window.is_active():
|
|
|
|
# we are at the end
|
2018-08-18 15:56:23 +02:00
|
|
|
if not app.events.remove_events(
|
2018-08-18 15:52:12 +02:00
|
|
|
self.account, jid, types=types_list):
|
2017-01-04 23:54:16 +01:00
|
|
|
# There were events to remove
|
|
|
|
self.redraw_after_event_removed(jid)
|
|
|
|
|
2018-03-25 01:16:20 +01:00
|
|
|
def _on_scrollbar_button_release(self, scrollbar, event):
|
|
|
|
if event.get_button()[1] != 1:
|
|
|
|
# We want only to catch the left mouse button
|
|
|
|
return
|
|
|
|
if not gtkgui_helpers.at_the_end(scrollbar.get_parent()):
|
|
|
|
app.log('autoscroll').info('Autoscroll disabled')
|
|
|
|
self.conv_textview.autoscroll = False
|
|
|
|
|
2018-06-01 13:54:04 +02:00
|
|
|
def has_focus(self):
|
|
|
|
if self.parent_win:
|
|
|
|
if self.parent_win.window.get_property('has-toplevel-focus'):
|
|
|
|
if self == self.parent_win.get_active_control():
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2018-03-20 22:19:30 +01:00
|
|
|
def _on_scroll(self, widget, event):
|
2018-03-24 02:36:22 +01:00
|
|
|
if not self.conv_textview.autoscroll:
|
|
|
|
# autoscroll is already disabled
|
|
|
|
return
|
|
|
|
|
|
|
|
if widget is None:
|
|
|
|
# call from _conv_textview_key_press_event()
|
|
|
|
# SHIFT + Gdk.KEY_Page_Up
|
|
|
|
if event != Gdk.KEY_Page_Up:
|
|
|
|
return
|
|
|
|
else:
|
2018-06-22 00:47:29 +02:00
|
|
|
# On scrolling UP disable autoscroll
|
2018-03-25 00:22:40 +01:00
|
|
|
# get_scroll_direction() sets has_direction only TRUE
|
|
|
|
# if smooth scrolling is deactivated. If we have smooth
|
|
|
|
# smooth scrolling we have to use get_scroll_deltas()
|
2018-03-24 02:36:22 +01:00
|
|
|
has_direction, direction = event.get_scroll_direction()
|
2018-03-25 00:22:40 +01:00
|
|
|
if not has_direction:
|
|
|
|
direction = None
|
|
|
|
smooth, delta_x, delta_y = event.get_scroll_deltas()
|
|
|
|
if smooth:
|
|
|
|
if delta_y < 0:
|
|
|
|
direction = Gdk.ScrollDirection.UP
|
|
|
|
elif delta_y > 0:
|
|
|
|
direction = Gdk.ScrollDirection.DOWN
|
|
|
|
elif delta_x < 0:
|
|
|
|
direction = Gdk.ScrollDirection.LEFT
|
|
|
|
elif delta_x > 0:
|
|
|
|
direction = Gdk.ScrollDirection.RIGHT
|
|
|
|
else:
|
|
|
|
app.log('autoscroll').warning(
|
|
|
|
'Scroll directions cant be determined')
|
|
|
|
|
2018-03-24 02:36:22 +01:00
|
|
|
if direction != Gdk.ScrollDirection.UP:
|
|
|
|
return
|
|
|
|
# Check if we have a Scrollbar
|
|
|
|
adjustment = self.conv_scrolledwindow.get_vadjustment()
|
|
|
|
if adjustment.get_upper() != adjustment.get_page_size():
|
|
|
|
app.log('autoscroll').info('Autoscroll disabled')
|
|
|
|
self.conv_textview.autoscroll = False
|
2018-03-20 22:19:30 +01:00
|
|
|
|
|
|
|
def on_conversation_vadjustment_changed(self, adjustment):
|
|
|
|
self.scroll_to_end()
|
|
|
|
|
2017-01-04 23:54:16 +01:00
|
|
|
def redraw_after_event_removed(self, jid):
|
|
|
|
"""
|
|
|
|
We just removed a 'printed_*' event, redraw contact in roster or
|
|
|
|
gc_roster and titles in roster and msg_win
|
|
|
|
"""
|
|
|
|
self.parent_win.redraw_tab(self)
|
|
|
|
self.parent_win.show_title()
|
|
|
|
# TODO : get the contact and check notify.get_show_in_roster()
|
|
|
|
if self.type_id == message_control.TYPE_PM:
|
2017-08-13 13:18:56 +02:00
|
|
|
room_jid, nick = app.get_room_and_nick_from_fjid(jid)
|
|
|
|
groupchat_control = app.interface.msg_win_mgr.get_gc_control(
|
2017-01-04 23:54:16 +01:00
|
|
|
room_jid, self.account)
|
2017-08-13 13:18:56 +02:00
|
|
|
if room_jid in app.interface.minimized_controls[self.account]:
|
2017-01-04 23:54:16 +01:00
|
|
|
groupchat_control = \
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.minimized_controls[self.account][room_jid]
|
|
|
|
contact = app.contacts.get_contact_with_highest_priority(
|
2017-01-04 23:54:16 +01:00
|
|
|
self.account, room_jid)
|
|
|
|
if contact:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.roster.draw_contact(room_jid, self.account)
|
2017-01-04 23:54:16 +01:00
|
|
|
if groupchat_control:
|
|
|
|
groupchat_control.draw_contact(nick)
|
|
|
|
if groupchat_control.parent_win:
|
|
|
|
groupchat_control.parent_win.redraw_tab(groupchat_control)
|
|
|
|
else:
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.roster.draw_contact(jid, self.account)
|
|
|
|
app.interface.roster.show_title()
|
2017-01-04 23:54:16 +01:00
|
|
|
|
|
|
|
def scroll_messages(self, direction, msg_buf, msg_type):
|
|
|
|
if msg_type == 'sent':
|
|
|
|
history = self.sent_history
|
|
|
|
pos = self.sent_history_pos
|
|
|
|
self.received_history_pos = len(self.received_history)
|
|
|
|
else:
|
|
|
|
history = self.received_history
|
|
|
|
pos = self.received_history_pos
|
|
|
|
self.sent_history_pos = len(self.sent_history)
|
|
|
|
size = len(history)
|
|
|
|
if self.orig_msg is None:
|
|
|
|
# user was typing something and then went into history, so save
|
|
|
|
# whatever is already typed
|
|
|
|
start_iter = msg_buf.get_start_iter()
|
|
|
|
end_iter = msg_buf.get_end_iter()
|
|
|
|
self.orig_msg = msg_buf.get_text(start_iter, end_iter, False)
|
|
|
|
if pos == size and size > 0 and direction == 'up' and \
|
|
|
|
msg_type == 'sent' and not self.correcting and (not \
|
|
|
|
history[pos - 1].startswith('/') or history[pos - 1].startswith('/me')):
|
|
|
|
self.correcting = True
|
2017-03-01 17:11:18 +01:00
|
|
|
gtkgui_helpers.add_css_class(
|
2018-03-01 22:47:01 +01:00
|
|
|
self.msg_textview, 'gajim-msg-correcting')
|
2017-01-04 23:54:16 +01:00
|
|
|
message = history[pos - 1]
|
|
|
|
msg_buf.set_text(message)
|
|
|
|
return
|
|
|
|
if self.correcting:
|
|
|
|
# We were previously correcting
|
2017-03-01 17:11:18 +01:00
|
|
|
gtkgui_helpers.remove_css_class(
|
2018-03-01 22:47:01 +01:00
|
|
|
self.msg_textview, 'gajim-msg-correcting')
|
2017-01-04 23:54:16 +01:00
|
|
|
self.correcting = False
|
|
|
|
pos += -1 if direction == 'up' else +1
|
|
|
|
if pos == -1:
|
|
|
|
return
|
|
|
|
if pos >= size:
|
|
|
|
pos = size
|
|
|
|
message = self.orig_msg
|
|
|
|
self.orig_msg = None
|
|
|
|
else:
|
|
|
|
message = history[pos]
|
|
|
|
if msg_type == 'sent':
|
|
|
|
self.sent_history_pos = pos
|
|
|
|
else:
|
|
|
|
self.received_history_pos = pos
|
|
|
|
if self.orig_msg is not None:
|
|
|
|
message = '> %s\n' % message.replace('\n', '\n> ')
|
|
|
|
msg_buf.set_text(message)
|
|
|
|
|
|
|
|
def widget_set_visible(self, widget, state):
|
|
|
|
"""
|
|
|
|
Show or hide a widget
|
|
|
|
"""
|
|
|
|
# make the last message visible, when changing to "full view"
|
|
|
|
if not state:
|
2018-03-20 22:19:30 +01:00
|
|
|
self.scroll_to_end()
|
2017-01-04 23:54:16 +01:00
|
|
|
|
|
|
|
widget.set_no_show_all(state)
|
|
|
|
if state:
|
|
|
|
widget.hide()
|
|
|
|
else:
|
|
|
|
widget.show_all()
|
|
|
|
|
|
|
|
def got_connected(self):
|
|
|
|
self.msg_textview.set_sensitive(True)
|
|
|
|
self.msg_textview.set_editable(True)
|
|
|
|
self.update_toolbar()
|
|
|
|
|
|
|
|
def got_disconnected(self):
|
|
|
|
self.msg_textview.set_sensitive(False)
|
|
|
|
self.msg_textview.set_editable(False)
|
|
|
|
self.conv_textview.tv.grab_focus()
|
|
|
|
|
|
|
|
self.no_autonegotiation = False
|
|
|
|
self.update_toolbar()
|
2017-10-03 13:08:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ScrolledWindow(Gtk.ScrolledWindow):
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-10-27 10:46:59 +02:00
|
|
|
Gtk.ScrolledWindow.__init__(self, *args, **kwargs)
|
2017-10-03 13:08:06 +02:00
|
|
|
|
2017-10-30 23:00:44 +01:00
|
|
|
self.set_overlay_scrolling(False)
|
|
|
|
self.set_max_content_height(100)
|
|
|
|
self.set_propagate_natural_height(True)
|
|
|
|
self.get_style_context().add_class('scrolled-no-border')
|
|
|
|
self.get_style_context().add_class('no-scroll-indicator')
|
|
|
|
self.get_style_context().add_class('scrollbar-style')
|
|
|
|
self.set_shadow_type(Gtk.ShadowType.IN)
|
|
|
|
|
2017-10-03 13:08:06 +02:00
|
|
|
def do_get_preferred_height(self):
|
|
|
|
min_height, natural_height = Gtk.ScrolledWindow.do_get_preferred_height(self)
|
2017-10-27 10:46:59 +02:00
|
|
|
# Gtk Bug: If policy is set to Automatic, the ScrolledWindow
|
2018-02-20 22:03:57 +01:00
|
|
|
# has a min size of around 46-82 depending on the System. Because
|
|
|
|
# we want it smaller, we set policy NEVER if the height is < 90
|
2018-06-22 00:47:29 +02:00
|
|
|
# so the ScrolledWindow will shrink to around 26 (1 line height).
|
2018-02-20 22:03:57 +01:00
|
|
|
# Once it gets over 90 its no problem to restore the policy.
|
|
|
|
if natural_height < 90:
|
2017-10-27 10:46:59 +02:00
|
|
|
GLib.idle_add(self.set_policy,
|
|
|
|
Gtk.PolicyType.AUTOMATIC,
|
|
|
|
Gtk.PolicyType.NEVER)
|
|
|
|
else:
|
|
|
|
GLib.idle_add(self.set_policy,
|
|
|
|
Gtk.PolicyType.AUTOMATIC,
|
|
|
|
Gtk.PolicyType.AUTOMATIC)
|
2017-10-03 13:08:06 +02:00
|
|
|
|
|
|
|
return min_height, natural_height
|