diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/src/windows/preferences_window/account_preferences_subpage.vala | 8 | ||||
-rw-r--r-- | main/src/windows/preferences_window/encryption_preferences_page.vala | 58 |
2 files changed, 43 insertions, 23 deletions
diff --git a/main/src/windows/preferences_window/account_preferences_subpage.vala b/main/src/windows/preferences_window/account_preferences_subpage.vala index 01cf5584..a1966e34 100644 --- a/main/src/windows/preferences_window/account_preferences_subpage.vala +++ b/main/src/windows/preferences_window/account_preferences_subpage.vala @@ -123,8 +123,14 @@ public class Dino.Ui.AccountPreferencesSubpage : Gtk.Box { return true; }); + // Only show avatar removal button if an avatar is set + var avatar_model = model.selected_account.avatar_model.tiles.get_item(0) as ViewModel.AvatarPictureTileModel; + avatar_model.notify["image-file"].connect(() => { + remove_avatar_button.visible = avatar_model.image_file != null; + }); + remove_avatar_button.visible = avatar_model.image_file != null; + model.selected_account.notify["connection-error"].connect(() => { - // TODO doesn't work if (model.selected_account.connection_error != null) { connection_status.add_css_class("error"); } else { diff --git a/main/src/windows/preferences_window/encryption_preferences_page.vala b/main/src/windows/preferences_window/encryption_preferences_page.vala index 2222584d..7477e6cd 100644 --- a/main/src/windows/preferences_window/encryption_preferences_page.vala +++ b/main/src/windows/preferences_window/encryption_preferences_page.vala @@ -18,36 +18,50 @@ public class Dino.Ui.PreferencesWindowEncryption : Adw.PreferencesPage { this.notify["model"].connect(() => { this.model.update.connect(() => { - if (drop_down != null) { - accounts_group.remove(drop_down); - drop_down = null; - } - - if (model.active_accounts_selection.get_n_items() > 0) { - drop_down = new DropDown(model.active_accounts_selection, null) { halign=Align.CENTER }; - drop_down.factory = new BuilderListItemFactory.from_resource(null, "/im/dino/Dino/account_picker_row.ui"); - - drop_down.notify["selected-item"].connect(() => { - var account_details = (ViewModel.AccountDetails) drop_down.selected_item; - if (account_details == null) return; - set_account(account_details.account); - }); - - drop_down.selected = 0; - set_account(((ViewModel.AccountDetails)model.active_accounts_selection.get_item(0)).account); - } else { - drop_down = new DropDown.from_strings(new string[] { _("No active accounts")}) { halign=Align.CENTER }; - } - accounts_group.add(drop_down); + repopulate_account_selector(); }); }); } - public void set_account(Account account) { + private void repopulate_account_selector() { + // Remove current selector + if (drop_down != null) { + accounts_group.remove(drop_down); + drop_down = null; + } + + // Don't show selector if the user has only one account (active + inactive) + accounts_group.visible = model.account_details.size != 1; + + // Populate selector + if (model.active_accounts_selection.get_n_items() > 0) { + drop_down = new DropDown(model.active_accounts_selection, null) { halign=Align.CENTER }; + drop_down.factory = new BuilderListItemFactory.from_resource(null, "/im/dino/Dino/account_picker_row.ui"); + + drop_down.notify["selected-item"].connect(() => { + var account_details = (ViewModel.AccountDetails) drop_down.selected_item; + if (account_details == null) return; + set_account(account_details.account); + }); + + drop_down.selected = 0; + set_account(((ViewModel.AccountDetails)model.active_accounts_selection.get_item(0)).account); + } else { + drop_down = new DropDown.from_strings(new string[] { _("No active accounts")}) { halign=Align.CENTER }; + unset_account(); + } + accounts_group.add(drop_down); + } + + private void unset_account() { foreach (var widget in added_widgets) { this.remove(widget); } added_widgets.clear(); + } + + private void set_account(Account account) { + unset_account(); Application app = GLib.Application.get_default() as Application; foreach (Plugins.EncryptionPreferencesEntry e in app.plugin_registry.encryption_preferences_entries) { |