]> Pileus Git - lackey/blob - views/edit.c
Improve event display formatting
[lackey] / views / edit.c
1 /*
2  * Copyright (C) 2013 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 /* Static data */
28 static WINDOW *win;
29
30 /* Helper functions */
31 static const char *timestr(date_t date)
32 {
33         static char buf[64];
34         if (date.year)
35                 sprintf(buf, "%04d-%02d-%02d %02d:%02d",
36                         date.year, date.month+1, date.day+1,
37                         date.hour, date.min);
38         else
39                 sprintf(buf, "[none]");
40         return buf;
41 }
42
43 /* Event editing */
44 static void draw_event(event_t *event)
45 {
46         wmove(win, 0, 0);
47         wprintw(win, "Edit Event\n");
48         wprintw(win, "    Name:        %s\n",  event->name      ?: "[none]");
49         wprintw(win, "    Start Time:  %s\n",  timestr(event->start));
50         wprintw(win, "    End Time:    %s\n",  timestr(event->end));
51         wprintw(win, "    Calendar:    %s\n",  event->cal->name ?: "[none]");
52         wprintw(win, "    Category:    %s\n",  event->cat       ?: "[none]");
53         wprintw(win, "    Location:    %s\n",  event->loc       ?: "[none]");
54         wprintw(win, "    Description: %s\n",  event->desc      ?: "[none]");
55 }
56
57 static int edit_event(event_t *event, int key, mmask_t btn, int row, int col)
58 {
59         return 0;
60 }
61
62 /* Todo editing */
63 static void draw_todo(todo_t *todo)
64 {
65         wmove(win, 0, 0);
66         wprintw(win, "Edit Todo\n");
67         wprintw(win, "    Name:        %s\n",   todo->name      ?: "[none]");
68         wprintw(win, "    Start Time:  %s\n",   timestr(todo->start));
69         wprintw(win, "    Due Date:    %s\n",   timestr(todo->due));
70         wprintw(win, "    Calendar:    %s\n",   todo->cal->name ?: "[none]");
71         wprintw(win, "    Category:    %s\n",   todo->cat       ?: "[none]");
72         wprintw(win, "    Completed:   %d%%\n", todo->status);
73         wprintw(win, "    Description: %s\n",   todo->desc      ?: "[none]");
74 }
75
76 static int edit_todo(todo_t *todo, int key, mmask_t btn, int row, int col)
77 {
78         return 0;
79 }
80
81 /* Edit init */
82 void edit_init(WINDOW *_win)
83 {
84         win = _win;
85 }
86
87 /* Edit init */
88 void edit_size(int rows, int cols)
89 {
90 }
91
92 /* Edit draw */
93 void edit_draw(void)
94 {
95         switch (EDIT) {
96                 case EDIT_CAL:   break;
97                 case EDIT_EVENT: draw_event(EVENT); break;
98                 case EDIT_TODO:  draw_todo(TODO);   break;
99                 default:         break;
100         }
101 }
102
103 /* Edit run */
104 int edit_run(int key, mmask_t btn, int row, int col)
105 {
106         switch (EDIT) {
107                 case EDIT_CAL:   return 1;
108                 case EDIT_EVENT: return edit_event(EVENT, key, btn, row, col);
109                 case EDIT_TODO:  return edit_todo(TODO, key, btn, row, col);
110                 default:         return 0;
111         }
112 }