Bool writeColorToVariant (CCSSettingColorValue value, GVariant **variant) { char *colString; colString = ccsColorToString (&value); if (!colString) return FALSE; *variant = g_variant_new_string (colString); free (colString); return TRUE; }
void ccsIniSetColor (IniDictionary *dictionary, const char *section, const char *entry, CCSSettingColorValue value) { char *string; string = ccsColorToString (&value); if (string) { setIniString (dictionary, section, entry, string); free (string); } }
GVariant * writeColorListValue (CCSSettingValueList list) { GVariant *value = NULL; GVariantBuilder *builder = g_variant_builder_new (G_VARIANT_TYPE ("as")); char *item; while (list) { item = ccsColorToString (&list->data->value.asColor); g_variant_builder_add (builder, "s", item); g_free (item); list = list->next; } value = g_variant_new ("as", builder); g_variant_builder_unref (builder); return value; }
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); }