Re: [PATCH] Improve session management, attempt 2



Am Montag, den 19.06.2006, 17:54 +0200 schrieb Alexander Larsson:
> On Mon, 2006-06-19 at 17:22 +0200, Christian Neumair wrote:
> > > We shouldn't open a default window in this case. Did you handle that?
> > 
> > The session restart command includes
> > "--no-default-window" (nautilus-application.c:save_session).
> 
> I guess that is good enough, although we could also always do that when
> specifying a session. Its unlikely that people would use the session
> switch manually though, so it doesn't really matter.

New patch attached, which takes into account your other worthy
suggestions and makes --load-session imply presence of
--no-default-window.

-- 
Christian Neumair <chris gnome-de org>
Index: libnautilus-private/nautilus-global-preferences.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-global-preferences.c,v
retrieving revision 1.227
diff -u -p -r1.227 nautilus-global-preferences.c
--- libnautilus-private/nautilus-global-preferences.c	16 Jun 2006 14:19:55 -0000	1.227
+++ libnautilus-private/nautilus-global-preferences.c	20 Jun 2006 17:52:00 -0000
@@ -384,6 +384,10 @@ static const PreferenceDefault preferenc
 	  PREFERENCE_STRING,
 	  ""
 	},
+	{ NAUTILUS_PREFERENCES_NAVIGATION_WINDOW_MAXIMIZED,
+	  PREFERENCE_BOOLEAN,
+	  GINT_TO_POINTER (FALSE)
+	},
 	{ NAUTILUS_PREFERENCES_TREE_SHOW_ONLY_DIRECTORIES,
 	  PREFERENCE_BOOLEAN,
 	  GINT_TO_POINTER (TRUE)
Index: libnautilus-private/nautilus-global-preferences.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-global-preferences.h,v
retrieving revision 1.133
diff -u -p -r1.133 nautilus-global-preferences.h
--- libnautilus-private/nautilus-global-preferences.h	16 Jun 2006 14:19:55 -0000	1.133
+++ libnautilus-private/nautilus-global-preferences.h	20 Jun 2006 17:52:01 -0000
@@ -88,6 +88,7 @@ typedef enum
 #define NAUTILUS_PREFERENCES_START_WITH_TOOLBAR			"preferences/start_with_toolbar"
 #define NAUTILUS_PREFERENCES_SIDE_PANE_VIEW                     "preferences/side_pane_view"
 #define NAUTILUS_PREFERENCES_NAVIGATION_WINDOW_SAVED_GEOMETRY 	"preferences/navigation_window_saved_geometry"
+#define NAUTILUS_PREFERENCES_NAVIGATION_WINDOW_MAXIMIZED        "preferences/navigation_window_saved_maximized"
 
 /* Sorting order */
 #define NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST		"preferences/sort_directories_first"
Index: libnautilus-private/nautilus-metadata.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-metadata.h,v
retrieving revision 1.30
diff -u -p -r1.30 nautilus-metadata.h
--- libnautilus-private/nautilus-metadata.h	11 Oct 2004 08:10:42 -0000	1.30
+++ libnautilus-private/nautilus-metadata.h	20 Jun 2006 17:52:06 -0000
@@ -55,6 +55,7 @@
 #define NAUTILUS_METADATA_KEY_WINDOW_GEOMETRY			"window_geometry"
 #define NAUTILUS_METADATA_KEY_WINDOW_SCROLL_POSITION		"window_scroll_position"
 #define NAUTILUS_METADATA_KEY_WINDOW_SHOW_HIDDEN_FILES		"window_show_hidden_files"
+#define NAUTILUS_METADATA_KEY_WINDOW_MAXIMIZED			"window_maximized"
 
 #define NAUTILUS_METADATA_KEY_SIDEBAR_BACKGROUND_COLOR   	"sidebar_background_color"
 #define NAUTILUS_METADATA_KEY_SIDEBAR_BACKGROUND_IMAGE   	"sidebar_background_tile_image"
Index: src/nautilus-application.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-application.c,v
retrieving revision 1.241
diff -u -p -r1.241 nautilus-application.c
--- src/nautilus-application.c	22 Mar 2006 09:04:21 -0000	1.241
+++ src/nautilus-application.c	20 Jun 2006 17:52:18 -0000
@@ -52,8 +52,11 @@
 #include "nautilus-shell.h"
 #include "nautilus-window-bookmarks.h"
 #include "nautilus-window-private.h"
+#include "nautilus-window-manage-views.h"
+#include <glib/gstdio.h>
 #include <bonobo/bonobo-main.h>
 #include <bonobo/bonobo-object.h>
+#include <eel/eel-gtk-extensions.h>
 #include <eel/eel-gtk-macros.h>
 #include <eel/eel-stock-dialogs.h>
 #include <eel/eel-string-list.h>
@@ -117,6 +120,8 @@ 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)
 
