[gedit/gsettings: 13/13] Move the state preferences to gsettings.



commit 8e09809ed41a901bed37fd4c94d275beff214142
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Mon Apr 26 17:11:32 2010 +0200

    Move the state preferences to gsettings.
    
    From now on, instead of using a GKeyFile for storing state preferences
    we will use gsettings.

 data/org.gnome.gedit.gschema.in.in |   15 +
 gedit/gedit-app.c                  |   14 +-
 gedit/gedit-file-chooser-dialog.c  |   32 ++-
 gedit/gedit-settings.c             |  518 ++----------------------------------
 gedit/gedit-settings.h             |   50 +---
 gedit/gedit-window-private.h       |    3 +
 gedit/gedit-window.c               |  100 +++++---
 7 files changed, 160 insertions(+), 572 deletions(-)
---
diff --git a/data/org.gnome.gedit.gschema.in.in b/data/org.gnome.gedit.gschema.in.in
index 9144d06..e9c50a0 100644
--- a/data/org.gnome.gedit.gschema.in.in
+++ b/data/org.gnome.gedit.gschema.in.in
@@ -47,6 +47,21 @@ schema org.gnome.gedit:
       key auto-detected = @as ['UTF-8', 'CURRENT', 'ISO-8859-15', 'UTF-16']
       key shown-in-menu = @as ['ISO-8859-15']
 
+  child window:
+    key state = @i 0
+    key size = @(ii) (650, 500)
+
+    child side-panel:
+      key size = @i 200
+      key active-page = @i 0
+
+    child bottom-panel:
+      key size = @i 140
+      key active-page = @i 0
+
+    child file-filter:
+      key filter-id = @i 0
+
   child plugins:
     key active-plugins = @as [ ACTIVE_PLUGINS@]
 
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index 06c6640..3ab7432 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -73,6 +73,7 @@ struct _GeditAppPrivate
 	GtkPrintSettings  *print_settings;
 	
 	GSettings         *settings;
+	GSettings         *window_settings;
 };
 
 G_DEFINE_TYPE(GeditApp, gedit_app, G_TYPE_OBJECT)
