Merge branch 'maint'

This commit is contained in:
Lukas Fleischer 2011-07-30 22:56:22 +02:00
commit 0884d62b22
6 changed files with 120 additions and 76 deletions

View File

@ -516,7 +516,7 @@ apoint_delete_bynum (long start, unsigned num, enum eraseflg flag)
erase_note (&apt->note, flag); erase_note (&apt->note, flag);
mem_free (apt); mem_free (apt);
if (need_check_notify) if (need_check_notify)
notify_check_next_app (); notify_check_next_app (0);
break; break;
} }
@ -657,13 +657,13 @@ apoint_switch_notify (void)
need_chk_notify = 0; need_chk_notify = 0;
LLIST_TS_LOCK (&alist_p); 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; apt->state ^= APOINT_NOTIFY;
if (notify_bar ()) if (notify_bar ())
notify_check_added (apt->mesg, apt->start, apt->state); notify_check_added (apt->mesg, apt->start, apt->state);
if (need_chk_notify) if (need_chk_notify)
notify_check_next_app (); notify_check_next_app (0);
LLIST_TS_UNLOCK (&alist_p); LLIST_TS_UNLOCK (&alist_p);
} }
@ -729,5 +729,9 @@ apoint_paste_item (void)
(void)apoint_new (bkp_cut_apoint.mesg, bkp_cut_apoint.note, (void)apoint_new (bkp_cut_apoint.mesg, bkp_cut_apoint.note,
bkp_start, bkp_cut_apoint.dur, bkp_start, bkp_cut_apoint.dur,
bkp_cut_apoint.state); 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); apoint_free_bkp (ERASE_FORCE_KEEP_NOTE);
} }

View File

