aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2009-08-08 00:05:18 +0800
committerMilan Crha <mcrha@redhat.com>2009-08-08 00:05:18 +0800
commita03f926fd5bc3bad2f5c8884299798290f240ac7 (patch)
treeae993c7ea30a5cd4f396262d0a3526c5de80fc22 /plugins
parent33aa045fc2608bd070c3f31f28ac9d3e702f5137 (diff)
downloadgsoc2013-evolution-a03f926fd5bc3bad2f5c8884299798290f240ac7.tar
gsoc2013-evolution-a03f926fd5bc3bad2f5c8884299798290f240ac7.tar.gz
gsoc2013-evolution-a03f926fd5bc3bad2f5c8884299798290f240ac7.tar.bz2
gsoc2013-evolution-a03f926fd5bc3bad2f5c8884299798290f240ac7.tar.lz
gsoc2013-evolution-a03f926fd5bc3bad2f5c8884299798290f240ac7.tar.xz
gsoc2013-evolution-a03f926fd5bc3bad2f5c8884299798290f240ac7.tar.zst
gsoc2013-evolution-a03f926fd5bc3bad2f5c8884299798290f240ac7.zip
Bug #584030 - [Mail-To-Task] improve duplicate handling and such
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mail-to-task/mail-to-task.c288
-rw-r--r--plugins/mail-to-task/org-gnome-mail-to-task.eplug.xml12
-rw-r--r--plugins/mail-to-task/org-gnome-mail-to-task.xml16
3 files changed, 293 insertions, 23 deletions
diff --git a/plugins/mail-to-task/mail-to-task.c b/plugins/mail-to-task/mail-to-task.c
index e7fa727ff1..b9c3ce3795 100644
--- a/plugins/mail-to-task/mail-to-task.c
+++ b/plugins/mail-to-task/mail-to-task.c
@@ -52,6 +52,7 @@
#include "e-util/e-dialog-utils.h"
#include <gtkhtml/gtkhtml.h>
#include <calendar/common/authentication.h>
+#include <calendar/gui/cal-editor-utils.h>
static gchar *
clean_name(const guchar *s)
@@ -321,6 +322,261 @@ 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) {
+ open_component_editor (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;
@@ -361,6 +617,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;
@@ -382,6 +639,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);
@@ -444,23 +702,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 */
@@ -588,6 +854,8 @@ mail_to_event (ECalSourceType source_type, gboolean with_attendees, GPtrArray *u
/* 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,13 +946,15 @@ org_gnome_mail_to_meeting_menu (EPlugin *ep, EMMenuTargetSelect *t)
void
org_gnome_mail_to_task (gpointer ep, EMPopupTargetSelect *t)
{
- mail_to_event (E_CAL_SOURCE_TYPE_TODO, TRUE, t->uids, t->folder, (EMFolderView *) t->target.widget);
+ /* do not create assigned tasks */
+ mail_to_event (E_CAL_SOURCE_TYPE_TODO, FALSE, t->uids, t->folder, (EMFolderView *) t->target.widget);
}
void
org_gnome_mail_to_task_menu (EPlugin *ep, EMMenuTargetSelect *t)
{
- mail_to_event (E_CAL_SOURCE_TYPE_TODO, TRUE, t->uids, t->folder, (EMFolderView *) t->target.widget);
+ /* do not create assigned tasks */
+ mail_to_event (E_CAL_SOURCE_TYPE_TODO, FALSE, t->uids, t->folder, (EMFolderView *) t->target.widget);
}
void
diff --git a/plugins/mail-to-task/org-gnome-mail-to-task.eplug.xml b/plugins/mail-to-task/org-gnome-mail-to-task.eplug.xml
index 65ae2f4a7b..e8494fb2d7 100644
--- a/plugins/mail-to-task/org-gnome-mail-to-task.eplug.xml
+++ b/plugins/mail-to-task/org-gnome-mail-to-task.eplug.xml
@@ -15,7 +15,7 @@
type="item"
path="70.mail_to_event1"
icon="appointment-new"
- _label="Convert to an _Event"
+ _label="Create an _Event"
enable="many"
visible="many"
activate="org_gnome_mail_to_event"/>
@@ -23,15 +23,15 @@
type="item"
path="70.mail_to_event2"
icon="stock_new-meeting"
- _label="Convert to a _Meeting"
- enable="many"
+ _label="Create a _Meeting"
+ enable="one"
visible="many"
activate="org_gnome_mail_to_meeting"/>
<item
type="item"
path="70.mail_to_event3"
icon="stock_todo"
- _label="Convert to a _Task"
+ _label="Create a _Task"
enable="many"
visible="many"
activate="org_gnome_mail_to_task"/>
@@ -39,7 +39,7 @@
type="item"
path="70.mail_to_event4"
icon="stock_insert-note"
- _label="Convert to a Mem_o"
+ _label="Create a Mem_o"
enable="many"
visible="many"
activate="org_gnome_mail_to_memo"/>
@@ -59,7 +59,7 @@
type="item"
verb="ConvertMeeting"
path="/commands/ConvertMeeting"
- enable="many"
+ enable="one"
activate="org_gnome_mail_to_meeting_menu"/>
<item
type="item"
diff --git a/plugins/mail-to-task/org-gnome-mail-to-task.xml b/plugins/mail-to-task/org-gnome-mail-to-task.xml
index 98accf4c6c..c3d72b6d09 100644
--- a/plugins/mail-to-task/org-gnome-mail-to-task.xml
+++ b/plugins/mail-to-task/org-gnome-mail-to-task.xml
@@ -1,16 +1,16 @@
<Root>
<commands>
- <cmd name="ConvertEvent" _label="Convert to an _Event"
- _tip="Convert the selected message to a new event"
+ <cmd name="ConvertEvent" _label="Create an _Event"
+ _tip="Create a new event from the selected message"
pixtype="stock" pixname="appointment-new"/>
- <cmd name="ConvertMeeting" _label="Convert to a _Meeting"
- _tip="Convert the selected message to a new meeting"
+ <cmd name="ConvertMeeting" _label="Create a _Meeting"
+ _tip="Create a new meeting from the selected message"
pixtype="stock" pixname="stock_new-meeting"/>
- <cmd name="ConvertTask" _label="Convert to a _Task"
- _tip="Convert the selected message to a new task"
+ <cmd name="ConvertTask" _label="Create a _Task"
+ _tip="Create a new task from the selected message"
pixtype="stock" pixname="stock_todo"/>
- <cmd name="ConvertMemo" _label="Convert to a Mem_o"
- _tip="Convert the selected message to a new memo"
+ <cmd name="ConvertMemo" _label="Create a Mem_o"
+ _tip="Create a new memo from the selected message"
pixtype="stock" pixname="stock_insert-note"/>
</commands>