[evolution/webkit: 22/105] Make attachments expandable.
- From: Dan VrÃtil <dvratil src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/webkit: 22/105] Make attachments expandable.
- Date: Mon, 9 Jan 2012 08:41:36 +0000 (UTC)
commit 85b903eb7f335c4721f7e24b72ed095d69cea264
Author: Dan VrÃtil <dvratil redhat com>
Date: Wed Sep 14 11:46:41 2011 +0200
Make attachments expandable.
Make attachments with widget_func and write_func expandable, as
EAttachmentButton is created throught widget_func and content of
the attachment is available throught write_func.
mail/e-mail-display.c | 92 ++++++++++++++++++++++++++++++-----------
mail/em-format-html-display.c | 25 +----------
2 files changed, 69 insertions(+), 48 deletions(-)
---
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index 8494c93..d96cacc 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -36,6 +36,7 @@
#include "mail/e-mail-request.h"
#include "mail/em-format-html-display.h"
#include "mail/e-mail-attachment-bar.h"
+#include "widgets/misc/e-attachment-button.h"
#include <libsoup/soup.h>
#include <libsoup/soup-requester.h>
@@ -373,8 +374,6 @@ mail_display_resource_requested (WebKitWebView *web_view,
g_free (data);
g_free (path);
}
-
- //g_signal_stop_emission_by_name (web_view, "resource-request-starting");
}
static void
@@ -398,7 +397,7 @@ mail_display_headers_collapsed_state_changed (EWebView *web_view,
static void
mail_display_install_js_callbacks (WebKitWebView *web_view,
- WebKitWebFrame *frame,
+ WebKitWebFrame *frame,
gpointer context,
gpointer window_object,
gpointer user_data)
@@ -452,7 +451,35 @@ mail_display_setup_webview (EMailDisplay *display)
}
static void
-e_mail_display_class_init (EMailDisplayClass *class)
+mail_display_insert_web_view (EMailDisplay *display,
+ EWebView *web_view,
+ gboolean expandable)
+{
+#if 0
+ GtkWidget *scrolled_window;
+
+ display->widgets = g_list_append (display->widgets, GTK_WIDGET (web_view));
+ scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+ g_object_set (G_OBJECT (scrolled_window),
+ "hscrollbar-policy", GTK_POLICY_NEVER,
+ "vscrollbar-policy", GTK_POLICY_NEVER,
+ "shadow-type", GTK_SHADOW_NONE, NULL);
+ //"min-content-height", 300, NULL);
+ gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (web_view));
+ display->widgets = g_list_append (display->widgets, scrolled_window);
+
+ gtk_box_pack_start (GTK_BOX (display->priv->vbox), scrolled_window, expandable, TRUE, 0);
+ gtk_widget_show_all (scrolled_window);
+#endif
+
+ gtk_box_pack_start (GTK_BOX (display->priv->vbox), GTK_WIDGET (web_view), expandable, TRUE, 0);
+ display->widgets = g_list_append (display->widgets, GTK_WIDGET (web_view));
+ gtk_widget_show_all (GTK_WIDGET (web_view));
+
+}
+
+static void
+mail_display_class_init (EMailDisplayClass *class)
{
GObjectClass *object_class;
GtkWidgetClass *widget_class;
@@ -495,19 +522,14 @@ e_mail_display_class_init (EMailDisplayClass *class)
static void
e_mail_display_init (EMailDisplay *display)
{
- GtkScrolledWindow *scrolled_window;
SoupSession *session;
SoupSessionFeature *feature;
GValue margin = {0};
display->priv = E_MAIL_DISPLAY_GET_PRIVATE (display);
- scrolled_window = GTK_SCROLLED_WINDOW (display);
- gtk_scrolled_window_set_policy (scrolled_window, GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
- gtk_scrolled_window_set_shadow_type (scrolled_window, GTK_SHADOW_NONE);
-
- display->priv->vbox = gtk_vbox_new (FALSE, 0);
- gtk_scrolled_window_add_with_viewport (scrolled_window, display->priv->vbox);
+ display->priv->vbox = gtk_vbox_new (FALSE, 10);
+ gtk_container_add (GTK_CONTAINER (display), display->priv->vbox);
g_value_init (&margin, G_TYPE_INT);
g_value_set_int (&margin, 10);
g_object_set_property (G_OBJECT (display->priv->vbox), "margin", &margin);
@@ -604,6 +626,8 @@ e_mail_display_load (EMailDisplay *display,
const gchar *msg_uri)
{
EWebView *web_view;
+ EAttachmentStore *attachment_store;
+ GtkWidget *attachment_bar;
EMFormatPURI *puri;
EMFormat *emf = (EMFormat *) display->priv->formatter;
gchar *uri;
@@ -612,34 +636,44 @@ e_mail_display_load (EMailDisplay *display,
g_return_if_fail (E_IS_MAIL_DISPLAY (display));
+ /* Don't use gtk_widget_show_all() to display all widgets at once,
+ it makes all parts of EMailAttachmentBar visible and that's not
+ what we want.
+ FIXME: Maybe using gtk_widget_set_no_show_all() in EAttachmentView
+ could help...
+ */
+
/* First remove all widgets left after previous message */
e_mail_display_clear (display);
box = GTK_BOX (display->priv->vbox);
+ gtk_widget_show (display->priv->vbox);
/* Headers webview */
web_view = mail_display_setup_webview (display);
- display->widgets = g_list_append (display->widgets, GTK_WIDGET (web_view));
- gtk_box_pack_start (box, GTK_WIDGET (web_view),
- TRUE, TRUE, 0);
+ mail_display_insert_web_view (display, web_view, FALSE);
uri = em_format_build_mail_uri (emf->folder, emf->message_uid, "headers");
e_web_view_load_uri (web_view, uri);
g_free (uri);
/* Attachment bar */
+ attachment_store = NULL;
puri = g_hash_table_lookup (emf->mail_part_table, "attachment-bar:");
if (puri && puri->widget_func) {
- GtkWidget *widget = puri->widget_func (emf, puri, NULL);
- display->widgets = g_list_append (display->widgets, widget);
- gtk_box_pack_start (box, widget, TRUE, TRUE, 0);
+ attachment_bar = puri->widget_func (emf, puri, NULL);
+ display->widgets = g_list_append (display->widgets, attachment_bar);
+ gtk_box_pack_start (box, attachment_bar, TRUE, TRUE, 0);
+ attachment_store = e_attachment_view_get_store (E_ATTACHMENT_VIEW (attachment_bar));
+ gtk_widget_show (attachment_bar);
}
for (iter = emf->mail_part_list; iter; iter = iter->next) {
+ GtkWidget *widget = NULL;
+
puri = iter->data;
uri = em_format_build_mail_uri (emf->folder, emf->message_uid, puri->uri);
if (puri->widget_func && strcmp (puri->uri, "attachment-bar:") != 0) {
- GtkWidget *widget;
widget = puri->widget_func (emf, puri, NULL);
if (!widget) {
@@ -647,21 +681,29 @@ e_mail_display_load (EMailDisplay *display,
continue;
}
display->widgets = g_list_append (display->widgets, widget);
- gtk_box_pack_start (box, widget,
- TRUE, TRUE, 0);
+ gtk_box_pack_start (box, widget, TRUE, TRUE, 0);
+ gtk_widget_show (widget);
+
+ }
- } else if (puri->write_func) {
+ if ((!puri->is_attachment && puri->write_func) || (puri->is_attachment && puri->write_func && puri->widget_func)) {
web_view = mail_display_setup_webview (display);
- display->widgets = g_list_append (display->widgets, GTK_WIDGET (web_view));
- gtk_box_pack_start (box, GTK_WIDGET (web_view),
- TRUE, TRUE, 0);
+ mail_display_insert_web_view (display, web_view, TRUE);
e_web_view_load_uri (web_view, uri);
+
+ if (widget) {
+ g_object_bind_property (widget, "expanded",
+ web_view, "visible", G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
+ }
+
}
g_free (uri);
}
- gtk_widget_show_all (display->priv->vbox);
+ /* Don't display EAttachmentBar if it's empty. */
+ if (attachment_store && e_attachment_store_get_num_attachments (attachment_store) == 0)
+ gtk_widget_hide (attachment_bar);
}
void
diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c
index 52da1c5..6d5d5fb 100644
--- a/mail/em-format-html-display.c
+++ b/mail/em-format-html-display.c
@@ -404,6 +404,7 @@ efhd_parse_attachment (EMFormat *emf,
puri->attachment = e_attachment_new ();
puri->attachment_view_part_id = g_strdup (classid);
puri->description = html;
+ puri->handle = info->handler;
cid = camel_mime_part_get_content_id (part);
if (cid)
@@ -902,7 +903,6 @@ efhd_attachment_button (EMFormat *emf,
GFileInfo *finfo;
const gchar *name;
GtkWidget *widget;
- GtkWidget *box;
gpointer parent;
guint32 size = 0;
@@ -964,32 +964,11 @@ efhd_attachment_button (EMFormat *emf,
e_attachment_set_file_info (info->attachment, fileinfo);
}
- box = gtk_hbox_new (FALSE, 5);
- gtk_widget_show (box);
-
widget = e_attachment_button_new (efhd->priv->attachment_view);
e_attachment_button_set_attachment (
E_ATTACHMENT_BUTTON (widget), attachment);
gtk_widget_set_can_focus (widget, TRUE);
gtk_widget_show (widget);
- gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 5);
-
- finfo = e_attachment_get_file_info (info->attachment);
- name = NULL;
- if (finfo)
- name = g_file_info_get_display_name (finfo);
-
- if (name == NULL)
- name = _("attachment.dat");
-
- widget = gtk_label_new (name);
- gtk_widget_show (widget);
- gtk_box_pack_start (GTK_BOX (box), widget, FALSE, FALSE, 5);
-
- /* Makes the EAttachmentButton and label with name to be aligned to left */
- widget = gtk_label_new ("");
- gtk_widget_show (widget);
- gtk_box_pack_start (GTK_BOX (box), widget, TRUE, TRUE, 5);
/* FIXME Not sure why the expanded callback can't just use
* info->puri.format, but there seems to be lifecycle
@@ -997,7 +976,7 @@ efhd_attachment_button (EMFormat *emf,
* a reference count? */
g_object_set_data (G_OBJECT (widget), "efh", efh);
- return box;
+ return widget;
}
static GtkWidget*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]