Philipp Hörist pushed to branch master at gajim / gajim

Commits:

3 changed files:

Changes:

  • gajim/gtk/accounts.py
    ... ... @@ -610,7 +610,7 @@ class GeneralPage(GenericSettingPage):
    610 610
                         desc=_('Recognize your account by color')),
    
    611 611
     
    
    612 612
                 Setting(SettingKind.LOGIN, _('Login'), SettingType.DIALOG,
    
    613
    -                    bind='anonymous_auth',
    
    613
    +                    bind='account::anonymous_auth',
    
    614 614
                         inverted=True,
    
    615 615
                         props={'dialog': LoginDialog}),
    
    616 616
     
    
    ... ... @@ -863,7 +863,7 @@ class PriorityDialog(SettingsDialog):
    863 863
                 Setting(SettingKind.SPIN, _('Priority'),
    
    864 864
                         SettingType.ACCOUNT_CONFIG,
    
    865 865
                         'priority',
    
    866
    -                    bind='adjust_priority_with_status',
    
    866
    +                    bind='account::adjust_priority_with_status',
    
    867 867
                         inverted=True,
    
    868 868
                         props={'range_': range_}),
    
    869 869
                 ]
    
    ... ... @@ -894,15 +894,15 @@ class CutstomHostnameDialog(SettingsDialog):
    894 894
     
    
    895 895
                 Setting(SettingKind.ENTRY, _('Hostname'),
    
    896 896
                         SettingType.ACCOUNT_CONFIG, 'custom_host',
    
    897
    -                    bind='use_custom_host'),
    
    897
    +                    bind='account::use_custom_host'),
    
    898 898
     
    
    899 899
                 Setting(SettingKind.ENTRY, _('Port'),
    
    900 900
                         SettingType.ACCOUNT_CONFIG, 'custom_port',
    
    901
    -                    bind='use_custom_host'),
    
    901
    +                    bind='account::use_custom_host'),
    
    902 902
     
    
    903 903
                 Setting(SettingKind.COMBO, _('Type'),
    
    904 904
                         SettingType.ACCOUNT_CONFIG, 'custom_type',
    
    905
    -                    bind='use_custom_host',
    
    905
    +                    bind='account::use_custom_host',
    
    906 906
                         props={'combo_items': type_values}),
    
    907 907
                 ]
    
    908 908
     
    
    ... ... @@ -932,7 +932,7 @@ class LoginDialog(SettingsDialog):
    932 932
             settings = [
    
    933 933
                 Setting(SettingKind.ENTRY, _('Password'),
    
    934 934
                         SettingType.ACCOUNT_CONFIG, 'password',
    
    935
    -                    bind='savepass'),
    
    935
    +                    bind='account::savepass'),
    
    936 936
     
    
    937 937
                 Setting(SettingKind.SWITCH, _('Save Password'),
    
    938 938
                         SettingType.ACCOUNT_CONFIG, 'savepass'),
    

  • gajim/gtk/const.py
    ... ... @@ -65,11 +65,13 @@ class SettingKind(IntEnum):
    65 65
     
    
    66 66
     @unique
    
    67 67
     class SettingType(IntEnum):
    
    68
    -    ACCOUNT_CONFIG = 0
    
    69
    -    CONFIG = 1
    
    70
    -    VALUE = 2
    
    71
    -    ACTION = 3
    
    72
    -    DIALOG = 4
    
    68
    +    CONFIG = 0
    
    69
    +    ACCOUNT_CONFIG = 1
    
    70
    +    CONTACT = 2
    
    71
    +    GROUP_CHAT = 3
    
    72
    +    VALUE = 4
    
    73
    +    ACTION = 5
    
    74
    +    DIALOG = 6
    
    73 75
     
    
    74 76
     
    
    75 77
     class ControlType(Enum):
    

  • gajim/gtk/settings.py
    ... ... @@ -73,10 +73,12 @@ class SettingsDialog(Gtk.ApplicationWindow):
    73 73
     
    
    74 74
     
    
    75 75
     class SettingsBox(Gtk.ListBox):
    
    76
    -    def __init__(self, account, extend=None):
    
    76
    +    def __init__(self, account=None, jid=None, context=None, extend=None):
    
    77 77
             Gtk.ListBox.__init__(self)
    
    78 78
             self.get_style_context().add_class('settings-box')
    
    79 79
             self.account = account
    
    80
    +        self.jid = jid
    
    81
    +        self.context = context
    
    80 82
             self.named_settings = {}
    
    81 83
     
    
    82 84
             self.map = {
    
    ... ... @@ -112,10 +114,16 @@ class SettingsBox(Gtk.ListBox):
    112 114
         def add_setting(self, setting):
    
    113 115
             if not isinstance(setting, Gtk.ListBoxRow):
    
    114 116
                 if setting.props is not None:
    
    115
    -                listitem = self.map[setting.kind](
    
    116
    -                    self.account, *setting[1:-1], **setting.props)
    
    117
    +                listitem = self.map[setting.kind](self.account,
    
    118
    +                                                  self.jid,
    
    119
    +                                                  self.context,
    
    120
    +                                                  *setting[1:-1],
    
    121
    +                                                  **setting.props)
    
    117 122
                 else:
    
    118
    -                listitem = self.map[setting.kind](self.account, *setting[1:-1])
    
    123
    +                listitem = self.map[setting.kind](self.account,
    
    124
    +                                                  self.jid,
    
    125
    +                                                  self.context,
    
    126
    +                                                  *setting[1:-1])
    
    119 127
     
    
    120 128
             if setting.name is not None:
    
    121 129
                 self.named_settings[setting.name] = listitem
    
    ... ... @@ -132,6 +140,8 @@ class SettingsBox(Gtk.ListBox):
    132 140
     class GenericSetting(Gtk.ListBoxRow):
    
    133 141
         def __init__(self,
    
    134 142
                      account,
    
    143
    +                 jid,
    
    144
    +                 context,
    
    135 145
                      label,
    
    136 146
                      type_,
    
    137 147
                      value,
    
    ... ... @@ -153,6 +163,8 @@ class GenericSetting(Gtk.ListBoxRow):
    153 163
             self.data = data
    
    154 164
             self.label = label
    
    155 165
             self.account = account
    
    166
    +        self.jid = jid
    
    167
    +        self.context = context
    
    156 168
             self.name = name
    
    157 169
             self.bind = bind
    
    158 170
             self.inverted = inverted
    
    ... ... @@ -197,31 +209,67 @@ class GenericSetting(Gtk.ListBoxRow):
    197 209
             if self.bind is None:
    
    198 210
                 return
    
    199 211
     
    
    200
    -        app.settings.bind_signal(self.bind,
    
    212
    +        bind_setting_type, setting, account, jid = self._parse_bind()
    
    213
    +
    
    214
    +        app.settings.bind_signal(setting,
    
    201 215
                                      self,
    
    202 216
                                      'set_sensitive',
    
    203
    -                                 account=self.account,
    
    217
    +                                 account=account,
    
    218
    +                                 jid=jid,
    
    204 219
                                      inverted=self.inverted)
    
    205 220
     
    
    206
    -        if self.account is not None:
    
    207
    -            value = app.settings.get_account_setting(self.account, self.bind)
    
    221
    +        if bind_setting_type == SettingType.CONTACT:
    
    222
    +            value = app.settings.get_contact_setting(account, jid, setting)
    
    223
    +
    
    224
    +        elif bind_setting_type == SettingType.GROUP_CHAT:
    
    225
    +            value = app.settings.get_group_chat_setting(account, jid, setting)
    
    226
    +
    
    227
    +        elif bind_setting_type == SettingType.ACCOUNT_CONFIG:
    
    228
    +            value = app.settings.get_account_setting(account, setting)
    
    229
    +
    
    208 230
             else:
    
    209
    -            value = app.settings.get(self.bind)
    
    231
    +            value = app.settings.get(setting)
    
    210 232
     
    
    211 233
             if self.inverted:
    
    212 234
                 value = not value
    
    213 235
             self.set_sensitive(value)
    
    214 236
     
    
    237
    +    def _parse_bind(self):
    
    238
    +        if '::' not in self.bind:
    
    239
    +            return SettingType.CONFIG, self.bind, None, None
    
    240
    +
    
    241
    +        bind_setting_type, setting = self.bind.split('::')
    
    242
    +        if bind_setting_type == 'account':
    
    243
    +            return SettingType.ACCOUNT_CONFIG, setting, self.account, None
    
    244
    +
    
    245
    +        if bind_setting_type == 'contact':
    
    246
    +            return SettingType.CONTACT, setting, self.account, self.jid
    
    247
    +
    
    248
    +        if bind_setting_type == 'group_chat':
    
    249
    +            return SettingType.GROUP_CHAT, setting, self.account, self.jid
    
    250
    +        raise ValueError(f'Invalid bind argument: {self.bind}')
    
    251
    +
    
    215 252
         def get_value(self):
    
    216
    -        return self.__get_value(self.type_, self.value, self.account)
    
    253
    +        return self.__get_value(self.type_,
    
    254
    +                                self.value,
    
    255
    +                                self.account,
    
    256
    +                                self.jid,
    
    257
    +                                self.context)
    
    217 258
     
    
    218 259
         @staticmethod
    
    219
    -    def __get_value(type_, value, account):
    
    260
    +    def __get_value(type_, value, account, jid, context):
    
    220 261
             if value is None:
    
    221 262
                 return None
    
    222 263
             if type_ == SettingType.VALUE:
    
    223 264
                 return value
    
    224 265
     
    
    266
    +        if type_ == SettingType.CONTACT:
    
    267
    +            return app.settings.get_contact_setting(account, jid, value)
    
    268
    +
    
    269
    +        if type_ == SettingType.GROUP_CHAT:
    
    270
    +            value = app.settings.get_group_chat_setting(
    
    271
    +                account, jid, value, context)
    
    272
    +
    
    225 273
             if type_ == SettingType.CONFIG:
    
    226 274
                 return app.settings.get(value)
    
    227 275
     
    
    ... ... @@ -244,7 +292,8 @@ class GenericSetting(Gtk.ListBoxRow):
    244 292
         def set_value(self, state):
    
    245 293
             if self.type_ == SettingType.CONFIG:
    
    246 294
                 app.settings.set(self.value, state)
    
    247
    -        if self.type_ == SettingType.ACCOUNT_CONFIG:
    
    295
    +
    
    296
    +        elif self.type_ == SettingType.ACCOUNT_CONFIG:
    
    248 297
                 if self.value == 'password':
    
    249 298
                     passwords.save_password(self.account, state)
    
    250 299
                 if self.value == 'no_log_for':
    
    ... ... @@ -254,6 +303,14 @@ class GenericSetting(Gtk.ListBoxRow):
    254 303
                                                      self.value,
    
    255 304
                                                      state)
    
    256 305
     
    
    306
    +        elif self.type_ == SettingType.CONTACT:
    
    307
    +            app.settings.set_contact_setting(
    
    308
    +                self.account, self.jid, self.value, state)
    
    309
    +
    
    310
    +        elif self.type_ == SettingType.GROUP_CHAT:
    
    311
    +            app.settings.set_group_chat_setting(
    
    312
    +                self.account, self.jid, self.value, state, self.context)
    
    313
    +
    
    257 314
             if self.callback is not None:
    
    258 315
                 self.callback(state, self.data)
    
    259 316