@@ -448,6 +453,7 @@ nautilus_application_startup (NautilusAp
 			      gboolean browser_window,
 			      const char *startup_id,
 			      const char *geometry,
+			      const char *session_to_load,
 			      const char *urls[])
 {
 	CORBA_Environment ev;
@@ -615,8 +621,13 @@ nautilus_application_startup (NautilusAp
 			Nautilus_Shell_open_windows (shell, url_list, corba_startup_id, corba_geometry, browser_window, &ev);
 			CORBA_free (url_list);
 		} else if (!no_default_window) {
+			g_assert (session_to_load == NULL);
 			Nautilus_Shell_open_default_window (shell, corba_startup_id, corba_geometry, browser_window, &ev);
 		}
+
+		if (session_to_load != NULL) {
+			Nautilus_Shell_load_session (shell, session_to_load, &ev);
+		}
 		
 		/* Add ourselves to the session */
 		init_session ();
@@ -1129,12 +1140,30 @@ nautilus_application_present_spatial_win
 	return window;
 }
 
+static gboolean
+another_navigation_window_already_showing (NautilusWindow *the_window)
+{
+	GList *list, *item;
+	
+	list = nautilus_application_get_window_list ();
+	for (item = list; item != NULL; item = item->next) {
+		if (item->data != the_window &&
+		    NAUTILUS_IS_NAVIGATION_WINDOW (item->data)) {
+			return TRUE;
+		}
+	}
+	
+	return FALSE;
+}
+
 NautilusWindow *
 nautilus_application_create_navigation_window (NautilusApplication *application,
 					       const char          *startup_id,
 					       GdkScreen           *screen)
 {
 	NautilusWindow *window;
+	char *geometry_string;
+	gboolean maximized;
 
 	g_return_val_if_fail (NAUTILUS_IS_APPLICATION (application), NULL);
 	
@@ -1144,6 +1173,31 @@ nautilus_application_create_navigation_w
 				  startup_id);
 #endif
 
+	maximized = eel_preferences_get_boolean
+			(NAUTILUS_PREFERENCES_NAVIGATION_WINDOW_MAXIMIZED);
+	if (maximized) {
+		gtk_window_maximize (GTK_WINDOW (window));
+	} else {
+		gtk_window_unmaximize (GTK_WINDOW (window));
+	}
+
+	geometry_string = eel_preferences_get
+			(NAUTILUS_PREFERENCES_NAVIGATION_WINDOW_SAVED_GEOMETRY);
+	if (geometry_string != NULL &&
+	    geometry_string[0] != 0) {
+		/* Ignore saved window position if a window with the same
+		 * location is already showing. That way the two windows
+		 * wont appear at the exact same location on the screen.
+		 */
+		eel_gtk_window_set_initial_geometry_from_string 
+			(GTK_WINDOW (window), 
+			 geometry_string,
+			 NAUTILUS_WINDOW_MIN_WIDTH, 
+			 NAUTILUS_WINDOW_MIN_HEIGHT,
+			 another_navigation_window_already_showing (window));
+	}
+	g_free (geometry_string);
+
 	return window;
 }
 
@@ -1273,41 +1327,263 @@ removed_from_session (GnomeClient *clien
 	nautilus_main_event_loop_quit ();
 }
 
