Commit 16751610 authored by Yuki's avatar Yuki Committed by Philipp Hörist
Browse files

Add paste-image-from-clipboard functionality

parent 4394bb11
......@@ -26,6 +26,7 @@
import os
import re
import time
from tempfile import TemporaryDirectory
from gi.repository import Gtk
from gi.repository import Gdk
......@@ -297,6 +298,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
hbox = self.xml.get_object('hbox')
hbox.pack_start(self.msg_scrolledwindow, True, True, 0)
id_ = self.msg_textview.connect('paste-clipboard',
self.handlers[id_] = self.msg_textview
id_ = self.msg_textview.connect('key_press_event',
self.handlers[id_] = self.msg_textview
......@@ -579,6 +583,62 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
return Gdk.EVENT_STOP
def _on_message_textview_paste_event(self, texview):
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
image = clipboard.wait_for_image()
if image is not None:
if not app.config.get('confirm_paste_image'):
_('You are trying to paste an image'),
_('Are you sure you want to paste your '
'clipboard image in the chat?'),
callback=lambda: self._paste_event_confirmed(image))],
def _paste_event_confirmed(self, image):
tmp_dir = TemporaryDirectory()
dir_ =
# get file transfer preference
ft_pref = app.config.get_per('accounts', self.account,
path = os.path.join(dir_, '0.png')
image.savev(path, 'png', [], [])
con = app.connections[self.account]
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 self.type_id == message_control.TYPE_GC:
# groupchat only supports httpupload on drag and drop
if httpupload.get_enabled():
# use httpupload
path, self.encryption,,
self.session, groupchat=True)
if httpupload.get_enabled() and jingle.get_enabled():
if ft_pref == 'httpupload':
path, self.encryption,, self.session)
ft = app.interface.instances['file_transfers']
ft.send_file(self.account,, path)
elif httpupload.get_enabled():
path, self.encryption,, self.session)
elif jingle.get_enabled():
ft = app.interface.instances['file_transfers']
ft.send_file(self.account,, path)
def _on_message_textview_key_press_event(self, widget, event):
if event.keyval == Gdk.KEY_space:
self.space_pressed = True
......@@ -185,6 +185,7 @@ class Config:
'remote_control': [opt_bool, False, _('If checked, Gajim can be controlled remotely using gajim-remote.'), True],
'autodetect_browser_mailer': [opt_bool, True, '', True],
'print_ichat_every_foo_minutes': [opt_int, 5, _('When not printing time for every message (print_time==sometimes), print it every x minutes.')],
'confirm_paste_image': [opt_bool, True, _('Ask before pasting an image.')],
'confirm_close_muc': [opt_bool, True, _('Ask before closing a group chat tab/window.')],
'confirm_close_muc_rooms': [opt_str, '', _('Always ask for confirmation before closing groupchats with any of the JIDs on this space separated list.')],
'noconfirm_close_muc_rooms': [opt_str, '', _('Never ask for confirmation before closing groupchats with any of the JIDs on this space separated list.')],
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment