From d0c7529cb9833ede3595051df5599a11fe03be48 Mon Sep 17 00:00:00 2001 From: Reinhard Tartler Date: Thu, 5 Apr 2007 15:25:19 +0200 Subject: import new upstream --- widget_gpo.c | 64 ++++++++++++++++++++++++------------------------------------ 1 file changed, 25 insertions(+), 39 deletions(-) (limited to 'widget_gpo.c') diff --git a/widget_gpo.c b/widget_gpo.c index a53b012..d46f464 100644 --- a/widget_gpo.c +++ b/widget_gpo.c @@ -1,9 +1,10 @@ -/* $Id: widget_gpo.c,v 1.1 2005/12/18 16:18:36 reinelt Exp $ +/* $Id: widget_gpo.c 752 2007-01-20 14:05:38Z michael $ + * $URL: https://ssl.bulix.org/svn/lcd4linux/branches/0.10.1/widget_gpo.c $ * * GPO widget handling * * Copyright (C) 2005 Michael Reinelt - * Copyright (C) 2005 The LCD4Linux Team + * Copyright (C) 2005, 2006, 2007 The LCD4Linux Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,11 +20,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * - * $Log: widget_gpo.c,v $ - * Revision 1.1 2005/12/18 16:18:36 reinelt - * GPO's added again - * */ /* @@ -44,7 +40,7 @@ #include "debug.h" #include "cfg.h" -#include "evaluator.h" +#include "property.h" #include "timer.h" #include "widget.h" #include "widget_gpo.h" @@ -58,24 +54,20 @@ void widget_gpo_update(void *Self) { WIDGET *W = (WIDGET *) Self; WIDGET_GPO *GPO = W->data; - RESULT result = { 0, 0, 0, NULL }; - int val; - - /* evaluate expression */ - val = 0; - if (GPO->tree != NULL) { - Eval(GPO->tree, &result); - val = R2N(&result); - DelResult(&result); - } - GPO->num = W->row; - GPO->val = val; + /* evaluate properties */ + property_eval(&GPO->expression); + property_eval(&GPO->update); /* finally, draw it! */ if (W->class->draw) W->class->draw(W); + /* add a new one-shot timer */ + if (P2N(&GPO->update) > 0) { + timer_add(widget_gpo_update, Self, P2N(&GPO->update), 1); + } + } @@ -93,25 +85,20 @@ int widget_gpo_init(WIDGET * Self) GPO = malloc(sizeof(WIDGET_GPO)); memset(GPO, 0, sizeof(WIDGET_GPO)); - /* get raw expression (we evaluate them ourselves) */ - GPO->expression = cfg_get_raw(section, "expression", NULL); + /* load properties */ + property_load(section, "expression", NULL, &GPO->expression); + property_load(section, "update", "1000", &GPO->update); - /* sanity check */ - if (GPO->expression == NULL || *GPO->expression == '\0') { - error("widget %s has no expression, using '0.0'", Self->name); - GPO->expression = "0"; + /* sanity checks */ + if (!property_valid(&GPO->expression)) { + error("Warning: widget %s has no expression", section); } - /* compile expression */ - Compile(GPO->expression, &GPO->tree); - - /* update interval (msec), default 1 sec */ - cfg_number(section, "update", 1000, 10, -1, &(GPO->update)); - free(section); Self->data = GPO; - timer_add(widget_gpo_update, Self, GPO->update, 0); + /* fire it the first time */ + widget_gpo_update(Self); return 0; } @@ -119,12 +106,11 @@ int widget_gpo_init(WIDGET * Self) int widget_gpo_quit(WIDGET * Self) { - if (Self) { - if (Self->data) { - WIDGET_GPO *GPO = Self->data; - DelTree(GPO->tree); - free(Self->data); - } + if (Self && Self->data) { + WIDGET_GPO *GPO = Self->data; + property_free(&GPO->expression); + property_free(&GPO->update); + free(Self->data); Self->data = NULL; } return 0; -- cgit v1.2.3