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); }
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; }
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 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; }
/** * e_cal_util_split_at_instance: * @icalcomp: A (recurring) #icalcomponent * @rid: The base RECURRENCE-ID to remove * @master_dtstart: The DTSTART of the master object * * Splits a recurring @icalcomp into two at time @rid. The returned icalcomponent * is modified @icalcomp which contains recurrences beginning at @rid, inclusive. * The instance identified by @rid should exist. The @master_dtstart can be * a null time, then it is read from the @icalcomp. * * Use e_cal_util_remove_instances() with E_CAL_OBJ_MOD_THIS_AND_FUTURE mode * on the @icalcomp to remove the overlapping interval from it, if needed. * * Returns: the split icalcomponent, or %NULL. * * Since: 3.16 **/ icalcomponent * e_cal_util_split_at_instance (icalcomponent *icalcomp, struct icaltimetype rid, struct icaltimetype master_dtstart) { icalproperty *prop; struct instance_data instance; struct icaltimetype start, end; struct icaldurationtype duration; GSList *remove_props = NULL, *link; g_return_val_if_fail (icalcomp != NULL, NULL); g_return_val_if_fail (!icaltime_is_null_time (rid), NULL); /* Make sure this is really recurring */ if (!icalcomponent_get_first_property (icalcomp, ICAL_RRULE_PROPERTY) && !icalcomponent_get_first_property (icalcomp, ICAL_RDATE_PROPERTY)) return NULL; /* Make sure the specified instance really exists */ start = icaltime_convert_to_zone (rid, icaltimezone_get_utc_timezone ()); end = start; icaltime_adjust (&end, 0, 0, 0, 1); instance.start = icaltime_as_timet (start); instance.found = FALSE; icalcomponent_foreach_recurrence (icalcomp, start, end, check_instance, &instance); /* Make the copy */ icalcomp = icalcomponent_new_clone (icalcomp); e_cal_util_remove_instances_ex (icalcomp, rid, E_CAL_OBJ_MOD_THIS_AND_PRIOR, TRUE, FALSE); start = rid; if (icaltime_is_null_time (master_dtstart)) master_dtstart = icalcomponent_get_dtstart (icalcomp); duration = icalcomponent_get_duration (icalcomp); /* Expect that DTSTART and DTEND are already set when the instance could not be found */ if (instance.found) { icalcomponent_set_dtstart (icalcomp, start); /* Update either DURATION or DTEND */ if (icaltime_is_null_time (icalcomponent_get_dtend (icalcomp))) { icalcomponent_set_duration (icalcomp, duration); } else { end = start; if (duration.is_neg) icaltime_adjust (&end, -duration.days - 7 * duration.weeks, -duration.hours, -duration.minutes, -duration.seconds); else icaltime_adjust (&end, duration.days + 7 * duration.weeks, duration.hours, duration.minutes, duration.seconds); icalcomponent_set_dtend (icalcomp, end); } } /* any RRULE with 'count' should be shortened */ for (prop = icalcomponent_get_first_property (icalcomp, ICAL_RRULE_PROPERTY); prop; prop = icalcomponent_get_next_property (icalcomp, ICAL_RRULE_PROPERTY)) { struct icaltimetype recur; struct icalrecurrencetype rule; rule = icalproperty_get_rrule (prop); if (rule.count != 0) { gint occurrences_count = 0; icalrecur_iterator *iter; iter = icalrecur_iterator_new (rule, master_dtstart); while (recur = icalrecur_iterator_next (iter), !icaltime_is_null_time (recur) && occurrences_count < rule.count) { if (icaltime_compare (recur, rid) >= 0) break; occurrences_count++; } icalrecur_iterator_free (iter); if (icaltime_is_null_time (recur)) { remove_props = g_slist_prepend (remove_props, prop); } else { rule.count -= occurrences_count; icalproperty_set_rrule (prop, rule); icalproperty_remove_parameter_by_name (prop, "X-EVOLUTION-ENDDATE"); } } } for (link = remove_props; link; link = g_slist_next (link)) { prop = link->data; icalcomponent_remove_property (icalcomp, prop); } g_slist_free (remove_props); return icalcomp; }
static icalcomponent * create_user_free_busy (ECalBackendHttp *cbhttp, const gchar *address, const gchar *cn, time_t start, time_t end) { GSList *slist = NULL, *l; icalcomponent *vfb; icaltimezone *utc_zone; ECalBackendSExp *obj_sexp; ECalBackendHttpPrivate *priv; ECalBackendStore *store; gchar *query, *iso_start, *iso_end; priv = cbhttp->priv; store = priv->store; /* create the (unique) VFREEBUSY object that we'll return */ vfb = icalcomponent_new_vfreebusy (); if (address != NULL) { icalproperty *prop; icalparameter *param; prop = icalproperty_new_organizer (address); if (prop != NULL && cn != NULL) { param = icalparameter_new_cn (cn); icalproperty_add_parameter (prop, param); } if (prop != NULL) icalcomponent_add_property (vfb, prop); } utc_zone = icaltimezone_get_utc_timezone (); icalcomponent_set_dtstart (vfb, icaltime_from_timet_with_zone (start, FALSE, utc_zone)); icalcomponent_set_dtend (vfb, icaltime_from_timet_with_zone (end, FALSE, utc_zone)); /* add all objects in the given interval */ iso_start = isodate_from_time_t (start); iso_end = isodate_from_time_t (end); query = g_strdup_printf ( "occur-in-time-range? (make-time \"%s\") (make-time \"%s\")", iso_start, iso_end); obj_sexp = e_cal_backend_sexp_new (query); g_free (query); g_free (iso_start); g_free (iso_end); if (!obj_sexp) return vfb; slist = e_cal_backend_store_get_components (store); for (l = slist; l; l = g_slist_next (l)) { ECalComponent *comp = l->data; icalcomponent *icalcomp, *vcalendar_comp; icalproperty *prop; icalcomp = e_cal_component_get_icalcomponent (comp); if (!icalcomp) continue; /* If the event is TRANSPARENT, skip it. */ prop = icalcomponent_get_first_property ( icalcomp, ICAL_TRANSP_PROPERTY); if (prop) { icalproperty_transp transp_val = icalproperty_get_transp (prop); if (transp_val == ICAL_TRANSP_TRANSPARENT || transp_val == ICAL_TRANSP_TRANSPARENTNOCONFLICT) continue; } if (!e_cal_backend_sexp_match_comp ( obj_sexp, l->data, E_TIMEZONE_CACHE (cbhttp))) continue; vcalendar_comp = icalcomponent_get_parent (icalcomp); if (!vcalendar_comp) vcalendar_comp = icalcomp; e_cal_recur_generate_instances ( comp, start, end, free_busy_instance, vfb, resolve_tzid, vcalendar_comp, icaltimezone_get_utc_timezone ()); } g_object_unref (obj_sexp); return vfb; }