[anjal] Make possibility to chose the web renderer for mail on runtime. Default
- From: Srinivasa Ragavan <sragavan src gnome org>
- To: svn-commits-list gnome org
- Subject: [anjal] Make possibility to chose the web renderer for mail on runtime. Default
- Date: Fri, 17 Apr 2009 04:20:24 -0400 (EDT)
commit 74ba7783fd4032819a256103456b537c7ce65688
Author: Srinivasa Ragavan <sragavan novell com>
Date: Fri Apr 17 13:48:51 2009 +0530
Make possibility to chose the web renderer for mail on runtime. Default
on webkit.
---
src/Makefile.am | 24 ++++++--
src/em-format-webkit-display.c | 9 +--
src/em-format-webkit.c | 31 +++++++---
src/em-format-webkit.h | 9 +++
src/em-webkit-stream.c | 10 +++-
src/em-webkit-stream.h | 14 +----
src/mail-message-view.c | 126 ++++++++++++++++++++++++++++++++++++---
src/mail-message-view.h | 5 +-
8 files changed, 186 insertions(+), 42 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index 3d84bae..73d12f0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,7 +7,9 @@ AM_CPPFLAGS = \
-DPACKAGE_DATA_DIR=\""$(datadir)"\" \
-DEVOLUTION_PRIVDATADIR=\""$(datadir)/evolution/2.24/"\" \
-DANJAL_IMAGEDIR=\""$(datadir)/anjal/images/"\" \
- $(ANJAL_CFLAGS) -I.
+ $(ANJAL_CFLAGS) -I. \
+ $(MOZILLA_CFLAGS) \
+ $(WEBKIT_CFLAGS)
AM_CFLAGS =\
-Wall\
@@ -54,18 +56,30 @@ anjal_SOURCES = \
em-format-webkit.h \
em-format-webkit-display.c \
em-format-webkit-display.h \
- em-webkit-stream.c \
- em-webkit-stream.h \
- gconf-bridge.h
+ gconf-bridge.h
+if ENABLE_WEBKIT
+anjal_SOURCES += em-webkit-stream.c \
+ em-webkit-stream.h
+endif
+
+if ENABLE_MOZILLA
+anjal_SOURCES += em-mozembed-stream.c \
+ em-mozembed-stream.h
+MOZ_ADD_LIBS = -lmozjs
+else
+MOZ_ADD_LIBS =
+endif
anjal_LDFLAGS = \
-Wl,--export-dynamic
anjal_LDADD = $(ANJAL_LIBS) \
+ $(MOZILLA_LIBS) \
+ $(WEBKIT_LIBS) \
-lemiscwidgets \
-lfilter \
- -L$(evolutioncomponentdir) -levolution-mail-shared
+ -L$(evolutioncomponentdir) -levolution-mail-shared $(MOZ_ADD_LIBS)
EXTRA_DIST = $(glade_DATA)
diff --git a/src/em-format-webkit-display.c b/src/em-format-webkit-display.c
index 2a48d83..ac0a56b 100644
--- a/src/em-format-webkit-display.c
+++ b/src/em-format-webkit-display.c
@@ -79,7 +79,6 @@
#include "mail/em-popup.h"
#include <misc/e-attachment.h>
#include <misc/e-icon-entry.h>
-#include "em-webkit-stream.h"
#include "mail-message-view.h"
#ifdef G_OS_WIN32
@@ -1246,7 +1245,7 @@ efwd_format_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, Came
pobj = (struct _smime_pobject *)em_format_webkit_add_pobject((EMFormatWebKit *)emf, sizeof(*pobj), classid, part, efwd_xpkcs7mime_button);
pobj->valid = camel_cipher_validity_clone(valid);
pobj->object.free = efwd_xpkcs7mime_free;
- pobj->object.body = ((EMWebKitStream *)stream)->body;
+ pobj->object.body = mail_message_view_get_body(stream);
efwd_draw_in_main_thread (emf, pobj);
g_free(classid);
}
@@ -1275,7 +1274,7 @@ efwd_image(EMFormatWebKit *efh, CamelStream *stream, CamelMimePart *part, EMForm
}
info->pobject = pobject;
- pobject->body = ((EMWebKitStream *)stream)->body;
+ pobject->body = mail_message_view_get_body(stream);
efwd_draw_in_main_thread (efh, pobject);
@@ -2198,7 +2197,7 @@ efwd_format_attachment(EMFormat *emf, CamelStream *stream, CamelMimePart *part,
pobj = em_format_webkit_add_pobject((EMFormatWebKit *)emf, sizeof(EMFormatWebKitPObject), classid, part, efwd_attachment_button);
info->pobject = pobj;
- pobj->body = ((EMWebKitStream *)stream)->body;
+ pobj->body = mail_message_view_get_body (stream);
efwd_draw_in_main_thread (emf, pobj);
/*
camel_stream_write_string(stream,
@@ -2254,7 +2253,7 @@ preview_message_exec (struct _preview_message_msg *m)
EMFormatWebKitPObject *pobj = m->pobject;
pobj->view = (gpointer) pobj->func(pobj->format, (gpointer)pobj->body, pobj);
if (pobj->view) {
- pobj->stream = em_webkit_stream_new (mail_message_view_create_webview(((EMFormatWebKit *)pobj->format)->msg_view, pobj->view), pobj->view);
+ pobj->stream = mail_message_view_create_webstream (mail_message_view_create_webview(((EMFormatWebKit *)pobj->format)->msg_view, pobj->view), pobj->view);
gtk_widget_show_all (pobj->view);
}
e_flag_set (m->done);
diff --git a/src/em-format-webkit.c b/src/em-format-webkit.c
index 91117fc..40b2f5f 100644
--- a/src/em-format-webkit.c
+++ b/src/em-format-webkit.c
@@ -76,7 +76,14 @@
#include "mail/em-inline-filter.h"
#include "em-format-webkit.h"
+#if HAVE_WEBKIT
#include "em-webkit-stream.h"
+#endif
+
+#if HAVE_MOZILLA
+#include "em-mozembed-stream.h"
+#endif
+
#include "mail/em-utils.h"
#include "mail-message-view.h"
@@ -988,7 +995,7 @@ struct _format_msg {
EMFormatWebKit *format;
EMFormat *format_source;
- EMWebKitStream *estream;
+ CamelStream *estream;
CamelFolder *folder;
char *uid;
CamelMimeMessage *message;
@@ -1010,8 +1017,17 @@ efw_format_exec (struct _format_msg *m)
camel_stream_printf((CamelStream *)m->estream,
"<!doctype html public \"-//W3C//DTD HTML 4.0 TRANSITIONAL//EN\">\n<html>\n"
- "<head>\n<meta name=\"generator\" content=\"Evolution Mail Component\">\n</head>\n"
- "<body bgcolor =\"#%06x\" text=\"#%06x\" marginwidth=6 marginheight=6>\n",
+ "<head>\n<meta name=\"generator\" content=\"Evolution Mail Component\">\n"
+ "<script language=\"JavaScript\"><!--"
+ "function height() {"
+ " if (document.all) "
+ " alert('Document height = ' + document.body.offsetHeight);"
+ " else if (document.layers)"
+ " alert('Document height = ' + document.body.document.height);"
+ " }"
+ "//--></script> "
+ "</head>\n"
+ "<body onLoad=\"height()\" bgcolor =\"#%06x\" text=\"#%06x\" marginwidth=6 marginheight=6>\n",
m->format->body_colour & 0xffffff,
m->format->header_colour & 0xffffff);
@@ -1145,13 +1161,12 @@ efw_format_timeout(struct _format_msg *m)
p->last_part = NULL;
} else {
efw->state = EM_FORMAT_WEBKIT_STATE_RENDERING;
-
- m->estream = (EMWebKitStream *)em_webkit_stream_new(mail_message_view_create_webview (efw->msg_view, efw->body), efw->body);
+ m->estream = mail_message_view_create_webstream(mail_message_view_create_webview (efw->msg_view, efw->body), efw->body);
if (p->last_part == m->message) {
- em_webkit_stream_set_flags (m->estream,
- WEBKIT_BEGIN_KEEP_SCROLL | WEBKIT_BEGIN_KEEP_IMAGES
- | WEBKIT_BEGIN_BLOCK_UPDATES | WEBKIT_BEGIN_BLOCK_IMAGES);
+ mail_message_view_set_web_flags (m->estream,
+ WEB_BEGIN_KEEP_SCROLL | WEB_BEGIN_KEEP_IMAGES
+ | WEB_BEGIN_BLOCK_UPDATES | WEB_BEGIN_BLOCK_IMAGES);
} else {
/* clear cache of inline-scanned text parts */
g_hash_table_remove_all(p->text_inline_parts);
diff --git a/src/em-format-webkit.h b/src/em-format-webkit.h
index 7949e61..cae7d45 100644
--- a/src/em-format-webkit.h
+++ b/src/em-format-webkit.h
@@ -42,6 +42,15 @@ struct _CamelMimePart;
struct _CamelMedium;
struct _CamelStream;
+typedef enum {
+ WEB_BEGIN_KEEP_SCROLL = 1 << 0,
+ WEB_BEGIN_KEEP_IMAGES = 1 << 1,
+ WEB_BEGIN_BLOCK_UPDATES = 1 << 2,
+ WEB_BEGIN_BLOCK_IMAGES = 1 << 3,
+ /*enable autochange content_type*/
+ WEB_BEGIN_CHANGECONTENTTYPE = 1 << 4
+} WebBeginFlags;
+
enum _em_format_webkit_header_flags {
EM_FORMAT_WEBKIT_HEADER_TO = 1<<0,
EM_FORMAT_WEBKIT_HEADER_CC = 1<<1,
diff --git a/src/em-webkit-stream.c b/src/em-webkit-stream.c
index 636734c..79016d0 100644
--- a/src/em-webkit-stream.c
+++ b/src/em-webkit-stream.c
@@ -112,7 +112,7 @@ static int
emws_sync_close(CamelStream *stream)
{
EMWebKitStream *emws = (EMWebKitStream *)stream;
-
+ gtk_widget_set_size_request (emws->view, -1, webkit_web_frame_get_height(webkit_web_view_get_main_frame(emws->view)));
return 0;
}
@@ -132,7 +132,13 @@ em_webkit_stream_new(WebKitWebView *view, GtkWidget *body)
}
void
-em_webkit_stream_set_flags (EMWebKitStream *emws, WebKitBeginFlags flags)
+em_webkit_stream_set_flags (EMWebKitStream *emws, int flags)
{
emws->flags = flags;
}
+
+GtkWidget *
+em_webkit_stream_get_body (EMWebKitStream *emws)
+{
+ return emws->body;
+}
diff --git a/src/em-webkit-stream.h b/src/em-webkit-stream.h
index 9dca20f..73fa0d7 100644
--- a/src/em-webkit-stream.h
+++ b/src/em-webkit-stream.h
@@ -37,15 +37,6 @@ extern "C" {
#include "mail/em-sync-stream.h"
#include <webkit/webkit.h>
-typedef enum {
- WEBKIT_BEGIN_KEEP_SCROLL = 1 << 0,
- WEBKIT_BEGIN_KEEP_IMAGES = 1 << 1,
- WEBKIT_BEGIN_BLOCK_UPDATES = 1 << 2,
- WEBKIT_BEGIN_BLOCK_IMAGES = 1 << 3,
- /*enable autochange content_type*/
- WEBKIT_BEGIN_CHANGECONTENTTYPE = 1 << 4
-} WebKitBeginFlags;
-
typedef struct _EMWebKitStream {
EMSyncStream sync;
@@ -53,7 +44,7 @@ typedef struct _EMWebKitStream {
GtkWidget *body;
guint destroy_id;
GString *buffer;
- WebKitBeginFlags flags;
+ int flags;
} EMWebKitStream;
typedef struct {
@@ -65,7 +56,8 @@ typedef struct {
CamelType em_webkit_stream_get_type (void);
CamelStream *em_webkit_stream_new(WebKitWebView *, GtkWidget *);
-void em_webkit_stream_set_flags (EMWebKitStream *emhs, WebKitBeginFlags flags);
+void em_webkit_stream_set_flags (EMWebKitStream *emhs, int flags);
+GtkWidget * em_webkit_stream_get_body (EMWebKitStream *emws);
#ifdef __cplusplus
}
diff --git a/src/mail-message-view.c b/src/mail-message-view.c
index f237dc9..9ade1ec 100644
--- a/src/mail-message-view.c
+++ b/src/mail-message-view.c
@@ -25,7 +25,14 @@
#endif
#include <glib/gi18n.h>
#include "mail-message-view.h"
+#if HAVE_WEBKIT
#include <webkit/webkit.h>
+#include "em-webkit-stream.h"
+#endif
+#if HAVE_MOZILLA
+#include <gtkmozembed.h>
+#include "em-mozembed-stream.h"
+#endif
#include "mail/mail-session.h"
#include "mail/mail-ops.h"
#include "e-msg-composer.h"
@@ -63,6 +70,7 @@ enum {
LAST_SIGNAL
};
+
static guint signals[LAST_SIGNAL] = { 0 };
static const char *norm_color = "#d3d7cf";
@@ -431,23 +439,30 @@ mark_mail_read (GtkWidget *w, GdkEventExpose *event, MailMessageView *mmv)
return FALSE;
}
+#if HAVE_WEBKIT
static void
-mmv_finished (WebKitWebView *webkitwebview, WebKitWebFrame *arg1, gpointer user_data)
+mmv_finished_webkit (WebKitWebView *webkitwebview, WebKitWebFrame *arg1, gpointer user_data)
{
MailMessageView *mmview = (MailMessageView *) user_data;
- gtk_widget_set_size_request (webkitwebview, -1, webkit_web_frame_get_height(arg1));
+ //gtk_widget_set_size_request (webkitwebview, -1, webkit_web_frame_get_height(arg1));
/* Connect on expose, and mark mail as read on expose, when the mail is actually seen */
g_signal_connect (webkitwebview, "expose-event" , mark_mail_read, mmview);
g_signal_emit (mmview, signals[MESSAGE_LOADED], 0);
}
+#endif
-static void
-mmv_loaded (WebKitWebView *webkitwebview, WebKitWebFrame *arg1, gpointer user_data)
+#if HAVE_MOZILLA
+static gboolean
+mmv_finished_mozilla (GtkWidget *w, MailMessageView *mmv)
{
- gtk_widget_set_size_request (webkitwebview, -1, webkit_web_frame_get_height(arg1));
+ g_signal_connect (w, "expose-event" , mark_mail_read, mmv);
+ g_signal_emit (mmv, signals[MESSAGE_LOADED], 0);
+
+ return FALSE;
}
+#endif
#define RADIUS 8
@@ -623,20 +638,112 @@ mmv_sh_color_expose (GtkWidget *w, GdkEventExpose *event, MailMessageView *mmv)
}
+#if HAVE_WEBKIT
GtkWidget *
-mail_message_view_create_webview (MailMessageView *mmv, GtkWidget *box)
+mmv_create_webview (MailMessageView *mmv, GtkWidget *box)
{
WebKitWebView *web = webkit_web_view_new ();
- g_signal_connect (web, "load-finished", G_CALLBACK(mmv_finished), mmv);
- g_signal_connect (web, "load-committed", G_CALLBACK(mmv_loaded), mmv);
- g_signal_connect (web, "load-started", G_CALLBACK(mmv_loaded), mmv);
+ g_signal_connect (web, "load-finished", G_CALLBACK(mmv_finished_webkit), mmv);
gtk_box_pack_start (box, web, FALSE, FALSE, 0);
webkit_web_view_set_editable (web, FALSE);
gtk_widget_show (web);
+
+ return web;
+}
+#endif
+
+#if HAVE_MOZILLA
+GtkWidget *
+mmv_create_mozview (MailMessageView *mmv, GtkWidget *box)
+{
+ GtkWidget *web;
+ web = gtk_moz_embed_new ();
+
+ g_signal_connect (web, "net_stop", mmv_finished_mozilla, mmv);
+
+ gtk_box_pack_start (box, web, TRUE, TRUE, 0);
+ gtk_widget_show (web);
+
return web;
}
+#endif
+
+typedef struct {
+ const char *renderer;
+ GtkWidget * (*create_web_view) (MailMessageView *, GtkWidget *);
+ void (*set_web_flags) (gpointer, int);
+ CamelStream * (*create_web_stream) (gpointer , GtkWidget *);
+ GtkWidget *(*get_body) (CamelStream *);
+}MailRenderer;
+
+static MailRenderer web_renderers[] = {
+#if HAVE_WEBKIT
+ { "webkit", mmv_create_webview , em_webkit_stream_set_flags, em_webkit_stream_new, em_webkit_stream_get_body},
+#endif
+#if HAVE_MOZILLA
+ { "mozilla", mmv_create_mozview, em_mozembed_stream_set_flags, em_mozembed_stream_new, em_mozembed_stream_get_body},
+#endif
+};
+
+static MailRenderer *current_renderer = NULL;
+
+static MailRenderer *
+get_current_renderer()
+{
+ if (!current_renderer) {
+ int i, len = G_N_ELEMENTS (web_renderers);
+ char *rend = g_getenv("ANJAL_RENDERER");
+
+ if (len == 0)
+ g_assert(0);
+
+ for(i=0; i<len && rend; i++) {
+ if(strcmp(rend, web_renderers[i].renderer) == 0) {
+ current_renderer = &web_renderers[i];
+ break;
+ }
+ }
+ if (!current_renderer) {
+ g_warning("Unable to find requested renderer, using the first one as default\n");
+ current_renderer = &web_renderers[0];
+ }
+ }
+
+ return current_renderer;
+}
+GtkWidget *
+mail_message_view_create_webview (MailMessageView *mmv, GtkWidget *box)
+{
+ MailRenderer *render = get_current_renderer();
+
+ return render->create_web_view(mmv, box);
+}
+
+GtkWidget *
+mail_message_view_get_body (CamelStream *stream)
+{
+ MailRenderer *render = get_current_renderer();
+
+ render->get_body(stream);
+}
+
+CamelStream *
+mail_message_view_create_webstream (gpointer web, GtkWidget *w)
+{
+ MailRenderer *render = get_current_renderer();
+
+ return render->create_web_stream(web, w);
+}
+
+void
+mail_message_view_set_web_flags (gpointer web, int flags)
+{
+ MailRenderer *render = get_current_renderer();
+
+ render->set_web_flags(web, flags);
+}
#define EXPOSE(widget,mmv) g_signal_connect (widget, "expose-event", G_CALLBACK (mmv_sh_color_expose), mmv);
@@ -654,7 +761,6 @@ unread_toggled (GtkWidget *w, GdkEventButton *event, MailMessageView *mmv)
gtk_label_set_markup (mmv->sub_details, mmv->priv->normal[0]);
gtk_label_set_markup (mmv->date_details, mmv->priv->normal[1]);
}
-// mmv_invalidate_row (mmv->priv->header_row);
}
static void
diff --git a/src/mail-message-view.h b/src/mail-message-view.h
index 336fed3..6e6785c 100644
--- a/src/mail-message-view.h
+++ b/src/mail-message-view.h
@@ -24,9 +24,9 @@
#define _MAIL_MESSAGE_VIEW_H_
#include <gtk/gtk.h>
-#include <webkit/webkit.h>
#include "em-format-webkit-display.h"
#include "mail-view.h"
+#include <camel/camel-stream.h>
#define MAIL_MESSAGE_VIEW_TYPE (mail_message_view_get_type ())
#define MAIL_MESSAGE_VIEW(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), MAIL_MESSAGE_VIEW_TYPE, MailFolderView))
@@ -70,6 +70,9 @@ typedef struct _MailMessageViewClass {
MailMessageView * mail_message_view_new (void);
void mail_message_view_set_message (MailMessageView *mmview, struct _CamelFolder *folder, const char *uid);
GtkWidget * mail_message_view_create_webview (MailMessageView *mmv, GtkWidget *box);
+CamelStream * mail_message_view_create_webstream (gpointer web, GtkWidget *w);
GtkWidget * mail_message_view_get_focus_widget (MailMessageView *mmv);
gboolean mail_message_view_get_unread (MailMessageView *mmv);
+void mail_message_view_set_web_flags (gpointer web, int flags);
+GtkWidget * mail_message_view_get_body (CamelStream *stream);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]