aboutsummaryrefslogtreecommitdiffstats
path: root/src/day.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/day.c')
-rw-r--r--src/day.c106
1 files changed, 95 insertions, 11 deletions
diff --git a/src/day.c b/src/day.c
index a8ee736..78f4acf 100644
--- a/src/day.c
+++ b/src/day.c
@@ -1,7 +1,7 @@
/*
* Calcurse - text-based organizer
*
- * Copyright (c) 2004-2017 calcurse Development Team <misc@calcurse.org>
+ * Copyright (c) 2004-2023 calcurse Development Team <misc@calcurse.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -58,7 +58,7 @@ static struct day_item sel_data = { 0, 0, 0, {NULL}};
/*
* Save the item to become the selected APP item.
- * Public function used to override the setting in do_storage().
+ * Public function used to override the setting in day_do_storage().
*/
int day_set_sel_data(struct day_item *d)
{
@@ -100,7 +100,7 @@ int day_sel_index(void)
/* If still not found, stay on the same day. */
VECTOR_FOREACH(&day_items, i) {
p = VECTOR_NTH(&day_items, i);
- if (p->order == update_time_in_date(sel_data.order, 0, 0))
+ if (p->order == DAY(sel_data.order))
return i;
}
return -1;
@@ -198,7 +198,8 @@ static void day_add_item(int type, time_t start, time_t order, union aptev_ptr i
/* Get the message of an item. */
char *day_item_get_mesg(struct day_item *day)
{
- switch (day->type) {
+ switch (day->type)
+ {
case APPT:
return day->item.apt->mesg;
case EVNT:
@@ -212,6 +213,15 @@ char *day_item_get_mesg(struct day_item *day)
}
}
+/* Get the display message of an item. */
+char *day_item_get_display_mesg(struct day_item *day)
+{
+ char *msg = day_item_get_mesg(day);
+ if (msg[0] == '\0')
+ return EMPTY_EVENT_DESC_DEFAULT;
+ return msg;
+}
+
/* Get the note attached to an item. */
char *day_item_get_note(struct day_item *day)
{
@@ -360,7 +370,7 @@ static int day_store_recur_events(time_t date)
p.rev = rev;
time_t occurrence;
if (recur_event_find_occurrence(rev, date, &occurrence)) {
- day_add_item(RECUR_EVNT, rev->day, occurrence, p);
+ day_add_item(RECUR_EVNT, occurrence, occurrence, p);
e_nb++;
}
}
@@ -529,7 +539,7 @@ day_display_item(struct day_item *day, WINDOW *win, int incolor, int width,
if (width <= 0)
return;
- char *mesg = day_item_get_mesg(day);
+ char *mesg = day_item_get_display_mesg(day);
ch_recur = (day->type == RECUR_EVNT) ? '*' : ' ';
ch_note = day_item_get_note(day) ? '>' : ' ';
@@ -578,12 +588,66 @@ void day_write_stdout(time_t date, const char *fmt_apt, const char *fmt_rapt,
}
}
+/*
+ * Store events and appointments for a range of days in the day vector -
+ * beginning with the selected day - and load them into the APP listbox. If no
+ * day-change occurs, reset the selected APP item and with it the selected day,
+ * thereby storing and loading the same range of days.
+ */
+void day_do_storage(int day_changed)
+{
+ int pre_sel;
+ /*
+ * Save the selected item before rebuilding the day vector -
+ * unless a preselection is already set.
+ */
+ if(!(pre_sel = day_check_sel_data()))
+ day_set_sel_data(ui_day_get_sel());
+
+ if (!day_changed)
+ ui_day_sel_reset();
+
+ /* The day_items vector. */
+ day_store_items(get_slctd_day(), 1, day_get_days());
+ /* The APP listbox. */
+ ui_day_load_items();
+
+ if (day_changed && !pre_sel)
+ ui_day_sel_reset();
+ else
+ ui_day_find_sel();
+
+ day_set_sel_data(&empty_day);
+}
+
/* Display an item inside a popup window. */
void day_popup_item(struct day_item *day)
{
+ const char *note_heading = _("Note:");
+ size_t note_size = 3500;
+
if (day->type == EVNT || day->type == RECUR_EVNT) {
- item_in_popup(NULL, NULL, day_item_get_mesg(day),
- _("Event:"));
+ if (day_item_get_note(day)) {
+ char note[note_size];
+ char *notepath, *msg;
+ FILE *fp;
+
+ asprintf(&notepath, "%s%s", path_notes, day_item_get_note(day));
+ fp = fopen(notepath, "r");
+ if (fp == NULL) {
+ item_in_popup(NULL, NULL, day_item_get_mesg(day), _("Event:"));
+ return;
+ }
+ note_read_contents(note, note_size, fp);
+ fclose(fp);
+ mem_free(notepath);
+
+ asprintf(&msg, "%s\n\n%s\n%s", day_item_get_display_mesg(day), note_heading, note);
+ item_in_popup(NULL, NULL, msg, _("Event:"));
+ mem_free(msg);
+ } else {
+ item_in_popup(NULL, NULL, day_item_get_display_mesg(day), _("Event:"));
+ }
} else if (day->type == APPT || day->type == RECUR_APPT) {
char a_st[100], a_end[100];
@@ -593,8 +657,28 @@ void day_popup_item(struct day_item *day)
apt_tmp.start = day->start;
apt_tmp.dur = day_item_get_duration(day);
apoint_sec2str(&apt_tmp, ui_day_sel_date(), a_st, a_end);
- item_in_popup(a_st, a_end, day_item_get_mesg(day),
- _("Appointment:"));
+
+ if (day_item_get_note(day)) {
+ char note[note_size];
+ char *notepath, *msg;
+ FILE *fp;
+
+ asprintf(&notepath, "%s%s", path_notes, day_item_get_note(day));
+ fp = fopen(notepath, "r");
+ if (fp == NULL) {
+ item_in_popup(a_st, a_end, day_item_get_mesg(day), _("Appointment:"));
+ return;
+ }
+ note_read_contents(note, note_size, fp);
+ fclose(fp);
+ mem_free(notepath);
+
+ asprintf(&msg, "%s\n\n%s\n%s", day_item_get_display_mesg(day), note_heading, note);
+ item_in_popup(a_st, a_end, msg, _("Appointment:"));
+ mem_free(msg);
+ } else {
+ item_in_popup(a_st, a_end, day_item_get_display_mesg(day), _("Appointment:"));
+ }
} else {
EXIT(_("unknown item type"));
/* NOTREACHED */
@@ -798,7 +882,7 @@ int day_paste_item(struct day_item *p, time_t date)
/* wanted: until = shift + old_until */
if (p->item.rapt->rpt->until &&
overflow_add(
- date - update_time_in_date(p->item.rapt->start, 0, 0),
+ date - DAY(p->item.rapt->start),
p->item.rapt->rpt->until,
&until)
)