X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=src%2Fmoonshot-identity-manager-app.vala;h=d903363594da027d29397b24178a6b233ab8b649;hb=f8c3b55edf6f8a54556d36982897a974f723f5ef;hp=d7fc42f32f9c8bb6955965387216773f7517b328;hpb=e7e57191d9419752caea92a21a86d1359b8c1a02;p=moonshot-ui.git diff --git a/src/moonshot-identity-manager-app.vala b/src/moonshot-identity-manager-app.vala index d7fc42f..d903363 100644 --- a/src/moonshot-identity-manager-app.vala +++ b/src/moonshot-identity-manager-app.vala @@ -39,13 +39,30 @@ 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) { + use_flat_file_store |= UserForcesFlatFileStore(); +#if GNOME_KEYRING + bool keyring_available = (!use_flat_file_store) && 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 card_list = model.get_card_list() ; if (card_list.size > 0) - this.default_id_card = card_list.first(); + this.default_id_card = card_list.last(); init_ipc_server (); @@ -60,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; } @@ -79,16 +96,14 @@ public class IdentityManagerApp { bool has_nai = request.nai != null && request.nai != ""; bool has_srv = request.service != null && request.service != ""; bool confirm = false; - IdCard nai_provided = null; foreach (IdCard id in model.get_card_list()) { - /* If NAI matches we add id card to the candidate list */ + /* If NAI matches, use this id card */ if (has_nai && request.nai == id.nai) { - nai_provided = id; - request.candidates.append (id); - continue; + identity = id; + break; } /* If any service matches we add id card to the candidate list */ @@ -106,7 +121,7 @@ public class IdentityManagerApp { } /* If more than one candidate we dissasociate service from all ids */ - if (has_srv && request.candidates.length() > 1) + if ((identity == null) && has_srv && request.candidates.length() > 1) { foreach (IdCard id in request.candidates) { @@ -144,10 +159,8 @@ public class IdentityManagerApp { } } -// model.store_id_cards (); - /* If there are no candidates we use the service matching rules */ - if (request.candidates.length () == 0) + if ((identity==null) && (request.candidates.length () == 0)) { foreach (IdCard id in model.get_card_list()) { @@ -164,23 +177,25 @@ public class IdentityManagerApp { } } - if (request.candidates.length () > 1) - { - if (has_nai && nai_provided != null) - { - identity = nai_provided; - confirm = false; - } - else + if ((identity == null) && 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; + identity.temporary = true; + } + if (identity == null) { + if (request.candidates.length () != 1) { confirm = true; + } else { + identity = request.candidates.nth_data (0); + } } - if (identity == null) - identity = request.candidates.nth_data (0); - if (identity == null) - confirm = true; - /* TODO: If candidate list empty return fail */ - if (confirm && (view != null)) { if (!explicitly_launched) @@ -191,8 +206,11 @@ public class IdentityManagerApp { } // Send back the identity (we can't directly run the // callback because we may be being called from a 'yield') - Idle.add( + GLib.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 @@ -241,7 +259,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(bool), 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 +313,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, + {"dbus-launched",0,GLib.OptionFlags.REVERSE,GLib.OptionArg.NONE, ref explicitly_launched,"launch for dbus rpc use",null}, + {"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} }; @@ -310,14 +331,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 @@ -332,7 +368,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) {