-static gint
-save_session (GnomeClient *client, gint phase, GnomeSaveStyle save_style, gint shutdown,
-	      GnomeInteractStyle interact_style, gint fast, gpointer data)
+static char *
+save_session_to_file (void)
 {
-	NautilusWindow *window;
+	xmlDocPtr doc;
+	xmlNodePtr root_node, history_node;
 	GList *l;
-	static char *clone_argv[] = { "nautilus", "--no-default-window" };
-	char **restart_argv;
-	int argc;
-	int i;
-	int num_windows;
-
-	num_windows = g_list_length (nautilus_application_window_list);
-	if (num_windows > 0) {
-		argc = 1 + num_windows;
-		i = 0;
-		restart_argv = g_new (char *, argc);
-		restart_argv[i++] = g_strdup ("nautilus");
-		for (l = nautilus_application_window_list; l != NULL; l = l->next) {
-			window = NAUTILUS_WINDOW (l->data);
-			restart_argv[i++] = nautilus_window_get_location (window);
+	char *dir, *filename;
+	unsigned n_processed;
+
+	doc = xmlNewDoc ("1.0");
+
+	root_node = xmlNewNode (NULL, "session");
+	xmlDocSetRootElement (doc, root_node);
+
+	history_node = xmlNewChild (root_node, NULL, "history", NULL);
+
+	n_processed = 0;
+	for (l = nautilus_get_history_list (); l != NULL; l = l->next) {
+		NautilusBookmark *bookmark;
+		xmlNodePtr bookmark_node;
+		char *tmp;
+
+		bookmark = l->data;
+
+		bookmark_node = xmlNewChild (history_node, NULL, "bookmark", NULL);
+
+		tmp = nautilus_bookmark_get_name (bookmark);
+		xmlNewProp (bookmark_node, "name", tmp);
+		g_free (tmp);
+
+		tmp = nautilus_bookmark_get_icon (bookmark);
+		xmlNewProp (bookmark_node, "icon", tmp);
+		g_free (tmp);
+
+		tmp = nautilus_bookmark_get_uri (bookmark);
+		xmlNewProp (bookmark_node, "uri", tmp);
+		g_free (tmp);
+
+		if (nautilus_bookmark_get_has_custom_name (bookmark)) {
+			xmlNewProp (bookmark_node, "has_custom_name", "TRUE");
 		}
-		
-		gnome_client_set_restart_command (client, argc, restart_argv);
 
-		for (i = 0; i < argc; i++) {
-			g_free (restart_argv[i]);
+		if (++n_processed > 50) { /* prevent history list from growing arbitrarily large. */
+			break;
 		}
-		g_free (restart_argv);
+	}
+
+	for (l = nautilus_application_window_list; l != NULL; l = l->next) {
+		xmlNodePtr win_node;
+		NautilusWindow *window;
+		char *tmp;
+
+		window = l->data;
+
+		win_node = xmlNewChild (root_node, NULL, "window", NULL);
+
+		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 */
+			tmp = eel_gtk_window_get_geometry_string (GTK_WINDOW (window));
+			xmlNewProp (win_node, "geometry", tmp);
+			g_free (tmp);
+
+			if (GTK_WIDGET (window)->window &&
+			    gdk_window_get_state (GTK_WIDGET (window)->window) & GDK_WINDOW_STATE_MAXIMIZED) {
+				xmlNewProp (win_node, "maximized", "TRUE");
+			}
+		}
+
+		tmp = nautilus_window_get_location (window);
+		xmlNewProp (win_node, "location", tmp);
+		g_free (tmp);
+	}
+
+	dir = nautilus_get_user_directory ();
+	filename = tempnam (dir, "saved-session-");
+	g_free (dir);
+
+	xmlIndentTreeOutput = 1;
+	if (filename == NULL || xmlSaveFormatFile (filename, doc, 1) < 0) {
+		g_message ("failed to save session to %s", filename);
+		g_free (filename);
+		filename = NULL;
+	}
+
+	xmlFreeDoc (doc);
+
+	return filename;
+}
+
+void
+nautilus_application_load_session (NautilusApplication *application,
+				   const char *filename)
+{
+	xmlDocPtr doc;
+	gboolean bail;
+
+	g_assert (filename != NULL);
+
+	bail = TRUE;
+
+	if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
+		xmlNodePtr root_node;
+
+		doc = xmlReadFile (filename, NULL, 0);
+		if (doc != NULL && (root_node = xmlDocGetRootElement (doc)) != NULL) {
+			xmlNodePtr node;
+
+			bail = FALSE;
+
+			for (node = root_node->children; node != NULL; node = node->next) {
+
+				if (!strcmp (node->name, "text")) {
+					continue;
+				} else if (!strcmp (node->name, "history")) {
+					xmlNodePtr bookmark_node;
+					gboolean emit_change;
+
+					emit_change = FALSE;
+
+					for (bookmark_node = node->children; bookmark_node != NULL; bookmark_node = bookmark_node->next) {
+						if (!strcmp (bookmark_node->name, "text")) {
+							continue;
+						} else if (!strcmp (bookmark_node->name, "bookmark")) {
+							xmlChar *name, *icon, *uri;
+							gboolean has_custom_name;
+
+							uri = xmlGetProp (bookmark_node, "uri");
+							name = xmlGetProp (bookmark_node, "name");
+							has_custom_name = xmlHasProp (bookmark_node, "has_custom_name") ? TRUE : FALSE;
+							icon = xmlGetProp (bookmark_node, "icon");
+
+							emit_change |= nautilus_add_to_history_list_no_notify (uri, name, has_custom_name, icon);
+
+							xmlFree (name);
+							xmlFree (uri);
+							xmlFree (icon);
+						} else {
+							g_message ("unexpected bookmark node %s while parsing %s", bookmark_node->name, filename);
+							bail = TRUE;
+							continue;
+						}
+					}
+
+					if (emit_change) {
+						nautilus_send_history_list_changed ();
+					}
+				} else if (!strcmp (node->name, "window")) {
+					NautilusWindow *window;
+					xmlChar *type, *location;
+
+					type = xmlGetProp (node, "type");
+					if (type == NULL) {
+						g_message ("empty type node while parsing %s", filename);
+						bail = TRUE;
+						continue;
+					}
+
+					location = xmlGetProp (node, "location");
+					if (location == NULL) {
+						g_message ("empty location node while parsing %s", filename);
+						bail = TRUE;
+						xmlFree (type);
+						continue;
+					}
+
+					if (!strcmp (type, "navigation")) {
+						xmlChar *geometry;
+
+						window = nautilus_application_create_navigation_window (application, NULL, gdk_screen_get_default ());
+
+						geometry = xmlGetProp (node, "geometry");
+						if (geometry != NULL) {
+							eel_gtk_window_set_initial_geometry_from_string 
+								(GTK_WINDOW (window), 
+								 geometry,
+								 NAUTILUS_WINDOW_MIN_WIDTH, 
+								 NAUTILUS_WINDOW_MIN_HEIGHT,
+								 FALSE);
+						}
+						xmlFree (geometry);
+
+						if (xmlHasProp (node, "maximized")) {
+							gtk_window_maximize (GTK_WINDOW (window));
+						} else {
+							gtk_window_unmaximize (GTK_WINDOW (window));
+						}
+
+						nautilus_window_open_location (window, location, FALSE);
+					} else if (!strcmp (type, "spatial")) {
+						window = nautilus_application_present_spatial_window (application, NULL, NULL, location, gdk_screen_get_default ());
+					} else {
+						g_message ("unknown window type \"%s\" while parsing %s", type, filename);
+						bail = TRUE;
+					}
+
+					xmlFree (type);
+					xmlFree (location);
+				} else {
+					g_message ("unexpected node %s while parsing %s", node->name, filename);
+					bail = TRUE;
+					continue;
+				}
+			}
+		}
+
+		if (doc != NULL) {
+			xmlFreeDoc (doc);
+		}
+	}
+
+	if (bail) {
+		g_message ("failed to load session from %s", filename);
 	} else {
-		gnome_client_set_restart_command (client, 
-						  G_N_ELEMENTS (clone_argv), 
-						  clone_argv);
+		char *uri;
+		GnomeVFSFileInfo *info;
+		/* only remove file if it is regular, user-owned and the user has write access. */
+
+		uri = gnome_vfs_get_uri_from_local_path (filename);
+		info = gnome_vfs_file_info_new ();
+		if (uri != NULL &&
+		    gnome_vfs_get_file_info (uri, info, GNOME_VFS_FILE_INFO_DEFAULT) == GNOME_VFS_OK &&
+		    (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_TYPE) &&
+		    (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS) &&
+		    (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_IDS) &&
+		    info->type == GNOME_VFS_FILE_TYPE_REGULAR &&
+		    (info->permissions & (GNOME_VFS_PERM_USER_WRITE |
+					  GNOME_VFS_PERM_USER_WRITE)) &&
+		    info->uid == geteuid ()) {
+			g_remove (filename);
+		}
+		gnome_vfs_file_info_unref (info);
+		g_free (uri);
 	}
-	
+}
+
+static gint
+save_session (GnomeClient *client, gint phase, GnomeSaveStyle save_style, gint shutdown,
+	      GnomeInteractStyle interact_style, gint fast, gpointer data)
+{
+	char *argv[3] = { NULL };
+
+	argv[0] = "nautilus";
+
+	argv[2] = save_session_to_file ();
+	if (argv[2] != NULL) {
+		argv[1] = "--load-session";
+	}
+
+	gnome_client_set_restart_command (client, 
+					  G_N_ELEMENTS (argv), 
+					  argv);
+
+	if (argv[2] != NULL) {
+		g_free (argv[2]);
+	}
+
 	return TRUE;
 }
 
Index: src/nautilus-application.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-application.h,v
retrieving revision 1.40
diff -u -p -r1.40 nautilus-application.h
--- src/nautilus-application.h	26 Feb 2006 11:03:25 -0000	1.40
+++ src/nautilus-application.h	20 Jun 2006 17:52:18 -0000
@@ -69,6 +69,7 @@ void                 nautilus_applicatio
 							     gboolean             browser_window,
 							     const char          *startup_id,
 							     const char          *default_geometry,
+							     const char          *session_to_load,
 							     const char          *urls[]);
 GList *              nautilus_application_get_window_list           (void);
 GList *              nautilus_application_get_spatial_window_list    (void);
