[gtk+] filechooser: Attach GSettings object to GtkSettings
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] filechooser: Attach GSettings object to GtkSettings
- Date: Thu, 24 Jan 2013 13:29:35 +0000 (UTC)
commit 78d91aaf9b9777d0d42879b5d4495265ea0abaa6
Author: Benjamin Otte <otte redhat com>
Date: Wed Jan 23 03:23:33 2013 +0100
filechooser: Attach GSettings object to GtkSettings
... instead of keeping one per GtkFileChooserDefault. This allows using
it in other places, too.
gtk/gtkfilechooserdefault.c | 66 +++++++++++++++++++-----------------------
gtk/gtkfilechooserprivate.h | 2 -
gtk/gtkfilechooserutils.c | 27 +++++++++++++++++
gtk/gtkfilechooserutils.h | 2 +
4 files changed, 59 insertions(+), 38 deletions(-)
---
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 8fcc25f..d31cab8 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -6015,16 +6015,6 @@ set_sort_column (GtkFileChooserDefault *impl)
}
static void
-settings_ensure (GtkFileChooserDefault *impl)
-{
- if (impl->settings != NULL)
- return;
-
- impl->settings = g_settings_new ("org.gtk.Settings.FileChooser");
- g_settings_delay (impl->settings);
-}
-
-static void
settings_load (GtkFileChooserDefault *impl)
{
LocationMode location_mode;
@@ -6033,15 +6023,16 @@ settings_load (GtkFileChooserDefault *impl)
gint sort_column;
GtkSortType sort_order;
gint sidebar_width;
+ GSettings *settings;
- settings_ensure (impl);
+ settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (impl));
- 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);
- sidebar_width = g_settings_get_int (impl->settings, SETTINGS_KEY_SIDEBAR_WIDTH);
+ location_mode = g_settings_get_enum (settings, SETTINGS_KEY_LOCATION_MODE);
+ show_hidden = g_settings_get_boolean (settings, SETTINGS_KEY_SHOW_HIDDEN);
+ show_size_column = g_settings_get_boolean (settings, SETTINGS_KEY_SHOW_SIZE_COLUMN);
+ sort_column = g_settings_get_enum (settings, SETTINGS_KEY_SORT_COLUMN);
+ sort_order = g_settings_get_enum (settings, SETTINGS_KEY_SORT_ORDER);
+ sidebar_width = g_settings_get_int (settings, SETTINGS_KEY_SIDEBAR_WIDTH);
location_mode_set (impl, location_mode, TRUE);
@@ -6065,25 +6056,29 @@ save_dialog_geometry (GtkFileChooserDefault *impl)
{
GtkWindow *toplevel;
int x, y, width, height;
+ GSettings *settings;
toplevel = get_toplevel (GTK_WIDGET (impl));
if (!(toplevel && GTK_IS_FILE_CHOOSER_DIALOG (toplevel)))
return;
+ settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (toplevel));
+
gtk_window_get_position (toplevel, &x, &y);
gtk_window_get_size (toplevel, &width, &height);
- g_settings_set (impl->settings, SETTINGS_KEY_WINDOW_POSITION, "(ii)", x, y);
- g_settings_set (impl->settings, SETTINGS_KEY_WINDOW_SIZE, "(ii)", width, height);
+ g_settings_set (settings, SETTINGS_KEY_WINDOW_POSITION, "(ii)", x, y);
+ g_settings_set (settings, SETTINGS_KEY_WINDOW_SIZE, "(ii)", width, height);
}
static void
settings_save (GtkFileChooserDefault *impl)
{
char *current_folder_uri;
+ GSettings *settings;
- settings_ensure (impl);
+ settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (impl));
/* Current folder */
@@ -6092,29 +6087,26 @@ settings_save (GtkFileChooserDefault *impl)
else
current_folder_uri = "";
- g_settings_set_string (impl->settings, SETTINGS_KEY_LAST_FOLDER_URI, current_folder_uri);
+ g_settings_set_string (settings, SETTINGS_KEY_LAST_FOLDER_URI, current_folder_uri);
if (impl->current_folder)
g_free (current_folder_uri);
/* All the other state */
- g_settings_set_enum (impl->settings, SETTINGS_KEY_LOCATION_MODE, impl->location_mode);
- g_settings_set_boolean (impl->settings, SETTINGS_KEY_SHOW_HIDDEN,
+ g_settings_set_enum (settings, SETTINGS_KEY_LOCATION_MODE, impl->location_mode);
+ g_settings_set_boolean (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);
- g_settings_set_int (impl->settings, SETTINGS_KEY_SIDEBAR_WIDTH,
+ g_settings_set_boolean (settings, SETTINGS_KEY_SHOW_SIZE_COLUMN, impl->show_size_column);
+ g_settings_set_enum (settings, SETTINGS_KEY_SORT_COLUMN, impl->sort_column);
+ g_settings_set_enum (settings, SETTINGS_KEY_SORT_ORDER, impl->sort_order);
+ g_settings_set_int (settings, SETTINGS_KEY_SIDEBAR_WIDTH,
gtk_paned_get_position (GTK_PANED (impl->browse_widgets_hpaned)));
save_dialog_geometry (impl);
/* Now apply the settings */
- g_settings_apply (impl->settings);
-
- g_object_unref (impl->settings);
- impl->settings = NULL;
+ g_settings_apply (settings);
}
/* GtkWidget::realize method */
@@ -6134,11 +6126,12 @@ static GFile *
get_file_for_last_folder_opened (GtkFileChooserDefault *impl)
{
char *last_folder_uri;
+ GSettings *settings;
GFile *file;
- settings_ensure (impl);
+ settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (impl));
- last_folder_uri = g_settings_get_string (impl->settings, SETTINGS_KEY_LAST_FOLDER_URI);
+ last_folder_uri = g_settings_get_string (settings, SETTINGS_KEY_LAST_FOLDER_URI);
/* If no last folder is set, we use the user's home directory, since
* this is the starting point for most documents.
@@ -8214,13 +8207,14 @@ gtk_file_chooser_default_get_default_size (GtkFileChooserEmbed *chooser_embed,
GtkFileChooserDefault *impl;
GtkRequisition req;
int x, y, width, height;
+ GSettings *settings;
impl = GTK_FILE_CHOOSER_DEFAULT (chooser_embed);
- settings_ensure (impl);
+ settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (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);
+ g_settings_get (settings, SETTINGS_KEY_WINDOW_POSITION, "(ii)", &x, &y);
+ g_settings_get (settings, SETTINGS_KEY_WINDOW_SIZE, "(ii)", &width, &height);
if (x >= 0 && y >= 0 && width > 0 && height > 0)
{
diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h
index 76380a1..fa2dc66 100644
--- a/gtk/gtkfilechooserprivate.h
+++ b/gtk/gtkfilechooserprivate.h
@@ -280,8 +280,6 @@ 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/gtkfilechooserutils.c b/gtk/gtkfilechooserutils.c
index f06b7aa..43148aa 100644
--- a/gtk/gtkfilechooserutils.c
+++ b/gtk/gtkfilechooserutils.c
@@ -414,3 +414,30 @@ _gtk_file_chooser_extract_recent_folders (GList *infos)
return result;
}
+
+GSettings *
+_gtk_file_chooser_get_settings_for_widget (GtkWidget *widget)
+{
+ static GQuark file_chooser_settings_quark = 0;
+ GtkSettings *gtksettings;
+ GSettings *settings;
+
+ if (G_UNLIKELY (file_chooser_settings_quark == 0))
+ file_chooser_settings_quark = g_quark_from_static_string ("-gtk-file-chooser-settings");
+
+ gtksettings = gtk_widget_get_settings (widget);
+ settings = g_object_get_qdata (G_OBJECT (gtksettings), file_chooser_settings_quark);
+
+ if (G_UNLIKELY (settings == NULL))
+ {
+ settings = g_settings_new ("org.gtk.Settings.FileChooser");
+ g_settings_delay (settings);
+
+ g_object_set_qdata_full (G_OBJECT (gtksettings),
+ file_chooser_settings_quark,
+ settings,
+ g_object_unref);
+ }
+
+ return settings;
+}
diff --git a/gtk/gtkfilechooserutils.h b/gtk/gtkfilechooserutils.h
index f4861ee..ad9ef36 100644
--- a/gtk/gtkfilechooserutils.h
+++ b/gtk/gtkfilechooserutils.h
@@ -52,6 +52,8 @@ GQuark _gtk_file_chooser_delegate_get_quark (void) G_GNUC_CONST;
GList *_gtk_file_chooser_extract_recent_folders (GList *infos);
+GSettings *_gtk_file_chooser_get_settings_for_widget (GtkWidget *widget);
+
G_END_DECLS
#endif /* __GTK_FILE_CHOOSER_UTILS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]