[PATCH] use XML session file when restarting Nautilus



The attached patch removes the old strategy of using GConf for
storing/reloading the window state when a Nautilus restart is requested
(using the CORBA shell, i.e. "nautilus --restart").

Instead, it makes Nautilus use the XML session file strategy, which is
also used for GNOME session saving.

best regards,
 Christian Neumair

-- 
Christian Neumair <cneumair gnome org>
Index: src/nautilus-application.c
===================================================================
--- src/nautilus-application.c	(revisión: 13851)
+++ src/nautilus-application.c	(copia de trabajo)
@@ -127,8 +127,6 @@ static void     update_session          
 static void     init_session                      (void);
 static gboolean is_kdesktop_present               (void);
 
-static char    *save_session_to_file              (void);
-
 BONOBO_CLASS_BOILERPLATE (NautilusApplication, nautilus_application,
 			  BonoboGenericFactory, BONOBO_TYPE_GENERIC_FACTORY)
 
@@ -1525,8 +1523,8 @@ icon_from_string (const char *string)
 	return NULL;
 }
 
-static char *
-save_session_to_file (void)
+char *
+nautilus_application_save_session_to_file (void)
 {
 	xmlDocPtr doc;
 	xmlNodePtr root_node, history_node;
@@ -1820,7 +1818,7 @@ save_session (GnomeClient *client, gint 
 
 	argv[0] = "nautilus";
 
-	argv[2] = save_session_to_file ();
+	argv[2] = nautilus_application_save_session_to_file ();
 	if (argv[2] != NULL) {
 		argv[1] = "--load-session";
 	}
Index: src/nautilus-application.h
===================================================================
--- src/nautilus-application.h	(revisión: 13851)
+++ src/nautilus-application.h	(copia de trabajo)
@@ -104,4 +104,5 @@ void                 nautilus_applicatio
 void                 nautilus_application_close_desktop     (void);
 void                 nautilus_application_load_session      (NautilusApplication *application,
 							     const char *filename); 
+char *               nautilus_application_save_session_to_file (void);
 #endif /* NAUTILUS_APPLICATION_H */
Index: src/nautilus-shell.c
===================================================================
--- src/nautilus-shell.c	(revisión: 13851)
+++ src/nautilus-shell.c	(copia de trabajo)
@@ -81,7 +81,6 @@ static void     corba_quit              
 						 CORBA_Environment      *ev);
 static void     corba_restart                   (PortableServer_Servant  servant,
 						 CORBA_Environment      *ev);
-static gboolean restore_window_states           (NautilusShell          *shell);
 
 BONOBO_CLASS_BOILERPLATE_FULL (NautilusShell, nautilus_shell,
 			       Nautilus_Shell,
@@ -187,11 +186,9 @@ open_windows_at_idle (gpointer _data)
 	GList *l;
 
 	if (data->uris == NULL) {
-		if (!restore_window_states (data->shell)) {
-			/* Open a window pointing at the default location. */
-			open_window (data->shell, NULL, data->startup_id,
-				     data->geometry, data->browser_window);
-		}
+		/* Open a window pointing at the default location. */
+		open_window (data->shell, NULL, data->startup_id,
+			     data->geometry, data->browser_window);
 	} else {
 		/* Open windows at each requested location. */
 		for (l = data->uris; l != NULL; l = l->next) {
@@ -349,190 +346,21 @@ corba_quit (PortableServer_Servant serva
 	g_idle_add (quit_at_idle, NULL);
 }
 
-/*
- * code for saving the state of nautilus windows across a restart
- *
- * for now, only the window geometry & uri is saved, into "start-state",
- * in a list of strings like:
- *
- *     "<width>,<height>,<x>,<y>,<location>"
- *
- * For example:
- *
- *     "800,600,10,10,file:///tmp"
- */
-
-#define WINDOW_STATE_ATTRIBUTE_WIDTH	0
-#define WINDOW_STATE_ATTRIBUTE_HEIGHT	1
-#define WINDOW_STATE_ATTRIBUTE_X	2
-#define WINDOW_STATE_ATTRIBUTE_Y	3
-#define WINDOW_STATE_ATTRIBUTE_LOCATION	4
-#define WINDOW_STATE_ATTRIBUTE_SCREEN	5
-
-static void
-save_window_states (void)
-{
-	GList *windows;
-	GList *node;
-	NautilusWindow *window;
-	GdkWindow *gdk_window;
-	char *window_attributes;
-	int x, y, width, height;
-	char *location;
-	GPtrArray *states;
-	int screen_num = -1;
-
-	states = g_ptr_array_new ();
-	windows = nautilus_application_get_window_list ();
-	for (node = windows; node; node = g_list_next (node)) {
-		g_assert (node->data != NULL);
-		window = node->data;
-
-		width = GTK_WIDGET (window)->allocation.width;
-		height = GTK_WIDGET (window)->allocation.height;
-
-		/* need root origin (origin of all the window dressing) */
-		gdk_window = GTK_WIDGET (window)->window;
-		gdk_window_get_root_origin (gdk_window, &x, &y);
-
-		location = nautilus_window_get_location_uri (window);
-
-		screen_num = gdk_screen_get_number (
-					gtk_window_get_screen (GTK_WINDOW (window)));
-
-		window_attributes = g_strdup_printf ("%d,%d,%d,%d,%s,%d", 
-						     width, height, 
-						     x, y, 
-						     location,
-						     screen_num);
-		g_free (location);
-
-		g_ptr_array_add (states, window_attributes);
-	}
-	g_ptr_array_add (states, NULL);
-
-	if (eel_preferences_key_is_writable (START_STATE_CONFIG)) {
-		eel_preferences_set_string_array (START_STATE_CONFIG,
-						  (char **) states->pdata);
-	}
-
-	g_ptr_array_free (states, TRUE);
-}
-
-static void
-restore_one_window (const char *attributes, NautilusShell *shell)
-{
-	char **attrs;
-	int attrs_len;
-	int x;
-	int y;
-	int width;
-	int height;
-	char *location;
-	NautilusWindow *window;
-	GdkScreen *screen = NULL;
-
-	g_return_if_fail (!eel_str_is_empty (attributes));
-	g_return_if_fail (NAUTILUS_IS_SHELL (shell));
-
-	attrs = g_strsplit (attributes, ",", -1);
-	attrs_len = g_strv_length (attrs);
-
-	x = 0;
-	y = 0;
-	width = 0;
-	height= 0;
-	location = NULL;
-
-	if (attrs_len > WINDOW_STATE_ATTRIBUTE_WIDTH) {
-		eel_str_to_int (attrs[WINDOW_STATE_ATTRIBUTE_WIDTH], &width);
-	}
-	if (attrs_len > WINDOW_STATE_ATTRIBUTE_HEIGHT) {
-		eel_str_to_int (attrs[WINDOW_STATE_ATTRIBUTE_HEIGHT], &width);
-	}
-	if (attrs_len > WINDOW_STATE_ATTRIBUTE_X) {
-		eel_str_to_int (attrs[WINDOW_STATE_ATTRIBUTE_X], &x);
-	}
-	if (attrs_len > WINDOW_STATE_ATTRIBUTE_Y) {
-		eel_str_to_int (attrs[WINDOW_STATE_ATTRIBUTE_Y], &y);
-	}
-	if (attrs_len > WINDOW_STATE_ATTRIBUTE_LOCATION) {
-		location = g_strdup (attrs[WINDOW_STATE_ATTRIBUTE_LOCATION]);
-	}
-
-	/* Support sessions with no screen number for backwards compat.
-	 */
-	if (attrs_len > WINDOW_STATE_ATTRIBUTE_SCREEN) {
-		int screen_num;
-		eel_str_to_int (attrs[WINDOW_STATE_ATTRIBUTE_SCREEN], &screen_num);
-		screen = gdk_display_get_screen (gdk_display_get_default (), screen_num);
-	} else {
-		screen = gdk_screen_get_default ();
-	}
-
-#if NEW_UI_COMPLETE 
-/* don't always create object windows here */
-#endif
-	if (eel_strlen (location) > 0) {
-		GFile *f;
-
-		f = g_file_new_for_uri (location);
-		window = nautilus_application_present_spatial_window (shell->details->application, 
-								      NULL,
-								      NULL,
-								      f,
-								      screen);
-		g_object_unref (f);
-	} else {
-		window = nautilus_application_create_navigation_window (shell->details->application,
-									NULL,
-									screen);
-		nautilus_window_go_home (window);
-	}
-
-	gtk_window_move (GTK_WINDOW (window), x, y);
-	gtk_widget_set_size_request (GTK_WIDGET (window), width, height);
-
-	g_free (location);
-	g_strfreev (attrs);
-}
-
-/* returns TRUE if there was state info which has been used to create new windows */
 static gboolean
-restore_window_states (NautilusShell *shell)
+restart_at_idle (gpointer data)
 {
-	char **states;
-	gboolean result;
-	int i;
-
-	result = FALSE;
-
-	states = eel_preferences_get_string_array (START_STATE_CONFIG);
-	if (!states) {
-		return result;
-	}
-
-	for (i = 0; states[i] != NULL; ++i) {
-		result = TRUE;
-		restore_one_window (states[i], shell);
-	}
+	char *filename;
 
-	if (eel_preferences_key_is_writable (START_STATE_CONFIG)) {
-		eel_preferences_set_string_array (START_STATE_CONFIG, NULL);
+	filename = nautilus_application_save_session_to_file ();
+	if (filename != NULL) {
+		nautilus_main_event_loop_quit (TRUE);
+		g_setenv ("_NAUTILUS_RESTART_SESSION_FILENAME", filename, 1);
+		g_free (filename);
+	} else {
+		g_message ("Could not save session. Not restarting.");
 	}
 
-	g_strfreev (states);
 
-	return result;
-}
-
-static gboolean
-restart_at_idle (gpointer data)
-{
-	save_window_states ();
-
-	nautilus_main_event_loop_quit (TRUE);
-	g_setenv ("_NAUTILUS_RESTART", "yes", 1);
 	return FALSE;
 }
 
Index: src/nautilus-main.c
===================================================================
--- src/nautilus-main.c	(revisión: 13851)
+++ src/nautilus-main.c	(copia de trabajo)
@@ -582,19 +582,17 @@ main (int argc, char *argv[])
 	 * an update takes place.
 	 */
 
-	if (g_getenv ("_NAUTILUS_RESTART") != NULL) {
-		g_unsetenv ("_NAUTILUS_RESTART");
-		
-		/* Might eventually want to copy all the parameters
-		 * from argv into the new exec. For now, though, that
-		 * would just interfere with the re-creation of
-		 * windows based on the window info stored in gconf,
-		 * including whether the desktop was started.
-		 */
-		argv_copy = g_new0 (char *, 2);
-		argv_copy[0] = argv[0];
-		
+	if (g_getenv ("_NAUTILUS_RESTART_SESSION_FILENAME") != NULL) {
+		argv_copy = g_new0 (char *, 4);
+		argv_copy[0] = g_strdup (argv[0]);
+		argv_copy[1] = g_strdup ("--load-session");
+		argv_copy[2] = g_strdup (g_getenv ("_NAUTILUS_RESTART_SESSION_FILENAME"));
+
+		g_unsetenv ("_NAUTILUS_RESTART_SESSION_FILENAME");
+
 		execvp (argv[0], argv_copy);
+
+		g_strfreev (argv_copy);
 	}
 
 	g_object_unref (G_OBJECT (program));


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