Commit 9c5fb0cb authored by Yuki's avatar Yuki

Add paste-image-from-clipboard functionality

parent c823ef6c
Pipeline #3501 failed with stages
in 0 seconds
......@@ -25,7 +25,9 @@
import os
import re
import os.path
import time
from tempfile import TemporaryDirectory
from gi.repository import Gtk
from gi.repository import Gdk
......@@ -297,6 +299,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._on_message_textview_paste_event)
self.handlers[id_] = self.msg_textview
id_ = self.msg_textview.connect('key_press_event',
self._on_message_textview_key_press_event)
self.handlers[id_] = self.msg_textview
......@@ -579,6 +584,41 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self.parent_win.notebook.event(event)
return Gdk.EVENT_STOP
def _on_message_textview_paste_event(self, textview):
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
image = clipboard.wait_for_image()
if image is not None:
with TemporaryDirectory() as dir_:
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
con.get_module('HTTPUpload').check_file_before_transfer(
path, self.encryption, self.contact,
self.session, groupchat=True)
else:
if httpupload.get_enabled() and jingle.get_enabled():
if ft_pref == 'httpupload':
con.get_module('HTTPUpload').check_file_before_transfer(
path, self.encryption, self.contact, self.session)
else:
ft = app.interface.instances['file_transfers']
ft.send_file(self.account, self.contact, path)
elif httpupload.get_enabled():
con.get_module('HTTPUpload').check_file_before_transfer(
path, self.encryption, self.contact, self.session)
elif jingle.get_enabled():
ft = app.interface.instances['file_transfers']
ft.send_file(self.account, self.contact, path)
def _on_message_textview_key_press_event(self, widget, event):
if event.keyval == Gdk.KEY_space:
self.space_pressed = True
......
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