Philipp Hörist pushed to branch master at gajim / gajim
Commits:
94842c27 by lovetox at 2022-05-10T21:12:50+02:00
feat: Plugins: Set error if init fails
- - - - -
aa4d0354 by lovetox at 2022-05-10T21:54:13+02:00
feat: Allow users to override settings
- - - - -
195ec814 by lovetox at 2022-05-10T22:05:07+02:00
feat: Plugins: Allow users to disable plugin repository
- - - - -
a496dbbb by lovetox at 2022-05-10T22:25:03+02:00
feat: Settings: Show lock icon if setting has an override
- - - - -
5 changed files:
- gajim/common/setting_values.py
- gajim/common/settings.py
- gajim/gtk/settings.py
- gajim/plugins/pluginmanager.py
- gajim/plugins/repository.py
Changes:
=====================================
gajim/common/setting_values.py
=====================================
@@ -105,6 +105,7 @@ class _ACCOUNT_DEFAULT:
'use_stun_server',
'use_urgency_hint',
'video_see_self',
+ 'plugins_repository_enabled',
'plugins_update_check',
'plugins_auto_update',
'plugins_notify_after_update',
@@ -297,6 +298,7 @@ class _ACCOUNT_DEFAULT:
'preview_leftclick_action': 'open',
'preview_verify_https': True,
'preview_anonymous_muc': False,
+ 'plugins_repository_enabled': True,
'plugins_update_check': True,
'plugins_auto_update': False,
'plugins_notify_after_update': True,
=====================================
gajim/common/settings.py
=====================================
@@ -106,6 +106,8 @@
_CallbackDict = dict[tuple[str, Optional[str], Optional[JID]],
list[weakref.WeakMethod[_SignalCallable]]]
+OVERRIDES_PATH = Path('/etc/gajim/app-overrides.json')
+
class Settings:
def __init__(self):
@@ -113,6 +115,7 @@ def __init__(self):
self._commit_scheduled = None
self._settings = {}
+ self._app_overrides: dict[str, AllSettingsT] = {}
self._account_settings = {}
self._callbacks: _CallbackDict = defaultdict(list)
@@ -206,6 +209,7 @@ def init(self) -> None:
self._migrate_old_config()
self._commit()
self._migrate_database()
+ self._load_app_overrides()
@staticmethod
def _setup_installation_defaults() -> None:
@@ -217,6 +221,19 @@ def _setup_installation_defaults() -> None:
# Windows and MacOS
APP_SETTINGS['dev_use_message_label'] = False
+ def _load_app_overrides(self) -> None:
+ if not OVERRIDES_PATH.exists():
+ return
+
+ with OVERRIDES_PATH.open() as f:
+ try:
+ self._app_overrides = json.load(f)
+ except Exception:
+ log.exception('Failed to load overrides')
+ return
+
+ self._settings['app'].update(self._app_overrides)
+
@staticmethod
def _namedtuple_factory(cursor: sqlite3.Cursor,
row: tuple[Any, ...]) -> NamedTuple:
@@ -517,6 +534,9 @@ def _commit_settings(self, name: str, schedule: bool =
True) -> None:
self._commit(schedule=schedule)
+ def has_app_override(self, setting: str) -> bool:
+ return setting in self._app_overrides
+
@overload
def get_app_setting(self, setting: BoolSettings) -> bool: ...
@overload
@@ -544,6 +564,11 @@ def set_app_setting(self, setting: str, value:
Optional[AllSettingsT]) -> None:
if setting not in APP_SETTINGS:
raise ValueError(f'Invalid app setting: {setting}')
+ if setting in self._app_overrides:
+ log.warning('Changing %s is not allowed because there exists an '
+ 'override', setting)
+ return
+
default = APP_SETTINGS[setting]
if not isinstance(value, type(default)) and value is not None:
raise TypeError(f'Invalid type for {setting}: '
=====================================
gajim/gtk/settings.py
=====================================
@@ -204,6 +204,16 @@ def __init__(self,
self.enabled_func = enabled_func
self.setting_value = self.get_value()
+ self._locked_icon = Gtk.Image.new_from_icon_name(
+ 'feather-lock-symbolic',
+ Gtk.IconSize.MENU)
+ self._locked_icon.set_visible(False)
+ self._locked_icon.set_no_show_all(True)
+ self._locked_icon.set_halign(Gtk.Align.END)
+ self._locked_icon.set_tooltip_text(_('Setting is locked by the
system'))
+
+ self._grid.add(self._locked_icon)
+
description_box = Gtk.Box(
orientation=Gtk.Orientation.VERTICAL, spacing=0)
description_box.set_valign(Gtk.Align.CENTER)
@@ -372,6 +382,13 @@ def on_row_activated(self) -> None:
raise NotImplementedError
def update_activatable(self) -> None:
+ if self.type_ == SettingType.CONFIG:
+ if app.settings.has_app_override(self.value):
+ self.set_activatable(False)
+ self.set_sensitive(False)
+ self._locked_icon.show()
+ return
+
if self.enabled_func is None:
return
=====================================
gajim/plugins/pluginmanager.py
=====================================
@@ -284,8 +284,9 @@ def init_plugins(self) -> None:
try:
self.activate_plugin(plugin)
- except GajimPluginActivateException:
- pass
+ except GajimPluginActivateException as error:
+ plugin.activatable = False
+ plugin.available_text = str(error)
def _load_plugin_module(self,
manifest: PluginManifest
=====================================
gajim/plugins/repository.py
=====================================
@@ -59,8 +59,9 @@ def __init__(self) -> None:
self._download_queue: set[PluginManifest] = set()
- make_http_request('https://gajim.org/updates.json',
- self._on_repository_received)
+ if app.settings.get('plugins_repository_enabled'):
+ make_http_request('https://gajim.org/updates.json',
+ self._on_repository_received)
@property
def available(self):
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/3dd59364b924b58f5a4c077ebe5199bdb2641d87...a496dbbbbfccadef03f01043c8dffcba57f9e6ec
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/3dd59364b924b58f5a4c077ebe5199bdb2641d87...a496dbbbbfccadef03f01043c8dffcba57f9e6ec
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits