From 45417bc6f0b6a38754bc707608c9b377d006cdfd Mon Sep 17 00:00:00 2001
From: Lukas Fleischer <calcurse@cryptocrack.de>
Date: Sun, 31 Jul 2011 02:04:18 +0200
Subject: Add configuration option to notify all appointments

If "notify-all" is enabled, all non-flagged appointments will be
notified (instead of flagged ones). This is useful for users that want
to be notified of everything.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
---
 src/calcurse.h |  1 +
 src/custom.c   |  5 +++++
 src/io.c       |  4 ++++
 src/notify.c   | 26 +++++++++++++++++++++-----
 4 files changed, 31 insertions(+), 5 deletions(-)

(limited to 'src')

diff --git a/src/calcurse.h b/src/calcurse.h
index 1a63657..b1b8e75 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -466,6 +466,7 @@ struct nbar {
   char             timefmt[BUFSIZ];  /* format for displaying time */
   char             cmd[BUFSIZ];      /* notification command */
   char            *shell;            /* user shell to launch notif. cmd */
+  unsigned         notify_all;       /* notify all appointments */
   pthread_mutex_t  mutex;
 };
 
diff --git a/src/custom.c b/src/custom.c
index 6385593..b2679d2 100644
--- a/src/custom.c
+++ b/src/custom.c
@@ -59,6 +59,7 @@ enum conf_var {
   CUSTOM_CONF_NOTIFYBARCLOCK,
   CUSTOM_CONF_NOTIFYBARWARNING,
   CUSTOM_CONF_NOTIFYBARCOMMAND,
+  CUSTOM_CONF_NOTIFYALL,
   CUSTOM_CONF_OUTPUTDATEFMT,
   CUSTOM_CONF_INPUTDATEFMT,
   CUSTOM_CONF_DMON_ENABLE,
@@ -89,6 +90,7 @@ static struct conf_varname conf_varmap[] =
   { CUSTOM_CONF_NOTIFYBARCLOCK, "notify-bar_clock" },
   { CUSTOM_CONF_NOTIFYBARWARNING, "notify-bar_warning" },
   { CUSTOM_CONF_NOTIFYBARCOMMAND, "notify-bar_command" },
+  { CUSTOM_CONF_NOTIFYALL, "notify-all" },
   { CUSTOM_CONF_OUTPUTDATEFMT, "output_datefmt" },
   { CUSTOM_CONF_INPUTDATEFMT, "input_datefmt" },
   { CUSTOM_CONF_DMON_ENABLE, "notify-daemon_enable" },
@@ -338,6 +340,9 @@ custom_set_conf (struct conf *conf, enum conf_var var, char *val)
     case CUSTOM_CONF_NOTIFYBARCOMMAND:
       (void)strncpy (nbar.cmd, val, strlen (val) + 1);
       break;
+    case CUSTOM_CONF_NOTIFYALL:
+      return conf_parse_bool (&nbar.notify_all, val);
+      break;
     case CUSTOM_CONF_OUTPUTDATEFMT:
       if (val[0] != '\0')
         (void)strncpy (conf->output_datefmt, val, strlen (val) + 1);
diff --git a/src/io.c b/src/io.c
index d59aeac..d8af1fb 100644
--- a/src/io.c
+++ b/src/io.c
@@ -944,6 +944,10 @@ io_save_conf (struct conf *conf)
   (void)fprintf (fp, "notify-bar_command=");
   (void)fprintf (fp, "%s\n", nbar.cmd);
 
+  (void)fprintf (fp, "\n# Notify all appointments instead of flagged ones only\n");
+  (void)fprintf (fp, "notify-all=");
+  (void)fprintf (fp, "%s\n", (nbar.notify_all) ? "yes" : "no");
+
   (void)fprintf (fp, "\n# Format of the date to be displayed "
                  "in non-interactive mode :\n");
   (void)fprintf (fp, "output_datefmt=");
diff --git a/src/notify.c b/src/notify.c
index 1b7e924..590a3e4 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;
@@ -132,6 +133,8 @@ notify_init_vars (void)
   if ((nbar.shell = getenv ("SHELL")) == NULL)
     nbar.shell = "/bin/sh";
 
+  nbar.notify_all = 0;
+
   (void)pthread_attr_init (&detached_thread_attr);
   (void)pthread_attr_setdetachstate (&detached_thread_attr,
                                      PTHREAD_CREATE_DETACHED);
@@ -281,7 +284,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;
@@ -619,7 +624,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
   {
@@ -647,6 +652,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)");
 
@@ -663,12 +671,14 @@ print_config_options (WINDOW *optwin)
 
   /* 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++)
     {
@@ -797,9 +807,15 @@ notify_config_bar (void)
             }
           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;
         }
-- 
cgit v1.2.3-70-g09d2