Support dynamic switching of card store type
[moonshot-ui.git] / src / moonshot-identity-manager-app.vala
index 1d44e1b..4237319 100644 (file)
@@ -39,8 +39,24 @@ public class IdentityManagerApp {
         if (view != null) view.show();    
     }
        
-    public IdentityManagerApp (bool headless) {
-        model = new IdentityManagerModel(this);
+    public IdentityManagerApp (bool headless, bool use_flat_file_store) {
+#if GNOME_KEYRING
+        bool keyring_available = GnomeKeyring.is_available();
+#else
+        bool keyring_available = false;
+#endif
+        IIdentityCardStore.StoreType store_type;
+        if (headless || use_flat_file_store || !keyring_available)
+            store_type = IIdentityCardStore.StoreType.FLAT_FILE;
+        else
+            store_type = IIdentityCardStore.StoreType.KEYRING;
+
+        model = new IdentityManagerModel(this, store_type);
+        /* if headless, but we have nothing in the flat file store
+         * and keyring is available, switch to keyring */
+        if (headless && keyring_available && !use_flat_file_store && !model.HasNonTrivialIdentities())
+            model.set_store_type(IIdentityCardStore.StoreType.KEYRING);
+
         if (!headless)
             view = new IdentityManagerView(this);
         LinkedList<IdCard> card_list = model.get_card_list() ;
@@ -241,7 +257,7 @@ public class IdentityManagerApp {
                                                              "/org/janet/moonshot",
                                                              "org.janet.Moonshot");
                 if (manager_proxy != null)
-                    manager_proxy.call("show_ui", out e, GLib.Type.INVALID, typeof(shown), out shown, GLib.Type.INVALID);
+                    manager_proxy.call("ShowUi", out e, GLib.Type.INVALID, typeof(bool), out shown, GLib.Type.INVALID);
 
                 if (!shown) {
                     GLib.error ("Couldn't own name org.janet.Moonshot on dbus or show previously launched identity manager.");
@@ -295,9 +311,12 @@ 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,
      ref explicitly_launched,"launch for dbus rpc use",null},
+    {"FlatFileStore",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}
 };
 
@@ -332,7 +351,7 @@ public static int main(string[] args){
         Intl.textdomain (Config.GETTEXT_PACKAGE);
        
           
-        var app = new IdentityManagerApp(headless);
+        var app = new IdentityManagerApp(headless, use_flat_file_store);
         app.explicitly_launched = explicitly_launched;
         
        if (app.explicitly_launched) {