[Xfce4-commits] [apps/mousepad] 28/45: Re-write the settings to make easier to use from code
noreply at xfce.org
noreply at xfce.org
Fri Jul 11 13:03:33 CEST 2014
This is an automated email from the git hooks/post-receive script.
mbrush pushed a commit to branch master
in repository apps/mousepad.
commit 83d0ced75fb623f2289e0657e4c68c454653609c
Author: Matthew Brush <mbrush at codebrainz.ca>
Date: Wed Jul 9 03:31:21 2014 -0700
Re-write the settings to make easier to use from code
But still keeping nested schemas to make it easier from dconf-editor
and in keyfile sections.
---
mousepad/mousepad-application.c | 4 +
mousepad/mousepad-document.c | 3 +-
mousepad/mousepad-private.h | 14 -
mousepad/mousepad-replace-dialog.c | 47 ++-
mousepad/mousepad-search-bar.c | 10 +-
mousepad/mousepad-settings.c | 562 ++++++++++++++++++++++++------------
mousepad/mousepad-settings.h | 156 +++++-----
mousepad/mousepad-view.c | 4 +-
mousepad/mousepad-window.c | 163 +++++------
9 files changed, 541 insertions(+), 422 deletions(-)
diff --git a/mousepad/mousepad-application.c b/mousepad/mousepad-application.c
index cf0ee44..e0c3e09 100644
--- a/mousepad/mousepad-application.c
+++ b/mousepad/mousepad-application.c
@@ -76,6 +76,8 @@ mousepad_application_init (MousepadApplication *application)
{
gchar *filename;
+ mousepad_settings_init ();
+
/* check if we have a saved accel map */
filename = mousepad_util_get_save_location (MOUSEPAD_ACCELS_RELPATH, FALSE);
if (G_LIKELY (filename != NULL))
@@ -123,6 +125,8 @@ mousepad_application_finalize (GObject *object)
/* cleanup the list of windows */
g_slist_free (application->windows);
+ mousepad_settings_finalize ();
+
(*G_OBJECT_CLASS (mousepad_application_parent_class)->finalize) (object);
}
diff --git a/mousepad/mousepad-document.c b/mousepad/mousepad-document.c
index 0d2819e..e92c7d1 100644
--- a/mousepad/mousepad-document.c
+++ b/mousepad/mousepad-document.c
@@ -260,8 +260,7 @@ mousepad_document_notify_cursor_position (GtkTextBuffer *buffer,
line = gtk_text_iter_get_line (&iter) + 1;
/* get the tab size */
- tab_size = mousepad_settings_get_int (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_TAB_WIDTH);
+ tab_size = MOUSEPAD_SETTING_GET_INT (TAB_WIDTH);
/* get the column */
column = mousepad_util_get_real_line_offset (&iter, tab_size);
diff --git a/mousepad/mousepad-private.h b/mousepad/mousepad-private.h
index 5fddbd1..ebdc5b5 100644
--- a/mousepad/mousepad-private.h
+++ b/mousepad/mousepad-private.h
@@ -122,20 +122,6 @@ enum
#define mousepad_widget_set_tooltip_text(widget,text) (mousepad_util_set_tooltip (widget, text))
#endif
-/* Access to the various GSettings instances */
-#define MOUSEPAD_VIEW_SETTINGS \
- (mousepad_settings_get_from_schema (mousepad_settings_get_default (), \
- MOUSEPAD_SCHEMA_VIEW_SETTINGS))
-#define MOUSEPAD_WINDOW_SETTINGS \
- (mousepad_settings_get_from_schema (mousepad_settings_get_default (), \
- MOUSEPAD_SCHEMA_WINDOW_SETTINGS))
-#define MOUSEPAD_SEARCH_STATE_SETTINGS \
- (mousepad_settings_get_from_schema (mousepad_settings_get_default (), \
- MOUSEPAD_SCHEMA_SEARCH_STATE))
-#define MOUSEPAD_WINDOW_STATE_SETTINGS \
- (mousepad_settings_get_from_schema (mousepad_settings_get_default (), \
- MOUSEPAD_SCHEMA_WINDOW_STATE))
-
G_END_DECLS
#endif /* !__MOUSEPAD_PRIVATE_H__ */
diff --git a/mousepad/mousepad-replace-dialog.c b/mousepad/mousepad-replace-dialog.c
index acf57a2..8bf568a 100644
--- a/mousepad/mousepad-replace-dialog.c
+++ b/mousepad/mousepad-replace-dialog.c
@@ -39,7 +39,7 @@ static void mousepad_replace_dialog_response (GtkWidg
static void mousepad_replace_dialog_changed (MousepadReplaceDialog *dialog);
static void mousepad_replace_dialog_settings_changed (MousepadReplaceDialog *dialog,
gchar *key,
- MousepadSettings *settings);
+ GSettings *settings);
static void mousepad_replace_dialog_history_combo_box (GtkComboBox *combo_box);
static void mousepad_replace_dialog_history_insert_text (const gchar *text);
@@ -120,19 +120,16 @@ mousepad_replace_dialog_class_init (MousepadReplaceDialogClass *klass)
static void
mousepad_replace_dialog_bind_setting (MousepadReplaceDialog *dialog,
- const gchar *key,
+ const gchar *path,
gpointer object,
const gchar *property)
{
- mousepad_settings_bind (MOUSEPAD_SCHEMA_SEARCH_STATE, key,
- object, property,
- G_SETTINGS_BIND_DEFAULT);
-
- mousepad_settings_connect_changed (MOUSEPAD_SCHEMA_SEARCH_STATE,
- key,
- G_CALLBACK (mousepad_replace_dialog_settings_changed),
- dialog,
- G_CONNECT_SWAPPED);
+ mousepad_setting_bind (path, object, property, G_SETTINGS_BIND_DEFAULT);
+
+ mousepad_setting_connect (path,
+ G_CALLBACK (mousepad_replace_dialog_settings_changed),
+ dialog,
+ G_CONNECT_SWAPPED);
}
@@ -224,7 +221,7 @@ mousepad_replace_dialog_init (MousepadReplaceDialog *dialog)
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Both"));
gtk_widget_show (combo);
- mousepad_replace_dialog_bind_setting (dialog, MOUSEPAD_STATE_SEARCH_DIRECTION, combo, "active");
+ mousepad_replace_dialog_bind_setting (dialog, MOUSEPAD_SETTING_SEARCH_DIRECTION, combo, "active");
/* release size group */
g_object_unref (G_OBJECT (size_group));
@@ -234,14 +231,14 @@ mousepad_replace_dialog_init (MousepadReplaceDialog *dialog)
gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
gtk_widget_show (check);
- mousepad_replace_dialog_bind_setting (dialog, MOUSEPAD_STATE_SEARCH_MATCH_CASE, check, "active");
+ mousepad_replace_dialog_bind_setting (dialog, MOUSEPAD_SETTING_SEARCH_MATCH_CASE, check, "active");
/* match whole word */
check = gtk_check_button_new_with_mnemonic (_("_Match whole word"));
gtk_box_pack_start (GTK_BOX (vbox), check, FALSE, FALSE, 0);
gtk_widget_show (check);
- mousepad_replace_dialog_bind_setting (dialog, MOUSEPAD_STATE_SEARCH_MATCH_WHOLE_WORD, check, "active");
+ mousepad_replace_dialog_bind_setting (dialog, MOUSEPAD_SETTING_SEARCH_MATCH_WHOLE_WORD, check, "active");
/* horizontal box for the replace all options */
hbox = gtk_hbox_new (FALSE, 8);
@@ -252,7 +249,7 @@ mousepad_replace_dialog_init (MousepadReplaceDialog *dialog)
gtk_box_pack_start (GTK_BOX (hbox), check, FALSE, FALSE, 0);
gtk_widget_show (check);
- mousepad_replace_dialog_bind_setting (dialog, MOUSEPAD_STATE_SEARCH_REPLACE_ALL, check, "active");
+ mousepad_replace_dialog_bind_setting (dialog, MOUSEPAD_SETTING_SEARCH_REPLACE_ALL, check, "active");
combo = dialog->search_location_combo = gtk_combo_box_new_text ();
gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0);
@@ -262,7 +259,7 @@ mousepad_replace_dialog_init (MousepadReplaceDialog *dialog)
gtk_widget_set_sensitive (combo, FALSE);
gtk_widget_show (combo);
- mousepad_replace_dialog_bind_setting (dialog, MOUSEPAD_STATE_SEARCH_REPLACE_ALL_LOCATION, combo, "active");
+ mousepad_replace_dialog_bind_setting (dialog, MOUSEPAD_SETTING_SEARCH_REPLACE_ALL_LOCATION, combo, "active");
label = dialog->hits_label = gtk_label_new (NULL);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
@@ -317,11 +314,11 @@ mousepad_replace_dialog_response (GtkWidget *widget,
gboolean match_case, match_whole_word, replace_all;
/* read the search settings */
- search_direction = mousepad_settings_get_int (MOUSEPAD_SCHEMA_SEARCH_STATE, MOUSEPAD_STATE_SEARCH_DIRECTION);
- replace_all_location = mousepad_settings_get_int (MOUSEPAD_SCHEMA_SEARCH_STATE, MOUSEPAD_STATE_SEARCH_REPLACE_ALL_LOCATION);
- match_case = mousepad_settings_get_boolean (MOUSEPAD_SCHEMA_SEARCH_STATE, MOUSEPAD_STATE_SEARCH_MATCH_CASE);
- match_whole_word = mousepad_settings_get_boolean (MOUSEPAD_SCHEMA_SEARCH_STATE, MOUSEPAD_STATE_SEARCH_MATCH_WHOLE_WORD);
- replace_all = mousepad_settings_get_boolean (MOUSEPAD_SCHEMA_SEARCH_STATE, MOUSEPAD_STATE_SEARCH_REPLACE_ALL);
+ search_direction = MOUSEPAD_SETTING_GET_INT (SEARCH_DIRECTION);
+ replace_all_location = MOUSEPAD_SETTING_GET_INT (SEARCH_REPLACE_ALL_LOCATION);
+ match_case = MOUSEPAD_SETTING_GET_BOOLEAN (SEARCH_MATCH_CASE);
+ match_whole_word = MOUSEPAD_SETTING_GET_BOOLEAN (SEARCH_MATCH_WHOLE_WORD);
+ replace_all = MOUSEPAD_SETTING_GET_BOOLEAN (SEARCH_REPLACE_ALL);
/* close dialog */
if (response_id == MOUSEPAD_RESPONSE_CLOSE)
@@ -443,8 +440,7 @@ mousepad_replace_dialog_changed (MousepadReplaceDialog *dialog)
gboolean sensitive;
gboolean replace_all;
- replace_all = mousepad_settings_get_boolean (MOUSEPAD_SCHEMA_SEARCH_STATE,
- MOUSEPAD_STATE_SEARCH_REPLACE_ALL);
+ replace_all = MOUSEPAD_SETTING_GET_BOOLEAN (SEARCH_REPLACE_ALL);
/* set the sensitivity of some dialog widgets */
gtk_widget_set_sensitive (dialog->search_location_combo, replace_all);
@@ -486,11 +482,10 @@ mousepad_replace_dialog_changed (MousepadReplaceDialog *dialog)
static void
mousepad_replace_dialog_settings_changed (MousepadReplaceDialog *dialog,
gchar *key,
- MousepadSettings *settings)
+ GSettings *settings)
{
/* reset occurences label */
- if (g_strcmp0 (key, MOUSEPAD_STATE_SEARCH_REPLACE_ALL) == 0)
- gtk_label_set_text (GTK_LABEL (dialog->hits_label), NULL);
+ gtk_label_set_text (GTK_LABEL (dialog->hits_label), NULL);
mousepad_replace_dialog_changed (dialog);
}
diff --git a/mousepad/mousepad-search-bar.c b/mousepad/mousepad-search-bar.c
index 6654a13..917bb3c 100644
--- a/mousepad/mousepad-search-bar.c
+++ b/mousepad/mousepad-search-bar.c
@@ -159,9 +159,8 @@ mousepad_search_bar_init (MousepadSearchBar *bar)
GtkToolItem *item;
gboolean match_case;
- /* load some preferences */
- match_case = mousepad_settings_get_boolean (MOUSEPAD_SCHEMA_SEARCH_STATE,
- MOUSEPAD_STATE_SEARCH_MATCH_CASE);
+ /* load some saved state */
+ match_case = MOUSEPAD_SETTING_GET_BOOLEAN (SEARCH_MATCH_CASE);
/* init variables */
bar->highlight_id = 0;
@@ -241,10 +240,7 @@ mousepad_search_bar_init (MousepadSearchBar *bar)
gtk_widget_show (check);
/* keep the widgets in sync with the GSettings */
- mousepad_settings_bind (MOUSEPAD_SCHEMA_SEARCH_STATE,
- MOUSEPAD_STATE_SEARCH_MATCH_CASE,
- check, "active",
- G_SETTINGS_BIND_DEFAULT);
+ MOUSEPAD_SETTING_BIND (SEARCH_MATCH_CASE, check, "active", G_SETTINGS_BIND_DEFAULT);
/* overflow menu item for when window is too narrow to show the tool bar item */
bar->match_case_entry = menuitem = gtk_check_menu_item_new_with_mnemonic (_("Mat_ch Case"));
diff --git a/mousepad/mousepad-settings.c b/mousepad/mousepad-settings.c
index f9fa270..db6fb20 100644
--- a/mousepad/mousepad-settings.c
+++ b/mousepad/mousepad-settings.c
@@ -1,6 +1,7 @@
#include <mousepad/mousepad-private.h>
#include <mousepad/mousepad-settings.h>
#include <stdlib.h>
+#include <ctype.h>
#ifdef MOUSEPAD_SETTINGS_KEYFILE_BACKEND
/* Needed to use keyfile GSettings backend */
@@ -9,332 +10,509 @@
#endif
-struct MousepadSettings_
+
+typedef enum
{
- GObject parent;
- GSettings *settings[MOUSEPAD_NUM_SCHEMAS];
-};
+ MOUSEPAD_SCHEMA_VIEW_SETTINGS,
+ MOUSEPAD_SCHEMA_WINDOW_SETTINGS,
+ MOUSEPAD_SCHEMA_SEARCH_STATE,
+ MOUSEPAD_SCHEMA_WINDOW_STATE,
+ MOUSEPAD_NUM_SCHEMAS
+}
+MousepadSchema;
-struct MousepadSettingsClass_
+static const gchar *
+mousepad_schema_ids[MOUSEPAD_NUM_SCHEMAS] =
{
- GObjectClass parent_class;
+ "org.xfce.mousepad.preferences.view",
+ "org.xfce.mousepad.preferences.window",
+ "org.xfce.mousepad.state.search",
+ "org.xfce.mousepad.state.window"
};
-static void mousepad_settings_finalize (GObject *object);
+static GSettings *mousepad_settings[MOUSEPAD_NUM_SCHEMAS] = { NULL };
+static gint mousepad_settings_init_count = 0;
-G_DEFINE_TYPE (MousepadSettings, mousepad_settings, G_TYPE_OBJECT)
+G_LOCK_DEFINE (settings_lock);
+#define MOUSEPAD_SETTINGS_LOCK() G_LOCK (settings_lock)
+#define MOUSEPAD_SETTINGS_UNLOCK() G_UNLOCK (settings_lock)
-/* Global instance, accessed by mousepad_settings_get_default() */
-static MousepadSettings *default_settings = NULL;
+void
+mousepad_settings_finalize (void)
+{
+ gint i;
+ MOUSEPAD_SETTINGS_LOCK ();
+ g_settings_sync ();
-static const gchar *mousepad_schema_ids[MOUSEPAD_NUM_SCHEMAS] =
-{
- "org.xfce.mousepad.preferences.view",
- "org.xfce.mousepad.preferences.window",
- "org.xfce.mousepad.state.search",
- "org.xfce.mousepad.state.window"
-};
+ mousepad_settings_init_count--;
+ if (mousepad_settings_init_count > 0)
+ {
+ MOUSEPAD_SETTINGS_UNLOCK ();
+ return;
+ }
+ MOUSEPAD_SETTINGS_UNLOCK ();
+ for (i = 0; i < MOUSEPAD_NUM_SCHEMAS; i++)
+ {
+ if (G_IS_SETTINGS (mousepad_settings[i]))
+ {
+ g_object_unref (mousepad_settings[i]);
+ mousepad_settings[i] = NULL;
+ }
+ }
+}
-GType
-mousepad_schema_get_type (void)
+
+static void
+mousepad_settings_update_gsettings_schema_dir (void)
{
- static GType type = 0;
- if (G_UNLIKELY (type == 0))
+ const gchar *old_value;
+
+ old_value = g_getenv ("GSETTINGS_SCHEMA_DIR");
+ /* Append to existing env. var. if not in there yet */
+ if (old_value != NULL &&
+ strstr (old_value, MOUSEPAD_GSETTINGS_SCHEMA_DIR) != NULL)
{
- static const GEnumValue values[] =
- {
- { MOUSEPAD_SCHEMA_VIEW_SETTINGS, "MOUSEPAD_SCHEMA_VIEW_SETTINGS", "view-settings" },
- { MOUSEPAD_SCHEMA_WINDOW_SETTINGS, "MOUSEPAD_SCHEMA_WINDOW_SETTINGS", "window-settings" },
- { MOUSEPAD_SCHEMA_SEARCH_STATE, "MOUSEPAD_SCHEMA_SEARCH_STATE", "search-state" },
- { MOUSEPAD_SCHEMA_WINDOW_STATE, "MOUSEPAD_SCHEMA_WINDOW_STATE", "window-state" },
- { 0, NULL, NULL }
- };
- type = g_enum_register_static ("MousepadSchema", values);
+ gchar *new_value;
+#ifndef G_OS_WIN32
+ const gchar *pathsep = ":";
+#else
+ const gchar *pathsep = ";";
+#endif
+ new_value = g_strconcat (old_value, pathsep, MOUSEPAD_GSETTINGS_SCHEMA_DIR, NULL);
+ g_setenv ("GSETTINGS_SCHEMA_DIR", new_value, TRUE);
+ g_free (new_value);
+ }
+ /* Create a new env. var. */
+ else
+ {
+ g_setenv ("GSETTINGS_SCHEMA_DIR", MOUSEPAD_GSETTINGS_SCHEMA_DIR, FALSE);
}
- return type;
}
-static void
-mousepad_settings_class_init (MousepadSettingsClass *klass)
+void
+mousepad_settings_init (void)
+{
+
+ MOUSEPAD_SETTINGS_LOCK ();
+
+ if (mousepad_settings_init_count == 0)
+ {
+ gint i;
+
+ /* If we're installed in an unusual location, we still want to load
+ * the schema so enforce this with the relevant environment variable. */
+ mousepad_settings_update_gsettings_schema_dir ();
+
+#ifdef MOUSEPAD_SETTINGS_KEYFILE_BACKEND
{
- GObjectClass *g_object_class;
+ GSettingsBackend *backend;
+ gchar *conf_file;
+
+ /* Path inside user's config directory */
+ conf_file = g_build_filename (g_get_user_config_dir (),
+ "Mousepad",
+ "settings.conf",
+ NULL);
+
+ /* Create a keyfile backend */
+ backend = g_keyfile_settings_backend_new (conf_file, "/", NULL);
+ g_free (conf_file);
+
+ for (i = 0; i < MOUSEPAD_NUM_SCHEMAS; i++)
+ {
+ mousepad_settings[i] = g_object_new (G_TYPE_SETTINGS,
+ "backend", backend,
+ "schema-id", mousepad_schema_ids[i],
+ NULL);
+ /* TODO: need to cleanup backend reference? */
+ }
+}
+#else
+ for (i = 0; i < MOUSEPAD_NUM_SCHEMAS; i++)
+ mousepad_settings[i] = g_settings_new (mousepad_schema_ids[i]);
+#endif
+ }
- g_object_class = G_OBJECT_CLASS (klass);
+ mousepad_settings_init_count++;
- g_object_class->finalize = mousepad_settings_finalize;
+ MOUSEPAD_SETTINGS_UNLOCK ();
}
-static void
-mousepad_settings_finalize (GObject *object)
+/* checks that string starts and ends with alnum character and contains only
+ * alnum, underscore or dash/hyphen characters */
+static gboolean
+mousepad_settings_check_path_part (const gchar *s,
+ gint len)
{
gint i;
- MousepadSettings *self = MOUSEPAD_SETTINGS (object);
- G_OBJECT_CLASS (mousepad_settings_parent_class)->finalize (object);
+ if (! isalnum (s[0]) || ! isalnum (s[len-1]))
+ return FALSE;
- g_settings_sync ();
-
- for (i = 0; i < MOUSEPAD_NUM_SCHEMAS; i++)
+ for (i = 0; i < len ; i++)
{
- if (G_IS_SETTINGS (self->settings[i]))
- g_object_unref (self->settings[i]);
+ if (! isalnum (s[i]) && s[i] != '-' && s[i] != '_')
+ return FALSE;
}
+
+ return TRUE;
}
-static void
-mousepad_settings_init (MousepadSettings *self)
-{
- gint i;
-#ifdef MOUSEPAD_SETTINGS_KEYFILE_BACKEND
- GSettingsBackend *backend;
- gchar *conf_file;
+static gboolean
+mousepad_settings_parse_path_names (const gchar *path,
+ const gchar **type,
+ gint *type_length,
+ const gchar **schema,
+ gint *schema_length,
+ const gchar **key,
+ gint *key_length,
+ gboolean validate_parts)
+{
+ const gchar *t=NULL, *s=NULL, *k=NULL, *p;
+ gint tl=0, sl=0, kl=0;
- /* Path inside user's config directory */
- conf_file = g_build_filename (g_get_user_config_dir (),
- "Mousepad",
- "settings.conf",
- NULL);
+ if (G_UNLIKELY (! path || ! path[0]))
+ return FALSE;
- /* Create a keyfile backend */
- backend = g_keyfile_settings_backend_new (conf_file, "/", NULL);
- g_free (conf_file);
+ p = path;
+ while (*p)
+ {
+ if (*p == '/' || p == path /* first char but not a slash */)
+ {
+ if (t == NULL)
+ {
+ /* skip leading slash if exists */
+ t = (*p == '/') ? ++p : p++;
+ continue;
+ }
+ else if (s == NULL)
+ {
+ tl = p - t;
+ s = ++p;
+ continue;
+ }
+ else if (k == NULL)
+ {
+ sl = p - s;
+ k = ++p;
+ continue;
+ }
+ }
+ ++p;
+ }
- for (i = 0; i < MOUSEPAD_NUM_SCHEMAS; i++)
+ kl = p - k;
+ /* remove trailing slash if it exists */
+ if (k[kl - 1] == '/')
+ kl--;
+
+ /* sanity checking on what was actually parsed (or not) */
+ if (!t || !s || !k || !tl || !sl || !kl ||
+ (validate_parts &&
+ (! mousepad_settings_check_path_part (t, tl) ||
+ ! mousepad_settings_check_path_part (s, sl) ||
+ ! mousepad_settings_check_path_part (k, kl))))
{
- self->settings[i] = g_object_new (G_TYPE_SETTINGS,
- "backend", backend,
- "schema-id", mousepad_schema_ids[i],
- NULL);
- /* TODO: need to cleanup backend reference? */
+ return FALSE;
}
-#else
- for (i = 0; i < MOUSEPAD_NUM_SCHEMAS; i++)
- self->settings[i] = g_settings_new (mousepad_schema_ids[i]);
-#endif
+
+ /* return desired values to caller */
+ if (type) *type = t;
+ if (type_length) *type_length = tl;
+ if (schema) *schema = s;
+ if (schema_length) *schema_length = sl;
+ if (key) *key = k;
+ if (key_length) *key_length = kl;
+
+ return TRUE;
}
-/* Called at exit to cleanup the MousepadSettings singleton */
-static void
-mousepad_settings_cleanup_default (void)
+static MousepadSchema
+mousepad_settings_schema_from_names (const gchar *type,
+ gint type_len,
+ const gchar *name,
+ gint name_len)
{
- /* cleanup the singleton settings instance */
- if (MOUSEPAD_IS_SETTINGS (default_settings))
+ if (type_len == 11 && strncmp ("preferences", type, type_len) == 0)
+ {
+ if (name_len == 4 && strncmp ("view", name, name_len) == 0)
+ return MOUSEPAD_SCHEMA_VIEW_SETTINGS;
+ else if (name_len == 6 && strncmp ("window", name, name_len) == 0)
+ return MOUSEPAD_SCHEMA_WINDOW_SETTINGS;
+ }
+ else if (type_len == 5 && strncmp ("state", type, type_len) == 0)
{
- g_object_unref (default_settings);
- default_settings = NULL;
+ if (name_len == 6 && strncmp ("search", name, name_len) == 0)
+ return MOUSEPAD_SCHEMA_SEARCH_STATE;
+ else if (name_len == 6 && strncmp ("window", name, name_len) == 0)
+ return MOUSEPAD_SCHEMA_WINDOW_STATE;
}
+ return MOUSEPAD_NUM_SCHEMAS; /* not found */
}
-static void
-mousepad_settings_update_gsettings_schema_dir (void)
+static MousepadSchema
+mousepad_settings_parse_path (const gchar *path,
+ const gchar **key_name)
{
- const gchar *old_value = g_getenv ("GSETTINGS_SCHEMA_DIR");
- /* Append to existing env. var. */
- if (old_value != NULL)
+ const gchar *type_name, *schema_name;
+ gint type_len, schema_len, key_len;
+
+ if (mousepad_settings_parse_path_names (path,
+ &type_name,
+ &type_len,
+ &schema_name,
+ &schema_len,
+ key_name,
+ &key_len,
+ TRUE))
{
- gchar *new_value;
-#ifndef G_OS_WIN32
- const gchar *pathsep = ":";
-#else
- const gchar *pathsep = ";";
-#endif
- new_value = g_strconcat (old_value, pathsep, MOUSEPAD_GSETTINGS_SCHEMA_DIR, NULL);
- g_setenv ("GSETTINGS_SCHEMA_DIR", new_value, TRUE);
- g_free (new_value);
+ MousepadSchema schema;
+
+ schema = mousepad_settings_schema_from_names (type_name,
+ type_len,
+ schema_name,
+ schema_len);
+
+ if (schema == MOUSEPAD_NUM_SCHEMAS && key_name != NULL)
+ *key_name = NULL;
+
+ return schema;
}
- /* Create a new env. var. */
- else
+ else if (key_name != NULL)
{
- g_setenv ("GSETTINGS_SCHEMA_DIR", MOUSEPAD_GSETTINGS_SCHEMA_DIR, FALSE);
+ *key_name = NULL;
}
+
+ return MOUSEPAD_NUM_SCHEMAS;
}
-/* The first time it's called, it constructs the singleton instance that
- * is always returned and is automatically cleaned up during normal exit. */
-MousepadSettings *
-mousepad_settings_get_default (void)
+gboolean
+mousepad_setting_bind (const gchar *path,
+ gpointer object,
+ const gchar *prop,
+ GSettingsBindFlags flags)
{
- static gsize default_initialized = 0;
+ gboolean result = FALSE;
+ const gchar *key_name;
+ MousepadSchema schema;
- if (g_once_init_enter (&default_initialized))
- {
+ g_return_val_if_fail (path != NULL, FALSE);
+ g_return_val_if_fail (object != NULL, FALSE);
+ g_return_val_if_fail (prop != NULL, FALSE);
- /* If we're installed in an unusual location, we still want to load
- * the schema so enforce this with the relevant environment variable. */
- mousepad_settings_update_gsettings_schema_dir ();
-
- default_settings = g_object_new (MOUSEPAD_TYPE_SETTINGS, NULL);
- /* Auto-cleanup at exit */
- atexit (mousepad_settings_cleanup_default);
+ schema = mousepad_settings_parse_path (path, &key_name);
- /* Never enter this block again */
- g_once_init_leave (&default_initialized, 1);
+ if (G_LIKELY (schema != MOUSEPAD_NUM_SCHEMAS))
+ {
+ MOUSEPAD_SETTINGS_LOCK ();
+ g_settings_bind (mousepad_settings[schema], key_name, object, prop, flags);
+ MOUSEPAD_SETTINGS_UNLOCK ();
+ result = TRUE;
}
- g_warn_if_fail (MOUSEPAD_IS_SETTINGS (default_settings));
-
- return default_settings;
+ return result;
}
-GSettings *
-mousepad_settings_get_from_schema (MousepadSettings *settings,
- MousepadSchema schema)
+gulong
+mousepad_setting_connect (const gchar *path,
+ GCallback callback,
+ gpointer user_data,
+ GSignalFlags connect_flags)
{
- g_return_val_if_fail (MOUSEPAD_IS_SETTINGS (settings), NULL);
- g_return_val_if_fail (schema < MOUSEPAD_NUM_SCHEMAS, NULL);
+ gulong signal_id = 0;
+ const gchar *key_name;
+ MousepadSchema schema;
- return settings->settings[schema];
+ g_return_val_if_fail (path != NULL, 0);
+ g_return_val_if_fail (callback != NULL, 0);
+
+ schema = mousepad_settings_parse_path (path, &key_name);
+
+ if (G_LIKELY (schema != MOUSEPAD_NUM_SCHEMAS))
+ {
+ gchar *signal_name;
+
+ signal_name = g_strdup_printf ("changed::%s", key_name);
+
+ MOUSEPAD_SETTINGS_LOCK ();
+ signal_id = g_signal_connect_data (mousepad_settings[schema],
+ signal_name,
+ callback,
+ user_data,
+ NULL,
+ connect_flags);
+ MOUSEPAD_SETTINGS_UNLOCK ();
+
+ g_free (signal_name);
+ }
+
+ return signal_id;
}
-void
-mousepad_settings_bind (MousepadSchema schema,
- const gchar *key,
- gpointer object,
- const gchar *prop,
- GSettingsBindFlags flags)
+gboolean
+mousepad_setting_get (const gchar *path,
+ const gchar *format_string,
+ ...)
{
- MousepadSettings *settings;
- g_return_if_fail (schema < MOUSEPAD_NUM_SCHEMAS);
- settings = mousepad_settings_get_default ();
- g_settings_bind (settings->settings[schema], key, object, prop, flags);
+ gboolean result = FALSE;
+ const gchar *key_name;
+ MousepadSchema schema;
+
+ g_return_val_if_fail (path != NULL, FALSE);
+ g_return_val_if_fail (format_string != NULL, FALSE);
+
+ schema = mousepad_settings_parse_path (path, &key_name);
+
+ if (G_LIKELY (schema != MOUSEPAD_NUM_SCHEMAS))
+ {
+
+ GVariant *variant;
+ va_list ap;
+
+ MOUSEPAD_SETTINGS_LOCK ();
+ variant = g_settings_get_value (mousepad_settings[schema], key_name);
+ MOUSEPAD_SETTINGS_UNLOCK ();
+
+ g_variant_ref_sink (variant);
+
+ va_start (ap, format_string);
+ g_variant_get_va (variant, format_string, NULL, &ap);
+ va_end (ap);
+
+ g_variant_unref (variant);
+
+ result = TRUE;
+ }
+
+ return result;
}
-gulong
-mousepad_settings_connect_changed (MousepadSchema schema,
- const gchar *key,
- GCallback callback,
- gpointer user_data,
- GSignalFlags connect_flags)
+gboolean
+mousepad_setting_set (const gchar *path,
+ const gchar *format_string,
+ ...)
{
- gulong signal_id;
- gchar *signal_name;
- MousepadSettings *settings;
+ gboolean result = FALSE;
+ const gchar *key_name;
+ MousepadSchema schema;
- g_return_val_if_fail (schema < MOUSEPAD_NUM_SCHEMAS, 0);
- g_return_val_if_fail (callback != NULL, 0);
+ g_return_val_if_fail (path != NULL, FALSE);
+ g_return_val_if_fail (format_string != NULL, FALSE);
- if (key != NULL)
- signal_name = g_strdup_printf ("changed::%s", key);
- else
- signal_name = g_strdup ("changed");
+ schema = mousepad_settings_parse_path (path, &key_name);
+
+ if (G_LIKELY (schema != MOUSEPAD_NUM_SCHEMAS))
+ {
+ GVariant *variant;
+ va_list ap;
- settings = mousepad_settings_get_default ();
+ va_start (ap, format_string);
+ variant = g_variant_new_va (format_string, NULL, &ap);
+ va_end (ap);
- signal_id = g_signal_connect_data (settings->settings[schema],
- signal_name,
- callback,
- user_data,
- NULL,
- connect_flags);
+ g_variant_ref_sink (variant);
- g_free (signal_name);
+ MOUSEPAD_SETTINGS_LOCK ();
+ g_settings_set_value (mousepad_settings[schema], key_name, variant);
+ MOUSEPAD_SETTINGS_UNLOCK ();
- return signal_id;
+ g_variant_unref (variant);
+
+ result = TRUE;
+ }
+
+
+ return result;
}
gboolean
-mousepad_settings_get_boolean (MousepadSchema schema,
- const gchar *key)
+mousepad_setting_get_boolean (const gchar *path)
{
- MousepadSettings *settings;
- g_return_val_if_fail (schema < MOUSEPAD_NUM_SCHEMAS, FALSE);
- settings = mousepad_settings_get_default ();
- return g_settings_get_boolean (settings->settings[schema], key);
+ gboolean value = FALSE;
+ gboolean result = mousepad_setting_get (path, "b", &value);
+ g_warn_if_fail (result);
+ return value;
}
void
-mousepad_settings_set_boolean (MousepadSchema schema,
- const gchar *key,
- gboolean value)
+mousepad_setting_set_boolean (const gchar *path,
+ gboolean value)
{
- MousepadSettings *settings;
- g_return_if_fail (schema < MOUSEPAD_NUM_SCHEMAS);
- settings = mousepad_settings_get_default ();
- g_settings_set_boolean (settings->settings[schema], key, value);
+ mousepad_setting_set (path, "b", value);
}
gint
-mousepad_settings_get_int (MousepadSchema schema,
- const gchar *key)
+mousepad_setting_get_int (const gchar *path)
{
- MousepadSettings *settings;
- g_return_val_if_fail (schema < MOUSEPAD_NUM_SCHEMAS, FALSE);
- settings = mousepad_settings_get_default ();
- return g_settings_get_int (settings->settings[schema], key);
+ gint value = 0;
+ gboolean result = mousepad_setting_get (path, "i", &value);
+ g_warn_if_fail (result);
+ return value;
}
void
-mousepad_settings_set_int (MousepadSchema schema,
- const gchar *key,
- gint value)
+mousepad_setting_set_int (const gchar *path,
+ gint value)
{
- MousepadSettings *settings;
- g_return_if_fail (schema < MOUSEPAD_NUM_SCHEMAS);
- settings = mousepad_settings_get_default ();
- g_settings_set_int (settings->settings[schema], key, value);
+ mousepad_setting_set (path, "i", value);
}
gchar *
-mousepad_settings_get_string (MousepadSchema schema,
- const gchar *key)
+mousepad_setting_get_string (const gchar *path)
{
- MousepadSettings *settings;
- g_return_val_if_fail (schema < MOUSEPAD_NUM_SCHEMAS, FALSE);
- settings = mousepad_settings_get_default ();
- return g_settings_get_string (settings->settings[schema], key);
+ gchar *value = NULL;
+ gboolean result = mousepad_setting_get (path, "s", &value);
+ g_warn_if_fail (result);
+ return value;
}
void
-mousepad_settings_set_string (MousepadSchema schema,
- const gchar *key,
- const gchar *value)
+mousepad_setting_set_string (const gchar *path,
+ const gchar *value)
{
- MousepadSettings *settings;
- g_return_if_fail (schema < MOUSEPAD_NUM_SCHEMAS);
- settings = mousepad_settings_get_default ();
- g_settings_set_string (settings->settings[schema], key, value);
+ mousepad_setting_set (path, "s", value);
}
diff --git a/mousepad/mousepad-settings.h b/mousepad/mousepad-settings.h
index aeb311b..8b44cae 100644
--- a/mousepad/mousepad-settings.h
+++ b/mousepad/mousepad-settings.h
@@ -2,105 +2,101 @@
#define MOUSEPAD_SETTINGS_H_ 1
#include <glib-object.h>
+#include <gio/gio.h>
G_BEGIN_DECLS
-typedef enum
-{
- MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SCHEMA_WINDOW_SETTINGS,
- MOUSEPAD_SCHEMA_SEARCH_STATE,
- MOUSEPAD_SCHEMA_WINDOW_STATE,
- MOUSEPAD_NUM_SCHEMAS
-}
-MousepadSchema;
+/* Setting names */
+#define MOUSEPAD_SETTING_AUTO_INDENT "/preferences/view/auto-indent"
+#define MOUSEPAD_SETTING_FONT_NAME "/preferences/view/font-name"
+#define MOUSEPAD_SETTING_SHOW_WHITESPACE "/preferences/view/show-whitespace"
+#define MOUSEPAD_SETTING_SHOW_LINE_ENDINGS "/preferences/view/show-line-endings"
+#define MOUSEPAD_SETTING_HIGHLIGHT_CURRENT_LINE "/preferences/view/highlight-current-line"
+#define MOUSEPAD_SETTING_INDENT_ON_TAB "/preferences/view/indent-on-tab"
+#define MOUSEPAD_SETTING_INDENT_WIDTH "/preferences/view/indent-width"
+#define MOUSEPAD_SETTING_INSERT_SPACES "/preferences/view/insert-spaces"
+#define MOUSEPAD_SETTING_RIGHT_MARGIN_POSITION "/preferences/view/right-margin-position"
+#define MOUSEPAD_SETTING_SHOW_LINE_MARKS "/preferences/view/show-line-marks"
+#define MOUSEPAD_SETTING_SHOW_LINE_NUMBERS "/preferences/view/show-line-numbers"
+#define MOUSEPAD_SETTING_SHOW_RIGHT_MARGIN "/preferences/view/show-right-margin"
+#define MOUSEPAD_SETTING_SMART_HOME_END "/preferences/view/smart-home-end"
+#define MOUSEPAD_SETTING_TAB_WIDTH "/preferences/view/tab-width"
+#define MOUSEPAD_SETTING_WORD_WRAP "/preferences/view/word-wrap"
+#define MOUSEPAD_SETTING_COLOR_SCHEME "/preferences/view/color-scheme"
+#define MOUSEPAD_SETTING_STATUSBAR_VISIBLE "/preferences/window/statusbar-visible"
+#define MOUSEPAD_SETTING_ALWAYS_SHOW_TABS "/preferences/window/always-show-tabs"
+#define MOUSEPAD_SETTING_CYCLE_TABS "/preferences/window/cycle-tabs"
+#define MOUSEPAD_SETTING_DEFAULT_TAB_SIZES "/preferences/window/default-tab-sizes"
+#define MOUSEPAD_SETTING_PATH_IN_TITLE "/preferences/window/path-in-title"
+#define MOUSEPAD_SETTING_RECENT_MENU_ITEMS "/preferences/window/recent-menu-items"
+#define MOUSEPAD_SETTING_REMEMBER_GEOMETRY "/preferences/window/remember-geometry"
-GType mousepad_schema_get_type (void);
-#define MOUSEPAD_TYPE_SCHEMA (mousepad_schema_get_type ())
+/* State setting names */
+#define MOUSEPAD_SETTING_SEARCH_DIRECTION "/state/search/direction"
+#define MOUSEPAD_SETTING_SEARCH_MATCH_CASE "/state/search/match-case"
+#define MOUSEPAD_SETTING_SEARCH_MATCH_WHOLE_WORD "/state/search/match-whole-word"
+#define MOUSEPAD_SETTING_SEARCH_REPLACE_ALL "/state/search/replace-all"
+#define MOUSEPAD_SETTING_SEARCH_REPLACE_ALL_LOCATION "/state/search/replace-all-location"
+#define MOUSEPAD_SETTING_WINDOW_HEIGHT "/state/window/height"
+#define MOUSEPAD_SETTING_WINDOW_WIDTH "/state/window/width"
-#define MOUSEPAD_TYPE_SETTINGS (mousepad_settings_get_type ())
-#define MOUSEPAD_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOUSEPAD_TYPE_SETTINGS, MousepadSettings))
-#define MOUSEPAD_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOUSEPAD_TYPE_SETTINGS, MousepadSettingsClass))
-#define MOUSEPAD_IS_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOUSEPAD_TYPE_SETTINGS))
-#define MOUSEPAD_IS_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOUSEPAD_TYPE_SETTINGS))
-#define MOUSEPAD_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOUSEPAD_TYPE_SETTINGS, MousepadSettingsClass))
+void mousepad_settings_init (void);
+void mousepad_settings_finalize (void);
-typedef struct MousepadSettings_ MousepadSettings;
-typedef struct MousepadSettingsClass_ MousepadSettingsClass;
+gboolean mousepad_setting_bind (const gchar *path,
+ gpointer object,
+ const gchar *prop,
+ GSettingsBindFlags flags);
-GType mousepad_settings_get_type (void);
+gulong mousepad_setting_connect (const gchar *path,
+ GCallback callback,
+ gpointer user_data,
+ GSignalFlags connect_flags);
-MousepadSettings *mousepad_settings_get_default (void);
+/* functions for reading and writing settings */
-GSettings *mousepad_settings_get_from_schema (MousepadSettings *settings,
- MousepadSchema schema);
+gboolean mousepad_setting_get (const gchar *path,
+ const gchar *format_string,
+ ...);
-void mousepad_settings_bind (MousepadSchema schema,
- const gchar *key,
- gpointer object,
- const gchar *prop,
- GSettingsBindFlags flags);
+gboolean mousepad_setting_set (const gchar *path,
+ const gchar *format_string,
+ ...);
-gulong mousepad_settings_connect_changed (MousepadSchema schema,
- const gchar *key,
- GCallback callback,
- gpointer user_data,
- GSignalFlags connect_flags);
+/* convenience functions for reading/writing common types */
-gboolean mousepad_settings_get_boolean (MousepadSchema schema,
- const gchar *key);
+gboolean mousepad_setting_get_boolean (const gchar *path);
-void mousepad_settings_set_boolean (MousepadSchema schema,
- const gchar *key,
- gboolean value);
+void mousepad_setting_set_boolean (const gchar *path,
+ gboolean value);
-gint mousepad_settings_get_int (MousepadSchema schema,
- const gchar *key);
+gint mousepad_setting_get_int (const gchar *path);
-void mousepad_settings_set_int (MousepadSchema schema,
- const gchar *key,
- gint value);
+void mousepad_setting_set_int (const gchar *path,
+ gint value);
-gchar *mousepad_settings_get_string (MousepadSchema schema,
- const gchar *key);
+gchar *mousepad_setting_get_string (const gchar *path);
-void mousepad_settings_set_string (MousepadSchema schema,
- const gchar *key,
- const gchar *value);
+void mousepad_setting_set_string (const gchar *path,
+ const gchar *value);
-/* Setting names */
-#define MOUSEPAD_SETTING_AUTO_INDENT "auto-indent"
-#define MOUSEPAD_SETTING_FONT_NAME "font-name"
-#define MOUSEPAD_SETTING_SHOW_WHITESPACE "show-whitespace"
-#define MOUSEPAD_SETTING_SHOW_LINE_ENDINGS "show-line-endings"
-#define MOUSEPAD_SETTING_HIGHLIGHT_CURRENT_LINE "highlight-current-line"
-#define MOUSEPAD_SETTING_INDENT_ON_TAB "indent-on-tab"
-#define MOUSEPAD_SETTING_INDENT_WIDTH "indent-width"
-#define MOUSEPAD_SETTING_INSERT_SPACES "insert-spaces"
-#define MOUSEPAD_SETTING_RIGHT_MARGIN_POSITION "right-margin-position"
-#define MOUSEPAD_SETTING_SHOW_LINE_MARKS "show-line-marks"
-#define MOUSEPAD_SETTING_SHOW_LINE_NUMBERS "show-line-numbers"
-#define MOUSEPAD_SETTING_SHOW_RIGHT_MARGIN "show-right-margin"
-#define MOUSEPAD_SETTING_SMART_HOME_END "smart-home-end"
-#define MOUSEPAD_SETTING_TAB_WIDTH "tab-width"
-#define MOUSEPAD_SETTING_WORD_WRAP "word-wrap"
-#define MOUSEPAD_SETTING_COLOR_SCHEME "color-scheme"
-#define MOUSEPAD_SETTING_STATUSBAR_VISIBLE "statusbar-visible"
-#define MOUSEPAD_SETTING_ALWAYS_SHOW_TABS "always-show-tabs"
-#define MOUSEPAD_SETTING_CYCLE_TABS "cycle-tabs"
-#define MOUSEPAD_SETTING_DEFAULT_TAB_SIZES "default-tab-sizes"
-#define MOUSEPAD_SETTING_PATH_IN_TITLE "path-in-title"
-#define MOUSEPAD_SETTING_RECENT_MENU_ITEMS "recent-menu-items"
-#define MOUSEPAD_SETTING_REMEMBER_GEOMETRY "remember-geometry"
+/* wrappers for above read/write functions with shorter arguments */
-/* State setting names */
-#define MOUSEPAD_STATE_SEARCH_DIRECTION "direction"
-#define MOUSEPAD_STATE_SEARCH_MATCH_CASE "match-case"
-#define MOUSEPAD_STATE_SEARCH_MATCH_WHOLE_WORD "match-whole-word"
-#define MOUSEPAD_STATE_SEARCH_REPLACE_ALL "replace-all"
-#define MOUSEPAD_STATE_SEARCH_REPLACE_ALL_LOCATION "replace-all-location"
-#define MOUSEPAD_STATE_WINDOW_HEIGHT "height"
-#define MOUSEPAD_STATE_WINDOW_WIDTH "width"
+#define MOUSEPAD_SETTING_BIND(setting, object, prop, flags) \
+ mousepad_setting_bind (MOUSEPAD_SETTING_##setting, object, prop, flags)
+
+#define MOUSEPAD_SETTING_CONNECT(setting, callback, user_data, connect_flags) \
+ mousepad_setting_connect (MOUSEPAD_SETTING_##setting, callback, user_data, connect_flags)
+
+#define MOUSEPAD_SETTING_GET(setting, ...) mousepad_setting_get (MOUSEPAD_SETTING_##setting, __VA_ARGS__)
+#define MOUSEPAD_SETTING_GET_BOOLEAN(setting) mousepad_setting_get_boolean (MOUSEPAD_SETTING_##setting)
+#define MOUSEPAD_SETTING_GET_INT(setting) mousepad_setting_get_int (MOUSEPAD_SETTING_##setting)
+#define MOUSEPAD_SETTING_GET_STRING(setting) mousepad_setting_get_string (MOUSEPAD_SETTING_##setting)
+
+#define MOUSEPAD_SETTING_SET(setting, ...) mousepad_setting_set (MOUSEPAD_SETTING_##setting, __VA_ARGS__)
+#define MOUSEPAD_SETTING_SET_BOOLEAN(setting, value) mousepad_setting_set_boolean (MOUSEPAD_SETTING_##setting, value)
+#define MOUSEPAD_SETTING_SET_INT(setting, value) mousepad_setting_set_int (MOUSEPAD_SETTING_##setting, value)
+#define MOUSEPAD_SETTING_SET_STRING(setting, value) mousepad_setting_set_string (MOUSEPAD_SETTING_##setting, value)
G_END_DECLS
diff --git a/mousepad/mousepad-view.c b/mousepad/mousepad-view.c
index 659302a..d26e687 100644
--- a/mousepad/mousepad-view.c
+++ b/mousepad/mousepad-view.c
@@ -263,9 +263,7 @@ mousepad_view_init (MousepadView *view)
/* bind Gsettings */
#define BIND_(setting, prop) \
- mousepad_settings_bind (MOUSEPAD_SCHEMA_VIEW_SETTINGS, \
- MOUSEPAD_SETTING_##setting, view, prop, \
- G_SETTINGS_BIND_DEFAULT)
+ MOUSEPAD_SETTING_BIND (setting, view, prop, G_SETTINGS_BIND_DEFAULT)
BIND_ (AUTO_INDENT, "auto-indent");
BIND_ (FONT_NAME, "font-name");
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index ac58320..78878af 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -182,7 +182,7 @@ static void mousepad_window_update_gomenu_idle_destroy (gpointer
static void mousepad_window_update_gomenu (MousepadWindow *window);
static void mousepad_window_update_tabs (MousepadWindow *window,
gchar *key,
- MousepadSettings *settings);
+ GSettings *settings);
static void mousepad_window_menu_color_schemes (MousepadWindow *window);
static void mousepad_window_menu_languages (MousepadWindow *window);
@@ -545,9 +545,9 @@ mousepad_window_class_init (MousepadWindowClass *klass)
/* Called in response to any settings changed which affect the statusbar labels. */
static void
-mousepad_window_update_statusbar_settings (MousepadWindow *window,
- gchar *key,
- MousepadSettings *settings)
+mousepad_window_update_statusbar_settings (MousepadWindow *window,
+ gchar *key,
+ GSettings *settings)
{
if (G_LIKELY (MOUSEPAD_IS_DOCUMENT (window->active)))
mousepad_document_send_signals (window->active);
@@ -557,9 +557,9 @@ mousepad_window_update_statusbar_settings (MousepadWindow *window,
/* Called in response to any setting changed which affects the window title. */
static void
-mousepad_window_update_window_title (MousepadWindow *window,
- gchar *key,
- MousepadSettings *settings)
+mousepad_window_update_window_title (MousepadWindow *window,
+ gchar *key,
+ GSettings *settings)
{
mousepad_window_set_title (window);
}
@@ -568,15 +568,14 @@ mousepad_window_update_window_title (MousepadWindow *window,
/* Called when always-show-tabs setting changes to update the UI. */
static void
-mousepad_window_update_tabs (MousepadWindow *window,
- gchar *key,
- MousepadSettings *settings)
+mousepad_window_update_tabs (MousepadWindow *window,
+ gchar *key,
+ GSettings *settings)
{
gint n_pages;
gboolean always_show;
- always_show = mousepad_settings_get_boolean (MOUSEPAD_SCHEMA_WINDOW_SETTINGS,
- MOUSEPAD_SETTING_ALWAYS_SHOW_TABS);
+ always_show = MOUSEPAD_SETTING_GET_BOOLEAN (ALWAYS_SHOW_TABS);
n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (window->notebook));
@@ -588,9 +587,9 @@ mousepad_window_update_tabs (MousepadWindow *window,
/* Called when 'window-recent-menu-items' setting changes to update the UI. */
static void
-mousepad_window_update_recent_menu (MousepadWindow *window,
- gchar *key,
- MousepadSettings *settings)
+mousepad_window_update_recent_menu (MousepadWindow *window,
+ gchar *key,
+ GSettings *settings)
{
mousepad_window_recent_menu (window);
}
@@ -636,8 +635,8 @@ mousepad_window_init (MousepadWindow *window)
g_closure_sink (window->menu_item_deselected_closure);
/* read settings from the preferences */
- width = mousepad_settings_get_int (MOUSEPAD_SCHEMA_WINDOW_STATE, MOUSEPAD_STATE_WINDOW_WIDTH);
- height = mousepad_settings_get_int (MOUSEPAD_SCHEMA_WINDOW_STATE, MOUSEPAD_STATE_WINDOW_HEIGHT);
+ width = MOUSEPAD_SETTING_GET_INT (WINDOW_WIDTH);
+ height = MOUSEPAD_SETTING_GET_INT (WINDOW_HEIGHT);
/* set the default window size */
gtk_window_set_default_size (GTK_WINDOW (window), width, height);
@@ -752,38 +751,33 @@ mousepad_window_init (MousepadWindow *window)
g_signal_connect (G_OBJECT (window), "drag-data-received", G_CALLBACK (mousepad_window_drag_data_received), window);
/* update the statusbar with certain settings */
- mousepad_settings_connect_changed (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_TAB_WIDTH,
- G_CALLBACK (mousepad_window_update_statusbar_settings),
- window,
- G_CONNECT_SWAPPED);
-
- mousepad_settings_connect_changed (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_INSERT_SPACES,
- G_CALLBACK (mousepad_window_update_statusbar_settings),
- window,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT (TAB_WIDTH,
+ G_CALLBACK (mousepad_window_update_statusbar_settings),
+ window,
+ G_CONNECT_SWAPPED);
+
+ MOUSEPAD_SETTING_CONNECT (INSERT_SPACES,
+ G_CALLBACK (mousepad_window_update_statusbar_settings),
+ window,
+ G_CONNECT_SWAPPED);
/* update the window title when 'path-in-title' setting changes */
- mousepad_settings_connect_changed (MOUSEPAD_SCHEMA_WINDOW_SETTINGS,
- MOUSEPAD_SETTING_PATH_IN_TITLE,
- G_CALLBACK (mousepad_window_update_window_title),
- window,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT (PATH_IN_TITLE,
+ G_CALLBACK (mousepad_window_update_window_title),
+ window,
+ G_CONNECT_SWAPPED);
/* update the tabs when 'always-show-tabs' setting changes */
- mousepad_settings_connect_changed (MOUSEPAD_SCHEMA_WINDOW_SETTINGS,
- MOUSEPAD_SETTING_ALWAYS_SHOW_TABS,
- G_CALLBACK (mousepad_window_update_tabs),
- window,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT (ALWAYS_SHOW_TABS,
+ G_CALLBACK (mousepad_window_update_tabs),
+ window,
+ G_CONNECT_SWAPPED);
/* update the recent items menu when 'window-recent-menu-items' setting changes */
- mousepad_settings_connect_changed (MOUSEPAD_SCHEMA_WINDOW_SETTINGS,
- MOUSEPAD_SETTING_RECENT_MENU_ITEMS,
- G_CALLBACK (mousepad_window_update_recent_menu),
- window,
- G_CONNECT_SWAPPED);
+ MOUSEPAD_SETTING_CONNECT (RECENT_MENU_ITEMS,
+ G_CALLBACK (mousepad_window_update_recent_menu),
+ window,
+ G_CONNECT_SWAPPED);
}
@@ -979,8 +973,8 @@ mousepad_window_save_geometry_timer (gpointer user_data)
GDK_THREADS_ENTER ();
/* check if we should remember the window geometry */
- remember_geometry = mousepad_settings_get_boolean (MOUSEPAD_SCHEMA_WINDOW_SETTINGS,
- MOUSEPAD_SETTING_REMEMBER_GEOMETRY);
+ remember_geometry = MOUSEPAD_SETTING_GET_BOOLEAN (REMEMBER_GEOMETRY);
+
if (G_LIKELY (remember_geometry))
{
/* check if the window is still visible */
@@ -996,8 +990,8 @@ mousepad_window_save_geometry_timer (gpointer user_data)
gtk_window_get_size (GTK_WINDOW (window), &width, &height);
/* ...and remember them as default for new windows */
- mousepad_settings_set_int (MOUSEPAD_SCHEMA_WINDOW_STATE, MOUSEPAD_STATE_WINDOW_WIDTH, width);
- mousepad_settings_set_int (MOUSEPAD_SCHEMA_WINDOW_STATE, MOUSEPAD_STATE_WINDOW_HEIGHT, height);
+ MOUSEPAD_SETTING_SET_INT (WINDOW_WIDTH, width);
+ MOUSEPAD_SETTING_SET_INT (WINDOW_HEIGHT, height);
}
}
}
@@ -1356,8 +1350,7 @@ mousepad_window_set_title (MousepadWindow *window)
mousepad_return_if_fail (MOUSEPAD_IS_WINDOW (window));
/* whether to show the full path */
- show_full_path = mousepad_settings_get_boolean (MOUSEPAD_SCHEMA_WINDOW_SETTINGS,
- MOUSEPAD_SETTING_PATH_IN_TITLE);
+ show_full_path = MOUSEPAD_SETTING_GET_BOOLEAN (PATH_IN_TITLE);
/* name we display in the title */
if (G_UNLIKELY (show_full_path && mousepad_document_get_filename (document)))
@@ -2102,8 +2095,7 @@ mousepad_window_menu_tab_sizes (MousepadWindow *window)
lock_menu_updates++;
/* get the default tab sizes and active tab size */
- tmp = mousepad_settings_get_string (MOUSEPAD_SCHEMA_WINDOW_SETTINGS,
- MOUSEPAD_SETTING_DEFAULT_TAB_SIZES);
+ tmp = MOUSEPAD_SETTING_GET_STRING (DEFAULT_TAB_SIZES);
/* get sizes array and free the temp string */
tab_sizes = g_strsplit (tmp, ",", -1);
@@ -2176,8 +2168,7 @@ mousepad_window_menu_tab_sizes_update (MousepadWindow *window)
lock_menu_updates++;
/* get tab size of active document */
- tab_size = mousepad_settings_get_int (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_TAB_WIDTH);
+ tab_size = MOUSEPAD_SETTING_GET_INT (TAB_WIDTH);
/* check if there is a default item with this number */
name = g_strdup_printf ("tab-size_%d", tab_size);
@@ -2287,8 +2278,7 @@ mousepad_window_update_actions (MousepadWindow *window)
page_num = gtk_notebook_page_num (notebook, GTK_WIDGET (document));
/* whether we cycle tabs */
- cycle_tabs = mousepad_settings_get_boolean (MOUSEPAD_SCHEMA_WINDOW_SETTINGS,
- MOUSEPAD_SETTING_CYCLE_TABS);
+ cycle_tabs = MOUSEPAD_SETTING_GET_BOOLEAN (CYCLE_TABS);
/* set the sensitivity of the back and forward buttons in the go menu */
action = gtk_action_group_get_action (window->action_group, "back");
@@ -2326,26 +2316,22 @@ mousepad_window_update_actions (MousepadWindow *window)
gtk_action_set_sensitive (action, sensitive);
/* toggle the document settings */
- active = mousepad_settings_get_boolean (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_WORD_WRAP);
+ active = MOUSEPAD_SETTING_GET_BOOLEAN (WORD_WRAP);
action = gtk_action_group_get_action (window->action_group, "word-wrap");
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active);
- active = mousepad_settings_get_boolean (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_SHOW_LINE_NUMBERS);
+ active = MOUSEPAD_SETTING_GET_BOOLEAN (SHOW_LINE_NUMBERS);
action = gtk_action_group_get_action (window->action_group, "line-numbers");
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active);
- active = mousepad_settings_get_boolean (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_AUTO_INDENT);
+ active = MOUSEPAD_SETTING_GET_BOOLEAN (AUTO_INDENT);
action = gtk_action_group_get_action (window->action_group, "auto-indent");
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active);
/* update the tabs size menu */
mousepad_window_menu_tab_sizes_update (window);
- active = mousepad_settings_get_boolean (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_INSERT_SPACES);
+ active = MOUSEPAD_SETTING_GET_BOOLEAN (INSERT_SPACES);
action = gtk_action_group_get_action (window->action_group, "insert-spaces");
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active);
@@ -2622,8 +2608,7 @@ mousepad_window_recent_menu_idle (gpointer user_data)
}
/* get the recent menu limit number */
- n = mousepad_settings_get_int (MOUSEPAD_SCHEMA_WINDOW_SETTINGS,
- MOUSEPAD_SETTING_RECENT_MENU_ITEMS);
+ n = MOUSEPAD_SETTING_GET_INT (RECENT_MENU_ITEMS);
/* append the items to the menu */
for (li = filtered, i = 1; n > 0 && li != NULL; li = li->next)
@@ -3277,8 +3262,7 @@ mousepad_window_menu_color_schemes (MousepadWindow *window)
lock_menu_updates++;
/* get the previously saved colour scheme name */
- selected_color_scheme = mousepad_settings_get_string (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_COLOR_SCHEME);
+ selected_color_scheme = MOUSEPAD_SETTING_GET_STRING (COLOR_SCHEME);
/* get list of schemes */
schemes = mousepad_util_color_schemes_get_sorted ();
@@ -3501,10 +3485,7 @@ mousepad_window_create_statusbar (MousepadWindow *window)
/* bind the GSetting to the GtkAction that controls the statusbar */
action = gtk_action_group_get_action (window->action_group, "statusbar");
- mousepad_settings_bind (MOUSEPAD_SCHEMA_WINDOW_SETTINGS,
- MOUSEPAD_SETTING_STATUSBAR_VISIBLE,
- action, "active",
- G_SETTINGS_BIND_DEFAULT);
+ MOUSEPAD_SETTING_BIND (STATUSBAR_VISIBLE, action, "active", G_SETTINGS_BIND_DEFAULT);
/* pack the statusbar into the window UI */
gtk_box_pack_end (GTK_BOX (window->box), window->statusbar, FALSE, FALSE, 0);
@@ -4528,8 +4509,8 @@ mousepad_window_action_select_font (GtkAction *action,
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
/* set the current font name */
- font_name = mousepad_settings_get_string (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_FONT_NAME);
+ font_name = MOUSEPAD_SETTING_GET_STRING (FONT_NAME);
+
if (G_LIKELY (font_name))
{
gtk_font_selection_dialog_set_font_name (GTK_FONT_SELECTION_DIALOG (dialog), font_name);
@@ -4543,9 +4524,7 @@ mousepad_window_action_select_font (GtkAction *action,
font_name = gtk_font_selection_dialog_get_font_name (GTK_FONT_SELECTION_DIALOG (dialog));
/* store the font in the preferences */
- mousepad_settings_set_string (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_FONT_NAME,
- font_name);
+ MOUSEPAD_SETTING_SET_STRING (FONT_NAME, font_name);
/* cleanup */
g_free (font_name);
@@ -4591,11 +4570,10 @@ mousepad_window_action_color_scheme (GtkToggleAction *action,
}
/* store as last used value */
- mousepad_settings_set_string (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_COLOR_SCHEME,
- (scheme != NULL) ?
- gtk_source_style_scheme_get_id (scheme) :
- "none");
+ MOUSEPAD_SETTING_SET_STRING (COLOR_SCHEME,
+ (scheme != NULL) ?
+ gtk_source_style_scheme_get_id (scheme) :
+ "none");
}
}
@@ -4614,9 +4592,7 @@ mousepad_window_action_line_numbers (GtkToggleAction *action,
active = gtk_toggle_action_get_active (action);
/* save as the last used line number setting */
- mousepad_settings_set_boolean (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_SHOW_LINE_NUMBERS,
- active);
+ MOUSEPAD_SETTING_SET_BOOLEAN (SHOW_LINE_NUMBERS, active);
}
@@ -4833,9 +4809,7 @@ mousepad_window_action_auto_indent (GtkToggleAction *action,
active = gtk_toggle_action_get_active (action);
/* save as the last auto indent mode */
- mousepad_settings_set_boolean (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_AUTO_INDENT,
- active);
+ MOUSEPAD_SETTING_SET_BOOLEAN (AUTO_INDENT, active);
}
@@ -4888,17 +4862,14 @@ mousepad_window_action_tab_size (GtkToggleAction *action,
if (tab_size == 0)
{
/* get tab size from document */
- tab_size = mousepad_settings_get_int (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_TAB_WIDTH);
+ tab_size = MOUSEPAD_SETTING_GET_INT (TAB_WIDTH);
/* select other size in dialog */
tab_size = mousepad_dialogs_other_tab_size (GTK_WINDOW (window), tab_size);
}
/* store as last used value */
- mousepad_settings_set_int (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_TAB_WIDTH,
- tab_size);
+ MOUSEPAD_SETTING_SET_INT (TAB_WIDTH, tab_size);
/* update menu */
mousepad_window_menu_tab_sizes_update (window);
@@ -4923,9 +4894,7 @@ mousepad_window_action_word_wrap (GtkToggleAction *action,
active = gtk_toggle_action_get_active (action);
/* store this as the last used wrap mode */
- mousepad_settings_set_boolean (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_WORD_WRAP,
- active);
+ MOUSEPAD_SETTING_SET_BOOLEAN (WORD_WRAP, active);
}
}
@@ -5008,9 +4977,7 @@ mousepad_window_action_insert_spaces (GtkToggleAction *action,
insert_spaces = gtk_toggle_action_get_active (action);
/* save as the last auto indent mode */
- mousepad_settings_set_boolean (MOUSEPAD_SCHEMA_VIEW_SETTINGS,
- MOUSEPAD_SETTING_INSERT_SPACES,
- insert_spaces);
+ MOUSEPAD_SETTING_SET_BOOLEAN (INSERT_SPACES, insert_spaces);
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list