[nautilus/gtk3-breakage] application: split SmClient code in its own module.



commit 940f8cb55e3ae423a734c540b0bbf413553e1b53
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Oct 26 17:29:48 2010 +0200

    application: split SmClient code in its own module.

 src/Makefile.am                     |    2 +
 src/nautilus-application-smclient.c |  454 ++++++++++++++++++++++++++++
 src/nautilus-application-smclient.h |   32 ++
 src/nautilus-application.c          |  556 +++++------------------------------
 4 files changed, 559 insertions(+), 485 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 7c9c8c9..2152e7e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -60,6 +60,8 @@ nautilus_SOURCES = \
 	nautilus-actions.h			\
 	nautilus-application.c			\
 	nautilus-application.h			\
+	nautilus-application-smclient.c		\
+	nautilus-application-smclient.h		\
 	nautilus-bookmark-list.c		\
 	nautilus-bookmark-list.h		\
 	nautilus-bookmarks-window.c		\
diff --git a/src/nautilus-application-smclient.c b/src/nautilus-application-smclient.c
new file mode 100644
index 0000000..6f74205
--- /dev/null
+++ b/src/nautilus-application-smclient.c
@@ -0,0 +1,454 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * nautilus-application-smclient: a little module for session handling.
+ *
+ * Copyright (C) 2000 Red Hat, Inc.
+ * Copyright (C) 2010 Cosimo Cecchi <cosimoc gnome org>
+ *
+ * Nautilus is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * Nautilus is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "nautilus-application-smclient.h"
+
+#include "nautilus-main.h"
+#include "nautilus-navigation-window.h"
+#include "nautilus-window-private.h"
+#include "nautilus-window-slot.h"
+
+#include <eel/eel-gtk-extensions.h>
+#include <libxml/xmlsave.h>
+
+static char *
+icon_to_string (GIcon *icon)
+{
+	const char * const *names;
+	GFile *file;
+	
+	if (icon == NULL) {
+		return NULL;
+	} else if (G_IS_THEMED_ICON (icon)) {
+		names = g_themed_icon_get_names (G_THEMED_ICON (icon));
+		return g_strjoinv (":", (char **)names);		
+	} else if (G_IS_FILE_ICON (icon)) {
+		file = g_file_icon_get_file (G_FILE_ICON (icon));
+		return g_file_get_path (file);
+	}
+	return NULL;
+}
+
+static char *
+nautilus_application_get_session_data (NautilusApplication *self)
+{
+	xmlDocPtr doc;
+	xmlNodePtr root_node, history_node;
+	GList *l, *window_list;
+	char *data;
+	unsigned n_processed;
+	xmlSaveCtxtPtr ctx;
+	xmlBufferPtr buffer;
+
+	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;
+		GIcon *icon;
+		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);
+
+		icon = nautilus_bookmark_get_icon (bookmark);
+		tmp = icon_to_string (icon);
+		g_object_unref (icon);
+		if (tmp) {
+			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");
+		}
+
+		if (++n_processed > 50) { /* prevent history list from growing arbitrarily large. */
+			break;
+		}
+	}
+
+	window_list = nautilus_application_get_window_list ();
+
+	for (l = window_list; l != NULL; l = l->next) {
+		xmlNodePtr win_node, slot_node;
+		NautilusWindow *window;
+		NautilusWindowSlot *slot, *active_slot;
+		GList *slots, *m;
+		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 */
+			GdkWindow *gdk_window;
+
+			tmp = eel_gtk_window_get_geometry_string (GTK_WINDOW (window));
+			xmlNewProp (win_node, "geometry", tmp);
+			g_free (tmp);
+
+			gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
+
+			if (gdk_window &&
+			    gdk_window_get_state (gdk_window) & GDK_WINDOW_STATE_MAXIMIZED) {
+				xmlNewProp (win_node, "maximized", "TRUE");
+			}
+
+			if (gdk_window &&
+			    gdk_window_get_state (gdk_window) & GDK_WINDOW_STATE_STICKY) {
+				xmlNewProp (win_node, "sticky", "TRUE");
+			}
+
+			if (gdk_window &&
+			    gdk_window_get_state (gdk_window) & GDK_WINDOW_STATE_ABOVE) {
+				xmlNewProp (win_node, "keep-above", "TRUE");
+			}
+		}
+
+		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);
+
+			slot_node = xmlNewChild (win_node, NULL, "slot", NULL);
+
+			tmp = nautilus_window_slot_get_location_uri (slot);
+			xmlNewProp (slot_node, "location", tmp);
+			g_free (tmp);
+
+			if (slot == active_slot) {
+				xmlNewProp (slot_node, "active", "TRUE");
+			}
+		}
+
+		g_list_free (slots);
+	}
+
+	buffer = xmlBufferCreate ();
+	xmlIndentTreeOutput = 1;
+	ctx = xmlSaveToBuffer (buffer, "UTF-8", XML_SAVE_FORMAT);
+	if (xmlSaveDoc (ctx, doc) < 0 ||
+	    xmlSaveFlush (ctx) < 0) {
+		g_message ("failed to save session");
+	}
+	
+	xmlSaveClose(ctx);
+	data = g_strndup (buffer->content, buffer->use);
+	xmlBufferFree (buffer);
+
+	xmlFreeDoc (doc);
+
+	return data;
+}
+
+static GIcon *
+icon_from_string (const char *string)
+{
+	GFile *file;
+	GIcon *icon;
+	gchar **names;
+	
+	if (g_path_is_absolute (string)) {
+		file = g_file_new_for_path (string);
+		icon = g_file_icon_new (file);
+		g_object_unref (file);
+		return icon;
+	} else {
+		names = g_strsplit (string, ":", 0);
+		icon = g_themed_icon_new_from_names (names, -1);
+		g_strfreev (names);
+		return icon;
+	}
+	return NULL;
+}
+
+void
+nautilus_application_smclient_load (NautilusApplication *application)
+{
+	xmlDocPtr doc;
+	gboolean bail;
+	xmlNodePtr root_node;
+	GKeyFile *state_file;
+	char *data;
+
+	if (!egg_sm_client_is_resumed (application->smclient)) {
+		return;
+	}
+
+	state_file = egg_sm_client_get_state_file (application->smclient);
+	if (!state_file) {
+		return;
+	}
+
+	data = g_key_file_get_string (state_file,
+				      "Nautilus",
+				      "documents",
+				      NULL);
+	if (data == NULL) {
+		return;
+	}
+	
+	bail = TRUE;
+
+	doc = xmlReadMemory (data, strlen (data), NULL, "UTF-8", 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_str, *uri;
+						gboolean has_custom_name;
+						GIcon *icon;
+						GFile *location;
+						
+						uri = xmlGetProp (bookmark_node, "uri");
+						name = xmlGetProp (bookmark_node, "name");
+						has_custom_name = xmlHasProp (bookmark_node, "has_custom_name") ? TRUE : FALSE;
+						icon_str = xmlGetProp (bookmark_node, "icon");
+						icon = NULL;
+						if (icon_str) {
+							icon = icon_from_string (icon_str);
+						}
+						location = g_file_new_for_uri (uri);
+						
+						emit_change |= nautilus_add_to_history_list_no_notify (location, name, has_custom_name, icon);
+						
+						g_object_unref (location);
+						
+						if (icon) {
+							g_object_unref (icon);
+						}
+						xmlFree (name);
+						xmlFree (uri);
+						xmlFree (icon_str);
+					} else {
+						g_message ("unexpected bookmark node %s while parsing session data", bookmark_node->name);
+						bail = TRUE;
+						continue;
+					}
+				}
+				
+				if (emit_change) {
+					nautilus_send_history_list_changed ();
+				}
+			} else if (!strcmp (node->name, "window")) {
+				NautilusWindow *window;
+				xmlChar *type, *location_uri, *slot_uri;
+				xmlNodePtr slot_node;
+				GFile *location;
+				int i;
+				
+				type = xmlGetProp (node, "type");
+				if (type == NULL) {
+					g_message ("empty type node while parsing session data");
+					bail = TRUE;
+					continue;
+				}
+				
+				location_uri = xmlGetProp (node, "location");
+				if (location_uri == NULL) {
+					g_message ("empty location node while parsing session data");
+					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_NAVIGATION_WINDOW_MIN_WIDTH,
+							 NAUTILUS_NAVIGATION_WINDOW_MIN_HEIGHT,
+							 FALSE);
+					}
+					xmlFree (geometry);
+					
+					if (xmlHasProp (node, "maximized")) {
+						gtk_window_maximize (GTK_WINDOW (window));
+					} else {
+						gtk_window_unmaximize (GTK_WINDOW (window));
+					}
+					
+					if (xmlHasProp (node, "sticky")) {
+						gtk_window_stick (GTK_WINDOW (window));
+					} else {
+						gtk_window_unstick (GTK_WINDOW (window));
+					}
+					
+					if (xmlHasProp (node, "keep-above")) {
+						gtk_window_set_keep_above (GTK_WINDOW (window), TRUE);
+					} else {
+						gtk_window_set_keep_above (GTK_WINDOW (window), FALSE);
+					}
+					
+					for (i = 0, slot_node = node->children; slot_node != NULL; slot_node = slot_node->next) {
+						if (!strcmp (slot_node->name, "slot")) {
+							slot_uri = xmlGetProp (slot_node, "location");
+							if (slot_uri != NULL) {
+								NautilusWindowSlot *slot;
+								
+								if (i == 0) {
+									slot = window->details->active_pane->active_slot;
+								} else {
+									slot = nautilus_window_open_slot (window->details->active_pane, NAUTILUS_WINDOW_OPEN_SLOT_APPEND);
+								}
+								
+								location = g_file_new_for_uri (slot_uri);
+								nautilus_window_slot_open_location (slot, location, FALSE);
+								
+								if (xmlHasProp (slot_node, "active")) {
+									nautilus_window_set_active_slot (slot->pane->window, slot);
+								}
+								
+								i++;
+							}
+							xmlFree (slot_uri);
+						}
+					}
+					
+					if (i == 0) {
+						/* This may be an old session file */
+						location = g_file_new_for_uri (location_uri);
+						nautilus_window_slot_open_location (window->details->active_pane->active_slot, location, FALSE);
+						g_object_unref (location);
+					}
+				} else if (!strcmp (type, "spatial")) {
+					location = g_file_new_for_uri (location_uri);
+					window = nautilus_application_get_spatial_window (application, NULL, NULL,
+											  location, gdk_screen_get_default (),
+											  NULL);
+
+					nautilus_window_go_to (window, location);
+
+					g_object_unref (location);
+				} else {
+					g_message ("unknown window type \"%s\" while parsing session data", type);
+					bail = TRUE;
+				}
+				
+				xmlFree (type);
+				xmlFree (location_uri);
+			} else {
+				g_message ("unexpected node %s while parsing session data", node->name);
+				bail = TRUE;
+				continue;
+			}
+		}
+	}
+	
+	if (doc != NULL) {
+		xmlFreeDoc (doc);
+	}
+
+	g_free (data);
+
+	if (bail) {
+		g_message ("failed to load session");
+	} 
+}
+
+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_main_event_loop_quit (TRUE);
+}
+
+void
+nautilus_application_smclient_init (NautilusApplication *self)
+{
+	g_assert (self->smclient == NULL);
+
+        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? */
+}
diff --git a/src/nautilus-application-smclient.h b/src/nautilus-application-smclient.h
new file mode 100644
index 0000000..fb50302
--- /dev/null
+++ b/src/nautilus-application-smclient.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * nautilus-application-smclient: a little module for session handling.
+ *
+ * Copyright (C) 2000 Red Hat, Inc.
+ * Copyright (C) 2010 Cosimo Cecchi <cosimoc gnome org>
+ *
+ * Nautilus is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * Nautilus is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __NAUTILUS_APPLICATION_SMCLIENT_H__
+#define __NAUTILUS_APPLICATION_SMCLIENT_H__
+
+#include "nautilus-application.h"
+
+void nautilus_application_smclient_init (NautilusApplication *self);
+void nautilus_application_smclient_load (NautilusApplication *self);
+
+#endif /* __NAUTILUS_APPLICATION_SMCLIENT_H__ */
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index 22da591..87676ec 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -26,6 +26,7 @@
  */
 
 #include <config.h>
