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.
30 #include <glib/gi18n.h>
31 #include <gtk/gtktreeviewcolumn.h>
32 #include <modest-runtime.h>
34 #include "modest-main-window.h"
35 #include "modest-window-priv.h"
36 #include "modest-widget-memory.h"
37 #include "modest-ui.h"
38 #include "modest-main-window-ui.h"
39 #include "modest-account-view-window.h"
40 #include "modest-account-mgr.h"
41 #include "modest-conf.h"
42 #include "modest-edit-msg-window.h"
43 #include <modest-tny-msg.h>
44 #include "modest-mail-operation.h"
45 #include "modest-icon-names.h"
47 /* 'private'/'protected' functions */
48 static void modest_main_window_class_init (ModestMainWindowClass *klass);
49 static void modest_main_window_init (ModestMainWindow *obj);
50 static void modest_main_window_finalize (GObject *obj);
52 static void restore_sizes (ModestMainWindow *self);
53 static void save_sizes (ModestMainWindow *self);
55 static gboolean on_header_view_button_press_event (ModestHeaderView *header_view,
56 GdkEventButton *event,
57 ModestMainWindow *self);
59 static gboolean on_folder_view_button_press_event (ModestFolderView *folder_view,
60 GdkEventButton *event,
61 ModestMainWindow *self);
63 static gboolean show_context_popup_menu (ModestMainWindow *window,
64 GtkTreeView *tree_view,
65 GdkEventButton *event,
75 typedef struct _ModestMainWindowPrivate ModestMainWindowPrivate;
76 struct _ModestMainWindowPrivate {
78 GtkWidget *folder_paned;
80 GtkWidget *main_paned;
82 ModestHeaderView *header_view;
83 ModestFolderView *folder_view;
84 ModestMsgView *msg_preview;
88 #define MODEST_MAIN_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
89 MODEST_TYPE_MAIN_WINDOW, \
90 ModestMainWindowPrivate))
92 typedef struct _GetMsgAsyncHelper {
93 ModestMainWindowPrivate *main_window_private;
95 ModestMailOperationReplyType reply_type;
96 ModestMailOperationForwardType forward_type;
102 static GtkWindowClass *parent_class = NULL;
104 /* uncomment the following if you have defined any signals */
105 /* static guint signals[LAST_SIGNAL] = {0}; */
108 modest_main_window_get_type (void)
110 static GType my_type = 0;
112 static const GTypeInfo my_info = {
113 sizeof(ModestMainWindowClass),
114 NULL, /* base init */
115 NULL, /* base finalize */
116 (GClassInitFunc) modest_main_window_class_init,
117 NULL, /* class finalize */
118 NULL, /* class data */
119 sizeof(ModestMainWindow),
121 (GInstanceInitFunc) modest_main_window_init,
124 my_type = g_type_register_static (MODEST_TYPE_WINDOW,
132 modest_main_window_class_init (ModestMainWindowClass *klass)
134 GObjectClass *gobject_class;
135 gobject_class = (GObjectClass*) klass;
137 parent_class = g_type_class_peek_parent (klass);
138 gobject_class->finalize = modest_main_window_finalize;
140 g_type_class_add_private (gobject_class, sizeof(ModestMainWindowPrivate));
144 modest_main_window_init (ModestMainWindow *obj)
146 ModestMainWindowPrivate *priv;
148 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
150 priv->folder_paned = NULL;
151 priv->msg_paned = NULL;
152 priv->main_paned = NULL;
153 priv->header_view = NULL;
154 priv->folder_view = NULL;
155 priv->msg_preview = NULL;
159 modest_main_window_finalize (GObject *obj)
161 G_OBJECT_CLASS(parent_class)->finalize (obj);
165 static ModestHeaderView*
166 header_view_new (ModestMainWindow *self)
168 ModestHeaderView *header_view;
170 header_view = modest_widget_factory_get_header_view
171 (modest_runtime_get_widget_factory());
172 modest_header_view_set_style
173 (header_view, MODEST_HEADER_VIEW_STYLE_DETAILS);
180 restore_sizes (ModestMainWindow *self)
183 ModestMainWindowPrivate *priv;
184 ModestWindowPrivate *parent_priv;
186 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
187 parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
189 conf = modest_runtime_get_conf ();
191 modest_widget_memory_restore (conf, G_OBJECT(priv->folder_paned),
192 "modest-folder-paned");
193 modest_widget_memory_restore (conf, G_OBJECT(priv->msg_paned),
195 modest_widget_memory_restore (conf, G_OBJECT(priv->main_paned),
196 "modest-main-paned");
197 modest_widget_memory_restore (conf, G_OBJECT(priv->header_view),
199 modest_widget_memory_restore (conf,G_OBJECT(self),
200 "modest-main-window");
205 save_sizes (ModestMainWindow *self)
207 ModestWindowPrivate *parent_priv;
208 ModestMainWindowPrivate *priv;
211 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
212 parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
214 conf = modest_runtime_get_conf ();
216 modest_widget_memory_save (conf,G_OBJECT(self), "modest-main-window");
217 modest_widget_memory_save (conf, G_OBJECT(priv->folder_paned),
218 "modest-folder-paned");
219 modest_widget_memory_save (conf, G_OBJECT(priv->msg_paned),
221 modest_widget_memory_save (conf, G_OBJECT(priv->main_paned),
222 "modest-main-paned");
223 modest_widget_memory_save (conf, G_OBJECT(priv->header_view), "header-view");
227 wrapped_in_scrolled_window (GtkWidget *widget, gboolean needs_viewport)
231 win = gtk_scrolled_window_new (NULL, NULL);
232 gtk_scrolled_window_set_policy
233 (GTK_SCROLLED_WINDOW (win),GTK_POLICY_NEVER,
234 GTK_POLICY_AUTOMATIC);
237 gtk_scrolled_window_add_with_viewport
238 (GTK_SCROLLED_WINDOW(win), widget);
240 gtk_container_add (GTK_CONTAINER(win),
248 on_delete_event (GtkWidget *widget, GdkEvent *event, ModestMainWindow *self)
256 modest_main_window_new (void)
259 ModestMainWindowPrivate *priv;
260 ModestWindowPrivate *parent_priv;
261 GtkWidget *main_vbox;
262 GtkWidget *status_hbox;
263 GtkWidget *header_win, *folder_win;
264 ModestWidgetFactory *widget_factory;
265 GtkActionGroup *action_group;
266 GError *error = NULL;
269 obj = g_object_new(MODEST_TYPE_MAIN_WINDOW, NULL);
270 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
271 parent_priv = MODEST_WINDOW_GET_PRIVATE(obj);
273 /* ***************** */
274 parent_priv->ui_manager = gtk_ui_manager_new();
275 action_group = gtk_action_group_new ("ModestMainWindowActions");
277 widget_factory = modest_runtime_get_widget_factory ();
279 /* Add common actions */
280 gtk_action_group_add_actions (action_group,
281 modest_action_entries,
282 G_N_ELEMENTS (modest_action_entries),
285 gtk_ui_manager_insert_action_group (parent_priv->ui_manager, action_group, 0);
286 g_object_unref (action_group);
288 /* Load the UI definition */
289 gtk_ui_manager_add_ui_from_file (parent_priv->ui_manager, MODEST_UIDIR "modest-ui.xml", &error);
291 g_printerr ("modest: could not merge modest-ui.xml: %s", error->message);
292 g_error_free (error);
295 /* *************** */
297 /* Add accelerators */
298 gtk_window_add_accel_group (GTK_WINDOW (obj),
299 gtk_ui_manager_get_accel_group (parent_priv->ui_manager));
301 /* Toolbar / Menubar */
302 parent_priv->toolbar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar");
303 parent_priv->menubar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar");
305 gtk_toolbar_set_tooltips (GTK_TOOLBAR (parent_priv->toolbar), TRUE);
307 /* widgets from factory */
308 priv->folder_view = modest_widget_factory_get_folder_view (widget_factory);
309 priv->header_view = header_view_new (MODEST_MAIN_WINDOW(obj));
310 priv->msg_preview = modest_widget_factory_get_msg_preview (widget_factory);
312 folder_win = wrapped_in_scrolled_window (GTK_WIDGET(priv->folder_view),
314 header_win = wrapped_in_scrolled_window (GTK_WIDGET(priv->header_view),
317 /* Connect platform specific signals */
318 g_signal_connect (priv->header_view,
319 "button-press-event",
320 G_CALLBACK (on_header_view_button_press_event),
322 g_signal_connect (priv->header_view,
324 G_CALLBACK (on_header_view_button_press_event),
326 g_signal_connect (priv->folder_view,
327 "button-press-event",
328 G_CALLBACK (on_folder_view_button_press_event),
330 g_signal_connect (priv->folder_view,
332 G_CALLBACK (on_folder_view_button_press_event),
336 priv->folder_paned = gtk_vpaned_new ();
337 priv->msg_paned = gtk_vpaned_new ();
338 priv->main_paned = gtk_hpaned_new ();
339 gtk_paned_add1 (GTK_PANED(priv->main_paned), folder_win);
340 gtk_paned_add2 (GTK_PANED(priv->main_paned), priv->msg_paned);
341 gtk_paned_add1 (GTK_PANED(priv->msg_paned), header_win);
342 gtk_paned_add2 (GTK_PANED(priv->msg_paned), GTK_WIDGET(priv->msg_preview));
344 gtk_widget_show (GTK_WIDGET(priv->header_view));
346 /* status bar / progress */
347 status_hbox = gtk_hbox_new (FALSE, 0);
348 gtk_box_pack_start (GTK_BOX(status_hbox),
349 modest_widget_factory_get_folder_info_label (widget_factory),
351 gtk_box_pack_start (GTK_BOX(status_hbox),
352 modest_widget_factory_get_status_bar(widget_factory),
354 gtk_box_pack_start (GTK_BOX(status_hbox),
355 modest_widget_factory_get_progress_bar(widget_factory),
357 gtk_box_pack_start (GTK_BOX(status_hbox),
358 modest_widget_factory_get_online_toggle(widget_factory),
361 /* putting it all together... */
362 main_vbox = gtk_vbox_new (FALSE, 6);
363 gtk_box_pack_start (GTK_BOX(main_vbox), parent_priv->menubar, FALSE, FALSE, 0);
364 gtk_box_pack_start (GTK_BOX(main_vbox), parent_priv->toolbar, FALSE, FALSE, 0);
365 gtk_box_pack_start (GTK_BOX(main_vbox), priv->main_paned, TRUE, TRUE,0);
366 gtk_box_pack_start (GTK_BOX(main_vbox), status_hbox, FALSE, FALSE, 0);
368 gtk_container_add (GTK_CONTAINER(obj), main_vbox);
369 restore_sizes (MODEST_MAIN_WINDOW(obj));
371 gtk_window_set_title (GTK_WINDOW(obj), _("Modest"));
372 gtk_window_set_icon_from_file (GTK_WINDOW(obj), MODEST_APP_ICON, NULL);
373 gtk_widget_show_all (main_vbox);
375 g_signal_connect (G_OBJECT(obj), "delete-event",
376 G_CALLBACK(on_delete_event), obj);
378 return (ModestWindow *) obj;
382 on_header_view_button_press_event (ModestHeaderView *header_view,
383 GdkEventButton *event,
384 ModestMainWindow *self)
386 if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
388 ModestWindowPrivate *parent_priv;
390 parent_priv = MODEST_WINDOW_GET_PRIVATE (self);
391 menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/HeaderViewContextMenu");
393 return show_context_popup_menu (self,
394 GTK_TREE_VIEW (header_view),
403 on_folder_view_button_press_event (ModestFolderView *folder_view,
404 GdkEventButton *event,
405 ModestMainWindow *self)
407 if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
409 ModestWindowPrivate *parent_priv;
411 parent_priv = MODEST_WINDOW_GET_PRIVATE (self);
412 menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/FolderViewContextMenu");
414 return show_context_popup_menu (self,
415 GTK_TREE_VIEW (folder_view),
424 show_context_popup_menu (ModestMainWindow *window,
425 GtkTreeView *tree_view,
426 GdkEventButton *event,
429 g_return_val_if_fail (menu, FALSE);
432 /* Ensure that the header is selected */
433 GtkTreeSelection *selection;
435 selection = gtk_tree_view_get_selection (tree_view);
437 if (gtk_tree_selection_count_selected_rows (selection) <= 1) {
440 /* Get tree path for row that was clicked */
441 if (gtk_tree_view_get_path_at_pos (tree_view,
446 gtk_tree_selection_unselect_all (selection);
447 gtk_tree_selection_select_path (selection, path);
448 gtk_tree_path_free (path);
453 if (gtk_tree_selection_count_selected_rows(selection) == 1)
454 gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
456 event->button, event->time);