diff options
Diffstat (limited to 'mail')
-rw-r--r-- | mail/Makefile.am | 2 | ||||
-rw-r--r-- | mail/e-mail-attachment-button.c | 542 | ||||
-rw-r--r-- | mail/e-mail-attachment-button.h | 90 | ||||
-rw-r--r-- | mail/e-mail-reader.c | 12 | ||||
-rw-r--r-- | mail/em-format-html-display.c | 268 | ||||
-rw-r--r-- | mail/em-format-html-display.h | 12 |
6 files changed, 711 insertions, 215 deletions
diff --git a/mail/Makefile.am b/mail/Makefile.am index 8039bfe52d..82fdf04096 100644 --- a/mail/Makefile.am +++ b/mail/Makefile.am @@ -39,6 +39,8 @@ libevolution_module_mail_la_SOURCES = \ e-attachment-handler-mail.h \ e-mail-attachment-bar.c \ e-mail-attachment-bar.h \ + e-mail-attachment-button.c \ + e-mail-attachment-button.h \ e-mail-browser.c \ e-mail-browser.h \ e-mail-display.c \ diff --git a/mail/e-mail-attachment-button.c b/mail/e-mail-attachment-button.c new file mode 100644 index 0000000000..1fe65df3b3 --- /dev/null +++ b/mail/e-mail-attachment-button.c @@ -0,0 +1,542 @@ +/* + * e-mail-attachment-button.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-mail-attachment-button.h" + +#include "e-util/e-binding.h" + +#define E_MAIL_ATTACHMENT_BUTTON_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), E_TYPE_MAIL_ATTACHMENT_BUTTON, EMailAttachmentButtonPrivate)) + +struct _EMailAttachmentButtonPrivate { + + EAttachmentView *view; + EAttachment *attachment; + gulong reference_handler_id; + + GtkWidget *inline_button; + GtkWidget *action_button; + GtkWidget *cell_view; + + guint expandable : 1; + guint expanded : 1; +}; + +enum { + PROP_0, + PROP_ATTACHMENT, + PROP_EXPANDABLE, + PROP_EXPANDED, + PROP_VIEW +}; + +enum { + CLICKED, + LAST_SIGNAL +}; + +static gpointer parent_class; +static gulong signals[LAST_SIGNAL]; + +static void +mail_attachment_button_action_clicked_cb (EMailAttachmentButton *button) +{ +} + +static void +mail_attachment_button_update_cell_view (EMailAttachmentButton *button) +{ + GtkCellView *cell_view; + EAttachment *attachment; + GtkTreeRowReference *reference; + GtkTreeModel *model = NULL; + GtkTreePath *path = NULL; + + cell_view = GTK_CELL_VIEW (button->priv->cell_view); + + attachment = e_mail_attachment_button_get_attachment (button); + if (attachment == NULL) + goto exit; + + reference = e_attachment_get_reference (attachment); + if (reference == NULL) + goto exit; + + model = gtk_tree_row_reference_get_model (reference); + path = gtk_tree_row_reference_get_path (reference); + +exit: + gtk_cell_view_set_model (cell_view, model); + gtk_cell_view_set_displayed_row (cell_view, path); + + if (path != NULL) + gtk_tree_path_free (path); +} + +static void +mail_attachment_button_update_pixbufs (EMailAttachmentButton *button) +{ + GtkCellView *cell_view; + GtkCellRenderer *renderer; + GtkIconTheme *icon_theme; + GdkPixbuf *pixbuf_expander_open; + GdkPixbuf *pixbuf_expander_closed; + GList *list; + + icon_theme = gtk_icon_theme_get_default (); + + /* Grab the first cell renderer. */ + cell_view = GTK_CELL_VIEW (button->priv->cell_view); + list = gtk_cell_view_get_cell_renderers (cell_view); + renderer = GTK_CELL_RENDERER (list->data); + g_list_free (list); + + pixbuf_expander_open = gtk_widget_render_icon ( + GTK_WIDGET (button), GTK_STOCK_GO_DOWN, + GTK_ICON_SIZE_BUTTON, NULL); + + pixbuf_expander_closed = gtk_widget_render_icon ( + GTK_WIDGET (button), GTK_STOCK_GO_FORWARD, + GTK_ICON_SIZE_BUTTON, NULL); + + g_object_set ( + renderer, + "pixbuf-expander-open", pixbuf_expander_open, + "pixbuf-expander-closed", pixbuf_expander_closed, + NULL); + + g_object_unref (pixbuf_expander_open); + g_object_unref (pixbuf_expander_closed); +} + +static void +mail_attachment_button_set_view (EMailAttachmentButton *button, + EAttachmentView *view) +{ + g_return_if_fail (button->priv->view == NULL); + + button->priv->view = g_object_ref (view); +} + +static void +mail_attachment_button_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_ATTACHMENT: + e_mail_attachment_button_set_attachment ( + E_MAIL_ATTACHMENT_BUTTON (object), + g_value_get_object (value)); + return; + + case PROP_EXPANDABLE: + e_mail_attachment_button_set_expandable ( + E_MAIL_ATTACHMENT_BUTTON (object), + g_value_get_boolean (value)); + return; + + case PROP_EXPANDED: + e_mail_attachment_button_set_expanded ( + E_MAIL_ATTACHMENT_BUTTON (object), + g_value_get_boolean (value)); + return; + + case PROP_VIEW: + mail_attachment_button_set_view ( + E_MAIL_ATTACHMENT_BUTTON (object), + g_value_get_object (value)); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +mail_attachment_button_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_ATTACHMENT: + g_value_set_object ( + value, + e_mail_attachment_button_get_attachment ( + E_MAIL_ATTACHMENT_BUTTON (object))); + return; + + case PROP_EXPANDABLE: + g_value_set_boolean ( + value, + e_mail_attachment_button_get_expandable ( + E_MAIL_ATTACHMENT_BUTTON (object))); + return; + + case PROP_EXPANDED: + g_value_set_boolean ( + value, + e_mail_attachment_button_get_expanded ( + E_MAIL_ATTACHMENT_BUTTON (object))); + return; + + case PROP_VIEW: + g_value_set_object ( + value, + e_mail_attachment_button_get_view ( + E_MAIL_ATTACHMENT_BUTTON (object))); + return; + } + + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); +} + +static void +mail_attachment_button_dispose (GObject *object) +{ + EMailAttachmentButtonPrivate *priv; + + priv = E_MAIL_ATTACHMENT_BUTTON_GET_PRIVATE (object); + + if (priv->view != NULL) { + g_object_unref (priv->view); + priv->view = NULL; + } + + if (priv->attachment != NULL) { + g_signal_handler_disconnect ( + priv->attachment, + priv->reference_handler_id); + g_object_unref (priv->attachment); + priv->attachment = NULL; + } + + if (priv->inline_button != NULL) { + g_object_unref (priv->inline_button); + priv->inline_button = NULL; + } + + if (priv->action_button != NULL) { + g_object_unref (priv->action_button); + priv->action_button = NULL; + } + + if (priv->cell_view != NULL) { + g_object_unref (priv->cell_view); + priv->cell_view = NULL; + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +mail_attachment_button_style_set (GtkWidget *widget, + GtkStyle *previous_style) +{ + EMailAttachmentButton *button; + + /* Chain up to parent's style_set() method. */ + GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style); + + button = E_MAIL_ATTACHMENT_BUTTON (widget); + mail_attachment_button_update_pixbufs (button); +} + +static void +mail_attachment_button_class_init (EMailAttachmentButtonClass *class) +{ + GObjectClass *object_class; + GtkWidgetClass *widget_class; + + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EMailAttachmentButtonPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = mail_attachment_button_set_property; + object_class->get_property = mail_attachment_button_get_property; + object_class->dispose = mail_attachment_button_dispose; + + widget_class = GTK_WIDGET_CLASS (class); + widget_class->style_set = mail_attachment_button_style_set; + + g_object_class_install_property ( + object_class, + PROP_ATTACHMENT, + g_param_spec_object ( + "attachment", + "Attachment", + NULL, + E_TYPE_ATTACHMENT, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_EXPANDABLE, + g_param_spec_boolean ( + "expandable", + "Expandable", + NULL, + TRUE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + + g_object_class_install_property ( + object_class, + PROP_EXPANDED, + g_param_spec_boolean ( + "expanded", + "Expanded", + NULL, + FALSE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); + + g_object_class_install_property ( + object_class, + PROP_VIEW, + g_param_spec_object ( + "view", + "View", + NULL, + E_TYPE_ATTACHMENT_VIEW, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); + + signals[CLICKED] = g_signal_new ( + "clicked", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (EMailAttachmentButtonClass, clicked), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); +} + +static void +mail_attachment_button_init (EMailAttachmentButton *button) +{ + GtkCellRenderer *renderer; + GtkCellLayout *cell_layout; + GtkWidget *container; + GtkWidget *widget; + + button->priv = E_MAIL_ATTACHMENT_BUTTON_GET_PRIVATE (button); + + /* Configure Widgets */ + + container = GTK_WIDGET (button); + + widget = gtk_button_new (); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); + button->priv->inline_button = g_object_ref (widget); + gtk_widget_show (widget); + + e_binding_new ( + G_OBJECT (button), "expandable", + G_OBJECT (widget), "sensitive"); + + widget = gtk_button_new (); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); + button->priv->action_button = g_object_ref (widget); + gtk_widget_show (widget); + + container = button->priv->inline_button; + + widget = gtk_cell_view_new (); + gtk_container_add (GTK_CONTAINER (container), widget); + button->priv->cell_view = g_object_ref (widget); + gtk_widget_show (widget); + + container = button->priv->action_button; + + widget = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE); + gtk_container_add (GTK_CONTAINER (container), widget); + gtk_widget_show (widget); + + /* Configure Renderers */ + + cell_layout = GTK_CELL_LAYOUT (button->priv->cell_view); + + renderer = gtk_cell_renderer_pixbuf_new (); + g_object_set (renderer, "is-expander", TRUE, NULL); + gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); + + e_mutual_binding_new ( + G_OBJECT (button), "expanded", + G_OBJECT (renderer), "is-expanded"); + + renderer = gtk_cell_renderer_pixbuf_new (); + g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL); + gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); + + gtk_cell_layout_add_attribute ( + cell_layout, renderer, "gicon", + E_ATTACHMENT_STORE_COLUMN_ICON); + + /* Configure Signal Handlers */ + + g_signal_connect_swapped ( + button->priv->action_button, "clicked", + G_CALLBACK (mail_attachment_button_action_clicked_cb), button); + + g_signal_connect_swapped ( + button->priv->inline_button, "clicked", + G_CALLBACK (e_mail_attachment_button_clicked), button); +} + +GType +e_mail_attachment_button_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (EMailAttachmentButtonClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) mail_attachment_button_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EMailAttachmentButton), + 0, /* n_preallocs */ + (GInstanceInitFunc) mail_attachment_button_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GTK_TYPE_HBOX, "EMailAttachmentButton", &type_info, 0); + } + + return type; +} + +GtkWidget * +e_mail_attachment_button_new (EAttachmentView *view) +{ + g_return_val_if_fail (E_IS_ATTACHMENT_VIEW (view), NULL); + + return g_object_new ( + E_TYPE_MAIL_ATTACHMENT_BUTTON, + "view", view, NULL); +} + +EAttachmentView * +e_mail_attachment_button_get_view (EMailAttachmentButton *button) +{ + g_return_val_if_fail (E_IS_MAIL_ATTACHMENT_BUTTON (button), NULL); + + return button->priv->view; +} + +EAttachment * +e_mail_attachment_button_get_attachment (EMailAttachmentButton *button) +{ + g_return_val_if_fail (E_IS_MAIL_ATTACHMENT_BUTTON (button), NULL); + + return button->priv->attachment; +} + +void +e_mail_attachment_button_set_attachment (EMailAttachmentButton *button, + EAttachment *attachment) +{ + g_return_if_fail (E_IS_MAIL_ATTACHMENT_BUTTON (button)); + + if (attachment != NULL) { + g_return_if_fail (E_IS_ATTACHMENT (attachment)); + g_object_ref (attachment); + } + + if (button->priv->attachment != NULL) { + g_signal_handler_disconnect ( + button->priv->attachment, + button->priv->reference_handler_id); + g_object_unref (button->priv->attachment); + } + + button->priv->attachment = attachment; + + if (attachment != NULL) { + gulong handler_id; + + handler_id = g_signal_connect_swapped ( + attachment, "notify::reference", + G_CALLBACK (mail_attachment_button_update_cell_view), + button); + mail_attachment_button_update_cell_view (button); + mail_attachment_button_update_pixbufs (button); + button->priv->reference_handler_id = handler_id; + } + + g_object_notify (G_OBJECT (button), "attachment"); +} + +gboolean +e_mail_attachment_button_get_expandable (EMailAttachmentButton *button) +{ + g_return_val_if_fail (E_IS_MAIL_ATTACHMENT_BUTTON (button), FALSE); + + return button->priv->expandable; +} + +void +e_mail_attachment_button_set_expandable (EMailAttachmentButton *button, + gboolean expandable) +{ + g_return_if_fail (E_IS_MAIL_ATTACHMENT_BUTTON (button)); + + button->priv->expandable = expandable; + + if (!expandable) + e_mail_attachment_button_set_expanded (button, FALSE); + + g_object_notify (G_OBJECT (button), "expandable"); +} + +gboolean +e_mail_attachment_button_get_expanded (EMailAttachmentButton *button) +{ + g_return_val_if_fail (E_IS_MAIL_ATTACHMENT_BUTTON (button), FALSE); + + return button->priv->expanded; +} + +void +e_mail_attachment_button_set_expanded (EMailAttachmentButton *button, + gboolean expanded) +{ + g_return_if_fail (E_IS_MAIL_ATTACHMENT_BUTTON (button)); + + button->priv->expanded = expanded; + + g_object_notify (G_OBJECT (button), "expanded"); +} + +void +e_mail_attachment_button_clicked (EMailAttachmentButton *button) +{ + g_return_if_fail (E_IS_MAIL_ATTACHMENT_BUTTON (button)); + + g_signal_emit (button, signals[CLICKED], 0); +} diff --git a/mail/e-mail-attachment-button.h b/mail/e-mail-attachment-button.h new file mode 100644 index 0000000000..26ec5cf0d6 --- /dev/null +++ b/mail/e-mail-attachment-button.h @@ -0,0 +1,90 @@ +/* + * e-mail-attachment-button.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_MAIL_ATTACHMENT_BUTTON_H +#define E_MAIL_ATTACHMENT_BUTTON_H + +#include <gtk/gtk.h> +#include <widgets/misc/e-attachment.h> +#include <widgets/misc/e-attachment-view.h> + +/* Standard GObject macros */ +#define E_TYPE_MAIL_ATTACHMENT_BUTTON \ + (e_mail_attachment_button_get_type ()) +#define E_MAIL_ATTACHMENT_BUTTON(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_MAIL_ATTACHMENT_BUTTON, EMailAttachmentButton)) +#define E_MAIL_ATTACHMENT_BUTTON_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_MAIL_ATTACHMENT_BUTTON, EMailAttachmentButtonClass)) +#define E_IS_MAIL_ATTACHMENT_BUTTON(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_MAIL_ATTACHMENT_BUTTON)) +#define E_IS_MAIL_ATTACHMENT_BUTTON_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_MAIL_ATTACHMENT_BUTTON)) +#define E_MAIL_ATTACHMENT_BUTTON_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_MAIL_ATTACHMENT_BUTTON, EMailAttachmentButtonClass)) + +G_BEGIN_DECLS + +typedef struct _EMailAttachmentButton EMailAttachmentButton; +typedef struct _EMailAttachmentButtonClass EMailAttachmentButtonClass; +typedef struct _EMailAttachmentButtonPrivate EMailAttachmentButtonPrivate; + +struct _EMailAttachmentButton { + GtkHBox parent; + EMailAttachmentButtonPrivate *priv; +}; + +struct _EMailAttachmentButtonClass { + GtkHBoxClass parent_class; + + /* Signals */ + void (*clicked) (EMailAttachmentButton *button); +}; + +GType e_mail_attachment_button_get_type (void); +GtkWidget * e_mail_attachment_button_new (EAttachmentView *view); +void e_mail_attachment_button_clicked(EMailAttachmentButton *button); +EAttachmentView * + e_mail_attachment_button_get_view + (EMailAttachmentButton *button); +EAttachment * e_mail_attachment_button_get_attachment + (EMailAttachmentButton *button); +void e_mail_attachment_button_set_attachment + (EMailAttachmentButton *button, + EAttachment *attachment); +gboolean e_mail_attachment_button_get_expandable + (EMailAttachmentButton *button); +void e_mail_attachment_button_set_expandable + (EMailAttachmentButton *button, + gboolean expandable); +gboolean e_mail_attachment_button_get_expanded + (EMailAttachmentButton *button); +void e_mail_attachment_button_set_expanded + (EMailAttachmentButton *button, + gboolean expanded); + +G_END_DECLS + +#endif /* E_MAIL_ATTACHMENT_BUTTON_H */ diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c index a026f6db8d..196f2f0323 100644 --- a/mail/e-mail-reader.c +++ b/mail/e-mail-reader.c @@ -1015,10 +1015,12 @@ action_mail_zoom_100_cb (GtkAction *action, EMailReader *reader) { EMFormatHTMLDisplay *html_display; + GtkHTML *html; html_display = e_mail_reader_get_html_display (reader); + html = EM_FORMAT_HTML (html_display)->html; - em_format_html_display_zoom_reset (html_display); + gtk_html_zoom_reset (html); } static void @@ -1026,10 +1028,12 @@ action_mail_zoom_in_cb (GtkAction *action, EMailReader *reader) { EMFormatHTMLDisplay *html_display; + GtkHTML *html; html_display = e_mail_reader_get_html_display (reader); + html = EM_FORMAT_HTML (html_display)->html; - em_format_html_display_zoom_in (html_display); + gtk_html_zoom_out (html); } static void @@ -1037,10 +1041,12 @@ action_mail_zoom_out_cb (GtkAction *action, EMailReader *reader) { EMFormatHTMLDisplay *html_display; + GtkHTML *html; html_display = e_mail_reader_get_html_display (reader); + html = EM_FORMAT_HTML (html_display)->html; - em_format_html_display_zoom_out (html_display); + gtk_html_zoom_out (html); } static GtkActionEntry mail_reader_entries[] = { diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c index 346efff92a..5faa671fd8 100644 --- a/mail/em-format-html-display.c +++ b/mail/em-format-html-display.c @@ -63,7 +63,6 @@ #include <e-util/e-util-private.h> #include <libedataserver/e-msgport.h> -#include <e-util/e-gui-utils.h> #include <e-util/e-dialog-utils.h> #include <e-util/e-icon-factory.h> @@ -76,6 +75,7 @@ #include "e-mail-display.h" #include "e-mail-attachment-bar.h" +#include "e-mail-attachment-button.h" #include "em-format-html-display.h" #include "em-icon-stream.h" #include "em-utils.h" @@ -99,17 +99,7 @@ ((obj), EM_TYPE_FORMAT_HTML_DISPLAY, EMFormatHTMLDisplayPrivate)) struct _EMFormatHTMLDisplayPrivate { - /* for Attachment bar */ - GtkWidget *attachment_bar; - GtkWidget *label; - GtkWidget *save_txt; - GtkWidget *arrow; - GtkWidget *forward; - GtkWidget *down; - GtkWidget *attachment_area; - gboolean show_bar; - GHashTable *files; - gboolean updated; + GtkWidget *attachment_view; /* weak reference */ }; struct _smime_pobject { @@ -149,7 +139,6 @@ static const char *smime_sign_colour[5] = { static void efhd_attachment_frame(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri); static gboolean efhd_attachment_image(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *pobject); static void efhd_message_add_bar(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info); -static void efhd_attachment_button_show (GtkWidget *w, void *data); static gboolean efhd_attachment_button (EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *pobject); static gboolean efhd_attachment_optional (EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *object); @@ -164,7 +153,6 @@ struct _attach_puri { GtkWidget *forward, *down; /* currently no way to correlate this data to the frame :( */ GtkHTML *frame; - CamelStream *output; unsigned int shown:1; /* Embedded Frame */ @@ -190,11 +178,9 @@ struct _attach_puri { static void efhd_message_prefix(EMFormat *emf, CamelStream *stream, CamelMimePart *part, EMFormatHandler *info); -static void efhd_complete(EMFormat *); - static void efhd_builtin_init(EMFormatHTMLDisplayClass *efhc); -static EMFormatHTMLClass *parent_class; +static gpointer parent_class; static void efhd_xpkcs7mime_free (EMFormatHTMLPObject *o) @@ -434,36 +420,14 @@ efhd_xpkcs7mime_button (EMFormatHTML *efh, } static void -efhd_finalize (GObject *object) -{ - EMFormatHTMLDisplayPrivate *priv; - - priv = EM_FORMAT_HTML_DISPLAY_GET_PRIVATE (object); - - if (priv->files != NULL) - g_hash_table_destroy (priv->files); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static void efhd_format_clone (EMFormat *emf, CamelFolder *folder, const gchar *uid, CamelMimeMessage *msg, EMFormat *src) { - EMFormatHTMLDisplayPrivate *priv; - - priv = EM_FORMAT_HTML_DISPLAY_GET_PRIVATE (emf); - - if (emf != src) { - priv->show_bar = (src != NULL) ? - EM_FORMAT_HTML_DISPLAY (src)->priv->show_bar : FALSE; - + if (emf != src) EM_FORMAT_HTML (emf)->header_wrap_flags = 0; - } /* Chain up to parent's format_clone() method. */ EM_FORMAT_CLASS (parent_class)-> @@ -656,22 +620,17 @@ efhd_format_secure (EMFormat *emf, static void efhd_class_init (EMFormatHTMLDisplayClass *class) { - GObjectClass *object_class; EMFormatClass *format_class; EMFormatHTMLClass *format_html_class; parent_class = g_type_class_peek_parent (class); g_type_class_add_private (class, sizeof (EMFormatHTMLDisplayPrivate)); - object_class = G_OBJECT_CLASS (class); - object_class->finalize = efhd_finalize; - format_class = EM_FORMAT_CLASS (class); format_class->format_clone = efhd_format_clone; format_class->format_attachment = efhd_format_attachment; format_class->format_optional = efhd_format_optional; format_class->format_secure = efhd_format_secure; - format_class->complete = efhd_complete; format_html_class = EM_FORMAT_HTML_CLASS (class); format_html_class->html_widget_type = E_TYPE_MAIL_DISPLAY; @@ -695,9 +654,6 @@ efhd_init (EMFormatHTMLDisplay *efhd) EM_FORMAT_HTML (efhd)->text_html_flags |= CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS | CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES; - - efhd->priv->show_bar = FALSE; - efhd->priv->files = NULL; } GType @@ -733,55 +689,6 @@ em_format_html_display_new (void) return g_object_new (EM_TYPE_FORMAT_HTML_DISPLAY, NULL); } -void -em_format_html_display_cut (EMFormatHTMLDisplay *efhd) -{ - gtk_html_cut (((EMFormatHTML *) efhd)->html); -} - -void -em_format_html_display_copy (EMFormatHTMLDisplay *efhd) -{ - gtk_html_copy (((EMFormatHTML *) efhd)->html); -} - -void -em_format_html_display_paste (EMFormatHTMLDisplay *efhd) -{ - gtk_html_paste (((EMFormatHTML *) efhd)->html, FALSE); -} - -void -em_format_html_display_zoom_in (EMFormatHTMLDisplay *efhd) -{ - gtk_html_zoom_in (((EMFormatHTML *) efhd)->html); -} - -void -em_format_html_display_zoom_out (EMFormatHTMLDisplay *efhd) -{ - gtk_html_zoom_out (((EMFormatHTML *) efhd)->html); -} - -void -em_format_html_display_zoom_reset (EMFormatHTMLDisplay *efhd) -{ - gtk_html_zoom_reset (((EMFormatHTML *) efhd)->html); -} - -/* ********************************************************************** */ - -static void -efhd_complete(EMFormat *emf) -{ - EMFormatHTMLDisplay *efhd = (EMFormatHTMLDisplay *)emf; - - if (efhd->priv->files) { - g_hash_table_destroy (efhd->priv->files); - efhd->priv->files = NULL; - } -} - /* ********************************************************************** */ static void @@ -948,12 +855,13 @@ efhd_attachment_show(EPopup *ep, EPopupItem *item, void *data) } static void -efhd_attachment_button_show(GtkWidget *w, void *data) +efhd_attachment_button_clicked (GtkWidget *widget, + struct _attach_puri *info) { - if (!efhd_can_process_attachment (w)) + if (!efhd_can_process_attachment (widget)) return; - efhd_attachment_show(NULL, NULL, data); + efhd_attachment_show (NULL, NULL, info); } static void @@ -1301,6 +1209,12 @@ efhd_attachment_button(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObje }; AtkObject *a11y; + EAttachmentView *view; + EAttachmentStore *store; + EAttachment *attachment; + GtkWidget *widget; + gpointer parent; + /* FIXME: handle default shown case */ d(printf("adding attachment button/content\n")); @@ -1311,60 +1225,40 @@ efhd_attachment_button(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObje return TRUE; } - if (efhd->priv->attachment_bar) { - EAttachmentView *view; - EAttachmentStore *store; - gpointer parent; + attachment = info->attachment; + e_attachment_set_signed (attachment, info->sign); + e_attachment_set_encrypted (attachment, info->encrypt); - parent = gtk_widget_get_toplevel (GTK_WIDGET (efh->html)); - parent = GTK_WIDGET_TOPLEVEL (parent) ? parent : NULL; + parent = gtk_widget_get_toplevel (GTK_WIDGET (efh->html)); + parent = GTK_WIDGET_TOPLEVEL (parent) ? parent : NULL; - gtk_widget_show (efhd->priv->attachment_bar); + view = E_ATTACHMENT_VIEW (efhd->priv->attachment_view); + gtk_widget_show (efhd->priv->attachment_view); - view = E_ATTACHMENT_VIEW (efhd->priv->attachment_bar); - store = e_attachment_view_get_store (view); - e_attachment_store_add_attachment (store, info->attachment); - e_attachment_load_async ( - info->attachment, (GAsyncReadyCallback) - e_attachment_load_handle_error, parent); + store = e_attachment_view_get_store (view); + e_attachment_store_add_attachment (store, info->attachment); - e_attachment_set_encrypted (info->attachment, info->encrypt); - e_attachment_set_signed (info->attachment, info->sign); - } - - mainbox = gtk_hbox_new(FALSE, 0); + e_attachment_load_async ( + info->attachment, (GAsyncReadyCallback) + e_attachment_load_handle_error, parent); - button = gtk_button_new(); - - if (info->handle) { - g_signal_connect(button, "clicked", G_CALLBACK(efhd_attachment_button_show), info); - g_object_set_data (G_OBJECT (button), "efh", efh); - } else { - gtk_widget_set_sensitive(button, FALSE); - GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS); - } - - hbox = gtk_hbox_new(FALSE, 2); - info->forward = gtk_image_new_from_stock(GTK_STOCK_GO_FORWARD, GTK_ICON_SIZE_BUTTON); - gtk_box_pack_start((GtkBox *)hbox, info->forward, TRUE, TRUE, 0); - if (info->handle) { - info->down = gtk_image_new_from_stock(GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_BUTTON); - gtk_box_pack_start((GtkBox *)hbox, info->down, TRUE, TRUE, 0); - } + widget = e_mail_attachment_button_new (view); + e_mail_attachment_button_set_attachment ( + E_MAIL_ATTACHMENT_BUTTON (widget), attachment); + e_mail_attachment_button_set_expandable ( + E_MAIL_ATTACHMENT_BUTTON (widget), (info->handle != NULL)); + e_mail_attachment_button_set_expanded ( + E_MAIL_ATTACHMENT_BUTTON (widget), info->shown); + gtk_container_add (GTK_CONTAINER (eb), widget); + gtk_widget_show (widget); - w = gtk_image_new(); - gtk_widget_set_size_request(w, 24, 24); - gtk_box_pack_start((GtkBox *)hbox, w, TRUE, TRUE, 0); - gtk_container_add((GtkContainer *)button, hbox); - gtk_box_pack_start((GtkBox *)mainbox, button, TRUE, TRUE, 0); + g_object_set_data (G_OBJECT (widget), "efh", efh); - /* Check for snooped type to get the right icon/processing */ - if (info->snoop_mime_type) - simple_type = g_strdup(info->snoop_mime_type); - else - simple_type = camel_content_type_simple (((CamelDataWrapper *)pobject->part)->mime_type); - camel_strdown(simple_type); + g_signal_connect ( + widget, "clicked", + G_CALLBACK (efhd_attachment_button_clicked), info); +#if 0 /* FIXME: offline parts, just get icon */ if (camel_content_type_is(((CamelDataWrapper *)pobject->part)->mime_type, "image", "*")) { EMFormatHTMLJob *job; @@ -1383,16 +1277,6 @@ efhd_attachment_button(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObje job->stream = (CamelStream *)em_icon_stream_new((GtkImage *)w, key, 24, 24, FALSE); em_format_html_job_queue(efh, job); } - } else { - GdkPixbuf *pixbuf, *mini; - - if ((pixbuf = e_icon_for_mime_type (simple_type, 24))) { - if ((mini = e_icon_factory_pixbuf_scale (pixbuf, 24, 24))) { - gtk_image_set_from_pixbuf ((GtkImage *) w, mini); - g_object_unref (mini); - } - g_object_unref (pixbuf); - } } drag_types[0].target = simple_type; @@ -1401,28 +1285,11 @@ efhd_attachment_button(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObje g_signal_connect (button, "drag-data-delete", G_CALLBACK(efhd_drag_data_delete), pobject); g_free(simple_type); - button = gtk_button_new(); - /*GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS);*/ - gtk_container_add((GtkContainer *)button, gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE)); - - a11y = gtk_widget_get_accessible (button); - atk_object_set_name (a11y, _("Attachment")); - g_signal_connect(button, "button_press_event", G_CALLBACK(efhd_attachment_popup), info); g_signal_connect(button, "popup_menu", G_CALLBACK(efhd_attachment_popup_menu), info); g_signal_connect(button, "clicked", G_CALLBACK(efhd_attachment_popup_menu), info); gtk_box_pack_start((GtkBox *)mainbox, button, TRUE, TRUE, 0); - - g_object_set_data (G_OBJECT (button), "efh", efh); - - gtk_widget_show_all(mainbox); - - if (info->shown) - gtk_widget_hide(info->forward); - else if (info->down) - gtk_widget_hide(info->down); - - gtk_container_add((GtkContainer *)eb, mainbox); +#endif return TRUE; } @@ -1430,37 +1297,34 @@ efhd_attachment_button(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObje /* not used currently */ /* frame source callback */ static void -efhd_attachment_frame(EMFormat *emf, CamelStream *stream, EMFormatPURI *puri) +efhd_attachment_frame (EMFormat *emf, + CamelStream *stream, + EMFormatPURI *puri) { struct _attach_puri *info = (struct _attach_puri *)puri; - if (info->shown) { - d(printf("writing to frame content, handler is '%s'\n", info->handle->mime_type)); - info->handle->handler(emf, stream, info->puri.part, info->handle); - camel_stream_close(stream); - } else { - /* FIXME: this is leaked if the object is closed without showing it - NB: need a virtual puri_free method? */ - info->output = stream; - camel_object_ref(stream); - } + if (info->shown) + info->handle->handler ( + emf, stream, info->puri.part, info->handle); + + camel_stream_close (stream); } static void efhd_bar_resize (EMFormatHTML *efh, GtkAllocation *event) { - EMFormatHTMLDisplay *efhd; + EMFormatHTMLDisplayPrivate *priv; GtkWidget *widget; gint width; - efhd = EM_FORMAT_HTML_DISPLAY (efh); + priv = EM_FORMAT_HTML_DISPLAY_GET_PRIVATE (efh); widget = GTK_WIDGET (efh->html); width = widget->allocation.width - 12; if (width > 0) { - widget = efhd->priv->attachment_bar; + widget = priv->attachment_view; gtk_widget_set_size_request (widget, width, -1); } } @@ -1470,14 +1334,14 @@ efhd_add_bar (EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *pobject) { - EMFormatHTMLDisplay *efhd = (EMFormatHTMLDisplay *)efh; - struct _EMFormatHTMLDisplayPrivate *priv = efhd->priv; - GtkRequisition requisition; + EMFormatHTMLDisplayPrivate *priv; GtkWidget *widget; + priv = EM_FORMAT_HTML_DISPLAY_GET_PRIVATE (efh); + widget = e_mail_attachment_bar_new (); gtk_container_add (GTK_CONTAINER (eb), widget); - priv->attachment_bar = g_object_ref (widget); + priv->attachment_view = widget; gtk_widget_hide (widget); g_signal_connect_swapped ( @@ -1488,19 +1352,23 @@ efhd_add_bar (EMFormatHTML *efh, } static void -efhd_message_add_bar(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info) +efhd_message_add_bar (EMFormat *emf, + CamelStream *stream, + CamelMimePart *part, + const EMFormatHandler *info) { - EMFormatHTMLDisplay *efhd = (EMFormatHTMLDisplay *) emf; + EMFormatHTMLDisplayPrivate *priv; const char *classid = "attachment-bar"; - if (efhd->priv->files) - return; + priv = EM_FORMAT_HTML_DISPLAY_GET_PRIVATE (emf); - efhd->priv->files = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - efhd->priv->updated = FALSE; + em_format_html_add_pobject ( + EM_FORMAT_HTML (emf), + sizeof (EMFormatHTMLPObject), + classid, part, efhd_add_bar); - em_format_html_add_pobject((EMFormatHTML *)emf, sizeof(EMFormatHTMLPObject), classid, part, efhd_add_bar); - camel_stream_printf(stream, "<td><object classid=\"%s\"></object></td>", classid); + camel_stream_printf ( + stream, "<td><object classid=\"%s\"></object></td>", classid); } static void diff --git a/mail/em-format-html-display.h b/mail/em-format-html-display.h index 9cfdb03780..7554053e37 100644 --- a/mail/em-format-html-display.h +++ b/mail/em-format-html-display.h @@ -25,7 +25,6 @@ #ifndef EM_FORMAT_HTML_DISPLAY_H #define EM_FORMAT_HTML_DISPLAY_H -#include <camel/camel-mime-part.h> #include <mail/em-format-html.h> /* Standard GObject macros */ @@ -67,17 +66,6 @@ struct _EMFormatHTMLDisplayClass { GType em_format_html_display_get_type (void); EMFormatHTMLDisplay * em_format_html_display_new (void); -void em_format_html_display_cut (EMFormatHTMLDisplay *efhd); -void em_format_html_display_copy (EMFormatHTMLDisplay *efhd); -void em_format_html_display_paste (EMFormatHTMLDisplay *efhd); - -void em_format_html_display_zoom_in (EMFormatHTMLDisplay *efhd); -void em_format_html_display_zoom_out (EMFormatHTMLDisplay *efhd); -void em_format_html_display_zoom_reset - (EMFormatHTMLDisplay *efhd); - -gboolean em_format_html_display_popup_menu - (EMFormatHTMLDisplay *efhd); G_END_DECLS |