Commit 262f9a8b authored by Yuki's avatar Yuki Committed by Philipp Hörist

Cleanup chat_control_base.py

parent b16a49f6
Pipeline #3515 passed with stages
in 2 minutes and 24 seconds
......@@ -25,7 +25,6 @@
import os
import re
import os.path
import time
from tempfile import TemporaryDirectory
......@@ -584,12 +583,12 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self.parent_win.notebook.event(event)
return Gdk.EVENT_STOP
def _on_message_textview_paste_event(self, textview):
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'):
self._paste_event_confirmed(image, textview)
self._paste_event_confirmed(image)
return
NewConfirmationDialog(
_('Warning'),
......@@ -598,43 +597,47 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
'clipboard image in the chat?'),
[DialogButton.make('Cancel'),
DialogButton.make('OK',
callback=lambda: self._paste_event_confirmed(image, textview))],
transient_for=self.parent_win.window).show()
def _paste_event_confirmed(self, image, textview):
with TemporaryDirectory() as dir_:
# get file transfer preference
ft_pref = app.config.get_per('accounts', self.account,
'filetransfer_preference')
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)
callback=lambda: self._paste_event_confirmed(image))],
).show()
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():
def _paste_event_confirmed(self, image):
tmp_dir = TemporaryDirectory()
dir_ = tmp_dir.name
# get file transfer preference
ft_pref = app.config.get_per('accounts', self.account,
'filetransfer_preference')
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)
elif jingle.get_enabled():
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)
tmp_dir.cleanup()
def _on_message_textview_key_press_event(self, widget, event):
if event.keyval == Gdk.KEY_space:
......
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