Skip to content
Snippets Groups Projects
Commit 08cd37b8 authored by Comrade DOS's avatar Comrade DOS Committed by Philipp Hörist
Browse files

[preview] Adding detection of supported mime types at runtime

parent 834d3713
No related branches found
No related tags found
1 merge request!184Adding detection of supported mime types at runtime
......@@ -26,6 +26,7 @@ from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GLib
from gi.repository import Soup
from gi.repository import GdkPixbuf
from gajim.common import app
from gajim.common import configpaths
......@@ -52,6 +53,7 @@ ERROR_MSG = None
try:
from PIL import Image # pylint: disable=unused-import
except ImportError:
Image = None
log.error('Pillow not available')
ERROR_MSG = _('Please install python-pillow')
......@@ -73,14 +75,21 @@ if ERROR_MSG is None:
from url_image_preview.utils import filename_from_uri
# pylint: enable=ungrouped-imports
ACCEPTED_MIME_TYPES = [
'image/png',
'image/jpeg',
'image/gif',
'image/raw',
'image/svg+xml',
'image/x-ms-bmp',
]
def get_accepted_mime_types():
accepted_mime_types = set()
for fmt in GdkPixbuf.Pixbuf.get_formats():
for mime_type in fmt.get_mime_types():
accepted_mime_types.add(mime_type.lower())
if Image is not None:
Image.init()
for mime_type in Image.MIME.values():
accepted_mime_types.add(mime_type.lower())
return tuple(filter(
lambda mime_type: mime_type.startswith('image'),
accepted_mime_types
))
ACCEPTED_MIME_TYPES = get_accepted_mime_types()
class UrlImagePreviewPlugin(GajimPlugin):
......
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