From 5a5c6d2604664478306b29b64bf876d7403b74bb Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 29 Jul 2011 18:01:38 +0200 Subject: Add "force" parameter to notify_check_next_app() This allows to force notify_check_next_app() to update the notification appointment, even if start times are equal (e.g. if the item description was changed). Signed-off-by: Lukas Fleischer --- src/apoint.c | 4 ++-- src/calcurse.h | 2 +- src/notify.c | 14 ++++++++------ src/recur.c | 4 ++-- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/apoint.c b/src/apoint.c index ab3fab5..8771426 100644 --- a/src/apoint.c +++ b/src/apoint.c @@ -516,7 +516,7 @@ apoint_delete_bynum (long start, unsigned num, enum eraseflg flag) erase_note (&apt->note, flag); mem_free (apt); if (need_check_notify) - notify_check_next_app (); + notify_check_next_app (0); break; } @@ -663,7 +663,7 @@ apoint_switch_notify (void) if (notify_bar ()) notify_check_added (apt->mesg, apt->start, apt->state); if (need_chk_notify) - notify_check_next_app (); + notify_check_next_app (0); LLIST_TS_UNLOCK (&alist_p); } diff --git a/src/calcurse.h b/src/calcurse.h index e3822ef..383f53e 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -751,7 +751,7 @@ void notify_update_bar (void); unsigned notify_get_next (struct notify_app *); unsigned notify_get_next_bkgd (void); char *notify_app_txt (void); -void notify_check_next_app (void); +void notify_check_next_app (int); void notify_check_added (char *, long, char); void notify_check_repeated (struct recur_apoint *); int notify_same_item (long); diff --git a/src/notify.c b/src/notify.c index 14a5f0c..6fedb71 100644 --- a/src/notify.c +++ b/src/notify.c @@ -306,7 +306,7 @@ notify_update_bar (void) notify_app.got_app = 0; pthread_mutex_unlock (¬ify_app.mutex); pthread_mutex_unlock (¬ify.mutex); - notify_check_next_app (); + notify_check_next_app (0); return; } } @@ -353,7 +353,7 @@ notify_main_thread (void *arg) got_app = notify_app.got_app; pthread_mutex_unlock (¬ify_app.mutex); if (!got_app) - notify_check_next_app (); + notify_check_next_app (0); } } pthread_exit ((void *) 0); @@ -427,6 +427,7 @@ 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 ((void *)0); @@ -439,7 +440,7 @@ notify_thread_app (void *arg) } else { - if (!notify_same_item (tmp_app.time)) + if (force || !notify_same_item (tmp_app.time)) { pthread_mutex_lock (¬ify_app.mutex); notify_update_app (tmp_app.time, tmp_app.state, tmp_app.txt); @@ -456,12 +457,13 @@ notify_thread_app (void *arg) /* Launch the thread notify_thread_app to look for next appointment. */ void -notify_check_next_app (void) +notify_check_next_app (int force) { pthread_t notify_t_app; + void *arg = (force ? (void *)1 : (void *)0); pthread_create (¬ify_t_app, &detached_thread_attr, notify_thread_app, - (void *)0); + arg); return; } @@ -566,7 +568,7 @@ void notify_start_main_thread (void) { pthread_create (¬ify_t_main, NULL, notify_main_thread, NULL); - notify_check_next_app (); + notify_check_next_app (0); } /* diff --git a/src/recur.c b/src/recur.c index 430e543..b2980fc 100644 --- a/src/recur.c +++ b/src/recur.c @@ -811,7 +811,7 @@ recur_apoint_erase (long start, unsigned num, unsigned delete_whole, erase_note (&rapt->note, flag); mem_free (rapt); if (need_check_notify) - notify_check_next_app (); + notify_check_next_app (0); break; } } @@ -819,7 +819,7 @@ recur_apoint_erase (long start, unsigned num, unsigned delete_whole, { recur_add_exc (&rapt->exc, start); if (need_check_notify) - notify_check_next_app (); + notify_check_next_app (0); } LLIST_TS_UNLOCK (&recur_alist_p); } -- cgit v1.2.3-54-g00ecf From cce0acbe007b346afdebe0e9ba5dedf72b2eaf53 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 29 Jul 2011 18:04:54 +0200 Subject: Update the notification item in day_edit_item() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensure the start time as well as the description of the notification appointment are synced after editing it. We use notify_check_next_app()'s force parameter to ensure that the notification item is updated even if only the description was modified. Reported-by: Andraž 'ruskie' Levstik Signed-off-by: Lukas Fleischer --- src/day.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/day.c b/src/day.c index 4c73f43..7e2f6fb 100644 --- a/src/day.c +++ b/src/day.c @@ -772,6 +772,7 @@ day_edit_item (struct conf *conf) struct apoint *a; long date; int item_num, ch; + int need_check_notify = 0; item_num = apoint_hilt (); p = day_get_item (item_num); @@ -811,15 +812,19 @@ day_edit_item (struct conf *conf) switch (ch) { case STRT: + need_check_notify = 1; update_start_time (&ra->start, &ra->dur); break; case END: update_duration (&ra->start, &ra->dur); break; case DESC: + if (notify_bar ()) + need_check_notify = notify_same_recur_item (ra); update_desc (&ra->mesg); break; case REPT: + need_check_notify = 1; update_rept (&ra->rpt, ra->start, conf); break; case KEY_GENERIC_CANCEL: @@ -835,12 +840,15 @@ day_edit_item (struct conf *conf) switch (ch) { case STRT: + need_check_notify = 1; update_start_time (&a->start, &a->dur); break; case END: update_duration (&a->start, &a->dur); break; case DESC: + if (notify_bar ()) + need_check_notify = notify_same_item (a->start); update_desc (&a->mesg); break; case KEY_GENERIC_CANCEL: @@ -848,6 +856,9 @@ day_edit_item (struct conf *conf) } break; } + + if (need_check_notify) + notify_check_next_app (1); } /* -- cgit v1.2.3-54-g00ecf From 0126cbd1b3fd1ee46ce3c6f01fef92761c2193c7 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 29 Jul 2011 18:26:58 +0200 Subject: Update the notification item in *_paste_item() Signed-off-by: Lukas Fleischer --- src/apoint.c | 4 ++++ src/recur.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/apoint.c b/src/apoint.c index 8771426..859e807 100644 --- a/src/apoint.c +++ b/src/apoint.c @@ -729,5 +729,9 @@ apoint_paste_item (void) (void)apoint_new (bkp_cut_apoint.mesg, bkp_cut_apoint.note, bkp_start, bkp_cut_apoint.dur, bkp_cut_apoint.state); + + if (notify_bar ()) + notify_check_added (bkp_cut_apoint.mesg, bkp_start, bkp_cut_apoint.state); + apoint_free_bkp (ERASE_FORCE_KEEP_NOTE); } diff --git a/src/recur.c b/src/recur.c index b2980fc..50e2beb 100644 --- a/src/recur.c +++ b/src/recur.c @@ -1144,5 +1144,9 @@ recur_apoint_paste_item (void) bkp_cut_recur_apoint.rpt->freq, bkp_cut_recur_apoint.rpt->until, &bkp_cut_recur_apoint.exc); + + if (notify_bar ()) + notify_check_repeated (&bkp_cut_recur_apoint); + recur_apoint_free_bkp (ERASE_FORCE_KEEP_NOTE); } -- cgit v1.2.3-54-g00ecf From 1da88589b22ddd4b8525c09fe4519ce1067687cb Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 29 Jul 2011 19:05:18 +0200 Subject: Fix recurrent appointment notification We probably broke this in 9fab24818a119aef08b9726f6c1cd31d5434ce34. Signed-off-by: Lukas Fleischer --- src/recur.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/recur.c b/src/recur.c index 50e2beb..caa5ec3 100644 --- a/src/recur.c +++ b/src/recur.c @@ -1004,9 +1004,9 @@ recur_exc_scan (llist_t *lexc, FILE *data_file) } static int -recur_apoint_starts_after (struct recur_apoint *rapt, long time) +recur_apoint_starts_before (struct recur_apoint *rapt, long time) { - return (rapt->start > time); + return (rapt->start < time); } /* @@ -1020,9 +1020,7 @@ recur_apoint_check_next (struct notify_app *app, long start, long day) long real_recur_start_time; LLIST_TS_LOCK (&recur_alist_p); - i = LLIST_TS_FIND_FIRST (&recur_alist_p, start, recur_apoint_starts_after); - - if (i) + LLIST_TS_FIND_FOREACH (&recur_alist_p, app->time, recur_apoint_starts_before, i) { struct recur_apoint *rapt = LLIST_TS_GET_DATA (i); @@ -1035,7 +1033,6 @@ recur_apoint_check_next (struct notify_app *app, long start, long day) app->got_app = 1; } } - LLIST_TS_UNLOCK (&recur_alist_p); return (app); -- cgit v1.2.3-54-g00ecf From 1a849cfb8e32c88ca795551bdc5c01716d44593f Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 29 Jul 2011 19:51:08 +0200 Subject: Fix notify_check_repeated() Remove the "current_time" check from the first if condition. As "greater than" relations (">") have higher precedence than assignments ("=") in C, this caused "real_app_time" to always be one or zero which definitely isn't what we want here. Reading further down, it turns out that we don't even need this comparison here, so we should be fine removing it. Signed-off-by: Lukas Fleischer --- src/notify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/notify.c b/src/notify.c index 6fedb71..1b7e924 100644 --- a/src/notify.c +++ b/src/notify.c @@ -510,7 +510,7 @@ notify_check_repeated (struct recur_apoint *i) pthread_mutex_lock (¬ify_app.mutex); if ((real_app_time = recur_item_inday (i->start, &i->exc, i->rpt->type, i->rpt->freq, i->rpt->until, - get_today ()) > current_time)) + get_today ()))) { if (!notify_app.got_app) { -- cgit v1.2.3-54-g00ecf From 709525cf8d545f039e99a033068c1242a3bc4a31 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Fri, 29 Jul 2011 20:22:54 +0200 Subject: Fix apoint_get() call in apoint_switch_notify() We passed the function arguments the wrong way round. This regression was introduced in commit 77ef3fe76e4ce4c9a990e8a5904ad2d83420ca02. Signed-off-by: Lukas Fleischer --- src/apoint.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apoint.c b/src/apoint.c index 859e807..6fd9e64 100644 --- a/src/apoint.c +++ b/src/apoint.c @@ -657,7 +657,7 @@ apoint_switch_notify (void) need_chk_notify = 0; LLIST_TS_LOCK (&alist_p); - struct apoint *apt = apoint_get (apoint_nb, date); + struct apoint *apt = apoint_get (date, apoint_nb); apt->state ^= APOINT_NOTIFY; if (notify_bar ()) -- cgit v1.2.3-54-g00ecf From 13a41f8e0a722f4491ad6256718227e7161b5896 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Sun, 24 Jul 2011 22:46:26 +0200 Subject: Fix sort order in app_arg() We used to iterate over the list of regular appointments and the list of recurrent appointments in separate loops, thus leading to recurrent appointments being printed first and regular appointments being printed afterwards, regardless of their start and end times. Merge these loops to coerce precedence of the start time. There's still a fair bit of hackery in here - we will fix that later. Signed-off-by: Lukas Fleischer --- src/args.c | 130 ++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 78 insertions(+), 52 deletions(-) diff --git a/src/args.c b/src/args.c index 652736a..e447997 100644 --- a/src/args.c +++ b/src/args.c @@ -351,7 +351,7 @@ static int app_arg (int add_line, struct date *day, long date, int print_note, struct conf *conf, regex_t *regex) { - llist_item_t *i; + llist_item_t *i, *j; long today; unsigned print_date = 1; int app_found = 0; @@ -417,72 +417,98 @@ app_arg (int add_line, struct date *day, long date, int print_note, } /* Same process is performed but this time on the appointments. */ + LLIST_TS_LOCK (&alist_p); LLIST_TS_LOCK (&recur_alist_p); - LLIST_TS_FIND_FOREACH (&recur_alist_p, today, recur_apoint_inday, i) - { - struct recur_apoint *ra = LLIST_TS_GET_DATA (i); - struct apoint *apt; - if (regex && regexec (regex, ra->mesg, 0, 0, 0) != 0) - continue; + /* + * Iterate over regular appointments and recurrent ones simultaneously (fixes + * http://lists.calcurse.org/bugs/msg00002.html). + */ + i = LLIST_TS_FIND_FIRST (&alist_p, today, apoint_inday); + j = LLIST_TS_FIND_FIRST (&recur_alist_p, today, recur_apoint_inday); + while (i || j) + { + struct apoint *apt = LLIST_TS_GET_DATA (i); + struct recur_apoint *ra = LLIST_TS_GET_DATA (j); - app_found = 1; - if (add_line) + while (i && regex && regexec (regex, apt->mesg, 0, 0, 0) != 0) { - fputs ("\n", stdout); - add_line = 0; + i = LLIST_TS_FIND_NEXT (i, today, apoint_inday); + apt = LLIST_TS_GET_DATA (i); } - if (print_date) + + while (j && regex && regexec (regex, ra->mesg, 0, 0, 0) != 0) { - arg_print_date (today, conf); - print_date = 0; + j = LLIST_TS_FIND_NEXT (j, today, recur_apoint_inday); + ra = LLIST_TS_GET_DATA (j); } - apt = apoint_recur_s2apoint_s (ra); - apoint_sec2str (apt, RECUR_APPT, today, apoint_start_time, - apoint_end_time); - mem_free (apt->mesg); - mem_free (apt); - fputs (" - ", stdout); - fputs (apoint_start_time, stdout); - fputs (" -> ", stdout); - fputs (apoint_end_time, stdout); - fputs ("\n\t", stdout); - fputs (ra->mesg, stdout); - fputs ("\n", stdout); - if (print_note && ra->note) - print_notefile (stdout, ra->note, 2); - } - LLIST_TS_UNLOCK (&recur_alist_p); - LLIST_TS_LOCK (&alist_p); - LLIST_TS_FIND_FOREACH (&alist_p, today, apoint_inday, i) - { - struct apoint *apt = LLIST_TS_GET_DATA (i); - if (regex && regexec (regex, apt->mesg, 0, 0, 0) != 0) - continue; + if (apt && ra) + { + if (apt->start <= recur_apoint_inday (ra, today)) + ra = NULL; + else + apt = NULL; + } - app_found = 1; - if (add_line) + if (apt) { + app_found = 1; + if (add_line) + { + fputs ("\n", stdout); + add_line = 0; + } + if (print_date) + { + arg_print_date (today, conf); + print_date = 0; + } + apoint_sec2str (apt, APPT, today, apoint_start_time, apoint_end_time); + fputs (" - ", stdout); + fputs (apoint_start_time, stdout); + fputs (" -> ", stdout); + fputs (apoint_end_time, stdout); + fputs ("\n\t", stdout); + fputs (apt->mesg, stdout); fputs ("\n", stdout); - add_line = 0; + if (print_note && apt->note) + print_notefile (stdout, apt->note, 2); + i = LLIST_TS_FIND_NEXT (i, today, apoint_inday); } - if (print_date) + else if (ra) { - arg_print_date (today, conf); - print_date = 0; + app_found = 1; + if (add_line) + { + fputs ("\n", stdout); + add_line = 0; + } + if (print_date) + { + arg_print_date (today, conf); + print_date = 0; + } + apt = apoint_recur_s2apoint_s (ra); + apoint_sec2str (apt, RECUR_APPT, today, apoint_start_time, + apoint_end_time); + mem_free (apt->mesg); + mem_free (apt); + fputs (" - ", stdout); + fputs (apoint_start_time, stdout); + fputs (" -> ", stdout); + fputs (apoint_end_time, stdout); + fputs ("\n\t", stdout); + fputs (ra->mesg, stdout); + fputs ("\n", stdout); + if (print_note && ra->note) + print_notefile (stdout, ra->note, 2); + apt = NULL; + j = LLIST_TS_FIND_NEXT (j, today, recur_apoint_inday); } - apoint_sec2str (apt, APPT, today, apoint_start_time, apoint_end_time); - fputs (" - ", stdout); - fputs (apoint_start_time, stdout); - fputs (" -> ", stdout); - fputs (apoint_end_time, stdout); - fputs ("\n\t", stdout); - fputs (apt->mesg, stdout); - fputs ("\n", stdout); - if (print_note && apt->note) - print_notefile (stdout, apt->note, 2); } + + LLIST_TS_UNLOCK (&recur_alist_p); LLIST_TS_UNLOCK (&alist_p); return (app_found); -- cgit v1.2.3-54-g00ecf