static gpointer alter_cal_client (gpointer user_data) { ECalClient *cal_client = user_data; GError *error = NULL; icalcomponent *icalcomp; struct icaltimetype now; gchar *uid = NULL; g_return_val_if_fail (cal_client != NULL, NULL); now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ()); icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT); icalcomponent_set_summary (icalcomp, "Initial event summary"); icalcomponent_set_dtstart (icalcomp, now); icalcomponent_set_dtend (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0)); if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error)) g_error ("create object sync: %s", error->message); icalcomponent_set_uid (icalcomp, uid); icalcomponent_set_summary (icalcomp, "Modified event summary"); if (!e_cal_client_modify_object_sync (cal_client, icalcomp, CALOBJ_MOD_ALL, NULL, &error)) g_error ("modify object sync: %s", error->message); if (!e_cal_client_remove_object_sync (cal_client, uid, NULL, CALOBJ_MOD_ALL, NULL, &error)) g_error ("remove object sync: %s", error->message); g_free (uid); icalcomponent_free (icalcomp); return FALSE; }
void dates_new_cb (GtkWidget *source, DatesData *d) { icalcomponent *comp; struct icalperiodtype period; if (!dates_view_get_selected_period (d->view, &period)) { struct icaltimetype date, now; /* Create a default time event */ date = *(dates_view_get_date (d->view)); now = icaltime_current_time_with_zone (date.zone); date.is_date = FALSE; now.is_date = FALSE; period.duration = icaldurationtype_null_duration (); period.duration.minutes = 0; /* New events default to starting at 9am */ period.duration.hours = 9; period.start = icaltime_add ( date, period.duration); /* NOTE: 11 is the magic number where we're viewing a * month or more. See dates_zoom_change. */ period.duration.hours = (d->zoom >= 11) ? 8 : 2; period.end = icaltime_add (period.start, period.duration); } comp = icalcomponent_new_vevent (); icalcomponent_set_dtstart (comp, period.start); icalcomponent_set_dtend (comp, period.end); icalcomponent_set_summary (comp, _("New event")); dates_new (d, comp, TRUE); }
gint main (gint argc, gchar **argv) { ECalClient *cal_client; GError *error = NULL; icalcomponent *icalcomp; struct icaltimetype now; gchar *uid = NULL; main_initialize (); cal_client = new_temp_client (E_CAL_CLIENT_SOURCE_TYPE_EVENTS, NULL); g_return_val_if_fail (cal_client != NULL, FALSE); if (!e_client_open_sync (E_CLIENT (cal_client), FALSE, NULL, &error)) { report_error ("client open sync", &error); g_object_unref (cal_client); return 1; } now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ()); icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT); icalcomponent_set_summary (icalcomp, "Test event summary"); icalcomponent_set_dtstart (icalcomp, now); icalcomponent_set_dtend (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0)); if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error)) { report_error ("create object sync", &error); icalcomponent_free (icalcomp); g_object_unref (cal_client); return 1; } icalcomponent_free (icalcomp); g_free (uid); /* synchronously without main-loop */ if (!test_sync (cal_client)) { g_object_unref (cal_client); return 1; } start_in_thread_with_main_loop (test_sync_in_thread, cal_client); if (!e_client_remove_sync (E_CLIENT (cal_client), NULL, &error)) { report_error ("client remove sync", &error); g_object_unref (cal_client); return 1; } g_object_unref (cal_client); if (get_main_loop_stop_result () == 0) g_print ("Test finished successfully.\n"); return get_main_loop_stop_result (); }
static icalcomponent * create_object (void) { icalcomponent *icalcomp; struct icaltimetype now; now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ()); icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT); icalcomponent_set_summary (icalcomp, "To-be-sent event summary"); icalcomponent_set_dtstart (icalcomp, now); icalcomponent_set_dtend (icalcomp, icaltime_from_timet_with_zone (icaltime_as_timet (now) + 60 * 60 * 60, 0, NULL)); return icalcomp; }
static void setup_cal (ECalClient *cal_client) { GError *error = NULL; icalcomponent *icalcomp; struct icaltimetype now; gchar *uid = NULL; now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ()); icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT); icalcomponent_set_summary (icalcomp, "Test event summary"); icalcomponent_set_dtstart (icalcomp, now); icalcomponent_set_dtend (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0)); if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error)) g_error ("create object sync: %s", error->message); icalcomponent_free (icalcomp); g_free (uid); }
static const gchar * test_object_modification (ECal *client, gchar *uid) { const gchar *summary = "This summary was modified"; icalcomponent *icalcomp, *icalcomp_modified; gboolean compare; GError *error = NULL; if (!e_cal_get_object (client, uid, NULL, &icalcomp, &error)) { cl_printf (client, "Test Modify object : Could not get the object: %s\n", error->message); g_free (uid); return error->message; } /* Modify one property of the icalcomp and save it. * Now retrieve it and check the field. */ icalcomponent_set_summary (icalcomp, summary); if (!e_cal_modify_object (client, icalcomp, CALOBJ_MOD_THIS, &error)) { cl_printf (client, "Test Modify object : Could not modify the object: %s\n", error->message); g_free (uid); g_free (icalcomp); return error->message; } if (!e_cal_get_object (client, uid, NULL, &icalcomp_modified, &error)) { cl_printf (client, "Test Modify object : Could not get the modified object: %s\n", error->message); g_free (uid); g_free (icalcomp); return "Test Object Creation failed"; } compare = !strcmp ( icalcomponent_get_summary (icalcomp_modified), summary); g_free (uid); g_free (icalcomp); g_free (icalcomp_modified); mu_assert ("Test Modify object : Modification failed\n", compare); return NULL; }
static void get_revision_compare_cycle (ECalClient *client) { icalcomponent *icalcomp; struct icaltimetype now; gchar *revision_before = NULL, *revision_after = NULL, *uid = NULL; GError *error = NULL; /* Build up new component */ now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ()); icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT); icalcomponent_set_summary (icalcomp, "Test event summary"); icalcomponent_set_dtstart (icalcomp, now); icalcomponent_set_dtend (icalcomp, icaltime_from_timet (icaltime_as_timet (now) + 60 * 60 * 60, 0)); if (!e_client_get_backend_property_sync (E_CLIENT (client), CLIENT_BACKEND_PROPERTY_REVISION, &revision_before, NULL, &error)) g_error ("Error getting book revision: %s", error->message); if (!e_cal_client_create_object_sync (client, icalcomp, &uid, NULL, &error)) g_error ("Error creating object: %s", error->message); if (!e_client_get_backend_property_sync (E_CLIENT (client), CLIENT_BACKEND_PROPERTY_REVISION, &revision_after, NULL, &error)) g_error ("Error getting book revision: %s", error->message); g_assert (revision_before); g_assert (revision_after); g_assert (strcmp (revision_before, revision_after) != 0); g_message ("Passed cycle, revision before '%s' revision after '%s'", revision_before, revision_after); g_free (revision_before); g_free (revision_after); g_free (uid); icalcomponent_free (icalcomp); }
static gchar * create_object (ECalClient *cal_client) { icalcomponent *icalcomp; struct icaltimetype now; gchar *uid = NULL; GError *error = NULL; g_return_val_if_fail (cal_client != NULL, NULL); now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ()); icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT); icalcomponent_set_summary (icalcomp, "To-be-removed event summary"); icalcomponent_set_dtstart (icalcomp, now); icalcomponent_set_dtend (icalcomp, icaltime_from_timet_with_zone (icaltime_as_timet (now) + 60 * 60 * 60, 0, NULL)); if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error)) g_error ("create object sync: %s", error->message); icalcomponent_free (icalcomp); return uid; }
// utility function to create a VCALENDAR from a single RideItem static icalcomponent *createEvent(RideItem *rideItem) { // calendar icalcomponent *root = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); // calendar version icalproperty *version = icalproperty_new_version("2.0"); icalcomponent_add_property(root, version); icalcomponent *event = icalcomponent_new(ICAL_VEVENT_COMPONENT); // // Unique ID // QString id = rideItem->ride()->id(); if (id == "") { id = QUuid::createUuid().toString() + "@" + "goldencheetah.org"; } icalproperty *uid = icalproperty_new_uid(id.toLatin1()); icalcomponent_add_property(event, uid); // // START DATE // struct icaltimetype atime; QDateTime utc = QDateTime::currentDateTime().toUTC(); atime.year = utc.date().year(); atime.month = utc.date().month(); atime.day = utc.date().day(); atime.hour = utc.time().hour(); atime.minute = utc.time().minute(); atime.second = utc.time().second(); // this is UTC is_utc is redundant but kept for completeness atime.is_utc = 1; atime.is_date = 0; // this is a date AND time atime.is_daylight = 0; // no daylight savings - its UTC atime.zone = icaltimezone_get_utc_timezone(); // set UTC timezone icalproperty *dtstart = icalproperty_new_dtstart(atime); icalcomponent_add_property(event, dtstart); // // Duration // // override values? QMap<QString, QString> lookup; lookup = rideItem->ride()->metricOverrides.value("workout_time"); int secs = lookup.value("value", "0.0").toDouble(); // from last - first timestamp? if (!rideItem->ride()->datePoints().isEmpty() && rideItem->ride()->datePoints().last() != NULL) { if (!secs) { secs = rideItem->ride()->datePoints().last()->secs; } } // ok, got seconds so now create in vcard struct icaldurationtype dur; dur.is_neg = 0; dur.days = dur.weeks = 0; dur.hours = secs / 3600; dur.minutes = secs % 3600 / 60; dur.seconds = secs % 60; icalcomponent_set_duration(event, dur); // set title & description QString title = rideItem->ride()->getTag("Title", ""); if (title == "") { title = rideItem->ride()->getTag("Sport", "") + " Workout"; } icalcomponent_set_summary(event, title.toLatin1()); icalcomponent_set_description(event, rideItem->ride()->getTag("Calendar Text", "").toLatin1()); // put the event into root icalcomponent_add_component(root, event); return root; }