Add mail operations feedback to accounts window
[modest] / src / hildon2 / modest-accounts-window.c
1 /* Copyright (c) 2008, 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-accounts-window.h>
31 #include <modest-osso-state-saving.h>
32 #include <libosso.h>
33 #include <hildon/hildon-pannable-area.h>
34 #include <hildon/hildon-banner.h>
35 #include <hildon/hildon-helper.h>
36 #include <modest-ui-actions.h>
37 #include <modest-window-mgr.h>
38 #include <modest-signal-mgr.h>
39 #include <modest-runtime.h>
40 #include <modest-platform.h>
41 #include <hildon/hildon-program.h>
42 #include <hildon/hildon-button.h>
43 #include <modest-maemo-utils.h>
44 #include <modest-icon-names.h>
45 #include <modest-defs.h>
46 #include <modest-folder-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-ui-constants.h>
51 #include <modest-account-mgr-helpers.h>
52 #include <modest-mailboxes-window.h>
53
54
55 /* 'private'/'protected' functions */
56 static void modest_accounts_window_class_init  (ModestAccountsWindowClass *klass);
57 static void modest_accounts_window_instance_init (ModestAccountsWindow *obj);
58 static void modest_accounts_window_finalize    (GObject *obj);
59
60 static void connect_signals (ModestAccountsWindow *self);
61 static void modest_accounts_window_disconnect_signals (ModestWindow *self);
62
63 static void on_account_activated (GtkTreeView *treeview,
64                                   GtkTreePath *path,
65                                   GtkTreeViewColumn *column,
66                                   ModestAccountsWindow *accounts_window);
67 static void on_progress_list_changed (ModestWindowMgr *mgr,
68                                       ModestAccountsWindow *self);
69 static void setup_menu (ModestAccountsWindow *self);
70 static gboolean _modest_accounts_window_map_event (GtkWidget *widget,
71                                                    GdkEvent *event,
72                                                    gpointer userdata);
73 static void update_progress_hint (ModestAccountsWindow *self);
74 static void on_queue_changed    (ModestMailOperationQueue *queue,
75                                  ModestMailOperation *mail_op,
76                                  ModestMailOperationQueueNotification type,
77                                  ModestAccountsWindow *self);
78 static void on_row_inserted (GtkTreeModel *tree_model,
79                              GtkTreePath  *path,
80                              GtkTreeIter  *iter,
81                              gpointer      user_data);
82 static void on_row_deleted (GtkTreeModel *tree_model,
83                             GtkTreePath  *path,
84                             gpointer      user_data);
85 static void row_count_changed (ModestAccountsWindow *self);
86
87 typedef struct _ModestAccountsWindowPrivate ModestAccountsWindowPrivate;
88 struct _ModestAccountsWindowPrivate {
89
90         GtkWidget *box;
91         GtkWidget *pannable;
92         GtkWidget *account_view;
93         GtkWidget *no_accounts_container;
94         GtkWidget *new_message_button;
95
96         /* signals */
97         GSList *sighandlers;
98
99         gboolean progress_hint;
100         guint queue_change_handler;
101 };
102 #define MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE((o), \
103                                                                             MODEST_TYPE_ACCOUNTS_WINDOW, \
104                                                                             ModestAccountsWindowPrivate))
105
106 /* globals */
107 static GtkWindowClass *parent_class = NULL;
108
109 /************************************************************************/
110
111 GType
112 modest_accounts_window_get_type (void)
113 {
114         static GType my_type = 0;
115         if (!my_type) {
116                 static const GTypeInfo my_info = {
117                         sizeof(ModestAccountsWindowClass),
118                         NULL,           /* base init */
119                         NULL,           /* base finalize */
120                         (GClassInitFunc) modest_accounts_window_class_init,
121                         NULL,           /* class finalize */
122                         NULL,           /* class data */
123                         sizeof(ModestAccountsWindow),
124                         1,              /* n_preallocs */
125                         (GInstanceInitFunc) modest_accounts_window_instance_init,
126                         NULL
127                 };
128                 my_type = g_type_register_static (MODEST_TYPE_HILDON2_WINDOW,
129                                                   "ModestAccountsWindow",
130                                                   &my_info, 0);
131         }
132         return my_type;
133 }
134
135 static void
136 modest_accounts_window_class_init (ModestAccountsWindowClass *klass)
137 {
138         GObjectClass *gobject_class;
139         gobject_class = (GObjectClass*) klass;
140         ModestWindowClass *modest_window_class = (ModestWindowClass *) klass;
141
142         parent_class            = g_type_class_peek_parent (klass);
143         gobject_class->finalize = modest_accounts_window_finalize;
144
145         g_type_class_add_private (gobject_class, sizeof(ModestAccountsWindowPrivate));
146         
147         modest_window_class->disconnect_signals_func = modest_accounts_window_disconnect_signals;
148 }
149
150 static void
151 modest_accounts_window_instance_init (ModestAccountsWindow *obj)
152 {
153         ModestAccountsWindowPrivate *priv;
154
155         priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(obj);
156
157         priv->sighandlers = NULL;
158         
159         priv->account_view = NULL;
160         priv->progress_hint = FALSE;
161         
162         modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(),
163                                             GTK_WINDOW(obj),
164                                             "applications_email_accountsview");
165 }
166
167 static void
168 modest_accounts_window_finalize (GObject *obj)
169 {
170         ModestAccountsWindowPrivate *priv;
171
172         priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(obj);
173
174         /* Sanity check: shouldn't be needed, the window mgr should
175            call this function before */
176         modest_accounts_window_disconnect_signals (MODEST_WINDOW (obj));        
177
178         G_OBJECT_CLASS(parent_class)->finalize (obj);
179 }
180
181 static void
182 modest_accounts_window_disconnect_signals (ModestWindow *self)
183 {       
184         ModestAccountsWindowPrivate *priv;      
185         priv = MODEST_ACCOUNTS_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 connect_signals (ModestAccountsWindow *self)
198 {
199         ModestAccountsWindowPrivate *priv;
200         GtkTreeModel *model;
201
202         priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(self);
203
204         /* accounts view */
205         priv->sighandlers = 
206                 modest_signal_mgr_connect (priv->sighandlers,
207                                            G_OBJECT (priv->account_view), "row-activated", 
208                                            G_CALLBACK (on_account_activated), self);
209
210         priv->sighandlers = 
211                 modest_signal_mgr_connect (priv->sighandlers,
212                                            G_OBJECT (modest_runtime_get_window_mgr ()),
213                                            "progress-list-changed",
214                                            G_CALLBACK (on_progress_list_changed), self);
215
216         model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->account_view));
217
218         priv->sighandlers =
219                 modest_signal_mgr_connect (priv->sighandlers,
220                                            G_OBJECT (model),
221                                            "row-inserted",
222                                            G_CALLBACK (on_row_inserted), self);
223
224         priv->sighandlers =
225                 modest_signal_mgr_connect (priv->sighandlers,
226                                            G_OBJECT (model),
227                                            "row-deleted",
228                                            G_CALLBACK (on_row_deleted), self);
229
230         priv->sighandlers = 
231                 modest_signal_mgr_connect (priv->sighandlers,
232                                            G_OBJECT (priv->new_message_button),
233                                            "clicked",
234                                            G_CALLBACK (modest_ui_actions_on_new_msg), self);
235
236         /* we don't register this in sighandlers, as it should be run
237          * after disconnecting all signals, in destroy stage */
238 }
239
240 ModestWindow *
241 modest_accounts_window_new (void)
242 {
243         ModestAccountsWindow *self = NULL;
244         ModestAccountsWindowPrivate *priv = NULL;
245         HildonProgram *app;
246         GdkPixbuf *window_icon;
247         GdkPixbuf *new_message_pixbuf;
248         GtkWidget *action_area_box;
249         guint accel_key;
250         GdkModifierType accel_mods;
251         GtkAccelGroup *accel_group;
252         GtkWidget *no_accounts_label;
253         GtkWidget *empty_view_new_message_button;
254         GtkWidget *box_alignment;
255
256         self  = MODEST_ACCOUNTS_WINDOW(g_object_new(MODEST_TYPE_ACCOUNTS_WINDOW, NULL));
257         priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(self);
258
259         new_message_pixbuf = modest_platform_get_icon ("general_add", MODEST_ICON_SIZE_BIG);
260
261         box_alignment = gtk_alignment_new (0, 0, 1.0, 1.0);
262         gtk_alignment_set_padding (GTK_ALIGNMENT (box_alignment), 
263                                    0, 0,
264                                    HILDON_MARGIN_DOUBLE, HILDON_MARGIN_DOUBLE);
265         priv->box = gtk_vbox_new (FALSE, 0);
266
267         no_accounts_label = gtk_label_new (_("mcen_ia_noaccounts"));
268         
269         gtk_misc_set_alignment (GTK_MISC (no_accounts_label), 0.5, 0.5);
270         hildon_helper_set_logical_font (no_accounts_label, "LargeSystemFont");
271
272         empty_view_new_message_button = hildon_button_new (MODEST_EDITABLE_SIZE, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
273         hildon_button_set_title (HILDON_BUTTON (empty_view_new_message_button), _("mcen_ti_new_message"));
274         hildon_button_set_image (HILDON_BUTTON (empty_view_new_message_button), gtk_image_new_from_pixbuf (new_message_pixbuf));
275
276
277         priv->no_accounts_container = gtk_vbox_new (FALSE, 0);
278         gtk_box_pack_start (GTK_BOX (priv->no_accounts_container), empty_view_new_message_button, FALSE, FALSE, 0);
279         gtk_widget_show_all (empty_view_new_message_button);
280         gtk_box_pack_end (GTK_BOX (priv->no_accounts_container), no_accounts_label, TRUE, TRUE, 0);
281         gtk_widget_show (no_accounts_label);
282         gtk_box_pack_start (GTK_BOX (priv->box), priv->no_accounts_container, TRUE, TRUE, 0);
283
284         g_signal_connect (G_OBJECT (empty_view_new_message_button),
285                           "clicked",
286                           G_CALLBACK (modest_ui_actions_on_new_msg), self);
287         
288         priv->pannable = hildon_pannable_area_new ();
289
290         priv->queue_change_handler =
291                 g_signal_connect (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
292                                   "queue-changed",
293                                   G_CALLBACK (on_queue_changed),
294                                   self);
295
296         priv->account_view  = GTK_WIDGET (modest_account_view_new (modest_runtime_get_account_mgr ()));
297
298         action_area_box = hildon_tree_view_get_action_area_box (GTK_TREE_VIEW (priv->account_view));
299         priv->new_message_button = hildon_button_new (0, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
300
301         hildon_button_set_title (HILDON_BUTTON (priv->new_message_button), _("mcen_ti_new_message"));
302         hildon_button_set_image (HILDON_BUTTON (priv->new_message_button), gtk_image_new_from_pixbuf (new_message_pixbuf));
303
304         gtk_box_pack_start (GTK_BOX (action_area_box), priv->new_message_button, TRUE, TRUE, 0);
305         gtk_widget_show_all (priv->new_message_button);
306         hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->account_view), TRUE);
307
308         g_object_unref (new_message_pixbuf);
309         setup_menu (self);
310
311         gtk_container_add (GTK_CONTAINER (priv->pannable), priv->account_view);
312         gtk_box_pack_start (GTK_BOX (priv->box), priv->pannable, TRUE, TRUE, 0);
313         gtk_container_add (GTK_CONTAINER (box_alignment), priv->box);
314         gtk_container_add (GTK_CONTAINER (self), box_alignment);
315
316         gtk_widget_show (priv->pannable);
317         gtk_widget_show (priv->box);
318         gtk_widget_show (box_alignment);
319
320         connect_signals (MODEST_ACCOUNTS_WINDOW (self));
321
322         /* Load previous osso state, for instance if we are being restored from 
323          * hibernation:  */
324         modest_osso_load_state ();
325
326         /* Get device name */
327         modest_maemo_utils_get_device_name ();
328
329         app = hildon_program_get_instance ();
330         hildon_program_add_window (app, HILDON_WINDOW (self));
331         
332         /* Set window icon */
333         window_icon = modest_platform_get_icon (MODEST_APP_ICON, MODEST_ICON_SIZE_BIG);
334         if (window_icon) {
335                 gtk_window_set_icon (GTK_WINDOW (self), window_icon);
336                 g_object_unref (window_icon);
337         }
338
339         /* Dont't restore settings here, 
340          * because it requires a gtk_widget_show(), 
341          * and we don't want to do that until later,
342          * so that the UI is not visible for non-menu D-Bus activation.
343          */
344
345         g_signal_connect (G_OBJECT (self), "map-event",
346                           G_CALLBACK (_modest_accounts_window_map_event),
347                           G_OBJECT (self));
348         update_progress_hint (self);
349
350         row_count_changed (self);
351
352         accel_group = gtk_accel_group_new ();
353         gtk_accelerator_parse ("<Control>n", &accel_key, &accel_mods);
354         gtk_widget_add_accelerator (priv->new_message_button, "clicked", accel_group,
355                                     accel_key, accel_mods, 0);
356         gtk_window_add_accel_group (GTK_WINDOW (self), accel_group);
357
358         return MODEST_WINDOW(self);
359 }
360
361 ModestAccountView *
362 modest_accounts_window_get_account_view (ModestAccountsWindow *self)
363 {
364         ModestAccountsWindowPrivate *priv = NULL;
365
366         g_return_val_if_fail (MODEST_IS_ACCOUNTS_WINDOW(self), FALSE);
367
368         priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
369         
370         return MODEST_ACCOUNT_VIEW (priv->account_view);
371 }
372
373 static void 
374 setup_menu (ModestAccountsWindow *self)
375 {
376         g_return_if_fail (MODEST_IS_ACCOUNTS_WINDOW(self));
377
378         /* Settings menu buttons */
379         modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_new_account"), NULL, 
380                                            APP_MENU_CALLBACK (modest_ui_actions_on_new_account), 
381                                            NULL);
382         modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_edit_accounts"), NULL,
383                                            APP_MENU_CALLBACK (modest_ui_actions_on_accounts), 
384                                            MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_edit_accounts));
385         modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_globalsmtpservers"), NULL,
386                                            APP_MENU_CALLBACK (modest_ui_actions_on_smtp_servers),
387                                            MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_tools_smtp_servers));
388         modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_sendandreceive"), NULL,
389                                            APP_MENU_CALLBACK (modest_ui_actions_on_send_receive),
390                                            MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_send_receive_all));
391         modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_outbox_cancelsend"), NULL,
392                                            APP_MENU_CALLBACK (modest_ui_actions_cancel_send),
393                                            MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_cancel_sending_all));
394         modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_options"), NULL,
395                                            APP_MENU_CALLBACK (modest_ui_actions_on_settings), 
396                                            NULL);
397 }
398
399
400 static void
401 on_account_activated (GtkTreeView *account_view,
402                       GtkTreePath *path,
403                       GtkTreeViewColumn *column,
404                       ModestAccountsWindow *self)
405 {
406         ModestAccountsWindowPrivate *priv;
407         gchar* account_name; 
408         GtkWidget *new_window;
409         gboolean registered;
410         ModestProtocolType store_protocol;
411         gboolean mailboxes_protocol;
412
413         priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
414
415         account_name = modest_account_view_get_path_account (MODEST_ACCOUNT_VIEW (priv->account_view), path);
416         if (!account_name)
417                 return;
418
419         /* If it's a multimailbox container, we have to show the mailboxes window */
420         store_protocol = modest_account_mgr_get_store_protocol (modest_runtime_get_account_mgr (), 
421                                                                 account_name);
422         mailboxes_protocol = 
423                 modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
424                                                                 store_protocol,
425                                                                 MODEST_PROTOCOL_REGISTRY_MULTI_MAILBOX_PROVIDER_PROTOCOLS);
426         if (mailboxes_protocol) {
427                 new_window = GTK_WIDGET (modest_mailboxes_window_new (account_name));
428         } else {
429
430                 new_window = GTK_WIDGET (modest_folder_window_new (NULL));
431         }
432
433         registered = modest_window_mgr_register_window (modest_runtime_get_window_mgr (), 
434                                                         MODEST_WINDOW (new_window),
435                                                         MODEST_WINDOW (self));
436
437         if (!registered) {
438                 gtk_widget_destroy (new_window);
439                 new_window = NULL;
440         } else {
441                 if (!mailboxes_protocol) {
442                         modest_folder_window_set_account (MODEST_FOLDER_WINDOW (new_window), account_name);
443                 }
444                 gtk_widget_show (new_window);
445         }
446         g_free (account_name);
447 }
448
449 static gboolean
450 _modest_accounts_window_map_event (GtkWidget *widget,
451                                    GdkEvent *event,
452                                    gpointer userdata)
453 {
454         ModestAccountsWindow *self = (ModestAccountsWindow *) userdata;
455         ModestAccountsWindowPrivate *priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
456
457         if (priv->progress_hint) {
458                 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
459         }
460
461         return FALSE;
462 }
463
464 static gboolean
465 has_active_operations (ModestAccountsWindow *self)
466 {
467         GSList *operations = NULL, *node;
468         ModestMailOperationQueue *queue;
469         gboolean has_active = FALSE;
470
471         queue = modest_runtime_get_mail_operation_queue ();
472         operations = modest_mail_operation_queue_get_by_source (queue, G_OBJECT (self));
473
474         for (node = operations; node != NULL; node = g_slist_next (node)) {
475                 if (!modest_mail_operation_is_finished (MODEST_MAIL_OPERATION (node->data))) {
476                         has_active = TRUE;
477                         break;
478                 }
479         }
480
481         if (operations) {
482                 g_slist_foreach (operations, (GFunc) g_object_unref, NULL);
483                 g_slist_free (operations);
484         }
485
486         return has_active;
487 }
488
489 static void
490 update_progress_hint (ModestAccountsWindow *self)
491 {
492         ModestAccountsWindowPrivate *priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
493
494         if (has_active_operations (self)) {
495                 priv->progress_hint = TRUE;
496         } else {
497                 priv->progress_hint = FALSE;
498         }
499
500         if (!priv->progress_hint) {
501                 priv->progress_hint = modest_window_mgr_has_progress_operation (modest_runtime_get_window_mgr ());
502         }
503         
504         if (GTK_WIDGET_VISIBLE (self)) {
505                 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), priv->progress_hint?1:0);
506         }
507 }
508
509 static void
510 on_progress_list_changed (ModestWindowMgr *mgr,
511                           ModestAccountsWindow *self)
512 {
513         update_progress_hint (self);
514 }
515
516 static void
517 on_row_inserted (GtkTreeModel *tree_model,
518                  GtkTreePath  *path,
519                  GtkTreeIter  *iter,
520                  gpointer      user_data)
521 {
522         ModestAccountsWindow *self;
523
524         self = (ModestAccountsWindow *) user_data;
525
526         row_count_changed (self);
527 }
528
529 static void
530 on_row_deleted (GtkTreeModel *tree_model,
531                 GtkTreePath  *path,
532                 gpointer      user_data)
533 {
534         ModestAccountsWindow *self;
535
536         self = (ModestAccountsWindow *) user_data;
537
538         row_count_changed (self);
539 }
540
541 static void row_count_changed (ModestAccountsWindow *self)
542 {
543         ModestAccountsWindowPrivate *priv;
544         GtkTreeModel *model;
545         gint count;
546         
547         priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
548         model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->account_view));
549
550         count = gtk_tree_model_iter_n_children (model, NULL);
551
552         if (count == 0) {
553                 gtk_widget_hide (priv->account_view);
554                 gtk_widget_show (priv->no_accounts_container);
555         } else {
556                 gtk_widget_hide (priv->no_accounts_container);
557                 gtk_widget_show (priv->account_view);
558         }
559         gtk_container_child_set (GTK_CONTAINER(priv->box), priv->pannable, 
560                                  "expand", count > 0,
561                                  "fill", count > 0,
562                                  NULL);
563 }
564
565 static void 
566 on_mail_operation_started (ModestMailOperation *mail_op,
567                            gpointer user_data)
568 {
569         ModestAccountsWindow *self;
570         ModestMailOperationTypeOperation op_type;
571         GObject *source = NULL;
572
573         self = MODEST_ACCOUNTS_WINDOW (user_data);
574         op_type = modest_mail_operation_get_type_operation (mail_op);
575         source = modest_mail_operation_get_source(mail_op);
576         if (G_OBJECT (self) == source) {
577                 update_progress_hint (self);
578         }
579         g_object_unref (source);
580 }
581
582 static void 
583 on_mail_operation_finished (ModestMailOperation *mail_op,
584                             gpointer user_data)
585 {
586         ModestAccountsWindow *self;
587
588         self = MODEST_ACCOUNTS_WINDOW (user_data);
589
590         /* Don't disable the progress hint if there are more pending
591            operations from this window */
592         update_progress_hint (self);
593
594         modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
595 }
596
597 static void
598 on_queue_changed (ModestMailOperationQueue *queue,
599                   ModestMailOperation *mail_op,
600                   ModestMailOperationQueueNotification type,
601                   ModestAccountsWindow *self)
602 {
603         ModestAccountsWindowPrivate *priv;
604
605         priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
606
607         /* If this operations was created by another window, do nothing */
608         if (!modest_mail_operation_is_mine (mail_op, G_OBJECT(self))) 
609                 return;
610
611         if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_ADDED) {
612                 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
613                                                                G_OBJECT (mail_op),
614                                                                "operation-started",
615                                                                G_CALLBACK (on_mail_operation_started),
616                                                                self);
617                 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
618                                                                G_OBJECT (mail_op),
619                                                                "operation-finished",
620                                                                G_CALLBACK (on_mail_operation_finished),
621                                                                self);
622         } else if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED) {
623                 priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
624                                                                   G_OBJECT (mail_op),
625                                                                   "operation-started");
626                 priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
627                                                                   G_OBJECT (mail_op),
628                                                                   "operation-finished");
629         }
630 }
631