~siretart/lcd4linux/debian

« back to all changes in this revision

Viewing changes to widget_timer.c

  • Committer: Reinhard Tartler
  • Date: 2011-04-27 17:24:15 UTC
  • mto: This revision was merged to the branch mainline in revision 750.
  • Revision ID: siretart@tauware.de-20110427172415-6n4aptmvmz0eztvm
Tags: upstream-0.11.0~svn1143
ImportĀ upstreamĀ versionĀ 0.11.0~svn1143

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 $
 
3
 *
 
4
 * timer widget handling
 
5
 *
 
6
 * Copyright (C) 2006 Michael Reinelt <michael@reinelt.co.at>
 
7
 * Copyright (C) 2006 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
 
8
 *
 
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)
 
12
 * any later version.
 
13
 *
 
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.
 
18
 *
 
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.
 
22
 *
 
23
 */
 
24
 
 
25
/*
 
26
 * exported functions:
 
27
 *
 
28
 * WIDGET_CLASS Widget_Timer
 
29
 *   the timer widget
 
30
 *
 
31
 */
 
32
 
 
33
 
 
34
#include "config.h"
 
35
 
 
36
#include <stdlib.h>
 
37
#include <stdio.h>
 
38
#include <string.h>
 
39
#include <ctype.h>
 
40
 
 
41
#include "debug.h"
 
42
#include "cfg.h"
 
43
#include "qprintf.h"
 
44
#include "property.h"
 
45
#include "timer_group.h"
 
46
#include "widget.h"
 
47
#include "widget_timer.h"
 
48
 
 
49
#ifdef WITH_DMALLOC
 
50
#include <dmalloc.h>
 
51
#endif
 
52
 
 
53
void widget_timer_update(void *Self)
 
54
{
 
55
    WIDGET *W = (WIDGET *) Self;
 
56
    WIDGET_TIMER *Timer = W->data;
 
57
    int update, active;
 
58
 
 
59
    /* evaluate expressions */
 
60
    property_eval(&Timer->update);
 
61
    property_eval(&Timer->active);
 
62
 
 
63
    /* get new update interval */
 
64
    update = P2N(&Timer->update);
 
65
    if (update < 10)
 
66
        update = 10;
 
67
 
 
68
    /* finally, fire it! */
 
69
    active = P2N(&Timer->active);
 
70
    if (active > 0) {
 
71
        property_eval(&Timer->expression);
 
72
    }
 
73
 
 
74
    /* add a new one-shot timer */
 
75
    timer_add_widget(widget_timer_update, Self, update, 1);
 
76
}
 
77
 
 
78
 
 
79
 
 
80
int widget_timer_init(WIDGET * Self)
 
81
{
 
82
    char *section;
 
83
    WIDGET_TIMER *Timer;
 
84
 
 
85
    /* prepare config section */
 
86
    /* strlen("Widget:")=7 */
 
87
    section = malloc(strlen(Self->name) + 8);
 
88
    strcpy(section, "Widget:");
 
89
    strcat(section, Self->name);
 
90
 
 
91
    Timer = malloc(sizeof(WIDGET_TIMER));
 
92
    memset(Timer, 0, sizeof(WIDGET_TIMER));
 
93
 
 
94
    /* load properties */
 
95
    property_load(section, "expression", NULL, &Timer->expression);
 
96
    property_load(section, "update", "100", &Timer->update);
 
97
    property_load(section, "active", "1", &Timer->active);
 
98
 
 
99
    free(section);
 
100
    Self->data = Timer;
 
101
    Self->x2 = NOCOORD;
 
102
    Self->y2 = NOCOORD;
 
103
 
 
104
    /* just do it! */
 
105
    widget_timer_update(Self);
 
106
 
 
107
    return 0;
 
108
}
 
109
 
 
110
 
 
111
int widget_timer_quit(WIDGET * Self)
 
112
{
 
113
    if (Self) {
 
114
        /* do not deallocate child widget! */
 
115
        if (Self->parent == NULL) {
 
116
            if (Self->data) {
 
117
                WIDGET_TIMER *Timer = Self->data;
 
118
                property_free(&Timer->expression);
 
119
                property_free(&Timer->update);
 
120
                property_free(&Timer->active);
 
121
                free(Self->data);
 
122
                Self->data = NULL;
 
123
            }
 
124
        }
 
125
    }
 
126
 
 
127
    return 0;
 
128
 
 
129
}
 
130
 
 
131
 
 
132
int widget_timer_register(void)
 
133
{
 
134
    WIDGET_CLASS wc;
 
135
    wc = Widget_Timer;
 
136
    widget_register(&wc);
 
137
    return 0;
 
138
}
 
139
 
 
140
 
 
141
WIDGET_CLASS Widget_Timer = {
 
142
    .name = "timer",
 
143
    .type = WIDGET_TYPE_TIMER,
 
144
    .init = widget_timer_init,
 
145
    .draw = NULL,
 
146
    .quit = widget_timer_quit,
 
147
};