From 9c9178448086b7bf26d2b0f98f460e41a11c7f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Mon, 7 May 2018 20:46:47 +0200 Subject: [PATCH] [preview] Add setting to allow all image urls Fixes #301 --- url_image_preview/config_dialog.py | 4 ++++ url_image_preview/url_image_preview.py | 25 +++++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/url_image_preview/config_dialog.py b/url_image_preview/config_dialog.py index 1cc8ae7..d3d97d4 100644 --- a/url_image_preview/config_dialog.py +++ b/url_image_preview/config_dialog.py @@ -57,6 +57,10 @@ class UrlImagePreviewConfigDialog(OptionsDialog): props={'items': sizes, 'plugin': self.plugin}), + Option(OptionKind.SWITCH, _('Preview all Image URLs'), + OptionType.VALUE, self.plugin.config['ALLOW_ALL_IMAGES'], + callback=self.on_option, data='ALLOW_ALL_IMAGES'), + Option('PreviewComboOption', _('Left click action'), OptionType.VALUE, self.plugin.config['LEFTCLICK_ACTION'], callback=self.on_option, data='LEFTCLICK_ACTION', diff --git a/url_image_preview/url_image_preview.py b/url_image_preview/url_image_preview.py index 81a4397..8e9733e 100644 --- a/url_image_preview/url_image_preview.py +++ b/url_image_preview/url_image_preview.py @@ -82,6 +82,7 @@ class UrlImagePreviewPlugin(GajimPlugin): self.config_default_values = { 'PREVIEW_SIZE': (150, 'Preview size(10-512)'), 'MAX_FILE_SIZE': (5242880, 'Max file size for image preview'), + 'ALLOW_ALL_IMAGES': (False, ''), 'LEFTCLICK_ACTION': ('open_menuitem', 'Open'), 'ANONYMOUS_MUC': (False, ''), 'GEO_PREVIEW_PROVIDER': ('Google', 'Google Maps'), @@ -177,14 +178,11 @@ class Base(object): except (KeyError, AttributeError): oob_url = None - # allow aesgcm uris without oob marker (aesgcm uris are always - # httpupload filetransfers) - if urlparts.scheme != "aesgcm" and real_text != oob_url: - if urlparts.scheme != "geo": - log.info("Not accepting URL for image preview " - "(wrong or no oob data): %s", real_text) - log.debug("additional_data: %s", additional_data) - return + if not self._accept_uri(urlparts, real_text, oob_url): + log.info("Not accepting URL for image preview " + "(wrong or no oob data): %s", real_text) + log.debug("additional_data: %s", additional_data) + return # Don't print the URL in the message window (in the calling function) self.textview.plugin_modified = True @@ -316,6 +314,17 @@ class Base(object): repl_end, filepaths, key, iv, encrypted]) + def _accept_uri(self, urlparts, real_text, oob_url): + # allow aesgcm uris without oob marker (aesgcm uris are always + # httpupload filetransfers) + if urlparts.scheme in ('aesgcm', 'geo'): + return True + + if real_text != oob_url: + if self.plugin.config['ALLOW_ALL_IMAGES']: + return True + return False + def _save_thumbnail(self, thumbpath, mem): size = self.plugin.config['PREVIEW_SIZE']