diff options
-rwxr-xr-x | ChangeLog | 6 | ||||
-rw-r--r-- | src/dmon.c | 5 | ||||
-rwxr-xr-x | src/notify.c | 42 | ||||
-rwxr-xr-x | src/notify.h | 3 |
4 files changed, 47 insertions, 9 deletions
@@ -14,6 +14,12 @@ * src/utils.c (exit_calcurse): start daemon only if requested * src/dmon.c (DMON_LOG): log daemon activity only if requested + + * src/notify.c (notify_needs_reminder): new function + + * src/notify.c (notify_get_next_bkgd) + * src/dmon.c (dmon_start): improved how the daemon checks for + appointments to remind 2009-07-29 Frederic Culot <frederic@culot.org> @@ -1,4 +1,4 @@ -/* $calcurse: dmon.c,v 1.10 2009/08/01 17:53:11 culot Exp $ */ +/* $calcurse: dmon.c,v 1.11 2009/08/01 20:29:49 culot Exp $ */ /* * Calcurse - text-based organizer @@ -190,8 +190,9 @@ dmon_start (int parent_exit_status) if (!notify_get_next_bkgd ()) DMON_ABRT (_("error loading next appointment\n")); + left = notify_time_left (); - if (left < nbar.cntdwn) + if (left > 0 && left < nbar.cntdwn && notify_needs_reminder ()) { DMON_LOG (_("launching notification at %s for: \"%s\"\n"), nowstr (), notify_app_txt ()); diff --git a/src/notify.c b/src/notify.c index 97fa9c8..7aa69ab 100755 --- a/src/notify.c +++ b/src/notify.c @@ -1,4 +1,4 @@ -/* $calcurse: notify.c,v 1.42 2009/08/01 13:31:20 culot Exp $ */ +/* $calcurse: notify.c,v 1.43 2009/08/01 20:29:49 culot Exp $ */ /* * Calcurse - text-based organizer @@ -76,6 +76,18 @@ notify_time_left (void) } /* + * Return 1 if the reminder was not sent already for the upcoming + * appointment. + */ +unsigned +notify_needs_reminder (void) +{ + if (notify_app.got_app & !(notify_app.state & APOINT_NOTIFIED)) + return 1; + return 0; +} + +/* * This is used to update the notify_app structure. * Note: the mutex associated with this structure must be locked by the * caller! @@ -164,6 +176,9 @@ 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; @@ -363,19 +378,34 @@ notify_get_next (struct notify_app_s *a) return 1; } +/* + * This is used for the daemon to check if we have an upcoming appointment or + * not. + */ unsigned notify_get_next_bkgd (void) { struct notify_app_s a; - - if (!notify_app.got_app) + + a.txt = (char *)0; + if (!notify_get_next (&a)) + return 0; + + if (!a.got_app) { - 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.txt) + mem_free (a.txt); + return 1; } diff --git a/src/notify.h b/src/notify.h index d8bcd21..0e21198 100755 --- a/src/notify.h +++ b/src/notify.h @@ -1,4 +1,4 @@ -/* $calcurse: notify.h,v 1.20 2009/08/01 13:31:21 culot Exp $ */ +/* $calcurse: notify.h,v 1.21 2009/08/01 20:29:50 culot Exp $ */ /* * Calcurse - text-based organizer @@ -64,6 +64,7 @@ struct notify_app_s }; int notify_time_left (void); +unsigned notify_needs_reminder (void); void notify_update_app (long, char, char *); int notify_bar (void); void notify_init_vars (void); |