[preview] Use Settings instead of Options

This commit is contained in:
Daniel Brötzmann
2019-04-23 10:10:36 +02:00
parent d493646a2a
commit 3fbc1b20c9

View File

@@ -20,115 +20,89 @@
from gi.repository import GObject from gi.repository import GObject
from gi.repository import Gtk from gi.repository import Gtk
from gajim.options_dialog import OptionsDialog, GenericOption, SpinOption from gajim.gtk.settings import SettingsDialog
from gajim.common.const import Option, OptionType, OptionKind from gajim.gtk.settings import GenericSetting
from gajim.gtk.settings import SpinSetting
from gajim.gtk.const import Setting
from gajim.gtk.const import SettingKind
from gajim.gtk.const import SettingType
from gajim.plugins.plugins_i18n import _ from gajim.plugins.plugins_i18n import _
class UrlImagePreviewConfigDialog(OptionsDialog): class UrlImagePreviewConfigDialog(SettingsDialog):
def __init__(self, plugin, parent): def __init__(self, plugin, parent):
sizes = [('256 KiB', '262144'), sizes = [('262144', '256 KiB'),
('512 KiB', '524288'), ('524288', '512 KiB'),
('1 MiB', '1048576'), ('1048576', '1 MiB'),
('5 MiB', '5242880'), ('5242880', '5 MiB'),
('10 MiB', '10485760')] ('10485760', '10 MiB')]
actions = [ actions = [
(_('Open'), 'open_menuitem'), ('open_menuitem', _('Open')),
(_('Save as'), 'save_as_menuitem'), ('save_as_menuitem', _('Save as')),
(_('Copy Link Location'), 'copy_link_location_menuitem'), ('copy_link_location_menuitem', _('Copy Link Location')),
(_('Open Link in Browser'), 'open_link_in_browser_menuitem'), ('open_link_in_browser_menuitem', _('Open Link in Browser')),
(_('Open File in Browser'), 'open_file_in_browser_menuitem')] ('open_file_in_browser_menuitem', _('Open File in Browser'))]
geo_providers = [ geo_providers = [
(_('No map preview'), 'no_preview'), ('no_preview', _('No map preview')),
('Google Maps', 'Google'), ('Google', _('Google Maps')),
('OpenStreetMap', 'OSM')] ('OSM', _('OpenStreetMap'))]
self.plugin = plugin self.plugin = plugin
options = [ settings = [
Option('PreviewSizeSpinOption', _('Preview size'), Setting('PreviewSizeSpinSetting', _('Preview Size'),
OptionType.VALUE, self.plugin.config['PREVIEW_SIZE'], SettingType.VALUE, self.plugin.config['PREVIEW_SIZE'],
callback=self.on_option, data='PREVIEW_SIZE', callback=self.on_setting, data='PREVIEW_SIZE',
props={'range_': (100, 1000)}), desc=_('Size of preview image'),
props={'range_': (100, 1000)}),
Option('PreviewComboOption', _('Accepted filesize'), Setting(SettingKind.COMBO, _('File Size'),
OptionType.VALUE, self.plugin.config['MAX_FILE_SIZE'], SettingType.VALUE, self.plugin.config['MAX_FILE_SIZE'],
callback=self.on_option, data='MAX_FILE_SIZE', callback=self.on_setting, data='MAX_FILE_SIZE',
props={'items': sizes, desc=_('Maximum file size for preview generation'),
'plugin': self.plugin}), props={'combo_items': sizes}),
Option(OptionKind.SWITCH, _('Preview all Image URLs'), Setting(SettingKind.SWITCH, _('Preview all Image URLs'),
OptionType.VALUE, self.plugin.config['ALLOW_ALL_IMAGES'], SettingType.VALUE, self.plugin.config['ALLOW_ALL_IMAGES'],
callback=self.on_option, data='ALLOW_ALL_IMAGES'), callback=self.on_setting, data='ALLOW_ALL_IMAGES',
desc=_('Generate preview for any URL containing images '
'(may be unsafe)')),
Option('PreviewComboOption', _('Left click action'), Setting(SettingKind.COMBO, _('Left Click'),
OptionType.VALUE, self.plugin.config['LEFTCLICK_ACTION'], SettingType.VALUE, self.plugin.config['LEFTCLICK_ACTION'],
callback=self.on_option, data='LEFTCLICK_ACTION', callback=self.on_setting, data='LEFTCLICK_ACTION',
props={'items': actions, desc=_('Action when left clicking a preview'),
'plugin': self.plugin}), props={'combo_items': actions}),
Option('PreviewComboOption', _('Map service for preview'), Setting(SettingKind.COMBO, _('Map Service'),
OptionType.VALUE, self.plugin.config['GEO_PREVIEW_PROVIDER'], SettingType.VALUE, self.plugin.config['GEO_PREVIEW_PROVIDER'],
callback=self.on_option, data='GEO_PREVIEW_PROVIDER', callback=self.on_setting, data='GEO_PREVIEW_PROVIDER',
props={'items': geo_providers, desc=_('Service used for map previews'),
'plugin': self.plugin}), props={'combo_items': geo_providers}),
Option(OptionKind.SWITCH, _('Enable HTTPS Verification'), Setting(SettingKind.SWITCH, _('HTTPS Verification'),
OptionType.VALUE, self.plugin.config['VERIFY'], SettingType.VALUE, self.plugin.config['VERIFY'],
callback=self.on_option, data='VERIFY'), desc=_('Whether to check for a valid certificate'),
callback=self.on_setting, data='VERIFY'),
] ]
OptionsDialog.__init__(self, parent, _('UrlImagePreview Options'), SettingsDialog.__init__(self, parent, _('UrlImagePreview Configuration'),
Gtk.DialogFlags.MODAL, options, None, Gtk.DialogFlags.MODAL, settings, None,
extend=[ extend=[
('PreviewComboOption', ComboOption), ('PreviewSizeSpinSetting', SizeSpinSetting)])
('PreviewSizeSpinOption', SizeSpinOption)])
def on_option(self, value, data): def on_setting(self, value, data):
self.plugin.config[data] = value self.plugin.config[data] = value
class SizeSpinOption(SpinOption): class SizeSpinSetting(SpinSetting):
__gproperties__ = { __gproperties__ = {
"option-value": (int, 'Size', '', 100, 1000, 300, "setting-value": (int, 'Size', '', 100, 1000, 300,
GObject.ParamFlags.READWRITE), } GObject.ParamFlags.READWRITE), }
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
SpinOption.__init__(self, *args, **kwargs) SpinSetting.__init__(self, *args, **kwargs)
class ComboOption(GenericOption):
__gproperties__ = {
"option-value": (str, 'Value', '', '',
GObject.ParamFlags.READWRITE), }
def __init__(self, *args, items, plugin):
GenericOption.__init__(self, *args)
self.plugin = plugin
self.combo = Gtk.ComboBox()
text_renderer = Gtk.CellRendererText()
self.combo.pack_start(text_renderer, True)
self.combo.add_attribute(text_renderer, 'text', 0)
self.store = Gtk.ListStore(str, str)
for item in items:
self.store.append(item)
self.combo.set_model(self.store)
self.combo.set_id_column(1)
self.combo.set_active_id(str(self.option_value))
self.combo.connect('changed', self.on_value_change)
self.combo.set_valign(Gtk.Align.CENTER)
self.option_box.pack_start(self.combo, True, True, 0)
self.show_all()
def on_value_change(self, combo):
self.set_value(combo.get_active_id())
def on_row_activated(self):
pass