aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2017-08-19 10:23:52 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2017-08-28 07:30:38 +0200
commitd56cc7acfe85119b70f7aac8dfd13ba41ec119e3 (patch)
tree69ea8c6e3e5d67d09bf129f3e50c3f54cb01ce58 /src
parent550a2e937906d7e3c821d7508901eea2dafd9344 (diff)
downloadcalcurse-d56cc7acfe85119b70f7aac8dfd13ba41ec119e3.tar.gz
calcurse-d56cc7acfe85119b70f7aac8dfd13ba41ec119e3.zip
Make heading in appointments panel configurable
Add a new configuration variable format.dayheading to set the format of the date displayed at the top of the event and appointment list. Signed-off-by: Lars Henriksen <LarsHenriksen@get2net.dk> Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src')
-rw-r--r--src/calcurse.h4
-rw-r--r--src/config.c1
-rw-r--r--src/custom.c20
-rw-r--r--src/ui-day.c21
-rw-r--r--src/vars.c1
5 files changed, 40 insertions, 7 deletions
diff --git a/src/calcurse.h b/src/calcurse.h
index 4ddb066..392e93e 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -264,6 +264,7 @@ struct conf {
const char *mergetool;
char output_datefmt[BUFSIZ]; /* format for displaying date */
int input_datefmt; /* format for reading date */
+ char day_heading[BUFSIZ]; /* format for displaying heading in appts panel */
};
/* Daemon-related configuration. */
@@ -291,6 +292,9 @@ enum datefmt {
_("mm/dd/yyyy") : (datefmt == DATEFMT_DDMMYYYY ? _("dd/mm/yyyy") : \
(datefmt == DATEFMT_YYYYMMDD ? _("yyyy/mm/dd") : _("yyyy-mm-dd"))))
+/* Day heading default format. */
+#define DAY_HEADING_DEFAULT "%B %-d, %Y"
+
struct date {
unsigned dd;
unsigned mm;
diff --git a/src/config.c b/src/config.c
index 3f073f3..896b192 100644
--- a/src/config.c
+++ b/src/config.c
@@ -102,6 +102,7 @@ static const struct confvar confmap[] = {
{"format.notifydate", CONFIG_HANDLER_STR(nbar.datefmt)},
{"format.notifytime", CONFIG_HANDLER_STR(nbar.timefmt)},
{"format.outputdate", config_parse_output_datefmt, config_serialize_output_datefmt, NULL},
+ {"format.dayheading", CONFIG_HANDLER_STR(conf.day_heading)},
{"general.autogc", CONFIG_HANDLER_BOOL(conf.auto_gc)},
{"general.autosave", CONFIG_HANDLER_BOOL(conf.auto_save)},
{"general.confirmdelete", CONFIG_HANDLER_BOOL(conf.confirm_delete)},
diff --git a/src/custom.c b/src/custom.c
index 20311b6..fd99e25 100644
--- a/src/custom.c
+++ b/src/custom.c
@@ -531,6 +531,7 @@ enum {
FIRST_DAY_OF_WEEK,
OUTPUT_DATE_FMT,
INPUT_DATE_FMT,
+ DAY_HEADING_FMT,
NB_OPTIONS
};
@@ -550,7 +551,8 @@ static void print_general_option(int i, WINDOW *win, int y, int hilt, void *cb_d
"general.progressbar = ",
"general.firstdayofweek = ",
"format.outputdate = ",
- "format.inputdate = "
+ "format.inputdate = ",
+ "format.dayheading = "
};
const char *panel;
@@ -654,6 +656,14 @@ static void print_general_option(int i, WINDOW *win, int y, int hilt, void *cb_d
datefmt_str[0], datefmt_str[1], datefmt_str[2],
datefmt_str[3]);
break;
+ case DAY_HEADING_FMT:
+ custom_apply_attr(win, ATTR_HIGHEST);
+ mvwaddstr(win, y, XPOS + strlen(opt[DAY_HEADING_FMT]),
+ conf.day_heading);
+ custom_remove_attr(win, ATTR_HIGHEST);
+ mvwaddstr(win, y + 1, XPOS,
+ _("(Format of the date displayed in the appointments panel)"));
+ break;
}
if (hilt)
@@ -752,6 +762,14 @@ static void general_option_edit(int i)
if (val != -1)
conf.input_datefmt = val;
break;
+ case DAY_HEADING_FMT:
+ status_mesg(output_datefmt_str, "");
+ strcpy(buf, conf.day_heading);
+ if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
+ strcpy(conf.day_heading, buf);
+ }
+ status_mesg(number_str, keys);
+ break;
}
mem_free(buf);
diff --git a/src/ui-day.c b/src/ui-day.c
index 24717dc..ab588fd 100644
--- a/src/ui-day.c
+++ b/src/ui-day.c
@@ -909,6 +909,17 @@ void ui_day_sel_move(int delta)
listbox_sel_move(&lb_apt, delta);
}
+static char *fmt_day_heading(time_t date)
+{
+ struct tm tm;
+ struct string s;
+
+ localtime_r(&date, &tm);
+ string_printf(&s, "%s ", ui_calendar_get_pom(date));
+ string_catftime(&s, conf.day_heading, &tm);
+ return string_buf(&s);
+}
+
/* Display appointments in the corresponding panel. */
void ui_day_draw(int n, WINDOW *win, int y, int hilt, void *cb_data)
{
@@ -918,20 +929,18 @@ void ui_day_draw(int n, WINDOW *win, int y, int hilt, void *cb_data)
int width = lb_apt.sw.w - 2;
hilt = hilt && (wins_slctd() == APP);
-
if (item->type == EVNT || item->type == RECUR_EVNT) {
day_display_item(item, win, !hilt, width - 1, y, 1);
} else if (item->type == APPT || item->type == RECUR_APPT) {
day_display_item_date(item, win, !hilt, date, y, 1);
day_display_item(item, win, !hilt, width - 1, y + 1, 1);
} else if (item->type == DAY_HEADING) {
- unsigned x = width - (strlen(_(monthnames[slctd_date.mm - 1])) + 15);
+ char *buf = fmt_day_heading(date);
+ utf8_chop(buf, width);
custom_apply_attr(win, ATTR_HIGHEST);
- mvwprintw(win, y, x, "%s %s %02d, %04d",
- ui_calendar_get_pom(date),
- _(monthnames[slctd_date.mm - 1]), slctd_date.dd,
- slctd_date.yyyy);
+ mvwprintw(win, y, width - utf8_strwidth(buf) - 1, "%s", buf);
custom_remove_attr(win, ATTR_HIGHEST);
+ mem_free(buf);
} else if (item->type == DAY_SEPARATOR) {
wmove(win, y, 0);
whline(win, 0, width);
diff --git a/src/vars.c b/src/vars.c
index 5a1fcd6..d236805 100644
--- a/src/vars.c
+++ b/src/vars.c
@@ -147,6 +147,7 @@ void vars_init(void)
conf.progress_bar = 1;
strncpy(conf.output_datefmt, "%D", 3);
conf.input_datefmt = 1;
+ strcpy(conf.day_heading, DAY_HEADING_DEFAULT);
datefmt_str[0] = _("mm/dd/yyyy");
datefmt_str[1] = _("dd/mm/yyyy");