Example #1
0
/**
 * Return an integer list from the specified GConf key
 *
 * @param key The GConf key to get the values from
 * @param[out] values Will contain an GSList with the values on return
 * @return TRUE on success, FALSE on failure
 */
gboolean mce_gconf_get_int_list(const gchar *const key, GSList **values)
{
	gboolean status = FALSE;
	GError *error = NULL;
	GConfValue *gcv, *gcv2;
	GSList *list;
	gint i;

	if( gconf_disabled ) {
		mce_log(LL_DEBUG, "blocked %s query", key);
		goto EXIT;
	}

	gcv = gconf_client_get(gconf_client, key, &error);

	if (gcv == NULL) {
		mce_log((error != NULL) ? LL_WARN : LL_INFO,
			"Could not retrieve %s from GConf; %s",
			key, (error != NULL) ? error->message : "Key not set");
		goto EXIT;
	}

	if ((gcv->type != GCONF_VALUE_LIST) ||
	    (gconf_value_get_list_type(gcv) != GCONF_VALUE_INT)) {
		mce_log(LL_ERR,
			"GConf key %s should have type: %d<%d>, but has type: %d<%d>",
			key, GCONF_VALUE_LIST, GCONF_VALUE_INT,
			gcv->type, gconf_value_get_list_type(gcv));
		goto EXIT;
	}

	list = gconf_value_get_list(gcv);

	for (i = 0; (gcv2 = g_slist_nth_data(list, i)) != NULL; i++) {
		gint data;

		data = gconf_value_get_int(gcv2);

		/* Prepend is more efficient than append */
		*values = g_slist_prepend(*values, GINT_TO_POINTER(data));
	}

	/* Reverse the list, since we want the entries in the right order */
	*values = g_slist_reverse(*values);
	gconf_value_free(gcv);

	status = TRUE;

EXIT:
	g_clear_error(&error);

	return status;
}
Example #2
0
void
eel_gconf_value_set_string_list (GConfValue *value,
                                 const GSList *string_list)
{
    const GSList *node;
    GConfValue *next_value;
    GSList *value_list;

    g_return_if_fail (value->type == GCONF_VALUE_LIST);
    g_return_if_fail (gconf_value_get_list_type (value) == GCONF_VALUE_STRING);

    value_list = NULL;
    for (node = string_list; node != NULL; node = node->next) {
        next_value = gconf_value_new (GCONF_VALUE_STRING);
        gconf_value_set_string (next_value, node->data);
        value_list = g_slist_append (value_list, next_value);
    }

    gconf_value_set_list (value, value_list);

    for (node = value_list; node != NULL; node = node->next) {
        gconf_value_free (node->data);
    }
    g_slist_free (value_list);
}
Example #3
0
GSList *
eel_gconf_value_get_string_list (const GConfValue *value)
{
    GSList *result;
    const GSList *slist;
    const GSList *node;
    const char *string;
    const GConfValue *next_value;

    if (value == NULL) {
        return NULL;
    }

    g_return_val_if_fail (value->type == GCONF_VALUE_LIST, NULL);
    g_return_val_if_fail (gconf_value_get_list_type (value) == GCONF_VALUE_STRING, NULL);

    slist = gconf_value_get_list (value);
    result = NULL;
    for (node = slist; node != NULL; node = node->next) {
        next_value = node->data;
        g_return_val_if_fail (next_value != NULL, NULL);
        g_return_val_if_fail (next_value->type == GCONF_VALUE_STRING, NULL);
        string = gconf_value_get_string (next_value);
        result = g_slist_prepend (result, g_strdup (string));
    }
    return g_slist_reverse (result);
}
static void
disabled_applets_notify (GConfClient   *client,
                         guint          cnxn_id,
                         GConfEntry    *entry,
                         PanelLockdown *lockdown)
{
        GSList *l;

        if (!entry->value || entry->value->type != GCONF_VALUE_LIST ||
            gconf_value_get_list_type (entry->value) != GCONF_VALUE_STRING)
                return;

        for (l = lockdown->disabled_applets; l; l = l->next)
                g_free (l->data);
        g_slist_free (lockdown->disabled_applets);
        lockdown->disabled_applets = NULL;

        for (l = gconf_value_get_list (entry->value); l; l = l->next) {
                const char *iid = gconf_value_get_string (l->data);

                lockdown->disabled_applets =
                        g_slist_prepend (lockdown->disabled_applets,
                                         g_strdup (iid));
        }

        panel_lockdown_invoke_closures (lockdown);
}
Example #5
0
static void
calendar_sources_selected_sources_notify (GConfClient        *client,
					  guint               cnx_id,
					  GConfEntry         *entry,
					  CalendarSourceData *source_data)
{
  GSList *l;

  if (!entry->value ||
      entry->value->type != GCONF_VALUE_LIST ||
      gconf_value_get_list_type (entry->value) != GCONF_VALUE_STRING)
    return;

  dprintf ("Selected sources key (%s) changed, reloading\n", entry->key);

  for (l = source_data->selected_sources; l; l = l->next)
    g_free (l->data);
  source_data->selected_sources = NULL;

  for (l = gconf_value_get_list (entry->value); l; l = l->next)
    {
      const char *source = gconf_value_get_string (l->data);

      source_data->selected_sources = 
	g_slist_prepend (source_data->selected_sources,
			 g_strdup (source));
    }
  source_data->selected_sources =
    g_slist_reverse (source_data->selected_sources);

  calendar_sources_load_esource_list (source_data);
}
Example #6
0
/** Helper for appending gconf float list to dbus message
 *
 * @param conf GConfValue of float list type
 * @param pcount number of items in the returned array is stored here
 * @return array of doubles that can be easily added to DBusMessage
 */
