Skip to content
Snippets Groups Projects
Commit 1b9ccad1 authored by Daniel Brötzmann's avatar Daniel Brötzmann Committed by Philipp Hörist
Browse files

Show preview when pasting image from clipboard

parent cbc7e8be
No related branches found
No related tags found
No related merge requests found
......@@ -53,7 +53,7 @@
from gajim.gtk.dialogs import DialogButton
from gajim.gtk.dialogs import NewConfirmationDialog
from gajim.gtk.dialogs import NewConfirmationCheckDialog
from gajim.gtk.dialogs import PastePreviewDialog
from gajim.gtk.message_input import MessageInputTextView
from gajim.gtk.util import at_the_end
from gajim.gtk.util import get_show_in_roster
......@@ -731,12 +731,13 @@ def _on_message_textview_paste_event(self, _texview):
if not app.settings.get('confirm_paste_image'):
self._paste_event_confirmed(True, image)
return
NewConfirmationCheckDialog(
PastePreviewDialog(
_('Paste Image'),
_('You are trying to paste an image'),
_('Are you sure you want to paste your '
'clipboard\'s image into the chat window?'),
_('_Do not ask me again'),
image,
[DialogButton.make('Cancel'),
DialogButton.make('Accept',
text=_('_Paste'),
......
......@@ -18,6 +18,7 @@
from gi.repository import GLib
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GdkPixbuf
from gi.repository import Pango
from gajim.common import app
......@@ -26,6 +27,7 @@
from gajim.common.helpers import convert_gio_to_openssl_cert
from gajim.gtk.util import get_builder
from gajim.gtk.util import get_thumbnail_size
class DialogButton(namedtuple('DialogButton', ('response text callback args '
......@@ -489,6 +491,38 @@ def _on_response(self, _dialog, response):
super()._on_response(_dialog, response)
class PastePreviewDialog(NewConfirmationCheckDialog):
def __init__(self, title, text, sec_text, check_text, image,
buttons, modal=True, transient_for=None):
NewConfirmationCheckDialog.__init__(self,
title,
text,
sec_text,
check_text,
buttons,
transient_for=transient_for,
modal=modal)
preview = Gtk.Image()
preview.set_halign(Gtk.Align.CENTER)
preview.get_style_context().add_class('preview-image')
size = 300
image_width = image.get_width()
image_height = image.get_height()
if size > image_width and size > image_height:
preview.set_from_pixbuf(image)
else:
thumb_width, thumb_height = get_thumbnail_size(image, size)
pixbuf_scaled = image.scale_simple(
thumb_width, thumb_height, GdkPixbuf.InterpType.BILINEAR)
preview.set_from_pixbuf(pixbuf_scaled)
content_area = self.get_content_area()
content_area.pack_start(preview, True, True, 0)
content_area.reorder_child(preview, 2)
class InputDialog(NewConfirmationDialog):
def __init__(self, title, text, sec_text, buttons, input_str=None,
transient_for=None, modal=True):
......
......@@ -23,6 +23,7 @@
import sys
import weakref
import logging
import math
import textwrap
import functools
from importlib import import_module
......@@ -757,6 +758,25 @@ def load_pixbuf(path, size=None):
return pixbuf
def get_thumbnail_size(pixbuf, size):
# Calculates the new thumbnail size while preserving the aspect ratio
image_width = pixbuf.get_width()
image_height = pixbuf.get_height()
if image_width > image_height:
if image_width > size:
image_height = math.ceil(
(size / float(image_width) * image_height))
image_width = int(size)
else:
if image_height > size:
image_width = math.ceil(
(size / float(image_height) * image_width))
image_height = int(size)
return image_width, image_height
def make_href_markup(string):
url_color = app.css_config.get_value('.gajim-url', StyleAttr.COLOR)
color = convert_rgb_to_hex(url_color)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment