static void ivcal_connect_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { EClient *client; ICalImporter *ici = user_data; GError *error = NULL; g_return_if_fail (ici != NULL); client = e_cal_client_connect_finish (result, &error); /* Sanity check. */ g_return_if_fail ( ((client != NULL) && (error == NULL)) || ((client == NULL) && (error != NULL))); if (error != NULL) { g_warning ("%s: %s", G_STRFUNC, error->message); g_error_free (error); ivcal_import_done (ici); return; } ici->cal_client = E_CAL_CLIENT (client); e_import_status (ici->import, ici->target, _("Importing..."), 0); ici->idle_id = g_idle_add (ivcal_import_items, ici); }
static void async_get_view_ready (GObject *source_object, GAsyncResult *result, gpointer user_data) { ECalClient *cal_client = E_CAL_CLIENT (source_object); ECalClientView *view = NULL; GError *error = NULL; GMainLoop *loop = (GMainLoop *) user_data; g_return_if_fail (cal_client != NULL); if (!e_cal_client_get_view_finish (cal_client, result, &view, &error)) g_error ("get view finish: %s", error->message); g_object_set_data_full (G_OBJECT (cal_client), "cal-view", view, g_object_unref); subtest_passed (SUBTEST_RESET, loop); g_signal_connect (view, "objects_added", G_CALLBACK (objects_added_cb), loop); g_signal_connect (view, "objects_modified", G_CALLBACK (objects_modified_cb), loop); g_signal_connect (view, "objects_removed", G_CALLBACK (objects_removed_cb), loop); g_signal_connect (view, "complete", G_CALLBACK (complete_cb), loop); e_cal_client_view_set_fields_of_interest (view, NULL, &error); if (error) g_error ("set fields of interest: %s", error->message); e_cal_client_view_start (view, NULL); alter_cal_client (cal_client); }
static void async_remove_result_ready (GObject *source_object, GAsyncResult *result, gpointer user_data) { ECalClient *cal_client; GMainLoop *loop = (GMainLoop *) user_data; GError *error = NULL; cal_client = E_CAL_CLIENT (source_object); if (!e_cal_client_remove_object_finish (cal_client, result, &error)) g_error ("remove object finish: %s", error->message); g_main_loop_quit (loop); }
/* asynchronous callback with a main-loop running */ static void async_refresh_result_ready (GObject *source_object, GAsyncResult *result, gpointer user_data) { ECalClient *cal_client; GError *error = NULL; cal_client = E_CAL_CLIENT (source_object); if (!e_client_refresh_finish (E_CLIENT (cal_client), result, &error)) { report_error ("refresh finish", &error); stop_main_loop (1); return; } stop_main_loop (0); }
/* asynchronous callback with a main-loop running */ static void async_attachment_uris_result_ready (GObject *source_object, GAsyncResult *result, gpointer user_data) { ECalClient *cal_client; GError *error = NULL; GSList *attachment_uris = NULL; cal_client = E_CAL_CLIENT (source_object); if (!e_cal_client_get_attachment_uris_finish (cal_client, result, &attachment_uris, &error)) { report_error ("get attachment uris finish", &error); stop_main_loop (1); return; } stop_main_loop (manage_result (attachment_uris) ? 0 : 1); }
static void async_send_result_ready (GObject *source_object, GAsyncResult *result, gpointer user_data) { ECalClient *cal_client; GError *error = NULL; GSList *users = NULL; icalcomponent *modified_icalcomp = NULL; GMainLoop *loop = (GMainLoop *) user_data; cal_client = E_CAL_CLIENT (source_object); if (!e_cal_client_send_objects_finish (cal_client, result, &users, &modified_icalcomp, &error)) g_error ("send objects finish: %s", error->message); manage_result (users, modified_icalcomp); g_main_loop_quit (loop); }
/* asynchronous open callback with a main-loop running */ static void async_open_ready (GObject *source_object, GAsyncResult *result, gpointer user_data) { ECalClient *cal_client; GError *error = NULL; cal_client = E_CAL_CLIENT (source_object); if (!e_client_open_finish (E_CLIENT (cal_client), result, &error)) { report_error ("open finish", &error); g_object_unref (cal_client); stop_main_loop (1); return; } e_client_remove (E_CLIENT (cal_client), NULL, async_remove_ready, NULL); }
/* asynchronous callback with a main-loop running */ static void async_send_result_ready (GObject *source_object, GAsyncResult *result, gpointer user_data) { ECalClient *cal_client; GError *error = NULL; GSList *users = NULL; icalcomponent *modified_icalcomp = NULL; cal_client = E_CAL_CLIENT (source_object); if (!e_cal_client_send_objects_finish (cal_client, result, &users, &modified_icalcomp, &error)) { report_error ("send objects finish", &error); stop_main_loop (1); return; } stop_main_loop (manage_result (users, modified_icalcomp) ? 0 : 1); }
static void receive_objects_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { ECalClient *cal_client = E_CAL_CLIENT (source_object); struct UpdateObjectsData *uod = user_data; GError *error = NULL; g_return_if_fail (uod != NULL); e_cal_client_receive_objects_finish (cal_client, result, &error); if (error != NULL) { g_warning ( "%s: Failed to receive objects: %s", G_STRFUNC, error->message); g_error_free (error); } if (uod->done_cb) uod->done_cb (uod->user_data); g_free (uod); }
static gboolean do_mail_to_event (AsyncData *data) { EClient *client; CamelFolder *folder = data->folder; GPtrArray *uids = data->uids; GError *error = NULL; client = e_client_cache_get_client_sync (data->client_cache, data->source, data->extension_name, 30, NULL, &error); /* Sanity check. */ g_return_val_if_fail ( ((client != NULL) && (error == NULL)) || ((client == NULL) && (error != NULL)), TRUE); if (error != NULL) { report_error_idle (_("Cannot open calendar. %s"), error->message); } else if (e_client_is_readonly (E_CLIENT (client))) { switch (data->source_type) { case E_CAL_CLIENT_SOURCE_TYPE_EVENTS: report_error_idle (_("Selected calendar is read only, thus cannot create event there. Select other calendar, please."), NULL); break; case E_CAL_CLIENT_SOURCE_TYPE_TASKS: report_error_idle (_("Selected task list is read only, thus cannot create task there. Select other task list, please."), NULL); break; case E_CAL_CLIENT_SOURCE_TYPE_MEMOS: report_error_idle (_("Selected memo list is read only, thus cannot create memo there. Select other memo list, please."), NULL); break; default: g_warn_if_reached (); break; } } else { gint i; ECalComponentDateTime dt, dt2; struct icaltimetype tt, tt2; struct _manage_comp *oldmc = NULL; #define cache_backend_prop(prop) { \ gchar *val = NULL; \ e_client_get_backend_property_sync (E_CLIENT (client), prop, &val, NULL, NULL); \ g_free (val); \ } /* precache backend properties, thus editor have them ready when needed */ cache_backend_prop (CAL_BACKEND_PROPERTY_CAL_EMAIL_ADDRESS); cache_backend_prop (CAL_BACKEND_PROPERTY_ALARM_EMAIL_ADDRESS); cache_backend_prop (CAL_BACKEND_PROPERTY_DEFAULT_OBJECT); e_client_get_capabilities (E_CLIENT (client)); #undef cache_backend_prop /* set start day of the event as today, without time - easier than looking for a calendar's time zone */ tt = icaltime_today (); dt.value = &tt; dt.tzid = NULL; tt2 = tt; icaltime_adjust (&tt2, 1, 0, 0, 0); dt2.value = &tt2; dt2.tzid = NULL; for (i = 0; i < (uids ? uids->len : 0); i++) { CamelMimeMessage *message; ECalComponent *comp; ECalComponentText text; icalproperty *icalprop; icalcomponent *icalcomp; struct _manage_comp *mc; /* retrieve the message from the CamelFolder */ /* FIXME Not passing a GCancellable or GError. */ message = camel_folder_get_message_sync ( folder, g_ptr_array_index (uids, i), NULL, NULL); if (!message) { continue; } comp = e_cal_component_new (); switch (data->source_type) { case E_CAL_CLIENT_SOURCE_TYPE_EVENTS: e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT); break; case E_CAL_CLIENT_SOURCE_TYPE_TASKS: e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_TODO); break; case E_CAL_CLIENT_SOURCE_TYPE_MEMOS: e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_JOURNAL); break; default: g_warn_if_reached (); break; } e_cal_component_set_uid (comp, camel_mime_message_get_message_id (message)); e_cal_component_set_dtstart (comp, &dt); if (data->source_type == E_CAL_CLIENT_SOURCE_TYPE_EVENTS) { /* make it an all-day event */ e_cal_component_set_dtend (comp, &dt2); } /* set the summary */ text.value = camel_mime_message_get_subject (message); text.altrep = NULL; e_cal_component_set_summary (comp, &text); /* set all fields */ if (data->selected_text) { GSList sl; text.value = data->selected_text; text.altrep = NULL; sl.next = NULL; sl.data = &text; e_cal_component_set_description_list (comp, &sl); } else set_description (comp, message); if (data->with_attendees) { gchar *organizer; /* set actual user as organizer, to be able to change event's properties */ organizer = set_organizer (comp, data->folder); set_attendees (comp, message, organizer); g_free (organizer); } /* set attachment files */ set_attachments (E_CAL_CLIENT (client), comp, message); /* priority */ set_priority (comp, CAMEL_MIME_PART (message)); /* no need to increment a sequence number, this is a new component */ e_cal_component_abort_sequence (comp); icalcomp = e_cal_component_get_icalcomponent (comp); icalprop = icalproperty_new_x ("1"); icalproperty_set_x_name (icalprop, "X-EVOLUTION-MOVE-CALENDAR"); icalcomponent_add_property (icalcomp, icalprop); mc = g_new0 (struct _manage_comp, 1); mc->client = g_object_ref (client); mc->comp = g_object_ref (comp); g_mutex_init (&mc->mutex); g_cond_init (&mc->cond); mc->mails_count = uids->len; mc->mails_done = i + 1; /* Current task */ mc->editor_title = NULL; mc->can_continue = TRUE; if (oldmc) { /* Wait for user to quit the editor created in previous iteration * before displaying next one */ gboolean can_continue; g_mutex_lock (&oldmc->mutex); g_cond_wait (&oldmc->cond, &oldmc->mutex); g_mutex_unlock (&oldmc->mutex); can_continue = oldmc->can_continue; free_manage_comp_struct (oldmc); oldmc = NULL; if (!can_continue) break; } e_cal_client_get_object_sync ( E_CAL_CLIENT (client), icalcomponent_get_uid (icalcomp), NULL, &mc->stored_comp, NULL, NULL); /* Prioritize ahead of GTK+ redraws. */ g_idle_add_full ( G_PRIORITY_HIGH_IDLE, (GSourceFunc) do_manage_comp_idle, mc, NULL); oldmc = mc; g_object_unref (comp); g_object_unref (message); } /* Wait for the last editor and then clean up */ if (oldmc) { g_mutex_lock (&oldmc->mutex); g_cond_wait (&oldmc->cond, &oldmc->mutex); g_mutex_unlock (&oldmc->mutex); free_manage_comp_struct (oldmc); } } /* free memory */ if (client != NULL) g_object_unref (client); g_ptr_array_unref (uids); g_object_unref (folder); g_object_unref (data->client_cache); g_object_unref (data->source); g_free (data->selected_text); g_free (data); data = NULL; if (error != NULL) g_error_free (error); return TRUE; }
static void do_save_calendar_rdf (FormatHandler *handler, ESourceSelector *selector, ECalClientSourceType type, gchar *dest_uri) { /* * According to some documentation about CSV, newlines 'are' allowed * in CSV-files. But you 'do' have to put the value between quotes. * The helper 'string_needsquotes' will check for that * * http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm * http://www.creativyst.com/cgi-bin/Prod/15/eg/csv2xml.pl */ ESource *primary_source; EClient *source_client; GError *error = NULL; GSList *objects = NULL; gchar *temp = NULL; GOutputStream *stream; if (!dest_uri) return; /* open source client */ primary_source = e_source_selector_ref_primary_selection (selector); source_client = e_cal_client_connect_sync ( primary_source, type, NULL, &error); g_object_unref (primary_source); /* Sanity check. */ g_return_if_fail ( ((source_client != NULL) && (error == NULL)) || ((source_client == NULL) && (error != NULL))); if (source_client == NULL) { display_error_message ( gtk_widget_get_toplevel (GTK_WIDGET (selector)), error->message); g_error_free (error); return; } stream = open_for_writing (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (selector))), dest_uri, &error); if (stream && e_cal_client_get_object_list_as_comps_sync (E_CAL_CLIENT (source_client), "#t", &objects, NULL, NULL)) { GSList *iter; xmlBufferPtr buffer = xmlBufferCreate (); xmlDocPtr doc = xmlNewDoc ((xmlChar *) "1.0"); xmlNodePtr fnode; doc->children = xmlNewDocNode (doc, NULL, (const guchar *)"rdf:RDF", NULL); xmlSetProp (doc->children, (const guchar *)"xmlns:rdf", (const guchar *)"http://www.w3.org/1999/02/22-rdf-syntax-ns#"); xmlSetProp (doc->children, (const guchar *)"xmlns", (const guchar *)"http://www.w3.org/2002/12/cal/ical#"); fnode = xmlNewChild (doc->children, NULL, (const guchar *)"Vcalendar", NULL); /* Should Evolution publicise these? */ xmlSetProp (fnode, (const guchar *)"xmlns:x-wr", (const guchar *)"http://www.w3.org/2002/12/cal/prod/Apple_Comp_628d9d8459c556fa#"); xmlSetProp (fnode, (const guchar *)"xmlns:x-lic", (const guchar *)"http://www.w3.org/2002/12/cal/prod/Apple_Comp_628d9d8459c556fa#"); /* Not sure if it's correct like this */ xmlNewChild (fnode, NULL, (const guchar *)"prodid", (const guchar *)"-//" PACKAGE_STRING "//iCal 1.0//EN"); /* Assuming GREGORIAN is the only supported calendar scale */ xmlNewChild (fnode, NULL, (const guchar *)"calscale", (const guchar *)"GREGORIAN"); temp = calendar_config_get_timezone (); xmlNewChild (fnode, NULL, (const guchar *)"x-wr:timezone", (guchar *) temp); g_free (temp); xmlNewChild (fnode, NULL, (const guchar *)"method", (const guchar *)"PUBLISH"); xmlNewChild (fnode, NULL, (const guchar *)"x-wr:relcalid", (guchar *) e_source_get_uid (primary_source)); xmlNewChild (fnode, NULL, (const guchar *)"x-wr:calname", (guchar *) e_source_get_display_name (primary_source)); /* Version of this RDF-format */ xmlNewChild (fnode, NULL, (const guchar *)"version", (const guchar *)"2.0"); for (iter = objects; iter; iter = iter->next) { ECalComponent *comp = iter->data; const gchar *temp_constchar; gchar *tmp_str = NULL; GSList *temp_list; ECalComponentDateTime temp_dt; struct icaltimetype *temp_time; gint *temp_int; ECalComponentText temp_comptext; xmlNodePtr c_node = xmlNewChild (fnode, NULL, (const guchar *)"component", NULL); xmlNodePtr node = xmlNewChild (c_node, NULL, (const guchar *)"Vevent", NULL); /* Getting the stuff */ e_cal_component_get_uid (comp, &temp_constchar); tmp_str = g_strdup_printf ("#%s", temp_constchar); xmlSetProp (node, (const guchar *)"about", (guchar *) tmp_str); g_free (tmp_str); add_string_to_rdf (node, "uid",temp_constchar); e_cal_component_get_summary (comp, &temp_comptext); add_string_to_rdf (node, "summary", temp_comptext.value); e_cal_component_get_description_list (comp, &temp_list); add_list_to_rdf (node, "description", temp_list, ECALCOMPONENTTEXT); if (temp_list) e_cal_component_free_text_list (temp_list); e_cal_component_get_categories_list (comp, &temp_list); add_list_to_rdf (node, "categories", temp_list, CONSTCHAR); if (temp_list) e_cal_component_free_categories_list (temp_list); e_cal_component_get_comment_list (comp, &temp_list); add_list_to_rdf (node, "comment", temp_list, ECALCOMPONENTTEXT); if (temp_list) e_cal_component_free_text_list (temp_list); e_cal_component_get_completed (comp, &temp_time); add_time_to_rdf (node, "completed", temp_time); if (temp_time) e_cal_component_free_icaltimetype (temp_time); e_cal_component_get_created (comp, &temp_time); add_time_to_rdf (node, "created", temp_time); if (temp_time) e_cal_component_free_icaltimetype (temp_time); e_cal_component_get_contact_list (comp, &temp_list); add_list_to_rdf (node, "contact", temp_list, ECALCOMPONENTTEXT); if (temp_list) e_cal_component_free_text_list (temp_list); e_cal_component_get_dtstart (comp, &temp_dt); add_time_to_rdf (node, "dtstart", temp_dt.value ? temp_dt.value : NULL); e_cal_component_free_datetime (&temp_dt); e_cal_component_get_dtend (comp, &temp_dt); add_time_to_rdf (node, "dtend", temp_dt.value ? temp_dt.value : NULL); e_cal_component_free_datetime (&temp_dt); e_cal_component_get_due (comp, &temp_dt); add_time_to_rdf (node, "due", temp_dt.value ? temp_dt.value : NULL); e_cal_component_free_datetime (&temp_dt); e_cal_component_get_percent (comp, &temp_int); add_nummeric_to_rdf (node, "percentComplete", temp_int); e_cal_component_get_priority (comp, &temp_int); add_nummeric_to_rdf (node, "priority", temp_int); e_cal_component_get_url (comp, &temp_constchar); add_string_to_rdf (node, "URL", temp_constchar); if (e_cal_component_has_attendees (comp)) { e_cal_component_get_attendee_list (comp, &temp_list); add_list_to_rdf (node, "attendee", temp_list, ECALCOMPONENTATTENDEE); if (temp_list) e_cal_component_free_attendee_list (temp_list); } e_cal_component_get_location (comp, &temp_constchar); add_string_to_rdf (node, "location", temp_constchar); e_cal_component_get_last_modified (comp, &temp_time); add_time_to_rdf (node, "lastModified",temp_time); /* Important note! * The documentation is not requiring this! * * if (temp_time) e_cal_component_free_icaltimetype (temp_time); * * Please uncomment and fix documentation if untrue * http://www.gnome.org/projects/evolution/developer-doc/libecal/ECalComponent.html * #e-cal-component-get-last-modified */ } /* I used a buffer rather than xmlDocDump: I want gio support */ xmlNodeDump (buffer, doc, doc->children, 2, 1); g_output_stream_write_all (stream, xmlBufferContent (buffer), xmlBufferLength (buffer), NULL, NULL, &error); g_output_stream_close (stream, NULL, NULL); e_cal_client_free_ecalcomp_slist (objects); xmlBufferFree (buffer); xmlFreeDoc (doc); } if (stream) g_object_unref (stream); g_object_unref (source_client); if (error != NULL) { display_error_message ( gtk_widget_get_toplevel (GTK_WIDGET (selector)), error->message); g_error_free (error); } }
static void cal_search_get_object_list_cb (GObject *source, GAsyncResult *result, gpointer user_data) { ECalClient *client = E_CAL_CLIENT (source); ECalShellView *cal_shell_view = user_data; GSList *icalcomps = NULL; GError *error = NULL; g_return_if_fail (client != NULL); g_return_if_fail (result != NULL); g_return_if_fail (cal_shell_view != NULL); e_cal_client_get_object_list_finish ( client, result, &icalcomps, &error); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { g_warn_if_fail (icalcomps == NULL); g_error_free (error); } else if (error != NULL || !icalcomps) { g_warn_if_fail (icalcomps == NULL); g_clear_error (&error); cal_shell_view->priv->search_pending_count--; if (!cal_shell_view->priv->search_pending_count) { cal_iterate_searching (cal_shell_view); } } else if (cal_shell_view->priv->searching_activity) { GSList *iter; GCancellable *cancellable; time_t start, end; cancellable = e_activity_get_cancellable (cal_shell_view->priv->searching_activity); start = time_add_day (cal_shell_view->priv->search_time, (-1) * cal_shell_view->priv->search_direction); end = cal_shell_view->priv->search_time; if (start > end) { time_t tmp = start; start = end; end = tmp; } for (iter = icalcomps; iter; iter = iter->next) { icalcomponent *icalcomp = iter->data; struct GenerateInstancesData *gid; gid = g_new0 (struct GenerateInstancesData, 1); gid->client = client; gid->cal_shell_view = cal_shell_view; gid->cancellable = g_object_ref (cancellable); e_cal_client_generate_instances_for_object ( client, icalcomp, start, end, cancellable, cal_searching_got_instance_cb, gid, cal_searching_instances_done_cb); } e_cal_client_free_icalcomp_slist (icalcomps); } else {
static void do_save_calendar_csv (FormatHandler *handler, ESourceSelector *selector, ECalClientSourceType type, gchar *dest_uri) { /* * According to some documentation about CSV, newlines 'are' allowed * in CSV-files. But you 'do' have to put the value between quotes. * The helper 'string_needsquotes' will check for that * * http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm * http://www.creativyst.com/cgi-bin/Prod/15/eg/csv2xml.pl */ ESource *primary_source; EClient *source_client; GError *error = NULL; GSList *objects = NULL; GOutputStream *stream; GString *line = NULL; CsvConfig *config = NULL; CsvPluginData *d = handler->data; const gchar *tmp = NULL; if (!dest_uri) return; /* open source client */ primary_source = e_source_selector_ref_primary_selection (selector); source_client = e_cal_client_connect_sync ( primary_source, type, NULL, &error); g_object_unref (primary_source); /* Sanity check. */ g_return_if_fail ( ((source_client != NULL) && (error == NULL)) || ((source_client == NULL) && (error != NULL))); if (source_client == NULL) { display_error_message ( gtk_widget_get_toplevel (GTK_WIDGET (selector)), error); g_error_free (error); return; } config = g_new (CsvConfig, 1); tmp = gtk_entry_get_text (GTK_ENTRY (d->delimiter_entry)); config->delimiter = userstring_to_systemstring (tmp ? tmp:", "); tmp = gtk_entry_get_text (GTK_ENTRY (d->newline_entry)); config->newline = userstring_to_systemstring (tmp ? tmp:"\\n"); tmp = gtk_entry_get_text (GTK_ENTRY (d->quote_entry)); config->quote = userstring_to_systemstring (tmp ? tmp:"\""); config->header = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON (d->header_check)); stream = open_for_writing ( GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (selector))), dest_uri, &error); if (stream && e_cal_client_get_object_list_as_comps_sync (E_CAL_CLIENT (source_client), "#t", &objects, NULL, NULL)) { GSList *iter; if (config->header) { gint i = 0; static const gchar *labels[] = { N_("UID"), N_("Summary"), N_("Description List"), N_("Categories List"), N_("Comment List"), N_("Completed"), N_("Created"), N_("Contact List"), N_("Start"), N_("End"), N_("Due"), N_("percent Done"), N_("Priority"), N_("URL"), N_("Attendees List"), N_("Location"), N_("Modified"), }; line = g_string_new (""); for (i = 0; i < G_N_ELEMENTS (labels); i++) { if (i > 0) g_string_append (line, config->delimiter); g_string_append (line, _(labels[i])); } g_string_append (line, config->newline); g_output_stream_write_all ( stream, line->str, line->len, NULL, NULL, NULL); g_string_free (line, TRUE); } for (iter = objects; iter; iter = iter->next) { ECalComponent *comp = iter->data; gchar *delimiter_temp = NULL; const gchar *temp_constchar; GSList *temp_list; ECalComponentDateTime temp_dt; struct icaltimetype *temp_time; gint *temp_int; ECalComponentText temp_comptext; line = g_string_new (""); /* Getting the stuff */ e_cal_component_get_uid (comp, &temp_constchar); line = add_string_to_csv (line, temp_constchar, config); e_cal_component_get_summary (comp, &temp_comptext); line = add_string_to_csv ( line, temp_comptext.value, config); e_cal_component_get_description_list (comp, &temp_list); line = add_list_to_csv ( line, temp_list, config, ECALCOMPONENTTEXT); if (temp_list) e_cal_component_free_text_list (temp_list); e_cal_component_get_categories_list (comp, &temp_list); line = add_list_to_csv ( line, temp_list, config, CONSTCHAR); if (temp_list) e_cal_component_free_categories_list (temp_list); e_cal_component_get_comment_list (comp, &temp_list); line = add_list_to_csv ( line, temp_list, config, ECALCOMPONENTTEXT); if (temp_list) e_cal_component_free_text_list (temp_list); e_cal_component_get_completed (comp, &temp_time); line = add_time_to_csv (line, temp_time, config); if (temp_time) e_cal_component_free_icaltimetype (temp_time); e_cal_component_get_created (comp, &temp_time); line = add_time_to_csv (line, temp_time, config); if (temp_time) e_cal_component_free_icaltimetype (temp_time); e_cal_component_get_contact_list (comp, &temp_list); line = add_list_to_csv ( line, temp_list, config, ECALCOMPONENTTEXT); if (temp_list) e_cal_component_free_text_list (temp_list); e_cal_component_get_dtstart (comp, &temp_dt); line = add_time_to_csv ( line, temp_dt.value ? temp_dt.value : NULL, config); e_cal_component_free_datetime (&temp_dt); e_cal_component_get_dtend (comp, &temp_dt); line = add_time_to_csv ( line, temp_dt.value ? temp_dt.value : NULL, config); e_cal_component_free_datetime (&temp_dt); e_cal_component_get_due (comp, &temp_dt); line = add_time_to_csv ( line, temp_dt.value ? temp_dt.value : NULL, config); e_cal_component_free_datetime (&temp_dt); e_cal_component_get_percent (comp, &temp_int); line = add_nummeric_to_csv (line, temp_int, config); e_cal_component_get_priority (comp, &temp_int); line = add_nummeric_to_csv (line, temp_int, config); e_cal_component_get_url (comp, &temp_constchar); line = add_string_to_csv (line, temp_constchar, config); if (e_cal_component_has_attendees (comp)) { e_cal_component_get_attendee_list (comp, &temp_list); line = add_list_to_csv ( line, temp_list, config, ECALCOMPONENTATTENDEE); if (temp_list) e_cal_component_free_attendee_list (temp_list); } else { line = add_list_to_csv ( line, NULL, config, ECALCOMPONENTATTENDEE); } e_cal_component_get_location (comp, &temp_constchar); line = add_string_to_csv (line, temp_constchar, config); e_cal_component_get_last_modified (comp, &temp_time); /* Append a newline (record delimiter) */ delimiter_temp = config->delimiter; config->delimiter = config->newline; line = add_time_to_csv (line, temp_time, config); /* And restore for the next record */ config->delimiter = delimiter_temp; /* Important note! * The documentation is not requiring this! * * if (temp_time) * e_cal_component_free_icaltimetype (temp_time); * * Please uncomment and fix documentation if untrue * http://www.gnome.org/projects/evolution/ * developer-doc/libecal/ECalComponent.html * #e-cal-component-get-last-modified */ g_output_stream_write_all ( stream, line->str, line->len, NULL, NULL, &error); /* It's written, so we can free it */ g_string_free (line, TRUE); } g_output_stream_close (stream, NULL, NULL); e_cal_client_free_ecalcomp_slist (objects); } if (stream) g_object_unref (stream); g_object_unref (source_client); g_free (config->delimiter); g_free (config->quote); g_free (config->newline); g_free (config); if (error != NULL) { display_error_message ( gtk_widget_get_toplevel (GTK_WIDGET (selector)), error); g_error_free (error); } }
static void app_load_events (App *app) { GList *clients; GList *l; GList *ll; gchar *since_iso8601; gchar *until_iso8601; /* out with the old */ g_hash_table_remove_all (app->appointments); /* nuke existing views */ for (ll = app->live_views; ll != NULL; ll = ll->next) { ECalClientView *view = E_CAL_CLIENT_VIEW (ll->data); g_signal_handlers_disconnect_by_func (view, on_objects_added, app); g_signal_handlers_disconnect_by_func (view, on_objects_modified, app); g_signal_handlers_disconnect_by_func (view, on_objects_removed, app); e_cal_client_view_stop (view, NULL); g_object_unref (view); } g_list_free (app->live_views); app->live_views = NULL; /* timezone could have changed */ app_update_timezone (app); since_iso8601 = isodate_from_time_t (app->since); until_iso8601 = isodate_from_time_t (app->until); print_debug ("Loading events since %s until %s", since_iso8601, until_iso8601); clients = calendar_sources_get_appointment_clients (app->sources); for (l = clients; l != NULL; l = l->next) { ECalClient *cal = E_CAL_CLIENT (l->data); GError *error; gchar *query; GSList *objects, *j; ECalClientView *view; e_cal_client_set_default_timezone (cal, app->zone); error = NULL; if (!e_client_open_sync (E_CLIENT (cal), TRUE, NULL, &error)) { ESource *source = e_client_get_source (E_CLIENT (cal)); g_warning ("Error opening calendar %s: %s\n", e_source_get_uid (source), error->message); g_error_free (error); continue; } query = g_strdup_printf ("occur-in-time-range? (make-time \"%s\") " "(make-time \"%s\")", since_iso8601, until_iso8601); error = NULL; objects = NULL; if (!e_cal_client_get_object_list_sync (cal, query, &objects, NULL, /* cancellable */ &error)) { ESource *source = e_client_get_source (E_CLIENT (cal)); g_warning ("Error querying calendar %s: %s\n", e_source_get_uid (source), error->message); g_error_free (error); g_free (query); continue; } for (j = objects; j != NULL; j = j->next) { icalcomponent *ical = j->data; CalendarAppointment *appointment; appointment = calendar_appointment_new (ical, cal, app->zone); if (appointment == NULL) continue; calendar_appointment_generate_occurrences (appointment, ical, cal, app->since, app->until, app->zone); g_hash_table_insert (app->appointments, g_strdup (appointment->uid), appointment); } e_cal_client_free_icalcomp_slist (objects); error = NULL; if (!e_cal_client_get_view_sync (cal, query, &view, NULL, /* cancellable */ &error)) { g_warning ("Error setting up live-query on calendar: %s\n", error->message); g_error_free (error); } else { g_signal_connect (view, "objects-added", G_CALLBACK (on_objects_added), app); g_signal_connect (view, "objects-modified", G_CALLBACK (on_objects_modified), app); g_signal_connect (view, "objects-removed", G_CALLBACK (on_objects_removed), app); e_cal_client_view_start (view, NULL); app->live_views = g_list_prepend (app->live_views, view); } g_free (query); } g_list_free (clients); g_free (since_iso8601); g_free (until_iso8601); app->cache_invalid = FALSE; }
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; }
void e_task_shell_view_delete_completed (ETaskShellView *task_shell_view) { ETaskShellContent *task_shell_content; ECalModel *model; GList *list, *link; const gchar *sexp; g_return_if_fail (E_IS_TASK_SHELL_VIEW (task_shell_view)); sexp = "(is-completed?)"; task_shell_content = task_shell_view->priv->task_shell_content; model = e_task_shell_content_get_task_model (task_shell_content); e_task_shell_view_set_status_message ( task_shell_view, _("Expunging"), -1.0); list = e_cal_model_list_clients (model); for (link = list; link != NULL; link = g_list_next (link)) { ECalClient *client = E_CAL_CLIENT (link->data); GSList *objects, *obj; GError *error = NULL; if (e_client_is_readonly (E_CLIENT (client))) continue; e_cal_client_get_object_list_sync ( client, sexp, &objects, NULL, &error); if (error != NULL) { g_warning ( "%s: Failed to get object list: %s", G_STRFUNC, error->message); g_clear_error (&error); continue; } for (obj = objects; obj != NULL; obj = obj->next) { icalcomponent *component = obj->data; const gchar *uid; uid = icalcomponent_get_uid (component); e_cal_client_remove_object_sync ( client, uid, NULL, CALOBJ_MOD_THIS, NULL, &error); if (error != NULL) { g_warning ( "%s: Failed to remove object: %s", G_STRFUNC, error->message); g_clear_error (&error); } } e_cal_client_free_icalcomp_slist (objects); } g_list_free_full (list, (GDestroyNotify) g_object_unref); e_task_shell_view_set_status_message (task_shell_view, NULL, -1.0); }
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; }
static void do_save_calendar_ical (FormatHandler *handler, ESourceSelector *selector, EClientCache *client_cache, gchar *dest_uri) { ESource *primary_source; EClient *source_client; GError *error = NULL; GSList *objects = NULL; icalcomponent *top_level = NULL; if (!dest_uri) return; /* open source client */ primary_source = e_source_selector_ref_primary_selection (selector); source_client = e_client_cache_get_client_sync (client_cache, primary_source, e_source_selector_get_extension_name (selector), 30, NULL, &error); g_object_unref (primary_source); /* Sanity check. */ g_return_if_fail ( ((source_client != NULL) && (error == NULL)) || ((source_client == NULL) && (error != NULL))); if (error != NULL) { display_error_message ( gtk_widget_get_toplevel (GTK_WIDGET (selector)), error->message); g_error_free (error); return; } /* create destination file */ top_level = e_cal_util_new_top_level (); e_cal_client_get_object_list_sync ( E_CAL_CLIENT (source_client), "#t", &objects, NULL, &error); if (objects != NULL) { CompTzData tdata; GOutputStream *stream; GSList *iter; tdata.zones = g_hash_table_new (g_str_hash, g_str_equal); tdata.client = E_CAL_CLIENT (source_client); for (iter = objects; iter; iter = iter->next) { icalcomponent *icalcomp = icalcomponent_new_clone (iter->data); icalcomponent_foreach_tzid (icalcomp, insert_tz_comps, &tdata); icalcomponent_add_component (top_level, icalcomp); } g_hash_table_foreach (tdata.zones, (GHFunc) append_tz_to_comp, top_level); g_hash_table_destroy (tdata.zones); tdata.zones = NULL; /* save the file */ stream = open_for_writing (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (selector))), dest_uri, &error); if (stream) { gchar *ical_str = icalcomponent_as_ical_string_r (top_level); g_output_stream_write_all (stream, ical_str, strlen (ical_str), NULL, NULL, &error); g_output_stream_close (stream, NULL, NULL); g_object_unref (stream); g_free (ical_str); } e_cal_client_free_icalcomp_slist (objects); } if (error != NULL) { display_error_message ( gtk_widget_get_toplevel (GTK_WIDGET (selector)), error->message); g_error_free (error); } /* terminate */ g_object_unref (source_client); icalcomponent_free (top_level); }