Identity Selector: Add special 'No Identity' idcard (LP# 1164611)
authorKevin Wasserman <krwasserman@hotmail.com>
Thu, 25 Apr 2013 18:41:14 +0000 (14:41 -0400)
committerKevin Wasserman <krwasserman@hotmail.com>
Thu, 25 Apr 2013 18:41:14 +0000 (14:41 -0400)
The 'No Identity' card is used to remember services that do
not want to use Moonshot for authentication.

src/moonshot-id.vala
src/moonshot-identities-manager.vala
src/moonshot-identity-management-view.vala
src/moonshot-server.vala

index 58af2d7..f783810 100644 (file)
@@ -14,6 +14,8 @@ public struct Rule
 
 public class IdCard : Object
 {
+  public const string NO_IDENTITY = "No Identity";
+
   private string _nai;
   
   public string display_name { get; set; default = ""; }
@@ -31,4 +33,16 @@ public class IdCard : Object
   public Gdk.Pixbuf pixbuf { get; set; default = null; }    
 
   public unowned string nai { get {  _nai = username + "@" + issuer; return _nai;}}
+
+  public bool IsNoIdentity() 
+  {
+    return (display_name == NO_IDENTITY);
+  }
+
+  public static IdCard NewNoIdentity() 
+  { 
+    IdCard card = new IdCard();
+    card.display_name = NO_IDENTITY;
+    return card;
+  }
 }
index e0b1dd2..aa20719 100644 (file)
@@ -5,7 +5,20 @@ public class IdentityManagerModel : Object {
 
     private IIdentityCardStore store;
     public LinkedList<IdCard>  get_card_list() {
-         return store.get_card_list(); 
+         var identities = store.get_card_list();
+         identities.sort( (a, b) => {
+             IdCard id_a = (IdCard )a;
+             IdCard id_b = (IdCard )b;
+             if (id_a.IsNoIdentity() && !id_b.IsNoIdentity()) {
+                return -1;
+             } else if (id_b.IsNoIdentity() && !id_a.IsNoIdentity()) {
+                return 1;
+             }
+             return strcmp(id_a.display_name, id_b.display_name);
+         });
+         if (!identities[0].IsNoIdentity())
+             identities.insert(0, IdCard.NewNoIdentity());
+         return identities;
     }
     public signal void card_list_changed();
 
index 82e21f2..e4a8486 100644 (file)
@@ -4,6 +4,7 @@ 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;
@@ -11,12 +12,15 @@ public class IdentityManagerView : Window {
     private UIManager ui_manager = new UIManager();
     private Entry search_entry;
     private VBox vbox_right;
+    private VBox login_vbox;
+    private VBox services_vbox;
     private CustomVBox custom_vbox;
     private VBox services_internal_vbox;
 
     private Entry username_entry;
     private Entry password_entry;
     private Label prompting_service;
+    private Label no_identity_title;
 
     private ListStore* listmodel;
     private TreeModelFilter filter;
@@ -204,8 +208,17 @@ public class IdentityManagerView : Window {
     private void fill_details (IdCardWidget id_card_widget)
     {
        var id_card = id_card_widget.id_card;
-       this.username_entry.set_text (id_card.username);
-       this.password_entry.set_text (id_card.password ?? "");
+       var vr_children = this.vbox_right.get_children();
+       foreach (var vr_child in vr_children)
+           this.vbox_right.remove(vr_child);
+       if (id_card.display_name == IdCard.NO_IDENTITY) {
+           this.vbox_right.pack_start(no_identity_title, false, true, 0);
+       } else {
+           this.username_entry.set_text (id_card.username);
+           this.password_entry.set_text (id_card.password ?? "");
+           this.vbox_right.pack_start(login_vbox, false, true, 0);
+       }
+       this.vbox_right.pack_start (services_vbox, false, true, 0);
 
        var children = this.services_internal_vbox.get_children ();
        foreach (var hbox in children)
@@ -763,6 +776,12 @@ SUCH DAMAGE.
         vbox_left.pack_start (prompting_service, false, false, 6);
         vbox_left.set_size_request (WINDOW_WIDTH, 0);
 
+        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();
+
         var login_vbox_title = new Label (_("Login: "));
         label_make_bold (login_vbox_title);
         login_vbox_title.set_alignment (0, (float) 0.5);
@@ -786,7 +805,7 @@ SUCH DAMAGE.
         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);
-        var login_vbox = new VBox (false, 6);
+        this.login_vbox = new VBox (false, 6);
         login_vbox.pack_start (login_vbox_title, false, true, 0);
         login_vbox.pack_start (login_vbox_alignment, false, true, 0);
 
@@ -797,13 +816,14 @@ SUCH DAMAGE.
         services_vbox_alignment.set_padding (0, 0, 12, 0);
         this.services_internal_vbox = new VBox (true, 6);
         services_vbox_alignment.add (services_internal_vbox);
-        var services_vbox = new VBox (false, 6);
+        this.services_vbox = new VBox (false, 6);
         services_vbox.pack_start (services_vbox_title, false, true, 0);
         services_vbox.pack_start (services_vbox_alignment, false, true, 0);
 
         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);
index 24077c4..539dbc3 100644 (file)
@@ -37,7 +37,7 @@ public class MoonshotServer : Object {
 
         var id_card = request.id_card;
 
-        if (id_card != null) {
+        if ((id_card != null) && (id_card.display_name != IdCard.NO_IDENTITY)) {
             nai_out = id_card.nai;
             password_out = id_card.password;