1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <glib/gi18n.h>
31 #include <tny-account-store.h>
32 #include <tny-simple-list.h>
33 #include <modest-tny-msg.h>
34 #include "modest-icon-names.h"
35 #include "modest-ui-actions.h"
36 #include <modest-widget-memory.h>
37 #include <modest-runtime.h>
39 #include <widgets/modest-msg-view-window.h>
40 #include <widgets/modest-window-priv.h>
41 #include "widgets/modest-msg-view.h"
44 static void modest_msg_view_window_class_init (ModestMsgViewWindowClass *klass);
45 static void modest_msg_view_window_init (ModestMsgViewWindow *obj);
46 static void modest_msg_view_window_finalize (GObject *obj);
55 typedef struct _ModestMsgViewWindowPrivate ModestMsgViewWindowPrivate;
56 struct _ModestMsgViewWindowPrivate {
62 #define MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
63 MODEST_TYPE_MSG_VIEW_WINDOW, \
64 ModestMsgViewWindowPrivate))
66 static GtkWindowClass *parent_class = NULL;
69 static const GtkActionEntry modest_action_entries [] = {
72 { "Edit", NULL, N_("_Edit") },
73 { "Actions", NULL, N_("_Actions") },
74 { "Help", NULL, N_("_Help") },
75 { "Email", NULL, N_("E_mail") },
78 { "EditUndo", GTK_STOCK_UNDO, N_("_Undo"), "<CTRL>Z", N_("Undo last action"), NULL },
79 { "EditRedo", GTK_STOCK_REDO, N_("_Redo"), "<shift><CTRL>Z", N_("Redo previous action"), NULL },
80 { "Cut", GTK_STOCK_CUT, N_("Cut"), "<CTRL>X", N_("_Cut"), G_CALLBACK (modest_ui_actions_on_cut) },
81 { "Copy", GTK_STOCK_COPY, N_("Copy"), "<CTRL>C", N_("Copy"), G_CALLBACK (modest_ui_actions_on_copy) },
82 { "Paste", GTK_STOCK_PASTE, N_("Paste"), "<CTRL>V", N_("Paste"), G_CALLBACK (modest_ui_actions_on_paste) },
83 { "EditDelete", GTK_STOCK_DELETE, N_("_Delete"), "<CTRL>Q", N_("Delete"), NULL },
84 { "SelectAll", NULL, N_("Select all"), "<CTRL>A", N_("Select all"), G_CALLBACK (modest_ui_actions_on_select_all) },
85 { "EditDeselectAll", NULL, N_("Deselect all"), "<Shift><CTRL>A", N_("Deselect all"), NULL },
88 { "ActionsNewMessage", MODEST_STOCK_NEW_MAIL, N_("_New"), "<CTRL>N", N_("Compose new message"), G_CALLBACK (modest_ui_actions_on_new_msg) },
89 { "ActionsReply", MODEST_STOCK_REPLY, N_("_Reply"), NULL, N_("Reply to a message"), G_CALLBACK (modest_ui_actions_on_reply) },
90 { "ActionsReplyAll", MODEST_STOCK_REPLY_ALL, N_("Reply to all"), NULL, N_("Reply to all"), G_CALLBACK (modest_ui_actions_on_reply_all) },
91 { "ActionsForward", MODEST_STOCK_FORWARD, N_("_Forward"), NULL, N_("Forward a message"), G_CALLBACK (modest_ui_actions_on_forward) },
92 { "ActionsBounce", NULL, N_("_Bounce"), NULL, N_("Bounce a message"), NULL },
93 { "ActionsSendReceive", GTK_STOCK_REFRESH, N_("Send/Receive"), NULL, N_("Send and receive messages"), NULL },
94 { "ActionsDelete", MODEST_STOCK_DELETE, N_("Delete message"), NULL, N_("Delete messages"), G_CALLBACK (modest_ui_actions_on_delete) },
97 { "HelpAbout", GTK_STOCK_ABOUT, N_("About"), NULL, N_("About Modest"), G_CALLBACK (modest_ui_actions_on_about) },
102 modest_msg_view_window_get_type (void)
104 static GType my_type = 0;
106 static const GTypeInfo my_info = {
107 sizeof(ModestMsgViewWindowClass),
108 NULL, /* base init */
109 NULL, /* base finalize */
110 (GClassInitFunc) modest_msg_view_window_class_init,
111 NULL, /* class finalize */
112 NULL, /* class data */
113 sizeof(ModestMsgViewWindow),
115 (GInstanceInitFunc) modest_msg_view_window_init,
118 my_type = g_type_register_static (MODEST_TYPE_WINDOW,
119 "ModestMsgViewWindow",
126 save_state (ModestWindow *self)
128 modest_widget_memory_save (modest_runtime_get_conf (),
130 MODEST_CONF_MSG_VIEW_WINDOW_KEY);
135 restore_settings (ModestWindow *self)
137 modest_widget_memory_restore (modest_runtime_get_conf (),
139 MODEST_CONF_MSG_VIEW_WINDOW_KEY);
143 modest_msg_view_window_class_init (ModestMsgViewWindowClass *klass)
145 GObjectClass *gobject_class;
146 gobject_class = (GObjectClass*) klass;
148 parent_class = g_type_class_peek_parent (klass);
149 gobject_class->finalize = modest_msg_view_window_finalize;
151 g_type_class_add_private (gobject_class, sizeof(ModestMsgViewWindowPrivate));
153 ModestWindowClass *modest_window_class = (ModestWindowClass *) klass;
154 modest_window_class->save_state_func = save_state;
158 modest_msg_view_window_init (ModestMsgViewWindow *obj)
160 ModestMsgViewWindowPrivate *priv;
161 priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(obj);
163 priv->toolbar = NULL;
164 priv->menubar = NULL;
165 priv->msg_view = NULL;
170 init_window (ModestMsgViewWindow *obj, TnyMsg *msg)
172 GtkWidget *main_vbox, *scrolled_window;
173 ModestMsgViewWindowPrivate *priv;
174 ModestWindowPrivate *parent_priv;
176 priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(obj);
177 parent_priv = MODEST_WINDOW_GET_PRIVATE(obj);
179 priv->msg_view = modest_msg_view_new (msg);
180 main_vbox = gtk_vbox_new (FALSE, 6);
182 gtk_box_pack_start (GTK_BOX(main_vbox), priv->menubar, FALSE, FALSE, 0);
183 gtk_box_pack_start (GTK_BOX(main_vbox), priv->toolbar, FALSE, FALSE, 0);
184 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
185 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
186 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
187 gtk_container_add (GTK_CONTAINER (scrolled_window),
189 gtk_box_pack_start (GTK_BOX(main_vbox), scrolled_window, TRUE, TRUE, 6);
191 gtk_widget_show_all (GTK_WIDGET(main_vbox));
192 gtk_container_add (GTK_CONTAINER(obj), main_vbox);
197 modest_msg_view_window_finalize (GObject *obj)
199 G_OBJECT_CLASS(parent_class)->finalize (obj);
205 on_delete_event (GtkWidget *widget, GdkEvent *event, ModestMsgViewWindow *self)
207 modest_window_save_state (MODEST_WINDOW(self));
213 modest_msg_view_window_new (TnyMsg *msg, const gchar *account)
216 ModestMsgViewWindowPrivate *priv;
217 ModestWindowPrivate *parent_priv;
218 GtkActionGroup *action_group;
219 GError *error = NULL;
220 TnyHeader *header = NULL;
221 const gchar *subject = NULL;
223 g_return_val_if_fail (msg, NULL);
225 obj = g_object_new(MODEST_TYPE_MSG_VIEW_WINDOW, NULL);
226 priv = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(obj);
227 parent_priv = MODEST_WINDOW_GET_PRIVATE(obj);
229 modest_window_set_active_account (MODEST_WINDOW(obj), account);
231 parent_priv->ui_manager = gtk_ui_manager_new();
232 action_group = gtk_action_group_new ("ModestMsgViewWindowActions");
234 /* Add common actions */
235 gtk_action_group_add_actions (action_group,
236 modest_action_entries,
237 G_N_ELEMENTS (modest_action_entries),
239 gtk_ui_manager_insert_action_group (parent_priv->ui_manager, action_group, 0);
240 g_object_unref (action_group);
243 /* Load the UI definition */
244 gtk_ui_manager_add_ui_from_file (parent_priv->ui_manager,
245 MODEST_UIDIR "modest-msg-view-window-ui.xml",
248 g_printerr ("modest: could not merge modest-msg-view-window-ui.xml: %s\n", error->message);
249 g_error_free (error);
254 /* Add accelerators */
255 gtk_window_add_accel_group (GTK_WINDOW (obj),
256 gtk_ui_manager_get_accel_group (parent_priv->ui_manager));
258 /* Toolbar / Menubar */
259 priv->toolbar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar");
260 priv->menubar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar");
262 gtk_toolbar_set_tooltips (GTK_TOOLBAR (priv->toolbar), TRUE);
265 init_window (MODEST_MSG_VIEW_WINDOW(obj), msg);
266 restore_settings (MODEST_MSG_VIEW_WINDOW(obj));
268 header = tny_msg_get_header (msg);
270 subject = tny_header_get_subject (header);
273 gtk_window_set_title (GTK_WINDOW (obj), subject);
275 gtk_window_set_title (GTK_WINDOW(obj), "Modest");
278 g_object_unref (header);
280 gtk_window_set_icon_from_file (GTK_WINDOW(obj), MODEST_APP_ICON, NULL);
282 g_signal_connect (G_OBJECT(obj), "delete-event", G_CALLBACK(on_delete_event), obj);
284 return MODEST_WINDOW(obj);
289 modest_msg_view_window_get_message (ModestMsgViewWindow *self)
292 g_return_val_if_fail (self, NULL);
294 msg_view = MODEST_MSG_VIEW_WINDOW_GET_PRIVATE(self)->msg_view;
296 return modest_msg_view_get_message (MODEST_MSG_VIEW(msg_view));
300 modest_msg_view_window_get_message_uid (ModestMsgViewWindow *self)
304 const gchar *retval = NULL;
306 msg = modest_msg_view_window_get_message (self);
311 header = tny_msg_get_header (msg);
313 retval = tny_header_get_uid (header);
314 g_object_unref (header);
320 modest_msg_view_window_new_with_header_model (TnyMsg *msg,
321 const gchar *account,
325 /* Currently we simply redirect to new constructor. It should store a
326 reference to the header list model, to enable next/prev message
328 g_message ("partially implemented %s", __FUNCTION__);
330 return modest_msg_view_window_new (msg, account);
335 modest_msg_view_window_select_next_message (ModestMsgViewWindow *window)
337 g_message ("not implemented %s", __FUNCTION__);
342 modest_msg_view_window_select_previous_message (ModestMsgViewWindow *window)
344 g_message ("not implemented %s", __FUNCTION__);
349 modest_msg_view_window_view_attachment (ModestMsgViewWindow *window, TnyMimePart *mime_part)
351 g_message ("not implemented %s", __FUNCTION__);
355 modest_msg_view_window_save_attachments (ModestMsgViewWindow *window, GList *mime_parts)
357 g_message ("not implemented %s", __FUNCTION__);
360 modest_msg_view_window_remove_attachments (ModestMsgViewWindow *window, GList *mime_parts)
362 g_message ("not implemented %s", __FUNCTION__);