[gnome-commander/GSettings] Makes set_gsettings_when_changed a funktion instead of a method
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander/GSettings] Makes set_gsettings_when_changed a funktion instead of a method
- Date: Thu, 4 Aug 2016 20:28:37 +0000 (UTC)
commit 09ee6789bd2328e20e249adbf4f65fc35a0f19f5
Author: Uwe Scholz <uwescholz src gnome org>
Date: Thu Aug 4 22:06:26 2016 +0200
Makes set_gsettings_when_changed a funktion instead of a method
src/gnome-cmd-data.cc | 71 -------------------------------------------------
src/gnome-cmd-data.h | 1 -
src/utils.cc | 70 ++++++++++++++++++++++++++++++++++++++++++++++++
src/utils.h | 2 +
4 files changed, 72 insertions(+), 72 deletions(-)
---
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index 9fc6c5e..6ce036c 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -4266,77 +4266,6 @@ gboolean GnomeCmdData::set_gsettings_enum_when_changed (GSettings *settings, con
return rv;
}
-
-/**
- * This method stores the value for a given key if the value is different from the currently stored one
- * under the keys value. This function is able of storing several types of GSettings values (except enums
- * which is done in @link set_gsettings_enum_when_changed @endlink ). Therefore, it first checks the type
- * of GVariant of the default value of the given key. Depending on the result, the gpointer is than casted
- * to the correct type so that *value can be saved.
- * @returns TRUE if new value could be stored, else FALSE
- */
-gboolean GnomeCmdData::set_gsettings_when_changed (GSettings *settings, const char *key, gpointer value)
-{
- GVariant *default_val;
- gboolean rv = true;
- default_val = g_settings_get_default_value (settings, key);
-
- switch (g_variant_classify(default_val))
- {
- case G_VARIANT_CLASS_INT32:
- {
- gint old_value;
- gint new_value = *(gint*) value;
-
- old_value = g_settings_get_int (settings, key);
- if (old_value != new_value)
- rv = g_settings_set_int (settings, key, new_value);
- break;
- }
- case G_VARIANT_CLASS_UINT32:
- {
- gint old_value;
- gint new_value = *(gint*) value;
-
- old_value = g_settings_get_uint (settings, key);
- if (old_value != new_value)
- rv = g_settings_set_uint (settings, key, new_value);
- break;
- }
- case G_VARIANT_CLASS_STRING:
- {
- gchar *old_value;
- gchar *new_value = (char*) value;
-
- old_value = g_settings_get_string (settings, key);
- if (strcmp(old_value, new_value) != 0)
- rv = g_settings_set_string (settings, key, new_value);
- g_free(old_value);
- break;
- }
- case G_VARIANT_CLASS_BOOLEAN:
- {
- gboolean old_value;
- gboolean new_value = *(gboolean*) value;
-
- old_value = g_settings_get_boolean (settings, key);
- if (old_value != new_value)
- rv = g_settings_set_boolean (settings, key, new_value);
- break;
- }
- default:
- {
- g_warning("Could not store value of type '%s' for key '%s'\n", g_variant_get_type_string
(default_val), key);
- rv = false;
- break;
- }
- }
- if (default_val)
- g_variant_unref (default_val);
-
- return rv;
-}
-
gboolean GnomeCmdData::set_gsettings_color_when_changed (GSettings *settings, const char *key, GdkColor
*color)
{
gboolean return_value;
diff --git a/src/gnome-cmd-data.h b/src/gnome-cmd-data.h
index 3bdd9f2..eca76b2 100644
--- a/src/gnome-cmd-data.h
+++ b/src/gnome-cmd-data.h
@@ -634,7 +634,6 @@ struct GnomeCmdData
gboolean set_color_if_valid_key_value(GdkColor *color, GSettings *settings, const char *key);
void gnome_cmd_data_get_color_gnome_config (const gchar *path, GdkColor *color);
gboolean gnome_cmd_data_get_bool (const gchar *path, gboolean def);
- gboolean set_gsettings_when_changed (GSettings *settings, const char *key, gpointer value);
gboolean set_gsettings_color_when_changed (GSettings *settings, const char *key, GdkColor *color);
gboolean set_gsettings_enum_when_changed (GSettings *settings, const char *key, gint value);
inline void gnome_cmd_data_set_string_history (const gchar *format, GList *strings);
diff --git a/src/utils.cc b/src/utils.cc
index 7f7077d..4358ff8 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -1449,3 +1449,73 @@ int split(const string &s, vector<string> &coll, const char *sep)
return n;
}
+
+/**
+ * This method stores the value for a given key if the value is different from the currently stored one
+ * under the keys value. This function is able of storing several types of GSettings values (except enums
+ * which is done in @link set_gsettings_enum_when_changed @endlink ). Therefore, it first checks the type
+ * of GVariant of the default value of the given key. Depending on the result, the gpointer is than casted
+ * to the correct type so that *value can be saved.
+ * @returns TRUE if new value could be stored, else FALSE
+ */
+gboolean set_gsettings_when_changed (GSettings *settings, const char *key, gpointer value)
+{
+ GVariant *default_val;
+ gboolean rv = true;
+ default_val = g_settings_get_default_value (settings, key);
+
+ switch (g_variant_classify(default_val))
+ {
+ case G_VARIANT_CLASS_INT32:
+ {
+ gint old_value;
+ gint new_value = *(gint*) value;
+
+ old_value = g_settings_get_int (settings, key);
+ if (old_value != new_value)
+ rv = g_settings_set_int (settings, key, new_value);
+ break;
+ }
+ case G_VARIANT_CLASS_UINT32:
+ {
+ gint old_value;
+ gint new_value = *(gint*) value;
+
+ old_value = g_settings_get_uint (settings, key);
+ if (old_value != new_value)
+ rv = g_settings_set_uint (settings, key, new_value);
+ break;
+ }
+ case G_VARIANT_CLASS_STRING:
+ {
+ gchar *old_value;
+ gchar *new_value = (char*) value;
+
+ old_value = g_settings_get_string (settings, key);
+ if (strcmp(old_value, new_value) != 0)
+ rv = g_settings_set_string (settings, key, new_value);
+ g_free(old_value);
+ break;
+ }
+ case G_VARIANT_CLASS_BOOLEAN:
+ {
+ gboolean old_value;
+ gboolean new_value = *(gboolean*) value;
+
+ old_value = g_settings_get_boolean (settings, key);
+ if (old_value != new_value)
+ rv = g_settings_set_boolean (settings, key, new_value);
+ break;
+ }
+ default:
+ {
+ g_warning("Could not store value of type '%s' for key '%s'\n", g_variant_get_type_string
(default_val), key);
+ rv = false;
+ break;
+ }
+ }
+ if (default_val)
+ g_variant_unref (default_val);
+
+ return rv;
+}
diff --git a/src/utils.h b/src/utils.h
index f3641a2..9a68dfc 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -50,6 +50,8 @@ void gnome_cmd_error_message (const gchar *title, GError *error);
void run_command_indir (const gchar *command, const gchar *dir, gboolean term);
+gboolean set_gsettings_when_changed (GSettings *settings, const char *key, gpointer value);
+
inline void run_command (const gchar *command)
{
GError *error = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]