Philipp Hörist pushed to branch master at gajim / gajim
Commits: a3d92681 by lovetox at 2020-09-07T15:01:16+02:00 Settings: Add action button to Popover and Switch settings
- - - - - 2e1252c4 by lovetox at 2020-09-07T15:01:16+02:00 Accounts: Replace ProxyComboSetting with PopoverSetting
- - - - -
3 changed files:
- gajim/gtk/accounts.py - gajim/gtk/const.py - gajim/gtk/settings.py
Changes:
===================================== gajim/gtk/accounts.py ===================================== @@ -212,7 +212,7 @@ class Settings(Gtk.ScrolledWindow): for page in self._pages[account]: if page.name != 'connection': continue - page.listbox.get_setting('proxy').update_values() + page.update_proxy_entries()
class AccountMenu(Gtk.Box): @@ -690,8 +690,11 @@ class ConnectionPage(GenericSettingPage): def __init__(self, account):
settings = [ - Setting(SettingKind.PROXY, _('Proxy'), - SettingType.ACCOUNT_CONFIG, 'proxy', name='proxy'), + Setting(SettingKind.POPOVER, _('Proxy'), + SettingType.ACCOUNT_CONFIG, 'proxy', name='proxy', + props={'entries': self._get_proxies(), + 'button-icon-name': 'preferences-system-symbolic', + 'button-callback': self._on_proxy_edit}),
Setting(SettingKind.HOSTNAME, _('Hostname'), SettingType.DIALOG, desc=_('Manually set the hostname for the server'), @@ -715,6 +718,20 @@ class ConnectionPage(GenericSettingPage): ] GenericSettingPage.__init__(self, account, settings)
+ @staticmethod + def _get_proxies(): + proxies = {'': _('No Proxy')} + for proxy in app.settings.get_proxies(): + proxies[proxy] = proxy + return proxies + + @staticmethod + def _on_proxy_edit(*args): + open_window('ManageProxies') + + def update_proxy_entries(self): + self.listbox.get_setting('proxy').update_entries(self._get_proxies()) +
class AdvancedPage(GenericSettingPage):
===================================== gajim/gtk/const.py ===================================== @@ -51,7 +51,6 @@ class SettingKind(IntEnum): LOGIN = 4 DIALOG = 5 CALLBACK = 6 - PROXY = 7 HOSTNAME = 8 PRIORITY = 9 FILECHOOSER = 10
===================================== gajim/gtk/settings.py ===================================== @@ -88,7 +88,6 @@ class SettingsBox(Gtk.ListBox): SettingKind.LOGIN: LoginSetting, SettingKind.FILECHOOSER: FileChooserSetting, SettingKind.CALLBACK: CallbackSetting, - SettingKind.PROXY: ProxyComboSetting, SettingKind.PRIORITY: PrioritySetting, SettingKind.HOSTNAME: CutstomHostnameSetting, SettingKind.CHANGEPASSWORD: ChangePasswordSetting, @@ -277,13 +276,22 @@ class GenericSetting(Gtk.ListBoxRow): self.set_activatable(enabled_func_value) self.set_sensitive(enabled_func_value)
+ def _add_action_button(self, kwargs): + icon_name = kwargs.get('button-icon-name') + if icon_name is None: + return + + button = Gtk.Button.new_from_icon_name(icon_name, Gtk.IconSize.MENU) + button.connect('clicked', kwargs['button-callback']) + self.setting_box.add(button) + def _on_destroy(self, *args): if self.bind is not None: app.settings.disconnect_signals(self)
class SwitchSetting(GenericSetting): - def __init__(self, *args): + def __init__(self, *args, **kwargs): GenericSetting.__init__(self, *args)
self.switch = Gtk.Switch() @@ -309,6 +317,8 @@ class SwitchSetting(GenericSetting): box.add(self.switch) self.setting_box.add(box)
+ self._add_action_button(kwargs) + self.show_all()
def on_row_activated(self): @@ -521,7 +531,7 @@ class LoginSetting(DialogSetting):
class PopoverSetting(GenericSetting): - def __init__(self, *args, entries): + def __init__(self, *args, entries, **kwargs): GenericSetting.__init__(self, *args)
if isinstance(entries, list): @@ -530,6 +540,7 @@ class PopoverSetting(GenericSetting): box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=12) box.set_halign(Gtk.Align.END) + box.set_hexpand(True)
self._current_label = Gtk.Label() self._current_label.set_valign(Gtk.Align.CENTER) @@ -561,7 +572,9 @@ class PopoverSetting(GenericSetting): self._popover.set_position(Gtk.PositionType.BOTTOM) self._popover.add(scrolled_window)
- self.setting_box.pack_end(box, True, True, 0) + self.setting_box.add(box) + + self._add_action_button(kwargs)
self._current_label.set_text(entries.get(self.setting_value, ''))
@@ -640,56 +653,6 @@ class ComboSetting(GenericSetting): pass
-class ProxyComboSetting(GenericSetting): - def __init__(self, *args): - GenericSetting.__init__(self, *args) - - self.combo = MaxWidthComboBoxText() - self.combo.set_valign(Gtk.Align.CENTER) - - self._signal_id = None - self.update_values() - - button = get_image_button( - 'preferences-system-symbolic', _('Manage Proxies')) - button.set_action_name('app.manage-proxies') - button.set_valign(Gtk.Align.CENTER) - - self.setting_box.pack_start(self.combo, True, True, 0) - self.setting_box.pack_start(button, False, True, 0) - self.show_all() - - def _block_signal(self, state): - if state: - if self._signal_id is None: - return - self.combo.disconnect(self._signal_id) - else: - self._signal_id = self.combo.connect('changed', - self.on_value_change) - self.combo.emit('changed') - - def update_values(self): - self._block_signal(True) - proxies = app.settings.get_proxies() - proxies.insert(0, _('No Proxy')) - self.combo.remove_all() - for index, value in enumerate(proxies): - self.combo.insert_text(-1, value) - if value == self.setting_value or index == 0: - self.combo.set_active(index) - self._block_signal(False) - - def on_value_change(self, combo): - if combo.get_active() == 0: - self.set_value('') - else: - self.set_value(combo.get_active_text()) - - def on_row_activated(self): - pass - - class PrioritySetting(DialogSetting): def __init__(self, *args, **kwargs): DialogSetting.__init__(self, *args, **kwargs)
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/c92c369a698b18aa6509e122058e0cd5...