1
/* $Id: widget_timer.c 1106 2010-02-07 14:03:46Z mzuther $
2
* $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/widget_timer.c $
4
* timer widget handling
6
* Copyright (C) 2006 Michael Reinelt <michael@reinelt.co.at>
7
* Copyright (C) 2006 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2, or (at your option)
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28
* WIDGET_CLASS Widget_Timer
45
#include "timer_group.h"
47
#include "widget_timer.h"
53
void widget_timer_update(void *Self)
55
WIDGET *W = (WIDGET *) Self;
56
WIDGET_TIMER *Timer = W->data;
59
/* evaluate expressions */
60
property_eval(&Timer->update);
61
property_eval(&Timer->active);
63
/* get new update interval */
64
update = P2N(&Timer->update);
68
/* finally, fire it! */
69
active = P2N(&Timer->active);
71
property_eval(&Timer->expression);
74
/* add a new one-shot timer */
75
timer_add_widget(widget_timer_update, Self, update, 1);
80
int widget_timer_init(WIDGET * Self)
85
/* prepare config section */
86
/* strlen("Widget:")=7 */
87
section = malloc(strlen(Self->name) + 8);
88
strcpy(section, "Widget:");
89
strcat(section, Self->name);
91
Timer = malloc(sizeof(WIDGET_TIMER));
92
memset(Timer, 0, sizeof(WIDGET_TIMER));
95
property_load(section, "expression", NULL, &Timer->expression);
96
property_load(section, "update", "100", &Timer->update);
97
property_load(section, "active", "1", &Timer->active);
105
widget_timer_update(Self);
111
int widget_timer_quit(WIDGET * Self)
114
/* do not deallocate child widget! */
115
if (Self->parent == NULL) {
117
WIDGET_TIMER *Timer = Self->data;
118
property_free(&Timer->expression);
119
property_free(&Timer->update);
120
property_free(&Timer->active);
132
int widget_timer_register(void)
136
widget_register(&wc);
141
WIDGET_CLASS Widget_Timer = {
143
.type = WIDGET_TYPE_TIMER,
144
.init = widget_timer_init,
146
.quit = widget_timer_quit,