Modify identity selection logic / fix bugs
[moonshot-ui.git] / src / moonshot-identity-management-view.vala
index c52a0ce..1ddb1c8 100644 (file)
@@ -4,7 +4,6 @@ using Gtk;
 public class IdentityManagerView : Window {
     private const int WINDOW_WIDTH = 400;
     private const int WINDOW_HEIGHT = 500;
-    private const int RIGHT_PANE_WIDTH = 275;
     protected IdentityManagerApp parent_app;
 #if OS_MACOS
        public OSXApplication osxApp;
@@ -437,26 +436,35 @@ 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)
     {
-        if ((identity.password == "") && !identity.IsNoIdentity())
-        {
-            var dialog = new AddPasswordDialog (identity, request);
-            var result = dialog.run ();
-
-            switch (result) {
-            case ResponseType.OK:
-                identity.password = dialog.password;
-                identity.store_password = dialog.remember;
-                model.update_card(identity);
-                break;
-            default:
-                identity = null;
-                break;
+        IdCard retval = identity;
+        bool idcard_has_pw = (identity.password != null) && (identity.password != "");
+        bool request_has_pw = (request.password != null) && (request.password != "");
+        if ((!idcard_has_pw) && (!identity.IsNoIdentity())) {
+            if (request_has_pw) {
+                identity.password = request.password;
+                retval = model.update_card(identity);
+            } else {
+                var dialog = new AddPasswordDialog (identity, request);
+                var result = dialog.run ();
+
+                switch (result) {
+                case ResponseType.OK:
+                    identity.password = dialog.password;
+                    identity.store_password = dialog.remember;
+                    if (dialog.remember)
+                        identity.temporary = false;
+                    retval = model.update_card(identity);
+                    break;
+                default:
+                    identity = null;
+                    break;
+                }
+                dialog.destroy ();
             }
-
-            dialog.destroy ();
         }
+        return retval;
     }
 
     public void send_identity_cb (IdCard identity)
@@ -749,7 +757,6 @@ SUCH DAMAGE.
 
         this.no_identity_title = new Label (_("No Identity: Send this identity to services which should not use Moonshot"));
         no_identity_title.set_alignment(0, (float ) 0.5);
-        no_identity_title.set_size_request(RIGHT_PANE_WIDTH, -1);
         no_identity_title.set_line_wrap(true);
         no_identity_title.show();
 
@@ -794,11 +801,10 @@ SUCH DAMAGE.
         this.vbox_right = new VBox (false, 18);
         vbox_right.pack_start (login_vbox, false, true, 0);
         vbox_right.pack_start (services_vbox, false, true, 0);
-        vbox_right.set_size_request( RIGHT_PANE_WIDTH, -1 );
 
         var hbox = new HBox (false, 12);
-        hbox.pack_start (vbox_left, true, true, 0);
-        hbox.pack_start (vbox_right, false, false, 0);
+        hbox.pack_start (vbox_left, false, false, 0);
+        hbox.pack_start (vbox_right, true, true, 0);
 
         var main_vbox = new VBox (false, 0);
         main_vbox.set_border_width (12);