+
 #include "nautilus-application.h"
 
 #include "file-manager/fm-desktop-icon-view.h"
@@ -35,37 +36,26 @@
 #if ENABLE_EMPTY_VIEW
 #include "file-manager/fm-empty-view.h"
 #endif /* ENABLE_EMPTY_VIEW */
+
 #include "nautilus-history-sidebar.h"
 #include "nautilus-places-sidebar.h"
 #include "nautilus-notes-viewer.h"
 #include "nautilus-image-properties-page.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <string.h>
+#include "nautilus-application-smclient.h"
 #include "nautilus-desktop-window.h"
-#include "nautilus-main.h"
 #include "nautilus-spatial-window.h"
+#include "nautilus-main.h"
 #include "nautilus-navigation-window.h"
 #include "nautilus-window-slot.h"
 #include "nautilus-navigation-window-slot.h"
 #include "nautilus-window-bookmarks.h"
-#include "libnautilus-private/nautilus-file-operations.h"
 #include "nautilus-window-private.h"
 #include "nautilus-window-manage-views.h"
-#include <unistd.h>
-#include <errno.h>
-#include <libxml/xmlsave.h>
-#include <glib/gstdio.h>
-#include <glib/gi18n.h>
-#include <gio/gio.h>
-#include <eel/eel-gtk-extensions.h>
-#include <eel/eel-gtk-macros.h>
-#include <eel/eel-stock-dialogs.h>
-#include <gdk/gdkx.h>
-#include <gtk/gtk.h>
+
+#include <libnautilus-private/nautilus-autorun.h>
 #include <libnautilus-private/nautilus-debug-log.h>
 #include <libnautilus-private/nautilus-file-utilities.h>
