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-icon-factory.h"
38 #include "modest-ui.h"
39 #include "modest-main-window-ui.h"
40 #include "modest-account-view-window.h"
41 #include "modest-account-mgr.h"
42 #include "modest-conf.h"
43 #include "modest-edit-msg-window.h"
44 #include <modest-tny-msg.h>
45 #include "modest-mail-operation.h"
46 #include "modest-icon-names.h"
48 /* 'private'/'protected' functions */
49 static void modest_main_window_class_init (ModestMainWindowClass *klass);
50 static void modest_main_window_init (ModestMainWindow *obj);
51 static void modest_main_window_finalize (GObject *obj);
53 static void restore_sizes (ModestMainWindow *self);
54 static void save_sizes (ModestMainWindow *self);
56 static gboolean on_header_view_button_press_event (ModestHeaderView *header_view,
57 GdkEventButton *event,
58 ModestMainWindow *self);
60 static gboolean on_folder_view_button_press_event (ModestFolderView *folder_view,
61 GdkEventButton *event,
62 ModestMainWindow *self);
64 static gboolean show_context_popup_menu (ModestMainWindow *window,
65 GtkTreeView *tree_view,
66 GdkEventButton *event,
76 typedef struct _ModestMainWindowPrivate ModestMainWindowPrivate;
77 struct _ModestMainWindowPrivate {
79 GtkWidget *folder_paned;
81 GtkWidget *main_paned;
83 ModestHeaderView *header_view;
84 ModestFolderView *folder_view;
85 ModestMsgView *msg_preview;
89 #define MODEST_MAIN_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
90 MODEST_TYPE_MAIN_WINDOW, \
91 ModestMainWindowPrivate))
93 typedef struct _GetMsgAsyncHelper {
94 ModestMainWindowPrivate *main_window_private;
96 ModestMailOperationReplyType reply_type;
97 ModestMailOperationForwardType forward_type;
103 static GtkWindowClass *parent_class = NULL;
105 /* uncomment the following if you have defined any signals */
106 /* static guint signals[LAST_SIGNAL] = {0}; */
109 modest_main_window_get_type (void)
111 static GType my_type = 0;
113 static const GTypeInfo my_info = {
114 sizeof(ModestMainWindowClass),
115 NULL, /* base init */
116 NULL, /* base finalize */
117 (GClassInitFunc) modest_main_window_class_init,
118 NULL, /* class finalize */
119 NULL, /* class data */
120 sizeof(ModestMainWindow),
122 (GInstanceInitFunc) modest_main_window_init,
125 my_type = g_type_register_static (MODEST_TYPE_WINDOW,
133 modest_main_window_class_init (ModestMainWindowClass *klass)
135 GObjectClass *gobject_class;
136 gobject_class = (GObjectClass*) klass;
138 parent_class = g_type_class_peek_parent (klass);
139 gobject_class->finalize = modest_main_window_finalize;
141 g_type_class_add_private (gobject_class, sizeof(ModestMainWindowPrivate));
145 modest_main_window_init (ModestMainWindow *obj)
147 ModestMainWindowPrivate *priv;
149 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
151 priv->folder_paned = NULL;
152 priv->msg_paned = NULL;
153 priv->main_paned = NULL;
154 priv->header_view = NULL;
155 priv->folder_view = NULL;
156 priv->msg_preview = NULL;
160 modest_main_window_finalize (GObject *obj)
162 G_OBJECT_CLASS(parent_class)->finalize (obj);
166 static ModestHeaderView*
167 header_view_new (ModestMainWindow *self)
169 ModestHeaderView *header_view;
171 header_view = modest_widget_factory_get_header_view
172 (modest_runtime_get_widget_factory());
173 modest_header_view_set_style
174 (header_view, MODEST_HEADER_VIEW_STYLE_DETAILS);
181 restore_sizes (ModestMainWindow *self)
184 ModestMainWindowPrivate *priv;
185 ModestWindowPrivate *parent_priv;
187 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
188 parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
190 conf = modest_runtime_get_conf ();
192 modest_widget_memory_restore (conf, G_OBJECT(priv->folder_paned),
193 "modest-folder-paned");
194 modest_widget_memory_restore (conf, G_OBJECT(priv->msg_paned),
196 modest_widget_memory_restore (conf, G_OBJECT(priv->main_paned),
197 "modest-main-paned");
198 modest_widget_memory_restore (conf, G_OBJECT(priv->header_view),
200 modest_widget_memory_restore (conf,G_OBJECT(self),
201 "modest-main-window");
206 save_sizes (ModestMainWindow *self)
208 ModestWindowPrivate *parent_priv;
209 ModestMainWindowPrivate *priv;
212 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
213 parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
215 conf = modest_runtime_get_conf ();
217 modest_widget_memory_save (conf,G_OBJECT(self), "modest-main-window");
218 modest_widget_memory_save (conf, G_OBJECT(priv->folder_paned),
219 "modest-folder-paned");
220 modest_widget_memory_save (conf, G_OBJECT(priv->msg_paned),
222 modest_widget_memory_save (conf, G_OBJECT(priv->main_paned),
223 "modest-main-paned");
224 modest_widget_memory_save (conf, G_OBJECT(priv->header_view), "header-view");
228 wrapped_in_scrolled_window (GtkWidget *widget, gboolean needs_viewport)
232 win = gtk_scrolled_window_new (NULL, NULL);
233 gtk_scrolled_window_set_policy
234 (GTK_SCROLLED_WINDOW (win),GTK_POLICY_NEVER,
235 GTK_POLICY_AUTOMATIC);
238 gtk_scrolled_window_add_with_viewport
239 (GTK_SCROLLED_WINDOW(win), widget);
241 gtk_container_add (GTK_CONTAINER(win),
249 on_delete_event (GtkWidget *widget, GdkEvent *event, ModestMainWindow *self)
257 modest_main_window_new (void)
260 ModestMainWindowPrivate *priv;
261 ModestWindowPrivate *parent_priv;
262 GtkWidget *main_vbox;
263 GtkWidget *status_hbox;
264 GtkWidget *header_win, *folder_win;
265 ModestWidgetFactory *widget_factory;
266 GtkActionGroup *action_group;
267 GError *error = NULL;
270 obj = g_object_new(MODEST_TYPE_MAIN_WINDOW, NULL);
271 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
272 parent_priv = MODEST_WINDOW_GET_PRIVATE(obj);
274 /* ***************** */
275 parent_priv->ui_manager = gtk_ui_manager_new();
276 action_group = gtk_action_group_new ("ModestMainWindowActions");
278 widget_factory = modest_runtime_get_widget_factory ();
280 /* Add common actions */
281 gtk_action_group_add_actions (action_group,
282 modest_action_entries,
283 G_N_ELEMENTS (modest_action_entries),
286 gtk_ui_manager_insert_action_group (parent_priv->ui_manager, action_group, 0);
287 g_object_unref (action_group);
289 /* Load the UI definition */
290 gtk_ui_manager_add_ui_from_file (parent_priv->ui_manager, MODEST_UIDIR "modest-ui.xml", &error);
292 g_printerr ("modest: could not merge modest-ui.xml: %s", error->message);
293 g_error_free (error);
296 /* *************** */
298 /* Add accelerators */
299 gtk_window_add_accel_group (GTK_WINDOW (obj),
300 gtk_ui_manager_get_accel_group (parent_priv->ui_manager));
302 /* Toolbar / Menubar */
303 parent_priv->toolbar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar");
304 parent_priv->menubar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/MenuBar");
306 gtk_toolbar_set_tooltips (GTK_TOOLBAR (parent_priv->toolbar), TRUE);
308 /* widgets from factory */
309 priv->folder_view = modest_widget_factory_get_folder_view (widget_factory);
310 priv->header_view = header_view_new (MODEST_MAIN_WINDOW(obj));
311 priv->msg_preview = modest_widget_factory_get_msg_preview (widget_factory);
313 folder_win = wrapped_in_scrolled_window (GTK_WIDGET(priv->folder_view),
315 header_win = wrapped_in_scrolled_window (GTK_WIDGET(priv->header_view),
318 /* Connect platform specific signals */
319 g_signal_connect (priv->header_view,
320 "button-press-event",
321 G_CALLBACK (on_header_view_button_press_event),
323 g_signal_connect (priv->header_view,
325 G_CALLBACK (on_header_view_button_press_event),
327 g_signal_connect (priv->folder_view,
328 "button-press-event",
329 G_CALLBACK (on_folder_view_button_press_event),
331 g_signal_connect (priv->folder_view,
333 G_CALLBACK (on_folder_view_button_press_event),
337 priv->folder_paned = gtk_vpaned_new ();
338 priv->msg_paned = gtk_vpaned_new ();
339 priv->main_paned = gtk_hpaned_new ();
340 gtk_paned_add1 (GTK_PANED(priv->main_paned), folder_win);
341 gtk_paned_add2 (GTK_PANED(priv->main_paned), priv->msg_paned);
342 gtk_paned_add1 (GTK_PANED(priv->msg_paned), header_win);
343 gtk_paned_add2 (GTK_PANED(priv->msg_paned), GTK_WIDGET(priv->msg_preview));
345 gtk_widget_show (GTK_WIDGET(priv->header_view));
347 /* status bar / progress */
348 status_hbox = gtk_hbox_new (FALSE, 0);
349 gtk_box_pack_start (GTK_BOX(status_hbox),
350 modest_widget_factory_get_folder_info_label (widget_factory),
352 gtk_box_pack_start (GTK_BOX(status_hbox),
353 modest_widget_factory_get_status_bar(widget_factory),
355 gtk_box_pack_start (GTK_BOX(status_hbox),
356 modest_widget_factory_get_progress_bar(widget_factory),
358 gtk_box_pack_start (GTK_BOX(status_hbox),
359 modest_widget_factory_get_online_toggle(widget_factory),
362 /* putting it all together... */
363 main_vbox = gtk_vbox_new (FALSE, 6);
364 gtk_box_pack_start (GTK_BOX(main_vbox), parent_priv->menubar, FALSE, FALSE, 0);
365 gtk_box_pack_start (GTK_BOX(main_vbox), parent_priv->toolbar, FALSE, FALSE, 0);
366 gtk_box_pack_start (GTK_BOX(main_vbox), priv->main_paned, TRUE, TRUE,0);
367 gtk_box_pack_start (GTK_BOX(main_vbox), status_hbox, FALSE, FALSE, 0);
369 gtk_container_add (GTK_CONTAINER(obj), main_vbox);
370 restore_sizes (MODEST_MAIN_WINDOW(obj));
372 gtk_window_set_title (GTK_WINDOW(obj), _("Modest"));
373 gtk_window_set_icon (GTK_WINDOW(obj),
374 modest_icon_factory_get_icon (MODEST_APP_ICON));
375 gtk_widget_show_all (main_vbox);
377 g_signal_connect (G_OBJECT(obj), "delete-event",
378 G_CALLBACK(on_delete_event), obj);
380 return (ModestWindow *) obj;
384 on_header_view_button_press_event (ModestHeaderView *header_view,
385 GdkEventButton *event,
386 ModestMainWindow *self)
388 if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
390 ModestWindowPrivate *parent_priv;
392 parent_priv = MODEST_WINDOW_GET_PRIVATE (self);
393 menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/HeaderViewContextMenu");
395 return show_context_popup_menu (self,
396 GTK_TREE_VIEW (header_view),
405 on_folder_view_button_press_event (ModestFolderView *folder_view,
406 GdkEventButton *event,
407 ModestMainWindow *self)
409 if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
411 ModestWindowPrivate *parent_priv;
413 parent_priv = MODEST_WINDOW_GET_PRIVATE (self);
414 menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/FolderViewContextMenu");
416 return show_context_popup_menu (self,
417 GTK_TREE_VIEW (folder_view),
426 show_context_popup_menu (ModestMainWindow *window,
427 GtkTreeView *tree_view,
428 GdkEventButton *event,
431 g_return_val_if_fail (menu, FALSE);
434 /* Ensure that the header is selected */
435 GtkTreeSelection *selection;
437 selection = gtk_tree_view_get_selection (tree_view);
439 if (gtk_tree_selection_count_selected_rows (selection) <= 1) {
442 /* Get tree path for row that was clicked */
443 if (gtk_tree_view_get_path_at_pos (tree_view,
448 gtk_tree_selection_unselect_all (selection);
449 gtk_tree_selection_select_path (selection, path);
450 gtk_tree_path_free (path);
455 if (gtk_tree_selection_count_selected_rows(selection) == 1)
456 gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
458 event->button, event->time);