@@ -97,6 +98,12 @@ gedit_app_dispose (GObject *object)
 {
 	GeditApp *app = GEDIT_APP (object); 
 
+	if (app->priv->window_settings != NULL)
+	{
+		g_object_unref (app->priv->window_settings);
+		app->priv->window_settings = NULL;
+	}
+
 	if (app->priv->settings != NULL)
 	{
 		g_object_unref (app->priv->settings);
@@ -356,6 +363,7 @@ gedit_app_init (GeditApp *app)
 	
 	/* Load settings */
 	app->priv->settings = gedit_settings_new ();
+	app->priv->window_settings = gedit_app_get_settings (app, "window", NULL);
 
 	/* initial lockdown state */
 	app->priv->lockdown = gedit_settings_get_lockdown (GEDIT_SETTINGS (app->priv->settings));
@@ -543,7 +551,8 @@ gedit_app_create_window_real (GeditApp    *app,
 		GdkWindowState state;
 		gint w, h;
 
-		state = gedit_settings_get_window_state ();
+		state = g_settings_get_int (app->priv->window_settings,
+					    GS_WINDOW_STATE);
 
 		if ((state & GDK_WINDOW_STATE_MAXIMIZED) != 0)
 		{
@@ -553,7 +562,8 @@ gedit_app_create_window_real (GeditApp    *app,
 		}
 		else
 		{
-			gedit_settings_get_window_size (&w, &h);
+			g_settings_get (app->priv->window_settings, GS_WINDOW_SIZE,
+					"(ii)", &w, &h);
 			gtk_window_set_default_size (GTK_WINDOW (window), w, h);
 			gtk_window_unmaximize (GTK_WINDOW (window));
 		}
diff --git a/gedit/gedit-file-chooser-dialog.c b/gedit/gedit-file-chooser-dialog.c
index db14b7e..e565b20 100644
--- a/gedit/gedit-file-chooser-dialog.c
+++ b/gedit/gedit-file-chooser-dialog.c
@@ -40,6 +40,7 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
+#include "gedit-app.h"
 #include "gedit-file-chooser-dialog.h"
 #include "gedit-encodings-combo-box.h"
 #include "gedit-language-manager.h"
@@ -54,6 +55,8 @@
 
 struct _GeditFileChooserDialogPrivate
 {
+	GSettings *filter_settings;
+
 	GtkWidget *option_menu;
 	GtkWidget *extra_widget;
 
@@ -65,10 +68,26 @@ struct _GeditFileChooserDialogPrivate
 G_DEFINE_TYPE(GeditFileChooserDialog, gedit_file_chooser_dialog, GTK_TYPE_FILE_CHOOSER_DIALOG)
 
 static void
+gedit_file_chooser_dialog_dispose (GObject *object)
+{
+	GeditFileChooserDialog *dialog = GEDIT_FILE_CHOOSER_DIALOG (object);
+
+	if (dialog->priv->filter_settings != NULL)
+	{
+		g_object_unref (dialog->priv->filter_settings);
+		dialog->priv->filter_settings = NULL;
+	}
+
+	G_OBJECT_CLASS (gedit_file_chooser_dialog_parent_class)->dispose (object);
+}
+
+static void
 gedit_file_chooser_dialog_class_init (GeditFileChooserDialogClass *klass)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+	object_class->dispose = gedit_file_chooser_dialog_dispose;
+
 	g_type_class_add_private (object_class, sizeof(GeditFileChooserDialogPrivate));
 }
 
@@ -250,9 +269,6 @@ filter_changed (GeditFileChooserDialog *dialog,
 {
 	GtkFileFilter *filter;
 
-	if (!gedit_settings_active_file_filter_can_set ())
-		return;
-
 	filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog));
 	if (filter != NULL)
 	{
@@ -267,7 +283,8 @@ filter_changed (GeditFileChooserDialog *dialog,
 
 		gedit_debug_message (DEBUG_COMMANDS, "Active filter: %s (%d)", name, id);
 
-		gedit_settings_set_active_file_filter (id);
+		g_settings_set_int (dialog->priv->filter_settings,
+				    GS_ACTIVE_FILE_FILTER, id);
 	}
 }
 
@@ -353,6 +370,10 @@ static void
 gedit_file_chooser_dialog_init (GeditFileChooserDialog *dialog)
 {
 	dialog->priv = GEDIT_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
+	
+	dialog->priv->filter_settings = gedit_app_get_settings (gedit_app_get_default (),
+								"window", "file-filter",
+								NULL);
 }
 
 static GtkWidget *
@@ -391,7 +412,8 @@ gedit_file_chooser_dialog_new_valist (const gchar          *title,
 				GEDIT_ENCODINGS_COMBO_BOX (GEDIT_FILE_CHOOSER_DIALOG (result)->priv->option_menu),
 				encoding);
 
-	active_filter = gedit_settings_get_active_file_filter ();
+	active_filter = g_settings_get_int (GEDIT_FILE_CHOOSER_DIALOG (result)->priv->filter_settings,
+					    GS_ACTIVE_FILE_FILTER);
 	gedit_debug_message (DEBUG_COMMANDS, "Active filter: %d", active_filter);
 
 	/* Filters */
diff --git a/gedit/gedit-settings.c b/gedit/gedit-settings.c
index a8d3384..ebbfa0e 100644
--- a/gedit/gedit-settings.c
+++ b/gedit/gedit-settings.c
@@ -41,25 +41,8 @@
 
 #define GS_SYSTEM_FONT "monospace-font-name"
 
-#define GEDIT_STATE_DEFAULT_WINDOW_STATE	0
-#define GEDIT_STATE_DEFAULT_WINDOW_WIDTH	650
-#define GEDIT_STATE_DEFAULT_WINDOW_HEIGHT	500
-#define GEDIT_STATE_DEFAULT_SIDE_PANEL_SIZE	200
-#define GEDIT_STATE_DEFAULT_BOTTOM_PANEL_SIZE	140
-
-#define GEDIT_STATE_FILE_LOCATION "gedit-2"
-
-#define GEDIT_STATE_WINDOW_GROUP "window"
-#define GEDIT_STATE_WINDOW_STATE "state"
-#define GEDIT_STATE_WINDOW_HEIGHT "height"
-#define GEDIT_STATE_WINDOW_WIDTH "width"
-#define GEDIT_STATE_SIDE_PANEL_SIZE "side_panel_size"
-#define GEDIT_STATE_BOTTOM_PANEL_SIZE "bottom_panel_size"
-#define GEDIT_STATE_SIDE_PANEL_ACTIVE_PAGE "side_panel_active_page"
-#define GEDIT_STATE_BOTTOM_PANEL_ACTIVE_PAGE "bottom_panel_active_page"
-
-#define GEDIT_STATE_FILEFILTER_GROUP "filefilter"
-#define GEDIT_STATE_FILEFILTER_ID "id"
+#define GEDIT_STATE_DEFAULT_WINDOW_WIDTH       650
+#define GEDIT_STATE_DEFAULT_WINDOW_HEIGHT      500
 
 #define GEDIT_SETTINGS_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GEDIT_TYPE_SETTINGS, GeditSettingsPrivate))
 
@@ -76,470 +59,12 @@ struct _GeditSettingsPrivate
 
 G_DEFINE_TYPE (GeditSettings, gedit_settings, G_TYPE_SETTINGS)
 
-/* GUI state is serialized to a .desktop file, not in gconf */
-
-/* FIXME: use the class to manage this */
-static gint window_state = -1;
-static gint window_height = -1;
-static gint window_width = -1;
-static gint side_panel_size = -1;
-static gint bottom_panel_size = -1;
-static gint side_panel_active_page = -1;
-static gint bottom_panel_active_page = -1;
-static gint active_file_filter = -1;
-
-
-static gchar *
-get_state_filename (void)
-{
-	gchar *config_dir;
-	gchar *filename = NULL;
-
-	config_dir = gedit_dirs_get_user_config_dir ();
-
-	if (config_dir != NULL)
-	{
-		filename = g_build_filename (config_dir,
-					     GEDIT_STATE_FILE_LOCATION,
-					     NULL);
-		g_free (config_dir);
-	}
-
-	return filename;
-}
-
-static GKeyFile *
-get_gedit_state_file (void)
-{
-	static GKeyFile *state_file = NULL;
-
-	if (state_file == NULL)
-	{
-		gchar *filename;
-		GError *err = NULL;
-
-		state_file = g_key_file_new ();
-
-		filename = get_state_filename ();
-
-		if (!g_key_file_load_from_file (state_file,
-						filename,
-						G_KEY_FILE_NONE,
-						&err))
-		{
-			if (err->domain != G_FILE_ERROR ||
-			    err->code != G_FILE_ERROR_NOENT)
-			{
-				g_warning ("Could not load gedit state file: %s\n",
-					   err->message);
-			}
-
-			g_error_free (err);
-		}
-
-		g_free (filename);
-	}
-
-	return state_file;
-}
-
-static void
-gedit_state_get_int (const gchar *group,
-		     const gchar *key,
-		     gint         defval,
-		     gint        *result)
-{
-	GKeyFile *state_file;
-	gint res;
-	GError *err = NULL;
-
-	state_file = get_gedit_state_file ();
-	res = g_key_file_get_integer (state_file,
-				      group,
-				      key,
-				      &err);
-
-	if (err != NULL)
-	{
-		if ((err->domain != G_KEY_FILE_ERROR) ||
-		    ((err->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND &&
-		      err->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND)))
-		{
-			g_warning ("Could not get state value %s::%s : %s\n",
-				   group,
-				   key,
-				   err->message);
-		}
-
-		*result = defval;
-		g_error_free (err);
-	}
-	else
-	{
-		*result = res;
-	}
-}
-
-static void
-gedit_state_set_int (const gchar *group,
-		     const gchar *key,
-		     gint         value)
-{
-	GKeyFile *state_file;
-
-	state_file = get_gedit_state_file ();
-	g_key_file_set_integer (state_file,
-				group,
-				key,
-				value);
-}
-
-static gboolean
-gedit_state_file_sync (void)
-{
-	GKeyFile *state_file;
-	gchar *config_dir;
-	gchar *filename = NULL;
-	gchar *content = NULL;
-	gsize length;
-	gint res;
-	GError *err = NULL;
-	gboolean ret = FALSE;
-
-	state_file = get_gedit_state_file ();
-	g_return_val_if_fail (state_file != NULL, FALSE);
-
-	config_dir = gedit_dirs_get_user_config_dir ();
-	if (config_dir == NULL)
-	{
-		g_warning ("Could not get config directory\n");
-		return ret;
-	}
-
-	res = g_mkdir_with_parents (config_dir, 0755);
-	if (res < 0)
-	{
-		g_warning ("Could not create config directory\n");
-		goto out;
-	}
-
-	content = g_key_file_to_data (state_file,
-				      &length,
-				      &err);
-
-	if (err != NULL)
-	{
-		g_warning ("Could not get data from state file: %s\n",
-			   err->message);
-		goto out;
-	}
-
-	if (content != NULL)
-	{
-		filename = get_state_filename ();
-		if (!g_file_set_contents (filename,
-					  content,
-					  length,
-					  &err))
-		{
-			g_warning ("Could not write gedit state file: %s\n",
-				   err->message);
-			goto out;
-		}
-	}
-
-	ret = TRUE;
-
- out:
-	if (err != NULL)
-		g_error_free (err);
-
-	g_free (config_dir);
-	g_free (filename);
-	g_free (content);
-
-	return ret;
-}
-
-/* Window state */
-gint
-gedit_settings_get_window_state (void)
-{
-	if (window_state == -1)
-	{
-		gedit_state_get_int (GEDIT_STATE_WINDOW_GROUP,
-				     GEDIT_STATE_WINDOW_STATE,
-				     GEDIT_STATE_DEFAULT_WINDOW_STATE,
-				     &window_state);
-	}
-
-	return window_state;
-}
-			
-void
-gedit_settings_set_window_state (gint ws)
-{
-	g_return_if_fail (ws > -1);
-	
-	window_state = ws;
-
-	gedit_state_set_int (GEDIT_STATE_WINDOW_GROUP,
-			     GEDIT_STATE_WINDOW_STATE,
-			     ws);
-}
-
-gboolean
-gedit_settings_window_state_can_set (void)
-{
-	return TRUE;
-}
-
-/* Window size */
-void
-gedit_settings_get_window_size (gint *width, gint *height)
-{
-	g_return_if_fail (width != NULL && height != NULL);
-
-	if (window_width == -1)
-	{
-		gedit_state_get_int (GEDIT_STATE_WINDOW_GROUP,
-				     GEDIT_STATE_WINDOW_WIDTH,
-				     GEDIT_STATE_DEFAULT_WINDOW_WIDTH,
-				     &window_width);
-	}
-
-	if (window_height == -1)
-	{
-		gedit_state_get_int (GEDIT_STATE_WINDOW_GROUP,
-				     GEDIT_STATE_WINDOW_HEIGHT,
-				     GEDIT_STATE_DEFAULT_WINDOW_HEIGHT,
-				     &window_height);
-	}
-
-	*width = window_width;
-	*height = window_height;
-}
-
-void
-gedit_settings_get_default_window_size (gint *width, gint *height)
-{
-	g_return_if_fail (width != NULL && height != NULL);
-
-	*width = GEDIT_STATE_DEFAULT_WINDOW_WIDTH;
-	*height = GEDIT_STATE_DEFAULT_WINDOW_HEIGHT;
-}
-
-void
-gedit_settings_set_window_size (gint width, gint height)
-{
-	g_return_if_fail (width > -1 && height > -1);
-
-	window_width = width;
-	window_height = height;
-
-	gedit_state_set_int (GEDIT_STATE_WINDOW_GROUP,
-			     GEDIT_STATE_WINDOW_WIDTH,
-			     width);
-	gedit_state_set_int (GEDIT_STATE_WINDOW_GROUP,
-			     GEDIT_STATE_WINDOW_HEIGHT,
-			     height);
-}
-
-gboolean 
-gedit_settings_window_size_can_set (void)
-{
-	return TRUE;
-}
-
-/* Side panel */
-gint
-gedit_settings_get_side_panel_size (void)
-{
-	if (side_panel_size == -1)
-	{
-		gedit_state_get_int (GEDIT_STATE_WINDOW_GROUP,
-				     GEDIT_STATE_SIDE_PANEL_SIZE,
-				     GEDIT_STATE_DEFAULT_SIDE_PANEL_SIZE,
-				     &side_panel_size);
-	}
-
-	return side_panel_size;
-}
-
-gint 
-gedit_settings_get_default_side_panel_size (void)
-{
-	return GEDIT_STATE_DEFAULT_SIDE_PANEL_SIZE;
-}
-
-void 
-gedit_settings_set_side_panel_size (gint ps)
-{
-	g_return_if_fail (ps > -1);
-	
-	if (side_panel_size == ps)
-		return;
-		
-	side_panel_size = ps;
-	gedit_state_set_int (GEDIT_STATE_WINDOW_GROUP,
-			     GEDIT_STATE_SIDE_PANEL_SIZE,
-			     ps);
-}
-
-gboolean 
-gedit_settings_side_panel_size_can_set (void)
-{
-	return TRUE;
-}
-
-gint
-gedit_settings_get_side_panel_active_page (void)
-{
-	if (side_panel_active_page == -1)
-	{
-		gedit_state_get_int (GEDIT_STATE_WINDOW_GROUP,
-				     GEDIT_STATE_SIDE_PANEL_ACTIVE_PAGE,
-				     0,
-				     &side_panel_active_page);
-	}
-
-	return side_panel_active_page;
-}
-
-void
-gedit_settings_set_side_panel_active_page (gint id)
-{
-	if (side_panel_active_page == id)
-		return;
-
-	side_panel_active_page = id;
-	gedit_state_set_int (GEDIT_STATE_WINDOW_GROUP,
-			     GEDIT_STATE_SIDE_PANEL_ACTIVE_PAGE,
-			     id);
-}
-
-gboolean 
-gedit_settings_side_panel_active_page_can_set (void)
-{
-	return TRUE;
-}
-
-/* Bottom panel */
-gint
-gedit_settings_get_bottom_panel_size (void)
-{
-	if (bottom_panel_size == -1)
-	{
-		gedit_state_get_int (GEDIT_STATE_WINDOW_GROUP,
-				     GEDIT_STATE_BOTTOM_PANEL_SIZE,
-				     GEDIT_STATE_DEFAULT_BOTTOM_PANEL_SIZE,
-				     &bottom_panel_size);
-	}
-
-	return bottom_panel_size;
-}
-
-gint 
-gedit_settings_get_default_bottom_panel_size (void)
-{
-	return GEDIT_STATE_DEFAULT_BOTTOM_PANEL_SIZE;
-}
-
-void 
-gedit_settings_set_bottom_panel_size (gint ps)
-{
-	g_return_if_fail (ps > -1);
-
-	if (bottom_panel_size == ps)
-		return;
-	
-	bottom_panel_size = ps;
-	gedit_state_set_int (GEDIT_STATE_WINDOW_GROUP,
-			     GEDIT_STATE_BOTTOM_PANEL_SIZE,
-			     ps);
-}
-
-gboolean 
-gedit_settings_bottom_panel_size_can_set (void)
-{
-	return TRUE;
-}
-
-gint
-gedit_settings_get_bottom_panel_active_page (void)
-{
-	if (bottom_panel_active_page == -1)
-	{
-		gedit_state_get_int (GEDIT_STATE_WINDOW_GROUP,
-				     GEDIT_STATE_BOTTOM_PANEL_ACTIVE_PAGE,
-				     0,
-				     &bottom_panel_active_page);
-	}
-
-	return bottom_panel_active_page;
-}
-
-void
-gedit_settings_set_bottom_panel_active_page (gint id)
-{
-	if (bottom_panel_active_page == id)
-		return;
-
-	bottom_panel_active_page = id;
-	gedit_state_set_int (GEDIT_STATE_WINDOW_GROUP,
-			     GEDIT_STATE_BOTTOM_PANEL_ACTIVE_PAGE,
-			     id);
-}
-
-gboolean 
-gedit_settings_bottom_panel_active_page_can_set (void)
-{
-	return TRUE;
-}
-
-/* File filter */
-gint
-gedit_settings_get_active_file_filter (void)
-{
-	if (active_file_filter == -1)
-	{
-		gedit_state_get_int (GEDIT_STATE_FILEFILTER_GROUP,
-				     GEDIT_STATE_FILEFILTER_ID,
-				     0,
-				     &active_file_filter);
-	}
-
-	return active_file_filter;
-}
-
-void
-gedit_settings_set_active_file_filter (gint id)
-{
-	g_return_if_fail (id >= 0);
-	
-	if (active_file_filter == id)
-		return;
-
-	active_file_filter = id;
-	gedit_state_set_int (GEDIT_STATE_FILEFILTER_GROUP,
-			     GEDIT_STATE_FILEFILTER_ID,
-			     id);
-}
-
-gboolean 
-gedit_settings_active_file_filter_can_set (void)
-{
-	return TRUE;
-}
-
 static void
 gedit_settings_finalize (GObject *object)
 {
 	GeditSettings *gs = GEDIT_SETTINGS (object);
-	
+
 	g_free (gs->priv->old_scheme);
-	
-	gedit_state_file_sync ();
 
 	G_OBJECT_CLASS (gedit_settings_parent_class)->finalize (object);
 }
@@ -583,17 +108,6 @@ gedit_settings_dispose (GObject *object)
 }
 
 static void
-gedit_settings_class_init (GeditSettingsClass *klass)
-{
-	GObjectClass *object_class = G_OBJECT_CLASS (klass);
-	
-	object_class->finalize = gedit_settings_finalize;
-	object_class->dispose = gedit_settings_dispose;
-
-	g_type_class_add_private (object_class, sizeof (GeditSettingsPrivate));
-}
-
-static void
 on_lockdown_changed (GSettings   *settings,
 		     const gchar *key,
 		     gpointer     useless)
@@ -1268,17 +782,28 @@ initialize (GeditSettings *gs)
 			  gs);
 }
 
+static void
+gedit_settings_class_init (GeditSettingsClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+	object_class->finalize = gedit_settings_finalize;
+	object_class->dispose = gedit_settings_dispose;
+
+	g_type_class_add_private (object_class, sizeof (GeditSettingsPrivate));
+}
+
 GSettings *
 gedit_settings_new ()
 {
 	GeditSettings *settings;
-	
+
 	settings = g_object_new (GEDIT_TYPE_SETTINGS,
 				 "schema", "org.gnome.gedit",
 				 NULL);
-	
+
 	initialize (settings);
-	
+
 	return G_SETTINGS (settings);
 }
 
@@ -1324,3 +849,12 @@ gedit_settings_get_system_font (GeditSettings *gs)
 	
 	return system_font;
 }