+#include <libnautilus-private/nautilus-file-operations.h>
 #include <libnautilus-private/nautilus-global-preferences.h>
 #include <libnautilus-private/nautilus-module.h>
 #include <libnautilus-private/nautilus-undo-manager.h>
@@ -73,7 +63,15 @@
 #include <libnautilus-private/nautilus-directory-private.h>
 #include <libnautilus-private/nautilus-signaller.h>
 #include <libnautilus-extension/nautilus-menu-provider.h>
-#include <libnautilus-private/nautilus-autorun.h>
+
+#include <glib/gstdio.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <eel/eel-gtk-extensions.h>
+#include <eel/eel-gtk-macros.h>
+#include <eel/eel-stock-dialogs.h>
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
 
 enum
 {
@@ -120,8 +118,6 @@ static void     drive_connected_callback           (GVolumeMonitor           *mo
 						    NautilusApplication      *application);
 static void     drive_listen_for_eject_button      (GDrive *drive, 
 						    NautilusApplication *application);
-static void     nautilus_application_load_session     (NautilusApplication *application); 
-static char *   nautilus_application_get_session_data (void);
 
 G_DEFINE_TYPE (NautilusApplication, nautilus_application, G_TYPE_OBJECT);
 
@@ -251,112 +247,6 @@ automount_all_volumes (NautilusApplication *application)
 	
 }
 
