gboolean e_composer_paste_uris (EMsgComposer *composer, GtkClipboard *clipboard) { EAttachmentStore *store; EAttachmentView *view; gchar **uris; gint ii; g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), FALSE); g_return_val_if_fail (GTK_IS_CLIPBOARD (clipboard), FALSE); view = e_msg_composer_get_attachment_view (composer); store = e_attachment_view_get_store (view); /* Extract the URI data from the clipboard. */ uris = gtk_clipboard_wait_for_uris (clipboard); g_return_val_if_fail (uris != NULL, FALSE); /* Add the URIs to the attachment store. */ 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, composer); g_object_unref (attachment); } return TRUE; }
static EAttachmentStore * mail_attachment_bar_get_store (EAttachmentView *view) { EMailAttachmentBarPrivate *priv; priv = E_MAIL_ATTACHMENT_BAR (view)->priv; view = E_ATTACHMENT_VIEW (priv->icon_view); return e_attachment_view_get_store (view); }
static EAttachmentStore * attachment_paned_get_store (EAttachmentView *view) { EAttachmentPanedPrivate *priv; priv = E_ATTACHMENT_PANED_GET_PRIVATE (view); view = E_ATTACHMENT_VIEW (priv->icon_view); return e_attachment_view_get_store (view); }
/* check for the any attachment */ static gboolean check_for_attachment (EMsgComposer *composer) { EAttachmentView *view; EAttachmentStore *store; view = e_msg_composer_get_attachment_view (composer); store = e_attachment_view_get_store (view); return (e_attachment_store_get_num_attachments (store) > 0); }
static void action_attach_cb (GtkAction *action, EMsgComposer *composer) { EAttachmentView *view; EAttachmentStore *store; view = e_msg_composer_get_attachment_view (composer); store = e_attachment_view_get_store (view); e_attachment_store_run_load_dialog (store, GTK_WINDOW (composer)); }
static void attachment_paned_update_status (EAttachmentPaned *paned) { EAttachmentView *view; EAttachmentStore *store; GtkExpander *expander; GtkLabel *label; guint num_attachments; guint64 total_size; gchar *display_size; gchar *markup; view = E_ATTACHMENT_VIEW (paned); store = e_attachment_view_get_store (view); expander = GTK_EXPANDER (paned->priv->expander); label = GTK_LABEL (paned->priv->status_label); num_attachments = e_attachment_store_get_num_attachments (store); total_size = e_attachment_store_get_total_size (store); display_size = g_format_size (total_size); if (total_size > 0) markup = g_strdup_printf ( "<b>%d</b> %s (%s)", num_attachments, ngettext ( "Attachment", "Attachments", num_attachments), display_size); else markup = g_strdup_printf ( "<b>%d</b> %s", num_attachments, ngettext ( "Attachment", "Attachments", num_attachments)); gtk_label_set_markup (label, markup); g_free (markup); g_free (display_size); if (num_attachments > 0) { gtk_widget_show (paned->priv->status_icon); gtk_widget_show (paned->priv->status_label); gtk_expander_set_expanded (expander, TRUE); } else { gtk_widget_hide (paned->priv->status_icon); gtk_widget_hide (paned->priv->status_label); gtk_expander_set_expanded (expander, FALSE); } }
static void mail_attachment_bar_update_status (EMailAttachmentBar *bar) { EAttachmentView *view; EAttachmentStore *store; GtkActivatable *activatable; GtkAction *action; GtkLabel *label; gint num_attachments; guint64 total_size; gchar *display_size; gchar *markup; view = E_ATTACHMENT_VIEW (bar); store = e_attachment_view_get_store (view); label = GTK_LABEL (bar->priv->status_label); num_attachments = e_attachment_store_get_num_attachments (store); total_size = e_attachment_store_get_total_size (store); display_size = g_format_size_for_display (total_size); if (total_size > 0) markup = g_strdup_printf ( "<b>%d</b> %s (%s)", num_attachments, ngettext ( "Attachment", "Attachments", num_attachments), display_size); else markup = g_strdup_printf ( "<b>%d</b> %s", num_attachments, ngettext ( "Attachment", "Attachments", num_attachments)); gtk_label_set_markup (label, markup); g_free (markup); activatable = GTK_ACTIVATABLE (bar->priv->save_all_button); action = gtk_activatable_get_related_action (activatable); gtk_action_set_visible (action, (num_attachments > 1)); activatable = GTK_ACTIVATABLE (bar->priv->save_one_button); action = gtk_activatable_get_related_action (activatable); gtk_action_set_visible (action, (num_attachments == 1)); g_free (display_size); }
static void mail_attachment_handler_x_uid_list (EAttachmentView *view, GdkDragContext *drag_context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time, EAttachmentHandler *handler) { static GdkAtom atom = GDK_NONE; EMailAttachmentHandlerPrivate *priv; CamelDataWrapper *wrapper; CamelMimeMessage *message; CamelMultipart *multipart; CamelMimePart *mime_part; CamelFolder *folder = NULL; EAttachment *attachment; EAttachmentStore *store; EMailSession *session; GPtrArray *uids; const gchar *data; const gchar *cp, *end; gchar *description; gpointer parent; gint length; guint ii; GError *local_error = NULL; 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; store = e_attachment_view_get_store (view); priv = E_MAIL_ATTACHMENT_HANDLER_GET_PRIVATE (handler); parent = gtk_widget_get_toplevel (GTK_WIDGET (view)); parent = gtk_widget_is_toplevel (parent) ? parent : NULL; uids = g_ptr_array_new (); data = (const gchar *) gtk_selection_data_get_data (selection_data); length = gtk_selection_data_get_length (selection_data); /* The UID list is delimited by NUL characters. * Brilliant. So we can't use g_strsplit(). */ cp = data; end = data + length; while (cp < end) { const gchar *start = cp; while (cp < end && *cp != '\0') cp++; /* Skip the first string. */ if (start > data) g_ptr_array_add (uids, g_strndup (start, cp - start)); cp++; } if (uids->len == 0) goto exit; session = e_mail_backend_get_session (priv->backend); /* The first string is the folder URI. */ /* FIXME Not passing a GCancellable here. */ folder = e_mail_session_uri_to_folder_sync ( session, data, 0, NULL, &local_error); if (folder == NULL) goto exit; /* Handle one message. */ if (uids->len == 1) { const gchar *message_uid; message_uid = g_ptr_array_index (uids, 0); /* FIXME Not passing a GCancellable here. */ message = camel_folder_get_message_sync ( folder, message_uid, NULL, &local_error); if (message == NULL) goto exit; attachment = e_attachment_new_for_message (message); e_attachment_store_add_attachment (store, attachment); e_attachment_load_async ( attachment, (GAsyncReadyCallback) call_attachment_load_handle_error, parent ? g_object_ref (parent) : NULL); g_object_unref (attachment); g_object_unref (message); goto exit; } /* Build a multipart/digest message out of the UIDs. */ multipart = camel_multipart_new (); wrapper = CAMEL_DATA_WRAPPER (multipart); camel_data_wrapper_set_mime_type (wrapper, "multipart/digest"); camel_multipart_set_boundary (multipart, NULL); for (ii = 0; ii < uids->len; ii++) { /* FIXME Not passing a GCancellable here. */ message = camel_folder_get_message_sync ( folder, uids->pdata[ii], NULL, &local_error); if (message == NULL) { g_object_unref (multipart); goto exit; } mime_part = camel_mime_part_new (); wrapper = CAMEL_DATA_WRAPPER (message); camel_mime_part_set_disposition (mime_part, "inline"); camel_medium_set_content ( CAMEL_MEDIUM (mime_part), wrapper); camel_mime_part_set_content_type (mime_part, "message/rfc822"); camel_multipart_add_part (multipart, mime_part); g_object_unref (mime_part); g_object_unref (message); } mime_part = camel_mime_part_new (); wrapper = CAMEL_DATA_WRAPPER (multipart); camel_medium_set_content (CAMEL_MEDIUM (mime_part), wrapper); description = g_strdup_printf ( ngettext ( "%d attached message", "%d attached messages", uids->len), uids->len); camel_mime_part_set_description (mime_part, description); g_free (description); 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) call_attachment_load_handle_error, parent ? g_object_ref (parent) : NULL); g_object_unref (attachment); g_object_unref (mime_part); g_object_unref (multipart); exit: if (local_error != NULL) { const gchar *folder_name = data; if (folder != NULL) folder_name = camel_folder_get_display_name (folder); e_alert_run_dialog_for_args ( parent, "mail-composer:attach-nomessages", folder_name, local_error->message, NULL); g_clear_error (&local_error); } if (folder != NULL) g_object_unref (folder); g_ptr_array_free (uids, TRUE); g_signal_stop_emission_by_name (view, "drag-data-received"); }
static void mail_attachment_handler_message_rfc822 (EAttachmentView *view, GdkDragContext *drag_context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time, EAttachmentHandler *handler) { 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, NULL, NULL); g_seekable_seek (G_SEEKABLE (stream), 0, G_SEEK_SET, NULL, NULL); message = camel_mime_message_new (); wrapper = CAMEL_DATA_WRAPPER (message); if (!camel_data_wrapper_construct_from_stream_sync ( wrapper, stream, NULL, NULL)) goto exit; store = e_attachment_view_get_store (view); parent = gtk_widget_get_toplevel (GTK_WIDGET (view)); parent = gtk_widget_is_toplevel (parent) ? parent : NULL; attachment = e_attachment_new_for_message (message); e_attachment_store_add_attachment (store, attachment); e_attachment_load_async ( attachment, (GAsyncReadyCallback) call_attachment_load_handle_error, parent ? g_object_ref (parent) : NULL); g_object_unref (attachment); success = TRUE; exit: g_object_unref (message); g_object_unref (stream); gtk_drag_finish (drag_context, success, FALSE, time); }
gboolean e_composer_paste_image (EMsgComposer *composer, GtkClipboard *clipboard) { EHTMLEditor *editor; EHTMLEditorView *html_editor_view; EAttachmentStore *store; EAttachmentView *view; GdkPixbuf *pixbuf = NULL; gchar *filename = NULL; gchar *uri = NULL; gboolean success = FALSE; GError *error = NULL; g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), FALSE); g_return_val_if_fail (GTK_IS_CLIPBOARD (clipboard), FALSE); view = e_msg_composer_get_attachment_view (composer); store = e_attachment_view_get_store (view); /* Extract the image data from the clipboard. */ pixbuf = gtk_clipboard_wait_for_image (clipboard); g_return_val_if_fail (pixbuf != NULL, FALSE); /* Reserve a temporary file. */ filename = e_mktemp (NULL); if (filename == NULL) { g_set_error ( &error, G_FILE_ERROR, g_file_error_from_errno (errno), "Could not create temporary file: %s", g_strerror (errno)); goto exit; } /* Save the pixbuf as a temporary file in image/png format. */ if (!gdk_pixbuf_save (pixbuf, filename, "png", &error, NULL)) goto exit; /* Convert the filename to a URI. */ uri = g_filename_to_uri (filename, NULL, &error); if (uri == NULL) goto exit; /* In HTML mode, paste the image into the message body. * In text mode, add the image to the attachment store. */ editor = e_msg_composer_get_editor (composer); html_editor_view = e_html_editor_get_view (editor); if (e_html_editor_view_get_html_mode (html_editor_view)) { EHTMLEditorSelection *selection; selection = e_html_editor_view_get_selection (html_editor_view); e_html_editor_selection_insert_image (selection, uri); e_html_editor_selection_scroll_to_caret (selection); } 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); } success = TRUE; exit: if (error != NULL) { g_warning ("%s", error->message); g_error_free (error); } g_object_unref (pixbuf); g_free (filename); g_free (uri); return success; }