2011-01-08 11:48:25 +01:00
|
|
|
/*
|
2020-11-28 09:07:13 +01:00
|
|
|
** Copyright (C) 2011-2020 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
2011-01-08 11:48:25 +01:00
|
|
|
**
|
|
|
|
** This program is free software; you can redistribute it and/or modify it
|
|
|
|
** under the terms of the GNU General Public License as published by the
|
|
|
|
** Free Software Foundation; either version 3, or (at your option) any
|
|
|
|
** later version.
|
|
|
|
**
|
|
|
|
** 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 General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program; if not, write to the Free Software Foundation,
|
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2012-03-22 21:37:54 +01:00
|
|
|
#include <config.h>
|
|
|
|
|
2020-11-28 09:07:13 +01:00
|
|
|
#include "mu-msg-view.hh"
|
|
|
|
#include "mu-msg-body-view.hh"
|
|
|
|
#include "mu-msg-header-view.hh"
|
|
|
|
#include "mu-msg-attach-view.hh"
|
|
|
|
#include <utils/mu-util.h>
|
2011-01-08 11:48:25 +01:00
|
|
|
|
2020-11-28 09:07:13 +01:00
|
|
|
#include <mu-msg.hh>
|
|
|
|
#include <mu-msg-part.hh>
|
|
|
|
|
|
|
|
using namespace Mu;
|
2012-03-22 21:37:54 +01:00
|
|
|
|
2011-01-08 11:48:25 +01:00
|
|
|
/* 'private'/'protected' functions */
|
2021-10-20 11:18:15 +02:00
|
|
|
static void mu_msg_view_class_init(MuMsgViewClass* klass);
|
|
|
|
static void mu_msg_view_init(MuMsgView* obj);
|
|
|
|
static void mu_msg_view_finalize(GObject* obj);
|
2011-01-08 11:48:25 +01:00
|
|
|
|
|
|
|
/* list my signals */
|
|
|
|
enum {
|
|
|
|
/* MY_SIGNAL_1, */
|
|
|
|
/* MY_SIGNAL_2, */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _MuMsgViewPrivate {
|
2011-03-07 23:50:24 +01:00
|
|
|
GtkWidget *_headers, *_attach, *_attachexpander, *_body;
|
2021-10-20 11:18:15 +02:00
|
|
|
Mu::MuMsg* _msg;
|
2011-01-08 11:48:25 +01:00
|
|
|
};
|
2021-10-20 11:18:15 +02:00
|
|
|
#define MU_MSG_VIEW_GET_PRIVATE(o) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((o), MU_TYPE_MSG_VIEW, MuMsgViewPrivate))
|
2011-01-08 11:48:25 +01:00
|
|
|
/* globals */
|
2021-10-20 11:18:15 +02:00
|
|
|
static GtkBoxClass* parent_class = NULL;
|
2011-01-08 11:48:25 +01:00
|
|
|
|
|
|
|
/* uncomment the following if you have defined any signals */
|
|
|
|
/* static guint signals[LAST_SIGNAL] = {0}; */
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
G_DEFINE_TYPE(MuMsgView, mu_msg_view, GTK_TYPE_BOX);
|
2011-01-08 11:48:25 +01:00
|
|
|
|
2011-03-15 19:38:26 +01:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
set_message(MuMsgView* self, Mu::MuMsg* msg)
|
2011-03-15 19:38:26 +01:00
|
|
|
{
|
|
|
|
if (self->_priv->_msg == msg)
|
|
|
|
return; /* nothing to todo */
|
2012-03-22 21:37:54 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (self->_priv->_msg) {
|
|
|
|
mu_msg_unref(self->_priv->_msg);
|
2011-03-15 19:38:26 +01:00
|
|
|
self->_priv->_msg = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg)
|
2021-10-20 11:18:15 +02:00
|
|
|
self->_priv->_msg = mu_msg_ref(msg);
|
2011-03-15 19:38:26 +01:00
|
|
|
}
|
|
|
|
|
2011-01-08 11:48:25 +01:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_view_class_init(MuMsgViewClass* klass)
|
2011-01-08 11:48:25 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
GObjectClass* gobject_class;
|
|
|
|
gobject_class = (GObjectClass*)klass;
|
2011-01-08 11:48:25 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
parent_class = (GtkBoxClass*)g_type_class_peek_parent(klass);
|
2011-01-08 11:48:25 +01:00
|
|
|
gobject_class->finalize = mu_msg_view_finalize;
|
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_type_class_add_private(gobject_class, sizeof(MuMsgViewPrivate));
|
2011-01-08 11:48:25 +01:00
|
|
|
|
|
|
|
/* signal definitions go here, e.g.: */
|
2021-10-20 11:18:15 +02:00
|
|
|
/* signals[MY_SIGNAL_1] = */
|
|
|
|
/* g_signal_new ("my_signal_1",....); */
|
|
|
|
/* signals[MY_SIGNAL_2] = */
|
|
|
|
/* g_signal_new ("my_signal_2",....); */
|
|
|
|
/* etc. */
|
2011-01-08 11:48:25 +01:00
|
|
|
}
|
|
|
|
|
2011-01-13 20:43:18 +01:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
on_body_action_requested(GtkWidget* w, const char* action, MuMsgView* self)
|
2011-01-13 20:43:18 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
if (g_strcmp0(action, "view-source") == 0) {
|
2011-01-22 00:46:33 +01:00
|
|
|
if (self->_priv->_msg)
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_view_set_message_source(self, self->_priv->_msg);
|
2011-01-22 00:46:33 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
} else if (g_strcmp0(action, "view-message") == 0) {
|
2011-01-22 00:46:33 +01:00
|
|
|
if (self->_priv->_msg)
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_view_set_message(self, self->_priv->_msg);
|
2012-03-22 21:37:54 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
} else if (g_strcmp0(action, "reindex") == 0)
|
|
|
|
g_warning("reindex");
|
2012-08-01 09:49:41 +02:00
|
|
|
else
|
2021-10-20 11:18:15 +02:00
|
|
|
g_warning("unknown action '%s'", action);
|
2011-01-13 20:43:18 +01:00
|
|
|
}
|
|
|
|
|
2011-03-07 23:50:24 +01:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
on_attach_activated(GtkWidget* w, guint partnum, Mu::MuMsg* msg)
|
2011-01-08 11:48:25 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
gchar* filepath;
|
|
|
|
GError* err;
|
2012-08-01 09:49:41 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
err = NULL;
|
|
|
|
filepath = mu_msg_part_get_cache_path(msg, MU_MSG_OPTION_NONE, partnum, &err);
|
2012-08-01 09:49:41 +02:00
|
|
|
if (!filepath) {
|
2021-10-20 11:18:15 +02:00
|
|
|
g_warning("failed to get cache path: %s",
|
|
|
|
err && err->message ? err->message : "error");
|
|
|
|
g_clear_error(&err);
|
2012-08-01 09:49:41 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-03-22 21:37:54 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
if (!mu_msg_part_save(msg, MU_MSG_OPTION_USE_EXISTING, filepath, partnum, &err)) {
|
|
|
|
g_warning("failed to save %s: %s",
|
|
|
|
filepath,
|
|
|
|
err && err->message ? err->message : "error");
|
|
|
|
g_clear_error(&err);
|
2012-08-01 09:49:41 +02:00
|
|
|
return;
|
2012-03-22 21:37:54 +01:00
|
|
|
|
2012-08-01 09:49:41 +02:00
|
|
|
} else
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_util_play(filepath, TRUE, FALSE, NULL);
|
2012-08-01 09:49:41 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_free(filepath);
|
2011-01-10 23:46:46 +01:00
|
|
|
}
|
2011-01-09 17:56:45 +01:00
|
|
|
|
2011-03-07 23:50:24 +01:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_view_init(MuMsgView* self)
|
2011-01-24 00:01:43 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
gtk_orientable_set_orientation(GTK_ORIENTABLE(self), GTK_ORIENTATION_VERTICAL);
|
2011-03-15 19:38:26 +01:00
|
|
|
|
2013-03-17 15:38:16 +01:00
|
|
|
self->_priv = MU_MSG_VIEW_GET_PRIVATE(self);
|
2019-08-01 21:12:23 +02:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
self->_priv->_msg = NULL;
|
|
|
|
self->_priv->_headers = mu_msg_header_view_new();
|
|
|
|
self->_priv->_attach = mu_msg_attach_view_new();
|
|
|
|
self->_priv->_attachexpander = gtk_expander_new_with_mnemonic("_Attachments");
|
|
|
|
|
|
|
|
gtk_container_add(GTK_CONTAINER(self->_priv->_attachexpander), self->_priv->_attach);
|
|
|
|
g_signal_connect(self->_priv->_attach,
|
|
|
|
"attach-activated",
|
|
|
|
G_CALLBACK(on_attach_activated),
|
|
|
|
self);
|
|
|
|
|
|
|
|
self->_priv->_body = mu_msg_body_view_new();
|
|
|
|
g_signal_connect(self->_priv->_body,
|
|
|
|
"action-requested",
|
|
|
|
G_CALLBACK(on_body_action_requested),
|
|
|
|
self);
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(self), self->_priv->_headers, FALSE, FALSE, 2);
|
|
|
|
gtk_box_pack_start(GTK_BOX(self), self->_priv->_attachexpander, FALSE, FALSE, 2);
|
|
|
|
gtk_box_pack_start(GTK_BOX(self), self->_priv->_body, TRUE, TRUE, 2);
|
2011-01-10 23:46:46 +01:00
|
|
|
}
|
|
|
|
|
2011-03-07 23:50:24 +01:00
|
|
|
static void
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_view_finalize(GObject* obj)
|
2011-03-07 23:50:24 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
set_message(MU_MSG_VIEW(obj), NULL);
|
2011-03-15 19:38:26 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
G_OBJECT_CLASS(parent_class)->finalize(obj);
|
2011-03-07 23:50:24 +01:00
|
|
|
}
|
2011-01-22 00:46:33 +01:00
|
|
|
|
2011-03-07 23:50:24 +01:00
|
|
|
GtkWidget*
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_view_new(void)
|
2011-01-22 02:13:06 +01:00
|
|
|
{
|
2011-03-07 23:50:24 +01:00
|
|
|
return GTK_WIDGET(g_object_new(MU_TYPE_MSG_VIEW, NULL));
|
2011-01-22 02:13:06 +01:00
|
|
|
}
|
|
|
|
|
2011-03-07 23:50:24 +01:00
|
|
|
void
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_view_set_message(MuMsgView* self, Mu::MuMsg* msg)
|
2011-01-08 11:48:25 +01:00
|
|
|
{
|
2011-03-07 23:50:24 +01:00
|
|
|
gint attachnum;
|
2012-03-22 21:37:54 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
g_return_if_fail(MU_IS_MSG_VIEW(self));
|
2011-03-07 23:50:24 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
set_message(self, msg);
|
2011-03-07 23:50:24 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_header_view_set_message(MU_MSG_HEADER_VIEW(self->_priv->_headers), msg);
|
|
|
|
attachnum = mu_msg_attach_view_set_message(MU_MSG_ATTACH_VIEW(self->_priv->_attach), msg);
|
2012-03-22 21:37:54 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_body_view_set_message(MU_MSG_BODY_VIEW(self->_priv->_body), msg);
|
2012-03-22 21:37:54 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
gtk_widget_set_visible(self->_priv->_headers, TRUE);
|
|
|
|
gtk_widget_set_visible(self->_priv->_attachexpander, attachnum > 0);
|
|
|
|
gtk_widget_set_visible(self->_priv->_body, TRUE);
|
2011-01-08 11:48:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_view_set_message_source(MuMsgView* self, Mu::MuMsg* msg)
|
2012-03-22 21:37:54 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
g_return_if_fail(MU_IS_MSG_VIEW(self));
|
2011-01-22 00:46:33 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
set_message(self, msg);
|
2012-03-22 21:37:54 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_body_view_set_message_source(MU_MSG_BODY_VIEW(self->_priv->_body), msg);
|
2012-03-22 21:37:54 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
gtk_widget_set_visible(self->_priv->_headers, FALSE);
|
|
|
|
gtk_widget_set_visible(self->_priv->_attachexpander, FALSE);
|
|
|
|
gtk_widget_set_visible(self->_priv->_body, TRUE);
|
2011-01-08 11:48:25 +01:00
|
|
|
}
|
|
|
|
|
2011-01-12 22:15:54 +01:00
|
|
|
void
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_view_set_note(MuMsgView* self, const gchar* html)
|
2011-01-12 22:15:54 +01:00
|
|
|
{
|
2021-10-20 11:18:15 +02:00
|
|
|
g_return_if_fail(MU_IS_MSG_VIEW(self));
|
2012-03-22 21:37:54 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
gtk_widget_set_visible(self->_priv->_headers, FALSE);
|
|
|
|
gtk_widget_set_visible(self->_priv->_attachexpander, FALSE);
|
|
|
|
gtk_widget_set_visible(self->_priv->_body, TRUE);
|
2011-03-07 23:50:24 +01:00
|
|
|
|
2021-10-20 11:18:15 +02:00
|
|
|
mu_msg_body_view_set_note(MU_MSG_BODY_VIEW(self->_priv->_body), html);
|
2011-01-22 02:13:06 +01:00
|
|
|
}
|