-static void
-smclient_save_state_cb (EggSMClient   *client,
-			GKeyFile      *state_file,
-			NautilusApplication *application)
-{
-	char *data;
-
-	data = nautilus_application_get_session_data ();
-	if (data) {
-		g_key_file_set_string (state_file,
-				       "Nautilus",
-				       "documents", 
-				       data);
-	}
-	g_free (data);
-}
-
-static void
-smclient_quit_cb (EggSMClient   *client,
-		  NautilusApplication *application)
-{
-	nautilus_main_event_loop_quit (TRUE);
-}
-
-static void
-nautilus_application_init (NautilusApplication *application)
-{
-	/* Create an undo manager */
-	application->undo_manager = nautilus_undo_manager_new ();
-
-	application->unique_app = unique_app_new_with_commands ("org.gnome.Nautilus", NULL,
-								"start_desktop", COMMAND_START_DESKTOP,
-								"stop_desktop", COMMAND_STOP_DESKTOP,
-								"open_browser", COMMAND_OPEN_BROWSER,
-								NULL);
-
-	
-        application->smclient = egg_sm_client_get ();
-        g_signal_connect (application->smclient, "save_state",
-                          G_CALLBACK (smclient_save_state_cb),
-                          application);
-	g_signal_connect (application->smclient, "quit",
-			  G_CALLBACK (smclient_quit_cb),
-			  application);
-	/* TODO: Should connect to quit_requested and block logout on active transfer? */
-	
-	/* register views */
-	fm_icon_view_register ();
-	fm_desktop_icon_view_register ();
-	fm_list_view_register ();
-	fm_compact_view_register ();
-#if ENABLE_EMPTY_VIEW
-	fm_empty_view_register ();
-#endif /* ENABLE_EMPTY_VIEW */
-
-	/* register sidebars */
-	nautilus_places_sidebar_register ();
-	fm_tree_view_register ();
-	nautilus_history_sidebar_register ();
-	nautilus_notes_viewer_register (); /* also property page */
-
-	/* register property pages */
-	nautilus_image_properties_page_register ();
-
-	/* initialize search path for custom icons */
-	gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
-					   NAUTILUS_DATADIR G_DIR_SEPARATOR_S "icons");
-}
-
-NautilusApplication *
-nautilus_application_new (void)
-{
-	return g_object_new (NAUTILUS_TYPE_APPLICATION, NULL);
-}
-
-static void
-nautilus_application_finalize (GObject *object)
-{
-	NautilusApplication *application;
-
-	application = NAUTILUS_APPLICATION (object);
-
-	nautilus_bookmarks_exiting ();
-	
-	g_object_unref (application->undo_manager);
-
-	if (application->volume_monitor) {
-		g_object_unref (application->volume_monitor);
-		application->volume_monitor = NULL;
-	}
-
-	g_object_unref (application->unique_app);
-
-	if (application->automount_idle_id != 0) {
-		g_source_remove (application->automount_idle_id);
-		application->automount_idle_id = 0;
-	}
-
-	if (application->proxy != NULL) {
-		g_object_unref (application->proxy);
-		application->proxy = NULL;
-	}
-
-        G_OBJECT_CLASS (nautilus_application_parent_class)->finalize (object);
-}
-
 static gboolean
 check_required_directories (NautilusApplication *application)
 {
@@ -994,7 +884,7 @@ nautilus_application_startup (NautilusApplication *application,
 		}
 
 		/* Load session info if availible */
-		nautilus_application_load_session (application);
+		nautilus_application_smclient_load (application);
 		
 		/* load accelerator map, and register save callback */
 		accel_map_filename = nautilus_get_accel_map_file ();
@@ -1747,383 +1637,73 @@ mount_removed_callback (GVolumeMonitor *monitor,
 	g_list_free (close_list);
 }
 
-static char *
-icon_to_string (GIcon *icon)
-{
-	const char * const *names;
-	GFile *file;
-	
-	if (icon == NULL) {
-		return NULL;
-	} else if (G_IS_THEMED_ICON (icon)) {
-		names = g_themed_icon_get_names (G_THEMED_ICON (icon));
-		return g_strjoinv (":", (char **)names);		
-	} else if (G_IS_FILE_ICON (icon)) {
-		file = g_file_icon_get_file (G_FILE_ICON (icon));
-		return g_file_get_path (file);
-	}
-	return NULL;
-}
-
-static GIcon *
-icon_from_string (const char *string)
-{
-	GFile *file;
-	GIcon *icon;
-	gchar **names;
-	
-	if (g_path_is_absolute (string)) {
-		file = g_file_new_for_path (string);
-		icon = g_file_icon_new (file);
-		g_object_unref (file);
-		return icon;
-	} else {
-		names = g_strsplit (string, ":", 0);
-		icon = g_themed_icon_new_from_names (names, -1);
-		g_strfreev (names);
-		return icon;
-	}
-	return NULL;
-}
-
-static char *
-nautilus_application_get_session_data (void)
+static void
+nautilus_application_init (NautilusApplication *application)
 {
-	xmlDocPtr doc;
-	xmlNodePtr root_node, history_node;
-	GList *l;
-	char *data;
-	unsigned n_processed;
-	xmlSaveCtxtPtr ctx;
-	xmlBufferPtr buffer;
-
-	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;
-		GIcon *icon;
-		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);
-
-		icon = nautilus_bookmark_get_icon (bookmark);
-		tmp = icon_to_string (icon);
-		g_object_unref (icon);
-		if (tmp) {
-			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");
-		}
-
-		if (++n_processed > 50) { /* prevent history list from growing arbitrarily large. */
-			break;
-		}
-	}
-
-	for (l = nautilus_application_window_list; l != NULL; l = l->next) {
-		xmlNodePtr win_node, slot_node;
-		NautilusWindow *window;
-		NautilusWindowSlot *slot, *active_slot;
-		GList *slots, *m;
-		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 */
-			GdkWindow *gdk_window;
-
-			tmp = eel_gtk_window_get_geometry_string (GTK_WINDOW (window));
-			xmlNewProp (win_node, "geometry", tmp);
-			g_free (tmp);
-
-			gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
-
-			if (gdk_window &&
-			    gdk_window_get_state (gdk_window) & GDK_WINDOW_STATE_MAXIMIZED) {
-				xmlNewProp (win_node, "maximized", "TRUE");
-			}
-
-			if (gdk_window &&
-			    gdk_window_get_state (gdk_window) & GDK_WINDOW_STATE_STICKY) {
-				xmlNewProp (win_node, "sticky", "TRUE");
-			}
-
-			if (gdk_window &&
-			    gdk_window_get_state (gdk_window) & GDK_WINDOW_STATE_ABOVE) {
-				xmlNewProp (win_node, "keep-above", "TRUE");
-			}
-		}
-
-		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);
-
-			slot_node = xmlNewChild (win_node, NULL, "slot", NULL);
+	/* Create an undo manager */
+	application->undo_manager = nautilus_undo_manager_new ();
 
