icalcomponent * icalcap_component_new_from_string(const char *data) { icalcomponent *ret = NULL; char *mtype; /* FIXME split the check */ if (strncmp(data, CONTENT_TYPE, strlen(CONTENT_TYPE))) { return NULL; } mtype = (char *)data+strlen(CONTENT_TYPE); ret = icalcomponent_new_from_string(mtype); if (ret == NULL) { return NULL; } #ifdef DEBUG g_message("icalcap_component_new_from_string icalcomponent_new_from_string = %p", ret); #endif /* FIXME * Validate here: should check at least the version */ if (icalcomponent_isa(ret) != ICAL_VCALENDAR_COMPONENT && icalcomponent_isa(ret) != ICAL_XROOT_COMPONENT) { icalcomponent_free(ret); return NULL; } return ret; }
void dates_ical_drop_cb (DatesView *view, const gchar *ical, DatesData *d) { icalcomponent *icalcomp, *icalcomp2; gint events; if (!d->cal_loaded) { /* TODO: Toggle the default calendar here maybe? */ g_warning ("No calendars selected to add new event to"); return; } icalcomp = icalcomponent_new_from_string (g_strdup (ical)); if (!icalcomp) g_warning ("Error creating icalcomponent from string"); switch (icalcomponent_isa (icalcomp)) { case ICAL_VEVENT_COMPONENT : icalcomponent_set_uid (icalcomp, ""); dates_new (d, icalcomponent_new_clone (icalcomp), TRUE); return; case ICAL_VCALENDAR_COMPONENT : /* Iterate through events */ /* TODO: A confirmation dialog when calendar has * multiple events? */ events = icalcomponent_count_components (icalcomp, ICAL_VEVENT_COMPONENT); if (events == 0) { g_warning ("Dragged ical contains no supported " "kinds."); break; } icalcomp2 = icalcomponent_get_first_component (icalcomp, ICAL_VEVENT_COMPONENT); do { icalcomponent_set_uid (icalcomp2, ""); dates_new (d, icalcomponent_new_clone ( icalcomp2), (events == 1) ? TRUE : FALSE); } while ((icalcomp2 = icalcomponent_get_next_component ( icalcomp2, ICAL_VEVENT_COMPONENT))); break; default : g_warning ("Dragged ical not a supported kind."); break; } icalcomponent_free (icalcomp); }
GSList* EDSCalendarStorage::toICalComponentsList(const std::vector<std::string> & iCals, const OpenAB::PIMItem::IDs& ids, std::vector<icaltimezone*>& timezones) { GSList * events = NULL; currentEventTimeZones.clear(); for(unsigned int i = 0; i < iCals.size(); ++i) { std::stringstream ss(iCals[i]); //In case of recurring events one iCalendar can contain couple of VEVENT objects, get them all while (1) { std::string event = EDSCalendarStorageCommon::cutVObject(ss); if (event.empty()) { break; } icalcomponent* newEvent = icalcomponent_new_from_string(event.c_str()); if (!newEvent) { LOG_DEBUG() << "Cannot parse vevent" << std::endl; g_slist_free_full(events, (GDestroyNotify) icalcomponent_free); return NULL; } icalcomponent_foreach_tzid(newEvent, EDSCalendarStorage::findTimeZonesCb, newEvent); icalcomponent_strip_errors(newEvent); if (ids.size() > i) icalcomponent_set_uid(newEvent, ids[i].c_str()); events = g_slist_append(events, newEvent); } } std::set<std::string>::iterator it; for(it = currentEventTimeZones.begin(); it != currentEventTimeZones.end(); ++it) { icaltimezone* tz = icaltimezone_get_builtin_timezone((*it).c_str()); if (tz) { timezones.push_back(tz); } } return events; }
static GList * build_object_list (const gchar * const *seq) { GList *list; gint i; list = NULL; for (i = 0; seq[i]; i++) { icalcomponent *comp; comp = icalcomponent_new_from_string ((gchar *)seq[i]); if (!comp) continue; list = g_list_prepend (list, comp); } return g_list_reverse (list); }
int main(int argc, char *argv[]) { char *dtstr = "20031026T190000"; icaltimezone *zone; struct icaltimetype tt; int utc_offset; if (argc > 1) { dtstr = argv[1]; } icalcomponent *zonecomp = icalcomponent_new_from_string(mytz); zone = icaltimezone_new(); icaltimezone_set_component(zone, zonecomp); tt = icaltime_from_string(dtstr); icaltime_set_timezone(&tt, zone); utc_offset = icaltimezone_get_utc_offset(zone, &tt, NULL); printf("OFFSET for %s is %d %p\n", dtstr, utc_offset, zone); }
static icalcomponent *get_server_objects(ECalBackend3e *cb, const char *query) { GError *local_err = NULL; char *servercal; icalcomponent *ical; if (!e_cal_backend_3e_open_connection(cb, &local_err)) { g_warning("Sync failed. Can't open connection to the 3e server. (%s)", local_err->message); g_error_free(local_err); return NULL; } servercal = ESClient_queryObjects(cb->priv->conn, cb->priv->calspec, query, &local_err); if (local_err) { g_clear_error(&local_err); } e_cal_backend_3e_close_connection(cb); if (servercal == NULL) { return NULL; } ical = icalcomponent_new_from_string(servercal); mydebug("===========\n%s\n==========\n\n", servercal); g_free (servercal); if (ical == NULL) { return NULL; } return ical; }
/** * e_cal_backend_sexp_match_object: * @sexp: An #ESExp object. * @object: An iCalendar string. * @backend: A backend. * * Match an iCalendar expression against the expression. * * Returns: TRUE if the object matches the expression, FALSE if not. */ gboolean e_cal_backend_sexp_match_object (ECalBackendSExp *sexp, const gchar *object, ECalBackend *backend) { ECalComponent *comp; icalcomponent *icalcomp; gboolean retval; icalcomp = icalcomponent_new_from_string ((gchar *) object); if (!icalcomp) return FALSE; comp = e_cal_component_new (); e_cal_component_set_icalcomponent (comp, icalcomp); retval = e_cal_backend_sexp_match_comp (sexp, comp, backend); g_object_unref (comp); return retval; }
void render_MIME_ICS_TPL(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset) { wc_mime_attachment *Mime = CTX(CTX_MIME_ATACH); icalproperty_method the_method = ICAL_METHOD_NONE; icalproperty *method = NULL; icalcomponent *cal = NULL; icalcomponent *c = NULL; WCTemplputParams SubTP; WCTemplputParams SuperTP; static int divcount = 0; if (StrLength(Mime->Data) == 0) { MimeLoadData(Mime); } if (StrLength(Mime->Data) > 0) { cal = icalcomponent_new_from_string(ChrPtr(Mime->Data)); } if (cal == NULL) { StrBufAppendPrintf(Mime->Data, _("There was an error parsing this calendar item.")); StrBufAppendPrintf(Mime->Data, "<br>\n"); return; } putlbstr("divname", ++divcount); putbstr("cal_partnum", NewStrBufDup(Mime->PartNum)); putlbstr("msgnum", Mime->msgnum); memset(&SubTP, 0, sizeof(WCTemplputParams)); memset(&SuperTP, 0, sizeof(WCTemplputParams)); /*//ical_dezonify(cal); */ /* If the component has subcomponents, recurse through them. */ c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT); c = (c != NULL) ? c : cal; method = icalcomponent_get_first_property(cal, ICAL_METHOD_PROPERTY); if (method != NULL) { the_method = icalproperty_get_method(method); } StackContext (TP, &SuperTP, &the_method, CTX_ICALMETHOD, 0, TP->Tokens); StackContext (&SuperTP, &SubTP, c, CTX_ICAL, 0, SuperTP.Tokens); FlushStrBuf(Mime->Data); /// DoTemplate(HKEY("ical_attachment_display"), Mime->Data, &SubTP); DoTemplate(HKEY("ical_edit"), Mime->Data, &SubTP); /*/ cal_process_object(Mime->Data, cal, 0, Mime->msgnum, ChrPtr(Mime->PartNum)); */ /* Free the memory we obtained from libical's constructor */ StrBufPlain(Mime->ContentType, HKEY("text/html")); StrBufAppendPrintf(WC->trailing_javascript, "eventEditAllDay(); \n" "RecurrenceShowHide(); \n" "EnableOrDisableCheckButton(); \n" ); UnStackContext(&SuperTP); UnStackContext(&SubTP); icalcomponent_free(cal); }