aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/apoint.c10
-rw-r--r--src/args.c130
-rw-r--r--src/calcurse.h2
-rw-r--r--src/day.c11
-rw-r--r--src/notify.c16
-rw-r--r--src/recur.c17
6 files changed, 115 insertions, 71 deletions
diff --git a/src/apoint.c b/src/apoint.c
index ab3fab5..6fd9e64 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;
}
@@ -657,13 +657,13 @@ 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 ())
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);
}
@@ -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/args.c b/src/args.c
index dfa6835..060ac3d 100644
--- a/src/args.c
+++ b/src/args.c
@@ -345,7 +345,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;
@@ -411,72 +411,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);
diff --git a/src/calcurse.h b/src/calcurse.h
index ee8e2f9..1a63657 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -768,7 +768,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/day.c b/src/day.c
index 884d86b..458f06a 100644
--- a/src/day.c
+++ b/src/day.c
@@ -781,6 +781,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);
@@ -820,15 +821,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:
@@ -844,12 +849,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:
@@ -857,6 +865,9 @@ day_edit_item (struct conf *conf)
}
break;
}
+
+ if (need_check_notify)
+ notify_check_next_app (1);
}
/*
diff --git a/src/notify.c b/src/notify.c
index 14a5f0c..1b7e924 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 (&notify_app.mutex);
pthread_mutex_unlock (&notify.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 (&notify_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 (&notify_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 (&notify_t_app, &detached_thread_attr, notify_thread_app,
- (void *)0);
+ arg);
return;
}
@@ -508,7 +510,7 @@ notify_check_repeated (struct recur_apoint *i)
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 ()) > current_time))
+ get_today ())))
{
if (!notify_app.got_app)
{
@@ -566,7 +568,7 @@ void
notify_start_main_thread (void)
{
pthread_create (&notify_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 b757400..dbc52ee 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);
}
@@ -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);
@@ -1144,5 +1141,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);
}