Commit dda1e91b authored by Daniel Brötzmann's avatar Daniel Brötzmann Committed by Philipp Hörist

[preview] Add preview widget

parent de16fa6f
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<!-- Generated with glade 3.22.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkMenu" id="context_menu">
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem" id="download">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Download</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="open">
<property name="visible">True</property>
......
# This is an excerpt of Media Types from
# https://www.iana.org/assignments/media-types/media-types.xhtml
# plus some additions
MIME_TYPES = (
# application/
'application/calendar+json',
'application/calendar+xml',
'application/epub+zip',
'application/json',
'application/mp4',
'application/msword',
'application/octet-stream',
'application/ogg',
'application/pdf',
'application/pgp-encrypted',
'application/pgp-signature',
'application/postscript',
'application/rtf',
'application/vcard+json',
'application/vcard+xml',
'application/vnd.amazon.mobi8-ebook',
'application/vnd.google-earth.kml+xml',
'application/vnd.google-earth.kmz',
# Start office
'application/vnd.ms-access',
'application/vnd.ms-excel',
'application/vnd.ms-excel.addin.macroEnabled.12',
'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
'application/vnd.ms-excel.sheet.macroEnabled.12',
'application/vnd.ms-excel.template.macroEnabled.12',
'application/vnd.ms-powerpoint',
'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
'application/vnd.ms-powerpoint.template.macroEnabled.12',
'application/vnd.ms-word.document.macroEnabled.12',
'application/vnd.ms-word.template.macroEnabled.12',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
'application/vnd.openxmlformats-officedocument.presentationml.template',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
'application/vnd.openxmlformats-officedocument.vmlDrawing',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
# End office
'application/vnd.sqlite3',
'application/zip',
# audio/*
'audio/aac',
'audio/ac3',
'audio/flac',
'audio/mp4',
'audio/mpeg',
'audio/ogg',
'audio/opus',
'audio/wav',
'audio/x-flac',
'audio/x-matroska',
# font/*
'font/ttf',
'font/woff',
'font/woff2',
# image/*
'image/bmp',
'image/x-bmp',
'image/x-ms-bmp',
'image/gif',
'image/heic',
'image/heif',
'image/jpeg',
'image/png',
'image/svg+xml',
'image/tiff',
'image/vnd.adobe.photoshop',
'image/vnd.dwg',
'image/vnd.dxf',
'image/vnd.microsoft.icon',
'image/x-icon',
'image/x-xcf',
# model/*
'model/mtl',
'model/obj',
'model/stl',
# text/*
'text/calendar',
'text/csv',
'text/markdown',
'text/rtf',
'text/vcard',
# video/*
'video/H264',
'video/H265',
'video/mp4',
'video/mpeg4-generic',
'video/ogg',
'video/quicktime',
'video/vc1',
'video/VP8',
'video/webm',
'video/x-matroska',
'video/x-msvideo',
)
.preview-box {
border: 1px solid;
border-color: @borders;
border-radius: 5px;
padding: 10px;
margin: 5px;
background-color: @theme_unfocused_base_color;
}
.preview-button {
border: 1px solid @borders;
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkBox" id="preview_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">3</property>
<child>
<object class="GtkEventBox" id="event_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="button_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="file_name">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="selectable">True</property>
<property name="ellipsize">end</property>
<property name="single_line_mode">True</property>
<property name="xalign">0</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="file_size">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="single_line_mode">True</property>
<property name="xalign">0</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="save_as_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Save as...</property>
<property name="valign">end</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">document-save-as-symbolic</property>
</object>
</child>
<style>
<class name="preview-button"/>
<class name="flat"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="open_folder_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Open folder</property>
<property name="valign">end</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">folder-symbolic</property>
</object>
</child>
<style>
<class name="preview-button"/>
<class name="flat"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="download_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Download</property>
<property name="valign">end</property>
<property name="relief">none</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">folder-download-symbolic</property>
</object>
</child>
<style>
<class name="preview-button"/>
<class name="flat"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<style>
<class name="preview-box"/>
</style>
</object>
</interface>
This diff is collapsed.
......@@ -26,7 +26,6 @@ from urllib.parse import unquote
from gi.repository import GdkPixbuf
from gi.repository import GLib
from gi.repository import Gtk
from PIL import Image
......@@ -35,7 +34,6 @@ from cryptography.hazmat.primitives.ciphers import Cipher
from cryptography.hazmat.primitives.ciphers import algorithms
from cryptography.hazmat.primitives.ciphers.modes import GCM
from gajim.gtk.util import get_cursor
log = logging.getLogger('gajim.p.preview.utils')
......@@ -237,35 +235,6 @@ def pixbuf_from_data(data):
return loader.get_pixbuf()
def create_clickable_image(pixbuf, preview):
if isinstance(pixbuf, GdkPixbuf.PixbufAnimation):
image = Gtk.Image.new_from_animation(pixbuf)
else:
image = Gtk.Image.new_from_pixbuf(pixbuf)
css = '''#Preview {
box-shadow: 0px 0px 3px 0px alpha(@theme_text_color, 0.2);
margin: 5px 10px 5px 10px; }'''
provider = Gtk.CssProvider()
provider.load_from_data(bytes(css.encode()))
context = image.get_style_context()
context.add_provider(provider,
Gtk.STYLE_PROVIDER_PRIORITY_USER)
image.set_name('Preview')
def _on_realize(box):
box.get_window().set_cursor(get_cursor('pointer'))
event_box = Gtk.EventBox()
event_box.connect('realize', _on_realize)
event_box.set_tooltip_text(preview.uri)
event_box.add(image)
event_box.show_all()
return event_box
def parse_fragment(fragment):
if not fragment:
raise ValueError('Invalid fragment')
......
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