static void initKeyValue (CompDisplay *d, CompOptionValue *v, CompActionState state, xmlDocPtr doc, xmlNodePtr node) { xmlChar *value; memset (&v->action, 0, sizeof (v->action)); v->action.state = state | CompActionStateInitKey; if (!doc) return; value = xmlNodeListGetString (doc, node->xmlChildrenNode, 1); if (value) { char *binding = (char *) value; if (strcasecmp (binding, "disabled") && *binding) stringToKeyAction (d, binding, &v->action); xmlFree (value); } if (state & CompActionStateAutoGrab) { CompScreen *s; for (s = d->screens; s; s = s->next) addScreenAction (s, &v->action); } }
static Bool kconfigStringToValue (CompObject *object, QString str, CompOptionType type, CompOptionValue *value) { switch (type) { case CompOptionTypeBool: value->b = str.toInt () ? TRUE : FALSE; break; case CompOptionTypeFloat: value->f = str.toFloat (); break; case CompOptionTypeString: value->s = strdup (str.ascii ()); if (!value->s) return FALSE; break; case CompOptionTypeColor: if (!stringToColor (str.ascii (), value->c)) return FALSE; break; case CompOptionTypeKey: while (object && object->type != COMP_OBJECT_TYPE_DISPLAY) object = object->parent; if (!object) return FALSE; stringToKeyAction (GET_CORE_DISPLAY (object), str.ascii (), &value->action); break; case CompOptionTypeButton: while (object && object->type != COMP_OBJECT_TYPE_DISPLAY) object = object->parent; if (!object) return FALSE; stringToButtonAction (GET_CORE_DISPLAY (object), str.ascii (), &value->action); break; case CompOptionTypeEdge: value->action.edgeMask = stringToEdgeMask (str.ascii ()); break; case CompOptionTypeBell: value->action.bell = str.toInt () ? TRUE : FALSE; break; case CompOptionTypeMatch: matchInit (&value->match); matchAddFromString (&value->match, str.ascii ()); break; default: return FALSE; } return TRUE; }
static Bool iniLoadOptionsFromFile (FILE *optionFile, CompObject *object, const char *plugin, Bool *reSave) { CompOption *option = NULL, *o; CompPlugin *p = NULL; CompOptionValue value; char *optionName = NULL, *optionValue = NULL; char tmp[MAX_OPTION_LENGTH]; int nOption, nOptionRead = 0; Bool status = FALSE, hasValue = FALSE; if (plugin) { p = findActivePlugin (plugin); if (!p) { compLogMessage ("ini", CompLogLevelWarn, "Could not find running plugin " \ "%s (iniLoadOptionsFromFile)", plugin); return FALSE; } } else { return FALSE; } if (p->vTable->getObjectOptions) option = (*p->vTable->getObjectOptions) (p, object, &nOption); while (fgets (tmp, MAX_OPTION_LENGTH, optionFile) != NULL) { status = FALSE; if (!iniParseLine (tmp, &optionName, &optionValue)) { compLogMessage ("ini", CompLogLevelWarn, "Ignoring line '%s' in %s", tmp, plugin); continue; } if (option) { o = compFindOption (option, nOption, optionName, 0); if (o) { value = o->value; switch (o->type) { case CompOptionTypeBool: hasValue = TRUE; value.b = (Bool) atoi (optionValue); break; case CompOptionTypeInt: hasValue = TRUE; value.i = atoi (optionValue); break; case CompOptionTypeFloat: hasValue = TRUE; value.f = atof (optionValue); break; case CompOptionTypeString: hasValue = TRUE; value.s = strdup (optionValue); break; case CompOptionTypeColor: hasValue = stringToColor (optionValue, value.c); break; case CompOptionTypeKey: hasValue = TRUE; stringToKeyAction (GET_CORE_DISPLAY (object), optionValue, &value.action); break; case CompOptionTypeButton: hasValue = TRUE; stringToButtonAction (GET_CORE_DISPLAY (object), optionValue, &value.action); break; case CompOptionTypeEdge: hasValue = TRUE; value.action.edgeMask = stringToEdgeMask (optionValue); break; case CompOptionTypeBell: hasValue = TRUE; value.action.bell = (Bool) atoi (optionValue); break; case CompOptionTypeList: hasValue = csvToList (GET_CORE_DISPLAY (object), optionValue, &value.list, value.list.type); break; case CompOptionTypeMatch: hasValue = TRUE; matchInit (&value.match); matchAddFromString (&value.match, optionValue); break; default: break; } if (hasValue) { status = (*core.setOptionForPlugin) (object, plugin, optionName, &value); if (o->type == CompOptionTypeMatch) { matchFini (&value.match); } } nOptionRead++; } } /* clear up */ if (optionName) free (optionName); if (optionValue) free (optionValue); } if (nOption != nOptionRead) { *reSave = TRUE; } return TRUE; }
static Bool csvToList (CompDisplay *d, char *csv, CompListValue *list, CompOptionType type) { char *splitStart = NULL; char *splitEnd = NULL; char *item = NULL; int itemLength, count, i; if (csv[0] == '\0') { list->nValue = 0; return FALSE; } int length = strlen (csv); count = 1; for (i = 0; csv[i] != '\0'; i++) if (csv[i] == ',' && i != length-1) count++; splitStart = csv; list->value = malloc (sizeof (CompOptionValue) * count); list->nValue = count; if (list->value) { for (i = 0; i < count; i++) { splitEnd = strchr (splitStart, ','); if (splitEnd) { itemLength = strlen (splitStart) - strlen (splitEnd); item = malloc (sizeof (char) * (itemLength + 1)); if (item) { strncpy (item, splitStart, itemLength); item[itemLength] = 0; } } else // last value { item = strdup (splitStart); } if (!item) { compLogMessage ("ini", CompLogLevelError, "Not enough memory"); list->nValue = 0; return FALSE; } switch (type) { case CompOptionTypeString: list->value[i].s = strdup (item); break; case CompOptionTypeBool: list->value[i].b = item[0] ? (Bool) atoi (item) : FALSE; break; case CompOptionTypeInt: list->value[i].i = item[0] ? atoi (item) : 0; break; case CompOptionTypeFloat: list->value[i].f = item[0] ? atof (item) : 0.0f; break; case CompOptionTypeKey: stringToKeyAction (d, item, &list->value[i].action); break; case CompOptionTypeButton: stringToButtonAction (d, item, &list->value[i].action); break; case CompOptionTypeEdge: list->value[i].action.edgeMask = stringToEdgeMask (item); break; case CompOptionTypeBell: list->value[i].action.bell = (Bool) atoi (item); break; case CompOptionTypeMatch: matchInit (&list->value[i].match); matchAddFromString (&list->value[i].match, item); break; default: break; } splitStart = ++splitEnd; if (item) { free (item); item = NULL; } } } return TRUE; }
static Bool fuseInitValueFromString(CompObject *object, CompOptionValue *value, CompOptionType type, char *str) { switch (type) { case CompOptionTypeBool: value->b = strcmp(str, "true") ? FALSE : TRUE; break; case CompOptionTypeInt: value->i = atoi(str); break; case CompOptionTypeFloat: value->f = strtod(str, NULL); break; case CompOptionTypeString: value->s = strdup(str); break; case CompOptionTypeColor: if (!stringToColor(str, value->c)) return FALSE; break; case CompOptionTypeKey: while (object && object->type != COMP_OBJECT_TYPE_DISPLAY) object = object->parent; if (!object) return FALSE; stringToKeyAction(GET_CORE_DISPLAY(object), str, &value->action); break; case CompOptionTypeButton: while (object && object->type != COMP_OBJECT_TYPE_DISPLAY) object = object->parent; if (!object) return FALSE; stringToButtonAction(GET_CORE_DISPLAY(object), str, &value->action); break; case CompOptionTypeEdge: value->action.edgeMask = stringToEdgeMask(str); break; case CompOptionTypeBell: value->action.bell = strcmp(str, "true") ? FALSE : TRUE; break; case CompOptionTypeMatch: matchInit(&value->match); matchAddFromString(&value->match, str); break; default: return FALSE; } return TRUE; }