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>
33 #include "modest-main-window.h"
34 #include "modest-widget-factory.h"
35 #include "modest-widget-memory.h"
36 #include "modest-icon-factory.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-platform-factory.h"
44 #include "modest-tny-msg-actions.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);
63 typedef struct _ModestMainWindowPrivate ModestMainWindowPrivate;
64 struct _ModestMainWindowPrivate {
66 GtkUIManager *ui_manager;
67 ModestWidgetFactory *widget_factory;
68 TnyPlatformFactory *factory;
69 ModestTnyAccountStore *account_store;
74 GtkWidget *folder_paned;
76 GtkWidget *main_paned;
78 ModestHeaderView *header_view;
79 ModestFolderView *folder_view;
80 ModestMsgView *msg_preview;
84 #define MODEST_MAIN_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
85 MODEST_TYPE_MAIN_WINDOW, \
86 ModestMainWindowPrivate))
88 typedef struct _GetMsgAsyncHelper {
89 ModestMainWindowPrivate *main_window_private;
91 ModestMailOperationReplyType reply_type;
92 ModestMailOperationForwardType forward_type;
98 static GtkWindowClass *parent_class = NULL;
100 /* uncomment the following if you have defined any signals */
101 /* static guint signals[LAST_SIGNAL] = {0}; */
104 modest_main_window_get_type (void)
106 static GType my_type = 0;
108 static const GTypeInfo my_info = {
109 sizeof(ModestMainWindowClass),
110 NULL, /* base init */
111 NULL, /* base finalize */
112 (GClassInitFunc) modest_main_window_class_init,
113 NULL, /* class finalize */
114 NULL, /* class data */
115 sizeof(ModestMainWindow),
117 (GInstanceInitFunc) modest_main_window_init,
120 my_type = g_type_register_static (GTK_TYPE_WINDOW,
128 modest_main_window_class_init (ModestMainWindowClass *klass)
130 GObjectClass *gobject_class;
131 gobject_class = (GObjectClass*) klass;
133 parent_class = g_type_class_peek_parent (klass);
134 gobject_class->finalize = modest_main_window_finalize;
136 g_type_class_add_private (gobject_class, sizeof(ModestMainWindowPrivate));
138 /* signal definitions go here, e.g.: */
139 /* signals[MY_SIGNAL_1] = */
140 /* g_signal_new ("my_signal_1",....); */
141 /* signals[MY_SIGNAL_2] = */
142 /* g_signal_new ("my_signal_2",....); */
147 modest_main_window_init (ModestMainWindow *obj)
149 ModestMainWindowPrivate *priv;
151 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
153 priv->factory = modest_tny_platform_factory_get_instance ();
154 priv->widget_factory = NULL;
155 priv->ui_manager = NULL;
156 priv->account_store = NULL;
160 modest_main_window_finalize (GObject *obj)
162 ModestMainWindowPrivate *priv;
163 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
164 if (priv->widget_factory) {
165 g_object_unref (G_OBJECT(priv->widget_factory));
166 priv->widget_factory = NULL;
168 if (priv->ui_manager) {
169 g_object_unref (G_OBJECT(priv->ui_manager));
170 priv->ui_manager = NULL;
172 if (priv->account_store) {
173 g_object_unref (G_OBJECT(priv->account_store));
174 priv->account_store = NULL;
177 G_OBJECT_CLASS(parent_class)->finalize (obj);
181 static ModestHeaderView*
182 header_view_new (ModestMainWindow *self)
184 ModestHeaderView *header_view;
185 ModestMainWindowPrivate *priv;
186 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
188 header_view = modest_widget_factory_get_header_view (priv->widget_factory);
189 modest_header_view_set_style (header_view, MODEST_HEADER_VIEW_STYLE_DETAILS);
195 restore_sizes (ModestMainWindow *self)
198 ModestMainWindowPrivate *priv;
200 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
201 conf = modest_tny_platform_factory_get_conf_instance
202 (MODEST_TNY_PLATFORM_FACTORY(priv->factory));
204 modest_widget_memory_restore (conf, G_OBJECT(priv->folder_paned),
205 "modest-folder-paned");
206 modest_widget_memory_restore (conf, G_OBJECT(priv->msg_paned),
208 modest_widget_memory_restore (conf, G_OBJECT(priv->main_paned),
209 "modest-main-paned");
210 modest_widget_memory_restore (conf, G_OBJECT(priv->header_view),
212 modest_widget_memory_restore (conf,G_OBJECT(self),
213 "modest-main-window");
218 save_sizes (ModestMainWindow *self)
220 ModestMainWindowPrivate *priv;
223 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
224 conf = modest_tny_platform_factory_get_conf_instance
225 (MODEST_TNY_PLATFORM_FACTORY(priv->factory));
227 modest_widget_memory_save (conf,G_OBJECT(self), "modest-main-window");
228 modest_widget_memory_save (conf, G_OBJECT(priv->folder_paned),
229 "modest-folder-paned");
230 modest_widget_memory_save (conf, G_OBJECT(priv->msg_paned),
232 modest_widget_memory_save (conf, G_OBJECT(priv->main_paned),
233 "modest-main-paned");
234 modest_widget_memory_save (conf, G_OBJECT(priv->header_view), "header-view");
238 wrapped_in_scrolled_window (GtkWidget *widget, gboolean needs_viewport)
242 win = gtk_scrolled_window_new (NULL, NULL);
243 gtk_scrolled_window_set_policy
244 (GTK_SCROLLED_WINDOW (win),GTK_POLICY_NEVER,
245 GTK_POLICY_AUTOMATIC);
248 gtk_scrolled_window_add_with_viewport
249 (GTK_SCROLLED_WINDOW(win), widget);
251 gtk_container_add (GTK_CONTAINER(win),
259 on_delete_event (GtkWidget *widget, GdkEvent *event, ModestMainWindow *self)
267 modest_main_window_new (ModestWidgetFactory *widget_factory,
268 TnyAccountStore *account_store)
271 ModestMainWindowPrivate *priv;
272 GtkWidget *main_vbox;
273 GtkWidget *status_hbox;
274 GtkWidget *header_win, *folder_win;
275 GtkActionGroup *action_group;
276 GError *error = NULL;
278 g_return_val_if_fail (widget_factory, NULL);
280 obj = g_object_new(MODEST_TYPE_MAIN_WINDOW, NULL);
281 priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
283 priv->widget_factory = g_object_ref (widget_factory);
284 priv->account_store = g_object_ref (account_store);
286 /* ***************** */
287 priv->ui_manager = gtk_ui_manager_new();
288 action_group = gtk_action_group_new ("ModestMainWindowActions");
290 /* Add common actions */
291 gtk_action_group_add_actions (action_group,
292 modest_action_entries,
293 G_N_ELEMENTS (modest_action_entries),
296 gtk_ui_manager_insert_action_group (priv->ui_manager, action_group, 0);
297 g_object_unref (action_group);
299 /* Load the UI definition */
300 gtk_ui_manager_add_ui_from_file (priv->ui_manager, MODEST_UIDIR "modest-ui.xml", &error);
302 g_warning ("Could not merge modest-ui.xml: %s", error->message);
303 g_error_free (error);
306 /* *************** */
307 /* priv->ui_manager = g_object_ref (ui_manager); */
309 /* Add accelerators */
310 gtk_window_add_accel_group (GTK_WINDOW (obj),
311 gtk_ui_manager_get_accel_group (priv->ui_manager));
314 /* Toolbar / Menubar */
315 priv->toolbar = gtk_ui_manager_get_widget (priv->ui_manager, "/ToolBar");
316 priv->menubar = gtk_ui_manager_get_widget (priv->ui_manager, "/MenuBar");
318 gtk_toolbar_set_tooltips (GTK_TOOLBAR (priv->toolbar), TRUE);
320 /* widgets from factory */
321 priv->folder_view = modest_widget_factory_get_folder_view (widget_factory);
322 priv->header_view = header_view_new (MODEST_MAIN_WINDOW(obj));
323 priv->msg_preview = modest_widget_factory_get_msg_preview (widget_factory);
325 folder_win = wrapped_in_scrolled_window (GTK_WIDGET(priv->folder_view),
327 header_win = wrapped_in_scrolled_window (GTK_WIDGET(priv->header_view),
331 priv->folder_paned = gtk_vpaned_new ();
332 priv->msg_paned = gtk_vpaned_new ();
333 priv->main_paned = gtk_hpaned_new ();
334 gtk_paned_add1 (GTK_PANED(priv->main_paned), folder_win);
335 gtk_paned_add2 (GTK_PANED(priv->main_paned), priv->msg_paned);
336 gtk_paned_add1 (GTK_PANED(priv->msg_paned), header_win);
337 gtk_paned_add2 (GTK_PANED(priv->msg_paned), GTK_WIDGET(priv->msg_preview));
339 gtk_widget_show (GTK_WIDGET(priv->header_view));
341 /* status bar / progress */
342 status_hbox = gtk_hbox_new (FALSE, 0);
343 gtk_box_pack_start (GTK_BOX(status_hbox),
344 modest_widget_factory_get_folder_info_label (widget_factory),
346 gtk_box_pack_start (GTK_BOX(status_hbox),
347 modest_widget_factory_get_status_bar(widget_factory),
349 gtk_box_pack_start (GTK_BOX(status_hbox),
350 modest_widget_factory_get_progress_bar(widget_factory),
352 gtk_box_pack_start (GTK_BOX(status_hbox),
353 modest_widget_factory_get_online_toggle(widget_factory),
356 /* putting it all together... */
357 main_vbox = gtk_vbox_new (FALSE, 6);
358 gtk_box_pack_start (GTK_BOX(main_vbox), priv->menubar, FALSE, FALSE, 0);
359 gtk_box_pack_start (GTK_BOX(main_vbox), priv->toolbar, FALSE, FALSE, 0);
360 gtk_box_pack_start (GTK_BOX(main_vbox), priv->main_paned, TRUE, TRUE,0);
361 gtk_box_pack_start (GTK_BOX(main_vbox), status_hbox, FALSE, FALSE, 0);
363 gtk_container_add (GTK_CONTAINER(obj), main_vbox);
364 restore_sizes (MODEST_MAIN_WINDOW(obj));
366 gtk_window_set_title (GTK_WINDOW(obj), _("Modest"));
367 gtk_window_set_icon (GTK_WINDOW(obj),
368 modest_icon_factory_get_icon (MODEST_APP_ICON));
369 gtk_widget_show_all (main_vbox);
371 g_signal_connect (G_OBJECT(obj), "delete-event",
372 G_CALLBACK(on_delete_event), obj);
374 return (ModestWindow *) obj;
377 ModestWidgetFactory *
378 modest_main_window_get_widget_factory (ModestMainWindow *main_window)
380 ModestMainWindowPrivate *priv;
382 g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (main_window), NULL);
384 priv = MODEST_MAIN_WINDOW_GET_PRIVATE (main_window);
386 return g_object_ref (priv->widget_factory);
390 modest_main_window_get_account_store (ModestMainWindow *main_window)
392 ModestMainWindowPrivate *priv;
394 g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (main_window), NULL);
396 priv = MODEST_MAIN_WINDOW_GET_PRIVATE (main_window);
398 return g_object_ref (priv->account_store);