unsigned int readEdgeFromVariant (GVariant *gsettingsValue) { const char *value; value = g_variant_get_string (gsettingsValue, NULL); if (value) return ccsStringToEdges (value); return 0; }
Bool ccsIniGetEdge (IniDictionary *dictionary, const char *section, const char *entry, unsigned int *value) { char *retValue; retValue = getIniString (dictionary, section, entry); if (retValue) { *value = ccsStringToEdges (retValue); return TRUE; } else return FALSE; }
Bool ccsIniGetList (IniDictionary *dictionary, const char *section, const char *entry, CCSSettingValueList *value, CCSSetting *parent) { CCSSettingValueList list = NULL; char *valueString, *valueStart, *valString; char *token; int nItems = 1, i = 0, len; valString = getIniString (dictionary, section, entry); if (!valString) return FALSE; if (isEmptyString (valString)) { *value = NULL; return TRUE; } valueString = strdup (valString); valueStart = valueString; /* remove trailing semicolon that we added to be able to differentiate between an empty list and a list with one empty item */ len = strlen (valueString); if (valueString[len - 1] == ';') valueString[len - 1] = 0; token = strchr (valueString, ';'); while (token) { token = strchr (token + 1, ';'); nItems++; } token = strsep (&valueString, ";"); switch (parent->info.forList.listType) { case TypeString: case TypeMatch: { char **array = malloc (nItems * sizeof (char*)); if (!array) break; while (token) { array[i++] = strdup (token); token = strsep (&valueString, ";"); } list = ccsGetValueListFromStringArray (array, nItems, parent); for (i = 0; i < nItems; i++) free (array[i]); free (array); } break; case TypeColor: { CCSSettingColorValue *array; array = malloc (nItems * sizeof (CCSSettingColorValue)); if (!array) break; while (token) { memset (&array[i], 0, sizeof (CCSSettingColorValue)); ccsStringToColor (token, &array[i]); token = strsep (&valueString, ";"); i++; } list = ccsGetValueListFromColorArray (array, nItems, parent); free (array); } break; case TypeBool: { Bool *array = malloc (nItems * sizeof (Bool)); Bool isTrue; if (!array) break; while (token) { isTrue = (token[0] == 'y' || token[0] == 'Y' || token[0] == '1' || token[0] == 't' || token[0] == 'T'); array[i++] = isTrue; token = strsep (&valueString, ";"); } list = ccsGetValueListFromBoolArray (array, nItems, parent); free (array); } break; case TypeInt: { int *array = malloc (nItems * sizeof (int)); if (!array) break; while (token) { array[i++] = strtoul (token, NULL, 10); token = strsep (&valueString, ";"); } list = ccsGetValueListFromIntArray (array, nItems, parent); free (array); } break; case TypeFloat: { float *array = malloc (nItems * sizeof (float)); if (!array) break; while (token) { array[i++] = strtod (token, NULL); token = strsep (&valueString, ";"); } list = ccsGetValueListFromFloatArray (array, nItems, parent); free (array); } break; case TypeKey: { CCSSettingValue *val = NULL; list = NULL; while (token) { val = malloc (sizeof (CCSSettingValue)); if (!val) break; if (ccsStringToKeyBinding (token, &val->value.asKey)) list = ccsSettingValueListAppend (list, val); else free (val); token = strsep (&valueString, ";"); } } break; case TypeButton: { CCSSettingValue *val = NULL; list = NULL; while (token) { val = malloc (sizeof (CCSSettingValue)); if (!val) break; if (ccsStringToButtonBinding (token, &val->value.asButton)) list = ccsSettingValueListAppend (list, val); else free (val); token = strsep (&valueString, ";"); } } break; case TypeEdge: { CCSSettingValue *val = NULL; list = NULL; while (token) { val = malloc (sizeof (CCSSettingValue)); if (!val) break; val->value.asEdge = ccsStringToEdges (token); list = ccsSettingValueListAppend (list, val); token = strsep (&valueString, ";"); } } break; case TypeBell: { CCSSettingValue *val = NULL; list = NULL; Bool isTrue; while (token) { val = malloc (sizeof (CCSSettingValue)); if (!val) break; isTrue = (token[0] == 'y' || token[0] == 'Y' || token[0] == '1' || token[0] == 't' || token[0] == 'T'); val->value.asBell = isTrue; list = ccsSettingValueListAppend (list, val); token = strsep (&valueString, ";"); } } break; default: break; } *value = list; free (valueStart); return TRUE; }