Bool writeButtonToVariant (CCSSettingButtonValue button, GVariant **variant)
{
    char                  *buttonString;

    buttonString = ccsButtonBindingToString (&button);
    if (!buttonString)
	return FALSE;

    *variant = g_variant_new_string (buttonString);
    free (buttonString);
    return TRUE;
}
void
ccsIniSetButton (IniDictionary         *dictionary,
		 const char            *section,
		 const char            *entry,
		 CCSSettingButtonValue value)
{
    char *str;

    str = ccsButtonBindingToString (&value);
    if (str)
    {
	setIniString (dictionary, section, entry, str);
	free (str);
    }
}
void
ccsIniSetList (IniDictionary       *dictionary,
	       const char          *section,
	       const char          *entry,
	       CCSSettingValueList value,
	       CCSSettingType      listType)
{
    char         *stringBuffer, *valueString;
    char         valueBuffer[100];
    unsigned int bufferSize = 1024, fill;

    stringBuffer = calloc (1, bufferSize);
    if (!stringBuffer)
	return;

    while (value)
    {
	switch (listType)
	{
	case TypeString:
	    valueString = value->data->value.asString;
	    break;
	case TypeMatch:
	    valueString = value->data->value.asMatch;
	    break;
	case TypeInt:
	    snprintf (valueBuffer, 100, "%d", value->data->value.asInt);
	    valueString = valueBuffer;
	    break;
	case TypeBool:
	    strncpy (valueBuffer,
		     (value->data->value.asBool) ? "true" : "false", 100);
	    valueString = valueBuffer;
	    break;
	case TypeFloat:
	    snprintf (valueBuffer, 100, "%f", value->data->value.asFloat);
	    valueString = valueBuffer;
	    break;
	case TypeColor:
	    valueString = ccsColorToString (&value->data->value.asColor);
	    break;
	case TypeKey:
	    valueString = ccsKeyBindingToString (&value->data->value.asKey);
	    break;
	case TypeButton:
	    valueString =
		ccsButtonBindingToString (&value->data->value.asButton);
	    break;
	case TypeEdge:
	    valueString = ccsEdgesToString (value->data->value.asEdge);
	    break;
	case TypeBell:
    	    strncpy (valueBuffer,
		     (value->data->value.asBell) ? "true" : "false", 100);
	    valueString = valueBuffer;
	    break;
	default:
	    valueString = NULL;
	    break;
	}

	if (!valueString)
	    return;

	fill = strlen (stringBuffer);
	/* the + 1 is the semicolon we're going to add */
	if ((fill + strlen (valueString) + 1) >= bufferSize)
	{
	    /* buffer is too small, make it larger */
	    bufferSize *= 2;
	    stringBuffer = realloc (stringBuffer, bufferSize);
	    if (!stringBuffer)
		return;

	    /* properly NULL terminate it */
	    stringBuffer[fill] = 0;
	}

	/* we made sure that the buffer is large enough before, so
	   there is no need for strncat */
	strcat (stringBuffer, valueString);
	strcat (stringBuffer, ";");

	if (listType == TypeColor  || listType == TypeKey ||
	    listType == TypeButton || listType == TypeEdge)
	{
	    free (valueString);
	}
	
	value = value->next;
    }

    setIniString (dictionary, section, entry, stringBuffer);
    free (stringBuffer);
}