[evolution/account-mgmt: 43/50] 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: 43/50] Adapt mail-to-task plugin to the new ESource API.
- Date: Wed, 7 Sep 2011 16:11:21 +0000 (UTC)
commit e54dc30427c391a8e9c0a370a01117ebd0ce5be4
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 | 108 ++++++++++++++++-------------------
1 files changed, 49 insertions(+), 59 deletions(-)
---
diff --git a/plugins/mail-to-task/mail-to-task.c b/plugins/mail-to-task/mail-to-task.c
index eb9e762..41ee541 100644
--- a/plugins/mail-to-task/mail-to-task.c
+++ b/plugins/mail-to-task/mail-to-task.c
@@ -36,8 +36,10 @@
#include <gconf/gconf-client.h>
#include <libecal/e-cal-client.h>
#include <libecal/e-cal-component.h>
+#include <libecal/e-source-calendar.h>
#include <libedataserver/e-account.h>
#include <libedataserver/e-flag.h>
+#include <libedataserver/e-source-selectable.h>
#include <libedataserverui/e-source-selector-dialog.h>
#include <libedataserverui/e-client-utils.h>
@@ -45,7 +47,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>
@@ -315,6 +316,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 +345,9 @@ set_organizer (ECalComponent *comp,
e_cal_component_set_organizer (comp, &organizer);
return res;
+#endif /* ACCOUNT_MGMT */
+
+ return NULL;
}
struct _att_async_cb_data {
@@ -1061,75 +1066,68 @@ mail_to_event (ECalClientSourceType source_type,
gboolean with_attendees,
EMailReader *reader)
{
+ 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;
+ 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 */
- 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);
- em_utils_uids_free (uids);
- g_object_unref (folder);
- return;
- }
- g_free (question);
+ switch (source_type) {
+ case E_CAL_SOURCE_TYPE_EVENT:
+ extension_name = E_SOURCE_EXTENSION_CALENDAR;
+ break;
+ case E_CAL_SOURCE_TYPE_JOURNAL:
+ extension_name = E_SOURCE_EXTENSION_MEMO_LIST;
+ break;
+ case E_CAL_SOURCE_TYPE_TODO:
+ extension_name = E_SOURCE_EXTENSION_TASK_LIST;
+ break;
+ default:
+ g_return_if_reached ();
}
- /* 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;
+ registry = e_source_registry_get_default ();
+ 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));
+ e_source_selector_dialog_select_default_source (
+ E_SOURCE_SELECTOR_DIALOG (dialog));
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;
+ source = e_source_selector_dialog_peek_primary_selection (
+ E_SOURCE_SELECTOR_DIALOG (dialog));
gtk_widget_destroy (dialog);
} else if (!source && default_source) {
@@ -1154,16 +1152,10 @@ 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;
}
@@ -1187,8 +1179,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]