@@ -95,5 +96,6 @@ void                 nautilus_applicatio
 void                 nautilus_application_close_all_spatial_windows  (void);
 void                 nautilus_application_open_desktop      (NautilusApplication *application);
 void                 nautilus_application_close_desktop     (void);
-
+void                 nautilus_application_load_session      (NautilusApplication *application,
+							     const char *filename); 
 #endif /* NAUTILUS_APPLICATION_H */
Index: src/nautilus-main.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-main.c,v
retrieving revision 1.156
diff -u -p -r1.156 nautilus-main.c
--- src/nautilus-main.c	26 Apr 2006 12:24:43 -0000	1.156
+++ src/nautilus-main.c	20 Jun 2006 17:52:20 -0000
@@ -190,6 +190,7 @@ main (int argc, char *argv[])
 	gboolean no_desktop;
 	const char *startup_id;
 	char *startup_id_copy;
+	char *session_to_load;
 	gchar *geometry;
 	const gchar **remaining;
 	gboolean perform_self_check;
@@ -216,6 +217,9 @@ main (int argc, char *argv[])
 		{ "restart", '\0', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &restart_shell,
 		  N_("Restart Nautilus."), NULL },
 		{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining, NULL,  N_("[URI...]") },
+		{ "load-session", 'l', 0, G_OPTION_ARG_STRING, &session_to_load,
+		  /* Translators: --no-default-window is a nautilus command line parameter, don't modify it. */
+		  N_("Load a saved session from the specified file. Implies \"--no-default-window\"."), N_("FILENAME") },
 
 		{ NULL }
 	};
