aboutsummaryrefslogtreecommitdiffstats
path: root/src/day.c
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2018-12-17 10:42:13 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2019-05-22 01:56:59 -0400
commit066df02cbf44d58a9b1e3a30b1310dc0f460e4c4 (patch)
tree6b873c9ceccada341913096186c7c165f46c9ea7 /src/day.c
parent8dd694b56956a1c4ec3519743904222b465e10a5 (diff)
downloadcalcurse-066df02cbf44d58a9b1e3a30b1310dc0f460e4c4.tar.gz
calcurse-066df02cbf44d58a9b1e3a30b1310dc0f460e4c4.zip
Introduce multiple days in the appointments panel
Overview of existing implementation ----------------------------------- The APP panel displays the 'day_items' vector in the 'lb_apt' listbox. A listbox consists of a scrollwin (structure) in which a number of items is displayed. The listbox keeps track of: - the number of items - the selected item - the type of each item in an array type[] - the height of each item (ie. how many screen lines) in an array ch[] - how to display an item (on the screen) The latter three are handled by functions fn_type(), fn_height(), fn_draw(). The first two are used to fill in the corresponding array entry, type[] or ch[], for item number i, the third draws item number i. The items are taken from the global variables vector_t day_items int day_items_nb in day.c. Items include captions (DAY_HEADING, DAY_SEPARATOR). Everything is sorted for display (DAY_HEADING, events, DAY_SEPARATOR, appts). These are filled in ("stored") [by day_store_items() for the selected day in the calendar], before being "loaded" into the listbox. See do_storage() in calcurse.c and ui_day_item_add() in ui-day.c. New APP panel design -------------------- Several days are displayed in the APP panel by loading them with day_store_items(). With several days come several headings and separators. DAY_SEPARATOR is reinterpreted to separate days, and a new separator, EVNT_SEPARATOR, separates events from appointments. To sort everything, an 'order' member of type time_t is added to the day_item structure. It is set for headings and separators as well as for appointments and events as follows: item order --------------------- DAY_HEADING BGNOFDAY (= midnight) EVNT_SEPARATOR BGNOFDAY DAY_SEPARATOR ENDOFDAY event start time (midnight) appointment start time (first day) BGNOFDAY (following days, if any) The sort function day_cmp() (used by vector_sort) is extended to sort by order first. The order field always indicates the day to which an item belongs. This comes in handy, because with several days in the APP panel it is necessary to distinguish between the selected day in the calendar and the selected day in the APP panel. This raises the question which day should actions (commands) operate on: the one selected in the calendar or the one selected in the APP panel? Unquestionably the one on the APP panel which is the one tacitly implied. In most cases it is not a problem, though, because actions work on the selected item and the selected day does not come into play. But in some cases it does: delete item When deleting an occurrence of a repeated item, the selected day is the exception day to add. view item day_popup_item() needs the day of the selected item for display of correct start/end times. cut/paste item Paste needs the selected day in which to paste. add item The day of the new item is taken from the calendar. Instead a dummy event is inserted in an empty day. This makes the day selectable, which is otherwise impossible with only the DAY_HEADING displayed. The dummy event is selectable but cannot be edited or deleted (but viewed or piped). With more than one day in the day_items vecter, an appointment spanning more than one day may occur more than once in the vector (with start/end times suitably adjusted for display). A day_item is no longer (always) identified by the aptev_ptr (item) value. Instead the combination (order, item.<ptr>) is used; order is roughly the day. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src/day.c')
-rw-r--r--src/day.c96
1 files changed, 66 insertions, 30 deletions
diff --git a/src/day.c b/src/day.c
index c4d1cac..e480732 100644
--- a/src/day.c
+++ b/src/day.c
@@ -42,9 +42,15 @@
#include "calcurse.h"
+static unsigned day_nb = 7;
static vector_t day_items;
static unsigned day_items_nb = 0;
+int day_get_nb(void)
+{
+ return day_nb;
+}
+
static void day_free(struct day_item *day)
{
mem_free(day);
@@ -73,6 +79,11 @@ static int day_cmp(struct day_item **pa, struct day_item **pb)
struct day_item *b = *pb;
int a_state, b_state;
+ if (a->order < b->order)
+ return -1;
+ if (a->order > b->order)
+ return 1;
+
if ((a->type == APPT || a->type == RECUR_APPT) &&
(b->type == APPT || b->type == RECUR_APPT)) {
if (a->start < b->start)
@@ -97,11 +108,12 @@ static int day_cmp(struct day_item **pa, struct day_item **pb)
}
/* Add an item to the current day list. */
-static void day_add_item(int type, time_t start, union aptev_ptr item)
+static void day_add_item(int type, time_t start, time_t order, union aptev_ptr item)
{
struct day_item *day = mem_malloc(sizeof(struct day_item));
day->type = type;
day->start = start;
+ day->order = order;
day->item = item;
VECTOR_ADD(&day_items, day);
@@ -208,6 +220,7 @@ void day_item_fork(struct day_item *day_in, struct day_item *day_out)
{
day_out->type = day_in->type;
day_out->start = day_in->start;
+ day_out->order = day_in->order;
switch (day_in->type) {
case APPT:
@@ -245,7 +258,7 @@ static int day_store_events(time_t date)
struct event *ev = LLIST_TS_GET_DATA(i);
p.ev = ev;
- day_add_item(EVNT, ev->day, p);
+ day_add_item(EVNT, ev->day, ev->day, p);
e_nb++;
}
@@ -269,8 +282,11 @@ static int day_store_recur_events(time_t date)
struct recur_event *rev = LLIST_TS_GET_DATA(i);
p.rev = rev;
- day_add_item(RECUR_EVNT, rev->day, p);
- e_nb++;
+ time_t occurrence;
+ if (recur_event_find_occurrence(rev, date, &occurrence)) {
+ day_add_item(RECUR_EVNT, rev->day, occurrence, p);
+ e_nb++;
+ }
}
return e_nb;
@@ -294,11 +310,14 @@ static int day_store_apoints(time_t date)
struct apoint *apt = LLIST_TS_GET_DATA(i);
p.apt = apt;
-
- if (apt->start >= date + DAYLEN(date))
- break;
-
- day_add_item(APPT, apt->start, p);
+ /*
+ * For appointments continuing from the previous day, order is
+ * set to midnight to sort it before appointments of the day.
+ */
+ day_add_item(APPT,
+ apt->start,
+ apt->start < date ? date : apt->start,
+ p);
a_nb++;
}
LLIST_TS_UNLOCK(&alist_p);
@@ -325,9 +344,13 @@ static int day_store_recur_apoints(time_t date)
p.rapt = rapt;
- time_t real_start;
- if (recur_apoint_find_occurrence(rapt, date, &real_start)) {
- day_add_item(RECUR_APPT, real_start, p);
+ time_t occurrence;
+ /* As for appointments */
+ if (recur_apoint_find_occurrence(rapt, date, &occurrence)) {
+ day_add_item(RECUR_APPT,
+ occurrence,
+ occurrence < date ? date : occurrence,
+ p);
a_nb++;
}
}
@@ -337,35 +360,49 @@ static int day_store_recur_apoints(time_t date)
}
/*
- * Store all of the items to be displayed for the selected day.
- * Items are of four types: recursive events, normal events,
+ * Store all of the items to be displayed for the selected day and the following
+ * (n - 1) days. Items are of four types: recursive events, normal events,
* recursive appointments and normal appointments.
- * The items are stored in the linked list pointed by day_items
- * and the length of the new pad to write is returned.
- * The number of events and appointments in the current day are also updated.
+ * The items are stored in the day_items vector; the number of events and
+ * appointments in the vector is stored in day_items_nb,
*/
void
-day_store_items(time_t date, int include_captions)
+day_store_items(time_t date, int include_captions, int n)
{
unsigned apts, events;
- union aptev_ptr p = { NULL };
+ union aptev_ptr p = { NULL }, d;
+ int i;
day_free_vector();
day_init_vector();
- if (include_captions)
- day_add_item(DAY_HEADING, 0, p);
+ for (i = 0; i < n; i++, date = NEXTDAY(date)) {
+ if (include_captions)
+ day_add_item(DAY_HEADING, 0, date, p);
+
+ events = day_store_recur_events(date);
+ events += day_store_events(date);
+ apts = day_store_recur_apoints(date);
+ apts += day_store_apoints(date);
- events = day_store_recur_events(date);
- events += day_store_events(date);
- apts = day_store_recur_apoints(date);
- apts += day_store_apoints(date);
+ if (include_captions && events > 0 && apts > 0)
+ day_add_item(EVNT_SEPARATOR, 0, date, p);
- if (include_captions && events > 0 && apts > 0)
- day_add_item(DAY_SEPARATOR, 0, p);
+ day_items_nb += events + apts;
+
+ if (events == 0 && apts == 0) {
+ /* Insert dummy event. */
+ d.ev = &dummy;
+ dummy.mesg = _("(none)");
+ day_add_item(EVNT, DUMMY, date, d);
+ day_items_nb++;
+ }
+
+ if (include_captions && i < n - 1)
+ day_add_item(DAY_SEPARATOR, 0, ENDOFDAY(date), p);
+ }
VECTOR_SORT(&day_items, day_cmp);
- day_items_nb = events + apts;
}
/*
@@ -473,8 +510,7 @@ void day_popup_item(struct day_item *day)
struct apoint apt_tmp;
apt_tmp.start = day->start;
apt_tmp.dur = day_item_get_duration(day);
- apoint_sec2str(&apt_tmp, get_slctd_day(), a_st, a_end);
-
+ apoint_sec2str(&apt_tmp, ui_day_selday(), a_st, a_end);
item_in_popup(a_st, a_end, day_item_get_mesg(day),
_("Appointment:"));
} else {