[nautilus] application: fix interaction with the session manager



commit 7c042f64ee59d9f149252f7e78e11ca6ad7d9dbe
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri Nov 12 12:24:07 2010 +0100

    application: fix interaction with the session manager
    
    The porting to GApplication broke the session management code that took
    care of saving and loading existing windows if the session saving is
    active.
    
    We now fix it by changing a bit our startup process, so that the
    EggSMClient object is actually created at the right time.

 src/nautilus-application-smclient.c |  118 ++++++++++++++++++++---------------
 src/nautilus-application-smclient.h |    5 +-
 src/nautilus-application.c          |   37 +++++++-----
 src/nautilus-application.h          |    2 +
 4 files changed, 95 insertions(+), 67 deletions(-)
---
diff --git a/src/nautilus-application-smclient.c b/src/nautilus-application-smclient.c
index 98f3e6d..611c76a 100644
--- a/src/nautilus-application-smclient.c
+++ b/src/nautilus-application-smclient.c
@@ -28,6 +28,7 @@
 #include "nautilus-window-slot.h"
 
 #include <eel/eel-gtk-extensions.h>
+#include <eel/eel-vfs-extensions.h>
 #include <libxml/xmlsave.h>
 
 static char *
@@ -95,8 +96,24 @@ nautilus_application_get_session_data (NautilusApplication *self)
 
 		window = l->data;
 
-		win_node = xmlNewChild (root_node, NULL, "window", NULL);
+		slots = nautilus_window_get_slots (window);
+		active_slot = nautilus_window_get_active_slot (window);
+
+		/* store one slot as window location. Otherwise
+		 * older Nautilus versions will bail when reading the file. */
+		tmp = nautilus_window_slot_get_location_uri (active_slot);
 
+		if (eel_uri_is_desktop (tmp)) {
+			g_list_free (slots);
+			g_free (tmp);
+			continue;
+		}
+
+		win_node = xmlNewChild (root_node, NULL, "window", NULL);
+		
+		xmlNewProp (win_node, "location", tmp);
+		g_free (tmp);
+		
 		xmlNewProp (win_node, "type", NAUTILUS_IS_NAVIGATION_WINDOW (window) ? "navigation" : "spatial");
 
 		if (NAUTILUS_IS_NAVIGATION_WINDOW (window)) { /* spatial windows store their state as file metadata */
@@ -124,15 +141,6 @@ nautilus_application_get_session_data (NautilusApplication *self)
 			}
 		}
 
-		slots = nautilus_window_get_slots (window);
-		active_slot = nautilus_window_get_active_slot (window);
-
-		/* store one slot as window location. Otherwise
-		 * older Nautilus versions will bail when reading the file. */
-		tmp = nautilus_window_slot_get_location_uri (active_slot);
-		xmlNewProp (win_node, "location", tmp);
-		g_free (tmp);
-
 		for (m = slots; m != NULL; m = m->next) {
 			slot = NAUTILUS_WINDOW_SLOT (m->data);
 
@@ -167,8 +175,50 @@ nautilus_application_get_session_data (NautilusApplication *self)
 	return data;
 }
 
+static void
+smclient_save_state_cb (EggSMClient *client,
+			GKeyFile *state_file,
+			NautilusApplication *application)
+{
+	char *data;
+
+	data = nautilus_application_get_session_data (application);
+
+	if (data != NULL) {
+		g_key_file_set_string (state_file,
+				       "Nautilus",
+				       "documents", 
+				       data);
+	}
+
+	g_free (data);
+}
+
+static void
+smclient_quit_cb (EggSMClient   *client,
+		  NautilusApplication *application)
+{
+	nautilus_application_quit (application);
+}
+
+static void
+nautilus_application_smclient_initialize (NautilusApplication *self)
+{
+	egg_sm_client_set_mode (EGG_SM_CLIENT_MODE_NORMAL);
+
+	g_signal_connect (self->smclient, "save_state",
+                          G_CALLBACK (smclient_save_state_cb),
+                          self);
+	g_signal_connect (self->smclient, "quit",
+			  G_CALLBACK (smclient_quit_cb),
+			  self);
+
+	/* TODO: Should connect to quit_requested and block logout on active transfer? */
+}
+
 void
-nautilus_application_smclient_load (NautilusApplication *application)
+nautilus_application_smclient_load (NautilusApplication *application,
+				    gboolean *no_default_window)
 {
 	xmlDocPtr doc;
 	gboolean bail;
@@ -176,6 +226,8 @@ nautilus_application_smclient_load (NautilusApplication *application)
 	GKeyFile *state_file;
 	char *data;
 
+	nautilus_application_smclient_initialize (application);
+
 	if (!egg_sm_client_is_resumed (application->smclient)) {
 		return;
 	}
@@ -192,7 +244,8 @@ nautilus_application_smclient_load (NautilusApplication *application)
 	if (data == NULL) {
 		return;
 	}
-	
+
+	*no_default_window = TRUE;
 	bail = TRUE;
 
 	doc = xmlReadMemory (data, strlen (data), NULL, "UTF-8", 0);
@@ -372,46 +425,11 @@ nautilus_application_smclient_load (NautilusApplication *application)
 	} 
 }
 