+
+void
+gedit_settings_get_default_window_size (gint *width, gint *height)
+{
+	g_return_if_fail (width != NULL && height != NULL);
+
+	*width = GEDIT_STATE_DEFAULT_WINDOW_WIDTH;
+	*height = GEDIT_STATE_DEFAULT_WINDOW_HEIGHT;
+}
diff --git a/gedit/gedit-settings.h b/gedit/gedit-settings.h
index b032d15..1b2020d 100644
--- a/gedit/gedit-settings.h
+++ b/gedit/gedit-settings.h
@@ -70,44 +70,7 @@ GeditLockdownMask	 gedit_settings_get_lockdown			(GeditSettings *gs);
 
 gchar			*gedit_settings_get_system_font			(GeditSettings *gs);
 
-/* Window state */
-gint			 gedit_settings_get_window_state		(void);
-void			 gedit_settings_set_window_state		(gint ws);
-gboolean		 gedit_settings_window_state_can_set		(void);
-
-/* Window size */
-void			 gedit_settings_get_window_size			(gint *width,
-									 gint *height);
-void			 gedit_settings_get_default_window_size		(gint *width,
-									 gint *height);
-void 			 gedit_settings_set_window_size			(gint width,
-									 gint height);
-gboolean		 gedit_settings_window_size_can_set		(void);
-
-/* Side panel */
-gint			 gedit_settings_get_side_panel_size		(void);
-gint			 gedit_settings_get_default_side_panel_size	(void);
-void 			 gedit_settings_set_side_panel_size		(gint ps);
-gboolean		 gedit_settings_side_panel_size_can_set		(void);
-gint			 gedit_settings_get_side_panel_active_page 	(void);
-void 			 gedit_settings_set_side_panel_active_page 	(gint id);
-gboolean		 gedit_settings_side_panel_active_page_can_set	(void);
-
-/* Bottom panel */
-gint			 gedit_settings_get_bottom_panel_size		(void);
-gint			 gedit_settings_get_default_bottom_panel_size	(void);
-void 			 gedit_settings_set_bottom_panel_size		(gint ps);
-gboolean		 gedit_settings_bottom_panel_size_can_set	(void);
-gint			 gedit_settings_get_bottom_panel_active_page	(void);
-void 			 gedit_settings_set_bottom_panel_active_page	(gint id);
-gboolean		 gedit_settings_bottom_panel_active_page_can_set (void);
-
-/* File filter */
-gint			 gedit_settings_get_active_file_filter	(void);
-void			 gedit_settings_set_active_file_filter	(gint id);
-gboolean		 gedit_settings_active_file_filter_can_set	(void);
-
-G_END_DECLS
+void			 gedit_settings_get_default_window_size		(gint *width, gint *height);
 
 /* key constants */
 #define GS_USE_DEFAULT_FONT		"use-default-font"
