5614da4358b2ea975cf1715ce49d206420666074
[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 <glib/gi18n.h>
31 #include <gtk/gtktreeviewcolumn.h>
32 #include <tny-account-store-view.h>
33 #include <tny-simple-list.h>
34 #include "modest-hildon-includes.h"
35
36 #include <string.h>
37
38 #include "widgets/modest-main-window.h"
39 #include "widgets/modest-msg-edit-window.h"
40 #include "widgets/modest-account-view-window.h"
41 #include "modest-runtime.h"
42 #include "modest-account-mgr-helpers.h"
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-tny-account.h"
49 #include "modest-conf.h"
50 #include <modest-maemo-utils.h>
51 #include "modest-tny-platform-factory.h"
52 #include "modest-tny-msg.h"
53 #include "modest-mail-operation.h"
54 #include "modest-icon-names.h"
55 #include "modest-progress-bar-widget.h"
56
57 /* 'private'/'protected' functions */
58 static void modest_main_window_class_init    (ModestMainWindowClass *klass);
59 static void modest_main_window_init          (ModestMainWindow *obj);
60 static void modest_main_window_finalize      (GObject *obj);
61 static gboolean modest_main_window_window_state_event (GtkWidget *widget, 
62                                                            GdkEventWindowState *event, 
63                                                            gpointer userdata);
64
65 static void connect_signals (ModestMainWindow *self);
66 static void restore_sizes (ModestMainWindow *self);
67 static void save_sizes (ModestMainWindow *self);
68
69 static void modest_main_window_show_toolbar   (ModestWindow *window,
70                                                gboolean show_toolbar);
71
72 static void         on_queue_changed                     (ModestMailOperationQueue *queue,
73                                                           ModestMailOperation *mail_op,
74                                                           ModestMailOperationQueueNotification type,
75                                                           ModestMainWindow *self);
76
77 static void on_account_update                 (TnyAccountStore *account_store, 
78                                                gchar *account_name,
79                                                gpointer user_data);
80
81 static gboolean on_inner_widgets_key_pressed  (GtkWidget *widget,
82                                                GdkEventKey *event,
83                                                gpointer user_data);
84
85 static void on_configuration_key_changed      (ModestConf* conf, 
86                                                const gchar *key, 
87                                                ModestConfEvent event, 
88                                                ModestMainWindow *self);
89
90 static void 
91 set_toolbar_mode (ModestMainWindow *self, 
92                   ModestToolBarModes mode);
93
94 /* list my signals */
95 enum {
96         /* MY_SIGNAL_1, */
97         /* MY_SIGNAL_2, */
98         LAST_SIGNAL
99 };
100
101
102 typedef struct _ModestMainWindowPrivate ModestMainWindowPrivate;
103 struct _ModestMainWindowPrivate {
104         GtkWidget *msg_paned;
105         GtkWidget *main_paned;
106         GtkWidget *main_vbox;
107         GtkWidget *contents_widget;
108
109         /* Progress observers */
110         GtkWidget        *progress_bar;
111         GSList           *progress_widgets;
112
113         /* Tollbar items */
114         GtkWidget   *progress_toolitem;
115         GtkWidget   *cancel_toolitem;
116         GtkWidget   *sort_toolitem;
117         GtkWidget   *refresh_toolitem;
118
119         /* On-demand widgets */
120         GtkWidget *accounts_popup;
121         GtkWidget *details_widget;
122
123
124         ModestHeaderView *header_view;
125         ModestFolderView *folder_view;
126
127         ModestMainWindowStyle style;
128         ModestMainWindowContentsStyle contents_style;
129 };
130 #define MODEST_MAIN_WINDOW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
131                                                 MODEST_TYPE_MAIN_WINDOW, \
132                                                 ModestMainWindowPrivate))
133
134 typedef struct _GetMsgAsyncHelper {
135         ModestMainWindowPrivate *main_window_private;
136         guint action;
137         ModestTnyMsgReplyType reply_type;
138         ModestTnyMsgForwardType forward_type;
139         gchar *from;
140         TnyIterator *iter;
141 } GetMsgAsyncHelper;
142
143
144 /* globals */
145 static GtkWindowClass *parent_class = NULL;
146
147
148 /* Private actions */
149 static const GtkActionEntry modest_folder_view_action_entries [] = {
150
151         /* Folder View CSM actions */
152         { "FolderViewCSMNewFolder", NULL, N_("FIXME: New Folder"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_new_folder) },
153         { "FolderViewCSMRenameFolder", NULL, N_("mcen_me_user_renamefolder"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_rename_folder) },
154         { "FolderViewCSMPasteMsgs", NULL, N_("FIXME: Paste"), NULL, NULL, NULL },
155         { "FolderViewCSMDeleteFolder", NULL, N_("FIXME: Delete"), NULL, NULL, G_CALLBACK (modest_ui_actions_on_delete_folder) },
156         { "FolderViewCSMSearchMessages", NULL, N_("mcen_me_inbox_search"), NULL, NULL, NULL },
157         { "FolderViewCSMHelp", NULL, N_("mcen_me_inbox_help"), NULL, NULL, NULL },
158 };
159
160 /************************************************************************/
161
162 GType
163 modest_main_window_get_type (void)
164 {
165         static GType my_type = 0;
166         if (!my_type) {
167                 static const GTypeInfo my_info = {
168                         sizeof(ModestMainWindowClass),
169                         NULL,           /* base init */
170                         NULL,           /* base finalize */
171                         (GClassInitFunc) modest_main_window_class_init,
172                         NULL,           /* class finalize */
173                         NULL,           /* class data */
174                         sizeof(ModestMainWindow),
175                         1,              /* n_preallocs */
176                         (GInstanceInitFunc) modest_main_window_init,
177                         NULL
178                 };
179                 my_type = g_type_register_static (MODEST_TYPE_WINDOW,
180                                                   "ModestMainWindow",
181                                                   &my_info, 0);
182         }
183         return my_type;
184 }
185
186 static void
187 modest_main_window_class_init (ModestMainWindowClass *klass)
188 {
189         GObjectClass *gobject_class;
190         gobject_class = (GObjectClass*) klass;
191         ModestWindowClass *modest_window_class;
192
193         modest_window_class = (ModestWindowClass *) klass;
194
195         parent_class            = g_type_class_peek_parent (klass);
196         gobject_class->finalize = modest_main_window_finalize;
197
198         modest_window_class->show_toolbar_func = modest_main_window_show_toolbar;
199
200         g_type_class_add_private (gobject_class, sizeof(ModestMainWindowPrivate));
201 }
202
203 static void
204 modest_main_window_init (ModestMainWindow *obj)
205 {
206         ModestMainWindowPrivate *priv;
207
208         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
209
210         priv->msg_paned    = NULL;
211         priv->main_paned   = NULL;      
212         priv->main_vbox    = NULL;
213         priv->header_view  = NULL;
214         priv->folder_view  = NULL;
215         priv->contents_widget  = NULL;
216         priv->accounts_popup  = NULL;
217         priv->details_widget  = NULL;
218
219         priv->progress_widgets  = NULL;
220         priv->progress_bar = NULL;
221
222         priv->style  = MODEST_MAIN_WINDOW_STYLE_SPLIT;
223         priv->contents_style  = MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS;
224 }
225
226 static void
227 modest_main_window_finalize (GObject *obj)
228 {
229         ModestMainWindowPrivate *priv;
230
231         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
232
233         g_slist_free (priv->progress_widgets);
234
235         G_OBJECT_CLASS(parent_class)->finalize (obj);
236 }
237
238 GtkWidget*
239 modest_main_window_get_child_widget (ModestMainWindow *self,
240                                      ModestWidgetType widget_type)
241 {
242         ModestMainWindowPrivate *priv;
243         GtkWidget *widget;
244         
245         g_return_val_if_fail (self, NULL);
246         g_return_val_if_fail (widget_type >= 0 && widget_type < MODEST_WIDGET_TYPE_NUM,
247                               NULL);
248         
249         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
250
251         switch (widget_type) {
252         case MODEST_WIDGET_TYPE_HEADER_VIEW:
253                 widget = (GtkWidget*)priv->header_view; break;
254         case MODEST_WIDGET_TYPE_FOLDER_VIEW:
255                 widget = (GtkWidget*)priv->folder_view; break;
256         default:
257                 return NULL;
258         }
259
260         return widget ? GTK_WIDGET(widget) : NULL;
261 }
262
263
264
265 static void
266 restore_sizes (ModestMainWindow *self)
267 {
268         ModestConf *conf;
269         ModestMainWindowPrivate *priv;
270
271         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
272
273         conf = modest_runtime_get_conf ();
274         
275         modest_widget_memory_restore (conf, G_OBJECT(priv->main_paned),
276                                       "modest-main-paned");
277         modest_widget_memory_restore (conf, G_OBJECT(priv->header_view),
278                                       "header-view");
279         modest_widget_memory_restore (conf, G_OBJECT(self), 
280                                       "modest-main-window");
281 }
282
283
284 static void
285 save_sizes (ModestMainWindow *self)
286 {
287         ModestConf *conf;
288         ModestMainWindowPrivate *priv;
289                 
290         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
291         conf = modest_runtime_get_conf ();
292         
293         modest_widget_memory_save (conf,G_OBJECT(self), "modest-main-window");
294         modest_widget_memory_save (conf, G_OBJECT(priv->main_paned),
295                                    "modest-main-paned");
296         modest_widget_memory_save (conf, G_OBJECT(priv->header_view), "header-view");
297 }
298
299 static void
300 wrap_in_scrolled_window (GtkWidget *win, GtkWidget *widget)
301 {
302         if (!gtk_widget_set_scroll_adjustments (widget, NULL, NULL))
303                 gtk_scrolled_window_add_with_viewport
304                         (GTK_SCROLLED_WINDOW(win), widget);
305         else
306                 gtk_container_add (GTK_CONTAINER(win),
307                                    widget);
308 }
309
310
311 static gboolean
312 on_delete_event (GtkWidget *widget, GdkEvent  *event, ModestMainWindow *self)
313 {
314         save_sizes (self);
315         return FALSE;
316 }
317
318
319 static void
320 on_connection_changed (TnyDevice *device, gboolean online, ModestMainWindow *self)
321 {
322         /* When going online, do the equivalent of pressing the send/receive button, 
323          * as per the specification:
324          * (without the check for >0 accounts, though that is not specified): */
325         if (online) {
326                 do_send_receive (MODEST_WINDOW (self));
327         }
328 }
329
330
331
332 static void
333 connect_signals (ModestMainWindow *self)
334 {       
335         ModestWindowPrivate *parent_priv;
336         ModestMainWindowPrivate *priv;
337         GtkWidget *menu;
338         
339         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
340         parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
341         
342         /* folder view */
343         g_signal_connect (G_OBJECT(priv->folder_view), "key-press-event",
344                           G_CALLBACK(on_inner_widgets_key_pressed), self);
345         g_signal_connect (G_OBJECT(priv->folder_view), "folder_selection_changed",
346                           G_CALLBACK(modest_ui_actions_on_folder_selection_changed), self);
347         g_signal_connect (G_OBJECT(priv->folder_view), "folder-display-name-changed",
348                           G_CALLBACK(modest_ui_actions_on_folder_display_name_changed), self);
349
350         menu = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/FolderViewCSM");
351         gtk_widget_tap_and_hold_setup (GTK_WIDGET (priv->folder_view), menu, NULL, 0);
352
353         /* header view */
354 /*      g_signal_connect (G_OBJECT(priv->header_view), "status_update", */
355 /*                        G_CALLBACK(modest_ui_actions_on_header_status_update), self); */
356         g_signal_connect (G_OBJECT(priv->header_view), "header_selected",
357                           G_CALLBACK(modest_ui_actions_on_header_selected), self);
358         g_signal_connect (G_OBJECT(priv->header_view), "header_activated",
359                           G_CALLBACK(modest_ui_actions_on_header_activated), self);
360         g_signal_connect (G_OBJECT(priv->header_view), "item_not_found",
361                           G_CALLBACK(modest_ui_actions_on_item_not_found), self);
362         g_signal_connect (G_OBJECT(priv->header_view), "key-press-event",
363                           G_CALLBACK(on_inner_widgets_key_pressed), self);
364
365         /* window */
366         g_signal_connect (G_OBJECT(self), "delete-event", G_CALLBACK(on_delete_event), self);
367         g_signal_connect (G_OBJECT (self), "window-state-event",
368                           G_CALLBACK (modest_main_window_window_state_event),
369                           NULL);
370         g_signal_connect (G_OBJECT(self), "delete-event", G_CALLBACK(on_delete_event), self);
371
372         /* Mail Operation Queue */
373         g_signal_connect (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
374                           "queue-changed",
375                           G_CALLBACK (on_queue_changed),
376                           self);
377
378         /* Track changes in the device name */
379         g_signal_connect (G_OBJECT(modest_runtime_get_conf ()),
380                           "key_changed",
381                           G_CALLBACK (on_configuration_key_changed), 
382                           self);
383
384         /* Track account changes. We need to refresh the toolbar */
385         g_signal_connect (G_OBJECT (modest_runtime_get_account_store ()),
386                           "account_update",
387                           G_CALLBACK (on_account_update),
388                           self);
389
390         /* Device */
391         g_signal_connect (G_OBJECT(modest_runtime_get_device()), "connection_changed",
392                           G_CALLBACK(on_connection_changed), self);
393 }
394
395 /** Idle handler, to send/receive at startup .*/
396 gboolean
397 sync_accounts_cb (ModestMainWindow *win)
398 {
399         do_send_receive (MODEST_WINDOW(win));
400         return FALSE; /* Do not call this idle handler again. */
401 }
402
403
404 ModestWindow*
405 modest_main_window_new (void)
406 {
407         ModestMainWindow *self; 
408         ModestMainWindowPrivate *priv;
409         ModestWindowPrivate *parent_priv;
410         GtkWidget *folder_win;
411         GtkActionGroup *action_group;
412         GError *error = NULL;
413         TnyFolderStoreQuery *query;
414         GdkPixbuf *window_icon;
415         ModestConf *conf;
416         GtkAction *action;
417
418         self  = MODEST_MAIN_WINDOW(g_object_new(MODEST_TYPE_MAIN_WINDOW, NULL));
419         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
420         parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
421
422         parent_priv->ui_manager = gtk_ui_manager_new();
423         action_group = gtk_action_group_new ("ModestMainWindowActions");
424         gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
425
426         /* Add common actions */
427         gtk_action_group_add_actions (action_group,
428                                       modest_action_entries,
429                                       G_N_ELEMENTS (modest_action_entries),
430                                       self);
431
432         gtk_action_group_add_actions (action_group,
433                                       modest_folder_view_action_entries,
434                                       G_N_ELEMENTS (modest_folder_view_action_entries),
435                                       self);
436
437         gtk_action_group_add_toggle_actions (action_group,
438                                              modest_toggle_action_entries,
439                                              G_N_ELEMENTS (modest_toggle_action_entries),
440                                              self);
441
442         gtk_ui_manager_insert_action_group (parent_priv->ui_manager, action_group, 0);
443         g_object_unref (action_group);
444
445         /* Load the UI definition */
446         gtk_ui_manager_add_ui_from_file (parent_priv->ui_manager,
447                                          MODEST_UIDIR "modest-main-window-ui.xml", &error);
448         if (error != NULL) {
449                 g_warning ("Could not merge modest-ui.xml: %s", error->message);
450                 g_error_free (error);
451                 error = NULL;
452         }
453
454         /* Add accelerators */
455         gtk_window_add_accel_group (GTK_WINDOW (self), 
456                                     gtk_ui_manager_get_accel_group (parent_priv->ui_manager));
457
458         /* Menubar. Update the state of some toggles */
459         parent_priv->menubar = modest_maemo_utils_menubar_to_menu (parent_priv->ui_manager);
460         conf = modest_runtime_get_conf ();
461         action = gtk_ui_manager_get_action (parent_priv->ui_manager, 
462                                             "/MenuBar/ViewMenu/ViewShowToolbarMainMenu/ViewShowToolbarNormalScreenMenu");
463         gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
464                                       modest_conf_get_bool (conf, MODEST_CONF_SHOW_TOOLBAR, NULL));
465         action = gtk_ui_manager_get_action (parent_priv->ui_manager, 
466                                             "/MenuBar/ViewMenu/ViewShowToolbarMainMenu/ViewShowToolbarFullScreenMenu");
467         gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
468                                       modest_conf_get_bool (conf, MODEST_CONF_SHOW_TOOLBAR_FULLSCREEN, NULL));
469         hildon_window_set_menu (HILDON_WINDOW (self), GTK_MENU (parent_priv->menubar));
470
471         /* folder view */
472         query = tny_folder_store_query_new ();
473         tny_folder_store_query_add_item (query, NULL,
474                                          TNY_FOLDER_STORE_QUERY_OPTION_SUBSCRIBED);
475         priv->folder_view = MODEST_FOLDER_VIEW(modest_folder_view_new (query));
476         if (!priv->folder_view)
477                 g_printerr ("modest: cannot instantiate folder view\n");
478         g_object_unref (G_OBJECT (query));
479         modest_folder_view_set_style (priv->folder_view,
480                                       MODEST_FOLDER_VIEW_STYLE_SHOW_ONE);
481
482         /* Get device name */
483         modest_maemo_utils_get_device_name ();
484
485         /* header view */
486         priv->header_view  =
487                 MODEST_HEADER_VIEW(modest_header_view_new (NULL, MODEST_HEADER_VIEW_STYLE_DETAILS));
488         if (!priv->header_view)
489                 g_printerr ("modest: cannot instantiate header view\n");
490         modest_header_view_set_style (priv->header_view, MODEST_HEADER_VIEW_STYLE_TWOLINES);
491         
492         /* Create scrolled windows */
493         folder_win = gtk_scrolled_window_new (NULL, NULL);
494         priv->contents_widget = gtk_scrolled_window_new (NULL, NULL);
495         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (folder_win),
496                                         GTK_POLICY_NEVER,
497                                         GTK_POLICY_AUTOMATIC);
498         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->contents_widget),
499                                         GTK_POLICY_NEVER,
500                                         GTK_POLICY_AUTOMATIC);
501
502         wrap_in_scrolled_window (folder_win, GTK_WIDGET(priv->folder_view));
503         wrap_in_scrolled_window (priv->contents_widget, GTK_WIDGET(priv->header_view));
504
505         /* paned */
506         priv->main_paned = gtk_hpaned_new ();
507         gtk_paned_add1 (GTK_PANED(priv->main_paned), folder_win);
508         gtk_paned_add2 (GTK_PANED(priv->main_paned), priv->contents_widget);
509         gtk_widget_show (GTK_WIDGET(priv->header_view));
510         gtk_tree_view_columns_autosize (GTK_TREE_VIEW(priv->header_view));
511
512         /* putting it all together... */
513         priv->main_vbox = gtk_vbox_new (FALSE, 6);
514         gtk_box_pack_start (GTK_BOX(priv->main_vbox), priv->main_paned, TRUE, TRUE,0);
515
516         gtk_container_add (GTK_CONTAINER(self), priv->main_vbox);
517         restore_sizes (MODEST_MAIN_WINDOW(self));
518
519         /* Set window icon */
520         window_icon = modest_platform_get_icon (MODEST_APP_ICON);
521         gtk_window_set_icon (GTK_WINDOW (self), window_icon);
522         
523         /* Connect signals */
524         connect_signals (self);
525
526         /* Set account store */
527         tny_account_store_view_set_account_store (TNY_ACCOUNT_STORE_VIEW (priv->folder_view),
528                                                   TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
529
530         /* do send & receive when we are idle */
531         g_idle_add ((GSourceFunc)sync_accounts_cb, self);
532         
533         return MODEST_WINDOW(self);
534 }
535
536 gboolean 
537 modest_main_window_close_all (ModestMainWindow *self)
538 {
539         GtkWidget *note;
540         GtkResponseType response;
541
542         /* Create the confirmation dialog MSG-NOT308 */
543         note = hildon_note_new_confirmation_add_buttons (GTK_WINDOW (self),
544                                                          _("emev_nc_close_windows"),
545                                                          _("mcen_bd_yes"), GTK_RESPONSE_YES,
546                                                          _("mcen_bd_no"), GTK_RESPONSE_NO,
547                                                          NULL);
548
549         response = gtk_dialog_run (GTK_DIALOG (note));
550         gtk_widget_destroy (GTK_WIDGET (note));
551
552         if (response == GTK_RESPONSE_YES)
553                 return TRUE;
554         else
555                 return FALSE;
556 }
557
558
559 void 
560 modest_main_window_set_style (ModestMainWindow *self, 
561                               ModestMainWindowStyle style)
562 {
563         ModestMainWindowPrivate *priv;
564
565         g_return_if_fail (MODEST_IS_MAIN_WINDOW (self));
566
567         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
568
569         /* no change -> nothing to do */
570         if (priv->style == style)
571                 return;
572
573         priv->style = style;
574
575         switch (style) {
576         case MODEST_MAIN_WINDOW_STYLE_SIMPLE:
577                 /* Remove main paned */
578                 g_object_ref (priv->main_paned);
579                 gtk_container_remove (GTK_CONTAINER (priv->main_vbox), priv->main_paned);
580
581                 /* Reparent the contents widget to the main vbox */
582                 gtk_widget_reparent (priv->contents_widget, priv->main_vbox);
583
584                 break;
585         case MODEST_MAIN_WINDOW_STYLE_SPLIT:
586                 /* Remove header view */
587                 g_object_ref (priv->contents_widget);
588                 gtk_container_remove (GTK_CONTAINER (priv->main_vbox), priv->contents_widget);
589
590                 /* Reparent the main paned */
591                 gtk_paned_add2 (GTK_PANED (priv->main_paned), priv->contents_widget);
592                 gtk_container_add (GTK_CONTAINER (priv->main_vbox), priv->main_paned);
593                 break;
594         default:
595                 g_return_if_reached ();
596         }
597
598         /* Let header view grab the focus if it's being shown */
599         if (priv->contents_style == MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
600                 gtk_widget_grab_focus (GTK_WIDGET (priv->header_view));
601         else 
602                 gtk_widget_grab_focus (GTK_WIDGET (priv->contents_widget));
603
604         /* Show changes */
605         gtk_widget_show_all (GTK_WIDGET (priv->main_vbox));
606 }
607
608 ModestMainWindowStyle
609 modest_main_window_get_style (ModestMainWindow *self)
610 {
611         ModestMainWindowPrivate *priv;
612
613         g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (self), -1);
614
615         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
616         return priv->style;
617 }
618
619 static gboolean
620 modest_main_window_window_state_event (GtkWidget *widget, GdkEventWindowState *event, gpointer userdata)
621 {
622         if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) {
623                 ModestWindowPrivate *parent_priv;
624                 ModestWindowMgr *mgr;
625                 gboolean is_fullscreen;
626                 GtkAction *fs_toggle_action;
627                 gboolean active;
628                 
629                 mgr = modest_runtime_get_window_mgr ();
630                 
631                 is_fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
632
633                 parent_priv = MODEST_WINDOW_GET_PRIVATE (widget);
634                 
635                 fs_toggle_action = gtk_ui_manager_get_action (parent_priv->ui_manager, "/MenuBar/ViewMenu/ViewToggleFullscreenMenu");
636                 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (fs_toggle_action)))?1:0;
637                 if (is_fullscreen != active) {
638                         gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (fs_toggle_action), is_fullscreen);
639                 }
640         }
641
642         return FALSE;
643
644 }
645
646 static void
647 set_homogeneous (GtkWidget *widget,
648                  gpointer data)
649 {
650         gtk_tool_item_set_expand (GTK_TOOL_ITEM (widget), TRUE);
651         gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (widget), TRUE);
652 }
653
654 static void 
655 modest_main_window_show_toolbar (ModestWindow *self,
656                                  gboolean show_toolbar)
657 {
658         ModestMainWindowPrivate *priv = NULL;
659         ModestWindowPrivate *parent_priv = NULL;        
660         GtkWidget *reply_button = NULL, *menu = NULL;
661         GtkWidget *placeholder = NULL;
662         gint insert_index;
663
664         parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
665         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
666
667         if (!parent_priv->toolbar && show_toolbar) {
668                 parent_priv->toolbar = gtk_ui_manager_get_widget (parent_priv->ui_manager, 
669                                                                   "/ToolBar");
670
671                 /* Set homogeneous toolbar */
672                 gtk_container_foreach (GTK_CONTAINER (parent_priv->toolbar), 
673                                        set_homogeneous, NULL);
674         
675                 priv->progress_toolitem = GTK_WIDGET (gtk_tool_item_new ());
676                 priv->cancel_toolitem = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/ToolbarCancel");
677                 priv->refresh_toolitem = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/ToolbarSendReceive");
678                 priv->sort_toolitem = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/ToolbarSort");
679                 gtk_tool_item_set_expand (GTK_TOOL_ITEM (priv->progress_toolitem), FALSE);
680                 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (priv->progress_toolitem), FALSE);
681                 gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (priv->cancel_toolitem), FALSE);
682                 gtk_tool_item_set_expand (GTK_TOOL_ITEM (priv->cancel_toolitem), FALSE);
683
684                 /* Add ProgressBar (Transfer toolbar) */ 
685                 priv->progress_bar = modest_progress_bar_widget_new ();
686                 gtk_widget_set_no_show_all (priv->progress_bar, TRUE);
687                 placeholder = gtk_ui_manager_get_widget (parent_priv->ui_manager, "/ToolBar/ProgressBarView");
688                 insert_index = gtk_toolbar_get_item_index(GTK_TOOLBAR (parent_priv->toolbar), GTK_TOOL_ITEM(placeholder));
689                 gtk_container_add (GTK_CONTAINER (priv->progress_toolitem), priv->progress_bar);
690                 gtk_toolbar_insert(GTK_TOOLBAR(parent_priv->toolbar), GTK_TOOL_ITEM (priv->progress_toolitem), insert_index);
691                 
692                 /* Add it to the observers list */
693                 priv->progress_widgets = g_slist_prepend(priv->progress_widgets, priv->progress_bar);
694
695                 /* Add to window */
696                 hildon_window_add_toolbar (HILDON_WINDOW (self), 
697                                            GTK_TOOLBAR (parent_priv->toolbar));
698
699                 /* Set reply button tap and hold menu */
700                 reply_button = gtk_ui_manager_get_widget (parent_priv->ui_manager, 
701                                                           "/ToolBar/ToolbarMessageReply");
702                 menu = gtk_ui_manager_get_widget (parent_priv->ui_manager,
703                                                   "/ToolbarReplyCSM");
704                 gtk_widget_tap_and_hold_setup (GTK_WIDGET (reply_button), menu, NULL, 0);
705
706                 /* Set send & receive button tap and hold menu */
707                 on_account_update (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()),
708                                    NULL, self);
709         }
710
711         /* TODO: Why is this sometimes NULL? murrayc */
712         if (parent_priv->toolbar) {
713                 if (show_toolbar) {
714                         gtk_widget_show (GTK_WIDGET (parent_priv->toolbar));
715                         set_toolbar_mode (MODEST_MAIN_WINDOW(self), TOOLBAR_MODE_NORMAL);
716                 } else
717                         gtk_widget_hide (GTK_WIDGET (parent_priv->toolbar));
718         }
719 }
720
721 /*
722  * TODO: modify the menu dynamically. Add handlers to each item of the
723  * menu when created
724  */
725 static void 
726 on_account_update (TnyAccountStore *account_store, 
727                    gchar *accout_name,
728                    gpointer user_data)
729 {
730         ModestMainWindow *self;
731         ModestMainWindowPrivate *priv;
732         ModestWindowPrivate *parent_priv;
733         TnyList *account_list;
734         GtkWidget *item, *send_receive_button;
735         TnyIterator *iter;
736         ModestAccountMgr *mgr;
737         gchar *default_account;
738
739         self = MODEST_MAIN_WINDOW (user_data);
740         priv = MODEST_MAIN_WINDOW_GET_PRIVATE (self);
741         parent_priv = MODEST_WINDOW_GET_PRIVATE (self);
742
743         /* If there is no toolbar then exit */
744         if (!parent_priv->toolbar)
745                 return;
746
747         if (priv->accounts_popup && gtk_menu_get_attach_widget (GTK_MENU (priv->accounts_popup)) ) {
748                 /* gtk_menu_detach will also unreference the popup, 
749                  * so we can forget about this instance, and create a new one later:
750                  */
751                 gtk_menu_detach (GTK_MENU (priv->accounts_popup));
752                 priv->accounts_popup = NULL;
753         }
754
755         /* Get accounts */
756         account_list = tny_simple_list_new ();
757         tny_account_store_get_accounts (account_store, 
758                                         account_list, 
759                                         TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
760
761         /* If there is only one account do not show any menu */
762         if (tny_list_get_length (account_list) <= 1)
763                 goto free;
764         
765         /* Get send receive button */
766         send_receive_button = gtk_ui_manager_get_widget (parent_priv->ui_manager, 
767                                                           "/ToolBar/ToolbarSendReceive");
768
769         /* Create the menu */
770         priv->accounts_popup = gtk_menu_new ();
771         item = gtk_menu_item_new_with_label (_("mcen_me_toolbar_sendreceive_all"));
772         gtk_menu_shell_append (GTK_MENU_SHELL (priv->accounts_popup), GTK_WIDGET (item));
773         item = gtk_separator_menu_item_new ();
774         gtk_menu_shell_append (GTK_MENU_SHELL (priv->accounts_popup), GTK_WIDGET (item));
775
776         iter = tny_list_create_iterator (account_list);
777         mgr = modest_runtime_get_account_mgr ();
778         default_account = modest_account_mgr_get_default_account (mgr);
779
780         do {
781                 TnyAccount *acc = NULL;
782                 const gchar *acc_name = NULL;
783
784                 /* Create tool item */
785                 acc = TNY_ACCOUNT (tny_iterator_get_current (iter));
786                 if (acc)
787                         acc_name = tny_account_get_name (acc);
788
789                 /* Create display name */
790                 gchar *display_name = NULL;
791                 if (acc_name) {
792                         if (default_account && !(strcmp (default_account, acc_name) == 0))
793                                 display_name = g_strdup_printf (_("mcen_me_toolbar_sendreceive_default"), acc_name);
794                         else
795                                 display_name = g_strdup_printf (_("mcen_me_toolbar_sendreceive_mailbox_n"), acc_name);
796                 }
797                 else
798                 {
799                         /* TODO: This probably should never happen: */
800                         display_name = g_strdup_printf (_("mcen_me_toolbar_sendreceive_default"), "");
801                 }
802                 
803
804                 item = gtk_menu_item_new_with_label (display_name);
805
806                 /* Free */
807                 g_free (display_name);
808                 g_object_unref (acc);
809
810                 /* Append item */
811                 gtk_menu_shell_append (GTK_MENU_SHELL (priv->accounts_popup), GTK_WIDGET (item));
812
813                 /* Go to next */
814                 tny_iterator_next (iter);
815
816         } while (!tny_iterator_is_done (iter));
817
818         g_object_unref (iter);
819
820         /* Mandatory in order to view the menu contents */
821         gtk_widget_show_all (priv->accounts_popup);
822
823         /* Setup tap_and_hold */
824         gtk_widget_tap_and_hold_setup (send_receive_button, priv->accounts_popup, NULL, 0);
825
826  free:
827
828         /* Free */
829         g_object_unref (account_list);
830 }
831
832 /* 
833  * This function manages the key events used to navigate between
834  * header and folder views (when the window is in split view)
835  *
836  * FROM         KEY        ACTION
837  * -------------------------------------------------
838  * HeaderView   GDK_Left   Move focus to folder view
839  * FolderView   GDK_Right  Move focus to header view
840  *
841  * There is no need to scroll to selected row, the widgets will be the
842  * responsibles of doing that (probably managing the focus-in event
843  */
844 static gboolean 
845 on_inner_widgets_key_pressed (GtkWidget *widget,
846                               GdkEventKey *event,
847                               gpointer user_data)
848 {
849         ModestMainWindowPrivate *priv;
850
851         priv = MODEST_MAIN_WINDOW_GET_PRIVATE (user_data);
852
853         /* Do nothing if we're in SIMPLE style */
854         if (priv->style == MODEST_MAIN_WINDOW_STYLE_SIMPLE)
855                 return FALSE;
856
857         if (MODEST_IS_HEADER_VIEW (widget) && event->keyval == GDK_Left)
858                 gtk_widget_grab_focus (GTK_WIDGET (priv->folder_view));
859         else if (MODEST_IS_FOLDER_VIEW (widget) && event->keyval == GDK_Right)
860                 gtk_widget_grab_focus (GTK_WIDGET (priv->header_view));
861
862         return FALSE;
863 }
864
865 static void
866 set_alignment (GtkWidget *widget,
867                gpointer data)
868 {
869         gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.0);
870         gtk_misc_set_padding (GTK_MISC (widget), 0, 0);
871 }
872
873 static GtkWidget *
874 create_details_widget (TnyAccount *account)
875 {
876         GtkWidget *vbox;
877         gchar *label;
878
879         vbox = gtk_vbox_new (FALSE, 0);
880
881         /* Account description */
882         if (!strcmp (tny_account_get_id (account), MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
883                 gchar *device_name;
884
885                 /* Get device name */
886                 device_name = modest_conf_get_string (modest_runtime_get_conf(),
887                                                       MODEST_CONF_DEVICE_NAME, NULL);
888    
889                 label = g_strdup_printf ("%s: %s",
890                                          _("mcen_fi_localroot_description"),
891                                          device_name);
892                 gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
893                 g_free (device_name);
894                 g_free (label);
895         } else if (!strcmp (tny_account_get_id (account), MODEST_MMC_ACCOUNT_ID)) {
896                 /* TODO: MMC ? */
897                 gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("FIXME: MMC ?"), FALSE, FALSE, 0);
898         } else {
899                 GString *proto;
900
901                 /* Put proto in uppercase */
902                 proto = g_string_new (tny_account_get_proto (account));
903                 proto = g_string_ascii_up (proto);
904
905                 label = g_strdup_printf ("%s %s: %s", 
906                                          proto->str,
907                                          _("mcen_fi_remoteroot_account"),
908                                          tny_account_get_name (account));
909                 gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
910                 g_string_free (proto, TRUE);
911                 g_free (label);
912         }
913
914         /* Message count */
915         label = g_strdup_printf ("%s: %d", _("mcen_fi_rootfolder_messages"), 
916                                  modest_tny_account_get_message_count (account));
917         gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
918         g_free (label);
919
920         /* Folder count */
921         label = g_strdup_printf ("%s: %d", _("mcen_fi_rootfolder_folders"), 
922                                  modest_tny_account_get_folder_count (account));
923         gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
924         g_free (label);
925
926         /* Size / Date */
927         if (!strcmp (tny_account_get_id (account), MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
928                 /* FIXME: format size */
929                 label = g_strdup_printf ("%s: %d", _("mcen_fi_rootfolder_size"), 
930                                          modest_tny_account_get_local_size (account));
931                 gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
932                 g_free (label);
933         } else if (!strcmp (tny_account_get_id (account), MODEST_MMC_ACCOUNT_ID)) {
934                 gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("FIXME: MMC ?"), FALSE, FALSE, 0);
935         } else {
936                 label = g_strdup_printf ("%s: %s", _("mcen_ti_lastupdated"), "08/08/08");
937                 gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (label), FALSE, FALSE, 0);
938                 g_free (label);
939         }
940
941         /* Set alignment */
942         gtk_container_foreach (GTK_CONTAINER (vbox), (GtkCallback) set_alignment, NULL);
943
944         return vbox;
945 }
946
947 void 
948 modest_main_window_set_contents_style (ModestMainWindow *self, 
949                                        ModestMainWindowContentsStyle style)
950 {
951         ModestMainWindowPrivate *priv;
952         GtkWidget *content;
953         TnyAccount *account;
954
955         g_return_if_fail (MODEST_IS_MAIN_WINDOW (self));
956
957         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
958
959         /* We allow to set the same content style than the previously
960            set if there are details, because it could happen when we're
961            selecting different accounts consecutively */
962         if ((priv->contents_style == style) &&
963             (priv->contents_style == MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS))
964                 return;
965
966         /* Remove previous child. Delete it if it was an account
967            details widget */
968         content = gtk_bin_get_child (GTK_BIN (priv->contents_widget));
969         if (priv->contents_style != MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS)
970                 g_object_ref (content);
971         gtk_container_remove (GTK_CONTAINER (priv->contents_widget), content);
972
973         priv->contents_style = style;
974
975         switch (priv->contents_style) {
976         case MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS:
977                 wrap_in_scrolled_window (priv->contents_widget, GTK_WIDGET (priv->header_view));
978                 break;
979         case MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS:
980                 /* TODO: show here account details */
981                 account = TNY_ACCOUNT (modest_folder_view_get_selected (priv->folder_view));
982                 priv->details_widget = create_details_widget (account);
983
984                 wrap_in_scrolled_window (priv->contents_widget, 
985                                          priv->details_widget);
986                 break;
987         default:
988                 g_return_if_reached ();
989         }
990
991         /* Show */
992         gtk_widget_show_all (priv->contents_widget);
993 }
994
995 static void 
996 on_configuration_key_changed (ModestConf* conf, 
997                               const gchar *key, 
998                               ModestConfEvent event, 
999                               ModestMainWindow *self)
1000 {
1001         ModestMainWindowPrivate *priv;
1002         TnyAccount *account;
1003
1004         if (!key || strcmp (key, MODEST_CONF_DEVICE_NAME))
1005                 return;
1006
1007         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
1008
1009         if (priv->contents_style != MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS)
1010                 return;
1011
1012         account = (TnyAccount *) modest_folder_view_get_selected (priv->folder_view);
1013         if (TNY_IS_ACCOUNT (account) &&
1014             !strcmp (tny_account_get_id (account), MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
1015                 GList *children;
1016                 GtkLabel *label;
1017                 const gchar *device_name;
1018                 gchar *new_text;
1019                 
1020                 /* Get label */
1021                 children = gtk_container_get_children (GTK_CONTAINER (priv->details_widget));
1022                 label = GTK_LABEL (children->data);
1023                 
1024                 device_name = modest_conf_get_string (modest_runtime_get_conf(),
1025                                                       MODEST_CONF_DEVICE_NAME, NULL);
1026                 
1027                 new_text = g_strdup_printf ("%s: %s",
1028                                             _("mcen_fi_localroot_description"),
1029                                             device_name);
1030                 
1031                 gtk_label_set_text (label, new_text);
1032                 gtk_widget_show (GTK_WIDGET (label));
1033                 
1034                 g_free (new_text);
1035                 g_list_free (children);
1036         }
1037 }
1038
1039 static void 
1040 set_toolbar_mode (ModestMainWindow *self, 
1041                   ModestToolBarModes mode)
1042 {
1043         ModestMainWindowPrivate *priv;
1044
1045         g_return_if_fail (MODEST_IS_MAIN_WINDOW (self));
1046
1047         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
1048                         
1049         switch (mode) {
1050         case TOOLBAR_MODE_NORMAL:
1051                 if (priv->sort_toolitem)
1052                 gtk_widget_show (priv->sort_toolitem);
1053                 
1054                 if (priv->refresh_toolitem)
1055                         gtk_widget_show (priv->refresh_toolitem);
1056                         
1057                 if (priv->progress_toolitem)
1058                         gtk_tool_item_set_expand (GTK_TOOL_ITEM (priv->progress_toolitem), FALSE);
1059                 if (priv->progress_bar)
1060                         gtk_widget_hide (priv->progress_bar);
1061                         
1062                 if (priv->cancel_toolitem)
1063                         gtk_widget_hide (priv->cancel_toolitem);
1064                 break;
1065         case TOOLBAR_MODE_TRANSFER:
1066                 if (priv->sort_toolitem)
1067                         gtk_widget_hide (priv->sort_toolitem);
1068                 
1069                 if (priv->refresh_toolitem)
1070                         gtk_widget_hide (priv->refresh_toolitem);
1071                 
1072                 if (priv->progress_toolitem)
1073                         gtk_tool_item_set_expand (GTK_TOOL_ITEM (priv->progress_toolitem), TRUE);
1074                 if (priv->progress_bar)
1075                         gtk_widget_show (priv->progress_bar);
1076                         
1077                 if (priv->cancel_toolitem)
1078                         gtk_widget_show (priv->cancel_toolitem);
1079                 break;
1080         default:
1081                 if (priv->cancel_toolitem)
1082                         gtk_widget_show (priv->sort_toolitem);
1083                         
1084                 if (priv->refresh_toolitem)
1085                         gtk_widget_show (priv->refresh_toolitem);
1086                         
1087                 if (priv->progress_bar)
1088                         gtk_widget_hide (priv->progress_bar);
1089                         
1090                 if (priv->cancel_toolitem)
1091                         gtk_widget_hide (priv->cancel_toolitem);
1092         }
1093 }
1094
1095 static void
1096 on_queue_changed (ModestMailOperationQueue *queue,
1097                   ModestMailOperation *mail_op,
1098                   ModestMailOperationQueueNotification type,
1099                   ModestMainWindow *self)
1100 {
1101         GSList *tmp;
1102         ModestMainWindowPrivate *priv;
1103         ModestMailOperationId op_id;
1104         ModestToolBarModes mode;
1105         
1106         priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
1107
1108         /* Get toolbar mode from operation id*/
1109         op_id = modest_mail_operation_get_id (mail_op);
1110         switch (op_id) {
1111         case MODEST_MAIL_OPERATION_ID_SEND:
1112         case MODEST_MAIL_OPERATION_ID_RECEIVE:
1113                 mode = TOOLBAR_MODE_TRANSFER;
1114                 break;
1115         default:
1116                 mode = TOOLBAR_MODE_NORMAL;
1117                 
1118         }
1119                 
1120         /* Add operation observers and change toolbar if neccessary*/
1121         tmp = priv->progress_widgets;
1122         switch (type) {
1123         case MODEST_MAIL_OPERATION_QUEUE_OPERATION_ADDED:
1124                 if (mode != TOOLBAR_MODE_NORMAL) 
1125                         set_toolbar_mode (MODEST_MAIN_WINDOW(self), mode);
1126                 while (tmp) {
1127                         modest_progress_object_add_operation (MODEST_PROGRESS_OBJECT (tmp->data),
1128                                                               mail_op);
1129                         tmp = g_slist_next (tmp);
1130                 }
1131                 break;
1132         case MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED:
1133                 if (mode != TOOLBAR_MODE_NORMAL) 
1134                         set_toolbar_mode (MODEST_MAIN_WINDOW(self), TOOLBAR_MODE_NORMAL);
1135                 while (tmp) {
1136                         modest_progress_object_remove_operation (MODEST_PROGRESS_OBJECT (tmp->data),
1137                                                                  mail_op);
1138                         tmp = g_slist_next (tmp);
1139                 }
1140                 break;
1141         }
1142 }