Philipp Hörist pushed to branch master at gajim / gajim
Commits: d8e6a6e4 by lovetox at 2020-09-16T21:30:06+02:00 Settings: Add contact and group chat settings
- - - - - 47a2dd56 by lovetox at 2020-09-16T22:06:08+02:00 Settings: Allow bind to all setting types
- - - - -
3 changed files:
- gajim/gtk/accounts.py - gajim/gtk/const.py - gajim/gtk/settings.py
Changes:
===================================== gajim/gtk/accounts.py ===================================== @@ -610,7 +610,7 @@ class GeneralPage(GenericSettingPage): desc=_('Recognize your account by color')),
Setting(SettingKind.LOGIN, _('Login'), SettingType.DIALOG, - bind='anonymous_auth', + bind='account::anonymous_auth', inverted=True, props={'dialog': LoginDialog}),
@@ -863,7 +863,7 @@ class PriorityDialog(SettingsDialog): Setting(SettingKind.SPIN, _('Priority'), SettingType.ACCOUNT_CONFIG, 'priority', - bind='adjust_priority_with_status', + bind='account::adjust_priority_with_status', inverted=True, props={'range_': range_}), ] @@ -894,15 +894,15 @@ class CutstomHostnameDialog(SettingsDialog):
Setting(SettingKind.ENTRY, _('Hostname'), SettingType.ACCOUNT_CONFIG, 'custom_host', - bind='use_custom_host'), + bind='account::use_custom_host'),
Setting(SettingKind.ENTRY, _('Port'), SettingType.ACCOUNT_CONFIG, 'custom_port', - bind='use_custom_host'), + bind='account::use_custom_host'),
Setting(SettingKind.COMBO, _('Type'), SettingType.ACCOUNT_CONFIG, 'custom_type', - bind='use_custom_host', + bind='account::use_custom_host', props={'combo_items': type_values}), ]
@@ -932,7 +932,7 @@ class LoginDialog(SettingsDialog): settings = [ Setting(SettingKind.ENTRY, _('Password'), SettingType.ACCOUNT_CONFIG, 'password', - bind='savepass'), + bind='account::savepass'),
Setting(SettingKind.SWITCH, _('Save Password'), SettingType.ACCOUNT_CONFIG, 'savepass'),
===================================== gajim/gtk/const.py ===================================== @@ -65,11 +65,13 @@ class SettingKind(IntEnum):
@unique class SettingType(IntEnum): - ACCOUNT_CONFIG = 0 - CONFIG = 1 - VALUE = 2 - ACTION = 3 - DIALOG = 4 + CONFIG = 0 + ACCOUNT_CONFIG = 1 + CONTACT = 2 + GROUP_CHAT = 3 + VALUE = 4 + ACTION = 5 + DIALOG = 6
class ControlType(Enum):
===================================== gajim/gtk/settings.py ===================================== @@ -73,10 +73,12 @@ class SettingsDialog(Gtk.ApplicationWindow):
class SettingsBox(Gtk.ListBox): - def __init__(self, account, extend=None): + def __init__(self, account=None, jid=None, context=None, extend=None): Gtk.ListBox.__init__(self) self.get_style_context().add_class('settings-box') self.account = account + self.jid = jid + self.context = context self.named_settings = {}
self.map = { @@ -112,10 +114,16 @@ class SettingsBox(Gtk.ListBox): def add_setting(self, setting): if not isinstance(setting, Gtk.ListBoxRow): if setting.props is not None: - listitem = self.map[setting.kind]( - self.account, *setting[1:-1], **setting.props) + listitem = self.map[setting.kind](self.account, + self.jid, + self.context, + *setting[1:-1], + **setting.props) else: - listitem = self.map[setting.kind](self.account, *setting[1:-1]) + listitem = self.map[setting.kind](self.account, + self.jid, + self.context, + *setting[1:-1])
if setting.name is not None: self.named_settings[setting.name] = listitem @@ -132,6 +140,8 @@ class SettingsBox(Gtk.ListBox): class GenericSetting(Gtk.ListBoxRow): def __init__(self, account, + jid, + context, label, type_, value, @@ -153,6 +163,8 @@ class GenericSetting(Gtk.ListBoxRow): self.data = data self.label = label self.account = account + self.jid = jid + self.context = context self.name = name self.bind = bind self.inverted = inverted @@ -197,31 +209,67 @@ class GenericSetting(Gtk.ListBoxRow): if self.bind is None: return
- app.settings.bind_signal(self.bind, + bind_setting_type, setting, account, jid = self._parse_bind() + + app.settings.bind_signal(setting, self, 'set_sensitive', - account=self.account, + account=account, + jid=jid, inverted=self.inverted)
- if self.account is not None: - value = app.settings.get_account_setting(self.account, self.bind) + if bind_setting_type == SettingType.CONTACT: + value = app.settings.get_contact_setting(account, jid, setting) + + elif bind_setting_type == SettingType.GROUP_CHAT: + value = app.settings.get_group_chat_setting(account, jid, setting) + + elif bind_setting_type == SettingType.ACCOUNT_CONFIG: + value = app.settings.get_account_setting(account, setting) + else: - value = app.settings.get(self.bind) + value = app.settings.get(setting)
if self.inverted: value = not value self.set_sensitive(value)
+ def _parse_bind(self): + if '::' not in self.bind: + return SettingType.CONFIG, self.bind, None, None + + bind_setting_type, setting = self.bind.split('::') + if bind_setting_type == 'account': + return SettingType.ACCOUNT_CONFIG, setting, self.account, None + + if bind_setting_type == 'contact': + return SettingType.CONTACT, setting, self.account, self.jid + + if bind_setting_type == 'group_chat': + return SettingType.GROUP_CHAT, setting, self.account, self.jid + raise ValueError(f'Invalid bind argument: {self.bind}') + def get_value(self): - return self.__get_value(self.type_, self.value, self.account) + return self.__get_value(self.type_, + self.value, + self.account, + self.jid, + self.context)
@staticmethod - def __get_value(type_, value, account): + def __get_value(type_, value, account, jid, context): if value is None: return None if type_ == SettingType.VALUE: return value
+ if type_ == SettingType.CONTACT: + return app.settings.get_contact_setting(account, jid, value) + + if type_ == SettingType.GROUP_CHAT: + value = app.settings.get_group_chat_setting( + account, jid, value, context) + if type_ == SettingType.CONFIG: return app.settings.get(value)
@@ -244,7 +292,8 @@ class GenericSetting(Gtk.ListBoxRow): def set_value(self, state): if self.type_ == SettingType.CONFIG: app.settings.set(self.value, state) - if self.type_ == SettingType.ACCOUNT_CONFIG: + + elif self.type_ == SettingType.ACCOUNT_CONFIG: if self.value == 'password': passwords.save_password(self.account, state) if self.value == 'no_log_for': @@ -254,6 +303,14 @@ class GenericSetting(Gtk.ListBoxRow): self.value, state)
+ elif self.type_ == SettingType.CONTACT: + app.settings.set_contact_setting( + self.account, self.jid, self.value, state) + + elif self.type_ == SettingType.GROUP_CHAT: + app.settings.set_group_chat_setting( + self.account, self.jid, self.value, state, self.context) + if self.callback is not None: self.callback(state, self.data)
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/ba321d4938db2ab1d1909360abb30c77...