update_card() returns modified card
authorKevin Wasserman <kevin.wasserman@painless-security.com>
Tue, 29 Oct 2013 01:46:59 +0000 (21:46 -0400)
committerKevin Wasserman <kevin.wasserman@painless-security.com>
Tue, 29 Oct 2013 01:46:59 +0000 (21:46 -0400)
replace old card with modified card where appropriate to
avoid duplicating ids.

src/moonshot-idcard-store.vala
src/moonshot-identities-manager.vala
src/moonshot-identity-management-view.vala
src/moonshot-identity-manager-app.vala
src/moonshot-identity-request.vala
src/moonshot-keyring-store.vala
src/moonshot-local-flat-file-store.vala

index 4303713..7fa060e 100644 (file)
@@ -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<IdCard> get_card_list(); 
 }
index 501d065..0c8dfb4 100644 (file)
@@ -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) {
index 7571af0..0b7e283 100644 (file)
@@ -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)
index 7a6bf83..a5f04c1 100644 (file)
@@ -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
index 3646edf..cc436ac 100644 (file)
@@ -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);
             }
         }
 
index 2192704..00e09f5 100644 (file)
@@ -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) {
index 116e956..c2d39ab 100644 (file)
@@ -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) {