-			tmp = nautilus_window_slot_get_location_uri (slot);
-			xmlNewProp (slot_node, "location", tmp);
-			g_free (tmp);
+	application->unique_app = unique_app_new_with_commands ("org.gnome.Nautilus", NULL,
+								"start_desktop", COMMAND_START_DESKTOP,
+								"stop_desktop", COMMAND_STOP_DESKTOP,
+								"open_browser", COMMAND_OPEN_BROWSER,
+								NULL);
 
-			if (slot == active_slot) {
-				xmlNewProp (slot_node, "active", "TRUE");
-			}
-		}
+	/* initialize the session manager client */
+	nautilus_application_smclient_init (application);
 
-		g_list_free (slots);
-	}
+	/* register views */
+	fm_icon_view_register ();
+	fm_desktop_icon_view_register ();
+	fm_list_view_register ();
+	fm_compact_view_register ();
+#if ENABLE_EMPTY_VIEW
+	fm_empty_view_register ();
+#endif /* ENABLE_EMPTY_VIEW */
 
-	buffer = xmlBufferCreate ();
-	xmlIndentTreeOutput = 1;
-	ctx = xmlSaveToBuffer (buffer, "UTF-8", XML_SAVE_FORMAT);
-	if (xmlSaveDoc (ctx, doc) < 0 ||
-	    xmlSaveFlush (ctx) < 0) {
-		g_message ("failed to save session");
-	}
-	
-	xmlSaveClose(ctx);
-	data = g_strndup (buffer->content, buffer->use);
-	xmlBufferFree (buffer);
+	/* register sidebars */
+	nautilus_places_sidebar_register ();
+	fm_tree_view_register ();
+	nautilus_history_sidebar_register ();
+	nautilus_notes_viewer_register (); /* also property page */
 
