From 81017f73686edcfdb61be27996f8001182cc8c98 Mon Sep 17 00:00:00 2001 From: reinelt <> Date: Sun, 11 Jan 2004 18:26:02 +0000 Subject: [lcd4linux @ 2004-01-11 18:26:02 by reinelt] further widget and layout processing --- Makefile.am | 1 + Makefile.in | 20 +++++++++--------- cfg.c | 55 ++++++++--------------------------------------- drv_MatrixOrbital.c | 7 ++++-- layout.c | 14 ++++++------ plugin.c | 7 +++++- plugin_string.c | 8 +++++-- widget.c | 49 ++++++++++++++++++++++++++++++++++++++---- widget.h | 15 +++++++++---- widget_text.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++---- 10 files changed, 158 insertions(+), 79 deletions(-) diff --git a/Makefile.am b/Makefile.am index 25f1164..d143f1c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,6 +22,7 @@ evaluator.c evaluator.h \ plugin.c plugin.h \ plugin_math.c \ plugin_string.c \ +plugin_cfg.c \ plugin_xmms.c \ plugin_i2c_sensors.c \ widget.c widget.h \ diff --git a/Makefile.in b/Makefile.in index 77ce17d..83c17af 100644 --- a/Makefile.in +++ b/Makefile.in @@ -101,7 +101,7 @@ AM_CFLAGS = $(X_CFLAGS) -D_GNU_SOURCE -Wall lcd4linux_LDFLAGS = $(X_LIBS) lcd4linux_LDADD = liblcd4linux.la @DRVLIBS@ -lcd4linux_SOURCES = lcd4linux.c pid.c pid.h parser.c parser.h processor.c processor.h layout.c layout.h evaluator.c evaluator.h plugin.c plugin.h plugin_math.c plugin_string.c plugin_xmms.c plugin_i2c_sensors.c widget.c widget.h widget_text.c widget_text.h system.c system.h isdn.c isdn.h wifi.c wifi.h mail.c mail.h seti.c seti.h battery.c battery.h dvb.c dvb.h filter.c filter.h exec.c exec.h expr.c expr.h mail2.c socket.c socket.h imon.c imon.h +lcd4linux_SOURCES = lcd4linux.c pid.c pid.h parser.c parser.h processor.c processor.h layout.c layout.h evaluator.c evaluator.h plugin.c plugin.h plugin_math.c plugin_string.c plugin_cfg.c plugin_xmms.c plugin_i2c_sensors.c widget.c widget.h widget_text.c widget_text.h system.c system.h isdn.c isdn.h wifi.c wifi.h mail.c mail.h seti.c seti.h battery.c battery.h dvb.c dvb.h filter.c filter.h exec.c exec.h expr.c expr.h mail2.c socket.c socket.h imon.c imon.h liblcd4linux_la_DEPENDENCIES = @DRIVERS@ @@ -139,11 +139,11 @@ PROGRAMS = $(bin_PROGRAMS) lcd4linux_OBJECTS = lcd4linux.$(OBJEXT) pid.$(OBJEXT) parser.$(OBJEXT) \ processor.$(OBJEXT) layout.$(OBJEXT) evaluator.$(OBJEXT) \ plugin.$(OBJEXT) plugin_math.$(OBJEXT) plugin_string.$(OBJEXT) \ -plugin_xmms.$(OBJEXT) plugin_i2c_sensors.$(OBJEXT) widget.$(OBJEXT) \ -widget_text.$(OBJEXT) system.$(OBJEXT) isdn.$(OBJEXT) wifi.$(OBJEXT) \ -mail.$(OBJEXT) seti.$(OBJEXT) battery.$(OBJEXT) dvb.$(OBJEXT) \ -filter.$(OBJEXT) exec.$(OBJEXT) expr.$(OBJEXT) mail2.$(OBJEXT) \ -socket.$(OBJEXT) imon.$(OBJEXT) +plugin_cfg.$(OBJEXT) plugin_xmms.$(OBJEXT) plugin_i2c_sensors.$(OBJEXT) \ +widget.$(OBJEXT) widget_text.$(OBJEXT) system.$(OBJEXT) isdn.$(OBJEXT) \ +wifi.$(OBJEXT) mail.$(OBJEXT) seti.$(OBJEXT) battery.$(OBJEXT) \ +dvb.$(OBJEXT) filter.$(OBJEXT) exec.$(OBJEXT) expr.$(OBJEXT) \ +mail2.$(OBJEXT) socket.$(OBJEXT) imon.$(OBJEXT) lcd4linux_DEPENDENCIES = liblcd4linux.la CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -169,10 +169,10 @@ DEP_FILES = .deps/BeckmannEgle.P .deps/Crystalfontz.P .deps/Cwlinux.P \ .deps/expr.P .deps/filter.P .deps/fontmap.P .deps/icon.P .deps/imon.P \ .deps/isdn.P .deps/layout.P .deps/lcd4linux.P .deps/lock.P .deps/mail.P \ .deps/mail2.P .deps/parport.P .deps/parser.P .deps/pid.P .deps/pixmap.P \ -.deps/plugin.P .deps/plugin_i2c_sensors.P .deps/plugin_math.P \ -.deps/plugin_string.P .deps/plugin_xmms.P .deps/processor.P \ -.deps/seti.P .deps/socket.P .deps/system.P .deps/udelay.P \ -.deps/widget.P .deps/widget_text.P .deps/wifi.P +.deps/plugin.P .deps/plugin_cfg.P .deps/plugin_i2c_sensors.P \ +.deps/plugin_math.P .deps/plugin_string.P .deps/plugin_xmms.P \ +.deps/processor.P .deps/seti.P .deps/socket.P .deps/system.P \ +.deps/udelay.P .deps/widget.P .deps/widget_text.P .deps/wifi.P SOURCES = $(liblcd4linux_la_SOURCES) $(lcd4linux_SOURCES) $(EXTRA_lcd4linux_SOURCES) OBJECTS = $(liblcd4linux_la_OBJECTS) $(lcd4linux_OBJECTS) diff --git a/cfg.c b/cfg.c index c5983d4..7e0becf 100644 --- a/cfg.c +++ b/cfg.c @@ -1,4 +1,4 @@ -/* $Id: cfg.c,v 1.25 2004/01/11 09:26:15 reinelt Exp $^ +/* $Id: cfg.c,v 1.26 2004/01/11 18:26:02 reinelt Exp $^ * * config file stuff * @@ -23,6 +23,9 @@ * * * $Log: cfg.c,v $ + * Revision 1.26 2004/01/11 18:26:02 reinelt + * further widget and layout processing + * * Revision 1.25 2004/01/11 09:26:15 reinelt * layout starts to exist... * @@ -181,7 +184,6 @@ #include "debug.h" #include "cfg.h" -#include "plugin.h" typedef struct { char *key; @@ -396,12 +398,15 @@ char *l4l_cfg_get (char *section, char *key, char *defval) int l4l_cfg_number (char *section, char *key, int defval, int min, int max, int *value) { - char *s, *e; + // start with default value + // in case of an (uncatched) error, you have the + // default value set, which may be handy... + *value=defval; + s=cfg_get(section, key, NULL); if (s==NULL) { - *value=defval; return 0; } @@ -529,12 +534,6 @@ static int cfg_read (char *file) val++; } - // provess 'value' in single-quotes - else if (*val=='\'' && *end=='\'') { - *end='\0'; - val++; - } - // if key is '}', a section has been closed if (strcmp(key, "}")==0) { section_close=1; @@ -613,39 +612,6 @@ static int cfg_read (char *file) } -static void cfg_plugin (RESULT *result, int argc, RESULT *argv[]) -{ - int i, len; - char *value; - char *buffer; - - // calculate key length - len=0; - for (i=0; i + * Copyright 2003,2004 Michael Reinelt + * Copyright 2004 The LCD4Linux Team * * This file is part of LCD4Linux. * @@ -22,6 +23,9 @@ * * * $Log: plugin_string.c,v $ + * Revision 1.2 2004/01/11 18:26:02 reinelt + * further widget and layout processing + * * Revision 1.1 2003/12/19 05:50:34 reinelt * added plugin_math.c and plugin_string.c * diff --git a/widget.c b/widget.c index 301914d..60414fe 100644 --- a/widget.c +++ b/widget.c @@ -1,4 +1,4 @@ -/* $Id: widget.c,v 1.5 2004/01/11 09:26:15 reinelt Exp $ +/* $Id: widget.c,v 1.6 2004/01/11 18:26:02 reinelt Exp $ * * generic widget handling * @@ -21,6 +21,9 @@ * * * $Log: widget.c,v $ + * Revision 1.6 2004/01/11 18:26:02 reinelt + * further widget and layout processing + * * Revision 1.5 2004/01/11 09:26:15 reinelt * layout starts to exist... * @@ -86,12 +89,50 @@ int widget_register (WIDGET_CLASS *widget) } -int widget_add (char *section, char *name) +int widget_add (char *name) { + int i; + char *section; + char *class; + + WIDGET_CLASS *Class; + WIDGET *Widget; + + // prepare config section + // strlen("Widget:")=7 + section=malloc(strlen(name)+8); + strcpy(section, "Widget:"); + strcat(section, name); + + // get widget class + class=cfg_get(section, "class", NULL); + if (class==NULL || *class=='\0') { + error ("error: widget '%s' has no class!", name); + return -1; + } + + // lookup widget class + for (i=0; iname = name; + Widget->class = Class; + if (Class->init!=0) { + Class->init(Widget); + } + return 0; } diff --git a/widget.h b/widget.h index 2ff0c8d..181e20b 100644 --- a/widget.h +++ b/widget.h @@ -1,4 +1,4 @@ -/* $Id: widget.h,v 1.4 2004/01/10 20:22:33 reinelt Exp $ +/* $Id: widget.h,v 1.5 2004/01/11 18:26:02 reinelt Exp $ * * generic widget handling * @@ -23,6 +23,9 @@ * * * $Log: widget.h,v $ + * Revision 1.5 2004/01/11 18:26:02 reinelt + * further widget and layout processing + * * Revision 1.4 2004/01/10 20:22:33 reinelt * added new function 'cfg_list()' (not finished yet) * added layout.c (will replace processor.c someday) @@ -48,20 +51,24 @@ struct WIDGET; // forward declaration + typedef struct WIDGET_CLASS { char *name; int (*init) (struct WIDGET *Self); - int (*update) (struct WIDGET *Self); - int (*render) (struct WIDGET *Self); + int (*update) (struct WIDGET *Self); // Fixme: do we really need this? + int (*draw) (struct WIDGET *Self); int (*quit) (struct WIDGET *Self); } WIDGET_CLASS; + typedef struct WIDGET{ - char *name; + char *name; WIDGET_CLASS *class; + void *data; } WIDGET; + int widget_register (WIDGET_CLASS *widget); diff --git a/widget_text.c b/widget_text.c index 59a122d..c644ce6 100644 --- a/widget_text.c +++ b/widget_text.c @@ -1,4 +1,4 @@ -/* $Id: widget_text.c,v 1.1 2004/01/10 20:22:33 reinelt Exp $ +/* $Id: widget_text.c,v 1.2 2004/01/11 18:26:02 reinelt Exp $ * * simple text widget handling * @@ -21,6 +21,9 @@ * * * $Log: widget_text.c,v $ + * Revision 1.2 2004/01/11 18:26:02 reinelt + * further widget and layout processing + * * Revision 1.1 2004/01/10 20:22:33 reinelt * added new function 'cfg_list()' (not finished yet) * added layout.c (will replace processor.c someday) @@ -48,12 +51,62 @@ #include "widget.h" +typedef struct WIDGET_TEXT { + char *value; + char *align; + int width; + int update; +} WIDGET_TEXT; + + +int widget_text_init (WIDGET *Self) { + + char *section; + WIDGET_TEXT *data; + + debug ("Michi: widget_text_init(%s)", Self->name); + + // prepare config section + // strlen("Widget:")=7 + section=malloc(strlen(Self->name)+8); + strcpy(section, "Widget:"); + strcat(section, Self->name); + + data=malloc(sizeof(WIDGET_TEXT)); + + data->value = cfg_get (section, "value", "''"); + data->align = cfg_get (section, "align", "L"); + + cfg_number (section, "width", 5, 0, 99999, &(data->width)); + cfg_number (section, "update", -1, -1, 99999, &(data->update)); + + free (section); + Self->data=data; + + + return 0; +} + + +int widget_text_quit (WIDGET *Self) { + + if (Self->data) { + free (Self->data); + Self->data=NULL; + } + + return 0; + +} + + + WIDGET_CLASS Widget_Text = { name: "text", - init: NULL, + init: widget_text_init, update: NULL, - render: NULL, - quit: NULL, + draw: NULL, + quit: widget_text_quit, }; -- cgit v1.2.3