static double *float_array_from_gconf_value(GConfValue *conf, int *pcount)
{
	double *array = 0;
	int     count = 0;

	GSList *list, *item;

	if( conf->type != GCONF_VALUE_LIST )
		goto EXIT;

	if( gconf_value_get_list_type(conf) != GCONF_VALUE_FLOAT )
		goto EXIT;

	list = gconf_value_get_list(conf);

	for( item = list; item; item = item->next )
		++count;

	array = g_malloc_n(count, sizeof *array);
	count = 0;

	for( item = list; item; item = item->next )
		array[count++] = gconf_value_get_float(item->data);

EXIT:
	return *pcount = count, array;
}
Example #7
0
/** Helper for deducing what kind of variant signature we need for a value
 *
 * @param conf GConf value
 *
 * @return D-Bus signature needed for adding given value to a container
 */
static const char *value_signature(GConfValue *conf)
{
	if( conf->type != GCONF_VALUE_LIST ) {
		return type_signature(conf->type);
	}

	switch( gconf_value_get_list_type(conf) ) {
	case GCONF_VALUE_STRING:
		return DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING;
	case GCONF_VALUE_INT:
		return DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_INT32_AS_STRING;
	case GCONF_VALUE_FLOAT:
		return DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_DOUBLE_AS_STRING;
	case GCONF_VALUE_BOOL:
		return DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BOOLEAN_AS_STRING;
	default: break;
	}

	return 0;
}
Example #8
0
static QVariant convertValue(GConfValue *src)
{
    if (!src) {
        return QVariant();
    } else {
        switch (src->type) {
        case GCONF_VALUE_INVALID:
            return QVariant(QVariant::Invalid);
        case GCONF_VALUE_BOOL:
            return QVariant((bool)gconf_value_get_bool(src));
        case GCONF_VALUE_INT:
            return QVariant(gconf_value_get_int(src));
        case GCONF_VALUE_FLOAT:
            return QVariant(gconf_value_get_float(src));
        case GCONF_VALUE_STRING:
            return QVariant(QString::fromUtf8(gconf_value_get_string(src)));
        case GCONF_VALUE_LIST:
            switch (gconf_value_get_list_type(src)) {
            case GCONF_VALUE_STRING:
                {
                    QStringList result;
                    for (GSList *elts = gconf_value_get_list(src); elts; elts = elts->next)
                        result.append(QString::fromUtf8(gconf_value_get_string((GConfValue *)elts->data)));
                    return QVariant(result);
                }
            default:
                {
                    QList<QVariant> result;
                    for (GSList *elts = gconf_value_get_list(src); elts; elts = elts->next)
                        result.append(convertValue((GConfValue *)elts->data));
                    return QVariant(result);
                }
            }
        case GCONF_VALUE_SCHEMA:
        default:
            return QVariant();
        }
    }
}
Example #9
0
gboolean
eel_gconf_value_is_equal (const GConfValue *a,
                          const GConfValue *b)
{
    GSList *node_a;
    GSList *node_b;

    if (a == NULL && b == NULL) {
        return TRUE;
    }

    if (a == NULL || b == NULL) {
        return FALSE;
    }

    if (a->type != b->type) {
        return FALSE;
    }

    switch (a->type) {
    case GCONF_VALUE_STRING:
    case GCONF_VALUE_INT:
    case GCONF_VALUE_FLOAT:
    case GCONF_VALUE_BOOL:
        return simple_value_is_equal (a, b);
        break;

    case GCONF_VALUE_LIST:
        if (gconf_value_get_list_type (a) !=
                gconf_value_get_list_type (b)) {
            return FALSE;
        }

        node_a = gconf_value_get_list (a);
        node_b = gconf_value_get_list (b);

        if (node_a == NULL && node_b == NULL) {
            return TRUE;
        }

        if (g_slist_length (node_a) !=
                g_slist_length (node_b)) {
            return FALSE;
        }

        for (;
                node_a != NULL && node_b != NULL;
                node_a = node_a->next, node_b = node_b->next) {
            g_assert (node_a->data != NULL);
            g_assert (node_b->data != NULL);
            if (!simple_value_is_equal (node_a->data, node_b->data)) {
                return FALSE;
            }
        }

        return TRUE;
    default:
        /* FIXME: pair ? */
        g_assert (0);
    }

    g_assert_not_reached ();
    return FALSE;
}
Example #10
0
/** Helper for appending GConfValue to dbus message
 *
 * @param reply DBusMessage under construction
 * @param conf GConfValue to be added to the reply
 *
 * @return TRUE if the value was succesfully appended, or FALSE on failure
 */
