From a5a7ae76ecc654e74d22120bf6147507c9dc4a92 Mon Sep 17 00:00:00 2001 From: Kevin Wasserman Date: Mon, 28 Oct 2013 21:46:59 -0400 Subject: [PATCH] update_card() returns modified card replace old card with modified card where appropriate to avoid duplicating ids. --- src/moonshot-idcard-store.vala | 2 +- src/moonshot-identities-manager.vala | 6 ++++-- src/moonshot-identity-management-view.vala | 6 ++++-- src/moonshot-identity-manager-app.vala | 2 +- src/moonshot-identity-request.vala | 2 +- src/moonshot-keyring-store.vala | 6 +++++- src/moonshot-local-flat-file-store.vala | 6 +++++- 7 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/moonshot-idcard-store.vala b/src/moonshot-idcard-store.vala index 4303713..7fa060e 100644 --- a/src/moonshot-idcard-store.vala +++ b/src/moonshot-idcard-store.vala @@ -8,7 +8,7 @@ public interface IIdentityCardStore : Object { public abstract void add_card(IdCard card); public abstract void remove_card(IdCard card); - public abstract void update_card(IdCard card); + public abstract IdCard? update_card(IdCard card); public abstract StoreType get_store_type(); public abstract LinkedList get_card_list(); } diff --git a/src/moonshot-identities-manager.vala b/src/moonshot-identities-manager.vala index 501d065..0c8dfb4 100644 --- a/src/moonshot-identities-manager.vala +++ b/src/moonshot-identities-manager.vala @@ -127,13 +127,15 @@ public class IdentityManagerModel : Object { card_list_changed(); } - public void update_card(IdCard card) { + public IdCard update_card(IdCard card) { + IdCard retval; if (!card.store_password) password_table.CachePassword(card, store); else password_table.RemovePassword(card, store); - store.update_card(card); + retval = store.update_card(card); card_list_changed(); + return retval; } public void remove_card(IdCard card) { diff --git a/src/moonshot-identity-management-view.vala b/src/moonshot-identity-management-view.vala index 7571af0..0b7e283 100644 --- a/src/moonshot-identity-management-view.vala +++ b/src/moonshot-identity-management-view.vala @@ -436,8 +436,9 @@ public class IdentityManagerView : Window { this.request_queue.push_tail (request); } - public void check_add_password(IdCard identity, IdentityRequest request, IdentityManagerModel model) + public IdCard check_add_password(IdCard identity, IdentityRequest request, IdentityManagerModel model) { + IdCard retval = identity; if ((identity.password == "") && !identity.IsNoIdentity()) { var dialog = new AddPasswordDialog (identity, request); @@ -447,7 +448,7 @@ public class IdentityManagerView : Window { case ResponseType.OK: identity.password = dialog.password; identity.store_password = dialog.remember; - model.update_card(identity); + retval = model.update_card(identity); break; default: identity = null; @@ -456,6 +457,7 @@ public class IdentityManagerView : Window { dialog.destroy (); } + return retval; } public void send_identity_cb (IdCard identity) diff --git a/src/moonshot-identity-manager-app.vala b/src/moonshot-identity-manager-app.vala index 7a6bf83..a5f04c1 100644 --- a/src/moonshot-identity-manager-app.vala +++ b/src/moonshot-identity-manager-app.vala @@ -225,7 +225,7 @@ public class IdentityManagerApp { Idle.add( () => { if (view != null) { - view.check_add_password(identity, request, model); + identity = view.check_add_password(identity, request, model); } request.return_identity (identity); // The following occasionally causes the app to exit without sending the dbus diff --git a/src/moonshot-identity-request.vala b/src/moonshot-identity-request.vala index 3646edf..cc436ac 100644 --- a/src/moonshot-identity-request.vala +++ b/src/moonshot-identity-request.vala @@ -72,7 +72,7 @@ public class IdentityRequest : Object { services[id_card.services.length] = this.service; id_card.services = services; - this.parent_app.model.update_card (id_card); + this.id_card = this.parent_app.model.update_card (id_card); } } diff --git a/src/moonshot-keyring-store.vala b/src/moonshot-keyring-store.vala index 2192704..00e09f5 100644 --- a/src/moonshot-keyring-store.vala +++ b/src/moonshot-keyring-store.vala @@ -12,10 +12,14 @@ public class KeyringStore : Object, IIdentityCardStore { store_id_cards (); } - public void update_card(IdCard card) { + public IdCard? update_card(IdCard card) { id_card_list.remove(card); id_card_list.add(card); store_id_cards (); + foreach (IdCard idcard in id_card_list) + if (idcard.display_name == card.display_name) + return idcard; + return null; } public void remove_card(IdCard card) { diff --git a/src/moonshot-local-flat-file-store.vala b/src/moonshot-local-flat-file-store.vala index 116e956..c2d39ab 100644 --- a/src/moonshot-local-flat-file-store.vala +++ b/src/moonshot-local-flat-file-store.vala @@ -9,10 +9,14 @@ public class LocalFlatFileStore : Object, IIdentityCardStore { store_id_cards (); } - public void update_card(IdCard card) { + public IdCard? update_card(IdCard card) { id_card_list.remove(card); id_card_list.add(card); store_id_cards (); + foreach(IdCard idcard in id_card_list) + if (idcard.display_name == card.display_name) + return idcard; + return null; } public void remove_card(IdCard card) { -- 2.1.4