icalset *icalcalendar_get_freebusy(icalcalendar *impl) { char path[MAXPATHLEN]; icalerror_check_arg_rz((impl != 0), "impl"); path[0] = '\0'; strncpy(path, impl->dir, MAXPATHLEN - 1); strncat(path, "/", MAXPATHLEN - strlen(path) - 1); strncat(path, FBLIST_FILE, MAXPATHLEN - strlen(path) - 1); path[MAXPATHLEN - 1] = '\0'; if (impl->freebusy == 0) { impl->freebusy = icalfileset_new(path); } return impl->freebusy; }
icalset *icalcalendar_get_properties(icalcalendar *impl) { char path[MAXPATHLEN]; icalerror_check_arg_rz((impl != 0), "impl"); path[0] = '\0'; strncpy(path, impl->dir, MAXPATHLEN - 1); strncat(path, "/", MAXPATHLEN - strlen(path) - 1); strncat(path, PROP_FILE, MAXPATHLEN - strlen(path) - 1); path[MAXPATHLEN - 1] = '\0'; if (impl->properties == 0) { impl->properties = icalfileset_new(path); } return impl->properties; }
void MainWindow::saveToIcsFile(icalcomponent *comp, std::string uid) { icalset* file = icalfileset_new("/home/quentin/Public/test.ics"); icalfileset *fset = (icalfileset*) file; icalcomponent* old = fetch(file, uid.c_str()); if (old != NULL) { icalcomponent_remove_component(icalcomponent_get_first_component(fset->cluster, ICAL_ANY_COMPONENT), old); } icalcomponent_add_component(icalcomponent_get_first_component(fset->cluster, ICAL_ANY_COMPONENT), comp); icalfileset_mark(file); icalfileset_commit(file); icalfileset_free(file); }
/** * Add all VTODO components in a file to a list of iCal todo entries. * @param ical_todos [in] Current list of iCal todo entries. * @param filename [in] Path of the iCal file. * @return List of iCal todo entries. */ GSList* read_vtodo_from_ical_file( GSList *ical_todos, const gchar *filename ) { icalset *ical_set; icalcomponent *component; icalcomponent *c; /* Create an iCalendar set based on contents of the specified file. */ ical_set = icalfileset_new( filename ); /* Construct a list of iCalendar todo entries based on the VTODO components in the iCalendar set. */ for( component = icalfileset_get_first_component( ical_set ); component != NULL; component = icalfileset_get_next_component( ical_set ) ) { /* If the iCalendar component has a VTODO subcomponent then copy the component into our iCalendar todo list. */ for( c = icalcomponent_get_first_component( component, ICAL_VTODO_COMPONENT ); c != NULL; c = icalcomponent_get_next_component( component, ICAL_VTODO_COMPONENT ) ) { { /* Add the component to the iCalendar todo list. */ ical_todos = g_slist_append( ical_todos, c ); } } icalcomponent_free( component ); } icalfileset_free( ical_set ); return( ical_todos ); }
int main(int c, char *argv[]){ icalset *clusterin, *clusterout = NULL; icalcomponent *itr; int count=0; int tostdout = 0; if(c < 2 || c > 3){ usage(argv[0]); exit(1); } if (c == 2){ tostdout = 1; } /*icalerror_set_error_state(ICAL_PARSE_ERROR, ICAL_ERROR_NONFATAL);*/ #ifdef SIGALRM signal(SIGALRM,sig_alrm); alarm(10); #endif clusterin = icalfileset_new(argv[1]); #ifdef SIGALRM alarm(0); #endif if (clusterin == 0){ printf("Could not open input cluster \"%s\"\n",argv[1]); if(icalerrno!= ICAL_NO_ERROR){ printf("Error: %s\n",icalerror_strerror(icalerrno)); } exit(1); } if (!tostdout){ #ifdef SIGALRM alarm(10); #endif clusterout = icalfileset_new(argv[2]); #ifdef SIGALRM alarm(0); #endif if (clusterout == 0){ printf("Could not open output cluster \"%s\"\n",argv[2]); exit(1); } } for (itr = icalset_get_first_component(clusterin); itr != 0; itr = icalset_get_next_component(clusterin)){ icalerror_set_error_state(ICAL_BADARG_ERROR, ICAL_ERROR_NONFATAL); icalrestriction_check(itr); icalerror_set_error_state(ICAL_BADARG_ERROR, ICAL_ERROR_DEFAULT); if (itr != 0){ if(tostdout){ printf("--------------\n%s\n",icalcomponent_as_ical_string(itr)); } else { icalfileset_add_component(clusterout, icalcomponent_new_clone(itr)); } count++; } else { printf("Got NULL component"); } } printf("Transfered %d components\n",count); icalset_free(clusterin); if (!tostdout){ icalfileset_mark(clusterout); icalset_free(clusterout); } return 0; }
int main(int argc, char *argv[]) { icalset *cin; struct icaltimetype next; icalcomponent *itr; icalproperty *desc, *dtstart, *rrule; struct icalrecurrencetype recur; icalrecur_iterator* ritr; time_t tt; char* file; icalerror_set_error_state(ICAL_PARSE_ERROR, ICAL_ERROR_NONFATAL); #ifndef WIN32 signal(SIGALRM,sig_alrm); #endif if (argc <= 1) { file = "../../test-data/recur.txt"; } else if (argc == 2) { file = argv[1]; } else { fprintf(stderr,"usage: recur [input file]\n"); exit(1); } #ifndef WIN32 alarm(300); /* to get file lock */ #endif cin = icalfileset_new(file); #ifndef WIN32 alarm(0); #endif if(cin == 0) { fprintf(stderr,"recur: can't open file %s\n",file); exit(1); } for (itr = icalfileset_get_first_component(cin); itr != 0; itr = icalfileset_get_next_component(cin)) { struct icaltimetype start = icaltime_from_timet(1,0); struct icaltimetype end = icaltime_today(); desc = icalcomponent_get_first_property(itr,ICAL_DESCRIPTION_PROPERTY); dtstart = icalcomponent_get_first_property(itr,ICAL_DTSTART_PROPERTY); rrule = icalcomponent_get_first_property(itr,ICAL_RRULE_PROPERTY); if (desc == 0 || dtstart == 0 || rrule == 0) { printf("\n******** Error in input component ********\n"); printf("The following component is malformed:\n %s\n", icalcomponent_as_ical_string(itr)); continue; } printf("\n\n#### %s\n",icalproperty_get_description(desc)); printf("#### %s\n",icalvalue_as_ical_string(icalproperty_get_value(rrule))); recur = icalproperty_get_rrule(rrule); start = icalproperty_get_dtstart(dtstart); ritr = icalrecur_iterator_new(recur,start); tt = icaltime_as_timet(start); printf("#### %s\n",ctime(&tt )); icalrecur_iterator_free(ritr); for(ritr = icalrecur_iterator_new(recur,start), next = icalrecur_iterator_next(ritr); !icaltime_is_null_time(next); next = icalrecur_iterator_next(ritr)) { tt = icaltime_as_timet(next); printf(" %s",ctime(&tt )); } icalrecur_iterator_free(ritr); icalcomponent_foreach_recurrence(itr, start, end, recur_callback, NULL); } icalset_free(cin); icaltimezone_free_builtin_timezones(); icalmemory_free_ring(); free_zone_directory(); return 0; }