@@ -149,4 +112,15 @@ G_END_DECLS
 #define GS_ENCODING_SHOW_IN_MENU	"show-in-menu"
 #define GS_ACTIVE_PLUGINS		"active-plugins"
 
+/* window state keys */
+#define GS_WINDOW_STATE			"state"
+#define GS_WINDOW_SIZE			"size"
+#define GS_SIDE_PANEL_SIZE		"size"
+#define GS_SIDE_PANEL_ACTIVE_PAGE	"active-page"
+#define GS_BOTTOM_PANEL_SIZE		"size"
+#define GS_BOTTOM_PANEL_ACTIVE_PAGE	"active-page"
+#define GS_ACTIVE_FILE_FILTER		"filter-id"
+
+G_END_DECLS
+
 #endif /* __GEDIT_SETTINGS_H__ */
diff --git a/gedit/gedit-window-private.h b/gedit/gedit-window-private.h
index 6d010a5..658ccdd 100644
--- a/gedit/gedit-window-private.h
+++ b/gedit/gedit-window-private.h
@@ -47,6 +47,9 @@ struct _GeditWindowPrivate
 {
 	GSettings      *editor_settings;
 	GSettings      *ui_settings;
+	GSettings      *window_settings;
+	GSettings      *side_panel_settings;
+	GSettings      *bottom_panel_settings;
 
 	GtkWidget      *notebook;
 
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index f601628..aad2b61 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -127,32 +127,31 @@ save_panes_state (GeditWindow *window)
 
 	gedit_debug (DEBUG_WINDOW);
 
-	if (gedit_settings_window_size_can_set ())
-		gedit_settings_set_window_size (window->priv->width,
-						window->priv->height);
+	g_settings_set (window->priv->window_settings, GS_WINDOW_SIZE, "(ii)",
+			window->priv->width, window->priv->height);
 
-	if (gedit_settings_window_state_can_set ())
-		gedit_settings_set_window_state (window->priv->window_state);
+	g_settings_set_int (window->priv->window_settings, GS_WINDOW_STATE,
+			    window->priv->window_state);
 
-	if ((window->priv->side_panel_size > 0) &&
-	    gedit_settings_side_panel_size_can_set ())
-		gedit_settings_set_side_panel_size (
-					window->priv->side_panel_size);
+	if (window->priv->side_panel_size > 0)
+		g_settings_set_int (window->priv->side_panel_settings,
+				    GS_SIDE_PANEL_SIZE,
+				    window->priv->side_panel_size);
 
 	pane_page = _gedit_panel_get_active_item_id (GEDIT_PANEL (window->priv->side_panel));
-	if (pane_page != 0 &&
-	    gedit_settings_side_panel_active_page_can_set ())
-		gedit_settings_set_side_panel_active_page (pane_page);
+	if (pane_page != 0)
+		g_settings_set_int (window->priv->side_panel_settings,
+				    GS_SIDE_PANEL_ACTIVE_PAGE, pane_page);
 
-	if ((window->priv->bottom_panel_size > 0) && 
-	    gedit_settings_bottom_panel_size_can_set ())
-		gedit_settings_set_bottom_panel_size (
-					window->priv->bottom_panel_size);
+	if (window->priv->bottom_panel_size > 0)
+		g_settings_set_int (window->priv->bottom_panel_settings,
+				    GS_BOTTOM_PANEL_SIZE,
+				    window->priv->bottom_panel_size);
 
 	pane_page = _gedit_panel_get_active_item_id (GEDIT_PANEL (window->priv->bottom_panel));
-	if (pane_page != 0 &&
-	    gedit_settings_bottom_panel_active_page_can_set ())
-		gedit_settings_set_bottom_panel_active_page (pane_page);
+	if (pane_page != 0)
+		g_settings_set_int (window->priv->bottom_panel_settings,
+				    GS_BOTTOM_PANEL_ACTIVE_PAGE, pane_page);
 }
 
 #ifdef OS_OSX
