Set the active account on creating folder window from mailboxes window,
[modest] / src / hildon2 / modest-mailboxes-window.c
1 /* Copyright (c) 2009, 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 <modest-mailboxes-window.h>
31 #include <hildon/hildon-pannable-area.h>
32 #include <modest-window-mgr.h>
33 #include <modest-signal-mgr.h>
34 #include <modest-runtime.h>
35 #include <modest-platform.h>
36 #include <modest-maemo-utils.h>
37 #include <modest-icon-names.h>
38 #include <modest-ui-constants.h>
39 #include <modest-account-mgr.h>
40 #include <modest-account-mgr-helpers.h>
41 #include <modest-defs.h>
42 #include <modest-ui-actions.h>
43 #include <modest-window.h>
44 #include <hildon/hildon.h>
45 #include <tny-account-store-view.h>
46 #include <modest-header-window.h>
47 #include <modest-ui-dimming-rules.h>
48 #include <modest-ui-dimming-manager.h>
49 #include <modest-window-priv.h>
50 #include "modest-text-utils.h"
51 #include "modest-tny-account.h"
52 #include <modest-folder-window.h>
53
54 /* 'private'/'protected' functions */
55 static void modest_mailboxes_window_class_init  (ModestMailboxesWindowClass *klass);
56 static void modest_mailboxes_window_init        (ModestMailboxesWindow *obj);
57 static void modest_mailboxes_window_finalize    (GObject *obj);
58
59 static void connect_signals (ModestMailboxesWindow *self);
60 static void modest_mailboxes_window_disconnect_signals (ModestWindow *self);
61
62 static void on_mailbox_activated (ModestFolderView *mailboxes_view,
63                                   TnyFolder *folder,
64                                   gpointer userdata);
65 static void on_progress_list_changed (ModestWindowMgr *mgr,
66                                       ModestMailboxesWindow *self);
67 static gboolean on_map_event (GtkWidget *widget,
68                               GdkEvent *event,
69                               gpointer userdata);
70 static void update_progress_hint (ModestMailboxesWindow *self);
71 static void on_queue_changed    (ModestMailOperationQueue *queue,
72                                  ModestMailOperation *mail_op,
73                                  ModestMailOperationQueueNotification type,
74                                  ModestMailboxesWindow *self);
75 static void on_activity_changed (ModestFolderView *view,
76                                  gboolean activity,
77                                  ModestMailboxesWindow *folder_window);
78 static gboolean on_key_press(GtkWidget *widget,
79                                 GdkEventKey *event,
80                                 gpointer user_data);
81
82 typedef struct _ModestMailboxesWindowPrivate ModestMailboxesWindowPrivate;
83 struct _ModestMailboxesWindowPrivate {
84
85         GtkWidget *folder_view;
86         GtkWidget *top_vbox;
87         GtkWidget *new_message_button;
88
89         /* signals */
90         GSList *sighandlers;
91
92         gchar *current_store_account;
93         gboolean progress_hint;
94         guint queue_change_handler;
95 };
96 #define MODEST_MAILBOXES_WINDOW_GET_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE((o), \
97                                                                           MODEST_TYPE_MAILBOXES_WINDOW, \
98                                                                           ModestMailboxesWindowPrivate))
99
100 /* globals */
101 static GtkWindowClass *parent_class = NULL;
102
103 /************************************************************************/
104
105 GType
106 modest_mailboxes_window_get_type (void)
107 {
108         static GType my_type = 0;
109         if (!my_type) {
110                 static const GTypeInfo my_info = {
111                         sizeof(ModestMailboxesWindowClass),
112                         NULL,           /* base init */
113                         NULL,           /* base finalize */
114                         (GClassInitFunc) modest_mailboxes_window_class_init,
115                         NULL,           /* class finalize */
116                         NULL,           /* class data */
117                         sizeof(ModestMailboxesWindow),
118                         1,              /* n_preallocs */
119                         (GInstanceInitFunc) modest_mailboxes_window_init,
120                         NULL
121                 };
122                 my_type = g_type_register_static (MODEST_TYPE_HILDON2_WINDOW,
123                                                   "ModestMailboxesWindow",
124                                                   &my_info, 0);
125         }
126         return my_type;
127 }
128
129 static void
130 modest_mailboxes_window_class_init (ModestMailboxesWindowClass *klass)
131 {
132         GObjectClass *gobject_class;
133         gobject_class = (GObjectClass*) klass;
134         ModestWindowClass *modest_window_class = (ModestWindowClass *) klass;
135
136         parent_class            = g_type_class_peek_parent (klass);
137         gobject_class->finalize = modest_mailboxes_window_finalize;
138
139         g_type_class_add_private (gobject_class, sizeof(ModestMailboxesWindowPrivate));
140         
141         modest_window_class->disconnect_signals_func = modest_mailboxes_window_disconnect_signals;
142 }
143
144 static void
145 modest_mailboxes_window_init (ModestMailboxesWindow *obj)
146 {
147         ModestMailboxesWindowPrivate *priv;
148
149         priv = MODEST_MAILBOXES_WINDOW_GET_PRIVATE(obj);
150
151         priv->sighandlers = NULL;
152         
153         priv->folder_view = NULL;
154
155         priv->top_vbox = NULL;
156
157         priv->current_store_account = NULL;
158         priv->progress_hint = FALSE;
159         priv->queue_change_handler = 0;
160 }
161
162 static void
163 modest_mailboxes_window_finalize (GObject *obj)
164 {
165         ModestMailboxesWindowPrivate *priv;
166
167         priv = MODEST_MAILBOXES_WINDOW_GET_PRIVATE(obj);
168
169         if (priv->current_store_account) {
170                 g_free (priv->current_store_account);
171                 priv->current_store_account = NULL;
172         }
173
174         /* Sanity check: shouldn't be needed, the window mgr should
175            call this function before */
176         modest_mailboxes_window_disconnect_signals (MODEST_WINDOW (obj));       
177
178         G_OBJECT_CLASS(parent_class)->finalize (obj);
179 }
180
181 static void
182 modest_mailboxes_window_disconnect_signals (ModestWindow *self)
183 {
184         ModestMailboxesWindowPrivate *priv;
185         priv = MODEST_MAILBOXES_WINDOW_GET_PRIVATE(self);
186
187         if (g_signal_handler_is_connected (G_OBJECT (modest_runtime_get_mail_operation_queue ()), 
188                                            priv->queue_change_handler))
189                 g_signal_handler_disconnect (G_OBJECT (modest_runtime_get_mail_operation_queue ()), 
190                                              priv->queue_change_handler);
191
192         modest_signal_mgr_disconnect_all_and_destroy (priv->sighandlers);
193         priv->sighandlers = NULL;
194 }
195
196 static void
197 on_visible_account_changed (ModestFolderView *mailboxes_view,
198                             const gchar *account_id,
199                             gpointer user_data)
200 {
201         if (account_id) {
202                 TnyAccount *acc = 
203                         modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store(),
204                                                                      MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
205                                                                      account_id);
206                 if (acc) {
207                         const gchar *name;
208                         gchar *title = NULL;
209
210                         name = modest_tny_account_get_parent_modest_account_name_for_server_account (acc);
211                         title = modest_account_mgr_get_display_name (modest_runtime_get_account_mgr(),
212                                                                      name);
213                         if (title) {
214                                 gtk_window_set_title (GTK_WINDOW (user_data), title);
215                                 g_free (title);
216                         } else {
217                                 gtk_window_set_title (GTK_WINDOW (user_data), _("mcen_ap_name"));
218                         }
219                         g_object_unref (acc);
220                 }
221         } else {
222                 gtk_window_set_title (GTK_WINDOW (user_data), _("mcen_ap_name"));
223         }
224 }
225
226 static void
227 connect_signals (ModestMailboxesWindow *self)
228 {
229         ModestMailboxesWindowPrivate *priv;
230
231         priv = MODEST_MAILBOXES_WINDOW_GET_PRIVATE(self);
232
233         /* mailboxes view */
234         priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers, 
235                                                        G_OBJECT (priv->folder_view), "folder-activated", 
236                                                        G_CALLBACK (on_mailbox_activated), self);
237
238         priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
239                                                        G_OBJECT (modest_runtime_get_window_mgr ()),
240                                                        "progress-list-changed",
241                                                        G_CALLBACK (on_progress_list_changed), self);
242
243         priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
244                                                        G_OBJECT (priv->folder_view),
245                                                        "activity-changed",
246                                                        G_CALLBACK (on_activity_changed), self);
247
248         priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
249                                                        G_OBJECT (priv->folder_view),
250                                                        "visible-account-changed",
251                                                        G_CALLBACK (on_visible_account_changed), self);
252
253         priv->sighandlers = 
254                 modest_signal_mgr_connect (priv->sighandlers,
255                                            G_OBJECT (priv->new_message_button),
256                                            "clicked",
257                                            G_CALLBACK (modest_ui_actions_on_new_msg), self);
258
259         /* connect window keys -> priv->folder_view scroll here? */
260         g_signal_connect(G_OBJECT(self), "key-press-event",
261                         G_CALLBACK(on_key_press), self);
262 }
263
264 ModestWindow *
265 modest_mailboxes_window_new (const gchar *account)
266 {
267         ModestMailboxesWindow *self = NULL;     
268         ModestMailboxesWindowPrivate *priv = NULL;
269         HildonProgram *app;
270         GdkPixbuf *window_icon;
271         GtkWidget *pannable;
272         GtkWidget *action_area_box;
273         GdkPixbuf *new_message_pixbuf;
274         guint accel_key;
275         GdkModifierType accel_mods;
276         GtkAccelGroup *accel_group;
277         GtkWidget *top_alignment;
278 #ifdef MODEST_TOOLKIT_HILDON2
279         GtkWidget *live_search;
280 #endif
281         
282         self  = MODEST_MAILBOXES_WINDOW(g_object_new(MODEST_TYPE_MAILBOXES_WINDOW, NULL));
283         priv = MODEST_MAILBOXES_WINDOW_GET_PRIVATE(self);
284
285         pannable = hildon_pannable_area_new ();
286         priv->queue_change_handler =
287                 g_signal_connect (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
288                                   "queue-changed",
289                                   G_CALLBACK (on_queue_changed),
290                                   self);
291
292         priv->folder_view  = modest_platform_create_folder_view (NULL);
293 #ifdef MODEST_TOOLKIT_HILDON2
294         live_search = modest_folder_view_setup_live_search (MODEST_FOLDER_VIEW (priv->folder_view));
295         hildon_live_search_widget_hook (HILDON_LIVE_SEARCH (live_search), GTK_WIDGET (self), priv->folder_view);
296 #endif
297         modest_folder_view_set_cell_style (MODEST_FOLDER_VIEW (priv->folder_view),
298                                            MODEST_FOLDER_VIEW_CELL_STYLE_COMPACT);
299         modest_folder_view_set_filter (MODEST_FOLDER_VIEW (priv->folder_view), 
300                                        MODEST_FOLDER_VIEW_FILTER_HIDE_ACCOUNTS);
301
302         action_area_box = hildon_tree_view_get_action_area_box (GTK_TREE_VIEW (priv->folder_view));
303         priv->new_message_button = hildon_button_new (0, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
304
305         hildon_button_set_title (HILDON_BUTTON (priv->new_message_button), _("mcen_ti_new_message"));
306         new_message_pixbuf = modest_platform_get_icon ("general_add", MODEST_ICON_SIZE_BIG);
307         hildon_button_set_image (HILDON_BUTTON (priv->new_message_button), gtk_image_new_from_pixbuf (new_message_pixbuf));
308         g_object_unref (new_message_pixbuf);
309
310         gtk_box_pack_start (GTK_BOX (action_area_box), priv->new_message_button, TRUE, TRUE, 0);
311         gtk_widget_show_all (priv->new_message_button);
312         hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->folder_view), TRUE);
313         
314         /* Set account store */
315         tny_account_store_view_set_account_store (TNY_ACCOUNT_STORE_VIEW (priv->folder_view),
316                                                   TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
317
318         priv->top_vbox = gtk_vbox_new (0, FALSE);
319         top_alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
320         gtk_alignment_set_padding (GTK_ALIGNMENT (top_alignment), 
321                                    0, 0, 
322                                    MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
323
324         gtk_container_add (GTK_CONTAINER (pannable), priv->folder_view);
325         gtk_box_pack_end (GTK_BOX (priv->top_vbox), pannable, TRUE, TRUE, 0);
326 #ifdef MODEST_TOOLKIT_HILDON2
327         gtk_box_pack_end (GTK_BOX (priv->top_vbox), live_search, FALSE, FALSE, 0);
328 #endif
329         gtk_container_add (GTK_CONTAINER (top_alignment), priv->top_vbox);
330         gtk_container_add (GTK_CONTAINER (self), top_alignment);
331
332         gtk_widget_show (priv->folder_view);
333         gtk_widget_show (pannable);
334         gtk_widget_show (top_alignment);
335         gtk_widget_show (priv->top_vbox);
336
337         connect_signals (MODEST_MAILBOXES_WINDOW (self));
338
339         /* Get device name */
340         modest_maemo_utils_get_device_name ();
341
342         app = hildon_program_get_instance ();
343         hildon_program_add_window (app, HILDON_WINDOW (self));
344         
345         /* Set window icon */
346         window_icon = modest_platform_get_icon (MODEST_APP_ICON, MODEST_ICON_SIZE_BIG);
347         if (window_icon) {
348                 gtk_window_set_icon (GTK_WINDOW (self), window_icon);
349                 g_object_unref (window_icon);
350         }
351
352         /* Dont't restore settings here, 
353          * because it requires a gtk_widget_show(), 
354          * and we don't want to do that until later,
355          * so that the UI is not visible for non-menu D-Bus activation.
356          */
357
358         g_signal_connect (G_OBJECT (self), "map-event",
359                           G_CALLBACK (on_map_event),
360                           G_OBJECT (self));
361         update_progress_hint (self);
362
363         accel_group = gtk_accel_group_new ();
364         gtk_accelerator_parse ("<Control>n", &accel_key, &accel_mods);
365         gtk_widget_add_accelerator (priv->new_message_button, "clicked", accel_group,
366                                     accel_key, accel_mods, 0);
367         gtk_window_add_accel_group (GTK_WINDOW (self), accel_group);
368
369         modest_folder_view_set_filter (MODEST_FOLDER_VIEW (priv->folder_view),
370                                        MODEST_FOLDER_VIEW_FILTER_SHOW_ONLY_MAILBOXES);
371
372         modest_mailboxes_window_set_account (MODEST_MAILBOXES_WINDOW (self), account);
373
374         return MODEST_WINDOW(self);
375 }
376
377 ModestFolderView *
378 modest_mailboxes_window_get_folder_view (ModestMailboxesWindow *self)
379 {
380         ModestMailboxesWindowPrivate *priv = NULL;
381
382         g_return_val_if_fail (MODEST_IS_MAILBOXES_WINDOW(self), FALSE);
383
384         priv = MODEST_MAILBOXES_WINDOW_GET_PRIVATE (self);
385         
386         return MODEST_FOLDER_VIEW (priv->folder_view);
387 }
388
389 void
390 modest_mailboxes_window_set_account (ModestMailboxesWindow *self,
391                                      const gchar *account_name)
392 {
393         ModestMailboxesWindowPrivate *priv = NULL;
394         ModestAccountMgr *mgr;
395         ModestAccountSettings *settings = NULL;
396         ModestServerAccountSettings *store_settings = NULL;
397
398         g_return_if_fail (MODEST_IS_MAILBOXES_WINDOW(self));
399
400         priv = MODEST_MAILBOXES_WINDOW_GET_PRIVATE (self);
401
402         /* Get account data */
403         mgr = modest_runtime_get_account_mgr ();
404
405         settings = modest_account_mgr_load_account_settings (mgr, account_name);
406         if (!settings)
407                 goto free_refs;
408
409         store_settings = modest_account_settings_get_store_settings (settings);
410         if (!store_settings)
411                 goto free_refs;
412
413         if (priv->current_store_account != NULL)
414                 g_free (priv->current_store_account);
415         priv->current_store_account = g_strdup (modest_server_account_settings_get_account_name (store_settings));
416
417         modest_folder_view_set_account_id_of_visible_server_account
418                 (MODEST_FOLDER_VIEW (priv->folder_view),
419                  priv->current_store_account);
420
421         modest_window_set_active_account (MODEST_WINDOW (self), account_name);
422         update_progress_hint (self);
423
424 free_refs:
425         if (store_settings)
426                 g_object_unref (store_settings);
427         if (settings)
428                 g_object_unref (settings);
429
430 }
431
432 static void
433 on_mailbox_activated (ModestFolderView *mailboxes_view,
434                       TnyFolder *folder,
435                       gpointer userdata)
436 {
437         ModestMailboxesWindowPrivate *priv = NULL;
438         ModestMailboxesWindow *self = (ModestMailboxesWindow *) userdata;
439         GtkWidget *new_window;
440         gboolean registered;
441         const gchar *active_account;
442
443         g_return_if_fail (MODEST_IS_MAILBOXES_WINDOW(self));
444
445         priv = MODEST_MAILBOXES_WINDOW_GET_PRIVATE (self);
446
447         if (!folder)
448                 return;
449
450         if (!TNY_IS_FOLDER (folder))
451                 return;
452
453         new_window = GTK_WIDGET (modest_folder_window_new (NULL));
454         active_account = modest_window_get_active_account (MODEST_WINDOW (self));
455         modest_window_set_active_account (MODEST_WINDOW (self), active_account);
456         registered = modest_window_mgr_register_window (modest_runtime_get_window_mgr (), 
457                                                         MODEST_WINDOW (new_window),
458                                                         MODEST_WINDOW (self));
459
460         if (!registered) {
461                 gtk_widget_destroy (new_window);
462                 new_window = NULL;
463         } else {
464                 const gchar *name;
465                 active_account = modest_window_get_active_account (MODEST_WINDOW (self));
466                 modest_folder_window_set_account (MODEST_FOLDER_WINDOW (new_window), active_account);
467                 name = tny_folder_get_name (folder);
468                 if (name) {
469                         modest_folder_window_set_mailbox (MODEST_FOLDER_WINDOW (new_window), name);
470                 }
471                 gtk_widget_show (new_window);
472         }
473         
474 }
475
476 static gboolean 
477 on_map_event (GtkWidget *widget,
478               GdkEvent *event,
479               gpointer userdata)
480 {
481         ModestMailboxesWindow *self = (ModestMailboxesWindow *) userdata;
482         ModestMailboxesWindowPrivate *priv = MODEST_MAILBOXES_WINDOW_GET_PRIVATE (self);
483
484         if (priv->progress_hint) {
485                 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
486         }
487
488         return FALSE;
489 }
490
491 static gboolean
492 has_active_operations (ModestMailboxesWindow *self)
493 {
494         GSList *operations = NULL, *node;
495         ModestMailOperationQueue *queue;
496         gboolean has_active = FALSE;
497
498         queue = modest_runtime_get_mail_operation_queue ();
499         operations = modest_mail_operation_queue_get_by_source (queue, G_OBJECT (self));
500
501         for (node = operations; node != NULL; node = g_slist_next (node)) {
502                 if (!modest_mail_operation_is_finished (MODEST_MAIL_OPERATION (node->data))) {
503                         has_active = TRUE;
504                         break;
505                 }
506         }
507
508         if (operations) {
509                 g_slist_foreach (operations, (GFunc) g_object_unref, NULL);
510                 g_slist_free (operations);
511         }
512
513         return has_active;
514 }
515
516 static void
517 update_progress_hint (ModestMailboxesWindow *self)
518 {
519         ModestMailboxesWindowPrivate *priv = MODEST_MAILBOXES_WINDOW_GET_PRIVATE (self);
520
521         if (has_active_operations (self)) {
522                 priv->progress_hint = TRUE;
523         } else {
524                 priv->progress_hint = FALSE;
525         }
526
527         if (!priv->progress_hint && priv->current_store_account) {
528                 priv->progress_hint = modest_window_mgr_has_progress_operation_on_account (modest_runtime_get_window_mgr (),
529                                                                                            priv->current_store_account);
530         }
531
532         if (!priv->progress_hint) {
533                 priv->progress_hint = modest_folder_view_get_activity (MODEST_FOLDER_VIEW (priv->folder_view));
534         }
535
536         modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
537
538         if (GTK_WIDGET_VISIBLE (self)) {
539                 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), priv->progress_hint ? 1:0);
540         }
541 }
542
543 static void
544 on_progress_list_changed (ModestWindowMgr *mgr,
545                           ModestMailboxesWindow *self)
546 {
547         update_progress_hint (self);
548 }
549
550 static void 
551 on_mail_operation_started (ModestMailOperation *mail_op,
552                            gpointer user_data)
553 {
554         ModestMailboxesWindow *self;
555         ModestMailOperationTypeOperation op_type;
556         GObject *source = NULL;
557
558         self = MODEST_MAILBOXES_WINDOW (user_data);
559         op_type = modest_mail_operation_get_type_operation (mail_op);
560         source = modest_mail_operation_get_source(mail_op);
561         if (G_OBJECT (self) == source) {
562                 update_progress_hint (self);
563         }
564         g_object_unref (source);
565 }
566
567 static void 
568 on_mail_operation_finished (ModestMailOperation *mail_op,
569                             gpointer user_data)
570 {
571         ModestMailboxesWindow *self;
572
573         self = MODEST_MAILBOXES_WINDOW (user_data);
574
575         /* Don't disable the progress hint if there are more pending
576            operations from this window */
577         update_progress_hint (self);
578
579         modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
580 }
581
582 static void
583 on_queue_changed (ModestMailOperationQueue *queue,
584                   ModestMailOperation *mail_op,
585                   ModestMailOperationQueueNotification type,
586                   ModestMailboxesWindow *self)
587 {
588         ModestMailboxesWindowPrivate *priv;
589
590         priv = MODEST_MAILBOXES_WINDOW_GET_PRIVATE (self);
591
592         /* If this operations was created by another window, do nothing */
593         if (!modest_mail_operation_is_mine (mail_op, G_OBJECT(self))) 
594                 return;
595
596         if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_ADDED) {
597                 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
598                                                                G_OBJECT (mail_op),
599                                                                "operation-started",
600                                                                G_CALLBACK (on_mail_operation_started),
601                                                                self);
602                 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
603                                                                G_OBJECT (mail_op),
604                                                                "operation-finished",
605                                                                G_CALLBACK (on_mail_operation_finished),
606                                                                self);
607         } else if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED) {
608                 priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
609                                                                   G_OBJECT (mail_op),
610                                                                   "operation-started");
611                 priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
612                                                                   G_OBJECT (mail_op),
613                                                                   "operation-finished");
614         }
615 }
616
617 static void
618 on_activity_changed (ModestFolderView *view,
619                      gboolean activity,
620                      ModestMailboxesWindow *self)
621 {
622         g_return_if_fail (MODEST_IS_MAILBOXES_WINDOW (self));
623
624         update_progress_hint (self);
625 }
626
627
628 static gboolean
629 on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
630 {
631         ModestMailboxesWindowPrivate *priv;
632         HildonPannableArea *pannable;
633
634         if (event->type == GDK_KEY_RELEASE)
635                 return FALSE;
636
637         priv = MODEST_MAILBOXES_WINDOW_GET_PRIVATE(user_data);
638
639         pannable = HILDON_PANNABLE_AREA (gtk_widget_get_parent (priv->folder_view));
640
641         switch (event->keyval) {
642
643         case GDK_Up:
644                 modest_maemo_utils_scroll_pannable(pannable, 0, -1);
645                 break;
646
647         case GDK_Down:
648                 modest_maemo_utils_scroll_pannable(pannable, 0, 1);
649                 break;
650         }
651
652         return FALSE;
653 }