1 /* Copyright (c) 2008, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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.
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.
30 #include <modest-header-window.h>
31 #include <modest-osso-state-saving.h>
33 #include <hildon/hildon-pannable-area.h>
34 #include <modest-window-mgr.h>
35 #include <modest-window-priv.h>
36 #include <modest-signal-mgr.h>
37 #include <modest-runtime.h>
38 #include <modest-platform.h>
39 #include <modest-maemo-utils.h>
40 #include <modest-icon-names.h>
41 #include <modest-ui-constants.h>
42 #include <modest-account-mgr.h>
43 #include <modest-account-mgr-helpers.h>
44 #include <modest-defs.h>
45 #include <modest-widget-memory.h>
46 #include <modest-ui-actions.h>
47 #include <modest-platform.h>
48 #include <modest-text-utils.h>
49 #include <hildon/hildon-button.h>
50 #include <hildon/hildon-program.h>
51 #include <hildon/hildon-banner.h>
52 #include <modest-ui-dimming-rules.h>
53 #include <modest-tny-folder.h>
56 CONTENTS_STATE_NONE = 0,
57 CONTENTS_STATE_EMPTY = 1,
58 CONTENTS_STATE_HEADERS = 2
62 EDIT_MODE_COMMAND_MOVE = 1,
63 EDIT_MODE_COMMAND_DELETE = 2,
66 typedef struct _ModestHeaderWindowPrivate ModestHeaderWindowPrivate;
67 struct _ModestHeaderWindowPrivate {
69 GtkWidget *header_view;
70 GtkWidget *empty_view;
71 GtkWidget *contents_view;
75 ContentsState contents_state;
83 GtkWidget *updating_banner;
84 guint updating_banner_timeout;
88 gulong queue_change_handler;
91 gboolean progress_hint;
92 gchar *current_store_account;
94 #define MODEST_HEADER_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
95 MODEST_TYPE_HEADER_WINDOW, \
96 ModestHeaderWindowPrivate))
98 /* 'private'/'protected' functions */
99 static void modest_header_window_class_init (ModestHeaderWindowClass *klass);
100 static void modest_header_window_init (ModestHeaderWindow *obj);
101 static void modest_header_window_finalize (GObject *obj);
103 static void connect_signals (ModestHeaderWindow *self);
104 static void modest_header_window_disconnect_signals (ModestWindow *self);
106 static void setup_menu (ModestHeaderWindow *self);
107 static GtkWidget *create_empty_view (void);
108 static GtkWidget *create_header_view (ModestWindow *progress_window,
111 static void update_view (ModestHeaderWindow *self,
112 TnyFolderChange *change);
113 static void set_contents_state (ModestHeaderWindow *window,
114 ContentsState state);
116 static void on_msg_count_changed (ModestHeaderView *header_view,
118 TnyFolderChange *change,
119 ModestHeaderWindow *header_window);
120 static void on_header_activated (ModestHeaderView *header_view,
123 ModestHeaderWindow *header_window);
124 static void on_updating_msg_list (ModestHeaderView *header_view,
127 static void set_delete_edit_mode (GtkButton *button,
128 ModestHeaderWindow *self);
129 static void set_moveto_edit_mode (GtkButton *button,
130 ModestHeaderWindow *self);
131 static gboolean on_expose_event(GtkTreeView *header_view,
132 GdkEventExpose *event,
134 static gboolean on_map_event (GtkWidget *widget,
137 static void on_vertical_movement (HildonPannableArea *area,
138 HildonMovementDirection direction,
139 gdouble x, gdouble y, gpointer user_data);
140 static void on_queue_changed (ModestMailOperationQueue *queue,
141 ModestMailOperation *mail_op,
142 ModestMailOperationQueueNotification type,
143 ModestHeaderWindow *self);
144 static void modest_header_window_pack_toolbar (ModestHildon2Window *self,
145 GtkPackType pack_type,
147 static void edit_mode_changed (ModestHeaderWindow *header_window,
150 ModestHeaderWindow *self);
151 static void on_progress_list_changed (ModestWindowMgr *mgr,
152 ModestHeaderWindow *self);
153 static void update_progress_hint (ModestHeaderWindow *self);
157 static GtkWindowClass *parent_class = NULL;
159 #define EMPTYVIEW_XALIGN 0.5
160 #define EMPTYVIEW_YALIGN 0.0
161 #define EMPTYVIEW_XSPACE 1.0
162 #define EMPTYVIEW_YSPACE 0.0
166 /************************************************************************/
169 modest_header_window_get_type (void)
171 static GType my_type = 0;
173 static const GTypeInfo my_info = {
174 sizeof(ModestHeaderWindowClass),
175 NULL, /* base init */
176 NULL, /* base finalize */
177 (GClassInitFunc) modest_header_window_class_init,
178 NULL, /* class finalize */
179 NULL, /* class data */
180 sizeof(ModestHeaderWindow),
182 (GInstanceInitFunc) modest_header_window_init,
185 my_type = g_type_register_static (MODEST_TYPE_HILDON2_WINDOW,
186 "ModestHeaderWindow",
193 modest_header_window_class_init (ModestHeaderWindowClass *klass)
195 GObjectClass *gobject_class;
196 gobject_class = (GObjectClass*) klass;
197 ModestWindowClass *modest_window_class = (ModestWindowClass *) klass;
198 ModestHildon2WindowClass *modest_hildon2_window_class = (ModestHildon2WindowClass *) klass;
200 parent_class = g_type_class_peek_parent (klass);
201 gobject_class->finalize = modest_header_window_finalize;
203 g_type_class_add_private (gobject_class, sizeof(ModestHeaderWindowPrivate));
205 modest_window_class->disconnect_signals_func = modest_header_window_disconnect_signals;
206 modest_hildon2_window_class->pack_toolbar_func = modest_header_window_pack_toolbar;
210 modest_header_window_init (ModestHeaderWindow *obj)
212 ModestHeaderWindowPrivate *priv;
214 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(obj);
216 priv->sighandlers = NULL;
218 priv->header_view = NULL;
219 priv->empty_view = NULL;
220 priv->top_vbox = NULL;
221 priv->contents_view = NULL;
222 priv->contents_state = CONTENTS_STATE_NONE;
224 priv->updating_banner = NULL;
225 priv->updating_banner_timeout = 0;
226 priv->autoscroll = TRUE;
227 priv->progress_hint = FALSE;
228 priv->queue_change_handler = 0;
229 priv->current_store_account = NULL;
231 modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(),
233 "applications_email_headerview");
237 modest_header_window_finalize (GObject *obj)
239 ModestHeaderWindowPrivate *priv;
241 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(obj);
243 g_object_unref (priv->header_view);
244 g_object_unref (priv->empty_view);
245 g_object_unref (priv->folder);
247 if (priv->current_store_account) {
248 g_free (priv->current_store_account);
249 priv->current_store_account = NULL;
252 /* Sanity check: shouldn't be needed, the window mgr should
253 call this function before */
254 modest_header_window_disconnect_signals (MODEST_WINDOW (obj));
256 if (priv->updating_banner_timeout > 0) {
257 g_source_remove (priv->updating_banner_timeout);
258 priv->updating_banner_timeout = 0;
260 if (priv->updating_banner) {
261 gtk_widget_destroy (priv->updating_banner);
262 priv->updating_banner = NULL;
265 G_OBJECT_CLASS(parent_class)->finalize (obj);
269 modest_header_window_disconnect_signals (ModestWindow *self)
271 ModestHeaderWindowPrivate *priv;
272 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
274 if (g_signal_handler_is_connected (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
275 priv->queue_change_handler))
276 g_signal_handler_disconnect (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
277 priv->queue_change_handler);
279 modest_signal_mgr_disconnect_all_and_destroy (priv->sighandlers);
280 priv->sighandlers = NULL;
285 connect_signals (ModestHeaderWindow *self)
287 ModestHeaderWindowPrivate *priv;
289 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
294 modest_signal_mgr_connect (priv->sighandlers,G_OBJECT(priv->header_view),
296 G_CALLBACK(on_msg_count_changed), self);
298 modest_signal_mgr_connect (priv->sighandlers, G_OBJECT (priv->header_view),
300 G_CALLBACK (on_header_activated), self);
302 modest_signal_mgr_connect (priv->sighandlers,
303 G_OBJECT (priv->header_view),
305 G_CALLBACK (on_updating_msg_list),
308 modest_signal_mgr_connect (priv->sighandlers,
309 G_OBJECT (priv->header_view),
311 G_CALLBACK (on_expose_event),
315 modest_signal_mgr_connect (priv->sighandlers,
318 G_CALLBACK (on_map_event),
322 modest_signal_mgr_connect (priv->sighandlers,
323 G_OBJECT (priv->contents_view),
325 G_CALLBACK (on_vertical_movement),
328 /* Mail Operation Queue */
329 priv->queue_change_handler =
330 g_signal_connect (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
332 G_CALLBACK (on_queue_changed),
334 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
335 G_OBJECT (modest_runtime_get_window_mgr ()),
336 "progress-list-changed",
337 G_CALLBACK (on_progress_list_changed), self);
341 create_header_view (ModestWindow *self, TnyFolder *folder)
343 GtkWidget *header_view;
345 header_view = modest_header_view_new (NULL, MODEST_HEADER_VIEW_STYLE_TWOLINES);
346 modest_header_view_set_folder (MODEST_HEADER_VIEW (header_view), folder,
347 TRUE, self, NULL, NULL);
348 modest_header_view_set_filter (MODEST_HEADER_VIEW (header_view),
349 MODEST_HEADER_VIEW_FILTER_NONE);
350 modest_widget_memory_restore (modest_runtime_get_conf (), G_OBJECT(header_view),
351 MODEST_CONF_HEADER_VIEW_KEY);
357 create_empty_view (void)
359 GtkWidget *label = NULL;
360 GtkWidget *align = NULL;
362 align = gtk_alignment_new(EMPTYVIEW_XALIGN, EMPTYVIEW_YALIGN, EMPTYVIEW_XSPACE, EMPTYVIEW_YSPACE);
363 label = gtk_label_new (_("mcen_ia_nomessages"));
364 gtk_widget_show (label);
365 gtk_widget_show (align);
366 gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
367 gtk_container_add (GTK_CONTAINER (align), label);
373 on_vertical_movement (HildonPannableArea *area,
374 HildonMovementDirection direction,
375 gdouble x, gdouble y, gpointer user_data)
377 ModestHeaderWindow *self = (ModestHeaderWindow *) user_data;
378 ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
380 priv->autoscroll = FALSE;
385 modest_header_window_new (TnyFolder *folder, const gchar *account_name)
387 ModestHeaderWindow *self = NULL;
388 ModestHeaderWindowPrivate *priv = NULL;
390 GdkPixbuf *window_icon;
391 ModestAccountMgr *mgr;
392 ModestAccountSettings *settings = NULL;
393 ModestServerAccountSettings *store_settings = NULL;
395 self = MODEST_HEADER_WINDOW(g_object_new(MODEST_TYPE_HEADER_WINDOW, NULL));
396 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
398 priv->folder = g_object_ref (folder);
400 priv->contents_view = hildon_pannable_area_new ();
402 priv->header_view = create_header_view (MODEST_WINDOW (self), folder);
403 priv->empty_view = create_empty_view ();
404 g_object_ref (priv->header_view);
405 g_object_ref (priv->empty_view);
406 g_signal_connect (G_OBJECT (self), "edit-mode-changed",
407 G_CALLBACK (edit_mode_changed), (gpointer) self);
410 priv->top_vbox = gtk_vbox_new (FALSE, 0);
411 gtk_box_pack_end (GTK_BOX (priv->top_vbox), priv->contents_view, TRUE, TRUE, 0);
413 gtk_container_add (GTK_CONTAINER (self), priv->top_vbox);
415 gtk_widget_show (priv->contents_view);
416 gtk_widget_show (priv->top_vbox);
418 connect_signals (MODEST_HEADER_WINDOW (self));
420 update_view (self, NULL);
422 /* Load previous osso state, for instance if we are being restored from
424 modest_osso_load_state ();
426 /* Get device name */
427 modest_maemo_utils_get_device_name ();
429 app = hildon_program_get_instance ();
430 hildon_program_add_window (app, HILDON_WINDOW (self));
432 /* Set window icon */
433 window_icon = modest_platform_get_icon (MODEST_APP_ICON, MODEST_ICON_SIZE_BIG);
435 gtk_window_set_icon (GTK_WINDOW (self), window_icon);
436 g_object_unref (window_icon);
439 /* Set window title */
440 if (TNY_IS_FOLDER (folder)) {
443 folder_name = modest_tny_folder_get_display_name (folder);
444 gtk_window_set_title (GTK_WINDOW (self), folder_name);
445 g_free (folder_name);
448 /* Dont't restore settings here,
449 * because it requires a gtk_widget_show(),
450 * and we don't want to do that until later,
451 * so that the UI is not visible for non-menu D-Bus activation.
454 /* setup edit modes */
455 modest_hildon2_window_register_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_DELETE,
456 _("mcen_ti_edit_delete"), _HL("wdgt_bd_delete"),
457 GTK_TREE_VIEW (priv->header_view),
458 GTK_SELECTION_MULTIPLE,
459 EDIT_MODE_CALLBACK (modest_ui_actions_on_edit_mode_delete_message));
460 modest_hildon2_window_register_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_MOVE,
461 _("mcen_ti_edit_move"), _HL("wdgt_bd_move"),
462 GTK_TREE_VIEW (priv->header_view),
463 GTK_SELECTION_MULTIPLE,
464 EDIT_MODE_CALLBACK (modest_ui_actions_on_edit_mode_move_to));
466 modest_window_set_active_account (MODEST_WINDOW (self), account_name);
467 mgr = modest_runtime_get_account_mgr ();
468 settings = modest_account_mgr_load_account_settings (mgr, account_name);
470 store_settings = modest_account_settings_get_store_settings (settings);
471 if (store_settings) {
472 priv->current_store_account =
473 g_strdup (modest_server_account_settings_get_account_name (store_settings));
474 g_object_unref (store_settings);
476 g_object_unref (settings);
478 update_progress_hint (self);
480 return MODEST_WINDOW(self);
484 modest_header_window_get_header_view (ModestHeaderWindow *self)
486 ModestHeaderWindowPrivate *priv = NULL;
488 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW(self), FALSE);
490 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
492 return MODEST_HEADER_VIEW (priv->header_view);
495 static void setup_menu (ModestHeaderWindow *self)
497 g_return_if_fail (MODEST_IS_HEADER_WINDOW(self));
499 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_move_messages"), NULL,
500 APP_MENU_CALLBACK (set_moveto_edit_mode),
501 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_move_to));
502 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_delete_messages"), NULL,
503 APP_MENU_CALLBACK (set_delete_edit_mode),
504 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_delete));
505 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_folder_details"), NULL,
506 APP_MENU_CALLBACK (modest_ui_actions_on_details),
507 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_details));
508 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_sort"), NULL,
509 APP_MENU_CALLBACK (modest_ui_actions_on_sort),
510 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_sort));
511 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_new_message"), "<Control>n",
512 APP_MENU_CALLBACK (modest_ui_actions_on_new_msg),
513 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_new_msg));
514 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_sendandreceive"), NULL,
515 APP_MENU_CALLBACK (modest_ui_actions_on_send_receive),
516 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_send_receive));
517 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_outbox_cancelsend"), NULL,
518 APP_MENU_CALLBACK (modest_ui_actions_cancel_send),
519 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_cancel_sending_all));
523 update_view (ModestHeaderWindow *self,
524 TnyFolderChange *change)
526 ModestHeaderWindowPrivate *priv = NULL;
527 gboolean refilter = FALSE;
528 gboolean folder_empty = FALSE;
529 gboolean all_marked_as_deleted = FALSE;
531 g_return_if_fail (MODEST_IS_HEADER_WINDOW(self));
532 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
533 g_return_if_fail (priv->folder);
535 if (change != NULL) {
536 TnyFolderChangeChanged changed;
538 changed = tny_folder_change_get_changed (change);
539 /* If something changes */
540 if ((changed) & TNY_FOLDER_CHANGE_CHANGED_ALL_COUNT)
541 folder_empty = (((guint) tny_folder_change_get_new_all_count (change)) == 0);
543 folder_empty = (((guint) tny_folder_get_all_count (TNY_FOLDER (priv->folder))) == 0);
545 if ((changed) & TNY_FOLDER_CHANGE_CHANGED_EXPUNGED_HEADERS)
548 folder_empty = (((guint) tny_folder_get_all_count (TNY_FOLDER (priv->folder))) == 0);
551 /* Check if all messages are marked to be deleted */
552 all_marked_as_deleted = modest_header_view_is_empty (MODEST_HEADER_VIEW (priv->header_view));
553 folder_empty = folder_empty || all_marked_as_deleted;
555 /* Set style of headers view */
556 set_contents_state (self, folder_empty?CONTENTS_STATE_EMPTY:CONTENTS_STATE_HEADERS);
559 modest_header_view_refilter (MODEST_HEADER_VIEW (priv->header_view));
563 set_contents_state (ModestHeaderWindow *self,
566 ModestHeaderWindowPrivate *priv = NULL;
568 g_return_if_fail (MODEST_IS_HEADER_WINDOW(self));
569 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
571 if (priv->contents_state == state)
574 /* Remove from container the old content */
575 switch (priv->contents_state) {
576 case CONTENTS_STATE_EMPTY:
577 gtk_container_remove (GTK_CONTAINER (priv->contents_view), priv->empty_view);
579 case CONTENTS_STATE_HEADERS:
580 gtk_container_remove (GTK_CONTAINER (priv->contents_view), priv->header_view);
582 case CONTENTS_STATE_NONE:
586 /* Add the new content */
588 case CONTENTS_STATE_EMPTY:
589 gtk_container_add (GTK_CONTAINER (priv->contents_view), priv->empty_view);
590 gtk_widget_show (priv->empty_view);
592 case CONTENTS_STATE_HEADERS:
593 gtk_container_add (GTK_CONTAINER (priv->contents_view), priv->header_view);
594 gtk_widget_show (priv->header_view);
596 case CONTENTS_STATE_NONE:
599 priv->contents_state = state;
604 on_msg_count_changed (ModestHeaderView *header_view,
606 TnyFolderChange *change,
607 ModestHeaderWindow *header_window)
609 g_return_if_fail (MODEST_IS_HEADER_WINDOW (header_window));
611 update_view (MODEST_HEADER_WINDOW (header_window), change);
615 on_header_activated (ModestHeaderView *header_view,
618 ModestHeaderWindow *header_window)
620 modest_ui_actions_on_header_activated (header_view, header, path, MODEST_WINDOW (header_window));
624 updating_banner_destroyed (gpointer data,
625 GObject *where_the_object_was)
627 ModestHeaderWindowPrivate *priv = NULL;
629 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (data);
631 priv->updating_banner = NULL;
635 show_updating_banner (gpointer user_data)
637 ModestHeaderWindowPrivate *priv = NULL;
639 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (user_data);
641 if (priv->updating_banner == NULL) {
643 /* We're outside the main lock */
644 gdk_threads_enter ();
645 priv->updating_banner =
646 modest_platform_animation_banner (GTK_WIDGET (user_data), NULL,
647 _CS ("ckdg_pb_updating"));
649 /* We need this because banners in Maemo could be
650 destroyed by dialogs so we need to properly update
651 our reference to it */
652 g_object_weak_ref (G_OBJECT (priv->updating_banner),
653 updating_banner_destroyed,
655 gdk_threads_leave ();
659 priv->updating_banner_timeout = 0;
664 * We use this function to show/hide a progress banner showing
665 * "Updating" while the header view is being filled. We're not showing
666 * it unless the update takes more than 2 seconds
668 * If starting = TRUE then the refresh is starting, otherwise it means
669 * that is has just finished
672 on_updating_msg_list (ModestHeaderView *header_view,
676 ModestHeaderWindowPrivate *priv = NULL;
678 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (user_data);
680 /* Remove old timeout */
681 if (priv->updating_banner_timeout > 0) {
682 g_source_remove (priv->updating_banner_timeout);
683 priv->updating_banner_timeout = 0;
686 /* Create a new timeout */
688 priv->updating_banner_timeout =
689 g_timeout_add (2000, show_updating_banner, user_data);
691 /* Remove the banner if exists */
692 if (priv->updating_banner) {
693 gtk_widget_destroy (priv->updating_banner);
694 priv->updating_banner = NULL;
700 set_delete_edit_mode (GtkButton *button,
701 ModestHeaderWindow *self)
703 modest_hildon2_window_set_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_DELETE);
707 set_moveto_edit_mode (GtkButton *button,
708 ModestHeaderWindow *self)
710 modest_hildon2_window_set_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_MOVE);
714 on_expose_event(GtkTreeView *header_view,
715 GdkEventExpose *event,
718 ModestHeaderWindow *self = (ModestHeaderWindow *) user_data;
719 ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
721 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW (self), FALSE);
723 if (priv->autoscroll)
724 hildon_pannable_area_jump_to (HILDON_PANNABLE_AREA (priv->contents_view), 0.0, 0.0);
730 on_map_event(GtkWidget *widget,
734 ModestHeaderWindow *self = (ModestHeaderWindow *) user_data;
735 ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
737 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW (self), FALSE);
739 if (priv->progress_hint) {
740 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
746 on_progress_list_changed (ModestWindowMgr *mgr,
747 ModestHeaderWindow *self)
749 update_progress_hint (self);
753 has_active_operations (ModestHeaderWindow *self)
755 GSList *operations = NULL, *node;
756 ModestMailOperationQueue *queue;
757 gboolean has_active = FALSE;
759 queue = modest_runtime_get_mail_operation_queue ();
760 operations = modest_mail_operation_queue_get_by_source (queue, G_OBJECT (self));
761 for (node = operations; node != NULL; node = g_slist_next (node)) {
762 if (!modest_mail_operation_is_finished (MODEST_MAIL_OPERATION (node->data))) {
767 g_slist_free (operations);
772 update_progress_hint (ModestHeaderWindow *self)
774 ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
775 priv->progress_hint = FALSE;
777 if (has_active_operations (self)) {
778 priv->progress_hint = TRUE;
781 if (!priv->progress_hint && priv->current_store_account) {
782 priv->progress_hint = modest_window_mgr_has_progress_operation_on_account (modest_runtime_get_window_mgr (),
783 priv->current_store_account);
786 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
788 if (GTK_WIDGET_VISIBLE (self)) {
789 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), priv->progress_hint?1:0);
794 modest_header_window_toolbar_on_transfer_mode (ModestHeaderWindow *self)
796 ModestHeaderWindowPrivate *priv= NULL;
798 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW (self), FALSE);
799 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
801 return priv->progress_hint;
805 modest_header_window_transfer_mode_enabled (ModestHeaderWindow *self)
807 ModestHeaderWindowPrivate *priv;
809 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW (self), FALSE);
810 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
812 return priv->progress_hint;
816 on_mail_operation_started (ModestMailOperation *mail_op,
819 ModestHeaderWindow *self;
820 ModestMailOperationTypeOperation op_type;
821 GObject *source = NULL;
823 self = MODEST_HEADER_WINDOW (user_data);
824 op_type = modest_mail_operation_get_type_operation (mail_op);
825 source = modest_mail_operation_get_source(mail_op);
826 if (G_OBJECT (self) == source) {
827 update_progress_hint (self);
829 g_object_unref (source);
833 on_mail_operation_finished (ModestMailOperation *mail_op,
836 ModestHeaderWindow *self;
837 ModestMailOperationTypeOperation op_type;
838 GSList *operations = NULL;
839 ModestMailOperationQueue *queue;
841 self = MODEST_HEADER_WINDOW (user_data);
842 op_type = modest_mail_operation_get_type_operation (mail_op);
844 queue = modest_runtime_get_mail_operation_queue ();
845 operations = modest_mail_operation_queue_get_by_source (queue, user_data);
847 /* Don't disable the progress hint if there are more pending
848 operations from this window */
849 update_progress_hint (self);
851 g_slist_free (operations);
852 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
856 on_queue_changed (ModestMailOperationQueue *queue,
857 ModestMailOperation *mail_op,
858 ModestMailOperationQueueNotification type,
859 ModestHeaderWindow *self)
861 ModestHeaderWindowPrivate *priv;
863 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
865 /* If this operations was created by another window, do nothing */
866 if (!modest_mail_operation_is_mine (mail_op, G_OBJECT(self)))
869 if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_ADDED) {
870 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
873 G_CALLBACK (on_mail_operation_started),
875 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
877 "operation-finished",
878 G_CALLBACK (on_mail_operation_finished),
880 } else if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED) {
881 priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
883 "operation-started");
884 priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
886 "operation-finished");
891 modest_header_window_pack_toolbar (ModestHildon2Window *self,
892 GtkPackType pack_type,
895 ModestHeaderWindowPrivate *priv;
897 g_return_if_fail (MODEST_IS_HEADER_WINDOW (self));
898 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
900 if (pack_type == GTK_PACK_START) {
901 gtk_box_pack_start (GTK_BOX (priv->top_vbox), toolbar, FALSE, FALSE, 0);
903 gtk_box_pack_end (GTK_BOX (priv->top_vbox), toolbar, FALSE, FALSE, 0);
908 edit_mode_changed (ModestHeaderWindow *header_window,
911 ModestHeaderWindow *self)
913 ModestHeaderWindowPrivate *priv;
914 ModestHeaderViewFilter filter = MODEST_HEADER_VIEW_FILTER_NONE;
916 g_return_if_fail (MODEST_IS_HEADER_WINDOW (self));
917 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
919 switch (edit_mode_id) {
920 case EDIT_MODE_COMMAND_MOVE:
921 filter = MODEST_HEADER_VIEW_FILTER_MOVEABLE;
923 case EDIT_MODE_COMMAND_DELETE:
924 filter = MODEST_HEADER_VIEW_FILTER_DELETABLE;
926 case MODEST_HILDON2_WINDOW_EDIT_MODE_NONE:
927 filter = MODEST_HEADER_VIEW_FILTER_NONE;
932 modest_header_view_set_filter (MODEST_HEADER_VIEW (priv->header_view),
935 modest_header_view_unset_filter (MODEST_HEADER_VIEW (priv->header_view),