summaryrefslogtreecommitdiffstats
path: root/src/notify.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/notify.c')
-rw-r--r--src/notify.c1082
1 files changed, 558 insertions, 524 deletions
diff --git a/src/notify.c b/src/notify.c
index 36aad5a..816da3c 100644
--- a/src/notify.c
+++ b/src/notify.c
@@ -44,11 +44,11 @@
#define NOTIFY_FIELD_LENGTH 25
struct notify_vars {
- WINDOW *win;
- char *apts_file;
- char time[NOTIFY_FIELD_LENGTH];
- char date[NOTIFY_FIELD_LENGTH];
- pthread_mutex_t mutex;
+ WINDOW *win;
+ char *apts_file;
+ char time[NOTIFY_FIELD_LENGTH];
+ char date[NOTIFY_FIELD_LENGTH];
+ pthread_mutex_t mutex;
};
static struct notify_vars notify;
@@ -62,13 +62,13 @@ static pthread_t notify_t_main;
*/
int notify_time_left(void)
{
- time_t ntimer;
- int left;
+ time_t ntimer;
+ int left;
- ntimer = time(NULL);
- left = notify_app.time - ntimer;
+ ntimer = time(NULL);
+ left = notify_app.time - ntimer;
- return left > 0 ? left : 0;
+ return left > 0 ? left : 0;
}
/*
@@ -77,12 +77,12 @@ int notify_time_left(void)
*/
unsigned notify_needs_reminder(void)
{
- if (notify_app.got_app
- && (((notify_app.state & APOINT_NOTIFY) && !nbar.notify_all) ||
- (!(notify_app.state & APOINT_NOTIFY) && nbar.notify_all))
- && !(notify_app.state & APOINT_NOTIFIED))
- return 1;
- return 0;
+ if (notify_app.got_app
+ && (((notify_app.state & APOINT_NOTIFY) && !nbar.notify_all) ||
+ (!(notify_app.state & APOINT_NOTIFY) && nbar.notify_all))
+ && !(notify_app.state & APOINT_NOTIFIED))
+ return 1;
+ return 0;
}
/*
@@ -92,60 +92,61 @@ unsigned notify_needs_reminder(void)
*/
void notify_update_app(long start, char state, char *msg)
{
- notify_free_app();
- notify_app.got_app = 1;
- notify_app.time = start;
- notify_app.state = state;
- notify_app.txt = mem_strdup(msg);
+ notify_free_app();
+ notify_app.got_app = 1;
+ notify_app.time = start;
+ notify_app.state = state;
+ notify_app.txt = mem_strdup(msg);
}
/* Return 1 if we need to display the notify-bar, else 0. */
int notify_bar(void)
{
- int display_bar = 0;
+ int display_bar = 0;
- pthread_mutex_lock(&nbar.mutex);
- display_bar = (nbar.show) ? 1 : 0;
- pthread_mutex_unlock(&nbar.mutex);
+ pthread_mutex_lock(&nbar.mutex);
+ display_bar = (nbar.show) ? 1 : 0;
+ pthread_mutex_unlock(&nbar.mutex);
- return display_bar;
+ return display_bar;
}
/* Initialize the nbar variable used to store notification options. */
void notify_init_vars(void)
{
- const char *time_format = "%T";
- const char *date_format = "%a %F";
- const char *cmd = "printf '\\a'";
+ const char *time_format = "%T";
+ const char *date_format = "%a %F";
+ const char *cmd = "printf '\\a'";
- pthread_mutex_init(&nbar.mutex, NULL);
- nbar.show = 1;
- nbar.cntdwn = 300;
- strncpy(nbar.datefmt, date_format, strlen(date_format) + 1);
- strncpy(nbar.timefmt, time_format, strlen(time_format) + 1);
- strncpy(nbar.cmd, cmd, strlen(cmd) + 1);
+ pthread_mutex_init(&nbar.mutex, NULL);
+ nbar.show = 1;
+ nbar.cntdwn = 300;
+ strncpy(nbar.datefmt, date_format, strlen(date_format) + 1);
+ strncpy(nbar.timefmt, time_format, strlen(time_format) + 1);
+ strncpy(nbar.cmd, cmd, strlen(cmd) + 1);
- if ((nbar.shell = getenv("SHELL")) == NULL)
- nbar.shell = "/bin/sh";
+ if ((nbar.shell = getenv("SHELL")) == NULL)
+ nbar.shell = "/bin/sh";
- nbar.notify_all = 0;
+ nbar.notify_all = 0;
- pthread_attr_init(&detached_thread_attr);
- pthread_attr_setdetachstate(&detached_thread_attr, PTHREAD_CREATE_DETACHED);
+ pthread_attr_init(&detached_thread_attr);
+ pthread_attr_setdetachstate(&detached_thread_attr,
+ PTHREAD_CREATE_DETACHED);
}
/* Extract the appointment file name from the complete file path. */
static void extract_aptsfile(void)
{
- char *file;
-
- file = strrchr(path_apts, '/');
- if (!file) {
- notify.apts_file = path_apts;
- } else {
- notify.apts_file = file;
- notify.apts_file++;
- }
+ char *file;
+
+ file = strrchr(path_apts, '/');
+ if (!file) {
+ notify.apts_file = path_apts;
+ } else {
+ notify.apts_file = file;
+ notify.apts_file++;
+ }
}
/*
@@ -155,12 +156,13 @@ static void extract_aptsfile(void)
*/
void notify_init_bar(void)
{
- pthread_mutex_init(&notify.mutex, NULL);
- pthread_mutex_init(&notify_app.mutex, NULL);
- notify_app.got_app = 0;
- notify_app.txt = 0;
- notify.win = newwin(win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
- extract_aptsfile();
+ pthread_mutex_init(&notify.mutex, NULL);
+ pthread_mutex_init(&notify_app.mutex, NULL);
+ notify_app.got_app = 0;
+ notify_app.txt = 0;
+ notify.win =
+ newwin(win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
+ extract_aptsfile();
}
/*
@@ -168,21 +170,21 @@ void notify_init_bar(void)
*/
void notify_free_app(void)
{
- notify_app.time = 0;
- notify_app.got_app = 0;
- notify_app.state = APOINT_NULL;
- if (notify_app.txt)
- mem_free(notify_app.txt);
- notify_app.txt = 0;
+ notify_app.time = 0;
+ notify_app.got_app = 0;
+ notify_app.state = APOINT_NULL;
+ if (notify_app.txt)
+ mem_free(notify_app.txt);
+ notify_app.txt = 0;
}
/* Stop the notify-bar main thread. */
void notify_stop_main_thread(void)
{
- if (notify_t_main) {
- pthread_cancel(notify_t_main);
- pthread_join(notify_t_main, NULL);
- }
+ if (notify_t_main) {
+ pthread_cancel(notify_t_main);
+ pthread_join(notify_t_main, NULL);
+ }
}
/*
@@ -191,35 +193,37 @@ void notify_stop_main_thread(void)
*/
void notify_reinit_bar(void)
{
- delwin(notify.win);
- notify.win = newwin(win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
+ delwin(notify.win);
+ notify.win =
+ newwin(win[NOT].h, win[NOT].w, win[NOT].y, win[NOT].x);
}
/* Launch user defined command as a notification. */
unsigned notify_launch_cmd(void)
{
- int pid;
+ int pid;
- if (notify_app.state & APOINT_NOTIFIED)
- return 1;
+ if (notify_app.state & APOINT_NOTIFIED)
+ return 1;
- notify_app.state |= APOINT_NOTIFIED;
+ notify_app.state |= APOINT_NOTIFIED;
- pid = fork();
+ pid = fork();
- if (pid < 0) {
- ERROR_MSG(_("error while launching command: could not fork"));
- return 0;
- } else if (pid == 0) {
- /* Child: launch user defined command */
- if (execlp(nbar.shell, nbar.shell, "-c", nbar.cmd, NULL) < 0) {
- ERROR_MSG(_("error while launching command"));
- _exit(1);
- }
- _exit(0);
- }
+ if (pid < 0) {
+ ERROR_MSG(_("error while launching command: could not fork"));
+ return 0;
+ } else if (pid == 0) {
+ /* Child: launch user defined command */
+ if (execlp(nbar.shell, nbar.shell, "-c", nbar.cmd, NULL) <
+ 0) {
+ ERROR_MSG(_("error while launching command"));
+ _exit(1);
+ }
+ _exit(0);
+ }
- return 1;
+ return 1;
}
/*
@@ -228,141 +232,152 @@ unsigned notify_launch_cmd(void)
*/
void notify_update_bar(void)
{
- const int space = 3;
- int file_pos, date_pos, app_pos, txt_max_len, too_long = 0;
- int time_left, blinking;
- char buf[BUFSIZ];
-
- date_pos = space;
- pthread_mutex_lock(&notify.mutex);
-
- file_pos = strlen(notify.date) + strlen(notify.time) + 7 + 2 * space;
- app_pos = file_pos + strlen(notify.apts_file) + 2 + space;
- txt_max_len = col - (app_pos + 12 + space);
-
- WINS_NBAR_LOCK;
- custom_apply_attr(notify.win, ATTR_HIGHEST);
- wattron(notify.win, A_UNDERLINE | A_REVERSE);
- mvwhline(notify.win, 0, 0, ACS_HLINE, col);
- mvwprintw(notify.win, 0, date_pos, "[ %s | %s ]", notify.date, notify.time);
- mvwprintw(notify.win, 0, file_pos, "(%s)", notify.apts_file);
- WINS_NBAR_UNLOCK;
-
- pthread_mutex_lock(&notify_app.mutex);
- if (notify_app.got_app) {
- if (strlen(notify_app.txt) > txt_max_len) {
- int shrink_len;
-
- too_long = 1;
- shrink_len = txt_max_len > 3 ? txt_max_len - 3 : 1;
- strncpy(buf, notify_app.txt, shrink_len);
- buf[shrink_len] = '\0';
- }
- time_left = notify_time_left();
- if (time_left > 0) {
- int hours_left, minutes_left;
-
- hours_left = (time_left / HOURINSEC);
- minutes_left = (time_left - hours_left * HOURINSEC) / MININSEC;
- pthread_mutex_lock(&nbar.mutex);
-
- if (time_left < nbar.cntdwn &&
- (((notify_app.state & APOINT_NOTIFY) && !nbar.notify_all) ||
- (!(notify_app.state & APOINT_NOTIFY) && nbar.notify_all)))
- blinking = 1;
- else
- blinking = 0;
-
- WINS_NBAR_LOCK;
- if (blinking)
- wattron(notify.win, A_BLINK);
- if (too_long)
- mvwprintw(notify.win, 0, app_pos, "> %02d:%02d :: %s.. <",
- hours_left, minutes_left, buf);
- else
- mvwprintw(notify.win, 0, app_pos, "> %02d:%02d :: %s <",
- hours_left, minutes_left, notify_app.txt);
- if (blinking)
- wattroff(notify.win, A_BLINK);
- WINS_NBAR_UNLOCK;
-
- if (blinking)
- notify_launch_cmd();
- pthread_mutex_unlock(&nbar.mutex);
- } else {
- notify_app.got_app = 0;
- pthread_mutex_unlock(&notify_app.mutex);
- pthread_mutex_unlock(&notify.mutex);
- notify_check_next_app(0);
- return;
- }
- }
- pthread_mutex_unlock(&notify_app.mutex);
-
- WINS_NBAR_LOCK;
- wattroff(notify.win, A_UNDERLINE | A_REVERSE);
- custom_remove_attr(notify.win, ATTR_HIGHEST);
- WINS_NBAR_UNLOCK;
- wins_wrefresh(notify.win);
-
- pthread_mutex_unlock(&notify.mutex);
+ const int space = 3;
+ int file_pos, date_pos, app_pos, txt_max_len, too_long = 0;
+ int time_left, blinking;
+ char buf[BUFSIZ];
+
+ date_pos = space;
+ pthread_mutex_lock(&notify.mutex);
+
+ file_pos =
+ strlen(notify.date) + strlen(notify.time) + 7 + 2 * space;
+ app_pos = file_pos + strlen(notify.apts_file) + 2 + space;
+ txt_max_len = col - (app_pos + 12 + space);
+
+ WINS_NBAR_LOCK;
+ custom_apply_attr(notify.win, ATTR_HIGHEST);
+ wattron(notify.win, A_UNDERLINE | A_REVERSE);
+ mvwhline(notify.win, 0, 0, ACS_HLINE, col);
+ mvwprintw(notify.win, 0, date_pos, "[ %s | %s ]", notify.date,
+ notify.time);
+ mvwprintw(notify.win, 0, file_pos, "(%s)", notify.apts_file);
+ WINS_NBAR_UNLOCK;
+
+ pthread_mutex_lock(&notify_app.mutex);
+ if (notify_app.got_app) {
+ if (strlen(notify_app.txt) > txt_max_len) {
+ int shrink_len;
+
+ too_long = 1;
+ shrink_len = txt_max_len > 3 ? txt_max_len - 3 : 1;
+ strncpy(buf, notify_app.txt, shrink_len);
+ buf[shrink_len] = '\0';
+ }
+ time_left = notify_time_left();
+ if (time_left > 0) {
+ int hours_left, minutes_left;
+
+ hours_left = (time_left / HOURINSEC);
+ minutes_left =
+ (time_left -
+ hours_left * HOURINSEC) / MININSEC;
+ pthread_mutex_lock(&nbar.mutex);
+
+ if (time_left < nbar.cntdwn &&
+ (((notify_app.state & APOINT_NOTIFY)
+ && !nbar.notify_all)
+ || (!(notify_app.state & APOINT_NOTIFY)
+ && nbar.notify_all)))
+ blinking = 1;
+ else
+ blinking = 0;
+
+ WINS_NBAR_LOCK;
+ if (blinking)
+ wattron(notify.win, A_BLINK);
+ if (too_long)
+ mvwprintw(notify.win, 0, app_pos,
+ "> %02d:%02d :: %s.. <",
+ hours_left, minutes_left, buf);
+ else
+ mvwprintw(notify.win, 0, app_pos,
+ "> %02d:%02d :: %s <",
+ hours_left, minutes_left,
+ notify_app.txt);
+ if (blinking)
+ wattroff(notify.win, A_BLINK);
+ WINS_NBAR_UNLOCK;
+
+ if (blinking)
+ notify_launch_cmd();
+ pthread_mutex_unlock(&nbar.mutex);
+ } else {
+ notify_app.got_app = 0;
+ pthread_mutex_unlock(&notify_app.mutex);
+ pthread_mutex_unlock(&notify.mutex);
+ notify_check_next_app(0);
+ return;
+ }
+ }
+ pthread_mutex_unlock(&notify_app.mutex);
+
+ WINS_NBAR_LOCK;
+ wattroff(notify.win, A_UNDERLINE | A_REVERSE);
+ custom_remove_attr(notify.win, ATTR_HIGHEST);
+ WINS_NBAR_UNLOCK;
+ wins_wrefresh(notify.win);
+
+ pthread_mutex_unlock(&notify.mutex);
}
/* Update the notication bar content */
/* ARGSUSED0 */
static void *notify_main_thread(void *arg)
{
- const unsigned thread_sleep = 1;
- const unsigned check_app = MININSEC;
- int elapse = 0;
- int got_app;
- struct tm ntime;
- time_t ntimer;
-
- elapse = 0;
-
- for (;;) {
- ntimer = time(NULL);
- localtime_r(&ntimer, &ntime);
- pthread_mutex_lock(&notify.mutex);
- pthread_mutex_lock(&nbar.mutex);
- strftime(notify.time, NOTIFY_FIELD_LENGTH, nbar.timefmt, &ntime);
- strftime(notify.date, NOTIFY_FIELD_LENGTH, nbar.datefmt, &ntime);
- pthread_mutex_unlock(&nbar.mutex);
- pthread_mutex_unlock(&notify.mutex);
- notify_update_bar();
- psleep(thread_sleep);
- elapse += thread_sleep;
- if (elapse >= check_app) {
- elapse = 0;
- pthread_mutex_lock(&notify_app.mutex);
- got_app = notify_app.got_app;
- pthread_mutex_unlock(&notify_app.mutex);
- if (!got_app)
- notify_check_next_app(0);
- }
- }
- pthread_exit(NULL);
+ const unsigned thread_sleep = 1;
+ const unsigned check_app = MININSEC;
+ int elapse = 0;
+ int got_app;
+ struct tm ntime;
+ time_t ntimer;
+
+ elapse = 0;
+
+ for (;;) {
+ ntimer = time(NULL);
+ localtime_r(&ntimer, &ntime);
+ pthread_mutex_lock(&notify.mutex);
+ pthread_mutex_lock(&nbar.mutex);
+ strftime(notify.time, NOTIFY_FIELD_LENGTH, nbar.timefmt,
+ &ntime);
+ strftime(notify.date, NOTIFY_FIELD_LENGTH, nbar.datefmt,
+ &ntime);
+ pthread_mutex_unlock(&nbar.mutex);
+ pthread_mutex_unlock(&notify.mutex);
+ notify_update_bar();
+ psleep(thread_sleep);
+ elapse += thread_sleep;
+ if (elapse >= check_app) {
+ elapse = 0;
+ pthread_mutex_lock(&notify_app.mutex);
+ got_app = notify_app.got_app;
+ pthread_mutex_unlock(&notify_app.mutex);
+ if (!got_app)
+ notify_check_next_app(0);
+ }
+ }
+ pthread_exit(NULL);
}
/* Fill the given structure with information about next appointment. */
unsigned notify_get_next(struct notify_app *a)
{
- time_t current_time;
+ time_t current_time;
- if (!a)
- return 0;
+ if (!a)
+ return 0;
- current_time = time(NULL);
+ current_time = time(NULL);
- a->time = current_time + DAYINSEC;
- a->got_app = 0;
- a->state = 0;
- a->txt = NULL;
- recur_apoint_check_next(a, current_time, get_today());
- apoint_check_next(a, current_time);
+ a->time = current_time + DAYINSEC;
+ a->got_app = 0;
+ a->state = 0;
+ a->txt = NULL;
+ recur_apoint_check_next(a, current_time, get_today());
+ apoint_check_next(a, current_time);
- return 1;
+ return 1;
}
/*
@@ -371,162 +386,166 @@ unsigned notify_get_next(struct notify_app *a)
*/
unsigned notify_get_next_bkgd(void)
{
- struct notify_app a;
+ struct notify_app a;
- a.txt = NULL;
- if (!notify_get_next(&a))
- return 0;
+ a.txt = NULL;
+ if (!notify_get_next(&a))
+ return 0;
- if (!a.got_app) {
- /* No next appointment, reset the previous notified one. */
- notify_app.got_app = 0;
- return 1;
- } else {
- if (!notify_same_item(a.time))
- notify_update_app(a.time, a.state, a.txt);
- }
+ if (!a.got_app) {
+ /* No next appointment, reset the previous notified one. */
+ notify_app.got_app = 0;
+ return 1;
+ } else {
+ if (!notify_same_item(a.time))
+ notify_update_app(a.time, a.state, a.txt);
+ }
- if (a.txt)
- mem_free(a.txt);
+ if (a.txt)
+ mem_free(a.txt);
- return 1;
+ return 1;
}
/* Return the description of next appointment to be notified. */
char *notify_app_txt(void)
{
- if (notify_app.got_app)
- return notify_app.txt;
- else
- return NULL;
+ if (notify_app.got_app)
+ return notify_app.txt;
+ else
+ return NULL;
}
/* Look for the next appointment within the next 24 hours. */
/* ARGSUSED0 */
static void *notify_thread_app(void *arg)
{
- struct notify_app tmp_app;
- int force = (arg ? 1 : 0);
-
- if (!notify_get_next(&tmp_app))
- pthread_exit(NULL);
-
- if (!tmp_app.got_app) {
- pthread_mutex_lock(&notify_app.mutex);
- notify_free_app();
- pthread_mutex_unlock(&notify_app.mutex);
- } else {
- if (force || !notify_same_item(tmp_app.time)) {
- pthread_mutex_lock(&notify_app.mutex);
- notify_update_app(tmp_app.time, tmp_app.state, tmp_app.txt);
- pthread_mutex_unlock(&notify_app.mutex);
- }
- }
-
- if (tmp_app.txt)
- mem_free(tmp_app.txt);
- notify_update_bar();
-
- pthread_exit(NULL);
+ struct notify_app tmp_app;
+ int force = (arg ? 1 : 0);
+
+ if (!notify_get_next(&tmp_app))
+ pthread_exit(NULL);
+
+ if (!tmp_app.got_app) {
+ pthread_mutex_lock(&notify_app.mutex);
+ notify_free_app();
+ pthread_mutex_unlock(&notify_app.mutex);
+ } else {
+ if (force || !notify_same_item(tmp_app.time)) {
+ pthread_mutex_lock(&notify_app.mutex);
+ notify_update_app(tmp_app.time, tmp_app.state,
+ tmp_app.txt);
+ pthread_mutex_unlock(&notify_app.mutex);
+ }
+ }
+
+ if (tmp_app.txt)
+ mem_free(tmp_app.txt);
+ notify_update_bar();
+
+ pthread_exit(NULL);
}
/* Launch the thread notify_thread_app to look for next appointment. */
void notify_check_next_app(int force)
{
- pthread_t notify_t_app;
- void *arg = (force ? (void *)1 : NULL);
+ pthread_t notify_t_app;
+ void *arg = (force ? (void *)1 : NULL);
- pthread_create(&notify_t_app, &detached_thread_attr, notify_thread_app, arg);
- return;
+ pthread_create(&notify_t_app, &detached_thread_attr,
+ notify_thread_app, arg);
+ return;
}
/* Check if the newly created appointment is to be notified. */
void notify_check_added(char *mesg, long start, char state)
{
- time_t current_time;
- int update_notify = 0;
- long gap;
-
- current_time = time(NULL);
- pthread_mutex_lock(&notify_app.mutex);
- if (!notify_app.got_app) {
- gap = start - current_time;
- if (gap >= 0 && gap <= DAYINSEC)
- update_notify = 1;
- } else if (start < notify_app.time && start >= current_time) {
- update_notify = 1;
- } else if (start == notify_app.time && state != notify_app.state) {
- update_notify = 1;
- }
-
- if (update_notify) {
- notify_update_app(start, state, mesg);
- }
- pthread_mutex_unlock(&notify_app.mutex);
- notify_update_bar();
+ time_t current_time;
+ int update_notify = 0;
+ long gap;
+
+ current_time = time(NULL);
+ pthread_mutex_lock(&notify_app.mutex);
+ if (!notify_app.got_app) {
+ gap = start - current_time;
+ if (gap >= 0 && gap <= DAYINSEC)
+ update_notify = 1;
+ } else if (start < notify_app.time && start >= current_time) {
+ update_notify = 1;
+ } else if (start == notify_app.time && state != notify_app.state) {
+ update_notify = 1;
+ }
+
+ if (update_notify) {
+ notify_update_app(start, state, mesg);
+ }
+ pthread_mutex_unlock(&notify_app.mutex);
+ notify_update_bar();
}
/* Check if the newly repeated appointment is to be notified. */
void notify_check_repeated(struct recur_apoint *i)
{
- unsigned real_app_time;
- int update_notify = 0;
- time_t current_time;
-
- current_time = time(NULL);
- pthread_mutex_lock(&notify_app.mutex);
- if (recur_item_find_occurrence(i->start, i->dur, &i->exc, i->rpt->type,
- i->rpt->freq, i->rpt->until, get_today(),
- &real_app_time)) {
- if (!notify_app.got_app) {
- if (real_app_time - current_time <= DAYINSEC)
- update_notify = 1;
- } else if (real_app_time < notify_app.time && real_app_time >= current_time) {
- update_notify = 1;
- } else if (real_app_time == notify_app.time && i->state != notify_app.state) {
- update_notify = 1;
- }
- }
- if (update_notify) {
- notify_update_app(real_app_time, i->state, i->mesg);
- }
- pthread_mutex_unlock(&notify_app.mutex);
- notify_update_bar();
+ unsigned real_app_time;
+ int update_notify = 0;
+ time_t current_time;
+
+ current_time = time(NULL);
+ pthread_mutex_lock(&notify_app.mutex);
+ if (recur_item_find_occurrence
+ (i->start, i->dur, &i->exc, i->rpt->type, i->rpt->freq,
+ i->rpt->until, get_today(), &real_app_time)) {
+ if (!notify_app.got_app) {
+ if (real_app_time - current_time <= DAYINSEC)
+ update_notify = 1;
+ } else if (real_app_time < notify_app.time
+ && real_app_time >= current_time) {
+ update_notify = 1;
+ } else if (real_app_time == notify_app.time
+ && i->state != notify_app.state) {
+ update_notify = 1;
+ }
+ }
+ if (update_notify) {
+ notify_update_app(real_app_time, i->state, i->mesg);
+ }
+ pthread_mutex_unlock(&notify_app.mutex);
+ notify_update_bar();
}
int notify_same_item(long time)
{
- int same = 0;
+ int same = 0;
- pthread_mutex_lock(&(notify_app.mutex));
- if (notify_app.got_app && notify_app.time == time)
- same = 1;
- pthread_mutex_unlock(&(notify_app.mutex));
+ pthread_mutex_lock(&(notify_app.mutex));
+ if (notify_app.got_app && notify_app.time == time)
+ same = 1;
+ pthread_mutex_unlock(&(notify_app.mutex));
- return same;
+ return same;
}
int notify_same_recur_item(struct recur_apoint *i)
{
- int same = 0;
- unsigned item_start = 0;
-
- recur_item_find_occurrence(i->start, i->dur, &i->exc, i->rpt->type,
- i->rpt->freq, i->rpt->until, get_today(),
- &item_start);
- pthread_mutex_lock(&notify_app.mutex);
- if (notify_app.got_app && item_start == notify_app.time)
- same = 1;
- pthread_mutex_unlock(&(notify_app.mutex));
-
- return same;
+ int same = 0;
+ unsigned item_start = 0;
+
+ recur_item_find_occurrence(i->start, i->dur, &i->exc, i->rpt->type,
+ i->rpt->freq, i->rpt->until,
+ get_today(), &item_start);
+ pthread_mutex_lock(&notify_app.mutex);
+ if (notify_app.got_app && item_start == notify_app.time)
+ same = 1;
+ pthread_mutex_unlock(&(notify_app.mutex));
+
+ return same;
}
/* Launch the notify-bar main thread. */
void notify_start_main_thread(void)
{
- pthread_create(&notify_t_main, NULL, notify_main_thread, NULL);
- notify_check_next_app(0);
+ pthread_create(&notify_t_main, NULL, notify_main_thread, NULL);
+ notify_check_next_app(0);
}
/*
@@ -536,248 +555,263 @@ void notify_start_main_thread(void)
*/
static void
print_option(WINDOW * win, unsigned x, unsigned y, char *name,
- char *valstr, unsigned valbool, char *desc, unsigned num)
+ char *valstr, unsigned valbool, char *desc, unsigned num)
{
- const int XOFF = 4;
- const int MAXCOL = col - 3;
- int x_opt, len;
-
- x_opt = x + XOFF + strlen(name);
- mvwprintw(win, y, x, "[%u] %s", num, name);
- erase_window_part(win, x_opt, y, MAXCOL, y);
- if ((len = strlen(valstr)) != 0) {
- unsigned maxlen;
-
- maxlen = MAXCOL - x_opt - 2;
- custom_apply_attr(win, ATTR_HIGHEST);
- if (len < maxlen) {
- mvwaddstr(win, y, x_opt, valstr);
- } else {
- char buf[BUFSIZ];
-
- strncpy(buf, valstr, maxlen - 1);
- buf[maxlen - 1] = '\0';
- mvwprintw(win, y, x_opt, "%s...", buf);
- }
- custom_remove_attr(win, ATTR_HIGHEST);
- } else {
- print_bool_option_incolor(win, valbool, y, x_opt);
- }
- mvwaddstr(win, y + 1, x, desc);
+ const int XOFF = 4;
+ const int MAXCOL = col - 3;
+ int x_opt, len;
+
+ x_opt = x + XOFF + strlen(name);
+ mvwprintw(win, y, x, "[%u] %s", num, name);
+ erase_window_part(win, x_opt, y, MAXCOL, y);
+ if ((len = strlen(valstr)) != 0) {
+ unsigned maxlen;
+
+ maxlen = MAXCOL - x_opt - 2;
+ custom_apply_attr(win, ATTR_HIGHEST);
+ if (len < maxlen) {
+ mvwaddstr(win, y, x_opt, valstr);
+ } else {
+ char buf[BUFSIZ];
+
+ strncpy(buf, valstr, maxlen - 1);
+ buf[maxlen - 1] = '\0';
+ mvwprintw(win, y, x_opt, "%s...", buf);
+ }
+ custom_remove_attr(win, ATTR_HIGHEST);
+ } else {
+ print_bool_option_incolor(win, valbool, y, x_opt);
+ }
+ mvwaddstr(win, y + 1, x, desc);
}
/* Print options related to the notify-bar. */
static unsigned print_config_options(WINDOW * optwin)
{
- const int XORIG = 3;
- const int YORIG = 0;
- const int YOFF = 3;
+ const int XORIG = 3;
+ const int YORIG = 0;
+ const int YOFF = 3;
- enum { SHOW, DATE, CLOCK, WARN, CMD, NOTIFY_ALL, DMON, DMON_LOG, NB_OPT };
+ enum { SHOW, DATE, CLOCK, WARN, CMD, NOTIFY_ALL, DMON, DMON_LOG,
+ NB_OPT };
- struct opt_s {
- char *name;
- char *desc;
- char valstr[BUFSIZ];
- unsigned valnum;
- } opt[NB_OPT];
+ struct opt_s {
+ char *name;
+ char *desc;
+ char valstr[BUFSIZ];
+ unsigned valnum;
+ } opt[NB_OPT];
- int i;
+ int i;
- opt[SHOW].name = "appearance.notifybar = ";
- opt[SHOW].desc = _("(if set to YES, notify-bar will be displayed)");
+ opt[SHOW].name = "appearance.notifybar = ";
+ opt[SHOW].desc =
+ _("(if set to YES, notify-bar will be displayed)");
- opt[DATE].name = "format.notifydate = ";
- opt[DATE].desc = _("(Format of the date to be displayed inside notify-bar)");
+ opt[DATE].name = "format.notifydate = ";
+ opt[DATE].desc =
+ _("(Format of the date to be displayed inside notify-bar)");
- opt[CLOCK].name = "format.notifytime = ";
- opt[CLOCK].desc = _("(Format of the time to be displayed inside notify-bar)");
+ opt[CLOCK].name = "format.notifytime = ";
+ opt[CLOCK].desc =
+ _("(Format of the time to be displayed inside notify-bar)");
- opt[WARN].name = "notification.warning = ";
- opt[WARN].desc = _("(Warn user if an appointment is within next "
- "'notify-bar_warning' seconds)");
+ opt[WARN].name = "notification.warning = ";
+ opt[WARN].desc = _("(Warn user if an appointment is within next "
+ "'notify-bar_warning' seconds)");
- opt[CMD].name = "notification.command = ";
- opt[CMD].desc = _("(Command used to notify user of an upcoming appointment)");
+ opt[CMD].name = "notification.command = ";
+ opt[CMD].desc =
+ _("(Command used to notify user of an upcoming appointment)");
- opt[NOTIFY_ALL].name = "notification.notifyall = ";
- opt[NOTIFY_ALL].desc =
- _("(Notify all appointments instead of flagged ones only)");
+ opt[NOTIFY_ALL].name = "notification.notifyall = ";
+ opt[NOTIFY_ALL].desc =
+ _("(Notify all appointments instead of flagged ones only)");
- opt[DMON].name = "daemon.enable = ";
- opt[DMON].desc = _("(Run in background to get notifications after exiting)");
+ opt[DMON].name = "daemon.enable = ";
+ opt[DMON].desc =
+ _("(Run in background to get notifications after exiting)");
- opt[DMON_LOG].name = "daemon.log = ";
- opt[DMON_LOG].desc = _("(Log activity when running in background)");
+ opt[DMON_LOG].name = "daemon.log = ";
+ opt[DMON_LOG].desc =
+ _("(Log activity when running in background)");
- pthread_mutex_lock(&nbar.mutex);
+ pthread_mutex_lock(&nbar.mutex);
- /* String value options */
- strncpy(opt[DATE].valstr, nbar.datefmt, BUFSIZ);
- strncpy(opt[CLOCK].valstr, nbar.timefmt, BUFSIZ);
- snprintf(opt[WARN].valstr, BUFSIZ, "%d", nbar.cntdwn);
- strncpy(opt[CMD].valstr, nbar.cmd, BUFSIZ);
+ /* String value options */
+ strncpy(opt[DATE].valstr, nbar.datefmt, BUFSIZ);
+ strncpy(opt[CLOCK].valstr, nbar.timefmt, BUFSIZ);
+ snprintf(opt[WARN].valstr, BUFSIZ, "%d", nbar.cntdwn);
+ strncpy(opt[CMD].valstr, nbar.cmd, BUFSIZ);
- /* Boolean options */
- opt[SHOW].valnum = nbar.show;
- opt[NOTIFY_ALL].valnum = nbar.notify_all;
- pthread_mutex_unlock(&nbar.mutex);
+ /* Boolean options */
+ opt[SHOW].valnum = nbar.show;
+ opt[NOTIFY_ALL].valnum = nbar.notify_all;
+ pthread_mutex_unlock(&nbar.mutex);
- opt[DMON].valnum = dmon.enable;
- opt[DMON_LOG].valnum = dmon.log;
+ opt[DMON].valnum = dmon.enable;
+ opt[DMON_LOG].valnum = dmon.log;
- opt[SHOW].valstr[0] = opt[NOTIFY_ALL].valstr[0] = opt[DMON].valstr[0] =
- opt[DMON_LOG].valstr[0] = '\0';
+ opt[SHOW].valstr[0] = opt[NOTIFY_ALL].valstr[0] =
+ opt[DMON].valstr[0] = opt[DMON_LOG].valstr[0] = '\0';
- for (i = 0; i < NB_OPT; i++) {
- int y;
+ for (i = 0; i < NB_OPT; i++) {
+ int y;
- y = YORIG + i * YOFF;
- print_option(optwin, XORIG, y, opt[i].name, opt[i].valstr,
- opt[i].valnum, opt[i].desc, i + 1);
- }
+ y = YORIG + i * YOFF;
+ print_option(optwin, XORIG, y, opt[i].name, opt[i].valstr,
+ opt[i].valnum, opt[i].desc, i + 1);
+ }
- return YORIG + NB_OPT * YOFF;
+ return YORIG + NB_OPT * YOFF;
}
static void reinit_conf_win(struct scrollwin *win)
{
- unsigned first_line;
-
- first_line = win->first_visible_line;
- wins_scrollwin_delete(win);
- custom_set_swsiz(win);
- wins_scrollwin_init(win);
- wins_show(win->win.p, win->label);
- win->first_visible_line = first_line;
+ unsigned first_line;
+
+ first_line = win->first_visible_line;
+ wins_scrollwin_delete(win);
+ custom_set_swsiz(win);
+ wins_scrollwin_init(win);
+ wins_show(win->win.p, win->label);
+ win->first_visible_line = first_line;
}
/* Notify-bar configuration. */
void notify_config_bar(void)
{
- struct scrollwin cwin;
- char *buf;
- const char *number_str = _("Enter an option number to change its value");
- const char *keys = _("(Press '^P' or '^N' to move up or down, 'Q' to quit)");
- const char *date_str =
- _("Enter the date format (see 'man 3 strftime' for possible formats) ");
- const char *time_str =
- _("Enter the time format (see 'man 3 strftime' for possible formats) ");
- const char *count_str =
- _
- ("Enter the number of seconds (0 not to be warned before an appointment)");
- const char *cmd_str = _("Enter the notification command ");
- int ch;
-
- clear();
- custom_set_swsiz(&cwin);
- cwin.label = _("notification options");
- wins_scrollwin_init(&cwin);
- wins_show(cwin.win.p, cwin.label);
- status_mesg(number_str, keys);
- cwin.total_lines = print_config_options(cwin.pad.p);
- wins_scrollwin_display(&cwin);
-
- buf = mem_malloc(BUFSIZ);
- while ((ch = wgetch(win[KEY].p)) != 'q') {
- buf[0] = '\0';
-
- switch (ch) {
- case CTRL('N'):
- wins_scrollwin_down(&cwin, 1);
- break;
- case CTRL('P'):
- wins_scrollwin_up(&cwin, 1);
- break;
- case '1':
- pthread_mutex_lock(&nbar.mutex);
- nbar.show = !nbar.show;
- pthread_mutex_unlock(&nbar.mutex);
- if (notify_bar())
- notify_start_main_thread();
- else
- notify_stop_main_thread();
- wins_scrollwin_delete(&cwin);
- reinit_conf_win(&cwin);
- break;
- case '2':
- status_mesg(date_str, "");
- pthread_mutex_lock(&nbar.mutex);
- strncpy(buf, nbar.datefmt, strlen(nbar.datefmt) + 1);
- pthread_mutex_unlock(&nbar.mutex);
- if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
- pthread_mutex_lock(&nbar.mutex);
- strncpy(nbar.datefmt, buf, strlen(buf) + 1);
- pthread_mutex_unlock(&nbar.mutex);
- }
- break;
- case '3':
- status_mesg(time_str, "");
- pthread_mutex_lock(&nbar.mutex);
- strncpy(buf, nbar.timefmt, strlen(nbar.timefmt) + 1);
- pthread_mutex_unlock(&nbar.mutex);
- if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
- pthread_mutex_lock(&nbar.mutex);
- strncpy(nbar.timefmt, buf, strlen(buf) + 1);
- pthread_mutex_unlock(&nbar.mutex);
- }
- break;
- case '4':
- status_mesg(count_str, "");
- pthread_mutex_lock(&nbar.mutex);
- snprintf(buf, BUFSIZ, "%d", nbar.cntdwn);
- pthread_mutex_unlock(&nbar.mutex);
- if (updatestring(win[STA].p, &buf, 0, 1) == 0 &&
- is_all_digit(buf) && atoi(buf) >= 0 && atoi(buf) <= DAYINSEC) {
- pthread_mutex_lock(&nbar.mutex);
- nbar.cntdwn = atoi(buf);
- pthread_mutex_unlock(&nbar.mutex);
- }
- 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(win[STA].p, &buf, 0, 1) == 0) {
- pthread_mutex_lock(&nbar.mutex);
- strncpy(nbar.cmd, buf, strlen(buf) + 1);
- pthread_mutex_unlock(&nbar.mutex);
- }
- break;
- case '6':
- pthread_mutex_lock(&nbar.mutex);
- nbar.notify_all = !nbar.notify_all;
- pthread_mutex_unlock(&nbar.mutex);
- notify_check_next_app(1);
- break;
- case '7':
- dmon.enable = !dmon.enable;
- break;
- case '8':
- dmon.log = !dmon.log;
- break;
- }
-
- if (resize) {
- resize = 0;
- wins_get_config();
- wins_reset();
- reinit_conf_win(&cwin);
- delwin(win[STA].p);
- win[STA].p = newwin(win[STA].h, win[STA].w, win[STA].y, win[STA].x);
- keypad(win[STA].p, TRUE);
- if (notify_bar()) {
- notify_reinit_bar();
- notify_update_bar();
- }
- clearok(curscr, TRUE);
- }
-
- status_mesg(number_str, keys);
- cwin.total_lines = print_config_options(cwin.pad.p);
- wins_scrollwin_display(&cwin);
- }
- mem_free(buf);
- wins_scrollwin_delete(&cwin);
+ struct scrollwin cwin;
+ char *buf;
+ const char *number_str =
+ _("Enter an option number to change its value");
+ const char *keys =
+ _("(Press '^P' or '^N' to move up or down, 'Q' to quit)");
+ const char *date_str =
+ _("Enter the date format (see 'man 3 strftime' for possible formats) ");
+ const char *time_str =
+ _("Enter the time format (see 'man 3 strftime' for possible formats) ");
+ const char *count_str =
+ _("Enter the number of seconds (0 not to be warned before an appointment)");
+ const char *cmd_str = _("Enter the notification command ");
+ int ch;
+
+ clear();
+ custom_set_swsiz(&cwin);
+ cwin.label = _("notification options");
+ wins_scrollwin_init(&cwin);
+ wins_show(cwin.win.p, cwin.label);
+ status_mesg(number_str, keys);
+ cwin.total_lines = print_config_options(cwin.pad.p);
+ wins_scrollwin_display(&cwin);
+
+ buf = mem_malloc(BUFSIZ);
+ while ((ch = wgetch(win[KEY].p)) != 'q') {
+ buf[0] = '\0';
+
+ switch (ch) {
+ case CTRL('N'):
+ wins_scrollwin_down(&cwin, 1);
+ break;
+ case CTRL('P'):
+ wins_scrollwin_up(&cwin, 1);
+ break;
+ case '1':
+ pthread_mutex_lock(&nbar.mutex);
+ nbar.show = !nbar.show;
+ pthread_mutex_unlock(&nbar.mutex);
+ if (notify_bar())
+ notify_start_main_thread();
+ else
+ notify_stop_main_thread();
+ wins_scrollwin_delete(&cwin);
+ reinit_conf_win(&cwin);
+ break;
+ case '2':
+ status_mesg(date_str, "");
+ pthread_mutex_lock(&nbar.mutex);
+ strncpy(buf, nbar.datefmt,
+ strlen(nbar.datefmt) + 1);
+ pthread_mutex_unlock(&nbar.mutex);
+ if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
+ pthread_mutex_lock(&nbar.mutex);
+ strncpy(nbar.datefmt, buf,
+ strlen(buf) + 1);
+ pthread_mutex_unlock(&nbar.mutex);
+ }
+ break;
+ case '3':
+ status_mesg(time_str, "");
+ pthread_mutex_lock(&nbar.mutex);
+ strncpy(buf, nbar.timefmt,
+ strlen(nbar.timefmt) + 1);
+ pthread_mutex_unlock(&nbar.mutex);
+ if (updatestring(win[STA].p, &buf, 0, 1) == 0) {
+ pthread_mutex_lock(&nbar.mutex);
+ strncpy(nbar.timefmt, buf,
+ strlen(buf) + 1);
+ pthread_mutex_unlock(&nbar.mutex);
+ }
+ break;
+ case '4':
+ status_mesg(count_str, "");
+ pthread_mutex_lock(&nbar.mutex);
+ snprintf(buf, BUFSIZ, "%d", nbar.cntdwn);
+ pthread_mutex_unlock(&nbar.mutex);
+ if (updatestring(win[STA].p, &buf, 0, 1) == 0 &&
+ is_all_digit(buf) && atoi(buf) >= 0
+ && atoi(buf) <= DAYINSEC) {
+ pthread_mutex_lock(&nbar.mutex);
+ nbar.cntdwn = atoi(buf);
+ pthread_mutex_unlock(&nbar.mutex);
+ }
+ 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(win[STA].p, &buf, 0, 1) == 0) {
+ pthread_mutex_lock(&nbar.mutex);
+ strncpy(nbar.cmd, buf, strlen(buf) + 1);
+ pthread_mutex_unlock(&nbar.mutex);
+ }
+ break;
+ case '6':
+ pthread_mutex_lock(&nbar.mutex);
+ nbar.notify_all = !nbar.notify_all;
+ pthread_mutex_unlock(&nbar.mutex);
+ notify_check_next_app(1);
+ break;
+ case '7':
+ dmon.enable = !dmon.enable;
+ break;
+ case '8':
+ dmon.log = !dmon.log;
+ break;
+ }
+
+ if (resize) {
+ resize = 0;
+ wins_get_config();
+ wins_reset();
+ reinit_conf_win(&cwin);
+ delwin(win[STA].p);
+ win[STA].p =
+ newwin(win[STA].h, win[STA].w, win[STA].y,
+ win[STA].x);
+ keypad(win[STA].p, TRUE);
+ if (notify_bar()) {
+ notify_reinit_bar();
+ notify_update_bar();
+ }
+ clearok(curscr, TRUE);
+ }
+
+ status_mesg(number_str, keys);
+ cwin.total_lines = print_config_options(cwin.pad.p);
+ wins_scrollwin_display(&cwin);
+ }
+ mem_free(buf);
+ wins_scrollwin_delete(&cwin);
}