* <many>: updates for new MIME-part handling
This commit is contained in:
@ -37,6 +37,8 @@ libmuwidgets_la_SOURCES= \
|
||||
mu-msg-attach-view.h \
|
||||
mu-msg-body-view.c \
|
||||
mu-msg-body-view.h \
|
||||
mu-msg-header-view.c \
|
||||
mu-msg-header-view.h \
|
||||
mu-msg-view.h \
|
||||
mu-msg-view.c
|
||||
|
||||
|
||||
@ -129,7 +129,11 @@ mu_msg_attach_view_init (MuMsgAttachView *obj)
|
||||
static void
|
||||
mu_msg_attach_view_finalize (GObject *obj)
|
||||
{
|
||||
mu_msg_unref (MU_MSG_ATTACH_VIEW(obj)->_priv->_msg);
|
||||
MuMsg *msg;
|
||||
|
||||
msg = MU_MSG_ATTACH_VIEW(obj)->_priv->_msg;
|
||||
if (msg)
|
||||
mu_msg_unref (msg);
|
||||
|
||||
G_OBJECT_CLASS(parent_class)->finalize (obj);
|
||||
}
|
||||
@ -149,7 +153,7 @@ typedef struct _CBData CBData;
|
||||
|
||||
|
||||
static void
|
||||
each_part (MuMsgPart *part, CBData *cbdata)
|
||||
each_part (MuMsg *msg, MuMsgPart *part, CBData *cbdata)
|
||||
{
|
||||
GtkTreeIter treeiter;
|
||||
GdkPixbuf *pixbuf;
|
||||
@ -180,7 +184,7 @@ each_part (MuMsgPart *part, CBData *cbdata)
|
||||
-1);
|
||||
if (pixbuf)
|
||||
g_object_unref (pixbuf);
|
||||
|
||||
|
||||
++cbdata->count;
|
||||
}
|
||||
|
||||
@ -206,7 +210,7 @@ mu_msg_attach_view_set_message (MuMsgAttachView *self, MuMsg *msg)
|
||||
|
||||
cbdata.store = store;
|
||||
cbdata.count = 0;
|
||||
mu_msg_msg_part_foreach (msg, (MuMsgPartForeachFunc)each_part, &cbdata);
|
||||
mu_msg_part_foreach (msg, (MuMsgPartForeachFunc)each_part, &cbdata);
|
||||
|
||||
return cbdata.count;
|
||||
}
|
||||
|
||||
@ -18,8 +18,8 @@
|
||||
*/
|
||||
#include <webkit/webkitwebview.h>
|
||||
#include "mu-msg-body-view.h"
|
||||
#include <mu-msg-part.h>
|
||||
|
||||
/* include other impl specific header files */
|
||||
|
||||
/* 'private'/'protected' functions */
|
||||
static void mu_msg_body_view_class_init (MuMsgBodyViewClass *klass);
|
||||
@ -35,6 +35,7 @@ enum {
|
||||
|
||||
struct _MuMsgBodyViewPrivate {
|
||||
WebKitWebSettings *_settings;
|
||||
MuMsg *_message;
|
||||
};
|
||||
#define MU_MSG_BODY_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
|
||||
MU_TYPE_MSG_BODY_VIEW, \
|
||||
@ -66,11 +67,72 @@ mu_msg_body_view_class_init (MuMsgBodyViewClass *klass)
|
||||
/* etc. */
|
||||
}
|
||||
|
||||
|
||||
|
||||
static char*
|
||||
save_file_for_cid (MuMsg *msg, const char* cid)
|
||||
{
|
||||
gint idx;
|
||||
gchar *filepath;
|
||||
gboolean rv;
|
||||
|
||||
g_return_val_if_fail (msg, NULL);
|
||||
g_return_val_if_fail (cid, NULL);
|
||||
|
||||
idx = mu_msg_part_find_cid (msg, cid);
|
||||
if (idx < 0) {
|
||||
g_warning ("%s: cannot find %s", __FUNCTION__, cid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
filepath = mu_msg_part_filepath_cache (msg, idx);
|
||||
if (!filepath) {
|
||||
g_warning ("%s: cannot create filepath", filepath);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rv = mu_msg_part_save (msg, filepath, idx, FALSE, TRUE);
|
||||
if (!rv) {
|
||||
g_warning ("%s: failed to save %s", __FUNCTION__, filepath);
|
||||
g_free (filepath);
|
||||
filepath = NULL;
|
||||
}
|
||||
|
||||
return filepath;
|
||||
}
|
||||
|
||||
static void
|
||||
on_resource_request_starting (MuMsgBodyView *self, WebKitWebFrame *frame,
|
||||
WebKitWebResource *resource, WebKitNetworkRequest *request,
|
||||
WebKitNetworkResponse *response, gpointer data)
|
||||
{
|
||||
const char* uri;
|
||||
MuMsg *msg;
|
||||
|
||||
msg = self->_priv->_message;
|
||||
uri = webkit_network_request_get_uri (request);
|
||||
|
||||
if (g_ascii_strncasecmp (uri, "cid:", 4) == 0) {
|
||||
gchar *filepath;
|
||||
filepath = save_file_for_cid (msg, uri + 4);
|
||||
if (filepath) {
|
||||
gchar *fileuri;
|
||||
fileuri = g_strdup_printf ("file://%s", filepath);
|
||||
webkit_network_request_set_uri (request, fileuri);
|
||||
g_free (fileuri);
|
||||
g_free (filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
mu_msg_body_view_init (MuMsgBodyView *obj)
|
||||
{
|
||||
obj->_priv = MU_MSG_BODY_VIEW_GET_PRIVATE(obj);
|
||||
|
||||
obj->_priv->_message = NULL;
|
||||
|
||||
obj->_priv->_settings = webkit_web_settings_new ();
|
||||
g_object_set (G_OBJECT(obj->_priv->_settings),
|
||||
"enable-scripts", FALSE,
|
||||
@ -81,7 +143,9 @@ mu_msg_body_view_init (MuMsgBodyView *obj)
|
||||
webkit_web_view_set_settings (WEBKIT_WEB_VIEW(obj),
|
||||
obj->_priv->_settings);
|
||||
webkit_web_view_set_editable (WEBKIT_WEB_VIEW(obj), FALSE);
|
||||
/* other settings */
|
||||
|
||||
g_signal_connect (obj, "resource-request-starting",
|
||||
G_CALLBACK (on_resource_request_starting), NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -92,6 +156,9 @@ mu_msg_body_view_finalize (GObject *obj)
|
||||
priv = MU_MSG_BODY_VIEW_GET_PRIVATE(obj);
|
||||
if (priv && priv->_settings)
|
||||
g_object_unref (priv->_settings);
|
||||
|
||||
if (priv->_message)
|
||||
mu_msg_unref (priv->_message);
|
||||
|
||||
G_OBJECT_CLASS(parent_class)->finalize (obj);
|
||||
}
|
||||
@ -104,7 +171,7 @@ mu_msg_body_view_new (void)
|
||||
|
||||
|
||||
void
|
||||
mu_msg_body_view_set_html (MuMsgBodyView *self, const char* html)
|
||||
set_html (MuMsgBodyView *self, const char* html)
|
||||
{
|
||||
g_return_if_fail (MU_IS_MSG_BODY_VIEW(self));
|
||||
|
||||
@ -115,8 +182,8 @@ mu_msg_body_view_set_html (MuMsgBodyView *self, const char* html)
|
||||
"");
|
||||
}
|
||||
|
||||
void
|
||||
mu_msg_body_view_set_text (MuMsgBodyView *self, const char* txt)
|
||||
static void
|
||||
set_text (MuMsgBodyView *self, const char* txt)
|
||||
{
|
||||
g_return_if_fail (MU_IS_MSG_BODY_VIEW(self));
|
||||
|
||||
@ -126,3 +193,23 @@ mu_msg_body_view_set_text (MuMsgBodyView *self, const char* txt)
|
||||
"utf-8",
|
||||
"");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mu_msg_body_view_set_message (MuMsgBodyView *self, MuMsg *msg)
|
||||
{
|
||||
const char* data;
|
||||
|
||||
g_return_if_fail (self);
|
||||
|
||||
if (self->_priv->_message)
|
||||
mu_msg_unref (self->_priv->_message);
|
||||
|
||||
self->_priv->_message = msg ? mu_msg_ref (msg) : NULL;
|
||||
|
||||
data = msg ? mu_msg_get_body_html (msg) : "";
|
||||
if (data)
|
||||
set_html (self, data);
|
||||
else
|
||||
set_text (self, mu_msg_get_body_text (msg));
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
#define __MU_MSG_BODY_VIEW_H__
|
||||
|
||||
#include <webkit/webkitwebview.h>
|
||||
#include <mu-msg.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -57,8 +58,8 @@ GType mu_msg_body_view_get_type (void) G_GNUC_CONST;
|
||||
/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */
|
||||
GtkWidget* mu_msg_body_view_new (void);
|
||||
|
||||
void mu_msg_body_view_set_html (MuMsgBodyView *self, const char* html);
|
||||
void mu_msg_body_view_set_text (MuMsgBodyView *self, const char* html);
|
||||
void mu_msg_body_view_set_message (MuMsgBodyView *self, MuMsg *msg);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
@ -20,7 +20,10 @@
|
||||
#include "mu-msg-view.h"
|
||||
#include "mu-msg-body-view.h"
|
||||
#include "mu-msg-attach-view.h"
|
||||
#include "mu-msg.h"
|
||||
#include "mu-msg-header-view.h"
|
||||
|
||||
#include <mu-msg.h>
|
||||
#include <mu-msg-part.h>
|
||||
|
||||
/* 'private'/'protected' functions */
|
||||
static void mu_msg_view_class_init (MuMsgViewClass *klass);
|
||||
@ -35,6 +38,7 @@ enum {
|
||||
};
|
||||
|
||||
struct _MuMsgViewPrivate {
|
||||
GtkWidget *_headers;
|
||||
GtkWidget *_body;
|
||||
GtkWidget *_attach, *_attacharea;
|
||||
};
|
||||
@ -71,41 +75,75 @@ mu_msg_view_class_init (MuMsgViewClass *klass)
|
||||
static void
|
||||
on_attach_activated (MuMsgView *self, guint partnum, MuMsg *msg)
|
||||
{
|
||||
char *tmpdir;
|
||||
|
||||
tmpdir = mu_util_create_tmpdir ();
|
||||
if (!tmpdir)
|
||||
return;
|
||||
|
||||
mu_msg_mime_part_save (msg, partnum, tmpdir, FALSE, TRUE);
|
||||
g_free (tmpdir);
|
||||
gchar* filepath;
|
||||
|
||||
filepath = mu_msg_part_filepath_cache (msg, partnum);
|
||||
if (filepath) {
|
||||
mu_msg_part_save (msg, filepath, partnum, FALSE, TRUE);
|
||||
mu_util_play (filepath);
|
||||
g_free (filepath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
mu_msg_view_init (MuMsgView *obj)
|
||||
static GtkWidget*
|
||||
get_header_widget (MuMsgView *self)
|
||||
{
|
||||
return self->_priv->_headers = mu_msg_header_view_new ();
|
||||
}
|
||||
|
||||
|
||||
static GtkWidget*
|
||||
get_body_widget (MuMsgView *self)
|
||||
{
|
||||
GtkWidget *scrolledwin;
|
||||
|
||||
obj->_priv = MU_MSG_VIEW_GET_PRIVATE(obj);
|
||||
|
||||
obj->_priv->_body = mu_msg_body_view_new ();
|
||||
self->_priv->_body = mu_msg_body_view_new ();
|
||||
scrolledwin = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_container_add (GTK_CONTAINER(scrolledwin),
|
||||
obj->_priv->_body);
|
||||
gtk_box_pack_start (GTK_BOX(obj), scrolledwin,
|
||||
TRUE, TRUE, 2);
|
||||
self->_priv->_body);
|
||||
|
||||
obj->_priv->_attacharea = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(obj->_priv->_attacharea),
|
||||
GTK_POLICY_NEVER,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
obj->_priv->_attach = mu_msg_attach_view_new ();
|
||||
gtk_container_add (GTK_CONTAINER(obj->_priv->_attacharea), obj->_priv->_attach);
|
||||
return scrolledwin;
|
||||
}
|
||||
|
||||
g_signal_connect (obj->_priv->_attach, "attach-activated",
|
||||
static GtkWidget*
|
||||
get_attach_widget (MuMsgView *self)
|
||||
{
|
||||
/* GtkWidget *scrolledwin; */
|
||||
|
||||
self->_priv->_attacharea = gtk_frame_new ("");
|
||||
/* scrolledwin = gtk_scrolled_window_new (NULL, NULL); */
|
||||
/* gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scrolledwin), */
|
||||
/* GTK_POLICY_NEVER, */
|
||||
/* GTK_POLICY_AUTOMATIC); */
|
||||
|
||||
self->_priv->_attach = mu_msg_attach_view_new ();
|
||||
gtk_container_add (GTK_CONTAINER(self->_priv->_attacharea),
|
||||
self->_priv->_attach);
|
||||
|
||||
g_signal_connect (self->_priv->_attach, "attach-activated",
|
||||
G_CALLBACK(on_attach_activated),
|
||||
obj);
|
||||
self);
|
||||
|
||||
return self->_priv->_attacharea;
|
||||
}
|
||||
|
||||
static void
|
||||
mu_msg_view_init (MuMsgView *self)
|
||||
{
|
||||
self->_priv = MU_MSG_VIEW_GET_PRIVATE(self);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX(self), get_header_widget (self),
|
||||
FALSE, FALSE, 2);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX(self), get_attach_widget (self),
|
||||
FALSE, FALSE, 2);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX(self), get_body_widget (self),
|
||||
TRUE, TRUE, 2);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
@ -123,55 +161,31 @@ mu_msg_view_new (void)
|
||||
|
||||
|
||||
static void
|
||||
add_attachment_area_maybe (MuMsgView *self, MuMsg *msg)
|
||||
update_attachment_area (MuMsgView *self, MuMsg *msg)
|
||||
{
|
||||
gint attach_num;
|
||||
GList *children, *cur;
|
||||
gboolean has_area;
|
||||
|
||||
has_area = FALSE;
|
||||
cur = children = gtk_container_get_children (GTK_CONTAINER(self));
|
||||
while (cur) {
|
||||
if (cur->data == self->_priv->_attacharea) {
|
||||
has_area = TRUE;
|
||||
break;
|
||||
}
|
||||
cur = g_list_next (cur);
|
||||
}
|
||||
g_list_free (children);
|
||||
|
||||
|
||||
attach_num = 0;
|
||||
if (msg)
|
||||
attach_num = mu_msg_attach_view_set_message
|
||||
(MU_MSG_ATTACH_VIEW(self->_priv->_attach), msg);
|
||||
|
||||
if (attach_num < 1 && has_area) {
|
||||
g_object_ref (self->_priv->_attacharea);
|
||||
gtk_container_remove (GTK_CONTAINER(self),
|
||||
self->_priv->_attacharea);
|
||||
} else if (attach_num >= 1 && !has_area) {
|
||||
gtk_box_pack_start (GTK_BOX(self), self->_priv->_attacharea,
|
||||
FALSE, FALSE, 0);
|
||||
if (attach_num > 0)
|
||||
gtk_widget_show_all (self->_priv->_attacharea);
|
||||
}
|
||||
else
|
||||
gtk_widget_hide_all (self->_priv->_attacharea);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mu_msg_view_set_message (MuMsgView *self, MuMsg *msg)
|
||||
{
|
||||
const char *data;
|
||||
|
||||
{
|
||||
g_return_if_fail (MU_IS_MSG_VIEW(self));
|
||||
|
||||
mu_msg_header_view_set_message (MU_MSG_HEADER_VIEW(self->_priv->_headers),
|
||||
msg);
|
||||
mu_msg_body_view_set_message (MU_MSG_BODY_VIEW(self->_priv->_body),
|
||||
msg);
|
||||
|
||||
data = msg ? mu_msg_get_body_html (msg) : "";
|
||||
if (data)
|
||||
mu_msg_body_view_set_html (MU_MSG_BODY_VIEW(self->_priv->_body),
|
||||
data);
|
||||
else
|
||||
mu_msg_body_view_set_text (MU_MSG_BODY_VIEW(self->_priv->_body),
|
||||
mu_msg_get_body_text (msg));
|
||||
|
||||
add_attachment_area_maybe (self, msg);
|
||||
update_attachment_area (self, msg);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user