@@ -243,6 +247,7 @@ main (int argc, char *argv[])
 	/* Get parameters. */
 	remaining = NULL;
 	geometry = NULL;
+	session_to_load = NULL;
 	kill_shell = FALSE;
 	no_default_window = FALSE;
 	no_desktop = FALSE;
@@ -262,6 +267,10 @@ main (int argc, char *argv[])
 				      GNOME_PARAM_HUMAN_READABLE_NAME, _("Nautilus"),
 				      NULL);
 
+	if (session_to_load != NULL) {
+		no_default_window = TRUE;
+	}
+
 	/* Do this here so that gdk_display is initialized */
 	if (startup_id_copy == NULL) {
 		/* Create a fake one containing a timestamp that we can use */
@@ -349,6 +358,7 @@ main (int argc, char *argv[])
 			 browser_window,
 			 startup_id_copy,
 			 geometry,
+			 session_to_load,
 			 remaining);
 		g_free (startup_id_copy);
 
Index: src/nautilus-navigation-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-navigation-window.c,v
retrieving revision 1.445
diff -u -p -r1.445 nautilus-navigation-window.c
--- src/nautilus-navigation-window.c	18 Mar 2006 07:13:50 -0000	1.445
+++ src/nautilus-navigation-window.c	20 Jun 2006 17:52:25 -0000
@@ -560,6 +560,22 @@ nautilus_navigation_window_unrealize (Gt
 	GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
 }
 