static gboolean append_gconf_value_to_dbus_message(DBusMessage *reply, GConfValue *conf)
{
	const char *sig = 0;

	DBusMessageIter body, variant, array;

	if( !(sig = value_signature(conf)) ) {
		goto bailout_message;
	}

	dbus_message_iter_init_append(reply, &body);

	if( !dbus_message_iter_open_container(&body, DBUS_TYPE_VARIANT,
					      sig, &variant) ) {
		goto bailout_message;
	}

	switch( conf->type ) {
	case GCONF_VALUE_STRING:
		{
			const char *arg = gconf_value_get_string(conf) ?: "";
			dbus_message_iter_append_basic(&variant,
						       DBUS_TYPE_STRING,
						       &arg);
		}
		break;

	case GCONF_VALUE_INT:
		{
			dbus_int32_t arg = gconf_value_get_int(conf);
			dbus_message_iter_append_basic(&variant,
						       DBUS_TYPE_INT32,
						       &arg);
		}
		break;

	case GCONF_VALUE_FLOAT:
		{
			double arg = gconf_value_get_float(conf);
			dbus_message_iter_append_basic(&variant,
						       DBUS_TYPE_DOUBLE,
						       &arg);
		}
		break;

	case GCONF_VALUE_BOOL:
		{
			dbus_bool_t arg = gconf_value_get_bool(conf);
			dbus_message_iter_append_basic(&variant,
						       DBUS_TYPE_BOOLEAN,
						       &arg);
		}
		break;

	case GCONF_VALUE_LIST:
		if( !(sig = type_signature(gconf_value_get_list_type(conf))) ) {
			goto bailout_variant;
		}

		if( !dbus_message_iter_open_container(&variant,
						      DBUS_TYPE_ARRAY,
						      sig, &array) ) {
			goto bailout_variant;
		}

		switch( gconf_value_get_list_type(conf) ) {
		case GCONF_VALUE_STRING:
			{
				int          cnt = 0;
				const char **arg = string_array_from_gconf_value(conf, &cnt);
				for( int i = 0; i < cnt; ++i ) {
					const char *str = arg[i];
					dbus_message_iter_append_basic(&array,
								       DBUS_TYPE_STRING,
								       &str);
				}
				g_free(arg);
			}
			break;
		case GCONF_VALUE_INT:
			{
				int           cnt = 0;
				dbus_int32_t *arg = int_array_from_gconf_value(conf, &cnt);
				dbus_message_iter_append_fixed_array(&array,
								     DBUS_TYPE_INT32,
								     &arg, cnt);
				g_free(arg);
			}
			break;
		case GCONF_VALUE_FLOAT:
			{
				int     cnt = 0;
				double *arg = float_array_from_gconf_value(conf, &cnt);
				dbus_message_iter_append_fixed_array(&array,
								     DBUS_TYPE_DOUBLE,
								     &arg, cnt);
				g_free(arg);
			}
			break;
		case GCONF_VALUE_BOOL:
			{
				int          cnt = 0;
				dbus_bool_t *arg = bool_array_from_gconf_value(conf, &cnt);
				dbus_message_iter_append_fixed_array(&array,
								     DBUS_TYPE_BOOLEAN,
								     &arg, cnt);
				g_free(arg);
			}
			break;

		default:
			goto bailout_array;
		}

		if( !dbus_message_iter_close_container(&variant, &array) ) {
			goto bailout_variant;
		}
		break;

	default:
		goto bailout_variant;
	}

	if( !dbus_message_iter_close_container(&body, &variant) ) {
		goto bailout_message;
	}
	return TRUE;

bailout_array:
	dbus_message_iter_abandon_container(&variant, &array);

bailout_variant:
	dbus_message_iter_abandon_container(&body, &variant);

bailout_message:
	return FALSE;
}
Example #11
0
static GVariant *
gconf_settings_backend_gconf_value_to_gvariant (GConfValue         *gconf_value,
                                                const GVariantType *expected_type)
{
  switch (gconf_value->type)
    {
    case GCONF_VALUE_STRING:
    case GCONF_VALUE_INT:
    case GCONF_VALUE_FLOAT:
    case GCONF_VALUE_BOOL:
      if (!gconf_settings_backend_simple_gconf_value_type_is_compatible (gconf_value->type, expected_type))
        return NULL;
      return gconf_settings_backend_simple_gconf_value_type_to_gvariant (gconf_value, expected_type);
    case GCONF_VALUE_LIST:
      {
        GConfValueType      list_type;
        const GVariantType *array_type;
        GSList             *list;
        GPtrArray          *array;
        GVariant           *result;

        if (!g_variant_type_is_array (expected_type))
          return NULL;

        list_type = gconf_value_get_list_type (gconf_value);
        array_type = g_variant_type_element (expected_type);
        if (!gconf_settings_backend_simple_gconf_value_type_is_compatible (list_type, array_type))
          return NULL;

        array = g_ptr_array_new ();
        for (list = gconf_value_get_list (gconf_value); list != NULL; list = list->next)
          {
            GVariant *variant;
            variant = gconf_settings_backend_simple_gconf_value_type_to_gvariant (list->data, array_type);
            g_ptr_array_add (array, variant);
          }

        result = g_variant_new_array (array_type, (GVariant **) array->pdata, array->len);
        g_ptr_array_free (array, TRUE);

        return result;
      }
      break;
    case GCONF_VALUE_PAIR:
      {
        GConfValue         *car;
        GConfValue         *cdr;
        const GVariantType *first_type;
        const GVariantType *second_type;
        GVariant           *tuple[2];
        GVariant           *result;

        if (!g_variant_type_is_tuple (expected_type) ||
            g_variant_type_n_items (expected_type) != 2)
          return NULL;

        car = gconf_value_get_car (gconf_value);
        cdr = gconf_value_get_cdr (gconf_value);
        first_type = g_variant_type_first (expected_type);
        second_type = g_variant_type_next (first_type);

        if (!gconf_settings_backend_simple_gconf_value_type_is_compatible (car->type, first_type) ||
            !gconf_settings_backend_simple_gconf_value_type_is_compatible (cdr->type, second_type))
          return NULL;

        tuple[0] = gconf_settings_backend_simple_gconf_value_type_to_gvariant (car, first_type);
        tuple[1] = gconf_settings_backend_simple_gconf_value_type_to_gvariant (cdr, second_type);

        result = g_variant_new_tuple (tuple, 2);
        return result;
      }
      break;
    default:
      return NULL;
    }

  g_assert_not_reached ();

  return NULL;
}
Example #12
0
/* Helper for utils_append_value, writes a list. The "list" is a struct with the
 * list type and an array with the values directly in it.
 */
