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 <hildon-widgets/hildon-window.h>
32 #include <glib/gi18n.h>
33 #include <gtk/gtktreeviewcolumn.h>
35 #include <widgets/modest-main-window.h>
36 #include <widgets/modest-edit-msg-window.h>
37 #include <modest-widget-factory.h>
38 #include "modest-widget-memory.h"
39 #include "modest-window-priv.h"
40 #include "modest-icon-factory.h"
41 #include "modest-ui.h"
42 #include "modest-main-window-ui.h"
43 #include "modest-account-view-window.h"
44 #include "modest-account-mgr.h"
45 #include "modest-conf.h"
47 #include "modest-tny-platform-factory.h"
48 #include "modest-tny-msg-actions.h"
49 #include "modest-mail-operation.h"
50 #include "modest-icon-names.h"
52 /* 'private'/'protected' functions */
53 static void modest_main_window_class_init (ModestMainWindowClass *klass);
54 static void modest_main_window_init (ModestMainWindow *obj);
55 static void modest_main_window_finalize (GObject *obj);
57 static void restore_sizes (ModestMainWindow *self);
58 static void save_sizes (ModestMainWindow *self);
67 typedef struct _ModestMainWindowPrivate ModestMainWindowPrivate;
68 struct _ModestMainWindowPrivate {
71 GtkWidget *main_paned;
73 ModestHeaderView *header_view;
74 ModestFolderView *folder_view;
75 ModestMsgView *msg_preview;
79 #define MODEST_MAIN_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
80 MODEST_TYPE_MAIN_WINDOW, \
81 ModestMainWindowPrivate))
83 typedef struct _GetMsgAsyncHelper {
84 ModestMainWindowPrivate *main_window_private;
86 ModestMailOperationReplyType reply_type;
87 ModestMailOperationForwardType forward_type;
93 static GtkWindowClass *parent_class = NULL;
95 /* uncomment the following if you have defined any signals */
96 /* static guint signals[LAST_SIGNAL] = {0}; */
99 modest_main_window_get_type (void)
101 static GType my_type = 0;
103 static const GTypeInfo my_info = {
104 sizeof(ModestMainWindowClass),
105 NULL, /* base init */
106 NULL, /* base finalize */
107 (GClassInitFunc) modest_main_window_class_init,
108 NULL, /* class finalize */
109 NULL, /* class data */
110 sizeof(ModestMainWindow),
112 (GInstanceInitFunc) modest_main_window_init,
115 my_type = g_type_register_static (MODEST_TYPE_WINDOW,
123 modest_main_window_class_init (ModestMainWindowClass *klass)
125 GObjectClass *gobject_class;
126 gobject_class = (GObjectClass*) klass;
128 parent_class = g_type_class_peek_parent (klass);
129 gobject_class->finalize = modest_main_window_finalize;
131 g_type_class_add_private (gobject_class, sizeof(ModestMainWindowPrivate));
135 modest_main_window_init (ModestMainWindow *obj)
137 ModestMainWindowPrivate *priv;
139 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
141 priv->msg_paned = NULL;
142 priv->main_paned = NULL;
143 priv->header_view = NULL;
144 priv->folder_view = NULL;
145 priv->msg_preview = NULL;
149 modest_main_window_finalize (GObject *obj)
151 G_OBJECT_CLASS(parent_class)->finalize (obj);
155 static ModestHeaderView*
156 header_view_new (ModestMainWindow *self)
158 ModestHeaderView *header_view;
159 ModestWindowPrivate *parent_priv;
161 parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
162 header_view = modest_widget_factory_get_header_view (parent_priv->widget_factory);
163 modest_header_view_set_style (header_view, 0); /* don't show headers */
170 restore_sizes (ModestMainWindow *self)
173 ModestMainWindowPrivate *priv;
174 ModestWindowPrivate *parent_priv;
176 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
177 parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
179 conf = modest_tny_platform_factory_get_conf_instance
180 (MODEST_TNY_PLATFORM_FACTORY(parent_priv->plat_factory));
182 modest_widget_memory_restore (conf,G_OBJECT(self),
183 "modest-main-window");
184 modest_widget_memory_restore (conf, G_OBJECT(priv->main_paned),
185 "modest-main-paned");
186 modest_widget_memory_restore (conf, G_OBJECT(priv->header_view),
192 save_sizes (ModestMainWindow *self)
194 ModestMainWindowPrivate *priv;
195 ModestWindowPrivate *parent_priv;
198 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
199 parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
201 conf = modest_tny_platform_factory_get_conf_instance
202 (MODEST_TNY_PLATFORM_FACTORY (parent_priv->plat_factory));
204 modest_widget_memory_save (conf,G_OBJECT(self), "modest-main-window");
205 modest_widget_memory_save (conf, G_OBJECT(priv->main_paned),
206 "modest-main-paned");
207 modest_widget_memory_save (conf, G_OBJECT(priv->header_view), "header-view");
211 wrapped_in_scrolled_window (GtkWidget *widget, gboolean needs_viewport)
215 win = gtk_scrolled_window_new (NULL, NULL);
216 gtk_scrolled_window_set_policy
217 (GTK_SCROLLED_WINDOW (win),GTK_POLICY_NEVER,
218 GTK_POLICY_AUTOMATIC);
221 gtk_scrolled_window_add_with_viewport
222 (GTK_SCROLLED_WINDOW(win), widget);
224 gtk_container_add (GTK_CONTAINER(win),
232 on_delete_event (GtkWidget *widget, GdkEvent *event, ModestMainWindow *self)
239 menubar_to_menu (GtkUIManager *ui_manager)
241 GtkWidget *main_menu;
245 /* Create new main menu */
246 main_menu = gtk_menu_new();
248 /* Get the menubar from the UI manager */
249 menubar = gtk_ui_manager_get_widget (ui_manager, "/MenuBar");
251 iter = gtk_container_get_children (GTK_CONTAINER (menubar));
255 menu = GTK_WIDGET (iter->data);
256 gtk_widget_reparent(menu, main_menu);
258 iter = g_list_next (iter);
264 modest_main_window_new (ModestWidgetFactory *widget_factory,
265 TnyAccountStore *account_store)
268 ModestMainWindowPrivate *priv;
269 ModestWindowPrivate *parent_priv;
270 GtkWidget *main_vbox;
271 GtkWidget *status_hbox;
272 GtkWidget *header_win, *folder_win;
273 GtkActionGroup *action_group;
274 GError *error = NULL;
276 g_return_val_if_fail (widget_factory, NULL);
278 obj = g_object_new(MODEST_TYPE_MAIN_WINDOW, NULL);
280 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
281 parent_priv = MODEST_WINDOW_GET_PRIVATE(obj);
283 parent_priv->widget_factory = g_object_ref (widget_factory);
284 parent_priv->account_store = g_object_ref (account_store);
286 parent_priv->ui_manager = gtk_ui_manager_new();
287 action_group = gtk_action_group_new ("ModestMainWindowActions");
289 /* Add common actions */
290 gtk_action_group_add_actions (action_group,
291 modest_action_entries,
292 G_N_ELEMENTS (modest_action_entries),
295 gtk_ui_manager_insert_action_group (parent_priv->ui_manager, action_group, 0);
296 g_object_unref (action_group);
298 /* Load the UI definition */
299 gtk_ui_manager_add_ui_from_file (parent_priv->ui_manager, MODEST_UIDIR "modest-ui.xml", &error);
301 g_warning ("Could not merge modest-ui.xml: %s", error->message);
302 g_error_free (error);
306 /* Add accelerators */
307 gtk_window_add_accel_group (GTK_WINDOW (obj),
308 gtk_ui_manager_get_accel_group (parent_priv->ui_manager));
312 parent_priv->toolbar = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar");
313 hildon_window_add_toolbar (HILDON_WINDOW (obj), GTK_TOOLBAR (parent_priv->toolbar));
316 parent_priv->menubar = menubar_to_menu (parent_priv->ui_manager);
317 hildon_window_set_menu (HILDON_WINDOW (obj), GTK_MENU (parent_priv->menubar));
319 /* widgets from factory */
320 priv->folder_view = modest_widget_factory_get_folder_view (widget_factory);
321 priv->header_view = header_view_new (MODEST_MAIN_WINDOW(obj));
322 priv->msg_preview = modest_widget_factory_get_msg_preview (widget_factory);
324 folder_win = wrapped_in_scrolled_window (GTK_WIDGET(priv->folder_view),
326 header_win = wrapped_in_scrolled_window (GTK_WIDGET(priv->header_view),
330 priv->main_paned = gtk_hpaned_new ();
331 gtk_paned_add1 (GTK_PANED(priv->main_paned), folder_win);
332 gtk_paned_add2 (GTK_PANED(priv->main_paned), header_win);
333 gtk_widget_show (GTK_WIDGET(priv->header_view));
335 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(priv->header_view));
338 /* status bar / progress */
339 status_hbox = gtk_hbox_new (FALSE, 0);
340 gtk_box_pack_start (GTK_BOX(status_hbox),
341 modest_widget_factory_get_folder_info_label (widget_factory),
343 gtk_box_pack_start (GTK_BOX(status_hbox),
344 modest_widget_factory_get_status_bar(widget_factory),
346 gtk_box_pack_start (GTK_BOX(status_hbox),
347 modest_widget_factory_get_progress_bar(widget_factory),
349 gtk_box_pack_start (GTK_BOX(status_hbox),
350 modest_widget_factory_get_online_toggle(widget_factory),
353 /* putting it all together... */
354 main_vbox = gtk_vbox_new (FALSE, 6);
355 gtk_box_pack_start (GTK_BOX(main_vbox), priv->main_paned, TRUE, TRUE,0);
356 /* gtk_box_pack_start (GTK_BOX(main_vbox), parent_priv->toolbar, FALSE, FALSE, 0); */
357 gtk_box_pack_start (GTK_BOX(main_vbox), status_hbox, FALSE, FALSE, 0);
360 gtk_container_add (GTK_CONTAINER(obj), main_vbox);
361 restore_sizes (MODEST_MAIN_WINDOW(obj));
363 gtk_window_set_title (GTK_WINDOW(obj), _("Modest"));
364 gtk_window_set_icon (GTK_WINDOW(obj),
365 modest_icon_factory_get_icon (MODEST_APP_ICON));
367 gtk_widget_show_all (main_vbox);
369 g_signal_connect (G_OBJECT(obj), "delete-event",
370 G_CALLBACK(on_delete_event), obj);
372 return (ModestWindow *) obj;