From c5065c398ca2d0aa4e0ed35adf7ad8f93fcae2ca Mon Sep 17 00:00:00 2001 From: Stanislav Malishevskiy Date: Wed, 3 Apr 2024 15:40:15 +0300 Subject: [PATCH] Change password inputs. --- .../manage_accounts/change_password_dialog.ui | 206 +++++------------- main/data/manage_accounts/dialog.ui | 2 +- .../change_password_dialog.vala | 69 +++--- main/src/ui/manage_accounts/dialog.vala | 20 +- 4 files changed, 96 insertions(+), 201 deletions(-) diff --git a/main/data/manage_accounts/change_password_dialog.ui b/main/data/manage_accounts/change_password_dialog.ui index 67e1ce6a..611528cb 100644 --- a/main/data/manage_accounts/change_password_dialog.ui +++ b/main/data/manage_accounts/change_password_dialog.ui @@ -2,157 +2,61 @@ diff --git a/main/data/manage_accounts/dialog.ui b/main/data/manage_accounts/dialog.ui index 0a76c361..8ee434cc 100644 --- a/main/data/manage_accounts/dialog.ui +++ b/main/data/manage_accounts/dialog.ui @@ -170,7 +170,7 @@ - + ⚙️ 2 diff --git a/main/src/ui/manage_accounts/change_password_dialog.vala b/main/src/ui/manage_accounts/change_password_dialog.vala index 126a174a..12c64757 100644 --- a/main/src/ui/manage_accounts/change_password_dialog.vala +++ b/main/src/ui/manage_accounts/change_password_dialog.vala @@ -11,14 +11,13 @@ namespace Dino.Ui{ public class ChangePasswordDialog : Gtk.Dialog { [GtkChild] private unowned Button change_password_button; - [GtkChild] private unowned Stack change_password_stack; + /*[GtkChild] private unowned Stack change_password_stack; */ [GtkChild] private unowned Button cancel_button; - [GtkChild] private unowned Entry current_passwd_entry; - [GtkChild] private unowned Entry new_passwd_entry; - [GtkChild] private unowned Entry confirm_new_passwd_entry; + [GtkChild] private unowned Adw.PasswordEntryRow current_password_entry; + [GtkChild] private unowned Adw.PasswordEntryRow new_password_entry; + [GtkChild] private unowned Adw.PasswordEntryRow confirm_new_password_entry; [GtkChild] private unowned Label change_password_error_label; - private bool are_forms_empty; private Account account; private StreamInteractor stream_interactor; @@ -28,65 +27,57 @@ namespace Dino.Ui{ this.account = a; Util.force_error_color(change_password_error_label); cancel_button.clicked.connect(() => { close(); }); - current_passwd_entry.changed.connect(on_current_passwd_entry_changed); - new_passwd_entry.changed.connect(on_new_passwd_entry_changed); - confirm_new_passwd_entry.changed.connect(on_confirm_new_passwd_entry_changed); + current_password_entry.changed.connect(on_current_password_entry_changed); + new_password_entry.changed.connect(on_new_password_entry_changed); + confirm_new_password_entry.changed.connect(on_confirm_new_password_entry_changed); change_password_button.clicked.connect(on_change_password_button_clicked); } - private void are_psswd_nonempty(){ - EntryBuffer newpsswd = new_passwd_entry.get_buffer(); - EntryBuffer confirm_newpsswd = confirm_new_passwd_entry.get_buffer(); - - if (current_passwd_entry.get_text_length() > 0 - && new_passwd_entry.get_text_length() > 0 - && confirm_new_passwd_entry.get_text_length() > 0 - && newpsswd.get_text() == confirm_newpsswd.get_text()){ - are_forms_empty = false; + private void is_form_filled(){ + if (current_password_entry.get_text().length > 0 + && new_password_entry.get_text().length > 0 + && confirm_new_password_entry.get_text().length > 0 + && new_password_entry.get_text() == confirm_new_password_entry.get_text()){ change_password_button.sensitive = true; } else { - are_forms_empty = true; change_password_button.sensitive = false; } } - private void check_new_passwd(){ - EntryBuffer newpsswd = new_passwd_entry.get_buffer(); - EntryBuffer confirm_newpsswd = confirm_new_passwd_entry.get_buffer(); - - if (newpsswd.get_text() != confirm_newpsswd.get_text()){ - new_passwd_entry.add_css_class("error"); - confirm_new_passwd_entry.add_css_class("error"); + private void check_new_password(){ + if (new_password_entry.get_text() != confirm_new_password_entry.get_text()){ + new_password_entry.add_css_class("error"); + confirm_new_password_entry.add_css_class("error"); } else { - new_passwd_entry.remove_css_class("error"); - confirm_new_passwd_entry.remove_css_class("error"); + new_password_entry.remove_css_class("error"); + confirm_new_password_entry.remove_css_class("error"); } } - private void on_current_passwd_entry_changed(){ - are_psswd_nonempty(); + private void on_current_password_entry_changed(){ + is_form_filled(); } - private void on_new_passwd_entry_changed(){ - are_psswd_nonempty(); - check_new_passwd(); + private void on_new_password_entry_changed(){ + is_form_filled(); + check_new_password(); } - private void on_confirm_new_passwd_entry_changed(){ - are_psswd_nonempty(); - check_new_passwd(); + private void on_confirm_new_password_entry_changed(){ + is_form_filled(); + check_new_password(); } private async void on_change_password_button_clicked(){ - string? pw_input = current_passwd_entry.get_buffer().get_text(); - string? new_pw_input = new_passwd_entry.get_buffer().get_text(); + string? pw_input = current_password_entry.get_text(); + string? new_pw_input = new_password_entry.get_text(); if (pw_input != null && account.password == pw_input){ change_password_button.sensitive = false; - change_password_stack.visible_child_name = "spinner"; + // change_password_stack.visible_child_name = "spinner"; string ret = yield stream_interactor.get_module(Register.IDENTITY).change_password(account, new_pw_input); change_password_button.sensitive = true; - change_password_stack.visible_child_name = "label"; + // change_password_stack.visible_child_name = "label"; if (ret == null) { account.password = new_pw_input; close(); diff --git a/main/src/ui/manage_accounts/dialog.vala b/main/src/ui/manage_accounts/dialog.vala index 365d4c3c..2fa5cc31 100644 --- a/main/src/ui/manage_accounts/dialog.vala +++ b/main/src/ui/manage_accounts/dialog.vala @@ -25,7 +25,7 @@ public class Dialog : Gtk.Dialog { [GtkChild] public unowned Label state_label; [GtkChild] public unowned Switch active_switch; [GtkChild] public unowned Util.EntryLabelHybrid password_hybrid; - [GtkChild] public unowned Button password_change_btn; + [GtkChild] public unowned Button password_change_button; [GtkChild] public unowned Util.EntryLabelHybrid alias_hybrid; [GtkChild] public unowned Grid settings_list; @@ -45,12 +45,12 @@ public class Dialog : Gtk.Dialog { image_button.clicked.connect(show_select_avatar); alias_hybrid.entry.changed.connect(() => { selected_account.alias = alias_hybrid.text; }); password_hybrid.entry.changed.connect(() => { selected_account.password = password_hybrid.text; }); - password_change_btn.clicked.connect(show_change_psswd_dialog); + password_change_button.clicked.connect(show_change_password_dialog); Util.LabelHybridGroup label_hybrid_group = new Util.LabelHybridGroup(); label_hybrid_group.add(alias_hybrid); label_hybrid_group.add(password_hybrid); - password_change_btn.sensitive = false; + password_change_button.sensitive = false; main_stack.set_visible_child_name("no_accounts"); @@ -112,10 +112,10 @@ public class Dialog : Gtk.Dialog { add_account_dialog.present(); } - private void show_change_psswd_dialog() { - ChangePasswordDialog change_psswd_dialog = new ChangePasswordDialog(selected_account, stream_interactor); - change_psswd_dialog.set_transient_for(this); - change_psswd_dialog.present(); + private void show_change_password_dialog() { + ChangePasswordDialog change_password_dialog = new ChangePasswordDialog(selected_account, stream_interactor); + change_password_dialog.set_transient_for(this); + change_password_dialog.present(); } // private void remove_account(AccountRow account_item) { @@ -224,10 +224,10 @@ public class Dialog : Gtk.Dialog { case ConnectionManager.ConnectionState.CONNECTING: state_label.label = _("Connecting…"); break; case ConnectionManager.ConnectionState.CONNECTED: - password_change_btn.sensitive = true; + password_change_button.sensitive = true; state_label.label = _("Connected"); break; case ConnectionManager.ConnectionState.DISCONNECTED: - password_change_btn.sensitive = false; + password_change_button.sensitive = false; state_label.label = _("Disconnected"); break; } state_label.remove_css_class("is_error"); @@ -235,7 +235,7 @@ public class Dialog : Gtk.Dialog { } private string get_connection_error_description(ConnectionManager.ConnectionError error) { - password_change_btn.sensitive = false; + password_change_button.sensitive = false; switch (error.source) { case ConnectionManager.ConnectionError.Source.SASL: return _("Wrong password");