/* TMut * Copyright (C) 2006-2007 Philip Van Hoof * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with self library; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #if HAVE_CONFIG_H #include "config.h" #endif #include #include "tmut-header-view.h" #include "tmut-tny-gtk-msg-view.h" #include "tmut-msg-view.h" #include "tmut-msg-creator.h" #include "tmut-shell-window.h" #include "tmut-shell-child.h" static GObjectClass *parent_class = NULL; typedef struct _TMutMsgViewPriv TMutMsgViewPriv; struct _TMutMsgViewPriv { TMutShellWindow *shell; TnyMsgView *msg_view; GtkScrolledWindow *sw; TnyAccountStore *account_store; }; #define TMUT_MSG_VIEW_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), TMUT_TYPE_MSG_VIEW, TMutMsgViewPriv)) void tmut_msg_view_on_reply_activated (GObject *sender, TMutMsgView *self) { TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self); TnyMsg *msg = tny_msg_view_get_msg (priv->msg_view); TMutMsgCreator *view = tmut_msg_creator_new (); if (priv->account_store) tny_account_store_view_set_account_store (TNY_ACCOUNT_STORE_VIEW (view), priv->account_store); tmut_msg_creator_set_reply_msg (view, msg); gtk_widget_show (GTK_WIDGET (view)); tmut_shell_window_set_child ( tmut_shell_child_get_window (TMUT_SHELL_CHILD (self)), TMUT_SHELL_CHILD (view), NULL); g_object_unref (msg); return; } void tmut_msg_view_on_forward_activated (GObject *sender, TMutMsgView *self) { TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self); TnyMsg *msg = tny_msg_view_get_msg (priv->msg_view); TMutMsgCreator *view = tmut_msg_creator_new (); if (priv->account_store) tny_account_store_view_set_account_store (TNY_ACCOUNT_STORE_VIEW (view), priv->account_store); tmut_msg_creator_set_forward_msg (view, msg); gtk_widget_show (GTK_WIDGET (view)); tmut_shell_window_set_child ( tmut_shell_child_get_window (TMUT_SHELL_CHILD (self)), TMUT_SHELL_CHILD (view), NULL); g_object_unref (msg); return; return; } static void tmut_msg_view_create_menu_default (TMutMsgView *self) { TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self); GtkWidget *hbox, *reply_button, *forward_button; hbox = gtk_hbox_new (FALSE, 0); reply_button = gtk_button_new_with_label (_("Reply")); forward_button = gtk_button_new_with_label (_("Forward")); gtk_widget_show (hbox); gtk_widget_show (reply_button); gtk_widget_show (forward_button); gtk_box_pack_start (GTK_BOX (self), hbox, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), reply_button, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (hbox), forward_button, TRUE, TRUE, 0); g_signal_connect (G_OBJECT (reply_button), "clicked", G_CALLBACK (tmut_msg_view_on_reply_activated), self); g_signal_connect (G_OBJECT (forward_button), "clicked", G_CALLBACK (tmut_msg_view_on_forward_activated), self); return; } static void tmut_msg_view_set_unavailable (TnyMsgView *self) { TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self); tny_msg_view_set_unavailable (priv->msg_view); return; } static TnyMsg* tmut_msg_view_get_msg (TnyMsgView *self) { TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self); return tny_msg_view_get_msg (priv->msg_view); } static void tmut_msg_view_set_msg (TnyMsgView *self, TnyMsg *msg) { TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self); tny_msg_view_set_msg (priv->msg_view, msg); return; } static void tmut_msg_view_clear (TnyMsgView *self) { TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self); tny_msg_view_clear (priv->msg_view); return; } static TnyMsgView* tmut_msg_view_create_new_inline_viewer (TnyMsgView *self) { TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self); /* This should not be a window, but the decorated one, as it has to be embeddable within a window. So we even decorate this one as usual. */ return tny_msg_view_create_new_inline_viewer (priv->msg_view); } static TnyMimePartView* tmut_msg_view_create_mime_part_view_for (TnyMsgView *self, TnyMimePart *part) { TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self); return tny_msg_view_create_mime_part_view_for (priv->msg_view, part); } static void tmut_msg_view_mp_clear (TnyMimePartView *self) { tny_msg_view_clear (TNY_MSG_VIEW (self)); return; } static void tmut_msg_view_mp_set_part (TnyMimePartView *self, TnyMimePart *part) { TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self); tny_mime_part_view_set_part (TNY_MIME_PART_VIEW (priv->msg_view), part); return; } static TnyMimePart* tmut_msg_view_mp_get_part (TnyMimePartView *self) { TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self); return tny_mime_part_view_get_part (TNY_MIME_PART_VIEW (priv->msg_view)); } /** * tmut_msg_view_set_view: * @self: a #TnyGtkMsgView instance * @view: a #TnyMsgView to decorate * * Set the @view to decorate with @self **/ void tmut_msg_view_set_view (TMutMsgView *self, TnyMsgView *view) { TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self); if (priv->msg_view) gtk_container_remove (GTK_CONTAINER (priv->sw), GTK_WIDGET (priv->msg_view)); priv->msg_view = view; gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (priv->sw), GTK_WIDGET (view)); gtk_widget_show (GTK_WIDGET (priv->msg_view)); return; } /** * tmut_msg_view_new: * Create a GtkWindow that implements #TnyMsgView * * Return value: a new #TnyMsgView instance implemented for Gtk+ **/ TnyMsgView* tmut_msg_view_new (TnyAccountStore *account_store) { TMutMsgView *self = g_object_new (TMUT_TYPE_MSG_VIEW, NULL); TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self); if (account_store) priv->account_store = TNY_ACCOUNT_STORE (g_object_ref (account_store)); return TNY_MSG_VIEW (self); } static void tmut_msg_view_instance_init (GTypeInstance *instance, gpointer g_class) { TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (instance); priv->account_store = NULL; priv->msg_view = NULL; priv->sw = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL)); gtk_widget_show (GTK_WIDGET (priv->sw)); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->sw), GTK_SHADOW_NONE); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start (GTK_BOX (instance), GTK_WIDGET (priv->sw), TRUE, TRUE, 0); TMUT_MSG_VIEW_GET_CLASS (instance)->create_menu ((TMutMsgView *) instance); tmut_msg_view_set_view (TMUT_MSG_VIEW (instance), tmut_tny_gtk_msg_view_new ()); return; } static void tmut_msg_view_finalize (GObject *object) { TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (object); if (priv->account_store) g_object_unref (priv->account_store); (*parent_class->finalize) (object); return; } TMutShellWindow* tmut_msg_view_get_window (TMutShellChild *self) { TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self); return priv->shell; } void tmut_msg_view_set_window (TMutShellChild *self, TMutShellWindow *window) { TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self); priv->shell = window; } static void tmut_shell_child_init (gpointer g, gpointer iface_data) { TMutShellChildIface *klass = (TMutShellChildIface *)g; klass->get_window= tmut_msg_view_get_window; klass->set_window= tmut_msg_view_set_window; return; } static TnyHeaderView* tmut_msg_view_create_header_view (TnyGtkMsgView *self) { return tmut_header_view_new (); } static void tmut_msg_view_class_init (TMutMsgViewClass *class) { GObjectClass *object_class; parent_class = g_type_class_peek_parent (class); object_class = (GObjectClass*) class; object_class->finalize = tmut_msg_view_finalize; class->create_menu= tmut_msg_view_create_menu_default; g_type_class_add_private (object_class, sizeof (TMutMsgViewPriv)); return; } static void tny_msg_view_init (gpointer g, gpointer iface_data) { TnyMsgViewIface *klass = (TnyMsgViewIface *)g; klass->get_msg= tmut_msg_view_get_msg; klass->set_msg= tmut_msg_view_set_msg; klass->set_unavailable= tmut_msg_view_set_unavailable; klass->clear= tmut_msg_view_clear; klass->create_mime_part_view_for= tmut_msg_view_create_mime_part_view_for; klass->create_new_inline_viewer= tmut_msg_view_create_new_inline_viewer; return; } static void tny_mime_part_view_init (gpointer g, gpointer iface_data) { TnyMimePartViewIface *klass = (TnyMimePartViewIface *)g; klass->get_part= tmut_msg_view_mp_get_part; klass->set_part= tmut_msg_view_mp_set_part; klass->clear= tmut_msg_view_mp_clear; return; } GType tmut_msg_view_get_type (void) { static GType type = 0; if (G_UNLIKELY(type == 0)) { static const GTypeInfo info = { sizeof (TMutMsgViewClass), NULL, /* base_init */ NULL, /* base_finalize */ (GClassInitFunc) tmut_msg_view_class_init, /* class_init */ NULL, /* class_finalize */ NULL, /* class_data */ sizeof (TMutMsgView), 0, /* n_preallocs */ tmut_msg_view_instance_init, /* instance_init */ NULL }; static const GInterfaceInfo tmut_shell_child_info = { (GInterfaceInitFunc) tmut_shell_child_init, /* interface_init */ NULL, /* interface_finalize */ NULL /* interface_data */ }; static const GInterfaceInfo tny_msg_view_info = { (GInterfaceInitFunc) tny_msg_view_init, /* interface_init */ NULL, /* interface_finalize */ NULL /* interface_data */ }; static const GInterfaceInfo tny_mime_part_view_info = { (GInterfaceInitFunc) tny_mime_part_view_init, /* interface_init */ NULL, /* interface_finalize */ NULL /* interface_data */ }; type = g_type_register_static (GTK_TYPE_VBOX, "TMutMsgView", &info, 0); g_type_add_interface_static (type, TNY_TYPE_MIME_PART_VIEW, &tny_mime_part_view_info); g_type_add_interface_static (type, TNY_TYPE_MSG_VIEW, &tny_msg_view_info); g_type_add_interface_static (type, TMUT_TYPE_SHELL_CHILD, &tmut_shell_child_info); } return type; }