[evolution/kill-bonobo] Bug #584030 - [Mail-To-Task] improve duplicate handling and such
- From: Matthew Barnes <mbarnes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [evolution/kill-bonobo] Bug #584030 - [Mail-To-Task] improve duplicate handling and such
- Date: Wed, 12 Aug 2009 14:03:30 +0000 (UTC)
commit 4846995f5ebab385dcae061cc30fa86486ac4ad4
Author: Milan Crha <mcrha redhat com>
Date: Fri Aug 7 18:05:18 2009 +0200
Bug #584030 - [Mail-To-Task] improve duplicate handling and such
calendar/gui/Makefile.am | 23 ++-
calendar/gui/cal-editor-utils.c | 121 ++++++++++++++
calendar/gui/cal-editor-utils.h | 38 +++++
plugins/mail-to-task/Makefile.am | 1 +
plugins/mail-to-task/mail-to-task.c | 313 +++++++++++++++++++++++++++++++++--
5 files changed, 468 insertions(+), 28 deletions(-)
---
diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am
index 28fcf3d..780cb5d 100644
--- a/calendar/gui/Makefile.am
+++ b/calendar/gui/Makefile.am
@@ -8,12 +8,13 @@ privsolib_LTLIBRARIES = libevolution-calendar.la
ecalendarincludedir = $(privincludedir)/calendar/gui
-ecalendarinclude_HEADERS = \
- e-attachment-handler-calendar.h \
+ecalendarinclude_HEADERS = \
+ cal-editor-utils.h \
calendar-config.h \
calendar-config-keys.h \
comp-util.h \
e-alarm-list.h \
+ e-attachment-handler-calendar.h \
e-cal-config.h \
e-cal-event.h \
e-cal-model-calendar.h \
@@ -83,12 +84,8 @@ etspec_DATA = \
e-memo-table.etspec
libevolution_calendar_la_SOURCES = \
- e-attachment-handler-calendar.c \
- e-attachment-handler-calendar.h \
- e-calendar-view.c \
- e-calendar-view.h \
- e-calendar-table.c \
- e-calendar-table.h \
+ cal-editor-utils.c \
+ cal-editor-utils.h \
calendar-config.c \
calendar-config.h \
calendar-config-keys.h \
@@ -100,6 +97,8 @@ libevolution_calendar_la_SOURCES = \
comp-util.h \
e-alarm-list.c \
e-alarm-list.h \
+ e-attachment-handler-calendar.c \
+ e-attachment-handler-calendar.h \
e-cal-component-preview.c \
e-cal-component-preview.h \
e-cal-config.c \
@@ -122,12 +121,16 @@ libevolution_calendar_la_SOURCES = \
e-cal-model-tasks.h \
e-calendar-selector.c \
e-calendar-selector.h \
+ e-calendar-table.c \
+ e-calendar-table.h \
+ e-calendar-view.c \
+ e-calendar-view.h \
e-cell-date-edit-text.h \
e-cell-date-edit-text.c \
e-comp-editor-registry.c \
e-comp-editor-registry.h \
- e-date-time-list.c \
- e-date-time-list.h \
+ e-date-time-list.c \
+ e-date-time-list.h \
e-day-view-layout.c \
e-day-view-layout.h \
e-day-view-main-item.c \
diff --git a/calendar/gui/cal-editor-utils.c b/calendar/gui/cal-editor-utils.c
new file mode 100644
index 0000000..0da7ca2
--- /dev/null
+++ b/calendar/gui/cal-editor-utils.c
@@ -0,0 +1,121 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <e-util/e-dialog-utils.h>
+
+#include "cal-editor-utils.h"
+
+#include "e-comp-editor-registry.h"
+#include "dialogs/event-editor.h"
+#include "dialogs/task-editor.h"
+#include "dialogs/memo-editor.h"
+
+extern ECompEditorRegistry *comp_editor_registry;
+
+/**
+ * open_component_editor:
+ * @client: Already opened #ECal, where to store the component
+ * @comp: #ECalComponent component to be stored
+ * @is_new: Whether the @comp is a new component or an existing
+ * @error: #GError for possible error reporting
+ *
+ * Opens component editor for the event stored in the comp component.
+ * If such component exists in the client already (with the same UID),
+ * then there's opened already stored event, instead of the comp.
+ *
+ * It blocks until finished and should be called in the main thread.
+ **/
+void
+open_component_editor (EShell *shell,
+ ECal *client,
+ ECalComponent *comp,
+ gboolean is_new,
+ GError **error)
+{
+ ECalComponentId *id;
+ CompEditorFlags flags = 0;
+ CompEditor *editor = NULL;
+
+ g_return_if_fail (E_IS_SHELL (shell));
+ g_return_if_fail (E_IS_CAL (client));
+ g_return_if_fail (E_IS_CAL_COMPONENT (comp));
+
+ id = e_cal_component_get_id (comp);
+ g_return_if_fail (id != NULL);
+ g_return_if_fail (id->uid != NULL);
+
+ if (is_new) {
+ flags |= COMP_EDITOR_NEW_ITEM;
+ } else {
+ editor = comp_editor_find_instance (id->uid);
+ }
+
+ if (!editor) {
+ if (itip_organizer_is_user (comp, client))
+ flags |= COMP_EDITOR_USER_ORG;
+
+ switch (e_cal_component_get_vtype (comp)) {
+ case E_CAL_COMPONENT_EVENT:
+ if (e_cal_component_has_attendees (comp))
+ flags |= COMP_EDITOR_MEETING;
+
+ editor = event_editor_new (client, shell, flags);
+
+ if (flags & COMP_EDITOR_MEETING)
+ event_editor_show_meeting (EVENT_EDITOR (editor));
+ break;
+ case E_CAL_COMPONENT_TODO:
+ if (e_cal_component_has_attendees (comp))
+ flags |= COMP_EDITOR_IS_ASSIGNED;
+
+ editor = task_editor_new (client, shell, flags);
+
+ if (flags & COMP_EDITOR_IS_ASSIGNED)
+ task_editor_show_assignment (TASK_EDITOR (editor));
+ break;
+ case E_CAL_COMPONENT_JOURNAL:
+ if (e_cal_component_has_organizer (comp))
+ flags |= COMP_EDITOR_IS_SHARED;
+
+ editor = memo_editor_new (client, shell, flags);
+ break;
+ default:
+ if (error)
+ *error = g_error_new (E_CALENDAR_ERROR, E_CALENDAR_STATUS_INVALID_OBJECT, "%s", _("Invalid object"));
+ break;
+ }
+
+ if (editor) {
+ comp_editor_edit_comp (editor, comp);
+
+ /* request save for new events */
+ comp_editor_set_changed (editor, is_new);
+ }
+ }
+
+ if (editor)
+ gtk_window_present (GTK_WINDOW (editor));
+
+ e_cal_component_free_id (id);
+}
diff --git a/calendar/gui/cal-editor-utils.h b/calendar/gui/cal-editor-utils.h
new file mode 100644
index 0000000..211684e
--- /dev/null
+++ b/calendar/gui/cal-editor-utils.h
@@ -0,0 +1,38 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ *
+ * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
+ *
+ */
+
+#ifndef CAL_EDITOR_UTILS_H
+#define CAL_EDITOR_UTILS_H
+
+#include <glib.h>
+#include <libecal/e-cal.h>
+#include <libecal/e-cal-component.h>
+#include <shell/e-shell.h>
+
+G_BEGIN_DECLS
+
+void open_component_editor (EShell *shell,
+ ECal *client,
+ ECalComponent *comp,
+ gboolean is_new,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* CAL_EDITOR_UTILS_H */
diff --git a/plugins/mail-to-task/Makefile.am b/plugins/mail-to-task/Makefile.am
index b7eb5ed..0815e65 100644
--- a/plugins/mail-to-task/Makefile.am
+++ b/plugins/mail-to-task/Makefile.am
@@ -13,6 +13,7 @@ liborg_gnome_mail_to_task_la_SOURCES = mail-to-task.c
liborg_gnome_mail_to_task_la_LDFLAGS = -module -avoid-version $(NO_UNDEFINED)
liborg_gnome_mail_to_task_la_LIBADD = \
$(top_builddir)/e-util/libeutil.la \
+ $(top_builddir)/calendar/gui/libevolution-calendar.la \
$(top_builddir)/calendar/common/libevolution-calendarprivate.la \
$(top_builddir)/mail/libevolution-mail.la \
$(EVOLUTION_CALENDAR_LIBS) \
diff --git a/plugins/mail-to-task/mail-to-task.c b/plugins/mail-to-task/mail-to-task.c
index 16c1ab5..1afbd31 100644
--- a/plugins/mail-to-task/mail-to-task.c
+++ b/plugins/mail-to-task/mail-to-task.c
@@ -55,6 +55,7 @@
#include <misc/e-popup-action.h>
#include <shell/e-shell-view.h>
#include <shell/e-shell-window-actions.h>
+#include <calendar/gui/cal-editor-utils.h>
#define E_SHELL_WINDOW_ACTION_CONVERT_TO_EVENT(window) \
E_SHELL_WINDOW_ACTION ((window), "mail-convert-to-event")
@@ -336,6 +337,267 @@ report_error_idle (const gchar *format, const gchar *param)
g_idle_add ((GSourceFunc)do_report_error, err);
}
+struct _manage_comp
+{
+ ECal *client;
+ ECalComponent *comp;
+ icalcomponent *stored_comp; /* the one in client already */
+};
+
+static void
+free_manage_comp_struct (struct _manage_comp *mc)
+{
+ g_return_if_fail (mc != NULL);
+
+ g_object_unref (mc->comp);
+ g_object_unref (mc->client);
+ if (mc->stored_comp)
+ icalcomponent_free (mc->stored_comp);
+ g_free (mc);
+}
+
+static gint
+do_ask (const gchar *text, gboolean is_create_edit_add)
+{
+ gint res;
+ GtkWidget *dialog = gtk_message_dialog_new (NULL,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION,
+ is_create_edit_add ? GTK_BUTTONS_NONE : GTK_BUTTONS_YES_NO,
+ "%s", text);
+
+ if (is_create_edit_add) {
+ gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_EDIT, GTK_RESPONSE_YES,
+ GTK_STOCK_NEW, GTK_RESPONSE_NO,
+ NULL);
+ }
+
+ res = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ gtk_widget_destroy (dialog);
+
+ return res;
+}
+
+static const gchar *
+get_question_edit_old (ECalSourceType source_type)
+{
+ const gchar *ask = NULL;
+
+ switch (source_type) {
+ case E_CAL_SOURCE_TYPE_EVENT:
+ ask = _("Selected calendar contains event '%s' already. Would you like to edit the old event?");
+ break;
+ case E_CAL_SOURCE_TYPE_TODO:
+ ask = _("Selected task list contains task '%s' already. Would you like to edit the old task?");
+ break;
+ case E_CAL_SOURCE_TYPE_JOURNAL:
+ ask = _("Selected memo list contains memo '%s' already. Would you like to edit the old memo?");
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+ return ask;
+}
+
+static const gchar *
+get_question_create_new (ECalSourceType source_type)
+{
+ const gchar *ask = NULL;
+
+ switch (source_type) {
+ case E_CAL_SOURCE_TYPE_EVENT:
+ ask = _("Selected calendar contains some events for the given mails already. Would you like to create new events anyway?");
+ break;
+ case E_CAL_SOURCE_TYPE_TODO:
+ ask = _("Selected task list contains some tasks for the given mails already. Would you like to create new tasks anyway?");
+ break;
+ case E_CAL_SOURCE_TYPE_JOURNAL:
+ ask = _("Selected memo list contains some memos for the given mails already. Would you like to create new memos anyway?");
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+ return ask;
+}
+
+static const gchar *
+get_question_create_new_n (ECalSourceType source_type, gint count)
+{
+ const gchar *ask = NULL;
+
+ switch (source_type) {
+ case E_CAL_SOURCE_TYPE_EVENT:
+ ask = ngettext (
+ "Selected calendar contains an event for the given mail already. Would you like to create new event anyway?",
+ "Selected calendar contains events for the given mails already. Would you like to create new events anyway?",
+ count);
+ break;
+ case E_CAL_SOURCE_TYPE_TODO:
+ ask = ngettext (
+ "Selected task list contains a task for the given mail already. Would you like to create new task anyway?",
+ "Selected task list contains tasks for the given mails already. Would you like to create new tasks anyway?",
+ count);
+ break;
+ case E_CAL_SOURCE_TYPE_JOURNAL:
+ ask = ngettext (
+ "Selected memo list contains a memo for the given mail already. Would you like to create new memo anyway?",
+ "Selected memo list contains memos for the given mails already. Would you like to create new memos anyway?",
+ count);
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+ return ask;
+}
+
+static gboolean
+do_manage_comp_idle (GSList *manage_comp_datas)
+{
+ GError *error = NULL;
+ guint with_old = 0;
+ gboolean need_editor = FALSE;
+ ECalSourceType source_type = E_CAL_SOURCE_TYPE_LAST;
+ GSList *l;
+
+ g_return_val_if_fail (manage_comp_datas != NULL, FALSE);
+
+ if (manage_comp_datas->data) {
+ struct _manage_comp *mc = manage_comp_datas->data;
+
+ if (mc->comp && (e_cal_component_has_attendees (mc->comp) || e_cal_component_has_organizer (mc->comp)))
+ need_editor = TRUE;
+
+ source_type = e_cal_get_source_type (mc->client);
+ }
+
+ if (source_type == E_CAL_SOURCE_TYPE_LAST) {
+ g_slist_foreach (manage_comp_datas, (GFunc) free_manage_comp_struct, NULL);
+ g_slist_free (manage_comp_datas);
+
+ g_warning ("mail-to-task: Incorrect call of %s, no data given", G_STRFUNC);
+ return FALSE;
+ }
+
+ for (l = manage_comp_datas; l; l = l->next) {
+ struct _manage_comp *mc = l->data;
+
+ if (mc && mc->stored_comp)
+ with_old++;
+ }
+
+ if (need_editor) {
+ for (l = manage_comp_datas; l && !error; l = l->next) {
+ ECalComponent *edit_comp = NULL;
+ struct _manage_comp *mc = l->data;
+
+ if (!mc)
+ continue;
+
+ if (mc->stored_comp) {
+ const gchar *ask = get_question_edit_old (source_type);
+
+ if (ask) {
+ char *msg = g_strdup_printf (ask, icalcomponent_get_summary (mc->stored_comp) ? icalcomponent_get_summary (mc->stored_comp) : _("[No Summary]"));
+ gint chosen;
+
+ chosen = do_ask (msg, TRUE);
+
+ if (chosen == GTK_RESPONSE_YES) {
+ edit_comp = e_cal_component_new ();
+ if (!e_cal_component_set_icalcomponent (edit_comp, icalcomponent_new_clone (mc->stored_comp))) {
+ g_object_unref (edit_comp);
+ edit_comp = NULL;
+
+ error = g_error_new (E_CALENDAR_ERROR, E_CALENDAR_STATUS_INVALID_OBJECT, "%s", _("Invalid object returned from a server"));
+ }
+ } else if (chosen == GTK_RESPONSE_NO) {
+ /* user wants to create a new event, thus generate a new UID */
+ gchar *new_uid = e_cal_component_gen_uid ();
+
+ edit_comp = mc->comp;
+ e_cal_component_set_uid (edit_comp, new_uid);
+ e_cal_component_set_recurid (edit_comp, NULL);
+
+ g_free (new_uid);
+ }
+
+ g_free (msg);
+ }
+ } else {
+ edit_comp = mc->comp;
+ }
+
+ if (edit_comp) {
+ EShell *shell;
+
+ /* FIXME Pass in the EShell instance. */
+ shell = e_shell_get_default ();
+ open_component_editor (
+ shell, mc->client, edit_comp,
+ edit_comp == mc->comp, &error);
+ if (edit_comp != mc->comp)
+ g_object_unref (edit_comp);
+ }
+ }
+ } else {
+ gboolean can = TRUE;
+
+ if (with_old > 0) {
+ const gchar *ask = NULL;
+
+ can = FALSE;
+
+ if (with_old == g_slist_length (manage_comp_datas)) {
+ ask = get_question_create_new_n (source_type, with_old);
+ } else {
+ ask = get_question_create_new (source_type);
+ }
+
+ if (ask)
+ can = do_ask (ask, FALSE) == GTK_RESPONSE_YES;
+ }
+
+ if (can) {
+ for (l = manage_comp_datas; l && !error; l = l->next) {
+ struct _manage_comp *mc = l->data;
+
+ if (!mc)
+ continue;
+
+ if (mc->stored_comp) {
+ gchar *new_uid = e_cal_component_gen_uid ();
+
+ e_cal_component_set_uid (mc->comp, new_uid);
+ e_cal_component_set_recurid (mc->comp, NULL);
+
+ g_free (new_uid);
+ }
+
+ e_cal_create_object (mc->client, e_cal_component_get_icalcomponent (mc->comp), NULL, &error);
+ }
+ }
+ }
+
+ if (error) {
+ e_notice (NULL, GTK_MESSAGE_ERROR, _("An error occurred during processing: %s"), error->message);
+ g_error_free (error);
+ }
+
+ g_slist_foreach (manage_comp_datas, (GFunc) free_manage_comp_struct, NULL);
+ g_slist_free (manage_comp_datas);
+
+ return FALSE;
+}
+
typedef struct {
ECal *client;
CamelFolder *folder;
@@ -376,6 +638,7 @@ do_mail_to_event (AsyncData *data)
}
}
} else {
+ GSList *mcs = NULL;
gint i;
ECalSourceType source_type = e_cal_get_source_type (client);
ECalComponentDateTime dt, dt2;
@@ -397,6 +660,7 @@ do_mail_to_event (AsyncData *data)
ECalComponentText text;
icalproperty *icalprop;
icalcomponent *icalcomp;
+ struct _manage_comp *mc;
/* retrieve the message from the CamelFolder */
message = camel_folder_get_message (folder, g_ptr_array_index (uids, i), NULL);
@@ -459,23 +723,31 @@ do_mail_to_event (AsyncData *data)
/* set attachment files */
set_attachments (client, comp, 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);
- /* save the task to the selected source */
- if (!e_cal_create_object (client, icalcomp, NULL, &err)) {
- report_error_idle (_("Could not create object. %s"), err ? err->message : _("Unknown error"));
+ mc = g_new0 (struct _manage_comp, 1);
+ mc->client = g_object_ref (client);
+ mc->comp = g_object_ref (comp);
- if (err)
- g_error_free (err);
- err = NULL;
- }
+ if (!e_cal_get_object (client, icalcomponent_get_uid (icalcomp), NULL, &(mc->stored_comp), NULL))
+ mc->stored_comp = NULL;
+
+ mcs = g_slist_append (mcs, mc);
g_object_unref (comp);
}
+
+ if (mcs) {
+ /* process this in the main thread, as we may ask user too */
+ g_idle_add ((GSourceFunc)do_manage_comp_idle, mcs);
+ }
}
/* free memory */
@@ -601,6 +873,8 @@ mail_to_event (ECalSourceType source_type,
/* ask the user which tasks list to save to */
dialog = e_source_selector_dialog_new (NULL, source_list);
+ 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));
@@ -678,30 +952,30 @@ static GtkActionEntry entries[] = {
{ "mail-convert-to-event",
"appointment-new",
- N_("Convert to an _Event"),
+ N_("Create an _Event"),
NULL,
- N_("Convert the selected messages to an event"),
+ N_("Create a new event from the selected message"),
G_CALLBACK (action_mail_convert_to_event_cb) },
{ "mail-convert-to-meeting",
"stock_new-meeting",
- N_("Convert to a _Meeting"),
+ N_("Create a _Meeting"),
NULL,
- N_("Convert the selected messages to a meeting"),
+ N_("Create a new meeting from the selected message"),
G_CALLBACK (action_mail_convert_to_meeting_cb) },
{ "mail-convert-to-memo",
"stock_insert-note",
- N_("Convert to a Mem_o"),
+ N_("Create a Mem_o"),
NULL,
- N_("Convert the selected messages to a memo"),
+ N_("Create a new memo from the selected message"),
G_CALLBACK (action_mail_convert_to_memo_cb) },
{ "mail-convert-to-task",
"stock_todo",
- N_("Convert to a _Task"),
+ N_("Create a _Task"),
NULL,
- N_("Convert the selected messages to a task"),
+ N_("Create a new task from the selected message"),
G_CALLBACK (action_mail_convert_to_task_cb) }
};
@@ -745,14 +1019,17 @@ update_actions_cb (EShellView *shell_view)
action = E_SHELL_WINDOW_ACTION_CONVERT_TO_EVENT (shell_window);
gtk_action_set_sensitive (action, sensitive);
- action = E_SHELL_WINDOW_ACTION_CONVERT_TO_MEETING (shell_window);
- gtk_action_set_sensitive (action, sensitive);
-
action = E_SHELL_WINDOW_ACTION_CONVERT_TO_MEMO (shell_window);
gtk_action_set_sensitive (action, sensitive);
action = E_SHELL_WINDOW_ACTION_CONVERT_TO_TASK (shell_window);
gtk_action_set_sensitive (action, sensitive);
+
+ sensitive = (state & E_MAIL_READER_SELECTION_SINGLE);
+
+ action = E_SHELL_WINDOW_ACTION_CONVERT_TO_MEETING (shell_window);
+ gtk_action_set_sensitive (action, sensitive);
+
}
gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]