@ -345,7 +345,7 @@ static int
app_arg (int add_line, struct date *day, long date, int print_note, app_arg (int add_line, struct date *day, long date, int print_note,
struct conf *conf, regex_t *regex) struct conf *conf, regex_t *regex)
{ {
llist_item_t *i; llist_item_t *i, *j;
long today; long today;
unsigned print_date = 1; unsigned print_date = 1;
int app_found = 0; int app_found = 0;
@ -411,15 +411,67 @@ app_arg (int add_line, struct date *day, long date, int print_note,
} }
/* Same process is performed but this time on the appointments. */ /* Same process is performed but this time on the appointments. */
LLIST_TS_LOCK (&alist_p);
LLIST_TS_LOCK (&recur_alist_p); LLIST_TS_LOCK (&recur_alist_p);
LLIST_TS_FIND_FOREACH (&recur_alist_p, today, recur_apoint_inday, i)
/*
* 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 recur_apoint *ra = LLIST_TS_GET_DATA (i); struct apoint *apt = LLIST_TS_GET_DATA (i);
struct apoint *apt; struct recur_apoint *ra = LLIST_TS_GET_DATA (j);
if (regex && regexec (regex, ra->mesg, 0, 0, 0) != 0) while (i && regex && regexec (regex, apt->mesg, 0, 0, 0) != 0)
continue; {
i = LLIST_TS_FIND_NEXT (i, today, apoint_inday);
apt = LLIST_TS_GET_DATA (i);
}
while (j && regex && regexec (regex, ra->mesg, 0, 0, 0) != 0)
{
j = LLIST_TS_FIND_NEXT (j, today, recur_apoint_inday);
ra = LLIST_TS_GET_DATA (j);
}
if (apt && ra)
{
if (apt->start <= recur_apoint_inday (ra, today))
ra = NULL;
else
apt = NULL;
}
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);
if (print_note && apt->note)
print_notefile (stdout, apt->note, 2);
i = LLIST_TS_FIND_NEXT (i, today, apoint_inday);
}
else if (ra)
{
app_found = 1; app_found = 1;
if (add_line) if (add_line)
{ {
@ -445,38 +497,12 @@ app_arg (int add_line, struct date *day, long date, int print_note,
fputs ("\n", stdout); fputs ("\n", stdout);
if (print_note && ra->note) if (print_note && ra->note)
print_notefile (stdout, ra->note, 2); print_notefile (stdout, ra->note, 2);
apt = NULL;
j = LLIST_TS_FIND_NEXT (j, today, recur_apoint_inday);
} }
}
LLIST_TS_UNLOCK (&recur_alist_p); 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;
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);
if (print_note && apt->note)
print_notefile (stdout, apt->note, 2);
}
LLIST_TS_UNLOCK (&alist_p); LLIST_TS_UNLOCK (&alist_p);
return (app_found); return (app_found);

View File

@ -768,7 +768,7 @@ void notify_update_bar (void);
unsigned notify_get_next (struct notify_app *); unsigned notify_get_next (struct notify_app *);
unsigned notify_get_next_bkgd (void); unsigned notify_get_next_bkgd (void);
char *notify_app_txt (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_added (char *, long, char);
void notify_check_repeated (struct recur_apoint *); void notify_check_repeated (struct recur_apoint *);
int notify_same_item (long); int notify_same_item (long);

View File

@ -781,6 +781,7 @@ day_edit_item (struct conf *conf)
struct apoint *a; struct apoint *a;
long date; long date;
int item_num, ch; int item_num, ch;
int need_check_notify = 0;
item_num = apoint_hilt (); item_num = apoint_hilt ();
p = day_get_item (item_num); p = day_get_item (item_num);
@ -820,15 +821,19 @@ day_edit_item (struct conf *conf)
switch (ch) switch (ch)
{ {
case STRT: case STRT:
need_check_notify = 1;
update_start_time (&ra->start, &ra->dur); update_start_time (&ra->start, &ra->dur);
break; break;
case END: case END:
update_duration (&ra->start, &ra->dur); update_duration (&ra->start, &ra->dur);
break; break;
case DESC: case DESC:
if (notify_bar ())
need_check_notify = notify_same_recur_item (ra);
update_desc (&ra->mesg); update_desc (&ra->mesg);
break; break;
case REPT: case REPT:
need_check_notify = 1;
update_rept (&ra->rpt, ra->start, conf); update_rept (&ra->rpt, ra->start, conf);
break; break;
case KEY_GENERIC_CANCEL: case KEY_GENERIC_CANCEL:
@ -844,12 +849,15 @@ day_edit_item (struct conf *conf)
switch (ch) switch (ch)
{ {
case STRT: case STRT:
need_check_notify = 1;
update_start_time (&a->start, &a->dur); update_start_time (&a->start, &a->dur);
break; break;
case END: case END:
update_duration (&a->start, &a->dur); update_duration (&a->start, &a->dur);
break; break;
case DESC: case DESC:
if (notify_bar ())
need_check_notify = notify_same_item (a->start);
update_desc (&a->mesg); update_desc (&a->mesg);
break; break;
case KEY_GENERIC_CANCEL: case KEY_GENERIC_CANCEL:
@ -857,6 +865,9 @@ day_edit_item (struct conf *conf)
} }
break; break;
} }
if (need_check_notify)
notify_check_next_app (1);
} }
/* /*

View File

@ -306,7 +306,7 @@ notify_update_bar (void)
notify_app.got_app = 0; notify_app.got_app = 0;
pthread_mutex_unlock (&notify_app.mutex); pthread_mutex_unlock (&notify_app.mutex);
pthread_mutex_unlock (&notify.mutex); pthread_mutex_unlock (&notify.mutex);
notify_check_next_app (); notify_check_next_app (0);
return; return;
} }
} }
@ -353,7 +353,7 @@ notify_main_thread (void *arg)
got_app = notify_app.got_app; got_app = notify_app.got_app;
pthread_mutex_unlock (&notify_app.mutex); pthread_mutex_unlock (&notify_app.mutex);
if (!got_app) if (!got_app)
notify_check_next_app (); notify_check_next_app (0);
} }
} }
pthread_exit ((void *) 0); pthread_exit ((void *) 0);
@ -427,6 +427,7 @@ static void *
notify_thread_app (void *arg) notify_thread_app (void *arg)
{ {
struct notify_app tmp_app; struct notify_app tmp_app;
int force = (arg ? 1 : 0);
if (!notify_get_next (&tmp_app)) if (!notify_get_next (&tmp_app))
pthread_exit ((void *)0); pthread_exit ((void *)0);
@ -439,7 +440,7 @@ notify_thread_app (void *arg)
} }
else else
{ {
if (!notify_same_item (tmp_app.time)) if (force || !notify_same_item (tmp_app.time))
{ {
pthread_mutex_lock (&notify_app.mutex); pthread_mutex_lock (&notify_app.mutex);
notify_update_app (tmp_app.time, tmp_app.state, tmp_app.txt); 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. */ /* Launch the thread notify_thread_app to look for next appointment. */
void void
notify_check_next_app (void) notify_check_next_app (int force)
{ {
pthread_t notify_t_app; pthread_t notify_t_app;
void *arg = (force ? (void *)1 : (void *)0);
pthread_create (&notify_t_app, &detached_thread_attr, notify_thread_app, pthread_create (&notify_t_app, &detached_thread_attr, notify_thread_app,
(void *)0); arg);
return; return;
} }
@ -508,7 +510,7 @@ notify_check_repeated (struct recur_apoint *i)
pthread_mutex_lock (&notify_app.mutex); pthread_mutex_lock (&notify_app.mutex);
if ((real_app_time = recur_item_inday (i->start, &i->exc, i->rpt->type, if ((real_app_time = recur_item_inday (i->start, &i->exc, i->rpt->type,
i->rpt->freq, i->rpt->until, i->rpt->freq, i->rpt->until,
get_today ()) > current_time)) get_today ())))
{ {
if (!notify_app.got_app) if (!notify_app.got_app)
{ {
@ -566,7 +568,7 @@ void
notify_start_main_thread (void) notify_start_main_thread (void)
{ {
pthread_create (&notify_t_main, NULL, notify_main_thread, NULL); pthread_create (&notify_t_main, NULL, notify_main_thread, NULL);
notify_check_next_app (); notify_check_next_app (0);
} }
/* /*

View File

@ -811,7 +811,7 @@ recur_apoint_erase (long start, unsigned num, unsigned delete_whole,
erase_note (&rapt->note, flag); erase_note (&rapt->note, flag);
mem_free (rapt); mem_free (rapt);
if (need_check_notify) if (need_check_notify)
notify_check_next_app (); notify_check_next_app (0);
break; break;
} }
} }
@ -819,7 +819,7 @@ recur_apoint_erase (long start, unsigned num, unsigned delete_whole,
{ {
recur_add_exc (&rapt->exc, start); recur_add_exc (&rapt->exc, start);
if (need_check_notify) if (need_check_notify)
notify_check_next_app (); notify_check_next_app (0);
} }
LLIST_TS_UNLOCK (&recur_alist_p); LLIST_TS_UNLOCK (&recur_alist_p);
} }
@ -1004,9 +1004,9 @@ recur_exc_scan (llist_t *lexc, FILE *data_file)
} }
static int 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; long real_recur_start_time;
LLIST_TS_LOCK (&recur_alist_p); LLIST_TS_LOCK (&recur_alist_p);
i = LLIST_TS_FIND_FIRST (&recur_alist_p, start, recur_apoint_starts_after); LLIST_TS_FIND_FOREACH (&recur_alist_p, app->time, recur_apoint_starts_before, i)
if (i)
{ {
struct recur_apoint *rapt = LLIST_TS_GET_DATA (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; app->got_app = 1;
} }
} }
LLIST_TS_UNLOCK (&recur_alist_p); LLIST_TS_UNLOCK (&recur_alist_p);
return (app); return (app);
@ -1144,5 +1141,9 @@ recur_apoint_paste_item (void)
bkp_cut_recur_apoint.rpt->freq, bkp_cut_recur_apoint.rpt->freq,
bkp_cut_recur_apoint.rpt->until, bkp_cut_recur_apoint.rpt->until,
&bkp_cut_recur_apoint.exc); &bkp_cut_recur_apoint.exc);
if (notify_bar ())
notify_check_repeated (&bkp_cut_recur_apoint);
recur_apoint_free_bkp (ERASE_FORCE_KEEP_NOTE); recur_apoint_free_bkp (ERASE_FORCE_KEEP_NOTE);
} }