Add flatstore-users
[moonshot-ui.git] / src / moonshot-identity-manager-app.vala
index 4237319..03088eb 100644 (file)
@@ -40,8 +40,9 @@ public class IdentityManagerApp {
     }
        
     public IdentityManagerApp (bool headless, bool use_flat_file_store) {
+        use_flat_file_store |= UserForcesFlatFileStore();
 #if GNOME_KEYRING
-        bool keyring_available = GnomeKeyring.is_available();
+        bool keyring_available = (!use_flat_file_store) && GnomeKeyring.is_available();
 #else
         bool keyring_available = false;
 #endif
@@ -76,9 +77,9 @@ public class IdentityManagerApp {
 #endif
     }
 
-    public bool add_identity (IdCard id) {
-        if (view != null) return view.add_identity(id);
-        model.add_card(id);
+    public bool add_identity (IdCard id, bool force_flat_file_store) {
+        if (view != null) return view.add_identity(id, force_flat_file_store);
+        model.add_card(id, force_flat_file_store);
         return true;
     }
 
@@ -192,8 +193,23 @@ public class IdentityManagerApp {
             }
             if (identity == null)
                 identity = request.candidates.nth_data (0);
-            if (identity == null)
-                confirm = true;
+            if ((identity != null) && 
+                ((identity.password == null) || (identity.password == "")))
+                identity.password = request.password;
+            if (identity == null) {
+                if (has_nai) {
+                    // create a temp identity
+                    string[] components = request.nai.split("@", 2);
+                    identity = new IdCard();
+                    identity.display_name = request.nai;
+                    identity.username = components[0];
+                    if (components.length > 1)
+                        identity.issuer = components[1];
+                    identity.password = request.password;
+                } else {
+                    confirm = true;
+                }
+            }
 
             /* TODO: If candidate list empty return fail */
             
@@ -209,6 +225,9 @@ public class IdentityManagerApp {
         // callback because we may be being called from a 'yield')
         Idle.add(
             () => {
+                if (view != null) {
+                    identity = view.check_add_password(identity, request, model);
+                }
                 request.return_identity (identity);
 // The following occasionally causes the app to exit without sending the dbus
 // reply, so for now we just don't exit
@@ -313,9 +332,9 @@ public class IdentityManagerApp {
 static bool explicitly_launched = true;
 static bool use_flat_file_store = false;
 const GLib.OptionEntry[] options = {
-    {"DBusLaunch",0,GLib.OptionFlags.REVERSE,GLib.OptionArg.NONE,
+    {"dbus-launched",0,GLib.OptionFlags.REVERSE,GLib.OptionArg.NONE,
      ref explicitly_launched,"launch for dbus rpc use",null},
-    {"FlatFileStore",0,0,GLib.OptionArg.NONE,
+    {"flat-file-store",0,0,GLib.OptionArg.NONE,
      ref use_flat_file_store,"force use of flat file identity store (used by default only for headless operation)",null},
     {null}
 };
@@ -329,14 +348,29 @@ public static int main(string[] args){
 #endif
 
         if (headless) {
+            try {
+                var opt_context = new OptionContext(null);
+                opt_context.set_help_enabled (true);
+                opt_context.add_main_entries (options, null);
+                opt_context.parse(ref args);
+            } catch (OptionError e) {
+                stdout.printf(_("error: %s\n"),e.message);
+                stdout.printf(_("Run '%s --help' to see a full list of available options\n"), args[0]);
+                return -1;
+            }
             explicitly_launched = false;
         } else {
             try {
-                Gtk.init_with_args(ref args, _(""), options, null);
+                if (!Gtk.init_with_args(ref args, _(""), options, null)) {
+                    stdout.printf(_("unable to initialize window\n"));
+                    return -1;
+                }
             } catch (GLib.Error e) {
                 stdout.printf(_("error: %s\n"),e.message);
-                stdout.printf(_("Run '%s --help' to see a full list of available options"), args[0]);
+                stdout.printf(_("Run '%s --help' to see a full list of available options\n"), args[0]);
+                return -1;
             }
+            gtk_available = true;
         }
 
 #if OS_WIN32