From: Pete Fotheringham Date: Tue, 7 Feb 2012 15:52:10 +0000 (+0000) Subject: Fix S928 [bug] 924920 Mac port - provisioning crashes on exit X-Git-Tag: 0.7.1~112 X-Git-Url: http://www.project-moonshot.org/gitweb/?a=commitdiff_plain;h=f53f8fe137ffceb1de8b7edef0956ebc1fd18c06;hp=636304ba4d1f72278520090a48f45513ff5ed5f0;p=moonshot-ui.git Fix S928 [bug] 924920 Mac port - provisioning crashes on exit Crash happens if a dialog is displayed in the signal_handler function. This seems toi be a bug in the gtk-mac-integration whihc will be raised with the authors. For now, on Mac we will installe the cards without confirmation --- diff --git a/src/moonshot-identity-management-view.vala b/src/moonshot-identity-management-view.vala index 250ca09..6692fcb 100644 --- a/src/moonshot-identity-management-view.vala +++ b/src/moonshot-identity-management-view.vala @@ -347,7 +347,14 @@ class IdentityManagerView : Window { public bool add_identity (IdCard id_card) { - /* TODO: Check if display name already exists */ +#if OS_MACOS + /* + * TODO: We should have a confirmation dialog, but currently it will crash on Mac OS + * so for now we will install silently + */ + var ret = Gtk.ResponseType.YES; +#else + public OSXApplication osxApp; var dialog = new Gtk.MessageDialog (this, Gtk.DialogFlags.DESTROY_WITH_PARENT, @@ -356,9 +363,9 @@ class IdentityManagerView : Window { _("Would you like to add '%s' ID Card to the ID Card Organizer?"), id_card.display_name); - dialog.show_all (); var ret = dialog.run (); - dialog.hide (); + dialog.destroy (); +#endif if (ret == Gtk.ResponseType.YES) { id_card.set_data ("pixbuf", find_icon ("avatar-default", 48)); @@ -422,7 +429,7 @@ class IdentityManagerView : Window { { var id_card = id_card_widget.id_card; - var dialog = new MessageDialog (null, + var dialog = new MessageDialog (this, DialogFlags.DESTROY_WITH_PARENT, MessageType.QUESTION, Gtk.ButtonsType.YES_NO, diff --git a/src/moonshot-identity-manager-app.vala b/src/moonshot-identity-manager-app.vala index 3681159..3989807 100644 --- a/src/moonshot-identity-manager-app.vala +++ b/src/moonshot-identity-manager-app.vala @@ -5,13 +5,21 @@ class IdentityManagerApp { public IdentityManagerModel model; private IdentityManagerView view; private MoonshotServer ipc_server; + #if OS_MACOS public OSXApplication osxApp; - public bool on_osx_open_files (string file_name ) { - print ("on_osx_open_files() file_name = %s\n", file_name); - return ipc_server.install_from_file(file_name); + + // the signal handler function. + // the current instance of our app class is passed in the + // id_manager_app_instanceparameter + public static bool on_osx_open_files (OSXApplication osx_app_instance, + string file_name, + IdentityManagerApp id_manager_app_instance ) { + int added_cards = id_manager_app_instance.ipc_server.install_from_file(file_name); + return true; } #endif + private const int WINDOW_WIDTH = 400; private const int WINDOW_HEIGHT = 500; public void show() { @@ -22,13 +30,14 @@ class IdentityManagerApp { model = new IdentityManagerModel(this); view = new IdentityManagerView(this); init_ipc_server (); + #if OS_MACOS - osxApp = OSXApplication.get_instance(); -// This wont work with Vala 0.12 -// osxApp.ns_application_open_file.connect(ipc_server.install_from_file); -// so we have to use this old way - Signal.connect(osxApp, "NSApplicationOpenFile", (GLib.Callback)(on_osx_open_files), ipc_server); -// Signal.connect_data(osxApp, "NSApplicationOpenFile", (GLib.Callback)(ipc_server.install_from_file), ipc_server, null, 0); + + osxApp = OSXApplication.get_instance(); + // The 'correct' way of connrcting wont work in Mac OS with Vala 0.12 e.g. + // osxApp.ns_application_open_file.connect(install_from_file); + // so we have to use this old way + Signal.connect(osxApp, "NSApplicationOpenFile", (GLib.Callback)(on_osx_open_files), this); #endif view.show(); diff --git a/src/moonshot-server.vala b/src/moonshot-server.vala index b7fcfbb..c581860 100644 --- a/src/moonshot-server.vala +++ b/src/moonshot-server.vala @@ -3,7 +3,7 @@ [DBus (name = "org.janet.Moonshot")] public class MoonshotServer : Object { - private static IdentityManagerView main_window; + private IdentityManagerView main_window; public MoonshotServer (Gtk.Window window) { @@ -152,13 +152,13 @@ public class MoonshotServer : Object { } - public bool install_from_file (string file_name) + public int install_from_file (string file_name) { var webp = new WebProvisioning.Parser (file_name); - print ("install_from_file() file_name = %s", file_name); + webp.parse(); bool result = false; - + int installed_cards = 0; foreach (IdCard card in WebProvisioning.cards) { string[] rules_patterns = {}; @@ -176,6 +176,7 @@ public class MoonshotServer : Object { i++; } } + result = install_id_card (card.display_name, card.username, card.password, @@ -187,12 +188,12 @@ public class MoonshotServer : Object { card.trust_anchor.subject, card.trust_anchor.subject_alt, card.trust_anchor.server_cert); - } - -print ("install_from_file() result %s\n", result.to_string()); - return result; + if (result) { + installed_cards++; + } } - + return installed_cards; + } }