/** * time_add_week_with_zone: * @time: A time_t value. * @weeks: Number of weeks to add. * @zone: Timezone to use. * * Adds or subtracts a number of weeks to/from the given time_t value, using * the given timezone. * NOTE: this function is only here to make the transition to the timezone * functions easier. New code should use icaltimetype values and * icaltime_adjust() to add or subtract days, hours, minutes & seconds. * * Returns: a time_t value containing @time plus the weeks added. */ time_t time_add_week_with_zone (time_t time, gint weeks, icaltimezone *zone) { return time_add_day_with_zone (time, weeks * 7, zone); }
static void e_send_options_load_general_opts (ESendOptionsGeneral *gopts, EGwSendOptionsGeneral *ggopts) { time_t temp; temp = time (NULL); gopts->priority = ggopts->priority; gopts->reply_enabled = ggopts->reply_enabled; gopts->reply_convenient = ggopts->reply_convenient; gopts->reply_within = ggopts->reply_within; gopts->expiration_enabled = ggopts->expiration_enabled; gopts->expire_after = ggopts->expire_after; gopts->delay_enabled = ggopts->delay_enabled; /* TODO convert gint to timet comparing the current day */ if (ggopts->delay_until) { gopts->delay_until = time_add_day_with_zone (temp, ggopts->delay_until, NULL); } else gopts->delay_until = 0; }
static gchar * test_get_free_busy (ECal *client) { /* TODO uses NULL for users and currently specific to file backend. */ GList *l, *freebusy = NULL; GError *error = NULL; icaltimezone *utc; time_t start, end; utc = icaltimezone_get_utc_timezone (); start = time_from_isodate ("20040212T000000Z"); end = time_add_day_with_zone (start, 2, utc); if (!e_cal_get_free_busy (client, NULL, start, end, &freebusy, &error)) { cl_printf (client, "Test free/busy : Could not retrieve free busy information : %s\n", error->message); return error->message; } if (freebusy) { cl_printf (client, "Printing free busy information\n"); for (l = freebusy; l; l = l->next) { gchar *comp_string; ECalComponent *comp = E_CAL_COMPONENT (l->data); comp_string = e_cal_component_get_as_string (comp); cl_printf (client, "%s\n\n", comp_string); g_object_unref (comp); g_free (comp_string); } } else { cl_printf (client, "free_busy was returned but NULL"); } return NULL; }
static const gchar * test_get_alarms_in_range (ECal *client) { GSList *alarms; icaltimezone *utc; time_t start, end; gboolean compare; utc = icaltimezone_get_utc_timezone (); start = time_from_isodate ("20040212T000000Z"); end = time_add_day_with_zone (start, 2, utc); alarms = e_cal_get_alarms_in_range (client, start, end); compare = (g_slist_length (alarms) == 3); e_cal_free_alarms (alarms); mu_assert ("Test getting alarms in range\n", compare); return NULL; }
static gboolean write_calendar (const gchar *uid, GOutputStream *stream, gint dur_type, gint dur_value, GError **error) { EShell *shell; ESource *source; ESourceRegistry *registry; EClient *client = NULL; GSList *objects = NULL; icaltimezone *utc; time_t start = time (NULL), end; icalcomponent *top_level; gchar *email = NULL; GSList *users = NULL; gulong handler_id; gboolean success = FALSE; utc = icaltimezone_get_utc_timezone (); start = time_day_begin_with_zone (start, utc); switch (dur_type) { case FB_DURATION_DAYS: end = time_add_day_with_zone (start, dur_value, utc); break; default: case FB_DURATION_WEEKS: end = time_add_week_with_zone (start, dur_value, utc); break; case FB_DURATION_MONTHS: end = time_add_month_with_zone (start, dur_value, utc); break; } shell = e_shell_get_default (); registry = e_shell_get_registry (shell); source = e_source_registry_ref_source (registry, uid); if (source != NULL) { EClientCache *client_cache; client_cache = e_shell_get_client_cache (shell); client = e_client_cache_get_client_sync (client_cache, source, E_SOURCE_EXTENSION_CALENDAR, 30, NULL, error); g_object_unref (source); } else { g_set_error ( error, E_CAL_CLIENT_ERROR, E_CAL_CLIENT_ERROR_NO_SUCH_CALENDAR, _("Invalid source UID '%s'"), uid); } if (client == NULL) return FALSE; if (e_client_get_backend_property_sync (client, CAL_BACKEND_PROPERTY_CAL_EMAIL_ADDRESS, &email, NULL, NULL)) { if (email && *email) users = g_slist_append (users, email); } top_level = e_cal_util_new_top_level (); handler_id = g_signal_connect ( client, "free-busy-data", G_CALLBACK (free_busy_data_cb), &objects); success = e_cal_client_get_free_busy_sync ( E_CAL_CLIENT (client), start, end, users, NULL, error); if (handler_id > 0) g_signal_handler_disconnect (client, handler_id); if (success) { gchar *ical_string; GSList *iter; gboolean done = FALSE; /* This is to workaround broken dispatch of "free-busy-data" signal, * introduced in 3.8.0. This code can be removed once the below bug is * properly fixed: https://bugzilla.gnome.org/show_bug.cgi?id=692361 */ while (!done) { g_usleep (G_USEC_PER_SEC / 10); done = !g_main_context_iteration (NULL, FALSE); } for (iter = objects; iter; iter = iter->next) { ECalComponent *comp = iter->data; icalcomponent *icalcomp = icalcomponent_new_clone (e_cal_component_get_icalcomponent (comp)); icalcomponent_add_component (top_level, icalcomp); } ical_string = icalcomponent_as_ical_string_r (top_level); success = g_output_stream_write_all ( stream, ical_string, strlen (ical_string), NULL, NULL, error); e_cal_client_free_ecalcomp_slist (objects); g_free (ical_string); } if (users) g_slist_free (users); g_free (email); g_object_unref (client); icalcomponent_free (top_level); return success; }
static gboolean write_calendar (const gchar *uid, GOutputStream *stream, gint dur_type, gint dur_value, GError **error) { EShell *shell; ESource *source; ESourceRegistry *registry; EClient *client = NULL; GSList *objects = NULL; icaltimezone *utc; time_t start = time (NULL), end; icalcomponent *top_level; gchar *email = NULL; GSList *users = NULL; gboolean success = FALSE; utc = icaltimezone_get_utc_timezone (); start = time_day_begin_with_zone (start, utc); switch (dur_type) { case FB_DURATION_DAYS: end = time_add_day_with_zone (start, dur_value, utc); break; default: case FB_DURATION_WEEKS: end = time_add_week_with_zone (start, dur_value, utc); break; case FB_DURATION_MONTHS: end = time_add_month_with_zone (start, dur_value, utc); break; } shell = e_shell_get_default (); registry = e_shell_get_registry (shell); source = e_source_registry_ref_source (registry, uid); if (source != NULL) { EClientCache *client_cache; client_cache = e_shell_get_client_cache (shell); client = e_client_cache_get_client_sync (client_cache, source, E_SOURCE_EXTENSION_CALENDAR, 30, NULL, error); g_object_unref (source); } else { g_set_error ( error, E_CAL_CLIENT_ERROR, E_CAL_CLIENT_ERROR_NO_SUCH_CALENDAR, _("Invalid source UID “%s”"), uid); } if (client == NULL) return FALSE; if (e_client_get_backend_property_sync (client, CAL_BACKEND_PROPERTY_CAL_EMAIL_ADDRESS, &email, NULL, NULL)) { if (email && *email) users = g_slist_append (users, email); } top_level = e_cal_util_new_top_level (); success = e_cal_client_get_free_busy_sync ( E_CAL_CLIENT (client), start, end, users, &objects, NULL, error); if (success) { gchar *ical_string; GSList *iter; for (iter = objects; iter; iter = iter->next) { ECalComponent *comp = iter->data; icalcomponent *icalcomp = icalcomponent_new_clone (e_cal_component_get_icalcomponent (comp)); icalcomponent_add_component (top_level, icalcomp); } ical_string = icalcomponent_as_ical_string_r (top_level); success = g_output_stream_write_all ( stream, ical_string, strlen (ical_string), NULL, NULL, error); e_cal_client_free_ecalcomp_slist (objects); g_free (ical_string); } if (users) g_slist_free (users); g_free (email); g_object_unref (client); icalcomponent_free (top_level); return success; }