+static gboolean
+nautilus_navigation_window_state_event (GtkWidget *widget,
+					GdkEventWindowState *event)
+{
+	if (event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED) {
+		eel_preferences_set_boolean (NAUTILUS_PREFERENCES_NAVIGATION_WINDOW_MAXIMIZED,
+					     event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED);
+	}
+
+	if (GTK_WIDGET_CLASS (parent_class)->window_state_event != NULL) {
+		return GTK_WIDGET_CLASS (parent_class)->window_state_event (widget, event);
+	}
+
+	return FALSE;
+}
+
 static void
 nautilus_navigation_window_destroy (GtkObject *object)
 {
@@ -1418,8 +1434,7 @@ nautilus_navigation_window_save_geometry
 
 	g_assert (NAUTILUS_IS_WINDOW (window));
 
-	if (GTK_WIDGET(window)->window &&
-	    !(gdk_window_get_state (GTK_WIDGET(window)->window) & GDK_WINDOW_STATE_MAXIMIZED)) {
+	if (GTK_WIDGET(window)->window) {
 		geometry_string = eel_gtk_window_get_geometry_string (GTK_WINDOW (window));
 		
 		if (eel_preferences_key_is_writable (NAUTILUS_PREFERENCES_NAVIGATION_WINDOW_SAVED_GEOMETRY)) {
@@ -1428,6 +1443,12 @@ nautilus_navigation_window_save_geometry
 				 geometry_string);
 		}
 		g_free (geometry_string);
+
+		if (eel_preferences_key_is_writable (NAUTILUS_PREFERENCES_NAVIGATION_WINDOW_MAXIMIZED)) {
+			eel_preferences_set_boolean
+				(NAUTILUS_PREFERENCES_NAVIGATION_WINDOW_MAXIMIZED, 
+				 gdk_window_get_state (GTK_WIDGET (window)->window) & GDK_WINDOW_STATE_MAXIMIZED);
+		}
 	}
 }
 
@@ -1462,6 +1483,7 @@ nautilus_navigation_window_class_init (N
 	GTK_OBJECT_CLASS (class)->destroy = nautilus_navigation_window_destroy;
 	GTK_WIDGET_CLASS (class)->show = nautilus_navigation_window_show;
 	GTK_WIDGET_CLASS (class)->unrealize = nautilus_navigation_window_unrealize;
+	GTK_WIDGET_CLASS (class)->window_state_event = nautilus_navigation_window_state_event;
 	NAUTILUS_WINDOW_CLASS (class)->load_view_as_menu = real_load_view_as_menu;
 	NAUTILUS_WINDOW_CLASS (class)->set_content_view_widget = real_set_content_view_widget;
 	NAUTILUS_WINDOW_CLASS (class)->set_throbber_active = real_set_throbber_active;
Index: src/nautilus-shell-interface.idl
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-shell-interface.idl,v
retrieving revision 1.9
diff -u -p -r1.9 nautilus-shell-interface.idl
--- src/nautilus-shell-interface.idl	19 Oct 2005 07:53:43 -0000	1.9
+++ src/nautilus-shell-interface.idl	20 Jun 2006 17:52:25 -0000
@@ -17,6 +17,7 @@ module Nautilus {
 		void stop_desktop ();
 		void quit ();
 		void restart ();
+		void load_session (in string filename);
 	};
 
 };
Index: src/nautilus-shell.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-shell.c,v
retrieving revision 1.62
diff -u -p -r1.62 nautilus-shell.c
--- src/nautilus-shell.c	7 Apr 2006 22:47:22 -0000	1.62
+++ src/nautilus-shell.c	20 Jun 2006 17:52:26 -0000
@@ -72,6 +72,9 @@ static void     corba_open_default_windo
 						 const CORBA_char       *geometry,
 						 CORBA_boolean           browser_window,
 						 CORBA_Environment      *ev);
