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