/* The clients are just created here but not loaded */ static void create_client_for_source (ESource *source, ECalClientSourceType source_type, CalendarSourceData *source_data) { ClientData *data; ECalClient *client; GError *error = NULL; client = g_hash_table_lookup (source_data->clients, source); g_return_if_fail (client == NULL); client = e_cal_client_new (source, source_type, &error); if (!client) { g_warning ("Could not load source '%s': %s", e_source_get_uid (source), error->message); g_clear_error(&error); return; } data = g_slice_new0 (ClientData); data->client = client; /* takes ownership */ data->backend_died_id = g_signal_connect (client, "backend-died", G_CALLBACK (backend_died_cb), source_data); g_hash_table_insert (source_data->clients, g_object_ref (source), data); }
static void on_delete_cb(GtkAction *action, EShellView *shell_view) { EShellSidebar *shell_sidebar = e_shell_view_get_shell_sidebar(shell_view); ESourceSelector *selector; g_object_get(shell_sidebar, "selector", &selector, NULL); ESource *source = e_source_selector_peek_primary_selection(selector); if (e_alert_run_dialog_for_args(GTK_WINDOW(shell_view), "calendar:prompt-delete-calendar", e_source_peek_name(source), NULL) != GTK_RESPONSE_YES) { g_object_unref (selector); return; } ESourceGroup *group = e_source_peek_group(source); char *calname = (char *)e_source_get_property(source, "eee-calname"); EeeAccount *account; GError *err = NULL; if (!eee_plugin_online) { display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (selector)), _("This action is not available with 3e plugin in offline mode.")); g_object_unref (selector); return; } if (!e_source_is_3e_owned_calendar(source)) { display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (selector)), _("This action is available only for 3e calendars.")); g_object_unref (selector); return; } g_object_unref (selector); account = eee_accounts_manager_find_account_by_source(mgr(), source); if (eee_account_delete_calendar(account, calname)) { // get ECal and remove calendar from the server ECalClient *ecal = e_cal_client_new(source, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, &err); if (!e_client_remove_sync((EClient *)ecal, NULL, &err)) { g_warning("** EEE ** ECal remove failed (%d:%s)", err->code, err->message); g_clear_error(&err); } g_object_unref(ecal); e_source_group_remove_source(group, source); } eee_account_disconnect(account); eee_accounts_manager_restart_sync(mgr()); }
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; ECalClient *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; primary_source = e_source_selector_get_primary_selection (selector); /* open source client */ source_client = e_cal_client_new (primary_source, type, &error); if (source_client) g_signal_connect ( source_client, "authenticate", G_CALLBACK (e_client_utils_authenticate_handler), NULL); if (!source_client || !e_client_open_sync (E_CLIENT (source_client), TRUE, NULL, &error)) { display_error_message ( gtk_widget_get_toplevel (GTK_WIDGET (selector)), error); if (source_client) g_object_unref (source_client); 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 (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 = objects->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) { display_error_message ( gtk_widget_get_toplevel (GTK_WIDGET (selector)), error); g_error_free (error); } return; }