-static void
-smclient_save_state_cb (EggSMClient *client,
-			GKeyFile *state_file,
-			NautilusApplication *application)
-{
-	char *data;
-
-	data = nautilus_application_get_session_data (application);
-
-	if (data != NULL) {
-		g_key_file_set_string (state_file,
-				       "Nautilus",
-				       "documents", 
-				       data);
-	}
-
-	g_free (data);
-}
-
-static void
-smclient_quit_cb (EggSMClient   *client,
-		  NautilusApplication *application)
-{
-	g_application_release (G_APPLICATION (application));
-}
-
 void
-nautilus_application_smclient_init (NautilusApplication *self)
+nautilus_application_smclient_startup (NautilusApplication *self)
 {
 	g_assert (self->smclient == NULL);
 
-	egg_sm_client_set_mode (EGG_SM_CLIENT_MODE_NORMAL);
-
-	/* TODO: Should connect to quit_requested and block logout on active transfer? */
-        self->smclient = egg_sm_client_get ();
-        g_signal_connect (self->smclient, "save_state",
-                          G_CALLBACK (smclient_save_state_cb),
-                          self);
-	g_signal_connect (self->smclient, "quit",
-			  G_CALLBACK (smclient_quit_cb),
-			  self);
-	/* TODO: Should connect to quit_requested and block logout on active transfer? */
+	egg_sm_client_set_mode (EGG_SM_CLIENT_MODE_DISABLED);
+	self->smclient = egg_sm_client_get ();
 }
diff --git a/src/nautilus-application-smclient.h b/src/nautilus-application-smclient.h
index fb50302..e71a19b 100644
--- a/src/nautilus-application-smclient.h
+++ b/src/nautilus-application-smclient.h
@@ -26,7 +26,8 @@
 
 #include "nautilus-application.h"
 
-void nautilus_application_smclient_init (NautilusApplication *self);
-void nautilus_application_smclient_load (NautilusApplication *self);
+void nautilus_application_smclient_startup (NautilusApplication *self);
+void nautilus_application_smclient_load (NautilusApplication *self,
+					 gboolean *no_default_window);
 
 #endif /* __NAUTILUS_APPLICATION_SMCLIENT_H__ */
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index ffb9c05..a0a1e56 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -1451,6 +1451,24 @@ nautilus_application_finalize (GObject *object)
         G_OBJECT_CLASS (nautilus_application_parent_class)->finalize (object);
 }
 
+void
+nautilus_application_quit (NautilusApplication *self)
+{
+	GApplication *app = G_APPLICATION (self);
+	gboolean exit_with_last_window;
+
+	exit_with_last_window =
+		g_settings_get_boolean (nautilus_preferences,
+					NAUTILUS_PREFERENCES_EXIT_WITH_LAST_WINDOW);
+
+	nautilus_application_close_desktop ();
+	g_application_release (app);
+
+	if (!exit_with_last_window) {
+		g_application_release (app);
+	}
+}
+
 static gint
 nautilus_application_command_line (GApplication *app,
 				   GApplicationCommandLine *command_line)
@@ -1583,22 +1601,11 @@ nautilus_application_command_line (GApplication *app,
 					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);
-		}
+		nautilus_application_quit (self);
 	} else {
 		if (!self->initialized) {
 			char *accel_map_filename;
 
-			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)) {
@@ -1630,8 +1637,8 @@ nautilus_application_command_line (GApplication *app,
 			g_signal_connect (gtk_accel_map_get (), "changed",
 					  G_CALLBACK (queue_accel_map_save_callback), NULL);
 
-			/* Load session info if availible */
-			nautilus_application_smclient_load (self);
+			/* Initialize SMClient and load session info if availible */
+			nautilus_application_smclient_load (self, &no_default_window);
 
 			self->initialized = TRUE;
 		}
@@ -1692,7 +1699,7 @@ nautilus_application_startup (GApplication *app)
 	self->undo_manager = nautilus_undo_manager_new ();
 
 	/* initialize the session manager client */
-	egg_sm_client_set_mode (EGG_SM_CLIENT_MODE_DISABLED);
+	nautilus_application_smclient_startup (self);
 
 	/* Initialize preferences. This is needed to create the
 	 * global GSettings objects.
diff --git a/src/nautilus-application.h b/src/nautilus-application.h
index 0e09543..25b6d52 100644
--- a/src/nautilus-application.h
+++ b/src/nautilus-application.h
@@ -76,6 +76,8 @@ GType nautilus_application_get_type (void);
 
 NautilusApplication *nautilus_application_dup_singleton (void);
 
+void nautilus_application_quit (NautilusApplication *self);
+
 NautilusWindow *     nautilus_application_get_spatial_window     (NautilusApplication *application,
 								  NautilusWindow      *requesting_window,
 								  const char          *startup_id,



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