void tmplput_CtxICalPropertyDate(StrBuf *Target, WCTemplputParams *TP) { icalproperty *p = (icalproperty *) CTX(CTX_ICALPROPERTY); struct icaltimetype t; time_t tt; char buf[256]; long len; t = icalproperty_get_dtend(p); tt = icaltime_as_timet(t); len = webcit_fmt_date(buf, sizeof(buf), tt, DATEFMT_FULL); StrBufAppendBufPlain(Target, buf, len, 0); }
void MainWindow::loadFromIcsFile() { char* line; icalcomponent *c; icalparser *parser = icalparser_new(); FILE* stream = fopen("/home/quentin/Public/test.ics", "r"); icalparser_set_gen_data(parser, stream); do { line = icalparser_get_line(parser, read_stream); c = icalparser_add_line(parser, line); if (c != 0) { icalcomponent *inner = icalcomponent_get_first_component(c, ICAL_ANY_COMPONENT); while (inner != NULL) { if (icalcomponent_isa(inner) == ICAL_VTODO_COMPONENT) { const char* name = icalcomponent_get_summary(inner); const char* uid = icalcomponent_get_uid(inner); icalproperty *p = icalcomponent_get_first_property(inner, ICAL_RELATEDTO_PROPERTY); const char* parent = icalproperty_get_relatedto(p); addTask(name, uid, parent); } if (icalcomponent_isa(inner) == ICAL_VEVENT_COMPONENT) { const char* name = icalcomponent_get_summary(inner); const char* uid = icalcomponent_get_uid(inner); icalproperty *p = icalcomponent_get_first_property(inner, ICAL_RELATEDTO_PROPERTY); const char* parent = icalproperty_get_relatedto(p); p = icalcomponent_get_first_property(inner, ICAL_DTSTART_PROPERTY); icaltimetype start = icalproperty_get_dtstart(p); p = icalcomponent_get_first_property(inner, ICAL_DTEND_PROPERTY); icaltimetype end = icalproperty_get_dtend(p); Task* task = findTask(parent); addEvent(task, uid, name, start, end); } inner = icalcomponent_get_next_component(c, ICAL_ANY_COMPONENT); } } } while (line != 0); }
void tmplput_ICalDate(StrBuf *Target, WCTemplputParams *TP) { icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL); icalproperty *p; icalproperty_kind Kind; struct icaltimetype t; time_t tt; char buf[256]; Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 0, ICAL_ANY_PROPERTY); p = icalcomponent_get_first_property(cal, Kind); if (p != NULL) { long len; t = icalproperty_get_dtend(p); tt = icaltime_as_timet(t); len = webcit_fmt_date(buf, 256, tt, DATEFMT_FULL); StrBufAppendBufPlain(Target, buf, len, 0); } }
int cond_ICalHaveTimeItem(StrBuf *Target, WCTemplputParams *TP) { icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL); icalproperty *p; icalproperty_kind Kind; Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 2, ICAL_ANY_PROPERTY); p = icalcomponent_get_first_property(cal, Kind); if (p != NULL) { struct icaltimetype *t; struct icaltimetype tt; WCTemplputParams *DynamicTP; DynamicTP = (WCTemplputParams*) malloc(sizeof(WCTemplputParams) + sizeof(struct icaltimetype)); t = (struct icaltimetype *) &DynamicTP[1]; memset(&tt, 0, sizeof(struct icaltimetype)); switch (Kind) { case ICAL_DTSTART_PROPERTY: tt = icalproperty_get_dtstart(p); break; case ICAL_DTEND_PROPERTY: tt = icalproperty_get_dtend(p); break; default: break; } memcpy(t, &tt, sizeof(struct icaltimetype)); StackDynamicContext (TP, DynamicTP, t, CTX_ICALTIME, 0, TP->Tokens, ReleaseIcalTimeCtx, TP->Tokens->Params[1]->lvalue); return 1; } return 0; }
static ECellDateEditValue * get_dtend (ECalModelCalendar *model, ECalModelComponent *comp_data) { struct icaltimetype tt_end; if (!comp_data->dtend) { icalproperty *prop; icaltimezone *zone = NULL, *model_zone = NULL; gboolean got_zone = FALSE; prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DTEND_PROPERTY); if (!prop) return NULL; tt_end = icalproperty_get_dtend (prop); if (icaltime_get_tzid (tt_end) && e_cal_client_get_timezone_sync (comp_data->client, icaltime_get_tzid (tt_end), &zone, NULL, NULL)) got_zone = TRUE; model_zone = e_cal_model_get_timezone (E_CAL_MODEL (model)); if (got_zone) { tt_end = icaltime_from_timet_with_zone (comp_data->instance_end, tt_end.is_date, zone); if (model_zone) icaltimezone_convert_time (&tt_end, zone, model_zone); } else { tt_end = icaltime_from_timet_with_zone ( comp_data->instance_end, tt_end.is_date, model_zone); } if (!icaltime_is_valid_time (tt_end) || icaltime_is_null_time (tt_end)) return NULL; if (tt_end.is_date && icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DTSTART_PROPERTY)) { struct icaltimetype tt_start; icaltimezone *start_zone = NULL; gboolean got_start_zone = FALSE; tt_start = icalproperty_get_dtstart (prop); if (icaltime_get_tzid (tt_start) && e_cal_client_get_timezone_sync (comp_data->client, icaltime_get_tzid (tt_start), &start_zone, NULL, NULL)) got_start_zone = TRUE; if (got_start_zone) { tt_start = icaltime_from_timet_with_zone (comp_data->instance_start, tt_start.is_date, start_zone); if (model_zone) icaltimezone_convert_time (&tt_start, start_zone, model_zone); } else { tt_start = icaltime_from_timet_with_zone ( comp_data->instance_start, tt_start.is_date, model_zone); } icaltime_adjust (&tt_start, 1, 0, 0, 0); /* Decrease by a day only if the DTSTART will still be before, or the same as, DTEND */ if (icaltime_compare (tt_start, tt_end) <= 0) icaltime_adjust (&tt_end, -1, 0, 0, 0); } comp_data->dtend = g_new0 (ECellDateEditValue, 1); comp_data->dtend->tt = tt_end; if (got_zone) comp_data->dtend->zone = zone; else comp_data->dtend->zone = NULL; } return e_cal_model_copy_cell_date_value (comp_data->dtend); }