[gtk+] Use GSettings for the filechooser settings
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Use GSettings for the filechooser settings
- Date: Wed, 13 Oct 2010 12:31:24 +0000 (UTC)
commit 803233cc14c02535a78b0000097d812ff42f7e6e
Author: Christian Persch <chpe gnome org>
Date: Tue Sep 28 22:56:02 2010 +0200
Use GSettings for the filechooser settings
Bug #630850.
configure.ac | 6 +
gtk/Makefile.am | 6 +-
gtk/gtkfilechooserdefault.c | 77 +++--
gtk/gtkfilechooserdialog.c | 1 -
gtk/gtkfilechooserprivate.h | 2 +
gtk/gtkfilechoosersettings.c | 504 --------------------------
gtk/gtkfilechoosersettings.h | 118 ------
gtk/org.gtk.Settings.FileChooser.gschema.xml | 64 ++++
8 files changed, 123 insertions(+), 655 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 139040b..36a9de4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1477,6 +1477,12 @@ if test -n "$export_dynamic"; then
GTK_DEP_LIBS=`echo $GTK_DEP_LIBS | sed -e "s/$export_dynamic//"`
fi
+#############
+# GSettings #
+#############
+
+GLIB_GSETTINGS
+
##################################################
# GObject introspection
##################################################
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 29df0c9..848d20f 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -362,7 +362,6 @@ gtk_private_h_sources = \
gtkfilechooserembed.h \
gtkfilechooserentry.h \
gtkfilechooserprivate.h \
- gtkfilechoosersettings.h \
gtkfilechooserutils.h \
gtkfilesystem.h \
gtkfilesystemmodel.h \
@@ -463,7 +462,6 @@ gtk_base_c_sources = \
gtkfilechooserdialog.c \
gtkfilechooserembed.c \
gtkfilechooserentry.c \
- gtkfilechoosersettings.c \
gtkfilechooserutils.c \
gtkfilechooserwidget.c \
gtkfilefilter.c \
@@ -1308,6 +1306,10 @@ EXTRA_DIST += \
gtktypebuiltins.c.template \
gtktypebuiltins.h.template
+gsettings_SCHEMAS = \
+ org.gtk.Settings.FileChooser.gschema.xml
+
+ GSETTINGS_RULES@
install-data-local:
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 7a47699..24c42f3 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -38,7 +38,6 @@
#include "gtkfilechooserdialog.h"
#include "gtkfilechooserembed.h"
#include "gtkfilechooserentry.h"
-#include "gtkfilechoosersettings.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooser.h"
#include "gtkfilesystem.h"
@@ -250,6 +249,15 @@ typedef enum {
#define NUM_LINES 45
#define NUM_CHARS 60
+#define SETTINGS_KEY_LOCATION_MODE "location-mode"
+#define SETTINGS_KEY_SHOW_HIDDEN "show-hidden"
+#define SETTINGS_KEY_EXPAND_FOLDERS "expand-folders"
+#define SETTINGS_KEY_SHOW_SIZE_COLUMN "show-size-column"
+#define SETTINGS_KEY_SORT_COLUMN "sort-column"
+#define SETTINGS_KEY_SORT_ORDER "sort-order"
+#define SETTINGS_KEY_WINDOW_POSITION "window-position"
+#define SETTINGS_KEY_WINDOW_SIZE "window-size"
+
static void gtk_file_chooser_default_iface_init (GtkFileChooserIface *iface);
static void gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface);
@@ -5739,9 +5747,19 @@ set_sort_column (GtkFileChooserDefault *impl)
}
static void
+settings_ensure (GtkFileChooserDefault *impl)
+{
+ if (impl->settings != NULL)
+ return;
+
+ impl->settings = g_settings_new_with_path ("org.gtk.Settings.FileChooser",
+ "/org/gtk/settings/file-chooser/");
+ g_settings_delay (impl->settings);
+}
+
+static void
settings_load (GtkFileChooserDefault *impl)
{
- GtkFileChooserSettings *settings;
LocationMode location_mode;
gboolean show_hidden;
gboolean expand_folders;
@@ -5749,16 +5767,14 @@ settings_load (GtkFileChooserDefault *impl)
gint sort_column;
GtkSortType sort_order;
- settings = _gtk_file_chooser_settings_new ();
-
- location_mode = _gtk_file_chooser_settings_get_location_mode (settings);
- show_hidden = _gtk_file_chooser_settings_get_show_hidden (settings);
- expand_folders = _gtk_file_chooser_settings_get_expand_folders (settings);
- show_size_column = _gtk_file_chooser_settings_get_show_size_column (settings);
- sort_column = _gtk_file_chooser_settings_get_sort_column (settings);
- sort_order = _gtk_file_chooser_settings_get_sort_order (settings);
+ settings_ensure (impl);
- g_object_unref (settings);
+ expand_folders = g_settings_get_boolean (impl->settings, SETTINGS_KEY_EXPAND_FOLDERS);
+ location_mode = g_settings_get_enum (impl->settings, SETTINGS_KEY_LOCATION_MODE);
+ show_hidden = g_settings_get_boolean (impl->settings, SETTINGS_KEY_SHOW_HIDDEN);
+ show_size_column = g_settings_get_boolean (impl->settings, SETTINGS_KEY_SHOW_SIZE_COLUMN);
+ sort_column = g_settings_get_enum (impl->settings, SETTINGS_KEY_SORT_COLUMN);
+ sort_order = g_settings_get_enum (impl->settings, SETTINGS_KEY_SORT_ORDER);
location_mode_set (impl, location_mode, TRUE);
@@ -5780,7 +5796,7 @@ settings_load (GtkFileChooserDefault *impl)
}
static void
-save_dialog_geometry (GtkFileChooserDefault *impl, GtkFileChooserSettings *settings)
+save_dialog_geometry (GtkFileChooserDefault *impl)
{
GtkWindow *toplevel;
int x, y, width, height;
@@ -5801,29 +5817,30 @@ save_dialog_geometry (GtkFileChooserDefault *impl, GtkFileChooserSettings *setti
gtk_window_get_position (toplevel, &x, &y);
gtk_window_get_size (toplevel, &width, &height);
- _gtk_file_chooser_settings_set_geometry (settings, x, y, width, height);
+ g_settings_set (impl->settings, "window-position", "(ii)", x, y);
+ g_settings_set (impl->settings, "window-size", "(ii)", width, height);
}
static void
settings_save (GtkFileChooserDefault *impl)
{
- GtkFileChooserSettings *settings;
+ settings_ensure (impl);
- settings = _gtk_file_chooser_settings_new ();
+ g_settings_set_enum (impl->settings, SETTINGS_KEY_LOCATION_MODE, impl->location_mode);
+ g_settings_set_boolean (impl->settings, SETTINGS_KEY_EXPAND_FOLDERS, impl->expand_folders);
+ g_settings_set_boolean (impl->settings, SETTINGS_KEY_SHOW_HIDDEN,
+ gtk_file_chooser_get_show_hidden (GTK_FILE_CHOOSER (impl)));
+ g_settings_set_boolean (impl->settings, SETTINGS_KEY_SHOW_SIZE_COLUMN, impl->show_size_column);
+ g_settings_set_enum (impl->settings, SETTINGS_KEY_SORT_COLUMN, impl->sort_column);
+ g_settings_set_enum (impl->settings, SETTINGS_KEY_SORT_ORDER, impl->sort_order);
- _gtk_file_chooser_settings_set_location_mode (settings, impl->location_mode);
- _gtk_file_chooser_settings_set_show_hidden (settings, gtk_file_chooser_get_show_hidden (GTK_FILE_CHOOSER (impl)));
- _gtk_file_chooser_settings_set_expand_folders (settings, impl->expand_folders);
- _gtk_file_chooser_settings_set_show_size_column (settings, impl->show_size_column);
- _gtk_file_chooser_settings_set_sort_column (settings, impl->sort_column);
- _gtk_file_chooser_settings_set_sort_order (settings, impl->sort_order);
+ save_dialog_geometry (impl);
- save_dialog_geometry (impl, settings);
+ /* Now apply the settings */
+ g_settings_apply (impl->settings);
- /* NULL GError */
- _gtk_file_chooser_settings_save (settings, NULL);
-
- g_object_unref (settings);
+ g_object_unref (impl->settings);
+ impl->settings = NULL;
}
/* GtkWidget::realize method */
@@ -7853,12 +7870,12 @@ gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed,
|| impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
|| impl->expand_folders)
{
- GtkFileChooserSettings *settings;
int x, y, width, height;
- settings = _gtk_file_chooser_settings_new ();
- _gtk_file_chooser_settings_get_geometry (settings, &x, &y, &width, &height);
- g_object_unref (settings);
+ settings_ensure (impl);
+
+ g_settings_get (impl->settings, SETTINGS_KEY_WINDOW_POSITION, "(ii)", &x, &y);
+ g_settings_get (impl->settings, SETTINGS_KEY_WINDOW_SIZE, "(ii)", &width, &height);
if (x >= 0 && y >= 0 && width > 0 && height > 0)
{
diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c
index 9408fa4..dd8a9a8 100644
--- a/gtk/gtkfilechooserdialog.c
+++ b/gtk/gtkfilechooserdialog.c
@@ -27,7 +27,6 @@
#include "gtkfilechooserwidget.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooserembed.h"
-#include "gtkfilechoosersettings.h"
#include "gtkfilesystem.h"
#include "gtksizerequest.h"
#include "gtktypebuiltins.h"
diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h
index a3ccaae..7fc8ec7 100644
--- a/gtk/gtkfilechooserprivate.h
+++ b/gtk/gtkfilechooserprivate.h
@@ -278,6 +278,8 @@ struct _GtkFileChooserDefault
gint sort_column;
GtkSortType sort_order;
+ GSettings *settings;
+
#if 0
GdkDragContext *shortcuts_drag_context;
GSource *shortcuts_drag_outside_idle;
diff --git a/gtk/org.gtk.Settings.FileChooser.gschema.xml b/gtk/org.gtk.Settings.FileChooser.gschema.xml
new file mode 100644
index 0000000..296d6d3
--- /dev/null
+++ b/gtk/org.gtk.Settings.FileChooser.gschema.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright © 2010 Christian Persch
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1, 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 Lesser 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.
+-->
+<schemalist>
+
+ <enum id='org.gtk.Settings.FileChooser.LocationMode'>
+ <value nick='path-bar' value='0'/>
+ <value nick='filename-entry' value='1'/>
+ </enum>
+
+ <enum id='org.gtk.Settings.FileChooser.SortColumn'>
+ <value nick='name' value='0'/>
+ <value nick='size' value='1'/>
+ <value nick='modified' value='2'/>
+ </enum>
+
+ <enum id='org.gtk.Settings.FileChooser.SortOrder'>
+ <value nick='ascending' value='0'/>
+ <value nick='descending' value='1'/>
+ </enum>
+
+ <schema id='org.gtk.Settings.FileChooser'>
+ <key name='location-mode' enum='org.gtk.Settings.FileChooser.LocationMode'>
+ <default>'path-bar'</default>
+ </key>
+ <key name='show-hidden' type='b'>
+ <default>false</default>
+ </key>
+ <key name='expand-folders' type='b'>
+ <default>false</default>
+ </key>
+ <key name='show-size-column' type='b'>
+ <default>true</default>
+ </key>
+ <key name='sort-column' enum='org.gtk.Settings.FileChooser.SortColumn'>
+ <default>'name'</default>
+ </key>
+ <key name='sort-order' enum='org.gtk.Settings.FileChooser.SortOrder'>
+ <default>'ascending'</default>
+ </key>
+ <key name='window-position' type='(ii)'>
+ <default>(-1, -1)</default>
+ </key>
+ <key name='window-size' type='(ii)'>
+ <default>(-1, -1)</default>
+ </key>
+ </schema>
+
+</schemalist>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]