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