diff options
author | Milan Crha <mcrha@redhat.com> | 2007-11-05 18:33:42 +0800 |
---|---|---|
committer | Milan Crha <mcrha@src.gnome.org> | 2007-11-05 18:33:42 +0800 |
commit | c8d11592e475658a7799ac8349bb799d96d2cc0f (patch) | |
tree | 75059e907c9531e3b368d6e861cee5e4097e8799 | |
parent | a1a1f31ef8aa921e84f82d0e88b00ead5e92c738 (diff) | |
download | gsoc2013-evolution-c8d11592e475658a7799ac8349bb799d96d2cc0f.tar.gz 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
-rw-r--r-- | mail/ChangeLog | 4 | ||||
-rw-r--r-- | mail/em-folder-view.c | 4 | ||||
-rw-r--r-- | plugins/mail-to-task/ChangeLog | 10 | ||||
-rw-r--r-- | plugins/mail-to-task/mail-to-task.c | 75 |
4 files changed, 88 insertions, 5 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog index c43eb5fb4d..a02b0d6b72 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,7 @@ +2007-11-05 Milan Crha <mcrha@redhat.com> + + * em-folder-view.c: (emfv_message_reply): Leak fix. + 2007-11-05 Sankar P <psankar@novell.com> * em-folder-tree.c: diff --git a/mail/em-folder-view.c b/mail/em-folder-view.c index 0a8171e14b..f543f7d364 100644 --- a/mail/em-folder-view.c +++ b/mail/em-folder-view.c @@ -1633,7 +1633,7 @@ html_contains_nonwhitespace (const char *html, gint len) static void emfv_message_reply(EMFolderView *emfv, int mode) { - char *html; + char *html = NULL; gint len; if (emfv->list->cursor_uid == NULL) @@ -1666,6 +1666,8 @@ emfv_message_reply(EMFolderView *emfv, int mode) } else { em_utils_reply_to_message (emfv->folder, emfv->list->cursor_uid, NULL, mode, (EMFormat *)emfv->preview); } + + g_free (html); } static void diff --git a/plugins/mail-to-task/ChangeLog b/plugins/mail-to-task/ChangeLog index 364227c2fe..8d09d629b4 100644 --- a/plugins/mail-to-task/ChangeLog +++ b/plugins/mail-to-task/ChangeLog @@ -1,5 +1,15 @@ 2007-11-05 Milan Crha <mcrha@redhat.com> + ** Fix for bug #334675 + + * 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. + +2007-11-05 Milan Crha <mcrha@redhat.com> + ** Fix for bug #353779 * org-gnome-mail-to-task.eplug.xml: 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); |