]> Pileus Git - lackey/blob - cals/dummy.c
250b1de09f252fe0dde87d44c7636b81c2e3c5b4
[lackey] / cals / dummy.c
1 /*
2  * Copyright (C) 2012 Andy Spencer <andy753421@gmail.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <stdlib.h>
19
20 #include "util.h"
21 #include "conf.h"
22 #include "date.h"
23 #include "cal.h"
24
25 /* Test data */
26 static cal_t cal = {
27         .type  = "dummy",
28         .name  = "dummy",
29         .desc  = "dummy calendar",
30 };
31
32 static event_t event = {
33         .cal   = &cal,
34         .start = {2012, OCT, 0, 12, 0},
35         .end   = {2012, OCT, 0, 13, 0},
36         .name  = "dummy event",
37         .desc  = "this event is random and does not exist",
38 };
39
40 static todo_t todo = {
41         .cal     = &cal,
42         .name    = "dummy todo",
43         .desc    = "this todo is random and does not exist",
44         .due     = {2012, OCT, 0, 13, 0},
45         .status  = 50,
46 };
47
48 static int     enable;
49
50 /* Config parser */
51 void dummy_config(const char *group, const char *name, const char *key, const char *value)
52 {
53         if (match(group, "dummy") && match(key, "enable"))
54                 enable = get_bool(value);
55 }
56
57 /* Cal functions */
58 cal_t *dummy_cals(void)
59 {
60         return &cal;
61 }
62
63 /* Event functions */
64 event_t *dummy_events(date_t start, date_t end)
65 {
66         event_t *last = &event;
67         for (int i = 0; i < 8; i++) {
68                 last->next        = new0(event_t);
69                 last->next->cal   = event.cal;
70                 last->next->start = event.start;
71                 last->next->end   = event.end;
72                 last->next->name  = strcopy(event.name);
73                 last->next->desc  = strcopy(event.desc);
74
75                 date_t *s = &last->next->start;
76                 date_t *e = &last->next->end;
77                 add_days(&s->year, &s->month, &s->day, 7*i);
78                 add_days(&e->year, &e->month, &e->day, 7*i);
79
80                 last = last->next;
81                 last->next = NULL;
82         }
83         return enable ? event.next : 0;
84 }
85
86 /* Todo functions */
87 todo_t *dummy_todos(date_t start, date_t end)
88 {
89         todo_t *last = &todo;
90         for (int i = 0; i < 6; i++) {
91                 last->next = new0(event_t);
92                 last->next->cal    = todo.cal;
93                 last->next->name   = strcopy(todo.name);
94                 last->next->desc   = strcopy(todo.desc);
95                 last->next->due    = todo.due;
96                 last->next->status = todo.status;
97                 last = last->next;
98                 last->next = NULL;
99         }
100         return enable ? todo.next : 0;
101 }