[gnac/gnac-gsettings] Added convenience functions for GSettings handling
- From: Benoît Dupasquier <bdupasqu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnac/gnac-gsettings] Added convenience functions for GSettings handling
- Date: Mon, 25 Oct 2010 23:37:50 +0000 (UTC)
commit dd3ce4d0665e479e910beed967d6aad714a595ac
Author: Benoît Dupasquier <bdupasqu src gnome org>
Date: Tue Oct 26 00:37:42 2010 +0100
Added convenience functions for GSettings handling
src/gnac-main.c | 50 ++++++++++++++++++++++++++++++++++++++++++-----
src/gnac-main.h | 16 +++++++++++++++
src/gnac-options.c | 5 +---
src/gnac-prefs.c | 54 +++++++++++++++++++++++++--------------------------
4 files changed, 87 insertions(+), 38 deletions(-)
---
diff --git a/src/gnac-main.c b/src/gnac-main.c
index e998ab5..27ed7f9 100644
--- a/src/gnac-main.c
+++ b/src/gnac-main.c
@@ -387,6 +387,49 @@ gnac_add_file(GFile *file)
}
+gboolean
+gnac_settings_set_boolean(const gchar *key,
+ gboolean value)
+{
+ return gnac_settings_set(key, g_variant_new_boolean(value));
+}
+
+
+gboolean
+gnac_settings_set_int(const gchar *key,
+ gint value)
+{
+ return gnac_settings_set(key, g_variant_new_int32(value));
+}
+
+
+gboolean
+gnac_settings_set_string(const gchar *key,
+ const gchar *value)
+{
+ if (!value) return FALSE;
+ return gnac_settings_set(key, g_variant_new_string(value));
+}
+
+
+gboolean
+gnac_settings_set(const gchar *key,
+ GVariant *value)
+{
+ gboolean ret;
+ gchar *val_str;
+ val_str = g_variant_print(value, FALSE);
+ ret = g_settings_set_value(settings, key, value);
+ if (!ret) {
+ libgnac_debug("Failed to set key \"%s\" to \"%s\"", key, val_str);
+ } else {
+ libgnac_debug("Key \"%s\" set to \"%s\"", key, val_str);
+ }
+ g_free(val_str);
+ return ret;
+}
+
+
static gboolean
gnac_confirm_exit(void)
{
@@ -885,12 +928,7 @@ gnac_on_ui_profile_changed_cb(GtkComboBox *box,
const gchar *profile_name = NULL;
profile_name = gnac_profiles_get_name();
if (profile_name) {
- gboolean ret = g_settings_set_string(settings,
- GNAC_KEY_LAST_USED_PROFILE, profile_name);
- if (!ret) {
- g_printerr("Failed to set key %s to %s\n",
- GNAC_KEY_LAST_USED_PROFILE, profile_name);
- }
+ gnac_settings_set_string(GNAC_KEY_LAST_USED_PROFILE, profile_name);
}
}
diff --git a/src/gnac-main.h b/src/gnac-main.h
index 1730412..2fd399a 100644
--- a/src/gnac-main.h
+++ b/src/gnac-main.h
@@ -93,6 +93,22 @@ gnac_on_ui_help_cb(GtkAction *action,
gpointer data);
gboolean
+gnac_settings_set_boolean(const gchar *key,
+ gboolean value);
+
+gboolean
+gnac_settings_set_int(const gchar *key,
+ gint value);
+
+gboolean
+gnac_settings_set_string(const gchar *key,
+ const gchar *value);
+
+gboolean
+gnac_settings_set(const gchar *key,
+ GVariant *value);
+
+gboolean
gnac_on_ui_focus_in_event_cb(GtkWidget *widget,
GdkEventFocus *event,
gpointer data);
diff --git a/src/gnac-options.c b/src/gnac-options.c
index 7fb89ef..f9fd1ee 100644
--- a/src/gnac-options.c
+++ b/src/gnac-options.c
@@ -102,10 +102,7 @@ gnac_options_audio_profile_cb(const gchar *option_name,
gpointer data,
GError **error)
{
- if (value) {
- g_settings_set_string(settings, GNAC_KEY_LAST_USED_PROFILE, value);
- libgnac_debug("profile \"%s\" selected", value);
- }
+ gnac_settings_set_string(GNAC_KEY_LAST_USED_PROFILE, value);
return TRUE;
}
diff --git a/src/gnac-prefs.c b/src/gnac-prefs.c
index 462b802..0b8864b 100644
--- a/src/gnac-prefs.c
+++ b/src/gnac-prefs.c
@@ -35,6 +35,7 @@
#include "gnac-properties.h"
#include "gnac-ui.h"
#include "gnac-utils.h"
+#include "libgnac-debug.h"
#include "libgnac-output.h"
#include "profiles/gnac-profiles.h"
@@ -378,8 +379,8 @@ gnac_prefs_same_radio_toggled(GtkWidget *widget,
gpointer data)
{
gnac_prefs_set_same_mode();
- g_settings_set_int(settings, GNAC_KEY_FOLDER_TYPE, FOLDER_CURRENT);
- g_settings_set_string(settings, GNAC_KEY_DESTINATION_DIRECTORY, "");
+ gnac_settings_set_int(GNAC_KEY_FOLDER_TYPE, FOLDER_CURRENT);
+ gnac_settings_set_string(GNAC_KEY_DESTINATION_DIRECTORY, "");
}
@@ -395,10 +396,11 @@ void
gnac_prefs_subfolder_radio_toggled(GtkWidget *widget,
gpointer data)
{
+ const gchar *subfolder;
gnac_prefs_set_subfolder_mode();
- g_settings_set_int(settings, GNAC_KEY_FOLDER_TYPE, FOLDER_SUBDIRECTORY);
- g_settings_set_string(settings, GNAC_KEY_DESTINATION_DIRECTORY,
- gnac_prefs_entry_get_text("subfolder_entry"));
+ gnac_settings_set_int(GNAC_KEY_FOLDER_TYPE, FOLDER_SUBDIRECTORY);
+ subfolder = gnac_prefs_entry_get_text("subfolder_entry");
+ gnac_settings_set_string(GNAC_KEY_DESTINATION_DIRECTORY, subfolder);
}
@@ -406,8 +408,9 @@ void
gnac_prefs_subfolder_editing_done(GtkWidget *widget,
gpointer data)
{
- g_settings_set_string(settings, GNAC_KEY_DESTINATION_DIRECTORY,
- gtk_entry_get_text(GTK_ENTRY(widget)));
+ const gchar *subfolder;
+ subfolder = gtk_entry_get_text(GTK_ENTRY(widget));
+ gnac_settings_set_string(GNAC_KEY_DESTINATION_DIRECTORY, subfolder);
}
@@ -420,12 +423,10 @@ gnac_prefs_selected_radio_toggled(GtkWidget *widget,
filechooserbutton = GTK_WIDGET(gtk_builder_get_object(gnac_prefs_builder,
"filechooserbutton"));
gnac_prefs_set_selected_mode();
- g_settings_set_int(settings, GNAC_KEY_FOLDER_TYPE, FOLDER_SELECTED);
+ gnac_settings_set_int(GNAC_KEY_FOLDER_TYPE, FOLDER_SELECTED);
uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(filechooserbutton));
- if (uri) {
- g_settings_set_string(settings, GNAC_KEY_DESTINATION_DIRECTORY, uri);
- g_free(uri);
- }
+ gnac_settings_set_string(GNAC_KEY_DESTINATION_DIRECTORY, uri);
+ g_free(uri);
}
@@ -438,10 +439,8 @@ gnac_prefs_selected_uri_changed(GtkWidget *widget,
filechooserbutton = GTK_WIDGET(gtk_builder_get_object(gnac_prefs_builder,
"filechooserbutton"));
uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(filechooserbutton));
- if (uri) {
- g_settings_set_string(settings, GNAC_KEY_DESTINATION_DIRECTORY, uri);
- g_free(uri);
- }
+ gnac_settings_set_string(GNAC_KEY_DESTINATION_DIRECTORY, uri);
+ g_free(uri);
}
@@ -465,7 +464,7 @@ gnac_prefs_update_example_label(GtkWidget *widget,
pattern_filename = gnac_prefs_entry_get_text("output_filename_entry");
if (pattern_filename && !g_str_equal(pattern_filename, ""))
{
- g_settings_set_string(settings, GNAC_KEY_RENAME_PATTERN_PATTERN, pattern_filename);
+ gnac_settings_set_string(GNAC_KEY_RENAME_PATTERN_PATTERN, pattern_filename);
}
if (gtk_combo_box_get_active(GTK_COMBO_BOX(combo)) != 0)
@@ -474,7 +473,8 @@ gnac_prefs_update_example_label(GtkWidget *widget,
pattern_folder = gnac_prefs_entry_get_text("folder_hierarchy_entry");
if (pattern_folder && !g_str_equal(pattern_folder, ""))
{
- g_settings_set_string(settings, GNAC_KEY_FOLDER_HIERARCHY_PATTERN, pattern_folder);
+ gnac_settings_set_string(GNAC_KEY_FOLDER_HIERARCHY_PATTERN,
+ pattern_folder);
pattern = g_strdup_printf("%s/%s", pattern_folder, pattern_filename);
}
else
@@ -560,11 +560,10 @@ gnac_prefs_pattern_changed_cb(GtkWidget *widget,
gtk_entry_set_text(GTK_ENTRY(filename_entry), pattern);
- g_settings_set_int(settings, GNAC_KEY_RENAME_PATTERN, active);
- if (pattern) {
- g_settings_set_string(settings, GNAC_KEY_RENAME_PATTERN_PATTERN, pattern);
- g_free(pattern);
- }
+ gnac_settings_set_int(GNAC_KEY_RENAME_PATTERN, active);
+ gnac_settings_set_string(GNAC_KEY_RENAME_PATTERN_PATTERN, pattern);
+
+ g_free(pattern);
}
@@ -595,11 +594,10 @@ gnac_prefs_folder_hierarchy_changed_cb(GtkWidget *widget,
gtk_entry_set_text(GTK_ENTRY(folder_entry), pattern);
- g_settings_set_int(settings, GNAC_KEY_FOLDER_HIERARCHY, active);
- if (pattern) {
- g_settings_set_string(settings, GNAC_KEY_FOLDER_HIERARCHY_PATTERN, pattern);
- g_free(pattern);
- }
+ gnac_settings_set_int(GNAC_KEY_FOLDER_HIERARCHY, active);
+ gnac_settings_set_string(GNAC_KEY_FOLDER_HIERARCHY_PATTERN, pattern);
+
+ g_free(pattern);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]