+static void     corba_load_session              (PortableServer_Servant  servant,
+						 const CORBA_char       *filename,
+						 CORBA_Environment      *ev);
 static void     corba_start_desktop             (PortableServer_Servant  servant,
 						 CORBA_Environment      *ev);
 static void     corba_stop_desktop              (PortableServer_Servant  servant,
@@ -93,6 +96,7 @@ nautilus_shell_class_init (NautilusShell
 
 	klass->epv.open_windows = corba_open_windows;
 	klass->epv.open_default_window = corba_open_default_window;
+	klass->epv.load_session = corba_load_session;
 	klass->epv.start_desktop = corba_start_desktop;
 	klass->epv.stop_desktop = corba_stop_desktop;
 	klass->epv.quit = corba_quit;
@@ -202,6 +206,20 @@ corba_open_default_window (PortableServe
 		/* Open a window pointing at the default location. */
 		open_window (shell, NULL, startup_id, geometry, browser_window);
 	}
+}
+
+static void
+corba_load_session (PortableServer_Servant servant,
+		    const CORBA_char *filename,
+		    CORBA_Environment *ev)
+{
+	NautilusShell	      *shell;
+	NautilusApplication   *application;
+
+	shell	    = NAUTILUS_SHELL (bonobo_object_from_servant (servant));
+	application = NAUTILUS_APPLICATION (shell->details->application);
+	
+	nautilus_application_load_session (application, filename);
 }
 
 static void
Index: src/nautilus-spatial-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-spatial-window.c,v
retrieving revision 1.459
diff -u -p -r1.459 nautilus-spatial-window.c
--- src/nautilus-spatial-window.c	14 Apr 2006 11:57:23 -0000	1.459
+++ src/nautilus-spatial-window.c	20 Jun 2006 17:52:31 -0000
@@ -192,6 +192,25 @@ nautilus_spatial_window_unrealize (GtkWi
 	}
 }
 
