Index: src/ical-code.c =================================================================== --- src/ical-code.c (revision 25298) +++ src/ical-code.c (working copy) @@ -83,10 +83,13 @@ static icalcomponent *ical = NULL, *aical = NULL; +static time_t ical_last_change = (time_t)0; + typedef struct _foreign_ical_files {; icalset *fical; icalcomponent *ical; + time_t ical_last_change; } foreign_ical_files; static foreign_ical_files f_ical[10]; @@ -3532,3 +3535,66 @@ gtk_widget_destroy(window); return(changed); } + +static gboolean xfical_refresher_run(gpointer user_data) +{ + struct stat s; + gint i; + gboolean changes_present = FALSE; + + + /* check internal file */ + if (stat(g_par.orage_file, &s) < 0) { + g_warning("stat of %s failed: %d (%s)", + g_par.orage_file, errno, strerror(errno)); + } + else if (s.st_mtime > ical_last_change) { + ical_last_change = s.st_mtime; + orage_message("updating %s", g_par.orage_file); + changes_present = TRUE; + } + + /* check foreign files */ + for (i = 0; i < g_par.foreign_count; i++) { + if (stat(g_par.foreign_data[i].file, &s) < 0) { + g_warning("stat of %s failed: %d (%s)", + g_par.foreign_data[i].file, errno, strerror(errno)); + } + else if (s.st_mtime > f_ical[i].ical_last_change) { + f_ical[i].ical_last_change = s.st_mtime; + orage_message("updating %s", g_par.foreign_data[i].file); + changes_present = TRUE; + } + } + + if (changes_present == TRUE) { + xfical_alarm_build_list(FALSE); + orage_mark_appointments(); + } + + /* keep running */ + return (TRUE); +} + +void xfical_init_refresher(void) +{ + static gint refresher_timeout_id = -1; + gint i = 0; + + if (refresher_timeout_id != -1) { + g_warning("refresher already initialized"); + return; + } + + /* init mtimes so that we don't do a useless update + * at start + */ + ical_last_change = time(NULL); + for (i = 0; i < g_par.foreign_count; i++) { + f_ical[i].ical_last_change = time(NULL); + } + + refresher_timeout_id = g_timeout_add(60*1000, + xfical_refresher_run, + NULL); +} Index: src/main.c =================================================================== --- src/main.c (revision 25298) +++ src/main.c (working copy) @@ -545,6 +545,9 @@ initialized = TRUE; process_args(argc, argv, running, initialized); + /* start files refresher timeout */ + xfical_init_refresher(); + gtk_main(); keep_tidy(); return(EXIT_SUCCESS); Index: src/ical-code.h =================================================================== --- src/ical-code.h (revision 25298) +++ src/ical-code.h (working copy) @@ -135,4 +135,6 @@ , gchar **tz); gboolean xfical_file_check(gchar *file_name); + +void xfical_init_refresher(void); #endif /* !__ICAL_CODE_H__ */