aboutsummaryrefslogtreecommitdiffstats
path: root/composer/e-msg-composer.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2009-04-28 03:36:19 +0800
committerMatthew Barnes <mbarnes@redhat.com>2009-04-28 03:36:19 +0800
commit4449a34101406bffe508dd40b8b653f7c7d14c7d (patch)
treee9fb2ce7efd3901cf1090040666f0ce15ad70554 /composer/e-msg-composer.c
parente377ea5e61171e57f9e892652d0fd1f77953eda8 (diff)
downloadgsoc2013-evolution-4449a34101406bffe508dd40b8b653f7c7d14c7d.tar.gz
gsoc2013-evolution-4449a34101406bffe508dd40b8b653f7c7d14c7d.tar.zst
gsoc2013-evolution-4449a34101406bffe508dd40b8b653f7c7d14c7d.zip
Commit the rest of the attachment UI rewrite
Oops, last commit only included the -new- files. This also removes EExpander, which is no longer used.
Diffstat (limited to 'composer/e-msg-composer.c')
-rw-r--r--composer/e-msg-composer.c697
1 files changed, 166 insertions, 531 deletions
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index d39a212e88..a2777294c6 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -60,7 +60,6 @@
#include "e-util/e-dialog-utils.h"
#include "misc/e-charset-picker.h"
-#include "misc/e-expander.h"
#include "e-util/e-error.h"
#include "e-util/e-plugin-ui.h"
#include "e-util/e-util-private.h"
@@ -98,7 +97,6 @@
#include "e-msg-composer.h"
#include "e-attachment.h"
-#include "e-attachment-bar.h"
#include "e-composer-autosave.h"
#include "e-composer-private.h"
#include "e-composer-header-table.h"
@@ -152,39 +150,6 @@ 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 }
-};
-
-static struct {
- gchar *target;
- GdkAtom atom;
- guint32 actions;
-} drag_info[] = {
- { "message/rfc822", NULL, GDK_ACTION_COPY },
- { "x-uid-list", NULL, GDK_ACTION_ASK |
- GDK_ACTION_MOVE |
- GDK_ACTION_COPY },
- { "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 }
-};
-
static gpointer parent_class;
static guint signals[LAST_SIGNAL];
@@ -195,7 +160,6 @@ static GSList *all_composers = NULL;
static GList *add_recipients (GList *list, const gchar *recips);
static void handle_mailto (EMsgComposer *composer, const gchar *mailto);
-static void handle_uri (EMsgComposer *composer, const gchar *uri, gboolean html_dnd);
/* used by e_msg_composer_add_message_attachments () */
static void add_attachments_from_multipart (EMsgComposer *composer, CamelMultipart *multipart,
@@ -527,7 +491,8 @@ build_message (EMsgComposer *composer,
GtkhtmlEditor *editor;
EMsgComposerPrivate *p = composer->priv;
- EAttachmentBar *attachment_bar;
+ EAttachmentView *view;
+ EAttachmentStore *store;
EComposerHeaderTable *table;
GtkToggleAction *action;
CamelDataWrapper *plain, *html, *current;
@@ -554,7 +519,8 @@ build_message (EMsgComposer *composer,
editor = GTKHTML_EDITOR (composer);
table = e_msg_composer_get_header_table (composer);
account = e_composer_header_table_get_account (table);
- attachment_bar = E_ATTACHMENT_BAR (p->attachment_bar);
+ view = e_msg_composer_get_attachment_view (composer);
+ store = e_attachment_view_get_store (view);
/* evil kludgy hack for Redirect */
if (p->redirect) {
@@ -714,7 +680,7 @@ build_message (EMsgComposer *composer,
} else
current = plain;
- if (e_attachment_bar_get_num_attachments (attachment_bar)) {
+ if (e_attachment_store_get_num_attachments (store) > 0) {
CamelMultipart *multipart = camel_multipart_new ();
if (p->is_alternative) {
@@ -733,7 +699,8 @@ build_message (EMsgComposer *composer,
camel_multipart_add_part (multipart, part);
camel_object_unref (part);
- e_attachment_bar_to_multipart (attachment_bar, multipart, p->charset);
+ e_attachment_store_add_to_multipart (
+ store, multipart, p->charset);
if (p->is_alternative) {
for (i = camel_multipart_get_number (multipart); i > 1; i--) {
@@ -976,107 +943,6 @@ skip_content:
return NULL;
}
-/* Attachment Bar */
-
-static void
-emcab_add (EPopup *ep, EPopupItem *item, gpointer data)
-{
- GtkWidget *widget = data;
- GtkWidget *composer;
-
- composer = gtk_widget_get_toplevel (widget);
- gtk_action_activate (ACTION (ATTACH));
-}
-
-static void
-emcab_properties (EPopup *ep, EPopupItem *item, gpointer data)
-{
- EAttachmentBar *attachment_bar = data;
-
- e_attachment_bar_edit_selected (attachment_bar);
-}
-
-static void
-emcab_remove (EPopup *ep, EPopupItem *item, gpointer data)
-{
- EAttachmentBar *attachment_bar = data;
-
- e_attachment_bar_remove_selected (attachment_bar);
-}
-
-static void
-emcab_popup_position (GtkMenu *menu, int *x, int *y, gboolean *push_in, gpointer user_data)
-{
- GtkWidget *widget = user_data;
- GnomeIconList *icon_list = user_data;
- GList *selection;
- GnomeCanvasPixbuf *image;
-
- gdk_window_get_origin (widget->window, x, y);
-
- selection = gnome_icon_list_get_selection (icon_list);
- if (selection == NULL)
- return;
-
- image = gnome_icon_list_get_icon_pixbuf_item (
- icon_list, GPOINTER_TO_INT(selection->data));
- if (image == NULL)
- return;
-
- /* Put menu to the center of icon. */
- *x += (int)(image->item.x1 + image->item.x2) / 2;
- *y += (int)(image->item.y1 + image->item.y2) / 2;
-}
-
-static void
-emcab_popups_free (EPopup *ep, GSList *list, gpointer data)
-{
- g_slist_free (list);
-}
-
-/* Popup menu handling. */
-static EPopupItem emcab_popups[] = {
- { E_POPUP_ITEM, "10.attach", N_("_Remove"), emcab_remove, NULL, GTK_STOCK_REMOVE, EM_POPUP_ATTACHMENTS_MANY },
- { E_POPUP_ITEM, "20.attach", N_("_Properties"), emcab_properties, NULL, GTK_STOCK_PROPERTIES, EM_POPUP_ATTACHMENTS_ONE },
- { E_POPUP_BAR, "30.attach.00", NULL, NULL, NULL, NULL, EM_POPUP_ATTACHMENTS_MANY|EM_POPUP_ATTACHMENTS_ONE },
- { E_POPUP_ITEM, "30.attach.01", N_("_Add attachment..."), emcab_add, NULL, GTK_STOCK_ADD, 0 },
-};
-
-/* if id != -1, then use it as an index for target of the popup */
-
-static void
-emcab_popup (EAttachmentBar *bar, GdkEventButton *event, int id)
-{
- GSList *attachments = NULL, *menus = NULL;
- int i;
- EMPopup *emp;
- EMPopupTargetAttachments *t;
- GtkMenu *menu;
-
- attachments = e_attachment_bar_get_attachment (bar, id);
-
- for (i=0;i<sizeof (emcab_popups)/sizeof (emcab_popups[0]);i++)
- menus = g_slist_prepend (menus, &emcab_popups[i]);
-
- /** @HookPoint-EMPopup: Composer Attachment Bar Context Menu
- * @Id: org.gnome.evolution.mail.composer.attachmentbar.popup
- * @Class: org.gnome.evolution.mail.popup:1.0
- * @Target: EMPopupTargetAttachments
- *
- * This is the context menu on the composer attachment bar.
- */
- emp = em_popup_new ("org.gnome.evolution.mail.composer.attachmentbar.popup");
- e_popup_add_items ((EPopup *)emp, menus, NULL, emcab_popups_free, bar);
- t = em_popup_target_new_attachments (emp, attachments);
- t->target.widget = (GtkWidget *)bar;
- menu = e_popup_create_menu_once ((EPopup *)emp, (EPopupTarget *)t, 0);
-
- if (event == NULL)
- gtk_menu_popup (menu, NULL, NULL, emcab_popup_position, bar, 0, gtk_get_current_event_time ());
- else
- gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event->button, event->time);
-}
-
/* Signatures */
static gchar *
@@ -1467,108 +1333,17 @@ autosave_load_draft (const gchar *filename)
/* Miscellaneous callbacks. */
-static gint
-attachment_bar_button_press_event_cb (EAttachmentBar *attachment_bar,
- GdkEventButton *event)
-{
- GnomeIconList *icon_list;
- gint icon_number;
-
- if (event->button != 3)
- return FALSE;
-
- icon_list = GNOME_ICON_LIST (attachment_bar);
- icon_number = gnome_icon_list_get_icon_at (
- icon_list, event->x, event->y);
- if (icon_number >= 0) {
- gnome_icon_list_unselect_all (icon_list);
- gnome_icon_list_select_icon (icon_list, icon_number);
- }
-
- emcab_popup (attachment_bar, event, icon_number);
-
- return TRUE;
-}
-
static void
-attachment_bar_changed_cb (EAttachmentBar *attachment_bar,
- EMsgComposer *composer)
+attachment_store_changed_cb (EMsgComposer *composer)
{
GtkhtmlEditor *editor;
- GtkWidget *widget;
- guint attachment_num;
-
- editor = GTKHTML_EDITOR (composer);
- attachment_num = e_attachment_bar_get_num_attachments (attachment_bar);
-
- if (attachment_num > 0) {
- gchar *markup;
-
- markup = g_strdup_printf (
- "<b>%d</b> %s", attachment_num, ngettext (
- "Attachment", "Attachments", attachment_num));
- widget = composer->priv->attachment_expander_num;
- gtk_label_set_markup (GTK_LABEL (widget), markup);
- g_free (markup);
-
- gtk_widget_show (composer->priv->attachment_expander_icon);
-
- widget = composer->priv->attachment_expander;
- gtk_expander_set_expanded (GTK_EXPANDER (widget), TRUE);
- } else {
- widget = composer->priv->attachment_expander_num;
- gtk_label_set_text (GTK_LABEL (widget), "");
-
- gtk_widget_hide (composer->priv->attachment_expander_icon);
-
- widget = composer->priv->attachment_expander;
- gtk_expander_set_expanded (GTK_EXPANDER (widget), FALSE);
- }
/* Mark the editor as changed so it prompts about unsaved
- changes on close. */
+ * changes on close. */
+ editor = GTKHTML_EDITOR (composer);
gtkhtml_editor_set_changed (editor, TRUE);
}
-static gint
-attachment_bar_key_press_event_cb (EAttachmentBar *attachment_bar,
- GdkEventKey *event)
-{
- if (event->keyval == GDK_Delete) {
- e_attachment_bar_remove_selected (attachment_bar);
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gboolean
-attachment_bar_popup_menu_cb (EAttachmentBar *attachment_bar)
-{
- emcab_popup (attachment_bar, NULL, -1);
-
- return TRUE;
-}
-
-static void
-attachment_expander_notify_cb (GtkExpander *expander,
- GParamSpec *pspec,
- EMsgComposer *composer)
-{
- GtkLabel *label;
- const gchar *text;
-
- label = GTK_LABEL (composer->priv->attachment_expander_label);
-
- /* Update the expander label */
- if (gtk_expander_get_expanded (expander))
- text = _("Hide _Attachment Bar");
- else
- text = _("Show _Attachment Bar");
-
- gtk_label_set_text_with_mnemonic (label, text);
-}
-
static void
msg_composer_subject_changed_cb (EMsgComposer *composer)
{
@@ -1765,35 +1540,6 @@ msg_composer_account_list_changed_cb (EMsgComposer *composer)
}
static void
-msg_composer_attach_message (EMsgComposer *composer,
- CamelMimeMessage *msg)
-{
- CamelMimePart *mime_part;
- GString *description;
- const gchar *subject;
- EMsgComposerPrivate *p = composer->priv;
-
- mime_part = camel_mime_part_new ();
- camel_mime_part_set_disposition (mime_part, "inline");
- subject = camel_mime_message_get_subject (msg);
-
- description = g_string_new (_("Attached message"));
- if (subject != NULL)
- g_string_append_printf (description, " - %s", subject);
- camel_mime_part_set_description (mime_part, description->str);
- g_string_free (description, TRUE);
-
- camel_medium_set_content_object (
- (CamelMedium *) mime_part, (CamelDataWrapper *) msg);
- camel_mime_part_set_content_type (mime_part, "message/rfc822");
-
- e_attachment_bar_attach_mime_part (
- E_ATTACHMENT_BAR (p->attachment_bar), mime_part);
-
- camel_object_unref (mime_part);
-}
-
-static void
msg_composer_update_preferences (GConfClient *client,
guint cnxn_id,
GConfEntry *entry,
@@ -1849,17 +1595,7 @@ struct _drop_data {
unsigned int aborted:1;
};
-int
-e_msg_composer_get_remote_download_count (EMsgComposer *composer)
-{
- EAttachmentBar *attachment_bar;
-
- g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), 0);
-
- attachment_bar = E_ATTACHMENT_BAR (composer->priv->attachment_bar);
- return e_attachment_bar_get_download_count (attachment_bar);
-}
-
+#if 0 /* FIXME */
static void
drop_action (EMsgComposer *composer,
GdkDragContext *context,
@@ -2033,55 +1769,7 @@ drop_action (EMsgComposer *composer,
gtk_drag_finish (context, success, delete, time);
}
-
-static void
-drop_popup_copy (EPopup *ep, EPopupItem *item, gpointer data)
-{
- struct _drop_data *m = data;
-
- drop_action (
- m->composer, m->context, GDK_ACTION_COPY,
- m->selection, m->info, m->time, FALSE);
-}
-
-static void
-drop_popup_move (EPopup *ep, EPopupItem *item, gpointer data)
-{
- struct _drop_data *m = data;
-
- drop_action (
- m->composer, m->context, GDK_ACTION_MOVE,
- m->selection, m->info, m->time, FALSE);
-}
-
-static void
-drop_popup_cancel (EPopup *ep, EPopupItem *item, gpointer data)
-{
- struct _drop_data *m = data;
-
- gtk_drag_finish (m->context, FALSE, FALSE, m->time);
-}
-
-static EPopupItem drop_popup_menu[] = {
- { E_POPUP_ITEM, "00.emc.02", N_("_Copy"), drop_popup_copy, NULL, "mail-copy", 0 },
- { E_POPUP_ITEM, "00.emc.03", N_("_Move"), drop_popup_move, NULL, "mail-move", 0 },
- { E_POPUP_BAR, "10.emc" },
- { E_POPUP_ITEM, "99.emc.00", N_("Cancel _Drag"), drop_popup_cancel, NULL, NULL, 0 },
-};
-
-static void
-drop_popup_free (EPopup *ep, GSList *items, gpointer data)
-{
- struct _drop_data *m = data;
-
- g_slist_free (items);
-
- g_object_unref (m->context);
- g_object_unref (m->composer);
- g_free (m->selection->data);
- g_free (m->selection);
- g_free (m);
-}
+#endif
static void
msg_composer_notify_header_cb (EMsgComposer *composer)
@@ -2341,33 +2029,14 @@ msg_composer_drag_motion (GtkWidget *widget,
gint y,
guint time)
{
- GList *targets;
- GdkDragAction actions = 0;
- GdkDragAction chosen_action;
-
- targets = context->targets;
- while (targets != NULL) {
- gint ii;
-
- for (ii = 0; ii < G_N_ELEMENTS (drag_info); ii++)
- if (targets->data == (gpointer) drag_info[ii].atom)
- actions |= drag_info[ii].actions;
-
- targets = g_list_next (targets);
- }
-
- actions &= context->actions;
- chosen_action = context->suggested_action;
-
- /* we default to copy */
- if (chosen_action == GDK_ACTION_ASK &&
- (actions & (GDK_ACTION_MOVE|GDK_ACTION_COPY)) !=
- (GDK_ACTION_MOVE|GDK_ACTION_COPY))
- chosen_action = GDK_ACTION_COPY;
+ EMsgComposer *composer;
+ EAttachmentView *view;
- gdk_drag_status (context, chosen_action, time);
+ /* Widget may be EMsgComposer or GtkHTML. */
+ composer = E_MSG_COMPOSER (gtk_widget_get_toplevel (widget));
+ view = e_msg_composer_get_attachment_view (composer);
- return (chosen_action != 0);
+ return e_attachment_view_drag_motion (view, context, x, y, time);
}
static void
@@ -2380,46 +2049,19 @@ msg_composer_drag_data_received (GtkWidget *widget,
guint time)
{
EMsgComposer *composer;
+ EAttachmentView *view;
/* Widget may be EMsgComposer or GtkHTML. */
composer = E_MSG_COMPOSER (gtk_widget_get_toplevel (widget));
-
- if (selection->data == NULL)
- return;
-
- if (selection->length == -1)
- return;
-
- if (context->action == GDK_ACTION_ASK) {
- EMPopup *emp;
- GSList *menus = NULL;
- GtkMenu *menu;
- gint ii;
- struct _drop_data *m;
-
- m = g_malloc0(sizeof (*m));
- m->context = g_object_ref (context);
- m->composer = g_object_ref (composer);
- m->action = context->action;
- m->info = info;
- m->time = time;
- m->selection = g_malloc0(sizeof (*m->selection));
- m->selection->data = g_malloc (selection->length);
- memcpy (m->selection->data, selection->data, selection->length);
- m->selection->length = selection->length;
-
- emp = em_popup_new ("org.gnome.evolution.mail.composer.popup.drop");
- for (ii = 0; ii < G_N_ELEMENTS (drop_popup_menu); ii++)
- menus = g_slist_append (menus, &drop_popup_menu[ii]);
-
- e_popup_add_items ((EPopup *)emp, menus, NULL, drop_popup_free, m);
- menu = e_popup_create_menu_once ((EPopup *)emp, NULL, 0);
- gtk_menu_popup (menu, NULL, NULL, NULL, NULL, 0, time);
- } else {
- drop_action (
- composer, context, context->action, selection,
- info, time, !GTK_WIDGET_TOPLEVEL (widget));
- }
+ view = e_msg_composer_get_attachment_view (composer);
+
+ /* Forward the data to the attachment view. Note that calling
+ * e_attachment_view_drag_data_received() will not work because
+ * that function only handles the case where all the other drag
+ * handlers have failed. */
+ e_attachment_paned_drag_data_received (
+ E_ATTACHMENT_PANED (view),
+ context, x, y, selection, info, time);
}
static void
@@ -2466,11 +2108,20 @@ static void
msg_composer_paste_clipboard (GtkhtmlEditor *editor)
{
EMsgComposer *composer;
+ EAttachmentView *view;
+ EAttachmentStore *store;
+ GtkClipboard *clipboard;
+ GdkPixbuf *pixbuf;
GtkWidget *parent;
GtkWidget *widget;
- GtkClipboard *clipboard;
+ gchar *filename;
+ gchar *uri;
+ GError *error = NULL;
composer = E_MSG_COMPOSER (editor);
+ view = e_msg_composer_get_attachment_view (composer);
+ store = e_attachment_view_get_store (view);
+
widget = gtk_window_get_focus (GTK_WINDOW (editor));
parent = gtk_widget_get_parent (widget);
@@ -2480,36 +2131,63 @@ msg_composer_paste_clipboard (GtkhtmlEditor *editor)
}
clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_CLIPBOARD);
- if (clipboard && gtk_clipboard_wait_is_image_available (clipboard)) {
- GdkPixbuf *pixbuf;
-
- pixbuf = gtk_clipboard_wait_for_image (clipboard);
- if (pixbuf) {
- char *tmpl = g_strconcat (_("Image"), "-XXXXXX", NULL);
- char *filename = e_mktemp (tmpl);
-
- g_free (tmpl);
-
- if (filename && gdk_pixbuf_save (pixbuf, filename, "png", NULL, NULL)) {
- if (gtkhtml_editor_get_html_mode (editor)) {
- char *uri = g_strconcat ("file://", filename, NULL);
- /* this loads image async, thus cannot remove file from this */
- gtkhtml_editor_insert_image (editor, uri);
- g_free (uri);
- } else {
- /* this loads image immediately, remove file from cache to free up disk space */
- e_attachment_bar_attach (E_ATTACHMENT_BAR (composer->priv->attachment_bar), filename, "image/png");
- g_remove (filename);
- }
- }
- g_free (filename);
- g_object_unref (pixbuf);
- }
- } else {
- /* Chain up to parent's paste_clipboard() method. */
- GTKHTML_EDITOR_CLASS (parent_class)->paste_clipboard (editor);
+ /* Assume the clipboard has an image. The return
+ * value will be NULL we we assumed wrong. */
+ pixbuf = gtk_clipboard_wait_for_image (clipboard);
+ if (!GDK_IS_PIXBUF (pixbuf))
+ goto chainup;
+
+ /* Reserve a temporary file. */
+ filename = e_mktemp (NULL);
+ if (filename == NULL) {
+ g_warning ("%s", g_strerror (errno));
+ g_object_unref (pixbuf);
+ g_error_free (error);
+ return;
+ }
+
+ /* Save the pixbuf as a temporary file in image/png format. */
+ if (!gdk_pixbuf_save (pixbuf, filename, "png", &error, NULL)) {
+ g_warning ("%s", error->message);
+ g_object_unref (pixbuf);
+ g_error_free (error);
+ g_free (filename);
+ return;
+ }
+
+ /* Convert the filename to a URI. */
+ uri = g_filename_to_uri (filename, NULL, &error);
+ if (error != NULL) {
+ g_warning ("%s", error->message);
+ g_object_unref (pixbuf);
+ g_error_free (error);
+ g_free (filename);
+ return;
}
+
+ if (gtkhtml_editor_get_html_mode (editor))
+ gtkhtml_editor_insert_image (editor, uri);
+ else {
+ EAttachment *attachment;
+
+ attachment = e_attachment_new_for_uri (uri);
+ e_attachment_store_add_attachment (store, attachment);
+ e_attachment_load_async (
+ attachment, (GAsyncReadyCallback)
+ e_attachment_load_handle_error, composer);
+ g_object_unref (attachment);
+ }
+
+ g_object_unref (pixbuf);
+ g_free (filename);
+ g_free (uri);
+
+ return;
+
+chainup:
+ /* Chain up to parent's paste_clipboard() method. */
+ GTKHTML_EDITOR_CLASS (parent_class)->paste_clipboard (editor);
}
static void
@@ -2733,11 +2411,6 @@ msg_composer_class_init (EMsgComposerClass *class)
GtkObjectClass *gtk_object_class;
GtkWidgetClass *widget_class;
GtkhtmlEditorClass *editor_class;
- gint ii;
-
- for (ii = 0; ii < G_N_ELEMENTS (drag_info); ii++)
- drag_info[ii].atom =
- gdk_atom_intern (drag_info[ii].target, FALSE);
parent_class = g_type_class_peek_parent (class);
g_type_class_add_private (class, sizeof (EMsgComposerPrivate));
@@ -2789,10 +2462,16 @@ msg_composer_class_init (EMsgComposerClass *class)
static void
msg_composer_init (EMsgComposer *composer)
{
+ EAttachmentView *view;
+ EAttachmentStore *store;
EComposerHeaderTable *table;
+ GdkDragAction drag_actions;
+ GtkTargetList *target_list;
+ GtkTargetEntry *targets;
GtkUIManager *manager;
GtkhtmlEditor *editor;
GtkHTML *html;
+ gint n_targets;
composer->priv = E_MSG_COMPOSER_GET_PRIVATE (composer);
@@ -2801,6 +2480,7 @@ msg_composer_init (EMsgComposer *composer)
editor = GTKHTML_EDITOR (composer);
html = gtkhtml_editor_get_html (editor);
manager = gtkhtml_editor_get_ui_manager (editor);
+ view = e_msg_composer_get_attachment_view (composer);
all_composers = g_slist_prepend (all_composers, composer);
table = E_COMPOSER_HEADER_TABLE (composer->priv->header_table);
@@ -2809,36 +2489,21 @@ msg_composer_init (EMsgComposer *composer)
/* Drag-and-Drop Support */
- gtk_drag_dest_set (
- GTK_WIDGET (composer), GTK_DEST_DEFAULT_ALL,
- drop_types, G_N_ELEMENTS (drop_types),
- GDK_ACTION_COPY | GDK_ACTION_ASK | GDK_ACTION_MOVE);
+ target_list = e_attachment_view_get_target_list (view);
+ drag_actions = e_attachment_view_get_drag_actions (view);
- /* XXX I'm not sure why we have to explicitly configure the
- * attachment bar as a drag destination when CompEditor
- * doesn't and previous Evolution releases (2.22 and
- * prior) don't, but this is the only way I could figure
- * out how to get drag-and-drop to the attachment bar
- * working again. I'm probably overlooking something
- * simple... */
+ targets = gtk_target_table_new_from_list (target_list, &n_targets);
gtk_drag_dest_set (
- composer->priv->attachment_bar, GTK_DEST_DEFAULT_ALL,
- drop_types, G_N_ELEMENTS (drop_types),
- GDK_ACTION_COPY | GDK_ACTION_ASK | GDK_ACTION_MOVE);
-
- g_signal_connect (
- composer->priv->attachment_bar, "drag-motion",
- G_CALLBACK (msg_composer_drag_motion), NULL);
-
- g_signal_connect (
- composer->priv->attachment_bar, "drag-data-received",
- G_CALLBACK (msg_composer_drag_data_received), NULL);
+ GTK_WIDGET (composer), GTK_DEST_DEFAULT_ALL,
+ targets, n_targets, drag_actions);
g_signal_connect (
html, "drag-data-received",
G_CALLBACK (msg_composer_drag_data_received), NULL);
+ gtk_target_table_free (targets, n_targets);
+
/* Configure Headers */
e_composer_header_table_set_account_list (
@@ -2877,23 +2542,17 @@ msg_composer_init (EMsgComposer *composer)
msg_composer_account_changed_cb (composer);
msg_composer_account_list_changed_cb (composer);
- /* Attachment Bar */
+ /* Attachments */
- g_signal_connect (
- composer->priv->attachment_bar, "button_press_event",
- G_CALLBACK (attachment_bar_button_press_event_cb), NULL);
- g_signal_connect (
- composer->priv->attachment_bar, "key_press_event",
- G_CALLBACK (attachment_bar_key_press_event_cb), NULL);
- g_signal_connect (
- composer->priv->attachment_bar, "popup-menu",
- G_CALLBACK (attachment_bar_popup_menu_cb), NULL);
- g_signal_connect (
- composer->priv->attachment_bar, "changed",
- G_CALLBACK (attachment_bar_changed_cb), composer);
- g_signal_connect_after (
- composer->priv->attachment_expander, "notify::expanded",
- G_CALLBACK (attachment_expander_notify_cb), composer);
+ store = e_attachment_view_get_store (view);
+
+ g_signal_connect_swapped (
+ store, "row-deleted",
+ G_CALLBACK (attachment_store_changed_cb), composer);
+
+ g_signal_connect_swapped (
+ store, "row-inserted",
+ G_CALLBACK (attachment_store_changed_cb), composer);
e_composer_autosave_register (composer);
@@ -3738,7 +3397,7 @@ disable_editor (EMsgComposer *composer)
action = GTKHTML_EDITOR_ACTION_INSERT_MENU (composer);
gtk_action_set_sensitive (action, FALSE);
- gtk_widget_set_sensitive (composer->priv->attachment_bar, FALSE);
+ gtk_widget_set_sensitive (composer->priv->attachment_paned, FALSE);
}
/**
@@ -3837,7 +3496,8 @@ add_recipients (GList *list, const gchar *recips)
static void
handle_mailto (EMsgComposer *composer, const gchar *mailto)
{
- EMsgComposerPrivate *priv = composer->priv;
+ EAttachmentView *view;
+ EAttachmentStore *store;
EComposerHeaderTable *table;
GList *to = NULL, *cc = NULL, *bcc = NULL;
EDestination **tov, **ccv, **bccv;
@@ -3846,9 +3506,10 @@ handle_mailto (EMsgComposer *composer, const gchar *mailto)
gsize nread, nwritten;
const gchar *p;
gint len, clen;
- CamelURL *url;
table = e_msg_composer_get_header_table (composer);
+ view = e_msg_composer_get_attachment_view (composer);
+ store = e_attachment_view_get_store (view);
buf = g_strdup (mailto);
@@ -3920,20 +3581,18 @@ handle_mailto (EMsgComposer *composer, const gchar *mailto)
}
} else if (!g_ascii_strcasecmp (header, "attach") ||
!g_ascii_strcasecmp (header, "attachment")) {
- /* Change file url to absolute path */
- if (!g_ascii_strncasecmp (content, "file:", 5)) {
- url = camel_url_new (content, NULL);
- e_attachment_bar_attach (E_ATTACHMENT_BAR (priv->attachment_bar),
- url->path,
- "attachment");
- camel_url_free (url);
- } else {
- e_attachment_bar_attach (E_ATTACHMENT_BAR (priv->attachment_bar),
- content,
- "attachment");
- }
- gtk_widget_show (priv->attachment_expander);
- gtk_widget_show (priv->attachment_scrolled_window);
+ EAttachment *attachment;
+
+ camel_url_decode (content);
+ if (g_ascii_strncasecmp (content, "file:", 5) == 0)
+ attachment = e_attachment_new_for_uri (content);
+ else
+ attachment = e_attachment_new_for_path (content);
+ e_attachment_store_add_attachment (store, attachment);
+ e_attachment_load_async (
+ attachment, (GAsyncReadyCallback)
+ e_attachment_load_handle_error, composer);
+ g_object_unref (attachment);
} else if (!g_ascii_strcasecmp (header, "from")) {
/* Ignore */
} else if (!g_ascii_strcasecmp (header, "reply-to")) {
@@ -3985,45 +3644,6 @@ handle_mailto (EMsgComposer *composer, const gchar *mailto)
}
}
-static void
-handle_uri (EMsgComposer *composer,
- const gchar *uri,
- gboolean html_dnd)
-{
- EMsgComposerPrivate *p = composer->priv;
- GtkhtmlEditor *editor;
- gboolean html_content;
-
- editor = GTKHTML_EDITOR (composer);
- html_content = gtkhtml_editor_get_html_mode (editor);
-
- if (!g_ascii_strncasecmp (uri, "mailto:", 7)) {
- handle_mailto (composer, uri);
- } else {
- CamelURL *url = camel_url_new (uri, NULL);
- gchar *type;
-
- if (!url)
- return;
-
- if (!g_ascii_strcasecmp (url->protocol, "file")) {
- type = e_util_guess_mime_type (uri + strlen ("file://"), TRUE);
- if (!type)
- return;
-
- if (strncmp (type, "image", 5) || !html_dnd || (!html_content && !strncmp (type, "image", 5))) {
- e_attachment_bar_attach (E_ATTACHMENT_BAR (p->attachment_bar),
- url->path, "attachment");
- }
- g_free (type);
- } else {
- e_attachment_bar_attach_remote_file (E_ATTACHMENT_BAR (p->attachment_bar),
- uri, "attachment");
- }
- camel_url_free (url);
- }
-}
-
/**
* e_msg_composer_new_from_url:
* @url: a mailto URL
@@ -4187,21 +3807,31 @@ e_msg_composer_remove_header (EMsgComposer *composer,
/**
* e_msg_composer_attach:
* @composer: a composer object
- * @attachment: the CamelMimePart to attach
+ * @mime_part: the #CamelMimePart to attach
*
* Attaches @attachment to the message being composed in the composer.
**/
void
-e_msg_composer_attach (EMsgComposer *composer, CamelMimePart *attachment)
+e_msg_composer_attach (EMsgComposer *composer,
+ CamelMimePart *mime_part)
{
- EAttachmentBar *bar;
- EMsgComposerPrivate *p = composer->priv;
+ EAttachmentView *view;
+ EAttachmentStore *store;
+ EAttachment *attachment;
g_return_if_fail (E_IS_MSG_COMPOSER (composer));
- g_return_if_fail (CAMEL_IS_MIME_PART (attachment));
-
- bar = E_ATTACHMENT_BAR (p->attachment_bar);
- e_attachment_bar_attach_mime_part (bar, attachment);
+ g_return_if_fail (CAMEL_IS_MIME_PART (mime_part));
+
+ view = e_msg_composer_get_attachment_view (composer);
+ store = e_attachment_view_get_store (view);
+
+ 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, composer);
+ g_object_unref (attachment);
}
/**
@@ -4315,12 +3945,17 @@ CamelMimeMessage *
e_msg_composer_get_message (EMsgComposer *composer,
gboolean save_html_object_data)
{
+ EAttachmentView *view;
+ EAttachmentStore *store;
GtkhtmlEditor *editor;
gboolean html_content;
g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), NULL);
- if (e_msg_composer_get_remote_download_count (composer) != 0) {
+ view = e_msg_composer_get_attachment_view (composer);
+ store = e_attachment_view_get_store (view);
+
+ if (e_attachment_store_get_num_loading (store) > 0) {
if (!em_utils_prompt_user (GTK_WINDOW (composer), NULL,
"mail-composer:ask-send-message-pending-download", NULL)) {
return NULL;
@@ -4623,14 +4258,6 @@ e_msg_composer_get_raw_message_text (EMsgComposer *composer)
return array;
}
-EAttachmentBar *
-e_msg_composer_get_attachment_bar (EMsgComposer *composer)
-{
- g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), NULL);
-
- return E_ATTACHMENT_BAR (composer->priv->attachment_bar);
-}
-
void
e_msg_composer_set_enable_autosave (EMsgComposer *composer,
gboolean enabled)
@@ -4794,6 +4421,14 @@ e_msg_composer_get_header_table (EMsgComposer *composer)
return E_COMPOSER_HEADER_TABLE (composer->priv->header_table);
}
+EAttachmentView *
+e_msg_composer_get_attachment_view (EMsgComposer *composer)
+{
+ g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), NULL);
+
+ return E_ATTACHMENT_VIEW (composer->priv->attachment_paned);
+}
+
void
e_msg_composer_set_send_options (EMsgComposer *composer,
gboolean send_enable)