Bool writeKeyToVariant (CCSSettingKeyValue key, GVariant **variant)
{
    char               *keyString;

    keyString = ccsKeyBindingToString (&key);
    if (!keyString)
	return FALSE;

    *variant = g_variant_new_string (keyString);
    free (keyString);

    return TRUE;
}
void
ccsIniSetKey (IniDictionary      *dictionary,
	      const char         *section,
	      const char         *entry,
	      CCSSettingKeyValue value)
{
    char *str;

    str = ccsKeyBindingToString (&value);
    if (str)
    {
	setIniString (dictionary, section, entry, str);
	free (str);
    }
}
Beispiel #3
0
static Bool
ccsGNOMEIntegrationBackendKeyValueToStringValue (CCSSettingValue *keyValue,
        CCSSettingValue *stringValue)
{
    char  *newValue;

    newValue = ccsKeyBindingToString (&keyValue->value.asKey);
    if (newValue)
    {
        if (strcmp (newValue, "Disabled") == 0)
        {
            /* Metacity doesn't like "Disabled", it wants "disabled" */
            newValue[0] = 'd';
        }

        stringValue->value.asString = newValue;

        return TRUE;
    }

    return FALSE;
}
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);
}