#include <stdio.h>
#include <stdlib.h>
#include <wordexp.h>
+#include <ncurses.h>
#include <libical/ical.h>
#include "util.h"
#include "conf.h"
#include "date.h"
#include "cal.h"
+#include "form.h"
/* Local types */
typedef struct {
/* Static data */
static ical_t *calendars;
+/* Form fields */
+static form_text_t ff_name = TEXT('t');
+static form_text_t ff_desc = TEXT('d');
+static form_text_t ff_loc = TEXT('o');
+static form_list_t ff_cat = LIST('g');
+static form_date_t ff_start = DATE('s');
+static form_date_t ff_end = DATE('e');
+static form_number_t ff_status = NUMBER('p', .f.after="%");
+static form_date_t ff_due = DATE('u');
+static form_list_t ff_cal = LIST('c');
+static form_list_t ff_recur = LIST('r');
+static form_number_t ff_freq = NUMBER(0);
+static form_button_t ff_wdays = BUTTONS("Su Mo Tu We Th Fr Sa");
+
+/* Edit event form */
+static form_t form_cal = { 1, 2, {
+ { LABEL("_Title: "), &ff_name.f },
+} };
+
+/* Edit event form */
+static form_t form_event = { 11, 4, {
+ { LABEL("_Title: "), &ff_name.f },
+ { LABEL("L_ocation: "), &ff_loc.f },
+ { },
+ { LABEL("_Start: "), &ff_start.f, LABEL(" _End: "), &ff_end.f },
+ { LABEL("_Calendar: "), &ff_cal.f, LABEL(" Cate_gory: "), &ff_cat.f },
+ { },
+ { LABEL("_Repeat: "), &ff_recur.f, LABEL(" Every: "), &ff_freq.f },
+ { },
+ { NULL, &ff_wdays.f },
+ { },
+ { LABEL("_Details: "), &ff_desc.f },
+} };
+
+/* Edit todo form */
+static form_t form_todo = { 11, 4, {
+ { LABEL("_Title: "), &ff_name.f },
+ { LABEL("Com_pleted: "), &ff_status.f },
+ { },
+ { LABEL("_Start: "), &ff_start.f, LABEL(" D_ue Date: "), &ff_due.f },
+ { LABEL("_Calendar: "), &ff_cal.f, LABEL(" Cate_gory: "), &ff_cat.f },
+ { },
+ { LABEL("_Repeat: "), &ff_recur.f, LABEL(" Every: "), &ff_freq.f },
+ { },
+ { NULL, &ff_wdays.f },
+ { },
+ { LABEL("_Details: "), &ff_desc.f },
+} };
+
/* Helper functions */
static int ical_compare(const void *_a, const void *_b)
{
/* Edit functions */
void ical_edit(edit_t mode)
{
+ switch (mode) {
+ case EDIT_NONE:
+ break;
+ case EDIT_CAL:
+ //load_username();
+ //load_password();
+ form_show(&form_cal);
+ break;
+ case EDIT_EVENT:
+ ff_name.text = strcopy(EVENT->name);
+ ff_desc.text = strcopy(EVENT->desc);
+ ff_loc.text = strcopy(EVENT->loc);
+ //ff_cat.text = strcopy(EVENT->cat);
+ ff_start.date = EVENT->start;
+ ff_end.date = EVENT->end;
+ //ff_recur.text = strcopy(EVENT->recur);
+ debug("ical_edit - event");
+ form_show(&form_event);
+ break;
+ case EDIT_TODO:
+ ff_name.text = strcopy(TODO->name);
+ ff_desc.text = strcopy(TODO->desc);
+ ff_status.number = TODO->status;
+ //ff_cat.text = strcopy(TODO->cat);
+ ff_start.date = TODO->start;
+ ff_due.date = TODO->due;
+ //ff_recur.text = strcopy(TODO->recur);
+ debug("ical_edit - todo");
+ form_show(&form_todo);
+ break;
+ }
}
void ical_save(edit_t mode)
{
+ //if (isevent || istodo) {
+ // //save_title();
+ // //save_location();
+ // //save_recur();
+ // //save_details();
+ //}
+ //if (isevent) {
+ // //save_start();
+ // //save_end();
+ //}
+ //if (istodo) {
+ // //save_due();
+ // //save_completed();
+ //}
+ //if (iscal) {
+ // //save_username();
+ // //save_password();
+ //}
}
/* Test functions */
#include "date.h"
#include "cal.h"
#include "view.h"
+#include "form.h"
/* Static data */
static WINDOW *win;
-/* Helper functions */
-static const char *timestr(date_t date)
-{
- static char buf[64];
- if (date.year)
- sprintf(buf, "%04d-%02d-%02d %02d:%02d",
- date.year, date.month+1, date.day+1,
- date.hour, date.min);
- else
- sprintf(buf, "[none]");
- return buf;
-}
-
-/* Event editing */
-static void draw_event(event_t *event)
-{
- wmove(win, 0, 0);
- wprintw(win, "Edit Event\n");
- wprintw(win, " Name: %s\n", event->name ?: "[none]");
- wprintw(win, " Start Time: %s\n", timestr(event->start));
- wprintw(win, " End Time: %s\n", timestr(event->end));
- wprintw(win, " Calendar: %s\n", event->cal->name ?: "[none]");
- wprintw(win, " Category: %s\n", event->cat ?: "[none]");
- wprintw(win, " Location: %s\n", event->loc ?: "[none]");
- wprintw(win, " Description: %s\n", event->desc ?: "[none]");
-}
-
-static int edit_event(event_t *event, int key, mmask_t btn, int row, int col)
-{
- return 0;
-}
-
-/* Todo editing */
-static void draw_todo(todo_t *todo)
-{
- wmove(win, 0, 0);
- wprintw(win, "Edit Todo\n");
- wprintw(win, " Name: %s\n", todo->name ?: "[none]");
- wprintw(win, " Start Time: %s\n", timestr(todo->start));
- wprintw(win, " Due Date: %s\n", timestr(todo->due));
- wprintw(win, " Calendar: %s\n", todo->cal->name ?: "[none]");
- wprintw(win, " Category: %s\n", todo->cat ?: "[none]");
- wprintw(win, " Completed: %d%%\n", todo->status);
- wprintw(win, " Description: %s\n", todo->desc ?: "[none]");
-}
-
-static int edit_todo(todo_t *todo, int key, mmask_t btn, int row, int col)
-{
- return 0;
-}
-
/* Edit init */
void edit_init(WINDOW *_win)
{
/* Edit draw */
void edit_draw(void)
{
- switch (EDIT) {
- case EDIT_CAL: break;
- case EDIT_EVENT: draw_event(EVENT); break;
- case EDIT_TODO: draw_todo(TODO); break;
- default: break;
- }
+ form_draw(win);
}
/* Edit run */
int edit_run(int key, mmask_t btn, int row, int col)
{
- switch (EDIT) {
- case EDIT_CAL: return 1;
- case EDIT_EVENT: return edit_event(EVENT, key, btn, row, col);
- case EDIT_TODO: return edit_todo(TODO, key, btn, row, col);
- default: return 0;
- }
+ return form_run(key, btn, row, col);
}