[gpointing-device-settings] Add backup/restore all properties functions.
- From: Hiroyuki Ikezoe <hiikezoe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gpointing-device-settings] Add backup/restore all properties functions.
- Date: Fri, 5 Mar 2010 11:36:44 +0000 (UTC)
commit c7115e0376c914597bd6247b8aedf3a3db2af74e
Author: Hiroyuki Ikezoe <poincare ikezoe net>
Date: Fri Mar 5 19:08:08 2010 +0900
Add backup/restore all properties functions.
src/gpds-xinput.c | 186 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/gpds-xinput.h | 4 +
2 files changed, 190 insertions(+), 0 deletions(-)
---
diff --git a/src/gpds-xinput.c b/src/gpds-xinput.c
index 0ad7d34..5252873 100644
--- a/src/gpds-xinput.c
+++ b/src/gpds-xinput.c
@@ -38,6 +38,7 @@ struct _GpdsXInputPriv
XDevice *device;
GpdsXInputPropertyEntry *property_entries;
guint n_property_entries;
+ GPtrArray *properties;
};
enum
@@ -111,6 +112,11 @@ dispose (GObject *object)
g_free(priv->property_entries);
}
+ if (priv->properties) {
+ g_ptr_array_unref(priv->properties);
+ priv->properties = NULL;
+ }
+
if (G_OBJECT_CLASS(gpds_xinput_parent_class)->dispose)
G_OBJECT_CLASS(gpds_xinput_parent_class)->dispose(object);
}
@@ -734,6 +740,186 @@ gpds_xinput_register_property_entries (GpdsXInput *xinput,
}
}
+static GValueArray *
+get_int_properties (GpdsXInput *xinput, const gchar *name)
+{
+ gulong n_values, i;
+ gint *int_values = NULL;
+ GValue value = { 0 };
+ GValueArray *array;
+
+ gpds_xinput_get_int_properties_by_name(xinput,
+ name,
+ NULL,
+ &int_values,
+ &n_values);
+ array = g_value_array_new(n_values);
+ g_value_init(&value, G_TYPE_INT);
+
+ for (i = 0; i < n_values; i++) {
+ g_value_set_int(&value, int_values[i]);
+ g_value_array_append(array, &value);
+ g_value_reset(&value);
+ }
+ g_free(int_values);
+
+ return array;
+}
+
+static GValueArray *
+get_float_properties (GpdsXInput *xinput, const gchar *name)
+{
+ gulong n_values, i;
+ gdouble *float_values = NULL;
+ GValue value = { 0 };
+ GValueArray *array;
+
+ gpds_xinput_get_float_properties_by_name(xinput,
+ name,
+ NULL,
+ &float_values,
+ &n_values);
+ array = g_value_array_new(n_values);
+ g_value_init(&value, G_TYPE_DOUBLE);
+
+ for (i = 0; i < n_values; i++) {
+ g_value_set_float(&value, float_values[i]);
+ g_value_array_append(array, &value);
+ g_value_reset(&value);
+ }
+ g_free(float_values);
+
+ return array;
+}
+
+static GPtrArray *
+property_array_new (guint size)
+{
+ GPtrArray *properties;
+
+ properties = g_ptr_array_sized_new(size);
+ g_ptr_array_set_free_func(properties, (GDestroyNotify)g_value_array_free);
+
+ return properties;
+}
+
+void
+gpds_xinput_backup_all_properties (GpdsXInput *xinput)
+{
+ guint i;
+ GpdsXInputPriv *priv;
+ GPtrArray *properties;
+
+ g_return_if_fail(GPDS_IS_XINPUT(xinput));
+
+ priv = GPDS_XINPUT_GET_PRIVATE(xinput);
+
+ if (!priv->n_property_entries)
+ return;
+
+ properties = property_array_new(priv->n_property_entries);
+
+ for (i = 0; i< priv->n_property_entries; i ++) {
+ GpdsXInputPropertyEntry *entry;
+ GValueArray *values = NULL;
+
+ entry = &priv->property_entries[i];
+ switch (entry->property_type) {
+ case G_TYPE_INT:
+ values = get_int_properties(xinput, entry->name);
+ break;
+ case G_TYPE_FLOAT:
+ values = get_float_properties(xinput, entry->name);
+ break;
+ default:
+ break;
+ }
+
+ if (values)
+ g_ptr_array_add(properties, values);
+ }
+
+ if (priv->properties)
+ g_ptr_array_unref(priv->properties);
+ priv->properties = properties;
+}
+
+static void
+set_int_properties (GpdsXInput *xinput, gint property_enum, GValueArray *values)
+{
+ guint i;
+ gint *int_values;
+
+ int_values = g_new0(gint, values->n_values);
+ for (i = 0; i < values->n_values; i++) {
+ GValue *value;
+ value = g_value_array_get_nth(values, i);
+
+ int_values[i] = g_value_get_int(value);
+ }
+ gpds_xinput_set_int_properties(xinput,
+ property_enum,
+ NULL,
+ int_values,
+ values->n_values);
+}
+
+static void
+set_float_properties (GpdsXInput *xinput, gint property_enum, GValueArray *values)
+{
+ guint i;
+ gdouble *float_values;
+
+ float_values = g_new0(gdouble, values->n_values);
+ for (i = 0; i < values->n_values; i++) {
+ GValue *value;
+ value = g_value_array_get_nth(values, i);
+
+ float_values[i] = g_value_get_double(value);
+ }
+ gpds_xinput_set_float_properties(xinput,
+ property_enum,
+ NULL,
+ float_values,
+ values->n_values);
+}
+
+void
+gpds_xinput_restore_all_properties (GpdsXInput *xinput)
+{
+ guint i;
+ GpdsXInputPriv *priv;
+
+ g_return_if_fail(GPDS_IS_XINPUT(xinput));
+
+ priv = GPDS_XINPUT_GET_PRIVATE(xinput);
+
+ if (!priv->n_property_entries)
+ return;
+
+ if (!priv->properties)
+ return;
+
+ for (i = 0; i< priv->properties->len; i ++) {
+ GpdsXInputPropertyEntry *entry;
+ GValueArray *values = NULL;
+
+ values = g_ptr_array_index(priv->properties, i);
+ entry = &priv->property_entries[i];
+
+ switch (entry->property_type) {
+ case G_TYPE_INT:
+ set_int_properties(xinput, entry->property_enum, values);
+ break;
+ case G_TYPE_FLOAT:
+ set_float_properties(xinput, entry->property_enum, values);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
/*
vi:ts=4:nowrap:ai:expandtab:sw=4
*/
diff --git a/src/gpds-xinput.h b/src/gpds-xinput.h
index a2a2276..ff04b1f 100644
--- a/src/gpds-xinput.h
+++ b/src/gpds-xinput.h
@@ -126,6 +126,10 @@ gboolean gpds_xinput_set_button_map (GpdsXInput *xinput,
GError **error,
guchar *map,
gshort n_buttons);
+void gpds_xinput_backup_all_properties
+ (GpdsXInput *xinput);
+void gpds_xinput_restore_all_properties
+ (GpdsXInput *xinput);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]