-	xmlFreeDoc (doc);
+	/* register property pages */
+	nautilus_image_properties_page_register ();
 
-	return data;
+	/* initialize search path for custom icons */
+	gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
+					   NAUTILUS_DATADIR G_DIR_SEPARATOR_S "icons");
 }
 
-void
-nautilus_application_load_session (NautilusApplication *application)
+static void
+nautilus_application_finalize (GObject *object)
 {
-	xmlDocPtr doc;
-	gboolean bail;
-	xmlNodePtr root_node;
-	GKeyFile *state_file;
-	char *data;
-
-	if (!egg_sm_client_is_resumed (application->smclient)) {
-		return;
-	}
+	NautilusApplication *application;
 
-	state_file = egg_sm_client_get_state_file (application->smclient);
-	if (!state_file) {
-		return;
-	}
+	application = NAUTILUS_APPLICATION (object);
 
-	data = g_key_file_get_string (state_file,
-				      "Nautilus",
-				      "documents",
-				      NULL);
-	if (data == NULL) {
-		return;
-	}
+	nautilus_bookmarks_exiting ();
 	
-	bail = TRUE;
+	g_object_unref (application->undo_manager);
 
-	doc = xmlReadMemory (data, strlen (data), NULL, "UTF-8", 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_str, *uri;
-						gboolean has_custom_name;
-						GIcon *icon;
-						GFile *location;
-						
-						uri = xmlGetProp (bookmark_node, "uri");
-						name = xmlGetProp (bookmark_node, "name");
-						has_custom_name = xmlHasProp (bookmark_node, "has_custom_name") ? TRUE : FALSE;
-						icon_str = xmlGetProp (bookmark_node, "icon");
-						icon = NULL;
-						if (icon_str) {
-							icon = icon_from_string (icon_str);
-						}
-						location = g_file_new_for_uri (uri);
-						
-						emit_change |= nautilus_add_to_history_list_no_notify (location, name, has_custom_name, icon);
-						
-						g_object_unref (location);
-						
-						if (icon) {
-							g_object_unref (icon);
-						}
-						xmlFree (name);
-						xmlFree (uri);
-						xmlFree (icon_str);
-					} else {
-						g_message ("unexpected bookmark node %s while parsing session data", bookmark_node->name);
-						bail = TRUE;
-						continue;
-					}
-				}
-				
-				if (emit_change) {
-					nautilus_send_history_list_changed ();
-				}
-			} else if (!strcmp (node->name, "window")) {
-				NautilusWindow *window;
-				xmlChar *type, *location_uri, *slot_uri;
-				xmlNodePtr slot_node;
-				GFile *location;
-				int i;
-				
-				type = xmlGetProp (node, "type");
-				if (type == NULL) {
-					g_message ("empty type node while parsing session data");
-					bail = TRUE;
-					continue;
-				}
-				
-				location_uri = xmlGetProp (node, "location");
-				if (location_uri == NULL) {
-					g_message ("empty location node while parsing session data");
-					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_NAVIGATION_WINDOW_MIN_WIDTH,
-							 NAUTILUS_NAVIGATION_WINDOW_MIN_HEIGHT,
-							 FALSE);
-					}
-					xmlFree (geometry);
-					
-					if (xmlHasProp (node, "maximized")) {
-						gtk_window_maximize (GTK_WINDOW (window));
-					} else {
-						gtk_window_unmaximize (GTK_WINDOW (window));
-					}
-					
-					if (xmlHasProp (node, "sticky")) {
-						gtk_window_stick (GTK_WINDOW (window));
-					} else {
-						gtk_window_unstick (GTK_WINDOW (window));
-					}
-					
-					if (xmlHasProp (node, "keep-above")) {
-						gtk_window_set_keep_above (GTK_WINDOW (window), TRUE);
-					} else {
-						gtk_window_set_keep_above (GTK_WINDOW (window), FALSE);
-					}
-					
-					for (i = 0, slot_node = node->children; slot_node != NULL; slot_node = slot_node->next) {
-						if (!strcmp (slot_node->name, "slot")) {
-							slot_uri = xmlGetProp (slot_node, "location");
-							if (slot_uri != NULL) {
-								NautilusWindowSlot *slot;
-								
-								if (i == 0) {
-									slot = window->details->active_pane->active_slot;
-								} else {
-									slot = nautilus_window_open_slot (window->details->active_pane, NAUTILUS_WINDOW_OPEN_SLOT_APPEND);
-								}
-								
-								location = g_file_new_for_uri (slot_uri);
-								nautilus_window_slot_open_location (slot, location, FALSE);
-								
-								if (xmlHasProp (slot_node, "active")) {
-									nautilus_window_set_active_slot (slot->pane->window, slot);
-								}
-								
-								i++;
-							}
-							xmlFree (slot_uri);
-						}
-					}
-					
-					if (i == 0) {
-						/* This may be an old session file */
-						location = g_file_new_for_uri (location_uri);
-						nautilus_window_slot_open_location (window->details->active_pane->active_slot, location, FALSE);
-						g_object_unref (location);
-					}
-				} else if (!strcmp (type, "spatial")) {
-					location = g_file_new_for_uri (location_uri);
-					window = nautilus_application_get_spatial_window (application, NULL, NULL,
-											  location, gdk_screen_get_default (),
-											  NULL);
+	if (application->volume_monitor) {
+		g_object_unref (application->volume_monitor);
+		application->volume_monitor = NULL;
+	}
 
-					nautilus_window_go_to (window, location);
+	g_object_unref (application->unique_app);
 
-					g_object_unref (location);
-				} else {
-					g_message ("unknown window type \"%s\" while parsing session data", type);
-					bail = TRUE;
-				}
-				
-				xmlFree (type);
-				xmlFree (location_uri);
-			} else {
-				g_message ("unexpected node %s while parsing session data", node->name);
-				bail = TRUE;
-				continue;
-			}
-		}
-	}
-	
-	if (doc != NULL) {
-		xmlFreeDoc (doc);
+	if (application->automount_idle_id != 0) {
+		g_source_remove (application->automount_idle_id);
+		application->automount_idle_id = 0;
 	}
 
-	g_free (data);
+	if (application->proxy != NULL) {
+		g_object_unref (application->proxy);
+		application->proxy = NULL;
+	}
 
-	if (bail) {
-		g_message ("failed to load session");
-	} 
+        G_OBJECT_CLASS (nautilus_application_parent_class)->finalize (object);
 }
 
 static void
@@ -2134,3 +1714,9 @@ nautilus_application_class_init (NautilusApplicationClass *class)
         object_class = G_OBJECT_CLASS (class);
         object_class->finalize = nautilus_application_finalize;
 }
+
+NautilusApplication *
+nautilus_application_new (void)
+{
+	return g_object_new (NAUTILUS_TYPE_APPLICATION, NULL);
+}



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