@@ -215,18 +214,6 @@ gedit_window_dispose (GObject *object)
 	gedit_debug (DEBUG_WINDOW);
 
 	window = GEDIT_WINDOW (object);
-	
-	if (window->priv->editor_settings != NULL)
-	{
-		g_object_unref (window->priv->editor_settings);
-		window->priv->editor_settings = NULL;
-	}
-	
-	if (window->priv->ui_settings != NULL)
-	{
-		g_object_unref (window->priv->ui_settings);
-		window->priv->ui_settings = NULL;
-	}
 
 	/* Stop tracking removal of panes otherwise we always
 	 * end up with thinking we had no pane active, since they
@@ -294,7 +281,38 @@ gedit_window_dispose (GObject *object)
 		g_object_unref (window->priv->window_group);
 		window->priv->window_group = NULL;
 	}
+
+	/* We must free the settings after saving the panels */
+	if (window->priv->editor_settings != NULL)
+	{
+		g_object_unref (window->priv->editor_settings);
+		window->priv->editor_settings = NULL;
+	}
+	
+	if (window->priv->ui_settings != NULL)
+	{
+		g_object_unref (window->priv->ui_settings);
+		window->priv->ui_settings = NULL;
+	}
+
+	if (window->priv->window_settings != NULL)
+	{
+		g_object_unref (window->priv->window_settings);
+		window->priv->window_settings = NULL;
+	}
+	
+	if (window->priv->side_panel_settings != NULL)
+	{
+		g_object_unref (window->priv->side_panel_settings);
+		window->priv->side_panel_settings = NULL;
+	}
 	
