Do not associate the service if the IdCard already has it
authorJavier Jardón <javier.jardon@codethink.co.uk>
Wed, 1 Feb 2012 20:12:21 +0000 (20:12 +0000)
committerJavier Jardón <javier.jardon@codethink.co.uk>
Wed, 1 Feb 2012 20:15:51 +0000 (20:15 +0000)
src/moonshot-identity-management-view.vala

index f5b9109..250ca09 100644 (file)
@@ -587,16 +587,25 @@ class IdentityManagerView : Window {
 
         if (request.service != null && request.service != "")
         {
-            string[] services = new string[identity.services.length + 1];
+            bool duplicate_service = false;
 
-            for (int i = 0; i < identity.services.length; i++)
-                services[i] = identity.services[i];
+            foreach (string service in identity.services)
+            {
+                if (service == request.service)
+                    duplicate_service = true;
+            }
+            if (duplicate_service == false)
+            {
+                string[] services = new string[identity.services.length + 1];
 
-            services[identity.services.length] = request.service;
+                for (int i = 0; i < identity.services.length; i++)
+                    services[i] = identity.services[i];
 
-            identity.services = services;
+                services[identity.services.length] = request.service;
+                identity.services = services;
 
-            identities_manager.update_card (identity);
+                identities_manager.update_card (identity);
+            }
         }
 
         if (identity.password == null)