+static gboolean
+nautilus_spatial_window_state_event (GtkWidget *widget,
+				     GdkEventWindowState *event)
+{
+	if (event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED &&
+	    NAUTILUS_WINDOW (widget)->details->viewed_file != NULL) {
+		nautilus_file_set_boolean_metadata (NAUTILUS_WINDOW (widget)->details->viewed_file,
+						    NAUTILUS_METADATA_KEY_WINDOW_MAXIMIZED,
+						    FALSE,
+						    event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED);
+	}
+
+	if (GTK_WIDGET_CLASS (parent_class)->window_state_event != NULL) {
+		return GTK_WIDGET_CLASS (parent_class)->window_state_event (widget, event);
+	}
+
+	return FALSE;
+}
+
 static void
 nautilus_spatial_window_destroy (GtkObject *object)
 {
@@ -984,6 +1003,7 @@ nautilus_spatial_window_class_init (Naut
 	GTK_WIDGET_CLASS (class)->show = nautilus_spatial_window_show;
 	GTK_WIDGET_CLASS (class)->configure_event = nautilus_spatial_window_configure_event;
 	GTK_WIDGET_CLASS (class)->unrealize = nautilus_spatial_window_unrealize;
+	GTK_WIDGET_CLASS (class)->window_state_event = nautilus_spatial_window_state_event;
 
 	NAUTILUS_WINDOW_CLASS (class)->prompt_for_location = 
 		real_prompt_for_location;
Index: src/nautilus-window-manage-views.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window-manage-views.c,v
retrieving revision 1.366
diff -u -p -r1.366 nautilus-window-manage-views.c
--- src/nautilus-window-manage-views.c	8 May 2006 23:12:50 -0000	1.366
+++ src/nautilus-window-manage-views.c	20 Jun 2006 17:52:36 -0000
@@ -657,23 +657,6 @@ nautilus_window_content_view_matches_iid
 }
 
 
-static gboolean
-another_navigation_window_already_showing (NautilusWindow *the_window)
-{
-	GList *list, *item;
-	
-	list = nautilus_application_get_window_list ();
-	for (item = list; item != NULL; item = item->next) {
-		if (item->data != the_window &&
-		    NAUTILUS_IS_NAVIGATION_WINDOW (item->data)) {
-			return TRUE;
-		}
-	}
-	
-	return FALSE;
-}
-
-
 /*
  * begin_location_change
  * 
@@ -783,6 +766,7 @@ setup_new_window (NautilusWindow *window
 	char *show_hidden_file_setting;
 	char *geometry_string;
 	char *scroll_string;
+	gboolean maximized;
 	
 	if (NAUTILUS_IS_SPATIAL_WINDOW (window) && !NAUTILUS_IS_DESKTOP_WINDOW (window)) {
 		/* load show hidden state */
@@ -801,6 +785,14 @@ setup_new_window (NautilusWindow *window
 		g_free (show_hidden_file_setting);
 		
 		/* load the saved window geometry */
+		maximized = nautilus_file_get_boolean_metadata
+			(file, NAUTILUS_METADATA_KEY_WINDOW_MAXIMIZED, FALSE);
+		if (maximized) {
+			gtk_window_maximize (GTK_WINDOW (window));
+		} else {
+			gtk_window_unmaximize (GTK_WINDOW (window));
+		}
+
 		geometry_string = nautilus_file_get_metadata 
 			(file, NAUTILUS_METADATA_KEY_WINDOW_GEOMETRY, NULL);
                 if (geometry_string != NULL) {
@@ -829,25 +821,6 @@ setup_new_window (NautilusWindow *window
 			window->details->pending_scroll_to = scroll_string;
 		}
         }
-	
-        if (NAUTILUS_IS_NAVIGATION_WINDOW (window)) {
-		geometry_string = eel_preferences_get
-				(NAUTILUS_PREFERENCES_NAVIGATION_WINDOW_SAVED_GEOMETRY);
-                if (geometry_string != NULL &&
-		    geometry_string[0] != 0) {
-			/* Ignore saved window position if a window with the same
-			 * location is already showing. That way the two windows
-			 * wont appear at the exact same location on the screen.
-			 */
-                        eel_gtk_window_set_initial_geometry_from_string 
-                                (GTK_WINDOW (window), 
-                                 geometry_string,
-                                 NAUTILUS_WINDOW_MIN_WIDTH, 
-                                 NAUTILUS_WINDOW_MIN_HEIGHT,
-				 another_navigation_window_already_showing (window));
-                }
-                g_free (geometry_string);
-	}
 }
 
 static void
Index: src/nautilus-window-private.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window-private.h,v
retrieving revision 1.113
diff -u -p -r1.113 nautilus-window-private.h
--- src/nautilus-window-private.h	20 Mar 2006 18:40:38 -0000	1.113
+++ src/nautilus-window-private.h	20 Jun 2006 17:52:37 -0000
@@ -203,6 +203,10 @@ void               nautilus_window_set_v
 void               nautilus_send_history_list_changed                    (void);
 void               nautilus_window_add_current_location_to_history_list  (NautilusWindow    *window);
 void               nautilus_remove_from_history_list_no_notify           (const char        *location);
+gboolean           nautilus_add_to_history_list_no_notify                (const char        *location,
+									  const char        *name,
+									  gboolean           has_custom_name,
+									  const char        *icon);
 GList *            nautilus_get_history_list                             (void);
 void               nautilus_window_bookmarks_preference_changed_callback (gpointer           user_data);
 void		   nautilus_window_update_icon				 (NautilusWindow    *window);
Index: src/nautilus-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window.c,v
retrieving revision 1.463
diff -u -p -r1.463 nautilus-window.c
--- src/nautilus-window.c	20 Mar 2006 18:40:38 -0000	1.463
+++ src/nautilus-window.c	20 Jun 2006 17:52:43 -0000
@@ -1352,7 +1352,7 @@ remove_from_history_list (NautilusBookma
 	}
 }
 
-static void
+static gboolean
 add_to_history_list (NautilusBookmark *bookmark)
 {
 	/* Note that the history is shared amongst all windows so
@@ -1389,8 +1389,10 @@ add_to_history_list (NautilusBookmark *b
 			}
 		}
 
-		nautilus_send_history_list_changed ();
+		return TRUE;
 	}
+
+	return FALSE;
 }
 
 void
@@ -1403,12 +1405,30 @@ nautilus_remove_from_history_list_no_not
 	g_object_unref (bookmark);
 }
 
+gboolean
+nautilus_add_to_history_list_no_notify (const char *uri,
+					const char *name,
+					gboolean has_custom_name,
+					const char *icon)
+{
+	NautilusBookmark *bookmark;
+	gboolean ret;
+
+	bookmark = nautilus_bookmark_new_with_icon (uri, name, has_custom_name, icon);
+	ret = add_to_history_list (bookmark);
+	g_object_unref (bookmark);
+
+	return ret;
+}
+
 static void
 real_add_current_location_to_history_list (NautilusWindow *window)
 {
         g_assert (NAUTILUS_IS_WINDOW (window));
                 
-        add_to_history_list (window->current_location_bookmark);
+	if (add_to_history_list (window->current_location_bookmark)) {
+		nautilus_send_history_list_changed ();
+	}
 }
 
 void


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