static void source_viewer_update_row (ESourceViewer *viewer, ESource *source) { GHashTable *source_index; GtkTreeRowReference *reference; GtkTreeModel *model; GtkTreePath *path; GtkTreeIter iter; const gchar *display_name; const gchar *source_uid; gboolean removable; gboolean writable; gboolean remote_creatable; gboolean remote_deletable; source_index = viewer->source_index; reference = g_hash_table_lookup (source_index, source); /* We show all sources, so the reference should be valid. */ g_return_if_fail (gtk_tree_row_reference_valid (reference)); model = gtk_tree_row_reference_get_model (reference); path = gtk_tree_row_reference_get_path (reference); gtk_tree_model_get_iter (model, &iter, path); gtk_tree_path_free (path); source_uid = e_source_get_uid (source); display_name = e_source_get_display_name (source); removable = e_source_get_removable (source); writable = e_source_get_writable (source); remote_creatable = e_source_get_remote_creatable (source); remote_deletable = e_source_get_remote_deletable (source); gtk_tree_store_set ( GTK_TREE_STORE (model), &iter, COLUMN_DISPLAY_NAME, display_name, COLUMN_SOURCE_UID, source_uid, COLUMN_REMOVABLE, removable, COLUMN_WRITABLE, writable, COLUMN_REMOTE_CREATABLE, remote_creatable, COLUMN_REMOTE_DELETABLE, remote_deletable, COLUMN_SOURCE, source, -1); }
static void mail_to_event (ECalClientSourceType source_type, gboolean with_attendees, EMailReader *reader) { EShell *shell; EMailBackend *backend; ESourceRegistry *registry; GPtrArray *uids; ESource *source = NULL; ESource *default_source; GList *list, *iter; GtkWindow *parent; const gchar *extension_name; parent = e_mail_reader_get_window (reader); uids = e_mail_reader_get_selected_uids (reader); /* Ask before converting 10 or more mails to events. */ if (uids->len > 10) { gchar *question; gint response; question = g_strdup_printf ( get_question_add_all_mails (source_type, uids->len), uids->len); response = do_ask (question, FALSE); g_free (question); if (response == GTK_RESPONSE_NO) { g_ptr_array_unref (uids); return; } } backend = e_mail_reader_get_backend (reader); shell = e_shell_backend_get_shell (E_SHELL_BACKEND (backend)); registry = e_shell_get_registry (shell); switch (source_type) { case E_CAL_CLIENT_SOURCE_TYPE_EVENTS: extension_name = E_SOURCE_EXTENSION_CALENDAR; default_source = e_source_registry_ref_default_calendar (registry); break; case E_CAL_CLIENT_SOURCE_TYPE_MEMOS: extension_name = E_SOURCE_EXTENSION_MEMO_LIST; default_source = e_source_registry_ref_default_memo_list (registry); break; case E_CAL_CLIENT_SOURCE_TYPE_TASKS: extension_name = E_SOURCE_EXTENSION_TASK_LIST; default_source = e_source_registry_ref_default_task_list (registry); break; default: g_return_if_reached (); } list = e_source_registry_list_sources (registry, extension_name); /* If there is only one writable source, no need to prompt the user. */ for (iter = list; iter != NULL; iter = g_list_next (iter)) { ESource *candidate = E_SOURCE (iter->data); if (e_source_get_writable (candidate)) { if (source == NULL) source = candidate; else { source = NULL; break; } } } g_list_free_full (list, (GDestroyNotify) g_object_unref); if (source == NULL) { GtkWidget *dialog; ESourceSelector *selector; /* ask the user which tasks list to save to */ dialog = e_source_selector_dialog_new ( parent, registry, extension_name); selector = e_source_selector_dialog_get_selector ( E_SOURCE_SELECTOR_DIALOG (dialog)); e_source_selector_set_primary_selection ( selector, default_source); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) source = e_source_selector_dialog_peek_primary_selection ( E_SOURCE_SELECTOR_DIALOG (dialog)); gtk_widget_destroy (dialog); } if (source) { /* if a source has been selected, perform the mail2event operation */ AsyncData *data = NULL; GThread *thread = NULL; GError *error = NULL; /* Fill the elements in AsynData */ data = g_new0 (AsyncData, 1); data->client_cache = g_object_ref (e_shell_get_client_cache (shell)); data->source = g_object_ref (source); data->extension_name = extension_name; data->source_type = source_type; data->folder = e_mail_reader_ref_folder (reader); data->uids = g_ptr_array_ref (uids); data->with_attendees = with_attendees; if (uids->len == 1) data->selected_text = get_selected_text (reader); else data->selected_text = NULL; thread = g_thread_try_new ( NULL, (GThreadFunc) do_mail_to_event, data, &error); if (error != NULL) { g_warning (G_STRLOC ": %s", error->message); g_error_free (error); } else { g_thread_unref (thread); } } g_object_unref (default_source); g_ptr_array_unref (uids); }
gboolean e_mail_store_save_initial_setup_sync (CamelStore *store, GHashTable *save_setup, ESource *collection_source, ESource *account_source, ESource *submission_source, ESource *transport_source, gboolean write_sources, GCancellable *cancellable, GError **error) { gboolean collection_changed = FALSE; gboolean account_changed = FALSE; gboolean submission_changed = FALSE; gboolean transport_changed = FALSE; gboolean success = TRUE; GHashTableIter iter; gpointer key, value; g_return_val_if_fail (CAMEL_IS_STORE (store), FALSE); g_return_val_if_fail (save_setup != NULL, FALSE); g_return_val_if_fail (E_IS_SOURCE (account_source), FALSE); if (!g_hash_table_size (save_setup)) return TRUE; /* The key name consists of up to four parts: Source:Extension:Property[:Type] Source can be 'Collection', 'Account', 'Submission', 'Transport', 'Backend' Extension is any extension name; it's up to the key creator to make sure the extension belongs to that particular Source. Property is a property name in the Extension. Type is an optional letter describing the type of the value; if not set, then string is used. Available values are: 'b' for boolean, 'i' for integer, 's' for string, 'f' for folder full path. All the part values are case sensitive. */ g_hash_table_iter_init (&iter, save_setup); while (g_hash_table_iter_next (&iter, &key, &value)) { gchar **keys; keys = g_strsplit (key, ":", -1); if (g_strv_length (keys) < 3 || g_strv_length (keys) > 4) { g_warning ("%s: Incorrect store setup key, expects 3 or 4 parts, but %d given in '%s'", G_STRFUNC, g_strv_length (keys), (const gchar *) key); } else if (g_str_equal (keys[0], "Collection")) { if (mail_store_save_setup_key (store, collection_source, keys[1], keys[2], keys[3], value)) collection_changed = TRUE; } else if (g_str_equal (keys[0], "Account")) { if (mail_store_save_setup_key (store, account_source, keys[1], keys[2], keys[3], value)) account_changed = TRUE; } else if (g_str_equal (keys[0], "Submission")) { if (mail_store_save_setup_key (store, submission_source, keys[1], keys[2], keys[3], value)) submission_changed = TRUE; } else if (g_str_equal (keys[0], "Transport")) { if (mail_store_save_setup_key (store, transport_source, keys[1], keys[2], keys[3], value)) transport_changed = TRUE; } else if (g_str_equal (keys[0], "Backend")) { ESource *backend_source = NULL; if (collection_source && e_source_has_extension (collection_source, keys[1])) backend_source = collection_source; else if (account_source && e_source_has_extension (account_source, keys[1])) backend_source = account_source; if (mail_store_save_setup_key (store, backend_source, keys[1], keys[2], keys[3], value)) transport_changed = TRUE; } else { g_warning ("%s: Unknown source name '%s' given in '%s'", G_STRFUNC, keys[0], (const gchar *) key); } } if (write_sources) { if (transport_changed && success && e_source_get_writable (transport_source)) success = e_source_write_sync (transport_source, cancellable, error); if (submission_changed && success && e_source_get_writable (submission_source)) success = e_source_write_sync (submission_source, cancellable, error); if (account_changed && success && e_source_get_writable (account_source)) success = e_source_write_sync (account_source, cancellable, error); if (collection_changed && success && e_source_get_writable (collection_source)) success = e_source_write_sync (collection_source, cancellable, error); } return success; }