[evolution/account-mgmt: 41/48] Adapt mail-to-task plugin to the new ESource API.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/account-mgmt: 41/48] Adapt mail-to-task plugin to the new ESource API.
- Date: Fri, 11 Nov 2011 01:28:50 +0000 (UTC)
commit 1fe90194b61347064da43f7b5630f59e70ba6e0f
Author: Matthew Barnes <mbarnes redhat com>
Date: Mon Mar 28 11:15:04 2011 -0400
Adapt mail-to-task plugin to the new ESource API.
plugins/mail-to-task/mail-to-task.c | 130 +++++++++++++++++++----------------
1 files changed, 71 insertions(+), 59 deletions(-)
---
diff --git a/plugins/mail-to-task/mail-to-task.c b/plugins/mail-to-task/mail-to-task.c
index f028528..469aef7 100644
--- a/plugins/mail-to-task/mail-to-task.c
+++ b/plugins/mail-to-task/mail-to-task.c
@@ -35,9 +35,10 @@
#include <gtkhtml/gtkhtml.h>
#include <libecal/e-cal-client.h>
#include <libecal/e-cal-component.h>
-#include <libedataserver/e-account.h>
-#include <libedataserver/e-data-server-util.h>
+#include <libecal/e-source-calendar.h>
#include <libedataserver/e-flag.h>
+#include <libedataserver/e-data-server-util.h>
+#include <libedataserver/e-source-selectable.h>
#include <libedataserverui/e-source-selector-dialog.h>
#include <libedataserverui/e-client-utils.h>
@@ -45,7 +46,6 @@
#include <mail/em-utils.h>
#include <mail/em-format-html.h>
#include <mail/message-list.h>
-#include <e-util/e-account-utils.h>
#include <e-util/e-dialog-utils.h>
#include <misc/e-popup-action.h>
#include <shell/e-shell-view.h>
@@ -80,11 +80,14 @@ get_component_editor (EShell *shell,
ECalComponentId *id;
CompEditorFlags flags = 0;
CompEditor *editor = NULL;
+ ESourceRegistry *registry;
g_return_val_if_fail (E_IS_SHELL (shell), NULL);
g_return_val_if_fail (E_IS_CAL_CLIENT (client), NULL);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), NULL);
+ registry = e_shell_get_registry (shell);
+
id = e_cal_component_get_id (comp);
g_return_val_if_fail (id != NULL, NULL);
g_return_val_if_fail (id->uid != NULL, NULL);
@@ -96,7 +99,7 @@ get_component_editor (EShell *shell,
}
if (!editor) {
- if (itip_organizer_is_user (comp, client))
+ if (itip_organizer_is_user (registry, comp, client))
flags |= COMP_EDITOR_USER_ORG;
switch (e_cal_component_get_vtype (comp)) {
@@ -315,6 +318,7 @@ static gchar *
set_organizer (ECalComponent *comp,
CamelFolder *folder)
{
+#if 0 /* ACCOUNT_MGMT */
EAccount *account = NULL;
const gchar *str, *name;
ECalComponentOrganizer organizer = {NULL, NULL, NULL, NULL};
@@ -343,6 +347,9 @@ set_organizer (ECalComponent *comp,
e_cal_component_set_organizer (comp, &organizer);
return res;
+#endif /* ACCOUNT_MGMT */
+
+ return NULL;
}
struct _att_async_cb_data {
@@ -1067,68 +1074,86 @@ mail_to_event (ECalClientSourceType source_type,
gboolean with_attendees,
EMailReader *reader)
{
+ EShell *shell;
+ EMailBackend *backend;
+ ESourceRegistry *registry;
CamelFolder *folder;
GPtrArray *uids;
- ESourceList *source_list = NULL;
- gboolean done = FALSE;
- GSList *groups, *p;
- ESource *source = NULL, *default_source = NULL;
+ ESource *source = NULL;
+ ESource *default_source;
+ GList *list, *iter;
+ GtkWindow *parent;
+ const gchar *extension_name;
GError *error = NULL;
- gint writable_sources = 0;
folder = e_mail_reader_get_folder (reader);
+ parent = e_mail_reader_get_window (reader);
uids = e_mail_reader_get_selected_uids (reader);
- if (!e_cal_client_get_sources (&source_list, source_type, &error)) {
- e_notice (NULL, GTK_MESSAGE_ERROR, _("Cannot get source list. %s"), error ? error->message : _("Unknown error."));
- if (error)
- g_error_free (error);
- em_utils_uids_free (uids);
- g_object_unref (folder);
- return;
- }
-
- /* Ask before converting 10 or more mails to events */
+ /* Ask before converting 10 or more mails to events. */
if (uids->len > 10) {
- gchar *question = g_strdup_printf (get_question_add_all_mails (source_type), uids->len);
- if (do_ask (question, FALSE) == GTK_RESPONSE_NO) {
- g_free (question);
- g_object_unref (source_list);
+ gchar *question;
+ gint response;
+
+ question = g_strdup_printf (
+ get_question_add_all_mails (source_type), uids->len);
+ response = do_ask (question, FALSE);
+ g_free (question);
+
+ if (response == GTK_RESPONSE_NO) {
em_utils_uids_free (uids);
g_object_unref (folder);
return;
}
- g_free (question);
}
- /* Find 'Default' source. When no source is default, ask user to pick one */
- groups = e_source_list_peek_groups (source_list);
- for (p = groups; p != NULL && !done; p = p->next) {
- ESourceGroup *group = E_SOURCE_GROUP (p->data);
- GSList *sources, *q;
+ 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_get_default_calendar (registry);
+ break;
+ case E_CAL_CLIENT_SOURCE_TYPE_MEMOS:
+ extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
+ default_source = e_source_registry_get_default_memo_list (registry);
+ break;
+ case E_CAL_CLIENT_SOURCE_TYPE_TASKS:
+ extension_name = E_SOURCE_EXTENSION_TASK_LIST;
+ default_source = e_source_registry_get_default_task_list (registry);
+ break;
+ default:
+ g_return_if_reached ();
+ }
+
+ list = e_source_registry_list_sources (registry, extension_name);
- sources = e_source_group_peek_sources (group);
- for (q = sources; q != NULL; q = q->next) {
- ESource *s = E_SOURCE (q->data);
+ /* 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);
+ ESourceSelectable *extension;
- if (s && e_source_get_property (s, "default") && !e_source_get_readonly (s)) {
- default_source = s;
- done = TRUE;
+ extension = e_source_get_extension (candidate, extension_name);
+ if (e_source_selectable_get_writable_hint (extension)) {
+ if (source == NULL)
+ source = candidate;
+ else {
+ source = NULL;
break;
}
-
- if (s && !e_source_get_readonly (s)) {
- writable_sources++;
- source = s;
- }
}
}
- if (!default_source && writable_sources > 1) {
+ g_list_free (list);
+
+ if (source == NULL) {
GtkWidget *dialog;
/* ask the user which tasks list to save to */
- dialog = e_source_selector_dialog_new (NULL, source_list);
+ dialog = e_source_selector_dialog_new (
+ parent, registry, extension_name);
e_source_selector_dialog_select_default_source (
E_SOURCE_SELECTOR_DIALOG (dialog));
@@ -1136,8 +1161,6 @@ mail_to_event (ECalClientSourceType source_type,
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
source = e_source_selector_dialog_peek_primary_selection (
E_SOURCE_SELECTOR_DIALOG (dialog));
- else
- source = NULL;
gtk_widget_destroy (dialog);
} else if (!source && default_source) {
@@ -1145,7 +1168,6 @@ mail_to_event (ECalClientSourceType source_type,
} else {
e_notice (NULL, GTK_MESSAGE_ERROR, _("No writable calendar is available."));
- g_object_unref (source_list);
em_utils_uids_free (uids);
g_object_unref (folder);
if (error)
@@ -1162,21 +1184,13 @@ mail_to_event (ECalClientSourceType source_type,
client = e_cal_client_new (source, source_type, &error);
if (!client) {
- gchar *uri = e_source_get_uri (source);
-
- e_notice (NULL, GTK_MESSAGE_ERROR, "Could not create the client '%s': %s", uri, error ? error->message : "Unknown error");
-
- g_free (uri);
- g_object_unref (source_list);
- em_utils_uids_free (uids);
- g_object_unref (folder);
- if (error)
- g_error_free (error);
+ e_notice (
+ parent, GTK_MESSAGE_ERROR,
+ "Could not connect to '%s'",
+ e_source_get_display_name (source));
return;
}
- g_signal_connect (client, "authenticate", G_CALLBACK (e_client_utils_authenticate_handler), NULL);
-
/* Fill the elements in AsynData */
data = g_new0 (AsyncData, 1);
data->client = client;
@@ -1195,8 +1209,6 @@ mail_to_event (ECalClientSourceType source_type,
g_error_free (error);
}
}
-
- g_object_unref (source_list);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]