* Added application wide toolbars to the pending windows
[modest] / src / maemo / modest-main-window.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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.
16  *
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.
28  */
29
30 #include <hildon-widgets/hildon-window.h>
31 #include <hildon-widgets/hildon-note.h>
32
33 #include <glib/gi18n.h>
34 #include <gtk/gtktreeviewcolumn.h>
35 #include <tny-account-store-view.h>
36 #include <modest-runtime.h>
37 #include <string.h>
38
39 #include <widgets/modest-main-window.h>
40 #include <widgets/modest-msg-edit-window.h>
41 #include <widgets/modest-account-view-window.h>
42
43 #include "modest-platform.h"
44 #include "modest-widget-memory.h"
45 #include "modest-window-priv.h"
46 #include "modest-main-window-ui.h"
47 #include "modest-account-mgr.h"
48 #include "modest-conf.h"
49 #include <modest-maemo-utils.h>
50 #include "modest-tny-platform-factory.h"
51 #include "modest-tny-msg.h"
52 #include "modest-mail-operation.h"
53 #include "modest-icon-names.h"
54
55 /* 'private'/'protected' functions */
56 static void modest_main_window_class_init    (ModestMainWindowClass *klass);
57 static void modest_main_window_init          (ModestMainWindow *obj);
58 static void modest_main_window_finalize      (GObject *obj);
59 static gboolean modest_main_window_window_state_event (GtkWidget *widget, 
60                                                            GdkEventWindowState *event, 
61                                                            gpointer userdata);
62
63 static void connect_signals (ModestMainWindow *self);
64 static void restore_sizes (ModestMainWindow *self);
65 static void save_sizes (ModestMainWindow *self);
66
67 static void modest_main_window_create_toolbar (ModestWindow *window);
68 static void modest_main_window_show_toolbar   (ModestWindow *window,
69                                                gboolean show_toolbar);
70
71 /* list my signals */
72 enum {
73         /* MY_SIGNAL_1, */
74         /* MY_SIGNAL_2, */
75         LAST_SIGNAL
76 };
77
78 typedef struct _ModestMainWindowPrivate ModestMainWindowPrivate;
79 struct _ModestMainWindowPrivate {
80         GtkWidget *msg_paned;
81         GtkWidget *main_paned;
82         GtkWidget *main_vbox;
83         GtkWidget *progress_bar;
84
85         ModestHeaderView *header_view;
86         ModestFolderView *folder_view;
87
88         ModestMainWindowStyle style;
89 };
90 #define MODEST_MAIN_WINDOW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
91                                                 MODEST_TYPE_MAIN_WINDOW, \
92                                                 ModestMainWindowPrivate))
93
94 typedef struct _GetMsgAsyncHelper {
95         ModestMainWindowPrivate *main_window_private;
96         guint action;
97         ModestTnyMsgReplyType reply_type;
98         ModestTnyMsgForwardType forward_type;
99         gchar *from;
100         TnyIterator *iter;
101 } GetMsgAsyncHelper;
102
103
104 /* globals */
105 static GtkWindowClass *parent_class = NULL;
106
107 /* uncomment the following if you have defined any signals */
108 /* static guint signals[LAST_SIGNAL] = {0}; */
109
110 GType
111 modest_main_window_get_type (void)
112 {
113         static GType my_type = 0;
114         if (!my_type) {
115                 static const GTypeInfo my_info = {
116                         sizeof(ModestMainWindowClass),
117                         NULL,           /* base init */
118                         NULL,           /* base finalize */
119                         (GClassInitFunc) modest_main_window_class_init,
120                         NULL,           /* class finalize */
121                         NULL,           /* class data */
122                         sizeof(ModestMainWindow),
123                         1,              /* n_preallocs */
124                         (GInstanceInitFunc) modest_main_window_init,
125                         NULL
126                 };
127                 my_type = g_type_register_static (MODEST_TYPE_WINDOW,
128                                                   "ModestMainWindow",
129                                                   &my_info, 0);
130         }
131         return my_type;
132 }
133
134 static void
135 modest_main_window_class_init (ModestMainWindowClass *klass)
136 {
137         GObjectClass *gobject_class;
138         gobject_class = (GObjectClass*) klass;
139         ModestWindowClass *modest_window_class;
140
141         modest_window_class = (ModestWindowClass *) klass;
142
143         parent_class            = g_type_class_peek_parent (klass);
144         gobject_class->finalize = modest_main_window_finalize;
145
146         modest_window_class->create_toolbar_func = modest_main_window_create_toolbar;
147         modest_window_class->show_toolbar_func = modest_main_window_show_toolbar;
148
149         g_type_class_add_private (gobject_class, sizeof(ModestMainWindowPrivate));
150 }
151
152
153 static void
154 on_key_changed (ModestConf* conf, const gchar *key, ModestConfEvent event, ModestMainWindow *win)
155 {
156         TnyAccount *account;
157         
158         if (!key || strcmp (key, MODEST_CONF_DEVICE_NAME) != 0)
159                 return; /* wrong key */
160         
161         /* ok, the device name changed; thus, we have to update the
162          * local folder account name*/
163         account =
164                 modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
165                                                                      MODEST_LOCAL_FOLDERS_ACCOUNT_ID,
166                                                                      TNY_ACCOUNT_TYPE_STORE);
167         if (!account) {
168                 g_printerr ("modest: could not get account\n");
169                 return;
170         }
171
172         if (event == MODEST_CONF_EVENT_KEY_UNSET) 
173                 tny_account_set_name (account, MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME);
174         else {
175                 gchar *device_name = modest_conf_get_string (modest_runtime_get_conf(),
176                                                              MODEST_CONF_DEVICE_NAME, NULL);
177                 tny_account_set_name (account, device_name);
178                 g_free (device_name);
179         }
180         g_object_unref (G_OBJECT(account));     
181 }
182
183 static void
184 modest_main_window_init (ModestMainWindow *obj)
185 {
186         ModestMainWindowPrivate *priv;
187
188         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
189
190         priv->msg_paned    = NULL;
191         priv->main_paned   = NULL;      
192         priv->main_vbox    = NULL;
193         priv->header_view  = NULL;
194         priv->folder_view  = NULL;
195         priv->style  = MODEST_MAIN_WINDOW_STYLE_SPLIT;
196
197         /* progress bar */
198         priv->progress_bar = gtk_progress_bar_new ();
199         gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(priv->progress_bar), 1.0);
200         gtk_progress_bar_set_ellipsize (GTK_PROGRESS_BAR(priv->progress_bar),
201                                         PANGO_ELLIPSIZE_END);
202 }
203
204 static void
205 modest_main_window_finalize (GObject *obj)
206 {
207         G_OBJECT_CLASS(parent_class)->finalize (obj);
208 }
209
210 GtkWidget*
211 modest_main_window_get_child_widget (ModestMainWindow *self,
212                                      ModestWidgetType widget_type)
213 {
214         ModestMainWindowPrivate *priv;
215         GtkWidget *widget;
216         
217         g_return_val_if_fail (self, NULL);
218         g_return_val_if_fail (widget_type >= 0 && widget_type < MODEST_WIDGET_TYPE_NUM,
219                               NULL);
220         
221         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
222
223         switch (widget_type) {
224         case MODEST_WIDGET_TYPE_HEADER_VIEW:
225                 widget = (GtkWidget*)priv->header_view; break;
226         case MODEST_WIDGET_TYPE_FOLDER_VIEW:
227                 widget = (GtkWidget*)priv->folder_view; break;
228         default:
229                 return NULL;
230         }
231
232         return widget ? GTK_WIDGET(widget) : NULL;
233 }
234
235
236
237 static void
238 restore_sizes (ModestMainWindow *self)
239 {
240         ModestConf *conf;
241         ModestMainWindowPrivate *priv;
242
243         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
244
245         conf = modest_runtime_get_conf ();
246         
247         modest_widget_memory_restore (conf, G_OBJECT(priv->main_paned),
248                                       "modest-main-paned");
249         modest_widget_memory_restore (conf, G_OBJECT(priv->header_view),
250                                       "header-view");
251 }
252
253
254 static void
255 save_sizes (ModestMainWindow *self)
256 {
257         ModestConf *conf;
258         ModestMainWindowPrivate *priv;
259                 
260         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
261         conf = modest_runtime_get_conf ();
262         
263         modest_widget_memory_save (conf,G_OBJECT(self), "modest-main-window");
264         modest_widget_memory_save (conf, G_OBJECT(priv->main_paned),
265                                    "modest-main-paned");
266         modest_widget_memory_save (conf, G_OBJECT(priv->header_view), "header-view");
267 }
268
269 static GtkWidget*
270 wrapped_in_scrolled_window (GtkWidget *widget, gboolean needs_viewport)
271 {
272         GtkWidget *win;
273
274         win = gtk_scrolled_window_new (NULL, NULL);
275         gtk_scrolled_window_set_policy
276                 (GTK_SCROLLED_WINDOW (win),GTK_POLICY_NEVER,
277                  GTK_POLICY_AUTOMATIC);
278         
279         if (needs_viewport)
280                 gtk_scrolled_window_add_with_viewport
281                         (GTK_SCROLLED_WINDOW(win), widget);
282         else
283                 gtk_container_add (GTK_CONTAINER(win),
284                                    widget);
285
286         return win;
287 }
288
289
290 static gboolean
291 on_delete_event (GtkWidget *widget, GdkEvent  *event, ModestMainWindow *self)
292 {
293         save_sizes (self);
294         return FALSE;
295 }
296
297 static void
298 connect_signals (ModestMainWindow *self)
299 {       
300         ModestWindowPrivate *parent_priv;
301         ModestMainWindowPrivate *priv;
302         GtkWidget *menu;
303         
304         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
305         parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
306         
307         /* folder view */
308         g_signal_connect (G_OBJECT(priv->folder_view), "folder_selection_changed",
309                           G_CALLBACK(modest_ui_actions_on_folder_selection_changed), self);
310
311         menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/FolderViewContextMenu");
312         gtk_widget_tap_and_hold_setup (GTK_WIDGET (priv->folder_view), menu, NULL, 0);
313
314         /* header view */
315 /*      g_signal_connect (G_OBJECT(priv->header_view), "status_update", */
316 /*                        G_CALLBACK(modest_ui_actions_on_header_status_update), self); */
317         g_signal_connect (G_OBJECT(priv->header_view), "header_selected",
318                           G_CALLBACK(modest_ui_actions_on_header_selected), self);
319         g_signal_connect (G_OBJECT(priv->header_view), "header_activated",
320                           G_CALLBACK(modest_ui_actions_on_header_activated), self);
321         g_signal_connect (G_OBJECT(priv->header_view), "item_not_found",
322                           G_CALLBACK(modest_ui_actions_on_item_not_found), self);
323
324         /* window */
325         g_signal_connect (G_OBJECT(self), "delete-event", G_CALLBACK(on_delete_event), self);
326         g_signal_connect (G_OBJECT (self), "window-state-event",
327                           G_CALLBACK (modest_main_window_window_state_event),
328                           NULL);
329
330
331         
332         /* modest_maemo_utils_get_device_name will probably change
333          * MODEST_CONF_DEVICE_NAME. If that happens, we update the local folders
334          * account name in the callback
335          */
336         g_signal_connect (G_OBJECT(modest_runtime_get_conf()), "key_changed",
337                           G_CALLBACK(on_key_changed), self);
338         
339         g_signal_connect (G_OBJECT(self), "delete-event", G_CALLBACK(on_delete_event), self);
340 }
341
342
343 gboolean
344 sync_accounts_cb (ModestMainWindow *win)
345 {
346         modest_ui_actions_on_send_receive (NULL, MODEST_WINDOW(win));
347         return FALSE;
348 }
349
350
351 ModestWindow*
352 modest_main_window_new (void)
353 {
354         ModestMainWindow *self; 
355         ModestMainWindowPrivate *priv;
356         ModestWindowPrivate *parent_priv;
357         GtkWidget *header_win, *folder_win;
358         GtkActionGroup *action_group;
359         GError *error = NULL;
360         TnyFolderStoreQuery *query;
361         GdkPixbuf *window_icon;
362         ModestConf *conf;
363         GtkAction *action;
364
365         self  = MODEST_MAIN_WINDOW(g_object_new(MODEST_TYPE_MAIN_WINDOW, NULL));
366         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
367         parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
368
369         parent_priv->ui_manager = gtk_ui_manager_new();
370         action_group = gtk_action_group_new ("ModestMainWindowActions");
371         gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
372
373         /* Add common actions */
374         gtk_action_group_add_actions (action_group,
375                                       modest_action_entries,
376                                       G_N_ELEMENTS (modest_action_entries),
377                                       self);
378
379         gtk_action_group_add_toggle_actions (action_group,
380                                              modest_toggle_action_entries,
381                                              G_N_ELEMENTS (modest_toggle_action_entries),
382                                              self);
383
384         gtk_ui_manager_insert_action_group (parent_priv->ui_manager, action_group, 0);
385         g_object_unref (action_group);
386
387         /* Load the UI definition */
388         gtk_ui_manager_add_ui_from_file (parent_priv->ui_manager,
389                                          MODEST_UIDIR "modest-main-window-ui.xml", &error);
390         if (error != NULL) {
391                 g_warning ("Could not merge modest-ui.xml: %s", error->message);
392                 g_error_free (error);
393                 error = NULL;
394         }
395
396         /* Add accelerators */
397         gtk_window_add_accel_group (GTK_WINDOW (self), 
398                                     gtk_ui_manager_get_accel_group (parent_priv->ui_manager));
399
400         /* Menubar. Update the state of some toggles */
401         parent_priv->menubar = modest_maemo_utils_menubar_to_menu (parent_priv->ui_manager);
402         conf = modest_runtime_get_conf ();
403         action = gtk_ui_manager_get_action (parent_priv->ui_manager, 
404                                             "/MenuBar/ViewMenu/ViewShowToolbarMainMenu/ViewShowToolbarNormalScreenMenu");
405         gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
406                                       modest_conf_get_bool (conf, MODEST_CONF_SHOW_TOOLBAR, NULL));
407         action = gtk_ui_manager_get_action (parent_priv->ui_manager, 
408                                             "/MenuBar/ViewMenu/ViewShowToolbarMainMenu/ViewShowToolbarFullScreenMenu");
409         gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
410                                       modest_conf_get_bool (conf, MODEST_CONF_SHOW_TOOLBAR_FULLSCREEN, NULL));
411         hildon_window_set_menu (HILDON_WINDOW (self), GTK_MENU (parent_priv->menubar));
412
413         /* folder view */
414         query = tny_folder_store_query_new ();
415         tny_folder_store_query_add_item (query, NULL,
416                                          TNY_FOLDER_STORE_QUERY_OPTION_SUBSCRIBED);
417         priv->folder_view = MODEST_FOLDER_VIEW(modest_folder_view_new (query));
418         if (!priv->folder_view)
419                 g_printerr ("modest: cannot instantiate folder view\n");        
420         g_object_unref (G_OBJECT (query));      
421         modest_maemo_utils_get_device_name ();
422
423         /* header view */
424         priv->header_view  =
425                 MODEST_HEADER_VIEW(modest_header_view_new (NULL, MODEST_HEADER_VIEW_STYLE_DETAILS));
426         if (!priv->header_view)
427                 g_printerr ("modest: cannot instantiate header view\n");
428         modest_header_view_set_style (priv->header_view, MODEST_HEADER_VIEW_STYLE_TWOLINES);
429         
430         folder_win = wrapped_in_scrolled_window (GTK_WIDGET(priv->folder_view), FALSE);
431         header_win = wrapped_in_scrolled_window (GTK_WIDGET(priv->header_view), FALSE);
432
433         /* paned */
434         priv->main_paned = gtk_hpaned_new ();
435         gtk_paned_add1 (GTK_PANED(priv->main_paned), folder_win);
436         gtk_paned_add2 (GTK_PANED(priv->main_paned), header_win);
437         gtk_widget_show (GTK_WIDGET(priv->header_view));
438         gtk_tree_view_columns_autosize (GTK_TREE_VIEW(priv->header_view));
439
440         /* putting it all together... */
441         priv->main_vbox = gtk_vbox_new (FALSE, 6);
442         gtk_box_pack_start (GTK_BOX(priv->main_vbox), priv->main_paned, TRUE, TRUE,0);
443
444         gtk_container_add (GTK_CONTAINER(self), priv->main_vbox);
445         restore_sizes (MODEST_MAIN_WINDOW(self));
446
447         /* Set window icon */
448         window_icon = modest_platform_get_icon (MODEST_APP_ICON);
449         gtk_window_set_icon (GTK_WINDOW (self), window_icon);
450
451         /* Connect signals */
452         connect_signals (self);
453
454         /* Set account store */
455         tny_account_store_view_set_account_store (TNY_ACCOUNT_STORE_VIEW (priv->folder_view),
456                                                   TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
457         g_idle_add ((GSourceFunc)sync_accounts_cb, self);
458         /* do send & receive when we are idle */        
459
460         g_message ("online? %s",
461                    tny_device_is_online (modest_runtime_get_device()) ? "yes" : "no");
462                 
463         return MODEST_WINDOW(self);
464 }
465
466 gboolean 
467 modest_main_window_close_all (ModestMainWindow *self)
468 {
469         GtkWidget *note;
470         GtkResponseType response;
471
472         /* Create the confirmation dialog MSG-NOT308 */
473         note = hildon_note_new_confirmation_add_buttons (GTK_WINDOW (self),
474                                                          _("emev_nc_close_windows"),
475                                                          _("mcen_db_yes"), GTK_RESPONSE_YES,
476                                                          _("mcen_db_no"), GTK_RESPONSE_NO,
477                                                          NULL);
478
479         response = gtk_dialog_run (GTK_DIALOG (note));
480         gtk_widget_destroy (GTK_WIDGET (note));
481
482         if (response == GTK_RESPONSE_YES)
483                 return TRUE;
484         else
485                 return FALSE;
486 }
487
488 void 
489 modest_main_window_set_style (ModestMainWindow *self, 
490                               ModestMainWindowStyle style)
491 {
492         ModestMainWindowPrivate *priv;
493         GtkWidget *scrolled_win;
494
495         g_return_if_fail (MODEST_IS_MAIN_WINDOW (self));
496
497         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
498
499         /* no change -> nothing to do */
500         if (priv->style == style)
501                 return;
502
503         priv->style = style;
504         scrolled_win = gtk_widget_get_parent (GTK_WIDGET (priv->header_view));
505
506         switch (style) {
507         case MODEST_MAIN_WINDOW_STYLE_SIMPLE:
508                 /* Remove main paned */
509                 g_object_ref (priv->main_paned);
510                 gtk_container_remove (GTK_CONTAINER (priv->main_vbox), priv->main_paned);
511
512                 /* Reparent header view with scrolled window */
513                 gtk_widget_reparent (scrolled_win, priv->main_vbox);
514                 break;
515         case MODEST_MAIN_WINDOW_STYLE_SPLIT:
516                 /* Remove header view */
517                 g_object_ref (scrolled_win);
518                 gtk_container_remove (GTK_CONTAINER (priv->main_vbox), scrolled_win);
519
520                 /* Reparent the main paned */
521                 gtk_paned_add2 (GTK_PANED (priv->main_paned), scrolled_win);
522                 gtk_container_add (GTK_CONTAINER (priv->main_vbox), priv->main_paned);
523                 break;
524         default:
525                 g_return_if_reached ();
526         }
527
528         /* Show changes */
529         gtk_widget_show (GTK_WIDGET (priv->main_vbox));
530 }
531
532 ModestMainWindowStyle
533 modest_main_window_get_style (ModestMainWindow *self)
534 {
535         ModestMainWindowPrivate *priv;
536
537         g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (self), -1);
538
539         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
540         return priv->style;
541 }
542
543 static gboolean
544 modest_main_window_window_state_event (GtkWidget *widget, GdkEventWindowState *event, gpointer userdata)
545 {
546         if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) {
547                 ModestWindowPrivate *parent_priv;
548                 ModestWindowMgr *mgr;
549                 gboolean is_fullscreen;
550                 GtkAction *fs_toggle_action;
551                 gboolean active;
552                 
553                 mgr = modest_runtime_get_window_mgr ();
554                 
555                 is_fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
556
557                 parent_priv = MODEST_WINDOW_GET_PRIVATE (widget);
558                 
559                 fs_toggle_action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewToggleFullscreenMenu");
560                 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (fs_toggle_action)))?1:0;
561                 if (is_fullscreen != active) {
562                         gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (fs_toggle_action), is_fullscreen);
563                 }
564         }
565
566         return FALSE;
567
568 }
569
570 static void
571 set_homogeneous (GtkWidget *widget,
572                  gpointer data)
573 {
574         gtk_tool_item_set_expand (GTK_TOOL_ITEM (widget), TRUE);
575         gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (widget), TRUE);
576 }
577
578 static void 
579 modest_main_window_create_toolbar (ModestWindow *self)
580 {
581         GtkWidget *reply_button, *menu;
582         ModestWindowPrivate *parent_priv;
583         
584         parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
585         
586         /* Toolbar */
587         parent_priv->toolbar = gtk_ui_manager_get_widget (parent_priv->ui_manager, 
588                                                           "/ToolBar");
589
590         /* Set homogeneous toolbar */
591         gtk_container_foreach (GTK_CONTAINER (parent_priv->toolbar), 
592                                set_homogeneous, NULL);
593
594         /* Set reply button tap and hold menu */
595         reply_button = gtk_ui_manager_get_widget (parent_priv->ui_manager, 
596                                                   "/ToolBar/ToolbarMessageReply");
597         menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolbarReplyContextMenu");
598         gtk_widget_tap_and_hold_setup (GTK_WIDGET (reply_button), menu, NULL, 0);
599 }
600
601 static void 
602 modest_main_window_show_toolbar (ModestWindow *self,
603                                  gboolean show_toolbar)
604 {
605         ModestWindowPrivate *parent_priv;
606         
607         parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
608
609         if (!parent_priv->toolbar)
610                 return;
611
612         if (show_toolbar) {
613                 hildon_window_add_toolbar (HILDON_WINDOW (self), 
614                                            GTK_TOOLBAR (parent_priv->toolbar));
615                 gtk_widget_show_all (GTK_WIDGET (self));
616         } else
617                 hildon_window_remove_toolbar (HILDON_WINDOW (self),
618                                               GTK_TOOLBAR (parent_priv->toolbar));
619 }