static GConfValue *gconf_value_new_g_value(GValue * value) { GConfValue *confValue; GType gType = G_VALUE_TYPE(value); switch (gType) { case G_TYPE_BOOLEAN: confValue = gconf_value_new(GCONF_VALUE_BOOL); gconf_value_set_bool(confValue, g_value_get_boolean(value)); break; case G_TYPE_INT: confValue = gconf_value_new(GCONF_VALUE_INT); gconf_value_set_int(confValue, g_value_get_int(value)); break; case G_TYPE_UINT: confValue = gconf_value_new(GCONF_VALUE_INT); gconf_value_set_int(confValue, g_value_get_uint(value)); break; case G_TYPE_STRING: confValue = gconf_value_new(GCONF_VALUE_STRING); gconf_value_set_string(confValue, g_value_get_string(value)); break; default: return NULL; } return confValue; }
int config_write (const GConfValueType data_type, const char *key, const gpointer data_value) { GConfValue *temp_value; config_open_close (CONFIG_OP_OPEN); temp_value = gconf_value_new (data_type); switch (data_type) { case GCONF_VALUE_STRING: gconf_value_set_string (temp_value, (char *) data_value); break; case GCONF_VALUE_INT: gconf_value_set_int (temp_value, (gint) data_value); break; case GCONF_VALUE_BOOL: gconf_value_set_bool (temp_value, (gboolean) data_value); break; case GCONF_VALUE_FLOAT: case GCONF_VALUE_SCHEMA: case GCONF_VALUE_LIST: case GCONF_VALUE_PAIR: case GCONF_VALUE_INVALID: { error (0, 0, _("Error writing to GConf database: Key type is not supported")); return FALSE; } } gconf_client_set (conf_client, key, temp_value, NULL); return TRUE; }
static GConfValue * corner_flip_from_widget (GConfPropertyEditor *peditor, GConfValue *value) { GConfValue *new_value; new_value = gconf_value_new (GCONF_VALUE_BOOL); gconf_value_set_bool (new_value, (gconf_value_get_int (value) == 1)); return new_value; }
static GConfValue * left_handed_to_gconf (GConfPropertyEditor *peditor, const GConfValue *value) { GConfValue *new_value; new_value = gconf_value_new (GCONF_VALUE_BOOL); gconf_value_set_bool (new_value, gconf_value_get_int (value) == 1); 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 void update_login_options (GtkWidget *widget, UmLoginOptions *d) { GError *error; gboolean active; GConfValue *value; const gchar *key = NULL; gchar *value_string; if (widget == d->userlist_check || widget == d->power_check) { active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); key = g_object_get_data (G_OBJECT (widget), "gconf-key"); } else { g_warning ("unhandled option in update_login_options"); return; } error = NULL; value = gconf_value_new (GCONF_VALUE_BOOL); gconf_value_set_bool (value, !active); value_string = gconf_value_encode (value); if (!dbus_g_proxy_call (d->proxy, "SetMandatoryValue", &error, G_TYPE_STRING, key, G_TYPE_STRING, value_string, G_TYPE_INVALID, G_TYPE_INVALID)) { g_warning ("error calling SetMandatoryValue: %s\n", error->message); g_error_free (error); } g_free (value_string); gconf_value_free (value); update_boolean_from_gconf (widget, d); }
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; }