aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mail-to-task/mail-to-task.c
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2007-11-05 18:33:42 +0800
committerMilan Crha <mcrha@src.gnome.org>2007-11-05 18:33:42 +0800
commitc8d11592e475658a7799ac8349bb799d96d2cc0f (patch)
tree75059e907c9531e3b368d6e861cee5e4097e8799 /plugins/mail-to-task/mail-to-task.c
parenta1a1f31ef8aa921e84f82d0e88b00ead5e92c738 (diff)
downloadgsoc2013-evolution-c8d11592e475658a7799ac8349bb799d96d2cc0f.tar
gsoc2013-evolution-c8d11592e475658a7799ac8349bb799d96d2cc0f.tar.gz
gsoc2013-evolution-c8d11592e475658a7799ac8349bb799d96d2cc0f.tar.bz2
gsoc2013-evolution-c8d11592e475658a7799ac8349bb799d96d2cc0f.tar.lz
gsoc2013-evolution-c8d11592e475658a7799ac8349bb799d96d2cc0f.tar.xz
gsoc2013-evolution-c8d11592e475658a7799ac8349bb799d96d2cc0f.tar.zst
gsoc2013-evolution-c8d11592e475658a7799ac8349bb799d96d2cc0f.zip
** Fix for bug #334675
2007-11-05 Milan Crha <mcrha@redhat.com> ** Fix for bug #334675 * plugins/mail-to-task/mail-to-task.c: (do_mail_to_task), (text_contains_nonwhitespace), (get_selected_text), (convert_to_task), (org_gnome_mail_to_task), (org_gnome_mail_to_task_menu): When selected only one message, then try to use selected text in preview as description, instead of whole message body. * Requires newer GthHtml (API extended, since revision 8614). * mail/em-folder-view.c: (emfv_message_reply): Leak fix. svn path=/trunk/; revision=34497
Diffstat (limited to 'plugins/mail-to-task/mail-to-task.c')
-rw-r--r--plugins/mail-to-task/mail-to-task.c75
1 files changed, 71 insertions, 4 deletions
diff --git a/plugins/mail-to-task/mail-to-task.c b/plugins/mail-to-task/mail-to-task.c
index 1b0ba16998..6d4f0c4735 100644
--- a/plugins/mail-to-task/mail-to-task.c
+++ b/plugins/mail-to-task/mail-to-task.c
@@ -28,12 +28,16 @@
#include "mail/em-menu.h"
#include "mail/em-popup.h"
#include "mail/em-utils.h"
+#include "mail/em-folder-view.h"
+#include "mail/em-format-html.h"
+#include <gtkhtml/gtkhtml.h>
#include <calendar/common/authentication.h>
typedef struct {
ECal *client;
struct _CamelFolder *folder;
GPtrArray *uids;
+ char *selected_text;
}AsyncData;
static char *
@@ -285,7 +289,17 @@ do_mail_to_task (AsyncData *data)
e_cal_component_set_summary (comp, &text);
/* set all fields */
- set_description (comp, message);
+ if (data->selected_text) {
+ GSList sl;
+
+ text.value = data->selected_text;
+ text.altrep = NULL;
+ sl.next = NULL;
+ sl.data = &text;
+
+ e_cal_component_set_description_list (comp, &sl);
+ } else
+ set_description (comp, message);
set_organizer (comp, message);
set_attendees (comp, message);
@@ -308,6 +322,7 @@ do_mail_to_task (AsyncData *data)
/* free memory */
g_object_unref (data->client);
g_ptr_array_free (data->uids, TRUE);
+ g_free (data->selected_text);
g_free (data);
data = NULL;
@@ -323,8 +338,55 @@ copy_uids (char *uid, GPtrArray *uid_array)
g_ptr_array_add (uid_array, g_strdup (uid));
}
+static gboolean
+text_contains_nonwhitespace (const char *text, gint len)
+{
+ const char *p;
+ gunichar c = 0;
+
+ if (!text || len<=0)
+ return FALSE;
+
+ p = text;
+
+ while (p && p - text < len) {
+ c = g_utf8_get_char (p);
+ if (!c)
+ break;
+
+ if (!g_unichar_isspace (c))
+ break;
+
+ p = g_utf8_next_char (p);
+ }
+
+ return p - text < len - 1 && c != 0;
+}
+
+/* should be freed with g_free after done with it */
+static char *
+get_selected_text (EMFolderView *emfv)
+{
+ char *text = NULL;
+ gint len;
+
+ if (!emfv || !emfv->preview || !gtk_html_command (((EMFormatHTML *)emfv->preview)->html, "is-selection-active"))
+ return NULL;
+
+ if (gtk_html_command (((EMFormatHTML *)emfv->preview)->html, "is-selection-active")
+ && (text = gtk_html_get_selection_plain_text (((EMFormatHTML *)emfv->preview)->html, &len))
+ && len && text && text[0] && text_contains_nonwhitespace (text, len)) {
+ /* selection is ok, so use it as returned from gtkhtml widget */
+ } else {
+ g_free (text);
+ text = NULL;
+ }
+
+ return text;
+}
+
static void
-convert_to_task (GPtrArray *uid_array, struct _CamelFolder *folder)
+convert_to_task (GPtrArray *uid_array, struct _CamelFolder *folder, EMFolderView *emfv)
{
GtkWidget *dialog;
GConfClient *conf_client;
@@ -366,6 +428,11 @@ convert_to_task (GPtrArray *uid_array, struct _CamelFolder *folder)
data->folder = folder;
data->uids = uid_array;
+ if (uid_array->len == 1)
+ data->selected_text = get_selected_text (emfv);
+ else
+ data->selected_text = NULL;
+
thread = g_thread_create ((GThreadFunc) do_mail_to_task, data, FALSE, &error);
if (!thread) {
g_warning (G_STRLOC ": %s", error->message);
@@ -396,7 +463,7 @@ org_gnome_mail_to_task (void *ep, EMPopupTargetSelect *t)
return;
}
- convert_to_task (uid_array, t->folder);
+ convert_to_task (uid_array, t->folder, (EMFolderView *) t->target.widget);
}
void org_gnome_mail_to_task_menu (EPlugin *ep, EMMenuTargetSelect *t)
@@ -413,7 +480,7 @@ void org_gnome_mail_to_task_menu (EPlugin *ep, EMMenuTargetSelect *t)
return;
}
- convert_to_task (uid_array, t->folder);
+ convert_to_task (uid_array, t->folder, (EMFolderView *) t->target.widget);
}
int e_plugin_lib_enable(EPluginLib *ep, int enable);