]> Pileus Git - lackey/blob - views/settings.c
579e27172da1e668672cf11275b770770a5661c8
[lackey] / views / settings.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 <string.h>
19 #include <ncurses.h>
20
21 #include "util.h"
22 #include "conf.h"
23 #include "date.h"
24 #include "cal.h"
25 #include "view.h"
26
27 /* Constant data */
28 #define PAD "    "
29
30 /* Static data */
31 static WINDOW *win;
32
33 /* Helper functions */
34 static void heading(WINDOW *win, char *label)
35 {
36         wattron(win, A_BOLD);
37         wprintw(win, "%s", label);
38         wattroff(win, A_BOLD);
39 }
40
41 static void checkbox(WINDOW *win, char *label, int *value)
42 {
43         wprintw(win, PAD "[%c] %s", *value?'x':' ', label);
44 }
45
46 /* Settings init */
47 void settings_init(WINDOW *_win)
48 {
49         win = _win;
50 }
51
52 /* Settings init */
53 void settings_size(int rows, int cols)
54 {
55 }
56
57 /* Settings draw */
58 void settings_draw(void)
59 {
60         int wtype = 0, wname = 0;
61
62         /* Figure out cal widths */
63         for (cal_t *cal = CALS; cal; cal = cal->next) {
64                 if (strlen(cal->type) > wtype)
65                         wtype = strlen(cal->type);
66                 if (strlen(cal->name) > wname)
67                         wname = strlen(cal->name);
68         }
69
70         heading(win, "Current Settings\n");
71         checkbox(win, "Compact layout\n", &COMPACT);
72
73         heading(win, "\nLoaded Calendars\n");
74         for (cal_t *cal = CALS; cal; cal = cal->next)
75                 wprintw(win, PAD "%s:%*s \"%s\"%*s - %s\n",
76                         cal->type, wtype-strlen(cal->type), "",
77                         cal->name, wname-strlen(cal->name), "",
78                         cal->desc ?: "(no description)");
79 }
80
81 /* Settings run */
82 int settings_run(int key, mmask_t btn, int row, int col)
83 {
84         return 0;
85 }