From 5f47194b3b5fc16b3fbda04a8d31f0a1c0713330 Mon Sep 17 00:00:00 2001 From: Ambika Eshwar Date: Tue, 6 Oct 2020 02:32:59 -0400 Subject: Implemented rendering of notes in events/appts as well Signed-off-by: Lukas Fleischer --- src/day.c | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'src/day.c') diff --git a/src/day.c b/src/day.c index 2a1e1a8..5bf84c4 100644 --- a/src/day.c +++ b/src/day.c @@ -581,9 +581,27 @@ void day_write_stdout(time_t date, const char *fmt_apt, const char *fmt_rapt, /* 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(¬epath, "%s%s", path_notes, day_item_get_note(day)); + fp = fopen(notepath, "r"); + note_read_contents(note, note_size, fp); + fclose(fp); + mem_free(notepath); + + asprintf(&msg, "%s\n\n%s\n%s", day_item_get_mesg(day), note_heading, note); + item_in_popup(NULL, NULL, msg, _("Event:")); + mem_free(msg); + } else { + item_in_popup(NULL, NULL, day_item_get_mesg(day), _("Event:")); + } } else if (day->type == APPT || day->type == RECUR_APPT) { char a_st[100], a_end[100]; @@ -593,8 +611,24 @@ 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(¬epath, "%s%s", path_notes, day_item_get_note(day)); + fp = fopen(notepath, "r"); + note_read_contents(note, note_size, fp); + fclose(fp); + mem_free(notepath); + + asprintf(&msg, "%s\n\n%s\n%s", day_item_get_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_mesg(day), _("Appointment:")); + } } else { EXIT(_("unknown item type")); /* NOTREACHED */ -- cgit v1.2.3-54-g00ecf