aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc
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 /widgets/misc
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 'widgets/misc')
-rw-r--r--widgets/misc/Makefile.am2
-rw-r--r--widgets/misc/e-attachment-handler.c34
-rw-r--r--widgets/misc/e-attachment-handler.h11
-rw-r--r--widgets/misc/e-attachment-paned.c17
-rw-r--r--widgets/misc/e-attachment-paned.h8
-rw-r--r--widgets/misc/e-attachment-store.c338
-rw-r--r--widgets/misc/e-attachment-store.h5
-rw-r--r--widgets/misc/e-attachment-view.c614
-rw-r--r--widgets/misc/e-attachment-view.h18
-rw-r--r--widgets/misc/e-attachment.c25
-rw-r--r--widgets/misc/e-mime-part-utils.c223
-rw-r--r--widgets/misc/e-mime-part-utils.h46
12 files changed, 532 insertions, 809 deletions
diff --git a/widgets/misc/Makefile.am b/widgets/misc/Makefile.am
index ad2f445eea..8ba66287f8 100644
--- a/widgets/misc/Makefile.am
+++ b/widgets/misc/Makefile.am
@@ -70,7 +70,6 @@ widgetsinclude_HEADERS = \
e-image-chooser.h \
e-map.h \
e-menu-tool-button.h \
- e-mime-part-utils.h \
e-online-button.h \
e-popup-action.h \
e-popup-menu.h \
@@ -134,7 +133,6 @@ libemiscwidgets_la_SOURCES = \
e-image-chooser.c \
e-map.c \
e-menu-tool-button.c \
- e-mime-part-utils.c \
e-online-button.c \
e-popup-action.c \
e-popup-menu.c \
diff --git a/widgets/misc/e-attachment-handler.c b/widgets/misc/e-attachment-handler.c
index dce139f9c3..03af1eec9b 100644
--- a/widgets/misc/e-attachment-handler.c
+++ b/widgets/misc/e-attachment-handler.c
@@ -155,3 +155,37 @@ e_attachment_handler_get_view (EAttachmentHandler *handler)
return E_ATTACHMENT_VIEW (handler->priv->view);
}
+
+GdkDragAction
+e_attachment_handler_get_drag_actions (EAttachmentHandler *handler)
+{
+ EAttachmentHandlerClass *class;
+
+ g_return_val_if_fail (E_IS_ATTACHMENT_HANDLER (handler), 0);
+
+ class = E_ATTACHMENT_HANDLER_GET_CLASS (handler);
+
+ if (class->get_drag_actions != NULL)
+ return class->get_drag_actions (handler);
+
+ return 0;
+}
+
+const GtkTargetEntry *
+e_attachment_handler_get_target_table (EAttachmentHandler *handler,
+ guint *n_targets)
+{
+ EAttachmentHandlerClass *class;
+
+ g_return_val_if_fail (E_IS_ATTACHMENT_HANDLER (handler), NULL);
+
+ class = E_ATTACHMENT_HANDLER_GET_CLASS (handler);
+
+ if (class->get_target_table != NULL)
+ return class->get_target_table (handler, n_targets);
+
+ if (n_targets != NULL)
+ *n_targets = 0;
+
+ return NULL;
+}
diff --git a/widgets/misc/e-attachment-handler.h b/widgets/misc/e-attachment-handler.h
index 8de5743ba6..05df3e8bbe 100644
--- a/widgets/misc/e-attachment-handler.h
+++ b/widgets/misc/e-attachment-handler.h
@@ -56,11 +56,22 @@ struct _EAttachmentHandler {
struct _EAttachmentHandlerClass {
GObjectClass parent_class;
+
+ GdkDragAction (*get_drag_actions) (EAttachmentHandler *handler);
+ const GtkTargetEntry *
+ (*get_target_table) (EAttachmentHandler *handler,
+ guint *n_targets);
};
GType e_attachment_handler_get_type (void);
EAttachmentView *
e_attachment_handler_get_view (EAttachmentHandler *handler);
+GdkDragAction e_attachment_handler_get_drag_actions
+ (EAttachmentHandler *handler);
+const GtkTargetEntry *
+ e_attachment_handler_get_target_table
+ (EAttachmentHandler *handler,
+ guint *n_targets);
G_END_DECLS
diff --git a/widgets/misc/e-attachment-paned.c b/widgets/misc/e-attachment-paned.c
index 42890236e9..f9f7bb1cca 100644
--- a/widgets/misc/e-attachment-paned.c
+++ b/widgets/misc/e-attachment-paned.c
@@ -729,3 +729,20 @@ e_attachment_paned_set_expanded (EAttachmentPaned *paned,
g_object_notify (G_OBJECT (paned), "expanded");
}
+
+void
+e_attachment_paned_drag_data_received (EAttachmentPaned *paned,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection,
+ guint info,
+ guint time)
+{
+ g_return_if_fail (E_IS_ATTACHMENT_PANED (paned));
+
+ /* XXX Dirty hack for forwarding drop events. */
+ g_signal_emit_by_name (
+ paned->priv->icon_view, "drag-data-received",
+ context, x, y, selection, info, time);
+}
diff --git a/widgets/misc/e-attachment-paned.h b/widgets/misc/e-attachment-paned.h
index c15d642771..076ab6033e 100644
--- a/widgets/misc/e-attachment-paned.h
+++ b/widgets/misc/e-attachment-paned.h
@@ -70,6 +70,14 @@ void e_attachment_paned_set_active_view
gboolean e_attachment_paned_get_expanded (EAttachmentPaned *paned);
void e_attachment_paned_set_expanded (EAttachmentPaned *paned,
gboolean expanded);
+void e_attachment_paned_drag_data_received
+ (EAttachmentPaned *paned,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection,
+ guint info,
+ guint time);
G_END_DECLS
diff --git a/widgets/misc/e-attachment-store.c b/widgets/misc/e-attachment-store.c
index e565d68cae..589f670f34 100644
--- a/widgets/misc/e-attachment-store.c
+++ b/widgets/misc/e-attachment-store.c
@@ -21,10 +21,12 @@
#include "e-attachment-store.h"
+#include <errno.h>
+#include <config.h>
#include <glib/gi18n.h>
#include "e-util/e-util.h"
-#include "e-util/gconf-bridge.h"
+#include "e-util/e-mktemp.h"
#define E_ATTACHMENT_STORE_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
@@ -32,8 +34,6 @@
struct _EAttachmentStorePrivate {
GHashTable *attachment_index;
- gchar *background_filename;
- gchar *background_options;
gchar *current_folder;
guint ignore_row_changed : 1;
@@ -41,8 +41,6 @@ struct _EAttachmentStorePrivate {
enum {
PROP_0,
- PROP_BACKGROUND_FILENAME,
- PROP_BACKGROUND_OPTIONS,
PROP_CURRENT_FOLDER,
PROP_NUM_ATTACHMENTS,
PROP_NUM_LOADING,
@@ -51,44 +49,6 @@ enum {
static gpointer parent_class;
-static const gchar *
-attachment_store_get_background_filename (EAttachmentStore *store)
-{
- return store->priv->background_filename;
-}
-
-static void
-attachment_store_set_background_filename (EAttachmentStore *store,
- const gchar *background_filename)
-{
- if (background_filename == NULL)
- background_filename = "";
-
- g_free (store->priv->background_filename);
- store->priv->background_filename = g_strdup (background_filename);
-
- g_object_notify (G_OBJECT (store), "background-filename");
-}
-
-static const gchar *
-attachment_store_get_background_options (EAttachmentStore *store)
-{
- return store->priv->background_options;
-}
-
-static void
-attachment_store_set_background_options (EAttachmentStore *store,
- const gchar *background_options)
-{
- if (background_options == NULL)
- background_options = "";
-
- g_free (store->priv->background_options);
- store->priv->background_options = g_strdup (background_options);
-
- g_object_notify (G_OBJECT (store), "background-options");
-}
-
static void
attachment_store_set_property (GObject *object,
guint property_id,
@@ -96,18 +56,6 @@ attachment_store_set_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
- case PROP_BACKGROUND_FILENAME:
- attachment_store_set_background_filename (
- E_ATTACHMENT_STORE (object),
- g_value_get_string (value));
- return;
-
- case PROP_BACKGROUND_OPTIONS:
- attachment_store_set_background_options (
- E_ATTACHMENT_STORE (object),
- g_value_get_string (value));
- return;
-
case PROP_CURRENT_FOLDER:
e_attachment_store_set_current_folder (
E_ATTACHMENT_STORE (object),
@@ -125,20 +73,6 @@ attachment_store_get_property (GObject *object,
GParamSpec *pspec)
{
switch (property_id) {
- case PROP_BACKGROUND_FILENAME:
- g_value_set_string (
- value,
- attachment_store_get_background_filename (
- E_ATTACHMENT_STORE (object)));
- return;
-
- case PROP_BACKGROUND_OPTIONS:
- g_value_set_string (
- value,
- attachment_store_get_background_options (
- E_ATTACHMENT_STORE (object)));
- return;
-
case PROP_CURRENT_FOLDER:
g_value_set_string (
value,
@@ -193,8 +127,6 @@ attachment_store_finalize (GObject *object)
g_hash_table_destroy (priv->attachment_index);
- g_free (priv->background_filename);
- g_free (priv->background_options);
g_free (priv->current_folder);
/* Chain up to parent's finalize() method. */
@@ -202,26 +134,6 @@ attachment_store_finalize (GObject *object)
}
static void
-attachment_store_constructed (GObject *object)
-{
- EAttachmentStorePrivate *priv;
- GConfBridge *bridge;
- const gchar *prop;
- const gchar *key;
-
- priv = E_ATTACHMENT_STORE_GET_PRIVATE (object);
- bridge = gconf_bridge_get ();
-
- prop = "background-filename";
- key = "/desktop/gnome/background/picture_filename";
- gconf_bridge_bind_property (bridge, key, object, prop);
-
- prop = "background-options";
- key = "/desktop/gnome/background/picture_options";
- gconf_bridge_bind_property (bridge, key, object, prop);
-}
-
-static void
attachment_store_class_init (EAttachmentStoreClass *class)
{
GObjectClass *object_class;
@@ -234,29 +146,6 @@ attachment_store_class_init (EAttachmentStoreClass *class)
object_class->get_property = attachment_store_get_property;
object_class->dispose = attachment_store_dispose;
object_class->finalize = attachment_store_finalize;
- object_class->constructed = attachment_store_constructed;
-
- g_object_class_install_property (
- object_class,
- PROP_BACKGROUND_FILENAME,
- g_param_spec_string (
- "background-filename",
- "Background Filename",
- NULL,
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT));
-
- g_object_class_install_property (
- object_class,
- PROP_BACKGROUND_OPTIONS,
- g_param_spec_string (
- "background-options",
- "Background Options",
- NULL,
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT));
g_object_class_install_property (
object_class,
@@ -737,101 +626,124 @@ e_attachment_store_run_save_dialog (EAttachmentStore *store,
return destination;
}
-/******************* e_attachment_store_save_list_async() ********************/
+/******************** e_attachment_store_get_uris_async() ********************/
-typedef struct _SaveContext SaveContext;
+typedef struct _UriContext UriContext;
-struct _SaveContext {
+struct _UriContext {
GSimpleAsyncResult *simple;
GList *attachment_list;
GError *error;
+ gchar **uris;
+ gint index;
};
-static SaveContext *
-attachment_store_save_context_new (EAttachmentStore *store,
- GList *attachment_list,
- GAsyncReadyCallback callback,
- gpointer user_data)
+static UriContext *
+attachment_store_uri_context_new (EAttachmentStore *store,
+ GList *attachment_list,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- SaveContext *save_context;
+ UriContext *uri_context;
GSimpleAsyncResult *simple;
+ guint length;
+ gchar **uris;
simple = g_simple_async_result_new (
G_OBJECT (store), callback, user_data,
- e_attachment_store_save_list_async);
+ e_attachment_store_get_uris_async);
+
+ /* Add one for NULL terminator. */
+ length = g_list_length (attachment_list) + 1;
+ uris = g_malloc0 (sizeof (gchar *) * length);
- save_context = g_slice_new0 (SaveContext);
- save_context->simple = simple;
- save_context->attachment_list = g_list_copy (attachment_list);
+ uri_context = g_slice_new0 (UriContext);
+ uri_context->simple = simple;
+ uri_context->attachment_list = g_list_copy (attachment_list);
+ uri_context->uris = uris;
g_list_foreach (
- save_context->attachment_list,
+ uri_context->attachment_list,
(GFunc) g_object_ref, NULL);
- return save_context;
+ return uri_context;
}
static void
-attachment_store_save_context_free (SaveContext *save_context)
+attachment_store_uri_context_free (UriContext *uri_context)
{
/* Do not free the GSimpleAsyncResult. */
/* The attachment list should be empty now. */
- g_warn_if_fail (save_context->attachment_list != NULL);
+ g_warn_if_fail (uri_context->attachment_list == NULL);
/* So should the error. */
- g_warn_if_fail (save_context->error != NULL);
+ g_warn_if_fail (uri_context->error == NULL);
- g_slice_free (SaveContext, save_context);
+ g_strfreev (uri_context->uris);
+
+ g_slice_free (UriContext, uri_context);
}
static void
-attachment_store_save_list_finished_cb (EAttachment *attachment,
- GAsyncResult *result,
- SaveContext *save_context)
+attachment_store_get_uris_save_cb (EAttachment *attachment,
+ GAsyncResult *result,
+ UriContext *uri_context)
{
- GFile *file;
GSimpleAsyncResult *simple;
+ GFile *file;
+ gchar **uris;
+ gchar *uri;
GError *error = NULL;
file = e_attachment_save_finish (attachment, result, &error);
- if (file != NULL)
- g_object_unref (file);
/* Remove the attachment from the list. */
- save_context->attachment_list = g_list_remove (
- save_context->attachment_list, attachment);
+ uri_context->attachment_list = g_list_remove (
+ uri_context->attachment_list, attachment);
g_object_unref (attachment);
- /* If this is the first error, cancel the other jobs. */
- if (error != NULL && save_context->error == NULL) {
- g_propagate_error (&save_context->error, error);
- g_list_foreach (
- save_context->attachment_list,
- (GFunc) e_attachment_cancel, NULL);
+ if (file != NULL) {
+ uri = g_file_get_uri (file);
+ uri_context->uris[uri_context->index++] = uri;
+ g_object_unref (file);
- /* Otherwise, we can only report back one error. So if this is
- * something other than cancellation, dump it to the terminal. */
- } else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- g_warning ("%s", error->message);
+ } else if (error != NULL) {
+ /* If this is the first error, cancel the other jobs. */
+ if (uri_context->error == NULL) {
+ g_propagate_error (&uri_context->error, error);
+ g_list_foreach (
+ uri_context->attachment_list,
+ (GFunc) e_attachment_cancel, NULL);
+
+ /* Otherwise, we can only report back one error. So if
+ * this is something other than cancellation, dump it to
+ * the terminal. */
+ } else if (!g_error_matches (
+ error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("%s", error->message);
- if (error != NULL)
g_error_free (error);
+ }
/* If there's still jobs running, let them finish. */
- if (save_context->attachment_list != NULL)
+ if (uri_context->attachment_list != NULL)
return;
/* Steal the result. */
- simple = save_context->simple;
- save_context->simple = NULL;
+ simple = uri_context->simple;
+ uri_context->simple = NULL;
- /* Steal the error, too. */
- error = save_context->error;
- save_context->error = NULL;
+ /* And the URI list. */
+ uris = uri_context->uris;
+ uri_context->uris = NULL;
+
+ /* And the error. */
+ error = uri_context->error;
+ uri_context->error = NULL;
if (error == NULL)
- g_simple_async_result_set_op_res_gboolean (simple, TRUE);
+ g_simple_async_result_set_op_res_gpointer (simple, uris, NULL);
else {
g_simple_async_result_set_from_error (simple, error);
g_error_free (error);
@@ -839,63 +751,109 @@ attachment_store_save_list_finished_cb (EAttachment *attachment,
g_simple_async_result_complete (simple);
- attachment_store_save_context_free (save_context);
+ attachment_store_uri_context_free (uri_context);
}
void
-e_attachment_store_save_list_async (EAttachmentStore *store,
- GList *attachment_list,
- GFile *destination,
- GAsyncReadyCallback callback,
- gpointer user_data)
+e_attachment_store_get_uris_async (EAttachmentStore *store,
+ GList *attachment_list,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- SaveContext *save_context;
+ GFile *temp_directory;
+ UriContext *uri_context;
+ GList *iter, *trash = NULL;
+ gchar *template;
+ gchar *path;
g_return_if_fail (E_IS_ATTACHMENT_STORE (store));
- g_return_if_fail (G_IS_FILE (destination));
g_return_if_fail (callback != NULL);
- /* Passing an empty list is silly, but we'll handle it. */
- if (attachment_list == NULL) {
+ uri_context = attachment_store_uri_context_new (
+ store, attachment_list, callback, user_data);
+
+ /* Grab the copied attachment list. */
+ attachment_list = uri_context->attachment_list;
+
+ /* First scan the list for attachments with a GFile. */
+ for (iter = attachment_list; iter != NULL; iter = iter->next) {
+ EAttachment *attachment = iter->data;
+ GFile *file;
+ gchar *uri;
+
+ file = e_attachment_get_file (attachment);
+ if (file == NULL)
+ continue;
+
+ uri = g_file_get_uri (file);
+ uri_context->uris[uri_context->index++] = uri;
+
+ /* Mark the list node for deletion. */
+ trash = g_list_prepend (trash, iter);
+ g_object_unref (attachment);
+ }
+
+ /* Expunge the list. */
+ for (iter = trash; iter != NULL; iter = iter->next) {
+ GList *link = iter->data;
+ attachment_list = g_list_delete_link (attachment_list, link);
+ }
+ g_list_free (trash);
+
+ uri_context->attachment_list = attachment_list;
+
+ /* Any remaining attachments in the list should have MIME parts
+ * only, so we need to save them all to a temporary directory.
+ * We use a directory so the files can retain their basenames. */
+ template = g_strdup_printf (PACKAGE "-%s-XXXXXX", g_get_user_name ());
+ path = e_mkdtemp (template);
+ g_free (template);
+
+ if (path == NULL) {
GSimpleAsyncResult *simple;
- simple = g_simple_async_result_new (
- G_OBJECT (store), callback, user_data,
- e_attachment_store_save_list_async);
- g_simple_async_result_set_op_res_gboolean (simple, TRUE);
+ /* Steal the result. */
+ simple = uri_context->simple;
+ uri_context->simple = NULL;
+
+ g_simple_async_result_set_error (
+ simple, G_FILE_ERROR,
+ g_file_error_from_errno (errno),
+ "%s", g_strerror (errno));
+
g_simple_async_result_complete_in_idle (simple);
+ attachment_store_uri_context_free (uri_context);
return;
}
- save_context = attachment_store_save_context_new (
- store, attachment_list, callback, user_data);
+ temp_directory = g_file_new_for_path (path);
- while (attachment_list != NULL) {
+ for (iter = attachment_list; iter != NULL; iter = iter->next)
e_attachment_save_async (
- E_ATTACHMENT (attachment_list->data),
- destination, (GAsyncReadyCallback)
- attachment_store_save_list_finished_cb,
- save_context);
- attachment_list = g_list_next (attachment_list);
- }
+ E_ATTACHMENT (iter->data),
+ temp_directory, (GAsyncReadyCallback)
+ attachment_store_get_uris_save_cb,
+ uri_context);
+
+ g_object_unref (temp_directory);
}
-gboolean
-e_attachment_store_save_list_finish (EAttachmentStore *store,
- GAsyncResult *result,
- GError **error)
+gchar **
+e_attachment_store_get_uris_finish (EAttachmentStore *store,
+ GAsyncResult *result,
+ GError **error)
{
GSimpleAsyncResult *simple;
- gboolean success;
+ gchar **uris;
g_return_val_if_fail (
g_simple_async_result_is_valid (result, G_OBJECT (store),
- e_attachment_store_save_list_async), FALSE);
+ e_attachment_store_get_uris_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
- success = g_simple_async_result_get_op_res_gboolean (simple);
+ uris = g_simple_async_result_get_op_res_gpointer (simple);
g_simple_async_result_propagate_error (simple, error);
g_object_unref (simple);
- return success;
+ return uris;
}
diff --git a/widgets/misc/e-attachment-store.h b/widgets/misc/e-attachment-store.h
index c672cb3c34..a6dd702b97 100644
--- a/widgets/misc/e-attachment-store.h
+++ b/widgets/misc/e-attachment-store.h
@@ -107,13 +107,12 @@ GFile * e_attachment_store_run_save_dialog
GtkWindow *parent);
/* Asynchronous Operations */
-void e_attachment_store_save_list_async
+void e_attachment_store_get_uris_async
(EAttachmentStore *store,
GList *attachment_list,
- GFile *destination,
GAsyncReadyCallback callback,
gpointer user_data);
-gboolean e_attachment_store_save_list_finish
+gchar ** e_attachment_store_get_uris_finish
(EAttachmentStore *store,
GAsyncResult *result,
GError **error);
diff --git a/widgets/misc/e-attachment-view.c b/widgets/misc/e-attachment-view.c
index b2dc62b934..d6dff653cc 100644
--- a/widgets/misc/e-attachment-view.c
+++ b/widgets/misc/e-attachment-view.c
@@ -36,38 +36,11 @@ enum {
LAST_SIGNAL
};
-enum {
- DND_TYPE_MESSAGE_RFC822,
- DND_TYPE_X_UID_LIST,
- DND_TYPE_TEXT_URI_LIST,
- DND_TYPE_NETSCAPE_URL,
- DND_TYPE_TEXT_VCARD,
- DND_TYPE_TEXT_CALENDAR
-};
-
-static GtkTargetEntry drop_types[] = {
- { "message/rfc822", 0, DND_TYPE_MESSAGE_RFC822 },
- { "x-uid-list", 0, DND_TYPE_X_UID_LIST },
- { "text/uri-list", 0, DND_TYPE_TEXT_URI_LIST },
- { "_NETSCAPE_URL", 0, DND_TYPE_NETSCAPE_URL },
- { "text/x-vcard", 0, DND_TYPE_TEXT_VCARD },
- { "text/calendar", 0, DND_TYPE_TEXT_CALENDAR }
-};
-
-/* The atoms need initialized at runtime. */
-static struct {
- const gchar *target;
- GdkAtom atom;
- GdkDragAction actions;
-} drag_info[] = {
- { "message/rfc822", NULL, GDK_ACTION_COPY },
- { "x-uid-list", NULL, GDK_ACTION_COPY |
- GDK_ACTION_MOVE |
- GDK_ACTION_ASK },
- { "text/uri-list", NULL, GDK_ACTION_COPY },
- { "_NETSCAPE_URL", NULL, GDK_ACTION_COPY },
- { "text/x-vcard", NULL, GDK_ACTION_COPY },
- { "text/calendar", NULL, GDK_ACTION_COPY }
+/* Note: Do not use the info field. */
+static GtkTargetEntry target_table[] = {
+ { "_NETSCAPE_URL", 0, 0 },
+ { "text/x-vcard", 0, 0 },
+ { "text/calendar", 0, 0 }
};
static const gchar *ui =
@@ -84,12 +57,6 @@ static const gchar *ui =
" <separator/>"
" <placeholder name='open-actions'/>"
" </popup>"
-" <popup name='dnd'>"
-" <menuitem action='drag-copy'/>"
-" <menuitem action='drag-move'/>"
-" <separator/>"
-" <menuitem action='drag-cancel'/>"
-" </popup>"
"</ui>";
static gulong signals[LAST_SIGNAL];
@@ -126,30 +93,6 @@ action_cancel_cb (GtkAction *action,
}
static void
-action_drag_cancel_cb (GtkAction *action,
- EAttachmentView *view)
-{
- EAttachmentViewPrivate *priv;
-
- priv = e_attachment_view_get_private (view);
- gtk_drag_finish (priv->drag_context, FALSE, FALSE, priv->time);
-}
-
-static void
-action_drag_copy_cb (GtkAction *action,
- EAttachmentView *view)
-{
- e_attachment_view_drag_action (view, GDK_ACTION_COPY);
-}
-
-static void
-action_drag_move_cb (GtkAction *action,
- EAttachmentView *view)
-{
- e_attachment_view_drag_action (view, GDK_ACTION_MOVE);
-}
-
-static void
action_open_in_cb (GtkAction *action,
EAttachmentView *view)
{
@@ -312,27 +255,6 @@ static GtkActionEntry standard_entries[] = {
NULL, /* XXX Add a tooltip! */
G_CALLBACK (action_cancel_cb) },
- { "drag-cancel",
- NULL,
- N_("Cancel _Drag"),
- NULL,
- NULL, /* XXX Add a tooltip! */
- G_CALLBACK (action_drag_cancel_cb) },
-
- { "drag-copy",
- NULL,
- N_("_Copy"),
- NULL,
- NULL, /* XXX Add a tooltip! */
- G_CALLBACK (action_drag_copy_cb) },
-
- { "drag-move",
- NULL,
- N_("_Move"),
- NULL,
- NULL, /* XXX Add a tooltip! */
- G_CALLBACK (action_drag_move_cb) },
-
{ "save-all",
GTK_STOCK_SAVE_AS,
N_("S_ave All"),
@@ -382,159 +304,153 @@ static GtkActionEntry editable_entries[] = {
};
static void
-drop_message_rfc822 (EAttachmentView *view,
- GtkSelectionData *selection_data,
- EAttachmentStore *store,
- GdkDragAction action)
+attachment_view_netscape_url (EAttachmentView *view,
+ GdkDragContext *drag_context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time)
{
- EAttachmentViewPrivate *priv;
+ static GdkAtom atom = GDK_NONE;
+ EAttachmentStore *store;
EAttachment *attachment;
- CamelMimeMessage *message;
- CamelDataWrapper *wrapper;
- CamelStream *stream;
const gchar *data;
- gboolean success = FALSE;
- gboolean delete = FALSE;
gpointer parent;
+ gchar *copied_data;
+ gchar **strv;
gint length;
- priv = e_attachment_view_get_private (view);
+ if (G_UNLIKELY (atom == GDK_NONE))
+ atom = gdk_atom_intern_static_string ("_NETSCAPE_URL");
+
+ if (gtk_selection_data_get_target (selection_data) != atom)
+ return;
+
+ g_signal_stop_emission_by_name (view, "drag-data-received");
+
+ /* _NETSCAPE_URL is represented as "URI\nTITLE" */
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);
+ copied_data = g_strndup (data, length);
+ strv = g_strsplit (copied_data, "\n", 2);
+ g_free (copied_data);
- 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);
+ attachment = e_attachment_new_for_uri (strv[0]);
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;
- delete = (action == GDK_ACTION_MOVE);
-
-exit:
- camel_object_unref (message);
- camel_object_unref (stream);
+ g_strfreev (strv);
- gtk_drag_finish (priv->drag_context, success, delete, priv->time);
+ gtk_drag_finish (drag_context, TRUE, FALSE, time);
}
static void
-drop_netscape_url (EAttachmentView *view,
- GtkSelectionData *selection_data,
- EAttachmentStore *store,
- GdkDragAction action)
+attachment_view_text_calendar (EAttachmentView *view,
+ GdkDragContext *drag_context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time)
{
- EAttachmentViewPrivate *priv;
+ static GdkAtom atom = GDK_NONE;
+ EAttachmentStore *store;
EAttachment *attachment;
+ CamelMimePart *mime_part;
+ GdkAtom data_type;
const gchar *data;
gpointer parent;
- gchar *copied_data;
- gchar **strv;
+ gchar *content_type;
gint length;
- /* _NETSCAPE_URL is represented as "URI\nTITLE" */
+ if (G_UNLIKELY (atom = GDK_NONE))
+ atom = gdk_atom_intern_static_string ("text/calendar");
- priv = e_attachment_view_get_private (view);
+ 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);
+ data_type = gtk_selection_data_get_data_type (selection_data);
- copied_data = g_strndup (data, length);
- strv = g_strsplit (copied_data, "\n", 2);
- g_free (copied_data);
+ mime_part = camel_mime_part_new ();
+
+ content_type = gdk_atom_name (data_type);
+ camel_mime_part_set_content (mime_part, data, length, content_type);
+ camel_mime_part_set_disposition (mime_part, "inline");
+ g_free (content_type);
+
+ 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_uri (strv[0]);
+ attachment = e_attachment_new ();
+ e_attachment_set_mime_part (attachment, mime_part);
e_attachment_store_add_attachment (store, attachment);
e_attachment_load_async (
attachment, (GAsyncReadyCallback)
e_attachment_load_handle_error, parent);
g_object_unref (attachment);
- g_strfreev (strv);
-
- gtk_drag_finish (priv->drag_context, TRUE, FALSE, priv->time);
-}
-
-static void
-drop_text_uri_list (EAttachmentView *view,
- GtkSelectionData *selection_data,
- EAttachmentStore *store,
- GdkDragAction action)
-{
- EAttachmentViewPrivate *priv;
- gpointer parent;
- gchar **uris;
- gint ii;
-
- priv = e_attachment_view_get_private (view);
-
- uris = gtk_selection_data_get_uris (selection_data);
-
- parent = gtk_widget_get_toplevel (GTK_WIDGET (view));
- parent = GTK_WIDGET_TOPLEVEL (parent) ? parent : NULL;
-
- for (ii = 0; uris[ii] != NULL; ii++) {
- EAttachment *attachment;
-
- attachment = e_attachment_new_for_uri (uris[ii]);
- e_attachment_store_add_attachment (store, attachment);
- e_attachment_load_async (
- attachment, (GAsyncReadyCallback)
- e_attachment_load_handle_error, parent);
- g_object_unref (attachment);
- }
-
- g_strfreev (uris);
+ camel_object_unref (mime_part);
- gtk_drag_finish (priv->drag_context, TRUE, FALSE, priv->time);
+ gtk_drag_finish (drag_context, TRUE, FALSE, time);
}
static void
-drop_text_generic (EAttachmentView *view,
- GtkSelectionData *selection_data,
- EAttachmentStore *store,
- GdkDragAction action)
+attachment_view_text_x_vcard (EAttachmentView *view,
+ GdkDragContext *drag_context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time)
{
- EAttachmentViewPrivate *priv;
+ static GdkAtom atom = GDK_NONE;
+ EAttachmentStore *store;
EAttachment *attachment;
CamelMimePart *mime_part;
- GdkAtom atom;
+ GdkAtom data_type;
const gchar *data;
gpointer parent;
gchar *content_type;
gint length;
- priv = e_attachment_view_get_private (view);
+ if (G_UNLIKELY (atom = GDK_NONE))
+ atom = gdk_atom_intern_static_string ("text/x-vcard");
+
+ 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);
- atom = gtk_selection_data_get_data_type (selection_data);
+ data_type = gtk_selection_data_get_data_type (selection_data);
mime_part = camel_mime_part_new ();
- content_type = gdk_atom_name (atom);
+ content_type = gdk_atom_name (data_type);
camel_mime_part_set_content (mime_part, data, length, content_type);
camel_mime_part_set_disposition (mime_part, "inline");
g_free (content_type);
+ store = e_attachment_view_get_store (view);
+
parent = gtk_widget_get_toplevel (GTK_WIDGET (view));
parent = GTK_WIDGET_TOPLEVEL (parent) ? parent : NULL;
@@ -548,22 +464,49 @@ drop_text_generic (EAttachmentView *view,
camel_object_unref (mime_part);
- gtk_drag_finish (priv->drag_context, TRUE, FALSE, priv->time);
+ gtk_drag_finish (drag_context, TRUE, FALSE, time);
}
static void
-drop_x_uid_list (EAttachmentView *view,
- GtkSelectionData *selection_data,
- EAttachmentStore *store,
- GdkDragAction action)
+attachment_view_uris (EAttachmentView *view,
+ GdkDragContext *drag_context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time)
{
- EAttachmentViewPrivate *priv;
+ EAttachmentStore *store;
+ gpointer parent;
+ gchar **uris;
+ gint ii;
- /* FIXME Ugh, this looks painful. Requires mailer stuff. */
+ uris = gtk_selection_data_get_uris (selection_data);
- priv = e_attachment_view_get_private (view);
+ if (uris == NULL)
+ return;
+
+ g_signal_stop_emission_by_name (view, "drag-data-received");
+
+ store = e_attachment_view_get_store (view);
+
+ parent = gtk_widget_get_toplevel (GTK_WIDGET (view));
+ parent = GTK_WIDGET_TOPLEVEL (parent) ? parent : NULL;
+
+ for (ii = 0; uris[ii] != NULL; ii++) {
+ EAttachment *attachment;
+
+ attachment = e_attachment_new_for_uri (uris[ii]);
+ e_attachment_store_add_attachment (store, attachment);
+ e_attachment_load_async (
+ attachment, (GAsyncReadyCallback)
+ e_attachment_load_handle_error, parent);
+ g_object_unref (attachment);
+ }
- gtk_drag_finish (priv->drag_context, FALSE, FALSE, priv->time);
+ g_strfreev (uris);
+
+ gtk_drag_finish (drag_context, TRUE, FALSE, time);
}
static void
@@ -669,10 +612,48 @@ attachment_view_update_actions (EAttachmentView *view)
}
static void
-attachment_view_class_init (EAttachmentViewIface *iface)
+attachment_view_init_handlers (EAttachmentView *view)
{
- gint ii;
+ EAttachmentViewPrivate *priv;
+ GtkTargetList *target_list;
+ GType *children;
+ guint ii;
+
+ priv = e_attachment_view_get_private (view);
+
+ target_list = gtk_target_list_new (
+ target_table, G_N_ELEMENTS (target_table));
+
+ gtk_target_list_add_uri_targets (target_list, 0);
+
+ priv->handlers = g_ptr_array_new ();
+ priv->target_list = target_list;
+ priv->drag_actions = GDK_ACTION_COPY;
+
+ children = g_type_children (E_TYPE_ATTACHMENT_HANDLER, NULL);
+
+ for (ii = 0; children[ii] != G_TYPE_INVALID; ii++) {
+ EAttachmentHandler *handler;
+ const GtkTargetEntry *targets;
+ guint n_targets;
+
+ handler = g_object_new (children[ii], "view", view, NULL);
+ targets = e_attachment_handler_get_target_table (
+ handler, &n_targets);
+ gtk_target_list_add_table (target_list, targets, n_targets);
+ priv->drag_actions |=
+ e_attachment_handler_get_drag_actions (handler);
+
+ g_ptr_array_add (priv->handlers, handler);
+ }
+
+ g_free (children);
+}
+
+static void
+attachment_view_class_init (EAttachmentViewIface *iface)
+{
iface->update_actions = attachment_view_update_actions;
g_object_interface_install_property (
@@ -693,11 +674,6 @@ attachment_view_class_init (EAttachmentViewIface *iface)
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
-
- for (ii = 0; ii < G_N_ELEMENTS (drag_info); ii++) {
- const gchar *target = drag_info[ii].target;
- drag_info[ii].atom = gdk_atom_intern (target, FALSE);
- }
}
GType
@@ -738,15 +714,10 @@ e_attachment_view_init (EAttachmentView *view)
GtkUIManager *ui_manager;
GtkActionGroup *action_group;
const gchar *domain = GETTEXT_PACKAGE;
- GType *children;
- guint ii;
GError *error = NULL;
priv = e_attachment_view_get_private (view);
- e_attachment_view_drag_source_set (view);
- e_attachment_view_drag_dest_set (view);
-
ui_manager = gtk_ui_manager_new ();
priv->merge_id = gtk_ui_manager_new_merge_id (ui_manager);
priv->ui_manager = ui_manager;
@@ -783,14 +754,28 @@ e_attachment_view_init (EAttachmentView *view)
G_OBJECT (view), "editable",
G_OBJECT (priv->editable_actions), "visible");
- /* Instantiate attachment handlers. */
- children = g_type_children (E_TYPE_ATTACHMENT_HANDLER, NULL);
- for (ii = 0; children[ii] != G_TYPE_INVALID; ii++) {
- EAttachmentHandler *handler;
- handler = g_object_new (children[ii], "view", view, NULL);
- priv->handlers = g_list_prepend (priv->handlers, handler);
- }
- g_free (children);
+ attachment_view_init_handlers (view);
+
+ e_attachment_view_drag_source_set (view);
+ e_attachment_view_drag_dest_set (view);
+
+ /* Connect built-in drag and drop handlers. */
+
+ g_signal_connect (
+ view, "drag-data-received",
+ G_CALLBACK (attachment_view_netscape_url), NULL);
+
+ g_signal_connect (
+ view, "drag-data-received",
+ G_CALLBACK (attachment_view_text_calendar), NULL);
+
+ g_signal_connect (
+ view, "drag-data-received",
+ G_CALLBACK (attachment_view_text_x_vcard), NULL);
+
+ g_signal_connect (
+ view, "drag-data-received",
+ G_CALLBACK (attachment_view_uris), NULL);
}
void
@@ -800,9 +785,13 @@ e_attachment_view_dispose (EAttachmentView *view)
priv = e_attachment_view_get_private (view);
- g_list_foreach (priv->handlers, (GFunc) g_object_unref, NULL);
- g_list_free (priv->handlers);
- priv->handlers = NULL;
+ g_ptr_array_foreach (priv->handlers, (GFunc) g_object_unref, NULL);
+ g_ptr_array_set_size (priv->handlers, 0);
+
+ if (priv->target_list != NULL) {
+ gtk_target_list_unref (priv->target_list);
+ priv->target_list = NULL;
+ }
if (priv->ui_manager != NULL) {
g_object_unref (priv->ui_manager);
@@ -823,11 +812,6 @@ e_attachment_view_dispose (EAttachmentView *view)
g_object_unref (priv->openwith_actions);
priv->openwith_actions = NULL;
}
-
- if (priv->drag_context != NULL) {
- g_object_unref (priv->drag_context);
- priv->drag_context = NULL;
- }
}
void
@@ -837,8 +821,7 @@ e_attachment_view_finalize (EAttachmentView *view)
priv = e_attachment_view_get_private (view);
- if (priv->selection_data != NULL)
- gtk_selection_data_free (priv->selection_data);
+ g_ptr_array_free (priv->handlers, TRUE);
}
EAttachmentViewPrivate *
@@ -893,6 +876,30 @@ e_attachment_view_set_editable (EAttachmentView *view,
g_object_notify (G_OBJECT (view), "editable");
}
+GtkTargetList *
+e_attachment_view_get_target_list (EAttachmentView *view)
+{
+ EAttachmentViewPrivate *priv;
+
+ g_return_val_if_fail (E_IS_ATTACHMENT_VIEW (view), NULL);
+
+ priv = e_attachment_view_get_private (view);
+
+ return priv->target_list;
+}
+
+GdkDragAction
+e_attachment_view_get_drag_actions (EAttachmentView *view)
+{
+ EAttachmentViewPrivate *priv;
+
+ g_return_val_if_fail (E_IS_ATTACHMENT_VIEW (view), 0);
+
+ priv = e_attachment_view_get_private (view);
+
+ return priv->drag_actions;
+}
+
GList *
e_attachment_view_get_selected_attachments (EAttachmentView *view)
{
@@ -1257,6 +1264,24 @@ e_attachment_view_drag_end (EAttachmentView *view,
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
}
+static void
+attachment_view_got_uris_cb (EAttachmentStore *store,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ struct {
+ gchar **uris;
+ gboolean done;
+ } *status = user_data;
+
+ /* XXX Since this is a best-effort function,
+ * should we care about errors? */
+ status->uris = e_attachment_store_get_uris_finish (
+ store, result, NULL);
+
+ status->done = TRUE;
+}
+
void
e_attachment_view_drag_data_get (EAttachmentView *view,
GdkDragContext *context,
@@ -1264,56 +1289,65 @@ e_attachment_view_drag_data_get (EAttachmentView *view,
guint info,
guint time)
{
- GList *selected, *iter;
- gchar **uris;
- gint ii = 0;
+ EAttachmentStore *store;
+ GList *selected;
+
+ struct {
+ gchar **uris;
+ gboolean done;
+ } status;
g_return_if_fail (E_IS_ATTACHMENT_VIEW (view));
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
g_return_if_fail (selection != NULL);
+ status.uris = NULL;
+ status.done = FALSE;
+
+ store = e_attachment_view_get_store (view);
+
selected = e_attachment_view_get_selected_attachments (view);
if (selected == NULL)
return;
- uris = g_malloc0 (sizeof (gchar *) * (g_list_length (selected) + 1));
+ e_attachment_store_get_uris_async (
+ store, selected, (GAsyncReadyCallback)
+ attachment_view_got_uris_cb, &status);
- for (iter = selected; iter != NULL; iter = iter->next) {
- EAttachment *attachment = iter->data;
- GFile *file;
-
- /* FIXME Need to handle attachments with no GFile. */
- file = e_attachment_get_file (attachment);
- if (file == NULL)
- continue;
+ g_list_foreach (selected, (GFunc) g_object_unref, NULL);
+ g_list_free (selected);
- uris[ii++] = g_file_get_uri (file);
- }
+ /* We can't return until we have results, so crank
+ * the main loop until the callback gets triggered. */
+ while (!status.done)
+ if (gtk_main_iteration ())
+ break;
- gtk_selection_data_set_uris (selection, uris);
+ if (status.uris != NULL)
+ gtk_selection_data_set_uris (selection, status.uris);
- g_strfreev (uris);
+ g_strfreev (status.uris);
}
void
e_attachment_view_drag_dest_set (EAttachmentView *view)
{
+ EAttachmentViewPrivate *priv;
GtkTargetEntry *targets;
- GtkTargetList *list;
gint n_targets;
g_return_if_fail (E_IS_ATTACHMENT_VIEW (view));
- list = gtk_target_list_new (NULL, 0);
- /* FIXME Add targets here... */
- targets = gtk_target_table_new_from_list (list, &n_targets);
+ priv = e_attachment_view_get_private (view);
+
+ targets = gtk_target_table_new_from_list (
+ priv->target_list, &n_targets);
gtk_drag_dest_set (
GTK_WIDGET (view), GTK_DEST_DEFAULT_ALL,
- targets, n_targets, GDK_ACTION_COPY);
+ targets, n_targets, priv->drag_actions);
gtk_target_table_free (targets, n_targets);
- gtk_target_list_unref (list);
}
void
@@ -1324,61 +1358,6 @@ e_attachment_view_drag_dest_unset (EAttachmentView *view)
gtk_drag_dest_unset (GTK_WIDGET (view));
}
-void
-e_attachment_view_drag_action (EAttachmentView *view,
- GdkDragAction action)
-{
- EAttachmentViewPrivate *priv;
- GtkSelectionData *selection_data;
- EAttachmentStore *store;
- GdkAtom atom;
- gchar *name;
-
- g_return_if_fail (E_IS_ATTACHMENT_VIEW (view));
-
- priv = e_attachment_view_get_private (view);
-
- selection_data = priv->selection_data;
- store = e_attachment_view_get_store (view);
- atom = gtk_selection_data_get_data_type (selection_data);
-
- switch (priv->info) {
- case DND_TYPE_MESSAGE_RFC822:
- drop_message_rfc822 (
- view, selection_data, store, action);
- return;
-
- case DND_TYPE_NETSCAPE_URL:
- drop_netscape_url (
- view, selection_data, store, action);
- return;
-
- case DND_TYPE_TEXT_URI_LIST:
- drop_text_uri_list (
- view, selection_data, store, action);
- return;
-
- case DND_TYPE_TEXT_VCARD:
- case DND_TYPE_TEXT_CALENDAR:
- drop_text_generic (
- view, selection_data, store, action);
- return;
-
- case DND_TYPE_X_UID_LIST:
- drop_x_uid_list (
- view, selection_data, store, action);
- return;
-
- default:
- name = gdk_atom_name (atom);
- g_warning ("Unknown drag type: %s", name);
- g_free (name);
- break;
- }
-
- gtk_drag_finish (priv->drag_context, FALSE, FALSE, priv->time);
-}
-
gboolean
e_attachment_view_drag_motion (EAttachmentView *view,
GdkDragContext *context,
@@ -1386,27 +1365,20 @@ e_attachment_view_drag_motion (EAttachmentView *view,
gint y,
guint time)
{
- GList *iter;
- GdkDragAction actions = 0;
+ EAttachmentViewPrivate *priv;
+ GdkDragAction actions;
GdkDragAction chosen_action;
g_return_val_if_fail (E_IS_ATTACHMENT_VIEW (view), FALSE);
g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), FALSE);
+ priv = e_attachment_view_get_private (view);
+
/* Disallow drops if we're not editable. */
if (!e_attachment_view_get_editable (view))
return FALSE;
- for (iter = context->targets; iter != NULL; iter = iter->next) {
- GdkAtom atom = iter->data;
- gint ii;
-
- for (ii = 0; ii < G_N_ELEMENTS (drag_info); ii++)
- if (atom == drag_info[ii].atom)
- actions |= drag_info[ii].actions;
- }
-
- actions &= context->actions;
+ actions = priv->drag_actions & context->actions;
chosen_action = context->suggested_action;
if (chosen_action == GDK_ACTION_ASK) {
@@ -1441,53 +1413,31 @@ e_attachment_view_drag_drop (EAttachmentView *view,
void
e_attachment_view_drag_data_received (EAttachmentView *view,
- GdkDragContext *context,
+ GdkDragContext *drag_context,
gint x,
gint y,
- GtkSelectionData *selection,
+ GtkSelectionData *selection_data,
guint info,
guint time)
{
- EAttachmentViewPrivate *priv;
- GtkUIManager *ui_manager;
- GdkDragAction action;
+ GdkAtom atom;
+ gchar *name;
g_return_if_fail (E_IS_ATTACHMENT_VIEW (view));
- g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
- g_return_if_fail (selection != NULL);
-
- priv = e_attachment_view_get_private (view);
- ui_manager = e_attachment_view_get_ui_manager (view);
+ g_return_if_fail (GDK_IS_DRAG_CONTEXT (drag_context));
- action = context->action;
+ /* Drop handlers are supposed to stop further emission of the
+ * "drag-data-received" signal if they can handle the data. If
+ * we get this far it means none of the handlers were successful,
+ * so report the drop as failed. */
- if (gtk_selection_data_get_data (selection) == NULL)
- return;
-
- if (gtk_selection_data_get_length (selection) == -1)
- return;
-
- if (priv->drag_context != NULL)
- g_object_unref (priv->drag_context);
-
- if (priv->selection_data != NULL)
- gtk_selection_data_free (priv->selection_data);
+ atom = gtk_selection_data_get_target (selection_data);
- priv->drag_context = g_object_ref (context);
- priv->selection_data = gtk_selection_data_copy (selection);
- priv->info = info;
- priv->time = time;
+ name = gdk_atom_name (atom);
+ g_warning ("Unknown selection target: %s", name);
+ g_free (name);
- if (action == GDK_ACTION_ASK) {
- GtkWidget *menu;
-
- menu = gtk_ui_manager_get_widget (ui_manager, "/dnd");
- g_return_if_fail (GTK_IS_MENU (menu));
-
- gtk_menu_popup (
- GTK_MENU (menu), NULL, NULL, NULL, NULL, 0, time);
- } else
- e_attachment_view_drag_action (view, action);
+ gtk_drag_finish (drag_context, FALSE, FALSE, time);
}
GtkAction *
diff --git a/widgets/misc/e-attachment-view.h b/widgets/misc/e-attachment-view.h
index 16a7ac1967..8b625d0d8a 100644
--- a/widgets/misc/e-attachment-view.h
+++ b/widgets/misc/e-attachment-view.h
@@ -93,7 +93,11 @@ struct _EAttachmentViewIface {
struct _EAttachmentViewPrivate {
/* Attachment Handlers */
- GList *handlers;
+ GPtrArray *handlers;
+
+ /* Drag Destination */
+ GtkTargetList *target_list;
+ GdkDragAction drag_actions;
/* Popup Menu Management */
GtkUIManager *ui_manager;
@@ -102,12 +106,6 @@ struct _EAttachmentViewPrivate {
GtkActionGroup *openwith_actions;
guint merge_id;
- /* Drag and Drop State */
- GdkDragContext *drag_context;
- GtkSelectionData *selection_data;
- guint info;
- guint time;
-
guint editable : 1;
};
@@ -124,6 +122,10 @@ EAttachmentStore *
gboolean e_attachment_view_get_editable (EAttachmentView *view);
void e_attachment_view_set_editable (EAttachmentView *view,
gboolean editable);
+GtkTargetList * e_attachment_view_get_target_list
+ (EAttachmentView *view);
+GdkDragAction e_attachment_view_get_drag_actions
+ (EAttachmentView *view);
GList * e_attachment_view_get_selected_attachments
(EAttachmentView *view);
void e_attachment_view_open_path (EAttachmentView *view,
@@ -182,8 +184,6 @@ void e_attachment_view_drag_data_get (EAttachmentView *view,
void e_attachment_view_drag_dest_set (EAttachmentView *view);
void e_attachment_view_drag_dest_unset
(EAttachmentView *view);
-void e_attachment_view_drag_action (EAttachmentView *view,
- GdkDragAction action);
gboolean e_attachment_view_drag_motion (EAttachmentView *view,
GdkDragContext *context,
gint x,
diff --git a/widgets/misc/e-attachment.c b/widgets/misc/e-attachment.c
index fb84261fa2..bd9795c908 100644
--- a/widgets/misc/e-attachment.c
+++ b/widgets/misc/e-attachment.c
@@ -22,6 +22,7 @@
#include "e-attachment.h"
#include <errno.h>
+#include <config.h>
#include <glib/gi18n.h>
#include <camel/camel-iconv.h>
#include <camel/camel-data-wrapper.h>
@@ -32,6 +33,7 @@
#include <camel/camel-stream-vfs.h>
#include "e-util/e-util.h"
+#include "e-util/e-mktemp.h"
#include "e-attachment-store.h"
#define E_ATTACHMENT_GET_PRIVATE(obj) \
@@ -1914,18 +1916,30 @@ static void
attachment_open_save_temporary (OpenContext *open_context)
{
GFile *file;
+ gchar *template;
gchar *path;
- gint fd;
GError *error = NULL;
- fd = e_file_open_tmp (&path, &error);
+ errno = 0;
+ /* XXX This could trigger a blocking temp directory cleanup. */
+ template = g_strdup_printf (PACKAGE "-%s-XXXXXX", g_get_user_name ());
+ path = e_mktemp (template);
+ g_free (template);
+
+ /* XXX Let's hope errno got set properly. */
+ if (path == NULL)
+ g_set_error (
+ &error, G_FILE_ERROR,
+ g_file_error_from_errno (errno),
+ "%s", g_strerror (errno));
+
+ /* We already know if there's an error, but this does the cleanup. */
if (attachment_open_check_for_error (open_context, error))
return;
file = g_file_new_for_path (path);
- close (fd);
g_free (path);
e_attachment_save_async (
@@ -2519,8 +2533,11 @@ e_attachment_save_handle_error (EAttachment *attachment,
g_return_if_fail (GTK_IS_WINDOW (parent));
file = e_attachment_save_finish (attachment, result, &error);
- if (file != NULL)
+
+ if (file != NULL) {
g_object_unref (file);
+ return;
+ }
/* Ignore cancellations. */
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
diff --git a/widgets/misc/e-mime-part-utils.c b/widgets/misc/e-mime-part-utils.c
deleted file mode 100644
index 3238ca93f5..0000000000
--- a/widgets/misc/e-mime-part-utils.c
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * e-mime-part-utils.c
- *
- * 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)
- *
- */
-
-#include "e-mime-part-utils.h"
-
-#include <errno.h>
-#include <gio/gio.h>
-#include <glib/gi18n.h>
-#include <camel/camel-stream-vfs.h>
-
-#include "e-util/e-util.h"
-
-static void
-mime_part_utils_open_in_cb (GtkAction *action,
- CamelMimePart *mime_part)
-{
- GtkWindow *parent;
- GFile *file;
- gchar *path;
- gchar *uri;
- gint fd;
- GError *error = NULL;
-
- parent = g_object_get_data (G_OBJECT (action), "parent-window");
-
- fd = e_file_open_tmp (&path, &error);
- if (error != NULL)
- goto fail;
-
- close (fd);
-
- file = g_file_new_for_path (path);
- e_mime_part_utils_save_to_file (mime_part, file, &error);
- g_free (path);
-
- if (error != NULL) {
- g_object_unref (file);
- goto fail;
- }
-
- uri = g_file_get_uri (file);
- e_show_uri (parent, uri);
- g_free (uri);
-
- g_object_unref (file);
-
- return;
-
-fail:
- g_warning ("%s", error->message);
- g_error_free (error);
-}
-
-GList *
-e_mime_part_utils_get_apps (CamelMimePart *mime_part)
-{
- GList *app_info_list;
- const gchar *filename;
- gchar *content_type;
- gchar *mime_type;
- gchar *cp;
-
- g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), NULL);
-
- filename = camel_mime_part_get_filename (mime_part);
- mime_type = camel_content_type_simple (
- camel_mime_part_get_content_type (mime_part));
- g_return_val_if_fail (mime_type != NULL, NULL);
-
- /* GIO expects lowercase MIME types. */
- for (cp = mime_type; *cp != '\0'; cp++)
- *cp = g_ascii_tolower (*cp);
-
- content_type = g_content_type_from_mime_type (mime_type);
- if (content_type != NULL)
- app_info_list = g_app_info_get_all_for_type (content_type);
- else
- app_info_list = g_app_info_get_all_for_type (mime_type);
- g_free (content_type);
-
- if (app_info_list != NULL || filename == NULL)
- goto exit;
-
- if (strcmp (mime_type, "application/octet-stream") != 0)
- goto exit;
-
- content_type = g_content_type_guess (filename, NULL, 0, NULL);
- app_info_list = g_app_info_get_all_for_type (content_type);
- g_free (content_type);
-
-exit:
- g_free (mime_type);
-
- return app_info_list;
-}
-
-gboolean
-e_mime_part_utils_save_to_file (CamelMimePart *mime_part,
- GFile *file,
- GError **error)
-{
- GFileOutputStream *output_stream;
- CamelDataWrapper *content;
- CamelStream *stream;
-
- g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), FALSE);
- g_return_val_if_fail (G_IS_FILE (file), FALSE);
-
- output_stream = g_file_replace (
- file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, error);
- if (output_stream == NULL)
- return FALSE;
-
- /* The CamelStream takes ownership of the GFileOutputStream. */
- content = camel_medium_get_content_object (CAMEL_MEDIUM (mime_part));
- stream = camel_stream_vfs_new_with_stream (G_OBJECT (output_stream));
-
- /* XXX Camel's streams are synchronous only, so we have to write
- * the whole thing in one shot and hope it doesn't block the
- * main loop for too long. */
- if (camel_data_wrapper_decode_to_stream (content, stream) < 0)
- goto file_error;
-
- if (camel_stream_flush (stream) < 0)
- goto file_error;
-
- camel_object_unref (stream);
-
- return TRUE;
-
-file_error:
- g_set_error (
- error, G_FILE_ERROR,
- g_file_error_from_errno (errno),
- "%s", g_strerror (errno));
-
- camel_object_unref (stream);
-
- return FALSE;
-}
-
-void
-e_mime_part_utils_add_open_actions (CamelMimePart *mime_part,
- GtkUIManager *ui_manager,
- GtkActionGroup *action_group,
- const gchar *widget_path,
- GtkWindow *parent,
- guint merge_id)
-{
- GList *app_info_list;
- GList *iter;
-
- g_return_if_fail (CAMEL_IS_MIME_PART (mime_part));
- g_return_if_fail (GTK_IS_UI_MANAGER (ui_manager));
- g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
- g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));
- g_return_if_fail (widget_path != NULL);
-
- app_info_list = e_mime_part_utils_get_apps (mime_part);
-
- for (iter = app_info_list; iter != NULL; iter = iter->next) {
- GAppInfo *app_info = iter->data;
- GtkAction *action;
- const gchar *app_executable;
- const gchar *app_name;
- gchar *action_tooltip;
- gchar *action_label;
- gchar *action_name;
-
- if (!g_app_info_should_show (app_info))
- continue;
-
- app_executable = g_app_info_get_executable (app_info);
- app_name = g_app_info_get_name (app_info);
-
- action_name = g_strdup_printf ("open-in-%s", app_executable);
- action_label = g_strdup_printf (_("Open in %s..."), app_name);
-
- action_tooltip = g_strdup_printf (
- _("Open this attachment in %s"), app_name);
-
- action = gtk_action_new (
- action_name, action_label, action_tooltip, NULL);
-
- g_object_set_data (
- G_OBJECT (action), "parent-window", parent);
-
- g_signal_connect (
- action, "activate",
- G_CALLBACK (mime_part_utils_open_in_cb), mime_part);
-
- gtk_action_group_add_action (action_group, action);
-
- gtk_ui_manager_add_ui (
- ui_manager, merge_id, widget_path, action_name,
- action_name, GTK_UI_MANAGER_AUTO, FALSE);
-
- g_free (action_name);
- g_free (action_label);
- g_free (action_tooltip);
- }
-
- g_list_foreach (app_info_list, (GFunc) g_object_unref, NULL);
- g_list_free (app_info_list);
-}
diff --git a/widgets/misc/e-mime-part-utils.h b/widgets/misc/e-mime-part-utils.h
deleted file mode 100644
index e923e07c8d..0000000000
--- a/widgets/misc/e-mime-part-utils.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * e-mime-part-utils.h
- *
- * 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 E_MIME_PART_UTILS_H
-#define E_MIME_PART_UTILS_H
-
-#include <gtk/gtk.h>
-#include <camel/camel-mime-part.h>
-#include <shell/e-shell-window.h>
-
-G_BEGIN_DECLS
-
-GList * e_mime_part_utils_get_apps (CamelMimePart *mime_part);
-gboolean e_mime_part_utils_save_to_file (CamelMimePart *mime_part,
- GFile *file,
- GError **error);
-
-void e_mime_part_utils_add_open_actions
- (CamelMimePart *mime_part,
- GtkUIManager *ui_manager,
- GtkActionGroup *action_group,
- const gchar *widget_path,
- GtkWindow *parent,
- guint merge_id);
-
-G_END_DECLS
-
-#endif /* E_MIME_PART_UTILS_H */