int widget_timer_init(WIDGET * Self) { char *section; WIDGET_TIMER *Timer; /* prepare config section */ /* strlen("Widget:")=7 */ section = malloc(strlen(Self->name) + 8); strcpy(section, "Widget:"); strcat(section, Self->name); Timer = malloc(sizeof(WIDGET_TIMER)); memset(Timer, 0, sizeof(WIDGET_TIMER)); /* load properties */ property_load(section, "expression", NULL, &Timer->expression); property_load(section, "update", "100", &Timer->update); property_load(section, "active", "1", &Timer->active); free(section); Self->data = Timer; Self->x2 = NOCOORD; Self->y2 = NOCOORD; /* just do it! */ widget_timer_update(Self); return 0; }
int widget_keypad_init(WIDGET * Self) { char *section; char *c; WIDGET_KEYPAD *keypad; /* prepare config section */ /* strlen("Widget:")=7 */ section = malloc(strlen(Self->name) + 8); strcpy(section, "Widget:"); strcat(section, Self->name); keypad = malloc(sizeof(WIDGET_KEYPAD)); memset(keypad, 0, sizeof(WIDGET_KEYPAD)); /* load properties */ property_load(section, "expression", NULL, &keypad->expression); /* state: pressed (default), released */ c = cfg_get(section, "state", "pressed"); if (!strcasecmp(c, "released")) keypad->key = WIDGET_KEY_RELEASED; else keypad->key = WIDGET_KEY_PRESSED; /* position: confirm (default), up, down, left, right, cancel */ c = cfg_get(section, "position", "confirm"); if (!strcasecmp(c, "up")) keypad->key += WIDGET_KEY_UP; else if (!strcasecmp(c, "down")) keypad->key += WIDGET_KEY_DOWN; else if (!strcasecmp(c, "left")) keypad->key += WIDGET_KEY_LEFT; else if (!strcasecmp(c, "right")) keypad->key += WIDGET_KEY_RIGHT; else if (!strcasecmp(c, "cancel")) keypad->key += WIDGET_KEY_CANCEL; else keypad->key += WIDGET_KEY_CONFIRM; free(section); Self->data = keypad; Self->x2 = NOCOORD; Self->y2 = NOCOORD; return 0; }