static void
utils_append_value_helper_list (DBusMessageIter  *main_iter,
				const GConfValue *value)
{
  DBusMessageIter  struct_iter;
  DBusMessageIter  array_iter;
  GConfValueType   list_type;
  const gchar     *array_type;
  GSList          *list;
  
  d(g_print ("Append value (list)\n"));

  g_assert (value->type == GCONF_VALUE_LIST);
  
  dbus_message_iter_open_container (main_iter,
				    DBUS_TYPE_STRUCT,
				    NULL, /* for struct */
				    &struct_iter);
  
  /* Write the list type. */
  list_type = gconf_value_get_list_type (value);
  dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_INT32, &list_type);

  /* And the value. */
  switch (list_type)
    {
    case GCONF_VALUE_INT:
      array_type = DBUS_TYPE_INT32_AS_STRING;
      break;
      
    case GCONF_VALUE_STRING:
      array_type = DBUS_TYPE_STRING_AS_STRING;
      break;
      
    case GCONF_VALUE_FLOAT:
      array_type = DBUS_TYPE_DOUBLE_AS_STRING;
      break;
      
    case GCONF_VALUE_BOOL:
      array_type = DBUS_TYPE_BOOLEAN_AS_STRING;
      break;
      
    case GCONF_VALUE_SCHEMA:
      array_type = DBUS_TYPE_STRUCT_AS_STRING;
      break;

    default:
      array_type = NULL;
      g_assert_not_reached ();
    }
  
  dbus_message_iter_open_container (&struct_iter,
				    DBUS_TYPE_ARRAY,
				    array_type,
				    &array_iter);
  
  list = gconf_value_get_list (value);
  
  switch (list_type)
    {
    case GCONF_VALUE_STRING:
      while (list)
	{
	  const gchar *s;

	  s = gconf_value_get_string (list->data);
	  dbus_message_iter_append_basic (&array_iter,
					  DBUS_TYPE_STRING,
					  &s);
	  
	  list = list->next;
	}
      break;

    case GCONF_VALUE_INT:
      while (list)
	{
	  gint32 i;

	  i = gconf_value_get_int (list->data);
	  dbus_message_iter_append_basic (&array_iter,
					  DBUS_TYPE_INT32,
					  &i);
	  
	  list = list->next;
	}
      break;
      
    case GCONF_VALUE_FLOAT:
      while (list)
	{
	  gdouble d;

	  d = gconf_value_get_float (list->data);
	  dbus_message_iter_append_basic (&array_iter,
					  DBUS_TYPE_DOUBLE,
					  &d);

	  list = list->next;
	}
      break;

    case GCONF_VALUE_BOOL:
      while (list)
	{
	  gboolean b;

	  b = gconf_value_get_bool (list->data);
	  dbus_message_iter_append_basic (&array_iter,
					  DBUS_TYPE_BOOLEAN,
					  &b);
	  
	  list = list->next;
	}
      break;
      
    case GCONF_VALUE_SCHEMA:
      while (list)
	{
	  GConfSchema *schema;

	  schema = gconf_value_get_schema (list->data);
	  utils_append_schema (&array_iter, schema);
	  
	  list = list->next;
	}
      break;

    default:
      g_assert_not_reached ();
    }
  
  dbus_message_iter_close_container (&struct_iter, &array_iter);
  dbus_message_iter_close_container (main_iter, &struct_iter);
}
Example #13
0
static gboolean
handle_file (const gchar *filename)
{
  GKeyFile *keyfile;
  GConfClient *client;
  GConfValue *value;
  gint i, j;
  gchar *gconf_key;
  gchar **groups;
  gchar **keys;
  GVariantBuilder *builder;
  GVariant *v;
  const gchar *s;
  gchar *str;
  gint ii;
  GSList *list, *l;
  GSettingsSchemaSource *source;
  GSettingsSchema *schema;
  GSettings *settings;
  GError *error;

  keyfile = g_key_file_new ();

  error = NULL;
  if (!g_key_file_load_from_file (keyfile, filename, 0, &error))
    {
      if (verbose)
        g_printerr ("%s: %s\n", filename, error->message);
      g_error_free (error);

      g_key_file_free (keyfile);

      return FALSE;
    }

  client = get_writable_client ();
  source = g_settings_schema_source_get_default ();

  groups = g_key_file_get_groups (keyfile, NULL);
  for (i = 0; groups[i]; i++)
    {
      gchar **schema_path;

      schema_path = g_strsplit (groups[i], ":", 2);

      schema = g_settings_schema_source_lookup (source, schema_path[0], TRUE);
      if (schema == NULL)
        {
          if (verbose)
            {
              g_print ("Schema '%s' not found, skipping\n", schema_path[0]);
            }

          g_strfreev (schema_path);
          continue;
        }

      g_settings_schema_unref (schema);

      if (verbose)
        {
          g_print ("Collecting settings for schema '%s'\n", schema_path[0]);
          if (schema_path[1])
            g_print ("for storage at '%s'\n", schema_path[1]);
        }

      if (schema_path[1] != NULL)
        settings = g_settings_new_with_path (schema_path[0], schema_path[1]);
      else
        settings = g_settings_new (schema_path[0]);

      g_settings_delay (settings);

      error = NULL;
      if ((keys = g_key_file_get_keys (keyfile, groups[i], NULL, &error)) == NULL)
        {
          g_printerr ("%s", error->message);
          g_error_free (error);

          continue;
        }

      for (j = 0; keys[j]; j++)
        {
          if (strchr (keys[j], '/') != 0)
            {
              g_printerr ("Key '%s' contains a '/'\n", keys[j]);

              continue;
            }

          error = NULL;
          if ((gconf_key = g_key_file_get_string (keyfile, groups[i], keys[j], &error)) ==  NULL)
            {
              g_printerr ("%s", error->message);
              g_error_free (error);

              continue;
            }

          error = NULL;
          if ((value = gconf_client_get_without_default (client, gconf_key, &error)) == NULL)
            {
              if (error)
                {
                  g_printerr ("Failed to get GConf key '%s': %s\n",
                              gconf_key, error->message);
                  g_error_free (error);
                }
              else
                {
                  if (verbose)
                    g_print ("Skipping GConf key '%s', no user value\n",
                             gconf_key);
                }

              g_free (gconf_key);

              continue;
            }

          switch (value->type)
            {
            case GCONF_VALUE_STRING:
              if (dry_run)
                g_print ("Set key '%s' to string '%s'\n", keys[j],
                         gconf_value_get_string (value));
              else
                g_settings_set (settings, keys[j], "s",
                                gconf_value_get_string (value));
              break;

            case GCONF_VALUE_INT:
              if (dry_run)
                g_print ("Set key '%s' to integer '%d'\n",
                         keys[j], gconf_value_get_int (value));
              else
                {
                  GVariant *range;
                  gchar *type;

                  range = g_settings_get_range (settings, keys[j]);
                  g_variant_get (range, "(&sv)", &type, NULL);

                  if (strcmp (type, "enum") == 0)
                    g_settings_set_enum (settings, keys[j], gconf_value_get_int (value));
                  else if (strcmp (type, "flags") == 0)
                    g_settings_set_flags (settings, keys[j], gconf_value_get_int (value));
                  else if (type_uint32 (settings, keys[j]))
                    g_settings_set (settings, keys[j], "u",
                                    gconf_value_get_int (value));
                  else
                    g_settings_set (settings, keys[j], "i",
                                    gconf_value_get_int (value));

                  g_variant_unref (range);
                }
              break;

            case GCONF_VALUE_BOOL:
              if (dry_run)
                g_print ("Set key '%s' to boolean '%d'\n",
                         keys[j], gconf_value_get_bool (value));
              else
                g_settings_set (settings, keys[j], "b",
                                gconf_value_get_bool (value));
              break;

            case GCONF_VALUE_FLOAT:
              if (dry_run)
                g_print ("Set key '%s' to double '%g'\n",
                         keys[j], gconf_value_get_float (value));
              else
                g_settings_set (settings, keys[j], "d",
                                gconf_value_get_float (value));
              break;

            case GCONF_VALUE_LIST:
              switch (gconf_value_get_list_type (value))
                {
                case GCONF_VALUE_STRING:
                  builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
                  list = gconf_value_get_list (value);
                  if (list != NULL)
                    {
                      for (l = list; l; l = l->next)
                        {
                          GConfValue *lv = l->data;
                          s = gconf_value_get_string (lv);
                          g_variant_builder_add (builder, "s", s);
                        }
                      v = g_variant_new ("as", builder);
                    }
                  else
                    v = g_variant_new_array (G_VARIANT_TYPE_STRING, NULL, 0);
                  g_variant_ref_sink (v);

                  if (dry_run)
                    {
                      str = g_variant_print (v, FALSE);
                      g_print ("Set key '%s' to a list of strings: %s\n",
                               keys[j], str);
                      g_free (str);
                    }
                  else
                    g_settings_set_value (settings, keys[j], v);

                  g_variant_unref (v);
                  g_variant_builder_unref (builder);
                  break;

                case GCONF_VALUE_INT:
                  builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
                  list = gconf_value_get_list (value);
                  if (list != NULL)
                    {
                      for (l = list; l; l = l->next)
                        {
                          GConfValue *lv = l->data;
                          ii = gconf_value_get_int (lv);
                          g_variant_builder_add (builder, "i", ii);
                        }
                      v = g_variant_new ("ai", builder);
                    }
                  else
                    v = g_variant_new_array (G_VARIANT_TYPE_INT32, NULL, 0);
                  g_variant_ref_sink (v);

                  if (dry_run)
                    {
                      str = g_variant_print (v, FALSE);
                      g_print ("Set key '%s' to a list of integers: %s\n",
                               keys[j], str);
                      g_free (str);
                    }
                  else
                    g_settings_set_value (settings, keys[j], v);

                  g_variant_unref (v);
                  g_variant_builder_unref (builder);
                  break;

                default:
                  g_printerr ("Keys of type 'list of %s' not handled yet\n",
                              gconf_value_type_to_string (gconf_value_get_list_type (value)));
                  break;
                }
              break;

            default:
              g_printerr ("Keys of type %s not handled yet\n",
                          gconf_value_type_to_string (value->type));
              break;
            }

          gconf_value_free (value);
          g_free (gconf_key);
        }

      g_strfreev (keys);

      if (!dry_run)
        g_settings_apply (settings);

      g_object_unref (settings);
      g_strfreev (schema_path);
    }

  g_strfreev (groups);

  g_object_unref (client);

  return TRUE;
}
Example #14
0
static void
node_set_value(xmlNodePtr node, GConfValue* value)
{
  const gchar* type;
  gchar* value_str;

  g_return_if_fail(node != NULL);
  g_return_if_fail(value != NULL);
  g_return_if_fail(value->type != GCONF_VALUE_INVALID);
  
  type = gconf_value_type_to_string(value->type);

  g_assert(type != NULL);
  
  my_xmlSetProp(node, "type", type);

  switch (value->type)
    {
    case GCONF_VALUE_INT:
    case GCONF_VALUE_FLOAT:
    case GCONF_VALUE_BOOL:
      free_childs(node);
      
      value_str = gconf_value_to_string(value);
  
      my_xmlSetProp(node, "value", value_str);

      g_free(value_str);
      break;
    case GCONF_VALUE_STRING:
      {
        xmlChar* encoded;
        
        free_childs(node);

        encoded = xmlEncodeEntitiesReentrant(node->doc,
                                             (xmlChar *)gconf_value_get_string(value));
        
        xmlNewChild(node, NULL, (xmlChar *)"stringvalue",
                    encoded);
        xmlFree(encoded);
      }
      break;      
    case GCONF_VALUE_SCHEMA:
      {
        node_set_schema_value(node, value);
      }
      break;
    case GCONF_VALUE_LIST:
      {
        GSList* list;

        free_childs(node);

        my_xmlSetProp(node, "ltype",
                      gconf_value_type_to_string(gconf_value_get_list_type(value)));
        
        /* Add a new child for each node */
        list = gconf_value_get_list(value);

        while (list != NULL)
          {
            xmlNodePtr child;
            /* this is O(1) because libxml saves the list tail */
            child = xmlNewChild(node, NULL, (xmlChar *)"li", NULL);

            g_return_if_fail(list->data != NULL);
            
            node_set_value(child, (GConfValue*)list->data);
            
            list = g_slist_next(list);
          }
      }
      break;
      
    case GCONF_VALUE_PAIR:
      {
        xmlNodePtr car, cdr;

        free_childs(node);

        car = xmlNewChild(node, NULL, (xmlChar *)"car", NULL);
        cdr = xmlNewChild(node, NULL, (xmlChar *)"cdr", NULL);

        g_return_if_fail(gconf_value_get_car(value) != NULL);
        g_return_if_fail(gconf_value_get_cdr(value) != NULL);
        
        node_set_value(car, gconf_value_get_car(value));
        node_set_value(cdr, gconf_value_get_cdr(value));
      }
      break;
      
    default:
      g_assert_not_reached();
      break;
    }
}