aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@src.gnome.org>2009-04-02 06:58:10 +0800
committerMatthew Barnes <mbarnes@src.gnome.org>2009-04-02 06:58:10 +0800
commit3a6dd7931ed7787b49a574ebe69eba5f46289fff (patch)
treef8bdde77fe6bf3fe9d8f4e68fbdb46df6a7abf56 /mail
parent0485fb58c5beeb04f0b3d833e6b73a2d2ec1acc7 (diff)
downloadgsoc2013-evolution-3a6dd7931ed7787b49a574ebe69eba5f46289fff.tar
gsoc2013-evolution-3a6dd7931ed7787b49a574ebe69eba5f46289fff.tar.gz
gsoc2013-evolution-3a6dd7931ed7787b49a574ebe69eba5f46289fff.tar.bz2
gsoc2013-evolution-3a6dd7931ed7787b49a574ebe69eba5f46289fff.tar.lz
gsoc2013-evolution-3a6dd7931ed7787b49a574ebe69eba5f46289fff.tar.xz
gsoc2013-evolution-3a6dd7931ed7787b49a574ebe69eba5f46289fff.tar.zst
gsoc2013-evolution-3a6dd7931ed7787b49a574ebe69eba5f46289fff.zip
Finish attachment drag and drop.
Expunge em-popup.c of dead code. Not much left. Kill the save-attachments (experimental) plugin. The attachment bar can already save all at once. svn path=/branches/kill-bonobo/; revision=37488
Diffstat (limited to 'mail')
-rw-r--r--mail/e-attachment-handler-mail.c160
-rw-r--r--mail/em-popup.c568
2 files changed, 136 insertions, 592 deletions
diff --git a/mail/e-attachment-handler-mail.c b/mail/e-attachment-handler-mail.c
index 32cd884fe2..b7be3b6b38 100644
--- a/mail/e-attachment-handler-mail.c
+++ b/mail/e-attachment-handler-mail.c
@@ -23,6 +23,7 @@
#include <config.h>
#include <glib/gi18n.h>
+#include <camel/camel-stream-mem.h>
#include "mail/em-composer-utils.h"
@@ -47,17 +48,21 @@ static const gchar *ui =
" </popup>"
"</ui>";
+/* Note: Do not use the info field. */
+static GtkTargetEntry target_table[] = {
+ { "message/rfc822", 0, 0 },
+ { "x-uid-list", 0, 0 }
+};
+
static void
-action_mail_forward_cb (GtkAction *action,
- EAttachmentHandler *handler)
+attachment_handler_mail_forward (GtkAction *action,
+ EAttachmentView *view)
{
- EAttachmentView *view;
EAttachment *attachment;
CamelMimePart *mime_part;
CamelDataWrapper *wrapper;
GList *selected;
- view = e_attachment_handler_get_view (handler);
selected = e_attachment_view_get_selected_attachments (view);
g_return_if_fail (g_list_length (selected) == 1);
@@ -72,16 +77,14 @@ action_mail_forward_cb (GtkAction *action,
}
static void
-action_mail_reply_all_cb (GtkAction *action,
- EAttachmentHandler *handler)
+attachment_handler_mail_reply_all (GtkAction *action,
+ EAttachmentView *view)
{
- EAttachmentView *view;
EAttachment *attachment;
CamelMimePart *mime_part;
CamelDataWrapper *wrapper;
GList *selected;
- view = e_attachment_handler_get_view (handler);
selected = e_attachment_view_get_selected_attachments (view);
g_return_if_fail (g_list_length (selected) == 1);
@@ -98,16 +101,14 @@ action_mail_reply_all_cb (GtkAction *action,
}
static void
-action_mail_reply_sender_cb (GtkAction *action,
- EAttachmentHandler *handler)
+attachment_handler_mail_reply_sender (GtkAction *action,
+ EAttachmentView *view)
{
- EAttachmentView *view;
EAttachment *attachment;
CamelMimePart *mime_part;
CamelDataWrapper *wrapper;
GList *selected;
- view = e_attachment_handler_get_view (handler);
selected = e_attachment_view_get_selected_attachments (view);
g_return_if_fail (g_list_length (selected) == 1);
@@ -130,26 +131,109 @@ static GtkActionEntry standard_entries[] = {
N_("_Forward"),
NULL,
NULL, /* XXX Add a tooltip! */
- G_CALLBACK (action_mail_forward_cb) },
+ G_CALLBACK (attachment_handler_mail_forward) },
{ "mail-reply-all",
"mail-reply-all",
N_("Reply to _All"),
NULL,
NULL, /* XXX Add a tooltip! */
- G_CALLBACK (action_mail_reply_all_cb) },
+ G_CALLBACK (attachment_handler_mail_reply_all) },
{ "mail-reply-sender",
"mail-reply-sender",
N_("_Reply to Sender"),
NULL,
NULL, /* XXX Add a tooltip! */
- G_CALLBACK (action_mail_reply_sender_cb) }
+ G_CALLBACK (attachment_handler_mail_reply_sender) }
};
static void
-attachment_handler_mail_update_actions_cb (EAttachmentView *view,
- EAttachmentHandler *handler)
+attachment_handler_mail_message_rfc822 (EAttachmentView *view,
+ GdkDragContext *drag_context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time)
+{
+ static GdkAtom atom = GDK_NONE;
+ EAttachmentStore *store;
+ EAttachment *attachment;
+ CamelMimeMessage *message;
+ CamelDataWrapper *wrapper;
+ CamelStream *stream;
+ const gchar *data;
+ gboolean success = FALSE;
+ gpointer parent;
+ gint length;
+
+ if (G_UNLIKELY (atom == GDK_NONE))
+ atom = gdk_atom_intern_static_string ("message/rfc822");
+
+ if (gtk_selection_data_get_target (selection_data) != atom)
+ return;
+
+ g_signal_stop_emission_by_name (view, "drag-data-received");
+
+ data = (const gchar *) gtk_selection_data_get_data (selection_data);
+ length = gtk_selection_data_get_length (selection_data);
+
+ stream = camel_stream_mem_new ();
+ camel_stream_write (stream, data, length);
+ camel_stream_reset (stream);
+
+ message = camel_mime_message_new ();
+ wrapper = CAMEL_DATA_WRAPPER (message);
+
+ if (camel_data_wrapper_construct_from_stream (wrapper, stream) == -1)
+ goto exit;
+
+ store = e_attachment_view_get_store (view);
+
+ parent = gtk_widget_get_toplevel (GTK_WIDGET (view));
+ parent = GTK_WIDGET_TOPLEVEL (parent) ? parent : NULL;
+
+ attachment = e_attachment_new_for_message (message);
+ e_attachment_store_add_attachment (store, attachment);
+ e_attachment_load_async (
+ attachment, (GAsyncReadyCallback)
+ e_attachment_load_handle_error, parent);
+ g_object_unref (attachment);
+
+ success = TRUE;
+
+exit:
+ camel_object_unref (message);
+ camel_object_unref (stream);
+
+ gtk_drag_finish (drag_context, success, FALSE, time);
+}
+
+static void
+attachment_handler_mail_x_uid_list (EAttachmentView *view,
+ GdkDragContext *drag_context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time)
+{
+ static GdkAtom atom = GDK_NONE;
+
+ if (G_UNLIKELY (atom == GDK_NONE))
+ atom = gdk_atom_intern_static_string ("x-uid-list");
+
+ if (gtk_selection_data_get_target (selection_data) != atom)
+ return;
+
+ return; /* REMOVE ME */
+
+ g_signal_stop_emission_by_name (view, "drag-data-received");
+}
+
+static void
+attachment_handler_mail_update_actions (EAttachmentView *view)
{
EAttachment *attachment;
CamelMimePart *mime_part;
@@ -184,7 +268,6 @@ exit:
static void
attachment_handler_mail_constructed (GObject *object)
{
- EAttachmentHandlerMailPrivate *priv;
EAttachmentHandler *handler;
EAttachmentView *view;
GtkActionGroup *action_group;
@@ -193,7 +276,6 @@ attachment_handler_mail_constructed (GObject *object)
GError *error = NULL;
handler = E_ATTACHMENT_HANDLER (object);
- priv = E_ATTACHMENT_HANDLER_MAIL_GET_PRIVATE (object);
/* Chain up to parent's constructed() method. */
G_OBJECT_CLASS (parent_class)->constructed (object);
@@ -205,7 +287,7 @@ attachment_handler_mail_constructed (GObject *object)
gtk_action_group_set_translation_domain (action_group, domain);
gtk_action_group_add_actions (
action_group, standard_entries,
- G_N_ELEMENTS (standard_entries), object);
+ G_N_ELEMENTS (standard_entries), view);
gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
g_object_unref (action_group);
@@ -218,20 +300,51 @@ attachment_handler_mail_constructed (GObject *object)
g_signal_connect (
view, "update-actions",
- G_CALLBACK (attachment_handler_mail_update_actions_cb),
- object);
+ G_CALLBACK (attachment_handler_mail_update_actions),
+ NULL);
+
+ g_signal_connect (
+ view, "drag-data-received",
+ G_CALLBACK (attachment_handler_mail_message_rfc822),
+ NULL);
+
+ g_signal_connect (
+ view, "drag-data-received",
+ G_CALLBACK (attachment_handler_mail_x_uid_list),
+ NULL);
+}
+
+static GdkDragAction
+attachment_handler_mail_get_drag_actions (EAttachmentHandler *handler)
+{
+ return GDK_ACTION_COPY;
+}
+
+static const GtkTargetEntry *
+attachment_handler_mail_get_target_table (EAttachmentHandler *handler,
+ guint *n_targets)
+{
+ if (n_targets != NULL)
+ *n_targets = G_N_ELEMENTS (target_table);
+
+ return target_table;
}
static void
attachment_handler_mail_class_init (EAttachmentHandlerMailClass *class)
{
GObjectClass *object_class;
+ EAttachmentHandlerClass *handler_class;
parent_class = g_type_class_peek_parent (class);
g_type_class_add_private (class, sizeof (EAttachmentHandlerMailPrivate));
object_class = G_OBJECT_CLASS (class);
object_class->constructed = attachment_handler_mail_constructed;
+
+ handler_class = E_ATTACHMENT_HANDLER_CLASS (class);
+ handler_class->get_drag_actions = attachment_handler_mail_get_drag_actions;
+ handler_class->get_target_table = attachment_handler_mail_get_target_table;
}
static void
@@ -261,8 +374,7 @@ e_attachment_handler_mail_get_type (void)
type = g_type_register_static (
E_TYPE_ATTACHMENT_HANDLER,
- "EAttachmentHandlerMail",
- &type_info, 0);
+ "EAttachmentHandlerMail", &type_info, 0);
}
return type;
diff --git a/mail/em-popup.c b/mail/em-popup.c
index c9dde270a0..e57b1de7f8 100644
--- a/mail/em-popup.c
+++ b/mail/em-popup.c
@@ -55,8 +55,6 @@
#include <e-util/e-util.h>
#include "e-attachment.h"
-static void emp_standard_menu_factory(EPopup *emp, void *data);
-
static GObjectClass *emp_parent;
static void
@@ -116,10 +114,6 @@ emp_class_init(GObjectClass *klass)
{
klass->finalize = emp_finalise;
((EPopupClass *)klass)->target_free = emp_target_free;
-
-#if 0 /* KILL-BONOBO */
- e_popup_class_add_factory((EPopupClass *)klass, NULL, emp_standard_menu_factory, NULL);
-#endif
}
GType
@@ -363,568 +357,6 @@ done:
return t;
}
-#if 0 /* KILL-BONOBO */
-/**
- * em_popup_target_new_attachments:
- * @emp:
- * @attachments: A list of EMsgComposerAttachment objects, reffed for
- * the list. Will be unreff'd once finished with.
- *
- * Owns the list @attachments and their items after they're passed in.
- *
- * Return value:
- **/
-EMPopupTargetAttachments *
-em_popup_target_new_attachments(EMPopup *emp, GSList *attachments)
-{
- EMPopupTargetAttachments *t = e_popup_target_new(&emp->popup, EM_POPUP_TARGET_ATTACHMENTS, sizeof(*t));
- guint32 mask = ~0;
- int len = g_slist_length(attachments);
-
- t->attachments = attachments;
- if (len > 0)
- mask &= ~ EM_POPUP_ATTACHMENTS_MANY;
- if (len == 1 && ((EAttachment *)attachments->data)->is_available_local) {
- EAttachment *attachment;
- CamelMimePart *mime_part;
- CamelContentType *mime_type;
- CamelDataWrapper *data_wrapper;
-
- attachment = attachments->data;
- mime_part = e_attachment_get_mime_part (attachment);
- mime_type = CAMEL_DATA_WRAPPER (mime_part)->mime_type;
- data_wrapper = camel_medium_get_content_object (
- CAMEL_MEDIUM (mime_part));
-
- if (camel_content_type_is (mime_type, "image", "*"))
- mask &= ~ EM_POPUP_ATTACHMENTS_IMAGE;
- if (CAMEL_IS_MIME_MESSAGE (data_wrapper))
- mask &= ~EM_POPUP_ATTACHMENTS_MESSAGE;
-
- mask &= ~ EM_POPUP_ATTACHMENTS_ONE;
- }
- if (len > 1)
- mask &= ~ EM_POPUP_ATTACHMENTS_MULTIPLE;
- t->target.mask = mask;
-
- return t;
-}
-#endif
-
-/* ********************************************************************** */
-
-#if 0 /* KILL-BONOBO */
-static void
-emp_part_popup_saveas(EPopup *ep, EPopupItem *item, void *data)
-{
- EPopupTarget *t = ep->target;
- CamelMimePart *part = NULL;
- GtkWidget *widget;
- gpointer parent;
-
- /* If it is of type EM_POPUP_TARGET_ATTACHMENTS, we can assume the length is one. */
- if (t->type == EM_POPUP_TARGET_ATTACHMENTS) {
- EAttachment *attachment;
-
- attachment = E_ATTACHMENT (((EMPopupTargetAttachments *) t)->attachments->data);
- part = e_attachment_get_mime_part (attachment);
- } else
- part = ((EMPopupTargetPart *) t)->part;
-
- widget = ep->target->widget;
- parent = gtk_widget_get_toplevel (widget);
- parent = GTK_WIDGET_TOPLEVEL (parent) ? parent : NULL;
-
- em_utils_save_part (parent, _("Save As..."), part);
-}
-#endif
-
-#if 0 /* KILL-BONOBO */
-static void
-emp_part_popup_set_background(EPopup *ep, EPopupItem *item, void *data)
-{
- EPopupTarget *t = ep->target;
- GConfClient *gconf;
- char *str, *filename, *path, *extension;
- unsigned int i=1;
- CamelMimePart *part = NULL;
-
- if (t->type == EM_POPUP_TARGET_ATTACHMENTS) {
- EAttachment *attachment;
-
- attachment = E_ATTACHMENT (((EMPopupTargetAttachments *) t)->attachments->data);
- part = e_attachment_get_mime_part (attachment);
- } else
- part = ((EMPopupTargetPart *) t)->part;
-
- if (!part)
- return;
-
- filename = g_strdup(camel_mime_part_get_filename(part));
-
- /* if filename is blank, create a default filename based on MIME type */
- if (!filename || !filename[0]) {
- CamelContentType *ct;
-
- ct = camel_mime_part_get_content_type(part);
- g_free (filename);
- filename = g_strdup_printf (_("untitled_image.%s"), ct->subtype);
- }
-
- e_filename_make_safe(filename);
-
- path = g_build_filename(g_get_home_dir(), ".gnome2", "wallpapers", filename, NULL);
-
- extension = strrchr(filename, '.');
- if (extension)
- *extension++ = 0;
-
- /* if file exists, stick a (number) on the end */
- while (g_file_test(path, G_FILE_TEST_EXISTS)) {
- char *name;
- name = g_strdup_printf(extension?"%s (%d).%s":"%s (%d)", filename, i++, extension);
- g_free(path);
- path = g_build_filename(g_get_home_dir(), ".gnome2", "wallpapers", name, NULL);
- g_free(name);
- }
-
- g_free(filename);
-
- if (em_utils_save_part_to_file(ep->target->widget, path, part)) {
- gconf = gconf_client_get_default();
-
- /* if the filename hasn't changed, blank the filename before
- * setting it so that gconf detects a change and updates it */
- if ((str = gconf_client_get_string(gconf, "/desktop/gnome/background/picture_filename", NULL)) != NULL
- && strcmp (str, path) == 0) {
- gconf_client_set_string(gconf, "/desktop/gnome/background/picture_filename", "", NULL);
- }
-
- g_free (str);
- gconf_client_set_string(gconf, "/desktop/gnome/background/picture_filename", path, NULL);
-
- /* if GNOME currently doesn't display a picture, set to "wallpaper"
- * display mode, otherwise leave it alone */
- if ((str = gconf_client_get_string(gconf, "/desktop/gnome/background/picture_options", NULL)) == NULL
- || strcmp(str, "none") == 0) {
- gconf_client_set_string(gconf, "/desktop/gnome/background/picture_options", "wallpaper", NULL);
- }
-
- gconf_client_suggest_sync(gconf, NULL);
-
- g_free(str);
- g_object_unref(gconf);
- }
-
- g_free(path);
-}
-#endif
-
-static void
-emp_part_popup_reply_sender(EPopup *ep, EPopupItem *item, void *data)
-{
- EPopupTarget *t = ep->target;
- CamelMimeMessage *message;
- CamelMimePart *part;
-
- if (t->type == EM_POPUP_TARGET_ATTACHMENTS) {
- EAttachment *attachment;
-
- attachment = E_ATTACHMENT (((EMPopupTargetAttachments *) t)->attachments->data);
- part = e_attachment_get_mime_part (attachment);
- } else
- part = ((EMPopupTargetPart *) t)->part;
-
- message = (CamelMimeMessage *)camel_medium_get_content_object((CamelMedium *)part);
- em_utils_reply_to_message(NULL, NULL, message, REPLY_MODE_SENDER, NULL);
-}
-
-static void
-emp_part_popup_reply_list (EPopup *ep, EPopupItem *item, void *data)
-{
- EPopupTarget *t = ep->target;
- CamelMimeMessage *message;
- CamelMimePart *part;
-
- if (t->type == EM_POPUP_TARGET_ATTACHMENTS) {
- EAttachment *attachment;
-
- attachment = E_ATTACHMENT (((EMPopupTargetAttachments *) t)->attachments->data);
- part = e_attachment_get_mime_part (attachment);
- } else
- part = ((EMPopupTargetPart *) t)->part;
-
- message = (CamelMimeMessage *)camel_medium_get_content_object((CamelMedium *)part);
- em_utils_reply_to_message(NULL, NULL, message, REPLY_MODE_LIST, NULL);
-}
-
-static void
-emp_part_popup_reply_all (EPopup *ep, EPopupItem *item, void *data)
-{
- EPopupTarget *t = ep->target;
- CamelMimeMessage *message;
- CamelMimePart *part;
-
- if (t->type == EM_POPUP_TARGET_ATTACHMENTS) {
- EAttachment *attachment;
-
- attachment = E_ATTACHMENT (((EMPopupTargetAttachments *) t)->attachments->data);
- part = e_attachment_get_mime_part (attachment);
- } else
- part = ((EMPopupTargetPart *) t)->part;
-
- message = (CamelMimeMessage *)camel_medium_get_content_object((CamelMedium *)part);
- em_utils_reply_to_message(NULL, NULL, message, REPLY_MODE_ALL, NULL);
-}
-
-static void
-emp_part_popup_forward (EPopup *ep, EPopupItem *item, void *data)
-{
- EPopupTarget *t = ep->target;
- CamelMimeMessage *message;
- CamelMimePart *part;
-
- if (t->type == EM_POPUP_TARGET_ATTACHMENTS) {
- EAttachment *attachment;
-
- attachment = E_ATTACHMENT (((EMPopupTargetAttachments *) t)->attachments->data);
- part = e_attachment_get_mime_part (attachment);
- } else
- part = ((EMPopupTargetPart *) t)->part;
-
- /* TODO: have a emfv specific override so we can get the parent folder uri */
- message = (CamelMimeMessage *)camel_medium_get_content_object((CamelMedium *) part);
- em_utils_forward_message(message, NULL);
-}
-
-#if 0 /* KILL-BONOBO */
-static EMPopupItem emp_standard_object_popups[] = {
- { E_POPUP_ITEM, "00.part.00", N_("_Save As..."), emp_part_popup_saveas, NULL, "document-save-as", 0 },
- { E_POPUP_ITEM, "00.part.10", N_("Set as _Background"), emp_part_popup_set_background, NULL, NULL, EM_POPUP_PART_IMAGE },
- { E_POPUP_BAR, "10.part", NULL, NULL, NULL, NULL, EM_POPUP_PART_MESSAGE },
- { E_POPUP_ITEM, "10.part.00", N_("_Reply to sender"), emp_part_popup_reply_sender, NULL, "mail-reply-sender" , EM_POPUP_PART_MESSAGE },
- { E_POPUP_ITEM, "10.part.01", N_("Reply to _List"), emp_part_popup_reply_list, NULL, NULL, EM_POPUP_PART_MESSAGE},
- { E_POPUP_ITEM, "10.part.03", N_("Reply to _All"), emp_part_popup_reply_all, NULL, "mail-reply-all", EM_POPUP_PART_MESSAGE},
- { E_POPUP_BAR, "20.part", NULL, NULL, NULL, NULL, EM_POPUP_PART_MESSAGE },
- { E_POPUP_ITEM, "20.part.00", N_("_Forward"), emp_part_popup_forward, NULL, "mail-forward", EM_POPUP_PART_MESSAGE },
-};
-
-static EMPopupItem emp_attachment_object_popups[] = {
- { E_POPUP_ITEM, "00.attach.00", N_("_Save As..."), emp_part_popup_saveas, NULL, "document-save-as", 0 },
- { E_POPUP_ITEM, "00.attach.10", N_("Set as _Background"), emp_part_popup_set_background, NULL, NULL, EM_POPUP_ATTACHMENTS_IMAGE },
- { E_POPUP_BAR, "05.attach", NULL, NULL, NULL, NULL, EM_POPUP_ATTACHMENTS_MESSAGE },
- { E_POPUP_ITEM, "05.attach.00", N_("_Reply to sender"), emp_part_popup_reply_sender, NULL, "mail-reply-sender" , EM_POPUP_ATTACHMENTS_MESSAGE },
- { E_POPUP_ITEM, "05.attach.01", N_("Reply to _List"), emp_part_popup_reply_list, NULL, NULL, EM_POPUP_ATTACHMENTS_MESSAGE},
- { E_POPUP_ITEM, "05.attach.03", N_("Reply to _All"), emp_part_popup_reply_all, NULL, "mail-reply-all", EM_POPUP_ATTACHMENTS_MESSAGE},
- { E_POPUP_BAR, "05.attach.10", NULL, NULL, NULL, NULL, EM_POPUP_ATTACHMENTS_MESSAGE },
- { E_POPUP_ITEM, "05.attach.15", N_("_Forward"), emp_part_popup_forward, NULL, "mail-forward", EM_POPUP_ATTACHMENTS_MESSAGE },
-};
-
-static const EPopupItem emp_standard_part_apps_bar = { E_POPUP_BAR, "99.object" };
-#endif
-
-/* ********************************************************************** */
-
-static void
-emp_uri_popup_link_open(EPopup *ep, EPopupItem *item, void *data)
-{
- EMPopupTargetURI *t = (EMPopupTargetURI *)ep->target;
- gchar *unescaped_uri = em_utils_url_unescape_amp (t->uri);
-
- /* FIXME Pass a parent window. */
- e_show_uri (NULL, unescaped_uri);
- g_free (unescaped_uri);
-}
-
-static void
-emp_uri_popup_address_send(EPopup *ep, EPopupItem *item, void *data)
-{
- EMPopupTargetURI *t = (EMPopupTargetURI *)ep->target;
-
- /* TODO: have an emfv specific override to get the from uri */
- em_utils_compose_new_message_with_mailto(t->uri, NULL);
-}
-
-static void
-emp_uri_popup_address_add(EPopup *ep, EPopupItem *item, void *data)
-{
- EMPopupTargetURI *t = (EMPopupTargetURI *)ep->target;
- CamelURL *url;
-
- url = camel_url_new(t->uri, NULL);
- if (url == NULL) {
- g_warning("cannot parse url '%s'", t->uri);
- return;
- }
-
- if (url->path && url->path[0])
- em_utils_add_address(ep->target->widget, url->path);
-
- camel_url_free(url);
-}
-
-static EPopupItem emp_standard_uri_popups[] = {
- { E_POPUP_ITEM, "00.uri.00", N_("_Open Link in Browser"), emp_uri_popup_link_open, NULL, NULL, EM_POPUP_URI_HTTP },
- { E_POPUP_ITEM, "00.uri.10", N_("_Send New Message To..."), emp_uri_popup_address_send, NULL, "mail-message-new", EM_POPUP_URI_MAILTO },
- { E_POPUP_ITEM, "00.uri.20", N_("_Add to Address Book"), emp_uri_popup_address_add, NULL, "contact-new", EM_POPUP_URI_MAILTO },
-};
-
-/* ********************************************************************** */
-
-#define LEN(x) (sizeof(x)/sizeof(x[0]))
-
-static void
-emp_apps_open_in(EPopup *ep, EPopupItem *item, void *data)
-{
- char *path;
- EPopupTarget *target = ep->target;
- CamelMimePart *part;
-
- if (target->type == EM_POPUP_TARGET_ATTACHMENTS) {
- EAttachment *attachment;
-
- attachment = E_ATTACHMENT (((EMPopupTargetAttachments *) target)->attachments->data);
- part = e_attachment_get_mime_part (attachment);
- } else
- part = ((EMPopupTargetPart *) target)->part;
-
- path = em_utils_temp_save_part(target->widget, part, TRUE);
- if (path) {
- GAppInfo *app = item->user_data;
- GList *uris = NULL;
- GError *error = NULL;
-
- if (g_app_info_supports_files (app)) {
- GFile *file = g_file_new_for_path (path);
-
- uris = g_list_append (uris, file);
- g_app_info_launch (app, uris, NULL, &error);
- g_object_unref (file);
- } else {
- char *uri;
-
- uri = e_util_filename_to_uri (path);
- uris = g_list_append (uris, uri);
-
- g_app_info_launch_uris (app, uris, NULL, &error);
- g_free (uri);
- }
-
- if (error) {
- g_warning ("%s", error->message);
- g_error_free (error);
- }
-
- g_list_free (uris);
- g_free (path);
- }
-}
-
-static void
-emp_apps_popup_free(EPopup *ep, GSList *free_list, void *data)
-{
- while (free_list) {
- GSList *n = free_list->next;
- EPopupItem *item = free_list->data;
-
- if (item->user_data && item->activate == emp_apps_open_in)
- g_object_unref (item->user_data);
-
- g_free(item->path);
- g_free(item->label);
- g_free(item);
- g_slist_free_1(free_list);
-
- free_list = n;
- }
-}
-
-static void
-emp_standard_items_free(EPopup *ep, GSList *items, void *data)
-{
- g_slist_free(items);
-}
-
-static void
-emp_add_vcard (EPopup *ep, EPopupItem *item, void *data)
-{
- EPopupTarget *target = ep->target;
- CamelMimePart *part;
- CamelDataWrapper *content;
- CamelStreamMem *mem;
-
- if (target->type == EM_POPUP_TARGET_ATTACHMENTS) {
- EAttachment *attachment;
-
- attachment = E_ATTACHMENT (((EMPopupTargetAttachments *) target)->attachments->data);
- part = e_attachment_get_mime_part (attachment);
- } else
- part = ((EMPopupTargetPart *) target)->part;
-
- if (!part)
- return;
-
- content = camel_medium_get_content_object (CAMEL_MEDIUM (part));
- mem = CAMEL_STREAM_MEM (camel_stream_mem_new ());
-
- if (camel_data_wrapper_decode_to_stream (content, CAMEL_STREAM (mem)) == -1 ||
- !mem->buffer->data)
- g_warning ("Read part's content failed!");
- else {
- GString *vcard = g_string_new_len ((const gchar *) mem->buffer->data, mem->buffer->len);
-
- em_utils_add_vcard (target->widget, vcard->str);
-
- g_string_free (vcard, TRUE);
- }
-
- camel_object_unref (mem);
-}
-
-#if 0 /* KILL-BONOBO */
-static void
-emp_standard_menu_factory(EPopup *emp, void *data)
-{
- int i, len;
- EPopupItem *items;
- GSList *menus = NULL;
- GList *apps = NULL;
- char *mime_type = NULL;
- const char *filename = NULL;
-
- switch (emp->target->type) {
-#if 0
- case EM_POPUP_TARGET_SELECT:
- return;
- items = emp_standard_select_popups;
- len = LEN(emp_standard_select_popups);
- break;
-#endif
- case EM_POPUP_TARGET_URI: {
- /*EMPopupTargetURI *t = (EMPopupTargetURI *)target;*/
-
- items = emp_standard_uri_popups;
- len = LEN(emp_standard_uri_popups);
- break; }
- case EM_POPUP_TARGET_PART: {
- EMPopupTargetPart *t = (EMPopupTargetPart *)emp->target;
- mime_type = camel_data_wrapper_get_mime_type((CamelDataWrapper *)t->part);
- filename = camel_mime_part_get_filename(t->part);
-
- items = emp_standard_object_popups;
- len = LEN(emp_standard_object_popups);
- break; }
- case EM_POPUP_TARGET_ATTACHMENTS: {
- EMPopupTargetAttachments *t = (EMPopupTargetAttachments *)emp->target;
- GSList *list = t->attachments;
- EAttachment *attachment;
- CamelMimePart *mime_part;
-
- if (g_slist_length(list) != 1 || !((EAttachment *)list->data)->is_available_local) {
- items = NULL;
- len = 0;
- break;
- }
-
- /* Only one attachment selected */
- attachment = list->data;
- mime_part = e_attachment_get_mime_part (attachment);
- mime_type = camel_data_wrapper_get_mime_type (CAMEL_DATA_WRAPPER (mime_part));
- filename = camel_mime_part_get_filename (mime_part);
-
- items = emp_attachment_object_popups;
- len = LEN(emp_attachment_object_popups);
- break; }
- default:
- items = NULL;
- len = 0;
- }
-
- if (mime_type) {
- gchar *cp;
-
- /* GIO expects lowercase MIME types. */
- for (cp = mime_type; *cp != '\0'; cp++)
- *cp = g_ascii_tolower (*cp);
-
- cp = g_content_type_from_mime_type (mime_type);
- apps = g_app_info_get_all_for_type (cp ? cp : mime_type);
- g_free (cp);
-
- if (apps == NULL && strcmp (mime_type, "application/octet-stream") == 0) {
- if (filename != NULL) {
- gchar *name_type;
-
- name_type = e_util_guess_mime_type (filename, FALSE);
- cp = g_content_type_from_mime_type (name_type);
- apps = g_app_info_get_all_for_type (cp ? cp : name_type);
- g_free (cp);
- g_free (name_type);
- }
- }
-
- if (apps) {
- GString *label = g_string_new("");
- GSList *open_menus = NULL;
- GList *l;
-
- menus = g_slist_prepend(menus, (void *)&emp_standard_part_apps_bar);
-
- for (l = apps, i = 0; l; l = l->next, i++) {
- GAppInfo *app = l->data;
- EPopupItem *item;
-
- if (!g_app_info_should_show (app)) {
- g_object_unref (app);
- l->data = NULL;
- continue;
- }
-
- item = g_malloc0(sizeof(*item));
- item->type = E_POPUP_ITEM;
- item->path = g_strdup_printf("99.object.%02d", i);
- item->label = g_strdup_printf(_("Open in %s..."), g_app_info_get_name (app));
- item->activate = emp_apps_open_in;
- item->user_data = app;
-
- open_menus = g_slist_prepend(open_menus, item);
- }
-
- if (open_menus)
- e_popup_add_items(emp, open_menus, NULL, emp_apps_popup_free, NULL);
-
- g_string_free(label, TRUE);
- g_list_free(apps);
- }
-
- if (g_ascii_strcasecmp (mime_type, "text/x-vcard") == 0||
- g_ascii_strcasecmp (mime_type, "text/vcard") == 0) {
- EPopupItem *item;
-
- item = g_malloc0 (sizeof (*item));
- item->type = E_POPUP_ITEM;
- item->path = "00.00.vcf.00"; /* make it first item */
- item->label = _("_Add to Address Book");
- item->activate = emp_add_vcard;
- item->user_data = NULL;
- item->image = "contact-new";
-
- e_popup_add_items (emp, g_slist_append (NULL, item), NULL, NULL, NULL);
- }
-
- g_free (mime_type);
- }
-
- for (i=0;i<len;i++) {
- if ((items[i].visible & emp->target->mask) == 0)
- menus = g_slist_prepend(menus, &items[i]);
- }
-
- if (menus)
- e_popup_add_items(emp, menus, NULL, emp_standard_items_free, NULL);
-}
-#endif
-
/* ********************************************************************** */
/* Popup menu plugin handler */