Skip to content
Snippets Groups Projects
Commit 47a2dd56 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Settings: Allow bind to all setting types

parent d8e6a6e4
No related branches found
No related tags found
No related merge requests found
......@@ -610,7 +610,7 @@ def __init__(self, account):
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 @@ def __init__(self, account, parent):
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 @@ def __init__(self, account, parent):
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 @@ def __init__(self, account, parent):
settings = [
Setting(SettingKind.ENTRY, _('Password'),
SettingType.ACCOUNT_CONFIG, 'password',
bind='savepass'),
bind='account::savepass'),
Setting(SettingKind.SWITCH, _('Save Password'),
SettingType.ACCOUNT_CONFIG, 'savepass'),
......
......@@ -209,30 +209,46 @@ def _bind_sensitive_state(self):
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.type_ == SettingType.CONTACT:
value = app.settings.get_contact_setting(
self.account, self.jid, self.bind)
if bind_setting_type == SettingType.CONTACT:
value = app.settings.get_contact_setting(account, jid, setting)
elif self.type_ == SettingType.GROUP_CHAT:
value = app.settings.get_group_chat_setting(
self.account, self.jid, self.bind)
elif bind_setting_type == SettingType.GROUP_CHAT:
value = app.settings.get_group_chat_setting(account, jid, setting)
elif self.type_ == SettingType.ACCOUNT_CONFIG:
value = app.settings.get_account_setting(self.account, self.bind)
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,
......
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