aboutsummaryrefslogtreecommitdiffstats
path: root/src/notify.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/notify.c')
-rw-r--r--src/notify.c102
1 files changed, 59 insertions, 43 deletions
diff --git a/src/notify.c b/src/notify.c
index 188d92c..6529087 100644
--- a/src/notify.c
+++ b/src/notify.c
@@ -80,7 +80,8 @@ unsigned
notify_needs_reminder (void)
{
if (notify_app.got_app
- && (notify_app.state & APOINT_NOTIFY)
+ && (((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;
@@ -111,7 +112,7 @@ notify_bar (void)
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. */
@@ -125,16 +126,17 @@ notify_init_vars (void)
pthread_mutex_init (&nbar.mutex, NULL);
nbar.show = 1;
nbar.cntdwn = 300;
- (void)strncpy (nbar.datefmt, date_format, strlen (date_format) + 1);
- (void)strncpy (nbar.timefmt, time_format, strlen (time_format) + 1);
- (void)strncpy (nbar.cmd, cmd, strlen (cmd) + 1);
+ 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";
- (void)pthread_attr_init (&detached_thread_attr);
- (void)pthread_attr_setdetachstate (&detached_thread_attr,
- PTHREAD_CREATE_DETACHED);
+ nbar.notify_all = 0;
+
+ 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. */
@@ -226,7 +228,7 @@ notify_launch_cmd (void)
else if (pid == 0)
{
/* Child: launch user defined command */
- if (execlp (nbar.shell, nbar.shell, "-c", nbar.cmd, (char *)0) < 0)
+ if (execlp (nbar.shell, nbar.shell, "-c", nbar.cmd, NULL) < 0)
{
ERROR_MSG (_("error while launching command"));
_exit (1);
@@ -272,7 +274,7 @@ notify_update_bar (void)
too_long = 1;
shrink_len = txt_max_len > 3 ? txt_max_len - 3 : 1;
- (void)strncpy (buf, notify_app.txt, shrink_len);
+ strncpy (buf, notify_app.txt, shrink_len);
buf[shrink_len] = '\0';
}
time_left = notify_time_left ();
@@ -284,7 +286,9 @@ notify_update_bar (void)
minutes_left = (time_left - hours_left * HOURINSEC) / MININSEC;
pthread_mutex_lock (&nbar.mutex);
- if (time_left < nbar.cntdwn && (notify_app.state & APOINT_NOTIFY))
+ 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;
@@ -301,7 +305,7 @@ notify_update_bar (void)
wattroff (notify.win, A_BLINK);
if (blinking)
- (void)notify_launch_cmd ();
+ notify_launch_cmd ();
pthread_mutex_unlock (&nbar.mutex);
}
else
@@ -359,7 +363,7 @@ notify_main_thread (void *arg)
notify_check_next_app (0);
}
}
- pthread_exit ((void *) 0);
+ pthread_exit (NULL);
}
/* Fill the given structure with information about next appointment. */
@@ -376,9 +380,9 @@ notify_get_next (struct notify_app *a)
a->time = current_time + DAYINSEC;
a->got_app = 0;
a->state = 0;
- a->txt = (char *)0;
- (void)recur_apoint_check_next (a, current_time, get_today ());
- (void)apoint_check_next (a, current_time);
+ a->txt = NULL;
+ recur_apoint_check_next (a, current_time, get_today ());
+ apoint_check_next (a, current_time);
return 1;
}
@@ -392,7 +396,7 @@ notify_get_next_bkgd (void)
{
struct notify_app a;
- a.txt = (char *)0;
+ a.txt = NULL;
if (!notify_get_next (&a))
return 0;
@@ -421,7 +425,7 @@ notify_app_txt (void)
if (notify_app.got_app)
return notify_app.txt;
else
- return (char *)0;
+ return NULL;
}
/* Look for the next appointment within the next 24 hours. */
@@ -433,7 +437,7 @@ notify_thread_app (void *arg)
int force = (arg ? 1 : 0);
if (!notify_get_next (&tmp_app))
- pthread_exit ((void *)0);
+ pthread_exit (NULL);
if (!tmp_app.got_app)
{
@@ -455,7 +459,7 @@ notify_thread_app (void *arg)
mem_free (tmp_app.txt);
notify_update_bar ();
- pthread_exit ((void *) 0);
+ pthread_exit (NULL);
}
/* Launch the thread notify_thread_app to look for next appointment. */
@@ -463,7 +467,7 @@ void
notify_check_next_app (int force)
{
pthread_t notify_t_app;
- void *arg = (force ? (void *)1 : (void *)0);
+ void *arg = (force ? (void *)1 : NULL);
pthread_create (&notify_t_app, &detached_thread_attr, notify_thread_app,
arg);
@@ -505,15 +509,15 @@ notify_check_added (char *mesg, long start, char state)
void
notify_check_repeated (struct recur_apoint *i)
{
- long real_app_time;
+ unsigned real_app_time;
int update_notify = 0;
time_t current_time;
current_time = time (NULL);
pthread_mutex_lock (&notify_app.mutex);
- if ((real_app_time = recur_item_inday (i->start, &i->exc, i->rpt->type,
- i->rpt->freq, i->rpt->until,
- get_today ())))
+ 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)
{
@@ -554,10 +558,11 @@ int
notify_same_recur_item (struct recur_apoint *i)
{
int same = 0;
- long item_start = 0;
+ unsigned item_start = 0;
- item_start = recur_item_inday (i->start, &i->exc, i->rpt->type,
- i->rpt->freq, i->rpt->until, get_today ());
+ 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;
@@ -602,7 +607,7 @@ print_option (WINDOW *win, unsigned x, unsigned y, char *name,
{
char buf[BUFSIZ];
- (void)strncpy (buf, valstr, maxlen - 1);
+ strncpy (buf, valstr, maxlen - 1);
buf[maxlen - 1] = '\0';
mvwprintw (win, y, x_opt, "%s...", buf);
}
@@ -622,7 +627,7 @@ print_config_options (WINDOW *optwin)
const int YOFF = 3;
enum
- { SHOW, DATE, CLOCK, WARN, CMD, DMON, DMON_LOG, NB_OPT };
+ { SHOW, DATE, CLOCK, WARN, CMD, NOTIFY_ALL, DMON, DMON_LOG, NB_OPT };
struct opt_s
{
@@ -650,6 +655,9 @@ print_config_options (WINDOW *optwin)
opt[CMD].name = _("notify-bar_command = ");
opt[CMD].desc = _("(Command used to notify user of an upcoming appointment)");
+ opt[NOTIFY_ALL].name = _("notify-all = ");
+ opt[NOTIFY_ALL].desc = _("(Notify all appointments instead of flagged ones only)");
+
opt[DMON].name = _("notify-daemon_enable = ");
opt[DMON].desc = _("(Run in background to get notifications after exiting)");
@@ -659,19 +667,21 @@ print_config_options (WINDOW *optwin)
pthread_mutex_lock (&nbar.mutex);
/* String value options */
- (void)strncpy (opt[DATE].valstr, nbar.datefmt, BUFSIZ);
- (void)strncpy (opt[CLOCK].valstr, nbar.timefmt, BUFSIZ);
- (void)snprintf (opt[WARN].valstr, BUFSIZ, "%d", nbar.cntdwn);
- (void)strncpy (opt[CMD].valstr, nbar.cmd, BUFSIZ);
+ 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);
opt[DMON].valnum = dmon.enable;
opt[DMON_LOG].valnum = dmon.log;
- opt[SHOW].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++)
{
@@ -719,7 +729,7 @@ notify_config_bar (void)
clear ();
custom_set_swsiz (&cwin);
- (void)snprintf (cwin.label, BUFSIZ, _("notification options"));
+ strncpy (cwin.label, _("notification options"), BUFSIZ);
wins_scrollwin_init (&cwin);
wins_show (cwin.win.p, cwin.label);
status_mesg (number_str, keys);
@@ -753,24 +763,24 @@ notify_config_bar (void)
case '2':
status_mesg (date_str, "");
pthread_mutex_lock (&nbar.mutex);
- (void)strncpy (buf, nbar.datefmt, strlen (nbar.datefmt) + 1);
+ 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);
- (void)strncpy (nbar.datefmt, buf, strlen (buf) + 1);
+ strncpy (nbar.datefmt, buf, strlen (buf) + 1);
pthread_mutex_unlock (&nbar.mutex);
}
break;
case '3':
status_mesg (time_str, "");
pthread_mutex_lock (&nbar.mutex);
- (void)strncpy (buf, nbar.timefmt, strlen (nbar.timefmt) + 1);
+ 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);
- (void)strncpy (nbar.timefmt, buf, strlen (buf) + 1);
+ strncpy (nbar.timefmt, buf, strlen (buf) + 1);
pthread_mutex_unlock (&nbar.mutex);
}
break;
@@ -790,19 +800,25 @@ notify_config_bar (void)
case '5':
status_mesg (cmd_str, "");
pthread_mutex_lock (&nbar.mutex);
- (void)strncpy (buf, nbar.cmd, strlen (nbar.cmd) + 1);
+ 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);
- (void)strncpy (nbar.cmd, buf, strlen (buf) + 1);
+ strncpy (nbar.cmd, buf, strlen (buf) + 1);
pthread_mutex_unlock (&nbar.mutex);
}
break;
case '6':
- dmon.enable = !dmon.enable;
+ 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;
}