Index: src/nautilus-toolbars-model.c
===================================================================
RCS file: src/nautilus-toolbars-model.c
diff -N src/nautilus-toolbars-model.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/nautilus-toolbars-model.c	12 Nov 2005 18:22:03 -0000
@@ -0,0 +1,302 @@
+/*
+ *  Copyright (C) 2002-2004 Marco Pesenti Gritti
+ *  Copyright (C) 2003, 2004 Christian Persch
+ *  Copyright (C) 2005 Christian Neumair
+ *
+ *  This program 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, or (at your option)
+ *  any later version.
+ *
+ *  This program 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.
+ *
+ *  $Id: nautilus-toolbars-model.c,v 1.36 2005/02/09 21:08:03 chpe Exp $
+ */
+
+#include "config.h"
+
+#include "nautilus-toolbars-model.h"
+//#include "eel-gconf-extensions.h"
+#include <nautilus-file-utilities.h>
+#include <cut-n-paste-code/libegg/eggtypebuiltins.h>
+
+#include <string.h>
+
+#define NAUTILUS_TOOLBARS_XML_FILE	"toolbars.xml"
+
+#define NAUTILUS_TOOLBARS_MODEL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), NAUTILUS_TYPE_TOOLBARS_MODEL, NautilusToolbarsModelDetails))
+
+struct _NautilusToolbarsModelDetails
+{
+	char *xml_file;
+	EggTbModelFlags style;
+	guint timeout;
+	guint style_notifier_id;
+};
+
+static void nautilus_toolbars_model_class_init (NautilusToolbarsModelClass *klass);
+static void nautilus_toolbars_model_init       (NautilusToolbarsModel *model);
+
+static GObjectClass *parent_class = NULL;
+
+GType
+nautilus_toolbars_model_get_type (void)
+{
+	static GType type = 0;
+
+	if (G_UNLIKELY (type == 0))
+	{
+		static const GTypeInfo our_info = {
+		sizeof (NautilusToolbarsModelClass),
+		NULL,			/* base_init */
+		NULL,			/* base_finalize */
+		(GClassInitFunc) nautilus_toolbars_model_class_init,
+		NULL,
+		NULL,			/* class_data */
+		sizeof (NautilusToolbarsModel),
+		0,			/* n_preallocs */
+		(GInstanceInitFunc) nautilus_toolbars_model_init
+	};
+
+	type = g_type_register_static (EGG_TYPE_TOOLBARS_MODEL,
+				       "NautilusToolbarsModel",
+				       &our_info, 0);
+	}
+
+	return type;
+}
+
+static gboolean
+save_changes_idle (NautilusToolbarsModel *model)
+{
+	egg_toolbars_model_save
+		(EGG_TOOLBARS_MODEL (model),
+		 model->details->xml_file,
+		 "1.0");
+
+	model->details->timeout = 0;
+
+	/* don't run again */
+	return FALSE;
+}
+
+static void
+save_changes (NautilusToolbarsModel *model)
+{
+	if (model->details->timeout == 0)
+	{
+		model->details->timeout =
+			g_idle_add ((GSourceFunc) save_changes_idle, model);
+	}
+}
+
+static void
+update_flags (NautilusToolbarsModel *model)
+{
+	EggToolbarsModel *eggmodel = EGG_TOOLBARS_MODEL (model);
+	int i, n_toolbars;
+	int flag = EGG_TB_MODEL_ACCEPT_ITEMS_ONLY;
+
+	n_toolbars = egg_toolbars_model_n_toolbars (eggmodel);
+
+	if (n_toolbars <= 1)
+	{
+		flag |= EGG_TB_MODEL_NOT_REMOVABLE;
+	}
+
+	for (i = 0; i < n_toolbars; i++)
+	{
+		const char *t_name;
+		EggTbModelFlags flags;
+
+		t_name = egg_toolbars_model_toolbar_nth (eggmodel, i);
+		g_return_if_fail (t_name != NULL);
+
+		flags = egg_toolbars_model_get_flags (eggmodel, i);
+		flags &= ~(EGG_TB_MODEL_NOT_REMOVABLE | EGG_TB_MODEL_STYLES_MASK);
+		flags |= flag;
+		flags |= model->details->style;
+		egg_toolbars_model_set_flags (eggmodel, i, flags);
+	}
+}
+
+static void
+update_flags_and_save_changes (NautilusToolbarsModel *model)
+{
+	update_flags (model);
+	save_changes (model);
+}
+
+/*
+static int
+get_toolbar_pos (EggToolbarsModel *model,
+		 const char *name)
+{
+	int i, n_toolbars;
+
+	n_toolbars = egg_toolbars_model_n_toolbars (model);
+
+	for (i = 0; i < n_toolbars; i++)
+	{
+		const char *t_name;
+
+		t_name = egg_toolbars_model_toolbar_nth (model, i);
+		g_return_val_if_fail (t_name != NULL, -1);
+		if (strcmp (name, t_name) == 0)
+		{
+			return i;
+		}
+	}
+
+	return -1;
+}*/
+/*
+static EggTbModelFlags
+get_toolbar_style (void)
+{
+	GFlagsClass *flags_class;
+	const GFlagsValue *value;
+	EggTbModelFlags flags = 0;
+	char *pref;
+
+	pref = eel_gconf_get_string (CONF_INTERFACE_TOOLBAR_STYLE);
+	if (pref != NULL)
+	{
+		flags_class = g_type_class_ref (EGG_TYPE_TB_MODEL_FLAGS);
+		value = g_flags_get_value_by_nick (flags_class, pref);
+		if (value != NULL)
+		{
+			flags = value->value;
+		}
+		g_type_class_unref (flags_class);
+	}
+	flags &= EGG_TB_MODEL_STYLES_MASK;
+
+	g_free (pref);
+
+	return flags;
+}*/
+
+/*
+static void
+toolbar_style_notifier (GConfClient *client,
+			guint cnxn_id,
+			GConfEntry *entry,
+			NautilusToolbarsModel *model)
+{
+	model->details->style = get_toolbar_style ();
+
+	update_flags (model);
+}*/
+
+void
+nautilus_toolbars_model_load (NautilusToolbarsModel *model)
+{
+	EggToolbarsModel *eggmodel = EGG_TOOLBARS_MODEL (model);
+	gboolean success;
+	char *path;
+
+	success = egg_toolbars_model_load (eggmodel, model->details->xml_file);
+	if (!success) {
+		path = g_build_filename (NAUTILUS_DATADIR, NAUTILUS_TOOLBARS_XML_FILE, NULL);
+		success = egg_toolbars_model_load (eggmodel, path);
+		g_free (path);
+	}
+
+	if (!success) {
+		g_warning ("could not load toolbar model!");
+	}
+
+	/* Ensure we have at least 1 toolbar */
+	if (egg_toolbars_model_n_toolbars (eggmodel) < 1) {
+		egg_toolbars_model_add_toolbar (eggmodel, 0, "DefaultToolbar");
+	}
+}
+
+static void
+nautilus_toolbars_model_init (NautilusToolbarsModel *model)
+{
+	NautilusToolbarsModelDetails *details;
+	char *user_directory;
+
+	details = model->details = NAUTILUS_TOOLBARS_MODEL_GET_PRIVATE (model);
+
+	user_directory = nautilus_get_user_directory ();
+	details->xml_file = g_build_filename (user_directory,
+					      NAUTILUS_TOOLBARS_XML_FILE,
+					      NULL);
+	g_free (user_directory);
+
+	/*
+	details->style = get_toolbar_style ();
+	details->style_notifier_id = eel_gconf_notification_add
+		(CONF_INTERFACE_TOOLBAR_STYLE,
+		 (GConfClientNotifyFunc) toolbar_style_notifier, model);
+		 */
+	
+	g_signal_connect_after (model, "item_added",
+				G_CALLBACK (save_changes), NULL);
+	g_signal_connect_after (model, "item_removed",
+				G_CALLBACK (save_changes), NULL);
+	g_signal_connect_after (model, "toolbar_added",
+				G_CALLBACK (update_flags_and_save_changes), NULL);
+	g_signal_connect_after (model, "toolbar_removed",
+				G_CALLBACK (update_flags_and_save_changes), NULL);
+}
+
+static void
+nautilus_toolbars_model_dispose (GObject *object)
+{
+	NautilusToolbarsModel *model = NAUTILUS_TOOLBARS_MODEL (object);
+
+	save_changes_idle (model);
+
+	G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+nautilus_toolbars_model_finalize (GObject *object)
+{
+	NautilusToolbarsModel *model = NAUTILUS_TOOLBARS_MODEL (object);
+	NautilusToolbarsModelDetails *details = model->details;
+
+	if (details->style_notifier_id != 0)
+	{
+//		eel_gconf_notification_remove (details->style_notifier_id);
+	}
+
+	if (details->timeout != 0)
+	{
+		g_source_remove (details->timeout);
+	}
+
+	g_free (details->xml_file);
+
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+nautilus_toolbars_model_class_init (NautilusToolbarsModelClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+	parent_class = g_type_class_peek_parent (klass);
+
+	object_class->dispose = nautilus_toolbars_model_dispose;
+	object_class->finalize = nautilus_toolbars_model_finalize;
+
+	g_type_class_add_private (object_class, sizeof (NautilusToolbarsModelDetails));
+}
+
+EggToolbarsModel *
+nautilus_toolbars_model_new (void)
+{
+	return EGG_TOOLBARS_MODEL (g_object_new (NAUTILUS_TYPE_TOOLBARS_MODEL, NULL));
+}
Index: src/nautilus-toolbars-model.h
===================================================================
RCS file: src/nautilus-toolbars-model.h
diff -N src/nautilus-toolbars-model.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/nautilus-toolbars-model.h	12 Nov 2005 18:22:03 -0000
@@ -0,0 +1,61 @@
+/*
+ *  Copyright (C) 2003, 2004 Marco Pesenti Gritti
+ *  Copyright (C) 2003, 2004 Christian Persch
+ *  Copyright (C) 2005 Christian Neumair
+ *
+ *  This program 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, or (at your option)
+ *  any later version.
+ *
+ *  This program 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.
+ *
+ *  $Id: nautilus-toolbars-model.h,v 1.15 2005/01/08 16:40:45 chpe Exp $
+ */
+
+#ifndef NAUTILUS_TOOLBARS_MODEL_H
+#define NAUTILUS_TOOLBARS_MODEL_H
+
+#include <cut-n-paste-code/libegg/egg-toolbars-model.h>
+
+G_BEGIN_DECLS
+
+#define NAUTILUS_TYPE_TOOLBARS_MODEL	     (nautilus_toolbars_model_get_type ())
+#define NAUTILUS_TOOLBARS_MODEL(o)	     (G_TYPE_CHECK_INSTANCE_CAST ((o), NAUTILUS_TYPE_TOOLBARS_MODEL, NautilusToolbarsModel))
+#define NAUTILUS_TOOLBARS_MODEL_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), NAUTILUS_TYPE_TOOLBARS_MODEL, NautilusToolbarsModelClass))
+#define NAUTILUS_IS_TOOLBARS_MODEL(o)	     (G_TYPE_CHECK_INSTANCE_TYPE ((o), NAUTILUS_TYPE_TOOLBARS_MODEL))
+#define NAUTILUS_IS_TOOLBARS_MODEL_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), NAUTILUS_TYPE_TOOLBARS_MODEL))
+#define NAUTILUS_TOOLBARS_MODEL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), NAUTILUS_TYPE_TOOLBARS_MODEL, NautilusToolbarsModelClass))
+
+typedef struct _NautilusToolbarsModelClass	NautilusToolbarsModelClass;
+typedef struct _NautilusToolbarsModel		NautilusToolbarsModel;
+typedef struct _NautilusToolbarsModelDetails	NautilusToolbarsModelDetails;
+
+struct _NautilusToolbarsModel
+{
+	EggToolbarsModel parent_object;
+
+	NautilusToolbarsModelDetails *details;
+};
+
+struct _NautilusToolbarsModelClass
+{
+	EggToolbarsModelClass parent_class;
+};
+
+GType		  nautilus_toolbars_model_get_type	(void);
+
+EggToolbarsModel *nautilus_toolbars_model_new	(void);
+
+void		  nautilus_toolbars_model_load	(NautilusToolbarsModel *model);
+
+G_END_DECLS
+
+#endif
Index: data/toolbars.xml
===================================================================
RCS file: data/toolbars.xml
diff -N data/toolbars.xml
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ data/toolbars.xml	12 Nov 2005 18:22:03 -0000
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<toolbars version="1.0">
+<available>
+	<toolitem name="Back"/>
+	<toolitem name="Forward"/>
+	<toolitem name="Up"/>
+	<toolitem name="Stop"/>
+	<toolitem name="Reload"/>
+	<toolitem name="Home"/>
+	<toolitem name="Go to Computer"/>
+	<toolitem name="Location"/>
+	<toolitem name="Zoom"/>
+	<toolitem name="ViewChooser"/>
+</available>
+<toolbar name="DefaultToolbar">
+	<toolitem name="Back"/>
+	<toolitem name="Forward"/>
+	<toolitem name="Up"/>
+	<toolitem name="Stop"/>
+	<toolitem name="Reload"/>
+	<separator/>
+	<toolitem name="Home"/>	
+	<toolitem name="Go to Computer"/>
+</toolbar>
+<toolbar name="EntryToolbar">
+	<toolitem name="Location"/>
+	<toolitem name="Zoom"/>
+	<toolitem name="ViewChooser"/>
+</toolbar>
+</toolbars>
