[nautilus] application: fix some bad interactions with GApplication



commit 4882f2ac24dfcf33e06e5e9a06dd2cd0368069ec
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu Nov 4 13:25:38 2010 +0100

    application: fix some bad interactions with GApplication

 src/nautilus-application.c |   96 +++++++++++++++++++++++++-------------------
 src/nautilus-application.h |    2 +-
 2 files changed, 56 insertions(+), 42 deletions(-)
---
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index e4d83dd..ffb9c05 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -1492,14 +1492,26 @@ nautilus_application_command_line (GApplication *app,
 	gint argc = 0;
 	gchar **argv = NULL, **uris = NULL;
 	gint retval = EXIT_SUCCESS;
+	gboolean exit_with_last_window;
 
 	context = g_option_context_new (_("\n\nBrowse the file system with the file manager"));
 	g_option_context_add_main_entries (context, options, NULL);
 	g_option_context_add_group (context, gtk_get_option_group (TRUE));
-	g_option_context_add_group (context, egg_sm_client_get_option_group ());
+
+	if (!self->initialized) {
+		g_option_context_add_group (context, egg_sm_client_get_option_group ());
+	}
 
 	argv = g_application_command_line_get_arguments (command_line, &argc);
 
+	/* we need to do this here, as parsing the EggSMClient option context,
+	 * unsets this variable.
+	 */
+	autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID");
+	if (autostart_id != NULL && *autostart_id != '\0') {
+		autostart_mode = TRUE;
+        }
+
 	if (!g_option_context_parse (context, &argc, &argv, &error)) {
 		g_printerr ("Could not parse arguments: %s\n", error->message);
 		g_error_free (error);
@@ -1558,11 +1570,6 @@ nautilus_application_command_line (GApplication *app,
 		goto out;
 	}
 
-	autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID");
-	if (autostart_id != NULL && *autostart_id != '\0') {
-		autostart_mode = TRUE;
-        }
-
 	/* If in autostart mode (aka started by gnome-session), we need to ensure 
          * nautilus starts with the correct options.
          */
@@ -1571,40 +1578,63 @@ nautilus_application_command_line (GApplication *app,
 		no_desktop = FALSE;
 	}
 
+	exit_with_last_window =
+		g_settings_get_boolean (nautilus_preferences,
+					NAUTILUS_PREFERENCES_EXIT_WITH_LAST_WINDOW);
+
 	if (kill_shell) {
 		nautilus_application_close_desktop ();
 		g_application_release (app);
+
+		if (!exit_with_last_window) {
+			g_application_release (app);
+		}
 	} else {
-		char *accel_map_filename;
+		if (!self->initialized) {
+			char *accel_map_filename;
 
-		if (!self->sm_initialized) {
 			nautilus_application_smclient_init (self);
 
 			if (egg_sm_client_is_resumed (self->smclient)) {
 				no_default_window = TRUE;
 			}
-		}
 
-		if (!no_desktop &&
-		    !g_settings_get_boolean (gnome_background_preferences,
-					     NAUTILUS_PREFERENCES_SHOW_DESKTOP)) {
-			no_desktop = TRUE;
-		}
+			if (!no_desktop &&
+			    !g_settings_get_boolean (gnome_background_preferences,
+						     NAUTILUS_PREFERENCES_SHOW_DESKTOP)) {
+				no_desktop = TRUE;
+			}
 
-		if (!no_desktop) {
-			nautilus_application_open_desktop (self);
-		}
+			if (!no_desktop) {
+				nautilus_application_open_desktop (self);
+			}
 
-		if (no_default_window && no_desktop) {
-			g_application_hold (app);
-		}
+			if (!exit_with_last_window) {
+				g_application_hold (app);
+			}
+
+			finish_startup (self, no_desktop);
+
+			/* Monitor the preference to show or hide the desktop */
+			g_signal_connect_swapped (gnome_background_preferences, "changed::" NAUTILUS_PREFERENCES_SHOW_DESKTOP,
+						  G_CALLBACK (desktop_changed_callback),
+						  self);
+
+			/* load accelerator map, and register save callback */
+			accel_map_filename = nautilus_get_accel_map_file ();
+			if (accel_map_filename) {
+				gtk_accel_map_load (accel_map_filename);
+				g_free (accel_map_filename);
+			}
 
-		finish_startup (self, no_desktop);
+			g_signal_connect (gtk_accel_map_get (), "changed",
+					  G_CALLBACK (queue_accel_map_save_callback), NULL);
 
-		/* Monitor the preference to show or hide the desktop */
-		g_signal_connect_swapped (gnome_background_preferences, "changed::" NAUTILUS_PREFERENCES_SHOW_DESKTOP,
-					  G_CALLBACK (desktop_changed_callback),
-					  self);
+			/* Load session info if availible */
+			nautilus_application_smclient_load (self);
+
+			self->initialized = TRUE;
+		}
 
 		/* Convert args to URIs */
 		if (remaining != NULL) {
@@ -1639,22 +1669,6 @@ nautilus_application_command_line (GApplication *app,
 				      geometry,
 				      browser_window);
 		}
-
-		if (!self->sm_initialized) {
-			/* Load session info if availible */
-			nautilus_application_smclient_load (self);
-			self->sm_initialized = TRUE;
-		}
-
-		/* load accelerator map, and register save callback */
-		accel_map_filename = nautilus_get_accel_map_file ();
-		if (accel_map_filename) {
-			gtk_accel_map_load (accel_map_filename);
-			g_free (accel_map_filename);
-		}
-
-		g_signal_connect (gtk_accel_map_get (), "changed",
-				  G_CALLBACK (queue_accel_map_save_callback), NULL);
 	}
 
  out:
diff --git a/src/nautilus-application.h b/src/nautilus-application.h
index 776079a..0e09543 100644
--- a/src/nautilus-application.h
+++ b/src/nautilus-application.h
@@ -65,7 +65,7 @@ typedef struct {
 	GDBusProxy *proxy;
 	gboolean session_is_active;
 
-	gboolean sm_initialized;
+	gboolean initialized;
 } NautilusApplication;
 
 typedef struct {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]