mirror of https://github.com/djcb/mu.git
192 lines
4.7 KiB
C
192 lines
4.7 KiB
C
/*
|
|
** Copyright (C) 2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
|
**
|
|
** 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.
|
|
**
|
|
*/
|
|
|
|
#include "mu-msg-view.h"
|
|
#include "mu-msg-body-view.h"
|
|
#include "mu-msg-attach-view.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);
|
|
static void mu_msg_view_init (MuMsgView *obj);
|
|
static void mu_msg_view_finalize (GObject *obj);
|
|
|
|
/* list my signals */
|
|
enum {
|
|
/* MY_SIGNAL_1, */
|
|
/* MY_SIGNAL_2, */
|
|
LAST_SIGNAL
|
|
};
|
|
|
|
struct _MuMsgViewPrivate {
|
|
GtkWidget *_headers;
|
|
GtkWidget *_body;
|
|
GtkWidget *_attach, *_attacharea;
|
|
};
|
|
#define MU_MSG_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
|
|
MU_TYPE_MSG_VIEW, \
|
|
MuMsgViewPrivate))
|
|
/* globals */
|
|
static GtkVBoxClass *parent_class = NULL;
|
|
|
|
/* uncomment the following if you have defined any signals */
|
|
/* static guint signals[LAST_SIGNAL] = {0}; */
|
|
|
|
G_DEFINE_TYPE (MuMsgView, mu_msg_view, GTK_TYPE_VBOX);
|
|
|
|
static void
|
|
mu_msg_view_class_init (MuMsgViewClass *klass)
|
|
{
|
|
GObjectClass *gobject_class;
|
|
gobject_class = (GObjectClass*) klass;
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
gobject_class->finalize = mu_msg_view_finalize;
|
|
|
|
g_type_class_add_private (gobject_class, sizeof(MuMsgViewPrivate));
|
|
|
|
/* signal definitions go here, e.g.: */
|
|
/* signals[MY_SIGNAL_1] = */
|
|
/* g_signal_new ("my_signal_1",....); */
|
|
/* signals[MY_SIGNAL_2] = */
|
|
/* g_signal_new ("my_signal_2",....); */
|
|
/* etc. */
|
|
}
|
|
|
|
static void
|
|
on_attach_activated (MuMsgView *self, guint partnum, MuMsg *msg)
|
|
{
|
|
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 GtkWidget*
|
|
get_header_widget (MuMsgView *self)
|
|
{
|
|
return self->_priv->_headers = mu_msg_header_view_new ();
|
|
}
|
|
|
|
|
|
static GtkWidget*
|
|
get_body_widget (MuMsgView *self)
|
|
{
|
|
GtkWidget *scrolledwin;
|
|
|
|
self->_priv->_body = mu_msg_body_view_new ();
|
|
scrolledwin = gtk_scrolled_window_new (NULL, NULL);
|
|
gtk_container_add (GTK_CONTAINER(scrolledwin),
|
|
self->_priv->_body);
|
|
|
|
return scrolledwin;
|
|
}
|
|
|
|
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),
|
|
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
|
|
mu_msg_view_finalize (GObject *obj)
|
|
{
|
|
/* free/unref instance resources here */
|
|
G_OBJECT_CLASS(parent_class)->finalize (obj);
|
|
}
|
|
|
|
GtkWidget*
|
|
mu_msg_view_new (void)
|
|
{
|
|
return GTK_WIDGET(g_object_new(MU_TYPE_MSG_VIEW, NULL));
|
|
}
|
|
|
|
|
|
static void
|
|
update_attachment_area (MuMsgView *self, MuMsg *msg)
|
|
{
|
|
gint attach_num;
|
|
|
|
attach_num = 0;
|
|
if (msg)
|
|
attach_num = mu_msg_attach_view_set_message
|
|
(MU_MSG_ATTACH_VIEW(self->_priv->_attach), msg);
|
|
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)
|
|
{
|
|
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);
|
|
|
|
update_attachment_area (self, msg);
|
|
}
|
|
|