+	if (window->priv->bottom_panel_settings != NULL)
+	{
+		g_object_unref (window->priv->bottom_panel_settings);
+		window->priv->bottom_panel_settings = NULL;
+	}
+
 	/* Now that there have broken some reference loops,
 	 * force collection again.
 	 */
@@ -3820,7 +3838,8 @@ init_panels_visibility (GeditWindow *window)
 	gedit_debug (DEBUG_WINDOW);
 
 	/* side pane */
-	active_page = gedit_settings_get_side_panel_active_page ();
+	active_page = g_settings_get_int (window->priv->side_panel_settings,
+					  GS_SIDE_PANEL_ACTIVE_PAGE);
 	_gedit_panel_set_active_item_by_id (GEDIT_PANEL (window->priv->side_panel),
 					    active_page);
 
@@ -3837,7 +3856,8 @@ init_panels_visibility (GeditWindow *window)
 	/* bottom pane, it can be empty */
 	if (gedit_panel_get_n_items (GEDIT_PANEL (window->priv->bottom_panel)) > 0)
 	{
-		active_page = gedit_settings_get_bottom_panel_active_page ();
+		active_page = g_settings_get_int (window->priv->bottom_panel_settings,
+						  GS_BOTTOM_PANEL_ACTIVE_PAGE);
 		_gedit_panel_set_active_item_by_id (GEDIT_PANEL (window->priv->bottom_panel),
 						    active_page);
 
@@ -4018,6 +4038,14 @@ gedit_window_init (GeditWindow *window)
 	window->priv->ui_settings = gedit_app_get_settings (gedit_app_get_default (),
 							    "preferences", "ui",
 							    NULL);
+	window->priv->window_settings = gedit_app_get_settings (gedit_app_get_default (),
+								"window", NULL);
+	window->priv->side_panel_settings = gedit_app_get_settings (gedit_app_get_default (),
+								    "window", "side-panel",
+								    NULL);
+	window->priv->bottom_panel_settings = gedit_app_get_settings (gedit_app_get_default (),
+								      "window", "bottom-panel",
+								      NULL);
 
 	window->priv->message_bus = gedit_message_bus_new ();
 
@@ -4059,8 +4087,10 @@ gedit_window_init (GeditWindow *window)
 
 	/* panes' state must be restored after panels have been mapped,
 	 * since the bottom pane position depends on the size of the vpaned. */
-	window->priv->side_panel_size = gedit_settings_get_side_panel_size ();
-	window->priv->bottom_panel_size = gedit_settings_get_bottom_panel_size ();
+	window->priv->side_panel_size = g_settings_get_int (window->priv->side_panel_settings,
+							    GS_SIDE_PANEL_SIZE);
+	window->priv->bottom_panel_size = g_settings_get_int (window->priv->bottom_panel_settings,
+							      GS_BOTTOM_PANEL_SIZE);
 
 	g_signal_connect_after (window->priv->hpaned,
 				"map",



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