'!' command added, to switch appointment notification state
init_notify_bar(), config_notify_bar() and print_notify_options() modified to add the notification command option. load_conf() updated to load notification command
This commit is contained in:
parent
4d5922e174
commit
9f2a831dd4
188
src/calcurse.c
188
src/calcurse.c
@ -1,4 +1,4 @@
|
|||||||
/* $calcurse: calcurse.c,v 1.34 2007/01/16 07:49:54 culot Exp $ */
|
/* $calcurse: calcurse.c,v 1.35 2007/02/24 17:32:55 culot Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calcurse - text-based organizer
|
* Calcurse - text-based organizer
|
||||||
@ -109,7 +109,8 @@ void store_day(int year, int month, int day, bool day_changed);
|
|||||||
void get_screen_config(void);
|
void get_screen_config(void);
|
||||||
void update_windows(int surrounded_window);
|
void update_windows(int surrounded_window);
|
||||||
void general_config(void), config_notify_bar(void);
|
void general_config(void), config_notify_bar(void);
|
||||||
void print_general_options(WINDOW *win), print_notify_options(WINDOW *win);
|
void print_general_options(WINDOW *win);
|
||||||
|
void print_notify_options(WINDOW *win, int col);
|
||||||
void print_option_incolor(WINDOW *win, bool option, int pos_x, int pos_y);
|
void print_option_incolor(WINDOW *win, bool option, int pos_x, int pos_y);
|
||||||
void del_item(void);
|
void del_item(void);
|
||||||
|
|
||||||
@ -366,6 +367,13 @@ int main(int argc, char **argv)
|
|||||||
do_storage = true;
|
do_storage = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case '!':
|
||||||
|
if (which_pan == APPOINTMENT && hilt_app != 0)
|
||||||
|
apoint_switch_notify(sel_year, sel_month,
|
||||||
|
sel_day, hilt_app);
|
||||||
|
do_storage = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case '+':
|
case '+':
|
||||||
case '-':
|
case '-':
|
||||||
if (which_pan == TODO && hilt_tod != 0) {
|
if (which_pan == TODO && hilt_tod != 0) {
|
||||||
@ -587,15 +595,15 @@ void init_notify_bar(void)
|
|||||||
{
|
{
|
||||||
char *time_format = "%T";
|
char *time_format = "%T";
|
||||||
char *date_format = "%a %F";
|
char *date_format = "%a %F";
|
||||||
|
char *cmd = "calcurse --next | mail name@domain.com";
|
||||||
|
|
||||||
nbar = (struct nbar_s *) malloc(sizeof(struct nbar_s));
|
nbar = (struct nbar_s *) malloc(sizeof(struct nbar_s));
|
||||||
nbar->datefmt = (char *) malloc(sizeof(char));
|
|
||||||
nbar->timefmt = (char *) malloc(sizeof(char));
|
|
||||||
pthread_mutex_init(&nbar->mutex, NULL);
|
pthread_mutex_init(&nbar->mutex, NULL);
|
||||||
nbar->show = 1;
|
nbar->show = 1;
|
||||||
nbar->cntdwn = 300;
|
nbar->cntdwn = 300;
|
||||||
strncpy(nbar->datefmt, date_format, strlen(date_format) + 1);
|
strncpy(nbar->datefmt, date_format, strlen(date_format) + 1);
|
||||||
strncpy(nbar->timefmt, time_format, strlen(time_format) + 1);
|
strncpy(nbar->timefmt, time_format, strlen(time_format) + 1);
|
||||||
|
strncpy(nbar->cmd, cmd, strlen(cmd) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -804,33 +812,38 @@ void general_config(void)
|
|||||||
delwin(conf_win);
|
delwin(conf_win);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Configuration for the notify-bar */
|
/* Notify-bar configuration. */
|
||||||
void config_notify_bar(void)
|
void
|
||||||
|
config_notify_bar(void)
|
||||||
{
|
{
|
||||||
WINDOW *conf_win;
|
WINDOW *conf_win;
|
||||||
char label[MAX_LENGTH];
|
char label[MAX_LENGTH];
|
||||||
char buf[MAX_LENGTH];
|
char *buf;
|
||||||
char *number_str = _("Enter an option number to change its value [Q to quit] ");
|
char *number_str =
|
||||||
|
_("Enter an option number to change its value [Q to quit] ");
|
||||||
char *date_str =
|
char *date_str =
|
||||||
_("Enter the date format (see 'man 3 strftime' for possible formats) ");
|
_("Enter the date format (see 'man 3 strftime' for possible formats) ");
|
||||||
char *time_str =
|
char *time_str =
|
||||||
_("Enter the time format (see 'man 3 strftime' for possible formats) ");
|
_("Enter the time format (see 'man 3 strftime' for possible formats) ");
|
||||||
char *count_str =
|
char *count_str =
|
||||||
_("Enter the number of seconds (0 not to be warned before an appointment)");
|
_("Enter the number of seconds (0 not to be warned before an appointment)");
|
||||||
|
char *cmd_str = _("Enter the notification command ");
|
||||||
int ch = 0 , win_row, change_win = 1;
|
int ch = 0 , win_row, change_win = 1;
|
||||||
|
|
||||||
|
buf = (char *)malloc(MAX_LENGTH);
|
||||||
win_row = (notify_bar()) ? row - 3 : row - 2;
|
win_row = (notify_bar()) ? row - 3 : row - 2;
|
||||||
snprintf(label, MAX_LENGTH, _("CalCurse %s | notify-bar options"), VERSION);
|
snprintf(label, MAX_LENGTH,
|
||||||
|
_("CalCurse %s | notify-bar options"), VERSION);
|
||||||
|
|
||||||
while (ch != 'q') {
|
while (ch != 'q') {
|
||||||
if (change_win) {
|
if (change_win) {
|
||||||
clear();
|
|
||||||
conf_win = newwin(win_row, col, 0, 0);
|
conf_win = newwin(win_row, col, 0, 0);
|
||||||
box(conf_win, 0, 0);
|
box(conf_win, 0, 0);
|
||||||
win_show(conf_win, label);
|
win_show(conf_win, label);
|
||||||
}
|
}
|
||||||
status_mesg(number_str, "");
|
status_mesg(number_str, "");
|
||||||
print_notify_options(conf_win);
|
print_notify_options(conf_win, col);
|
||||||
buf[0] = '\0';
|
*buf = '\0';
|
||||||
ch = wgetch(swin);
|
ch = wgetch(swin);
|
||||||
|
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
@ -850,8 +863,10 @@ void config_notify_bar(void)
|
|||||||
break;
|
break;
|
||||||
case '2':
|
case '2':
|
||||||
status_mesg(date_str, "");
|
status_mesg(date_str, "");
|
||||||
if (getstring(swin, colr, buf, MAX_LENGTH, 0, 1) ==
|
pthread_mutex_lock(&nbar->mutex);
|
||||||
GETSTRING_VALID) {
|
strncpy(buf, nbar->datefmt, strlen(nbar->datefmt) + 1);
|
||||||
|
pthread_mutex_unlock(&nbar->mutex);
|
||||||
|
if (updatestring(swin, colr, &buf, 0, 1) == 0) {
|
||||||
pthread_mutex_lock(&nbar->mutex);
|
pthread_mutex_lock(&nbar->mutex);
|
||||||
strncpy(nbar->datefmt, buf, strlen(buf) + 1);
|
strncpy(nbar->datefmt, buf, strlen(buf) + 1);
|
||||||
pthread_mutex_unlock(&nbar->mutex);
|
pthread_mutex_unlock(&nbar->mutex);
|
||||||
@ -860,8 +875,10 @@ void config_notify_bar(void)
|
|||||||
break;
|
break;
|
||||||
case '3':
|
case '3':
|
||||||
status_mesg(time_str, "");
|
status_mesg(time_str, "");
|
||||||
if (getstring(swin, colr, buf, MAX_LENGTH, 0, 1) ==
|
pthread_mutex_lock(&nbar->mutex);
|
||||||
GETSTRING_VALID) {
|
strncpy(buf, nbar->timefmt, strlen(nbar->timefmt) + 1);
|
||||||
|
pthread_mutex_unlock(&nbar->mutex);
|
||||||
|
if (updatestring(swin, colr, &buf, 0, 1) == 0) {
|
||||||
pthread_mutex_lock(&nbar->mutex);
|
pthread_mutex_lock(&nbar->mutex);
|
||||||
strncpy(nbar->timefmt, buf, strlen(buf) + 1);
|
strncpy(nbar->timefmt, buf, strlen(buf) + 1);
|
||||||
pthread_mutex_unlock(&nbar->mutex);
|
pthread_mutex_unlock(&nbar->mutex);
|
||||||
@ -870,8 +887,11 @@ void config_notify_bar(void)
|
|||||||
break;
|
break;
|
||||||
case '4':
|
case '4':
|
||||||
status_mesg(count_str, "");
|
status_mesg(count_str, "");
|
||||||
if (getstring(swin, colr, buf, MAX_LENGTH, 0, 1) ==
|
pthread_mutex_lock(&nbar->mutex);
|
||||||
GETSTRING_VALID && is_all_digit(buf) &&
|
printf(buf, "%d", nbar->cntdwn);
|
||||||
|
pthread_mutex_unlock(&nbar->mutex);
|
||||||
|
if (updatestring(swin, colr, &buf, 0, 1) == 0 &&
|
||||||
|
is_all_digit(buf) &&
|
||||||
atoi(buf) >= 0 && atoi(buf) <= DAYINSEC) {
|
atoi(buf) >= 0 && atoi(buf) <= DAYINSEC) {
|
||||||
pthread_mutex_lock(&nbar->mutex);
|
pthread_mutex_lock(&nbar->mutex);
|
||||||
nbar->cntdwn = atoi(buf);
|
nbar->cntdwn = atoi(buf);
|
||||||
@ -879,8 +899,21 @@ void config_notify_bar(void)
|
|||||||
}
|
}
|
||||||
change_win = 0;
|
change_win = 0;
|
||||||
break;
|
break;
|
||||||
|
case '5':
|
||||||
|
status_mesg(cmd_str, "");
|
||||||
|
pthread_mutex_lock(&nbar->mutex);
|
||||||
|
strncpy(buf, nbar->cmd, strlen(nbar->cmd) + 1);
|
||||||
|
pthread_mutex_unlock(&nbar->mutex);
|
||||||
|
if (updatestring(swin, colr, &buf, 0, 1) == 0) {
|
||||||
|
pthread_mutex_lock(&nbar->mutex);
|
||||||
|
strncpy(nbar->cmd, buf, strlen(buf) + 1);
|
||||||
|
pthread_mutex_unlock(&nbar->mutex);
|
||||||
|
}
|
||||||
|
change_win = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
free(buf);
|
||||||
delwin(conf_win);
|
delwin(conf_win);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -939,45 +972,74 @@ void print_general_options(WINDOW *win)
|
|||||||
doupdate();
|
doupdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* prints options related to the notify-bar */
|
/* Print options related to the notify-bar. */
|
||||||
void print_notify_options(WINDOW *win)
|
void
|
||||||
|
print_notify_options(WINDOW *win, int col)
|
||||||
{
|
{
|
||||||
int x_pos, y_pos;
|
enum {SHOW, DATE, CLOCK, WARN, CMD, NB_OPT};
|
||||||
char *option1 = _("notify-bar_show = ");
|
|
||||||
char *option2 = _("notify-bar_date = ");
|
struct opt_s {
|
||||||
char *option3 = _("notify-bar_clock = ");
|
char name[MAX_LENGTH];
|
||||||
char *option4 = _("notify-bar_warning = ");
|
char desc[MAX_LENGTH];
|
||||||
|
char value[MAX_LENGTH];
|
||||||
|
} opt[NB_OPT];
|
||||||
|
|
||||||
|
int i, y, x, l, x_pos, y_pos, x_offset, y_offset, maxcol;
|
||||||
|
|
||||||
x_pos = 3;
|
x_pos = 3;
|
||||||
|
x_offset = 4;
|
||||||
y_pos = 4;
|
y_pos = 4;
|
||||||
|
y_offset = 3;
|
||||||
|
maxcol = col - 2;
|
||||||
|
|
||||||
|
strncpy(opt[SHOW].name, _("notify-bar_show = "), MAX_LENGTH);
|
||||||
|
strncpy(opt[DATE].name, _("notify-bar_date = "), MAX_LENGTH);
|
||||||
|
strncpy(opt[CLOCK].name, _("notify-bar_clock = "), MAX_LENGTH);
|
||||||
|
strncpy(opt[WARN].name, _("notify-bar_warning = "), MAX_LENGTH);
|
||||||
|
strncpy(opt[CMD].name, _("notify-bar_command = "), MAX_LENGTH);
|
||||||
|
|
||||||
|
strncpy(opt[SHOW].desc,
|
||||||
|
_("(if set to YES, notify-bar will be displayed)"),
|
||||||
|
MAX_LENGTH);
|
||||||
|
strncpy(opt[DATE].desc,
|
||||||
|
_("(Format of the date to be displayed inside notify-bar)"),
|
||||||
|
MAX_LENGTH);
|
||||||
|
strncpy(opt[CLOCK].desc,
|
||||||
|
_("(Format of the time to be displayed inside notify-bar)"),
|
||||||
|
MAX_LENGTH);
|
||||||
|
strncpy(opt[WARN].desc,
|
||||||
|
_("(Warn user if an appointment is within next 'notify-bar_warning'"
|
||||||
|
"seconds)"),
|
||||||
|
MAX_LENGTH);
|
||||||
|
strncpy(opt[CMD].desc,
|
||||||
|
_("(Command used to notify user of an upcoming appointment)"),
|
||||||
|
MAX_LENGTH);
|
||||||
|
|
||||||
pthread_mutex_lock(&nbar->mutex);
|
pthread_mutex_lock(&nbar->mutex);
|
||||||
mvwprintw(win, y_pos, x_pos, "[1] %s ", option1);
|
|
||||||
print_option_incolor(win, nbar->show, y_pos,
|
|
||||||
x_pos + 4 + strlen(option1));
|
|
||||||
mvwprintw(win, y_pos + 1, x_pos,
|
|
||||||
_("(if set to YES, notify-bar will be displayed)"));
|
|
||||||
|
|
||||||
mvwprintw(win, y_pos + 3, x_pos, "[2] %s ", option2);
|
strncpy(opt[DATE].value, nbar->datefmt, MAX_LENGTH);
|
||||||
custom_apply_attr(win, ATTR_HIGHEST);
|
strncpy(opt[CLOCK].value, nbar->timefmt, MAX_LENGTH);
|
||||||
mvwprintw(win, y_pos + 3, x_pos + 4 + strlen(option2), "%s", nbar->datefmt);
|
snprintf(opt[WARN].value, MAX_LENGTH, "%d", nbar->cntdwn);
|
||||||
custom_remove_attr(win, ATTR_HIGHEST);
|
strncpy(opt[CMD].value, nbar->cmd, MAX_LENGTH);
|
||||||
mvwprintw(win, y_pos + 4, x_pos,
|
|
||||||
_("(Format of the date to be displayed inside notify-bar)"));
|
|
||||||
|
|
||||||
mvwprintw(win, y_pos + 6, x_pos, "[3] %s ", option3);
|
l = strlen(opt[SHOW].name);
|
||||||
custom_apply_attr(win, ATTR_HIGHEST);
|
x = x_pos + x_offset + l;
|
||||||
mvwprintw(win, y_pos + 6, x_pos + 4 + strlen(option3), "%s", nbar->timefmt);
|
mvwprintw(win, y_pos, x_pos, "[1] %s", opt[SHOW].name);
|
||||||
custom_remove_attr(win, ATTR_HIGHEST);
|
erase_window_part(win, x, y_pos, maxcol, y_pos);
|
||||||
mvwprintw(win, y_pos + 7, x_pos,
|
print_option_incolor(win, nbar->show, y_pos, x);
|
||||||
_("(Format of the time to be displayed inside notify-bar)"));
|
mvwprintw(win, y_pos + 1, x_pos, opt[SHOW].desc);
|
||||||
|
|
||||||
mvwprintw(win, y_pos + 9, x_pos, "[4] %s ", option4);
|
for (i = 1; i < NB_OPT; i++) {
|
||||||
|
l = strlen(opt[i].name);
|
||||||
|
y = y_pos + i * y_offset;
|
||||||
|
x = x_pos + x_offset + l;
|
||||||
|
mvwprintw(win, y, x_pos, "[%d] %s", i + 1, opt[i].name);
|
||||||
|
erase_window_part(win, x, y, maxcol, y);
|
||||||
custom_apply_attr(win, ATTR_HIGHEST);
|
custom_apply_attr(win, ATTR_HIGHEST);
|
||||||
mvwprintw(win, y_pos + 9, x_pos + 4 + strlen(option4), "%d", nbar->cntdwn);
|
mvwprintw(win, y, x, "%s", opt[i].value);
|
||||||
custom_remove_attr(win, ATTR_HIGHEST);
|
custom_remove_attr(win, ATTR_HIGHEST);
|
||||||
mvwprintw(win, y_pos + 10, x_pos,
|
mvwprintw(win, y + 1, x_pos, opt[i].desc);
|
||||||
_("(Warn user if an appointment is within next 'notify-bar_warning' seconds)"));
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&nbar->mutex);
|
pthread_mutex_unlock(&nbar->mutex);
|
||||||
wmove(swin, 1, 0);
|
wmove(swin, 1, 0);
|
||||||
@ -1168,30 +1230,25 @@ void add_item(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { /* Insert the event Id */
|
} else /* Insert the event Id */
|
||||||
Id = 1;
|
Id = 1;
|
||||||
}
|
|
||||||
// get the item description
|
|
||||||
status_mesg(mesg_3, "");
|
status_mesg(mesg_3, "");
|
||||||
if (getstring(swin, colr, item_mesg, MAX_LENGTH, 0, 1) ==
|
if (getstring(swin, colr, item_mesg, MAX_LENGTH, 0, 1) ==
|
||||||
GETSTRING_VALID) {
|
GETSTRING_VALID) {
|
||||||
if (is_appointment){
|
if (is_appointment) {
|
||||||
// insert the appointment in list
|
|
||||||
apoint_start = date2sec(sel_year, sel_month, sel_day,
|
apoint_start = date2sec(sel_year, sel_month, sel_day,
|
||||||
heures, minutes);
|
heures, minutes);
|
||||||
apoint_pointeur =
|
apoint_pointeur = apoint_new(item_mesg, apoint_start,
|
||||||
apoint_new(item_mesg, apoint_start, min2sec(apoint_duration));
|
min2sec(apoint_duration), 0L);
|
||||||
if (notify_bar()) notify_check_added(item_mesg, apoint_start);
|
if (notify_bar())
|
||||||
// insert the event in list
|
notify_check_added(item_mesg, apoint_start);
|
||||||
} else {
|
} else
|
||||||
event_pointeur = event_new(item_mesg, date2sec(
|
event_pointeur = event_new(item_mesg, date2sec(
|
||||||
sel_year,
|
sel_year, sel_month, sel_day, 12, 0), Id);
|
||||||
sel_month,
|
|
||||||
sel_day,
|
if (hilt_app == 0)
|
||||||
12, 0),
|
hilt_app++;
|
||||||
Id);
|
|
||||||
}
|
|
||||||
if (hilt_app == 0) hilt_app++;
|
|
||||||
}
|
}
|
||||||
erase_window_part(swin, 0, 0, nc_bar, nl_bar);
|
erase_window_part(swin, 0, 0, nc_bar, nl_bar);
|
||||||
}
|
}
|
||||||
@ -1376,6 +1433,9 @@ void load_conf(void)
|
|||||||
} else if (var == 12) {
|
} else if (var == 12) {
|
||||||
nbar->cntdwn = atoi(e_conf);
|
nbar->cntdwn = atoi(e_conf);
|
||||||
var = 0;
|
var = 0;
|
||||||
|
} else if (var == 13) {
|
||||||
|
strncpy(nbar->cmd, e_conf, strlen(e_conf) + 1);
|
||||||
|
var = 0;
|
||||||
}
|
}
|
||||||
if (strncmp(e_conf, "auto_save=", 10) == 0)
|
if (strncmp(e_conf, "auto_save=", 10) == 0)
|
||||||
var = 1;
|
var = 1;
|
||||||
@ -1401,6 +1461,8 @@ void load_conf(void)
|
|||||||
var = 11;
|
var = 11;
|
||||||
else if (strncmp(e_conf, "notify-bar_warning=", 19) ==0)
|
else if (strncmp(e_conf, "notify-bar_warning=", 19) ==0)
|
||||||
var = 12;
|
var = 12;
|
||||||
|
else if (strncmp(e_conf, "notify-bar_command=", 19) ==0)
|
||||||
|
var = 13;
|
||||||
}
|
}
|
||||||
fclose(data_file);
|
fclose(data_file);
|
||||||
pthread_mutex_unlock(&nbar->mutex);
|
pthread_mutex_unlock(&nbar->mutex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user