static GConfValue * motion_acceleration_from_gconf (GConfPropertyEditor *peditor, const GConfValue *value) { GConfValue *new_value; gfloat motion_acceleration; new_value = gconf_value_new (GCONF_VALUE_FLOAT); if (gconf_value_get_float (value) == -1.0) { int numerator, denominator; get_default_mouse_info (&numerator, &denominator, NULL); motion_acceleration = CLAMP ((gfloat)(numerator / denominator), 0.2, 6.0); } else { motion_acceleration = CLAMP (gconf_value_get_float (value), 0.2, 6.0); } if (motion_acceleration >= 1) gconf_value_set_float (new_value, motion_acceleration + 4); else gconf_value_set_float (new_value, motion_acceleration * 5); return new_value; }
static GConfValue * motion_acceleration_to_gconf (GConfPropertyEditor *peditor, const GConfValue *value) { GConfValue *new_value; gfloat motion_acceleration; new_value = gconf_value_new (GCONF_VALUE_FLOAT); motion_acceleration = CLAMP (gconf_value_get_float (value), 1.0, 10.0); if (motion_acceleration < 5) gconf_value_set_float (new_value, motion_acceleration / 5.0); else gconf_value_set_float (new_value, motion_acceleration - 4); return new_value; }
static GConfValue * threshold_from_gconf (GConfPropertyEditor *peditor, const GConfValue *value) { GConfValue *new_value; new_value = gconf_value_new (GCONF_VALUE_FLOAT); if (gconf_value_get_int (value) == -1) { int threshold; get_default_mouse_info (NULL, NULL, &threshold); gconf_value_set_float (new_value, CLAMP (threshold, 1, 10)); } else { gconf_value_set_float (new_value, CLAMP (gconf_value_get_int (value), 1, 10)); } return new_value; }
static GConfValue * drag_threshold_from_gconf (GConfPropertyEditor *peditor, const GConfValue *value) { GConfValue *new_value; new_value = gconf_value_new (GCONF_VALUE_FLOAT); gconf_value_set_float (new_value, CLAMP (gconf_value_get_int (value), 1, 10)); return new_value; }
/* Helper for utils_get_value, reads int/string/float/bool/schema. */ static GConfValue * utils_get_value_helper_fundamental (DBusMessageIter *iter, GConfValueType value_type) { GConfValue *value; GConfSchema *schema; gint32 i; const gchar *s; gdouble d; gboolean b; d(g_print ("Get value (fundamental)\n")); if (value_type == GCONF_VALUE_INVALID) return NULL; value = gconf_value_new (value_type); switch (value_type) { case GCONF_VALUE_INT: dbus_message_iter_get_basic (iter, &i); gconf_value_set_int (value, i); break; case GCONF_VALUE_STRING: dbus_message_iter_get_basic (iter, &s); gconf_value_set_string (value, s); break; case GCONF_VALUE_FLOAT: dbus_message_iter_get_basic (iter, &d); gconf_value_set_float (value, d); break; case GCONF_VALUE_BOOL: dbus_message_iter_get_basic (iter, &b); gconf_value_set_bool (value, b); break; case GCONF_VALUE_SCHEMA: schema = utils_get_schema (iter); gconf_value_set_schema_nocopy (value, schema); break; default: g_assert_not_reached (); } return value; }
static GConfValue * _to_gconf_value (const GValue *value) { GConfValue *gv; GType type = G_VALUE_TYPE (value); switch (type) { case G_TYPE_STRING: { gv = gconf_value_new (GCONF_VALUE_STRING); gconf_value_set_string (gv, g_value_get_string (value)); } break; case G_TYPE_INT: { gv = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gv, g_value_get_int (value)); } break; case G_TYPE_UINT: { gv = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gv, g_value_get_uint (value)); } break; case G_TYPE_BOOLEAN: { gv = gconf_value_new (GCONF_VALUE_BOOL); gconf_value_set_bool (gv, g_value_get_boolean (value)); } break; case G_TYPE_DOUBLE: { gv = gconf_value_new (GCONF_VALUE_FLOAT); gconf_value_set_float (gv, g_value_get_double (value)); } break; case G_TYPE_FLOAT: { gv = gconf_value_new (GCONF_VALUE_FLOAT); gconf_value_set_float (gv, g_value_get_float (value)); } break; default: if (type == G_TYPE_VALUE_ARRAY) { GSList *l = NULL; GType list_type = G_TYPE_STRING; GValueArray *array = g_value_get_boxed (value); gint i; if (array && array->n_values > 0) { list_type = G_VALUE_TYPE (&(array->values[0])); } gv = gconf_value_new (GCONF_VALUE_LIST); switch (list_type) { case G_TYPE_STRING: gconf_value_set_list_type (gv, GCONF_VALUE_STRING); break; case G_TYPE_INT: case G_TYPE_UINT: gconf_value_set_list_type (gv, GCONF_VALUE_INT); break; case G_TYPE_BOOLEAN: gconf_value_set_list_type (gv, GCONF_VALUE_BOOL); break; case G_TYPE_FLOAT: case G_TYPE_DOUBLE: gconf_value_set_list_type (gv, GCONF_VALUE_FLOAT); break; default: g_assert_not_reached (); } for (i = 0; array && i < array->n_values; i++) { GConfValue *tmp; g_assert (G_VALUE_TYPE (&(array->values[i])) == list_type); tmp = _to_gconf_value (&(array->values[i])); l = g_slist_append (l, tmp); } gconf_value_set_list_nocopy (gv, l); } else g_assert_not_reached (); } return gv; }
/* Syncs an object property to GConf */ static void prop_binding_sync_prop_to_pref (PropBinding *binding) { GValue value; GConfValue *gconf_value; memset (&value, 0, sizeof (GValue)); g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (binding->prop)); g_object_get_property (binding->object, binding->prop->name, &value); switch (value.g_type) { case G_TYPE_STRING: gconf_value = gconf_value_new (GCONF_VALUE_STRING); gconf_value_set_string (gconf_value, g_value_get_string (&value)); break; case G_TYPE_INT: gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, g_value_get_int (&value)); break; case G_TYPE_UINT: gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, g_value_get_uint (&value)); break; case G_TYPE_LONG: gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, g_value_get_long (&value)); break; case G_TYPE_ULONG: gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, g_value_get_ulong (&value)); break; case G_TYPE_INT64: gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, g_value_get_int64 (&value)); break; case G_TYPE_UINT64: gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, g_value_get_uint64 (&value)); break; case G_TYPE_CHAR: gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, g_value_get_char (&value)); break; case G_TYPE_UCHAR: gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, g_value_get_uchar (&value)); break; case G_TYPE_ENUM: gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, g_value_get_enum (&value)); break; case G_TYPE_BOOLEAN: gconf_value = gconf_value_new (GCONF_VALUE_BOOL); gconf_value_set_bool (gconf_value, g_value_get_boolean (&value)); break; case G_TYPE_DOUBLE: gconf_value = gconf_value_new (GCONF_VALUE_FLOAT); #ifdef HAVE_CORBA_GCONF /* FIXME we cast to a float explicitly as CORBA GConf * uses doubles in its API, but treats them as floats * when transporting them over CORBA. See #322837 */ gconf_value_set_float (gconf_value, (float) g_value_get_double (&value)); #else gconf_value_set_float (gconf_value, g_value_get_double (&value)); #endif break; case G_TYPE_FLOAT: gconf_value = gconf_value_new (GCONF_VALUE_FLOAT); gconf_value_set_float (gconf_value, g_value_get_float (&value)); break; default: if (g_type_is_a (value.g_type, G_TYPE_ENUM)) { gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, g_value_get_enum (&value)); } else { g_warning ("prop_binding_sync_prop_to_pref: " "Unhandled value type '%s'.\n", g_type_name (value.g_type)); goto done; } break; } /* Set to GConf */ gconf_client_set (bridge->client, binding->key, gconf_value, NULL); /* Store until change notification comes in, so that we are able * to ignore it */ binding->val_changes = g_slist_append (binding->val_changes, gconf_value); done: g_value_unset (&value); }
static GConfValue * gconf_settings_backend_simple_gvariant_to_gconf_value (GVariant *value, const GVariantType *type) { GConfValue *gconf_value = NULL; if (g_variant_type_equal (type, G_VARIANT_TYPE_BOOLEAN)) { gconf_value = gconf_value_new (GCONF_VALUE_BOOL); gconf_value_set_bool (gconf_value, g_variant_get_boolean (value)); } else if (g_variant_type_equal (type, G_VARIANT_TYPE_BYTE)) { guchar i = g_variant_get_byte (value); gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, i); } else if (g_variant_type_equal (type, G_VARIANT_TYPE_INT16)) { gint16 i = g_variant_get_int16 (value); gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, i); } else if (g_variant_type_equal (type, G_VARIANT_TYPE_UINT16)) { guint16 i = g_variant_get_uint16 (value); if (i > G_MAXINT) return NULL; gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, i); } else if (g_variant_type_equal (type, G_VARIANT_TYPE_INT32)) { gint32 i = g_variant_get_int32 (value); gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, i); } else if (g_variant_type_equal (type, G_VARIANT_TYPE_UINT32)) { guint32 i = g_variant_get_uint32 (value); if (i > G_MAXINT) return NULL; gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, i); } else if (g_variant_type_equal (type, G_VARIANT_TYPE_INT64)) { gint64 i = g_variant_get_int64 (value); if (i < G_MININT || i > G_MAXINT) return NULL; gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, i); } else if (g_variant_type_equal (type, G_VARIANT_TYPE_UINT64)) { guint64 i = g_variant_get_uint64 (value); if (i > G_MAXINT) return NULL; gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, i); } else if (g_variant_type_equal (type, G_VARIANT_TYPE_HANDLE)) { guint32 i = g_variant_get_handle (value); if (i > G_MAXINT) return NULL; gconf_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (gconf_value, i); } else if (g_variant_type_equal (type, G_VARIANT_TYPE_DOUBLE)) { gconf_value = gconf_value_new (GCONF_VALUE_FLOAT); gconf_value_set_float (gconf_value, g_variant_get_double (value)); } else if (g_variant_type_equal (type, G_VARIANT_TYPE_STRING) || g_variant_type_equal (type, G_VARIANT_TYPE_OBJECT_PATH) || g_variant_type_equal (type, G_VARIANT_TYPE_SIGNATURE)) { gconf_value = gconf_value_new (GCONF_VALUE_STRING); gconf_value_set_string (gconf_value, g_variant_get_string (value, NULL)); } return gconf_value; }
/* Helper for utils_get_value, reads a list. The "list" is a struct with the * list type and an array with the values directly in it. */ static GConfValue * utils_get_value_helper_list (DBusMessageIter *iter) { DBusMessageIter struct_iter; DBusMessageIter array_iter; GConfValue *value; gint32 list_type; GSList *list; GConfValue *child_value; d(g_print ("Get value (list)\n")); value = gconf_value_new (GCONF_VALUE_LIST); dbus_message_iter_recurse (iter, &struct_iter); /* Get the list type. */ dbus_message_iter_get_basic (&struct_iter, &list_type); gconf_value_set_list_type (value, list_type); /* Get the array. */ dbus_message_iter_next (&struct_iter); dbus_message_iter_recurse (&struct_iter, &array_iter); /* And the values from the array. */ list = NULL; switch (list_type) { case GCONF_VALUE_STRING: while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_STRING) { const gchar *str; dbus_message_iter_get_basic (&array_iter, &str); child_value = gconf_value_new (GCONF_VALUE_STRING); gconf_value_set_string (child_value, str); list = g_slist_prepend (list, child_value); dbus_message_iter_next (&array_iter); } break; case GCONF_VALUE_INT: while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_INT32) { gint32 i; dbus_message_iter_get_basic (&array_iter, &i); child_value = gconf_value_new (GCONF_VALUE_INT); gconf_value_set_int (child_value, i); list = g_slist_prepend (list, child_value); dbus_message_iter_next (&array_iter); } break; case GCONF_VALUE_FLOAT: while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_DOUBLE) { gdouble d; dbus_message_iter_get_basic (&array_iter, &d); child_value = gconf_value_new (GCONF_VALUE_FLOAT); gconf_value_set_float (child_value, d); list = g_slist_prepend (list, child_value); dbus_message_iter_next (&array_iter); } break; case GCONF_VALUE_BOOL: while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_BOOLEAN) { gboolean b; dbus_message_iter_get_basic (&array_iter, &b); child_value = gconf_value_new (GCONF_VALUE_BOOL); gconf_value_set_bool (child_value, b); list = g_slist_prepend (list, child_value); dbus_message_iter_next (&array_iter); } break; case GCONF_VALUE_SCHEMA: while (dbus_message_iter_get_arg_type (&array_iter) == DBUS_TYPE_STRUCT) { child_value = utils_get_schema_value (&array_iter); list = g_slist_prepend (list, child_value); dbus_message_iter_next (&array_iter); } break; default: g_assert_not_reached (); } list = g_slist_reverse (list); gconf_value_set_list_nocopy (value, list); return value; }