From 01a223138bc1ca6e60d1c6e86c027c4327fd010b Mon Sep 17 00:00:00 2001 From: Kevin Wasserman Date: Mon, 19 May 2014 20:08:08 -0400 Subject: [PATCH] Add 'Update Password' button When pressed, allows user to enter a new password for the current identity. --- src/moonshot-identity-management-view.vala | 29 +++++++++++++++++++- src/moonshot-password-dialog.vala | 44 ++++++++++++++++++++---------- 2 files changed, 57 insertions(+), 16 deletions(-) diff --git a/src/moonshot-identity-management-view.vala b/src/moonshot-identity-management-view.vala index 4eebbda..c5c2a1e 100644 --- a/src/moonshot-identity-management-view.vala +++ b/src/moonshot-identity-management-view.vala @@ -22,6 +22,7 @@ public class IdentityManagerView : Window { private Label prompting_service; private Label no_identity_title; private CheckButton remember_checkbutton; + private Button update_password_button; private ListStore* listmodel; private TreeModelFilter filter; @@ -189,6 +190,28 @@ public class IdentityManagerView : Window { return false; } + private void update_password_cb() + { + if (this.custom_vbox.current_idcard != null) { + var identity = this.custom_vbox.current_idcard.id_card; + var dialog = new AddPasswordDialog(identity, null); + var result = dialog.run (); + + switch (result) { + case ResponseType.OK: + identity.password = dialog.password; + identity.store_password = dialog.remember; + if (dialog.remember) + identity.temporary = false; + identity = identities_manager.update_card(identity); + break; + default: + break; + } + dialog.destroy (); + } + } + private void load_id_cards () { string current_idcard_nai = null; if (this.custom_vbox.current_idcard != null) { @@ -806,11 +829,14 @@ SUCH DAMAGE. password_entry.set_sensitive (false); this.remember_checkbutton = new CheckButton.with_label (_("Remember password")); remember_checkbutton.set_sensitive(false); + this.update_password_button = new Button.with_label (_("Update Pasword")); + this.update_password_button.clicked.connect(update_password_cb); + set_atk_relation (issuer_label, issuer_entry, Atk.RelationType.LABEL_FOR); set_atk_relation (username_label, username_entry, Atk.RelationType.LABEL_FOR); set_atk_relation (password_entry, password_entry, Atk.RelationType.LABEL_FOR); - var login_table = new Table (4, 2, false); + var login_table = new Table (5, 2, false); login_table.set_col_spacings (10); login_table.set_row_spacings (10); login_table.attach_defaults (issuer_label, 0, 1, 0, 1); @@ -820,6 +846,7 @@ SUCH DAMAGE. login_table.attach_defaults (password_label, 0, 1, 2, 3); login_table.attach_defaults (password_entry, 1, 2, 2, 3); login_table.attach_defaults (remember_checkbutton, 1, 2, 3, 4); + login_table.attach_defaults (update_password_button, 0, 1, 4, 5); var login_vbox_alignment = new Alignment (0, 0, 0, 0); login_vbox_alignment.set_padding (0, 0, 12, 0); login_vbox_alignment.add (login_table); diff --git a/src/moonshot-password-dialog.vala b/src/moonshot-password-dialog.vala index 060959d..a5cc9f0 100644 --- a/src/moonshot-password-dialog.vala +++ b/src/moonshot-password-dialog.vala @@ -13,22 +13,30 @@ class AddPasswordDialog : Dialog get { return remember_checkbutton.get_active (); } } - public AddPasswordDialog (IdCard id_card, IdentityRequest request) + public AddPasswordDialog (IdCard id_card, IdentityRequest? request) { this.set_title (_("Please enter password for ") + id_card.display_name); this.set_modal (true); - this.add_buttons (_("Send"), ResponseType.OK, - _("Return to application"), ResponseType.CANCEL); + if (request != null) { + this.add_buttons (_("Send"), ResponseType.OK, + _("Return to application"), ResponseType.CANCEL); + } else { + this.add_buttons (_("Done"), ResponseType.OK, + _("Cancel"), ResponseType.CANCEL); + } this.set_default_response (ResponseType.OK); var content_area = this.get_content_area (); ((Box) content_area).set_spacing (12); - - var service_label = new Label (_("for use with:")); - service_label.set_alignment (1, (float) 0.5); - var service_value = new Label (request.service); - service_value.set_alignment (0, (float) 0.5); + Label service_label = null; + Label service_value = null; + if (request != null) { + service_label = new Label (_("for use with:")); + service_label.set_alignment (1, (float) 0.5); + service_value = new Label (request.service); + service_value.set_alignment (0, (float) 0.5); + } var nai_label = new Label (_("Network Access Identifier:")); nai_label.set_alignment (1, (float) 0.5); @@ -46,15 +54,21 @@ class AddPasswordDialog : Dialog set_atk_relation (password_entry, password_entry, Atk.RelationType.LABEL_FOR); var table = new Table (4, 2, false); + int row = 0; table.set_col_spacings (10); table.set_row_spacings (10); - table.attach_defaults (service_label, 0, 1, 0, 1); - table.attach_defaults (service_value, 1, 2, 0, 1); - table.attach_defaults (nai_label, 0, 1, 1, 2); - table.attach_defaults (nai_value, 1, 2, 1, 2); - table.attach_defaults (password_label, 0, 1, 2, 3); - table.attach_defaults (password_entry, 1, 2, 2, 3); - table.attach_defaults (remember_checkbutton, 1, 2, 3, 4); + if (request != null) { + table.attach_defaults (service_label, 0, 1, row, row + 1); + table.attach_defaults (service_value, 1, 2, row, row + 1); + row++; + } + table.attach_defaults (nai_label, 0, 1, row, row+1); + table.attach_defaults (nai_value, 1, 2, row, row+1); + row++; + table.attach_defaults (password_label, 0, 1, row, row+1); + table.attach_defaults (password_entry, 1, 2, row, row+1); + row++; + table.attach_defaults (remember_checkbutton, 1, 2, row, row+1); var vbox = new VBox (false, 0); vbox.set_border_width (6); -- 2.1.4