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 <hildon/hildon-helper.h>
35 #include <modest-window-mgr.h>
36 #include <modest-window-priv.h>
37 #include <modest-signal-mgr.h>
38 #include <modest-runtime.h>
39 #include <modest-platform.h>
40 #include <modest-maemo-utils.h>
41 #include <modest-icon-names.h>
42 #include <modest-ui-constants.h>
43 #include <modest-account-mgr.h>
44 #include <modest-account-mgr-helpers.h>
45 #include <modest-defs.h>
46 #include <modest-widget-memory.h>
47 #include <modest-ui-actions.h>
48 #include <modest-platform.h>
49 #include <modest-text-utils.h>
50 #include <hildon/hildon-button.h>
51 #include <hildon/hildon-program.h>
52 #include <hildon/hildon-banner.h>
53 #include <modest-ui-dimming-rules.h>
54 #include <modest-tny-folder.h>
57 CONTENTS_STATE_NONE = 0,
58 CONTENTS_STATE_EMPTY = 1,
59 CONTENTS_STATE_HEADERS = 2
63 EDIT_MODE_COMMAND_MOVE = 1,
64 EDIT_MODE_COMMAND_DELETE = 2,
67 typedef struct _ModestHeaderWindowPrivate ModestHeaderWindowPrivate;
68 struct _ModestHeaderWindowPrivate {
70 GtkWidget *header_view;
71 GtkWidget *empty_view;
72 GtkWidget *contents_view;
74 GtkWidget *new_message_button;
77 ContentsState contents_state;
85 GtkWidget *updating_banner;
86 guint updating_banner_timeout;
90 gulong queue_change_handler;
93 gboolean progress_hint;
94 gchar *current_store_account;
97 GtkWidget *sort_button;
99 #define MODEST_HEADER_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
100 MODEST_TYPE_HEADER_WINDOW, \
101 ModestHeaderWindowPrivate))
103 /* 'private'/'protected' functions */
104 static void modest_header_window_class_init (ModestHeaderWindowClass *klass);
105 static void modest_header_window_init (ModestHeaderWindow *obj);
106 static void modest_header_window_finalize (GObject *obj);
108 static void connect_signals (ModestHeaderWindow *self);
109 static void modest_header_window_disconnect_signals (ModestWindow *self);
111 static void setup_menu (ModestHeaderWindow *self);
112 static GtkWidget *create_empty_view (ModestWindow *self);
113 static GtkWidget *create_header_view (ModestWindow *progress_window,
116 static void update_view (ModestHeaderWindow *self,
117 TnyFolderChange *change);
118 static void set_contents_state (ModestHeaderWindow *window,
119 ContentsState state);
121 static void on_msg_count_changed (ModestHeaderView *header_view,
123 TnyFolderChange *change,
124 ModestHeaderWindow *header_window);
125 static void on_header_activated (ModestHeaderView *header_view,
128 ModestHeaderWindow *header_window);
129 static void on_updating_msg_list (ModestHeaderView *header_view,
132 static void set_delete_edit_mode (GtkButton *button,
133 ModestHeaderWindow *self);
134 static void set_moveto_edit_mode (GtkButton *button,
135 ModestHeaderWindow *self);
136 static gboolean on_expose_event(GtkTreeView *header_view,
137 GdkEventExpose *event,
139 static gboolean on_map_event (GtkWidget *widget,
142 static void on_vertical_movement (HildonPannableArea *area,
143 HildonMovementDirection direction,
144 gdouble x, gdouble y, gpointer user_data);
145 static void on_queue_changed (ModestMailOperationQueue *queue,
146 ModestMailOperation *mail_op,
147 ModestMailOperationQueueNotification type,
148 ModestHeaderWindow *self);
149 static void modest_header_window_pack_toolbar (ModestHildon2Window *self,
150 GtkPackType pack_type,
152 static void edit_mode_changed (ModestHeaderWindow *header_window,
155 ModestHeaderWindow *self);
156 static void on_progress_list_changed (ModestWindowMgr *mgr,
157 ModestHeaderWindow *self);
158 static void update_progress_hint (ModestHeaderWindow *self);
159 static void on_sort_column_changed (GtkTreeSortable *treesortable,
161 static void update_sort_button (ModestHeaderWindow *self);
165 static GtkWindowClass *parent_class = NULL;
167 #define EMPTYVIEW_XALIGN 0.5
168 #define EMPTYVIEW_YALIGN 0.5
169 #define EMPTYVIEW_XSPACE 1.0
170 #define EMPTYVIEW_YSPACE 1.0
174 /************************************************************************/
177 modest_header_window_get_type (void)
179 static GType my_type = 0;
181 static const GTypeInfo my_info = {
182 sizeof(ModestHeaderWindowClass),
183 NULL, /* base init */
184 NULL, /* base finalize */
185 (GClassInitFunc) modest_header_window_class_init,
186 NULL, /* class finalize */
187 NULL, /* class data */
188 sizeof(ModestHeaderWindow),
190 (GInstanceInitFunc) modest_header_window_init,
193 my_type = g_type_register_static (MODEST_TYPE_HILDON2_WINDOW,
194 "ModestHeaderWindow",
201 modest_header_window_class_init (ModestHeaderWindowClass *klass)
203 GObjectClass *gobject_class;
204 gobject_class = (GObjectClass*) klass;
205 ModestWindowClass *modest_window_class = (ModestWindowClass *) klass;
206 ModestHildon2WindowClass *modest_hildon2_window_class = (ModestHildon2WindowClass *) klass;
208 parent_class = g_type_class_peek_parent (klass);
209 gobject_class->finalize = modest_header_window_finalize;
211 g_type_class_add_private (gobject_class, sizeof(ModestHeaderWindowPrivate));
213 modest_window_class->disconnect_signals_func = modest_header_window_disconnect_signals;
214 modest_hildon2_window_class->pack_toolbar_func = modest_header_window_pack_toolbar;
218 modest_header_window_init (ModestHeaderWindow *obj)
220 ModestHeaderWindowPrivate *priv;
222 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(obj);
224 priv->sighandlers = NULL;
226 priv->header_view = NULL;
227 priv->empty_view = NULL;
228 priv->top_vbox = NULL;
229 priv->contents_view = NULL;
230 priv->contents_state = CONTENTS_STATE_NONE;
232 priv->updating_banner = NULL;
233 priv->updating_banner_timeout = 0;
234 priv->autoscroll = TRUE;
235 priv->progress_hint = FALSE;
236 priv->queue_change_handler = 0;
237 priv->current_store_account = NULL;
238 priv->sort_button = NULL;
239 priv->new_message_button = NULL;
241 modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(),
243 "applications_email_headerview");
247 modest_header_window_finalize (GObject *obj)
249 ModestHeaderWindowPrivate *priv;
251 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(obj);
253 g_object_unref (priv->folder);
254 g_object_unref (priv->header_view);
255 g_object_unref (priv->empty_view);
257 if (priv->current_store_account) {
258 g_free (priv->current_store_account);
259 priv->current_store_account = NULL;
262 /* Sanity check: shouldn't be needed, the window mgr should
263 call this function before */
264 modest_header_window_disconnect_signals (MODEST_WINDOW (obj));
266 if (priv->updating_banner_timeout > 0) {
267 g_source_remove (priv->updating_banner_timeout);
268 priv->updating_banner_timeout = 0;
270 if (priv->updating_banner) {
271 gtk_widget_destroy (priv->updating_banner);
272 priv->updating_banner = NULL;
275 G_OBJECT_CLASS(parent_class)->finalize (obj);
279 modest_header_window_disconnect_signals (ModestWindow *self)
281 ModestHeaderWindowPrivate *priv;
282 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
284 if (g_signal_handler_is_connected (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
285 priv->queue_change_handler))
286 g_signal_handler_disconnect (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
287 priv->queue_change_handler);
289 modest_signal_mgr_disconnect_all_and_destroy (priv->sighandlers);
290 priv->sighandlers = NULL;
295 connect_signals (ModestHeaderWindow *self)
297 ModestHeaderWindowPrivate *priv;
298 GtkTreeSortable *sortable;
300 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
305 modest_signal_mgr_connect (priv->sighandlers,G_OBJECT(priv->header_view),
307 G_CALLBACK(on_msg_count_changed), self);
309 modest_signal_mgr_connect (priv->sighandlers, G_OBJECT (priv->header_view),
311 G_CALLBACK (on_header_activated), self);
313 modest_signal_mgr_connect (priv->sighandlers,
314 G_OBJECT (priv->header_view),
316 G_CALLBACK (on_updating_msg_list),
319 modest_signal_mgr_connect (priv->sighandlers,
320 G_OBJECT (priv->header_view),
322 G_CALLBACK (on_expose_event),
325 sortable = GTK_TREE_SORTABLE (gtk_tree_model_filter_get_model
326 (GTK_TREE_MODEL_FILTER (gtk_tree_view_get_model (
327 GTK_TREE_VIEW (priv->header_view)))));
329 modest_signal_mgr_connect (priv->sighandlers,
331 "sort-column-changed",
332 G_CALLBACK (on_sort_column_changed),
336 modest_signal_mgr_connect (priv->sighandlers,
339 G_CALLBACK (on_map_event),
343 modest_signal_mgr_connect (priv->sighandlers,
344 G_OBJECT (priv->contents_view),
346 G_CALLBACK (on_vertical_movement),
349 /* Mail Operation Queue */
350 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
351 G_OBJECT (modest_runtime_get_window_mgr ()),
352 "progress-list-changed",
353 G_CALLBACK (on_progress_list_changed), self);
355 modest_signal_mgr_connect (priv->sighandlers,
356 G_OBJECT (priv->new_message_button),
358 G_CALLBACK (modest_ui_actions_on_new_msg), self);
362 folder_refreshed_cb (ModestMailOperation *mail_op,
366 /* Update the view (folder could be empty) */
367 update_view (MODEST_HEADER_WINDOW (user_data), NULL);
371 create_header_view (ModestWindow *self, TnyFolder *folder)
373 GtkWidget *header_view;
375 header_view = modest_header_view_new (NULL, MODEST_HEADER_VIEW_STYLE_TWOLINES);
376 modest_header_view_set_folder (MODEST_HEADER_VIEW (header_view), folder,
377 TRUE, self, folder_refreshed_cb, self);
378 modest_header_view_set_filter (MODEST_HEADER_VIEW (header_view),
379 MODEST_HEADER_VIEW_FILTER_NONE);
380 modest_widget_memory_restore (modest_runtime_get_conf (), G_OBJECT(header_view),
381 MODEST_CONF_HEADER_VIEW_KEY);
387 create_empty_view (ModestWindow *self)
389 GtkWidget *viewport = NULL;
390 GtkWidget *label = NULL;
391 GtkWidget *align = NULL;
392 GtkWidget *vbox = NULL;
393 GtkWidget *button = NULL;
394 GdkPixbuf *new_message_pixbuf;
396 vbox = gtk_vbox_new (0, FALSE);
398 align = gtk_alignment_new(EMPTYVIEW_XALIGN, EMPTYVIEW_YALIGN, EMPTYVIEW_XSPACE, EMPTYVIEW_YSPACE);
399 label = gtk_label_new (_("mcen_ia_nomessages"));
400 hildon_helper_set_logical_font (label, "LargeSystemFont");
401 gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
402 gtk_widget_show (label);
403 gtk_widget_show (align);
404 gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
405 gtk_container_add (GTK_CONTAINER (align), label);
406 gtk_box_pack_end (GTK_BOX (vbox), align, TRUE, TRUE, 0);
408 button = hildon_button_new (MODEST_EDITABLE_SIZE,
409 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
411 hildon_button_set_title (HILDON_BUTTON (button), _("mcen_ti_new_message"));
412 new_message_pixbuf = modest_platform_get_icon ("general_add", MODEST_ICON_SIZE_BIG);
413 hildon_button_set_image (HILDON_BUTTON (button),
414 gtk_image_new_from_pixbuf (new_message_pixbuf));
415 g_object_unref (new_message_pixbuf);
416 gtk_widget_show_all (button);
417 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
419 gtk_widget_show (vbox);
421 g_signal_connect (button,
423 G_CALLBACK (modest_ui_actions_on_new_msg), self);
425 viewport = gtk_viewport_new ((GtkAdjustment *) gtk_adjustment_new (0, 0, 0, 0, 0, 0),
426 (GtkAdjustment *) gtk_adjustment_new (0, 0, 0, 0, 0, 0));
427 gtk_container_add (GTK_CONTAINER (viewport), vbox);
433 on_vertical_movement (HildonPannableArea *area,
434 HildonMovementDirection direction,
435 gdouble x, gdouble y, gpointer user_data)
437 ModestHeaderWindow *self = (ModestHeaderWindow *) user_data;
438 ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
440 priv->autoscroll = FALSE;
445 modest_header_window_new (TnyFolder *folder, const gchar *account_name, const gchar *mailbox)
447 ModestHeaderWindow *self = NULL;
448 ModestHeaderWindowPrivate *priv = NULL;
450 GdkPixbuf *window_icon;
451 ModestAccountMgr *mgr;
452 ModestAccountSettings *settings = NULL;
453 ModestServerAccountSettings *store_settings = NULL;
454 GtkWidget *action_area_box;
455 GdkPixbuf *new_message_pixbuf;
456 GtkWidget *alignment;
457 gchar *account_display_name = NULL;
459 self = MODEST_HEADER_WINDOW(g_object_new(MODEST_TYPE_HEADER_WINDOW, NULL));
460 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
462 priv->folder = g_object_ref (folder);
464 priv->contents_view = hildon_pannable_area_new ();
465 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
466 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
468 HILDON_MARGIN_DOUBLE, HILDON_MARGIN_DOUBLE);
470 /* We need to do this here to properly listen for mail
471 operations because create_header_view launches a mail
473 priv->queue_change_handler =
474 g_signal_connect (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
476 G_CALLBACK (on_queue_changed),
479 priv->header_view = create_header_view (MODEST_WINDOW (self), folder);
480 priv->empty_view = create_empty_view (MODEST_WINDOW (self));
482 /* Transform the floating reference in a "hard" reference. We
483 need to do this because the widgets could be added/removed
484 to containers many times so we always need to keep a
485 reference. It could happen also that some widget is never
486 added to any container */
487 g_object_ref_sink (priv->header_view);
488 g_object_ref_sink (priv->empty_view);
490 g_signal_connect (G_OBJECT (self), "edit-mode-changed",
491 G_CALLBACK (edit_mode_changed), (gpointer) self);
493 action_area_box = hildon_tree_view_get_action_area_box (GTK_TREE_VIEW (priv->header_view));
494 priv->new_message_button = hildon_button_new (0, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
496 hildon_button_set_title (HILDON_BUTTON (priv->new_message_button), _("mcen_ti_new_message"));
497 new_message_pixbuf = modest_platform_get_icon ("general_add", MODEST_ICON_SIZE_BIG);
498 hildon_button_set_image (HILDON_BUTTON (priv->new_message_button), gtk_image_new_from_pixbuf (new_message_pixbuf));
499 g_object_unref (new_message_pixbuf);
501 gtk_box_pack_start (GTK_BOX (action_area_box), priv->new_message_button, TRUE, TRUE, 0);
502 gtk_widget_show_all (priv->new_message_button);
503 hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->header_view), TRUE);
507 priv->top_vbox = gtk_vbox_new (FALSE, 0);
508 gtk_container_add (GTK_CONTAINER (alignment), priv->contents_view);
509 gtk_box_pack_end (GTK_BOX (priv->top_vbox), alignment, TRUE, TRUE, 0);
511 gtk_container_add (GTK_CONTAINER (self), priv->top_vbox);
513 gtk_widget_show (alignment);
514 gtk_widget_show (priv->contents_view);
515 gtk_widget_show (priv->top_vbox);
517 connect_signals (MODEST_HEADER_WINDOW (self));
519 update_view (self, NULL);
521 /* Load previous osso state, for instance if we are being restored from
523 modest_osso_load_state ();
525 /* Get device name */
526 modest_maemo_utils_get_device_name ();
528 app = hildon_program_get_instance ();
529 hildon_program_add_window (app, HILDON_WINDOW (self));
531 /* Set window icon */
532 window_icon = modest_platform_get_icon (MODEST_APP_ICON, MODEST_ICON_SIZE_BIG);
534 gtk_window_set_icon (GTK_WINDOW (self), window_icon);
535 g_object_unref (window_icon);
538 /* Dont't restore settings here,
539 * because it requires a gtk_widget_show(),
540 * and we don't want to do that until later,
541 * so that the UI is not visible for non-menu D-Bus activation.
544 /* setup edit modes */
545 modest_hildon2_window_register_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_DELETE,
546 _("mcen_ti_edit_delete"), _HL("wdgt_bd_delete"),
547 GTK_TREE_VIEW (priv->header_view),
548 GTK_SELECTION_MULTIPLE,
549 EDIT_MODE_CALLBACK (modest_ui_actions_on_edit_mode_delete_message));
550 modest_hildon2_window_register_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_MOVE,
551 _("mcen_ti_edit_move"), _HL("wdgt_bd_move"),
552 GTK_TREE_VIEW (priv->header_view),
553 GTK_SELECTION_MULTIPLE,
554 EDIT_MODE_CALLBACK (modest_ui_actions_on_edit_mode_move_to));
557 modest_window_set_active_account (MODEST_WINDOW (self), account_name);
558 modest_window_set_active_mailbox (MODEST_WINDOW (self), mailbox);
559 mgr = modest_runtime_get_account_mgr ();
560 settings = modest_account_mgr_load_account_settings (mgr, account_name);
562 account_display_name = g_strdup (modest_account_settings_get_display_name (settings));
563 store_settings = modest_account_settings_get_store_settings (settings);
564 if (store_settings) {
565 priv->current_store_account =
566 g_strdup (modest_server_account_settings_get_account_name (store_settings));
567 g_object_unref (store_settings);
569 g_object_unref (settings);
571 /* Set window title */
572 if (TNY_IS_FOLDER (folder)) {
575 if (tny_folder_get_folder_type (folder) == TNY_FOLDER_TYPE_INBOX) {
576 const gchar *box_name;
578 if (box_name == NULL || box_name[0] == '\0') {
579 box_name = account_display_name;
581 folder_name = g_strconcat (_("mcen_me_folder_inbox"), " (", box_name, ")", NULL);
583 folder_name = modest_tny_folder_get_display_name (folder);
586 gtk_window_set_title (GTK_WINDOW (self), folder_name);
587 g_free (folder_name);
589 g_free (account_display_name);
592 update_progress_hint (self);
593 update_sort_button (self);
595 return MODEST_WINDOW(self);
599 modest_header_window_get_header_view (ModestHeaderWindow *self)
601 ModestHeaderWindowPrivate *priv = NULL;
603 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW(self), FALSE);
605 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
607 return MODEST_HEADER_VIEW (priv->header_view);
610 static void setup_menu (ModestHeaderWindow *self)
612 ModestHeaderWindowPrivate *priv;
614 g_return_if_fail (MODEST_IS_HEADER_WINDOW(self));
615 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
617 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_new_message"), "<Control>n",
618 APP_MENU_CALLBACK (modest_ui_actions_on_new_msg),
619 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_new_msg));
620 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_move_messages"), NULL,
621 APP_MENU_CALLBACK (set_moveto_edit_mode),
622 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_move_to));
623 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_delete_messages"), NULL,
624 APP_MENU_CALLBACK (set_delete_edit_mode),
625 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_delete));
626 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_folder_details"), NULL,
627 APP_MENU_CALLBACK (modest_ui_actions_on_details),
628 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_details));
629 priv->sort_button = hildon_button_new (MODEST_EDITABLE_SIZE,
630 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
631 hildon_button_set_title (HILDON_BUTTON (priv->sort_button), _("mcen_me_sort"));
632 g_signal_connect (G_OBJECT (priv->sort_button), "clicked",
633 G_CALLBACK (modest_ui_actions_on_sort), (gpointer) self);
634 hildon_button_set_style(HILDON_BUTTON (priv->sort_button), HILDON_BUTTON_STYLE_PICKER);
635 hildon_button_set_title_alignment (HILDON_BUTTON (priv->sort_button), 0.5, 0.5);
636 hildon_button_set_value_alignment (HILDON_BUTTON (priv->sort_button), 0.5, 0.5);
637 modest_hildon2_window_add_button_to_menu (MODEST_HILDON2_WINDOW (self), GTK_BUTTON (priv->sort_button),
638 modest_ui_dimming_rules_on_sort);
639 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_sendandreceive"), NULL,
640 APP_MENU_CALLBACK (modest_ui_actions_on_send_receive),
641 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_send_receive));
642 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_outbox_cancelsend"), NULL,
643 APP_MENU_CALLBACK (modest_ui_actions_cancel_send),
644 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_cancel_sending_all));
648 update_view (ModestHeaderWindow *self,
649 TnyFolderChange *change)
651 ModestHeaderWindowPrivate *priv = NULL;
652 gboolean refilter = FALSE;
653 gboolean folder_empty = FALSE;
654 gboolean all_marked_as_deleted = FALSE;
656 g_return_if_fail (MODEST_IS_HEADER_WINDOW(self));
657 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
658 g_return_if_fail (priv->folder);
660 if (change != NULL) {
661 TnyFolderChangeChanged changed;
663 changed = tny_folder_change_get_changed (change);
664 /* If something changes */
665 if ((changed) & TNY_FOLDER_CHANGE_CHANGED_ALL_COUNT)
666 folder_empty = (((guint) tny_folder_change_get_new_all_count (change)) == 0);
668 folder_empty = (((guint) tny_folder_get_all_count (TNY_FOLDER (priv->folder))) == 0);
670 if ((changed) & TNY_FOLDER_CHANGE_CHANGED_EXPUNGED_HEADERS)
673 folder_empty = (((guint) tny_folder_get_all_count (TNY_FOLDER (priv->folder))) == 0);
676 /* Check if all messages are marked to be deleted */
677 all_marked_as_deleted = modest_header_view_is_empty (MODEST_HEADER_VIEW (priv->header_view));
678 folder_empty = folder_empty || all_marked_as_deleted;
680 /* Set style of headers view */
681 set_contents_state (self, folder_empty?CONTENTS_STATE_EMPTY:CONTENTS_STATE_HEADERS);
684 modest_header_view_refilter (MODEST_HEADER_VIEW (priv->header_view));
688 set_contents_state (ModestHeaderWindow *self,
691 ModestHeaderWindowPrivate *priv = NULL;
693 g_return_if_fail (MODEST_IS_HEADER_WINDOW(self));
694 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
696 if (priv->contents_state == state)
699 /* Remove from container the old content */
700 switch (priv->contents_state) {
701 case CONTENTS_STATE_EMPTY:
702 gtk_container_remove (GTK_CONTAINER (priv->contents_view), priv->empty_view);
704 case CONTENTS_STATE_HEADERS:
705 gtk_container_remove (GTK_CONTAINER (priv->contents_view), priv->header_view);
707 case CONTENTS_STATE_NONE:
711 /* Add the new content */
713 case CONTENTS_STATE_EMPTY:
714 gtk_container_add (GTK_CONTAINER (priv->contents_view), priv->empty_view);
715 gtk_widget_show (priv->empty_view);
717 case CONTENTS_STATE_HEADERS:
718 gtk_container_add (GTK_CONTAINER (priv->contents_view), priv->header_view);
719 gtk_widget_show (priv->header_view);
721 case CONTENTS_STATE_NONE:
724 priv->contents_state = state;
728 on_msg_count_changed (ModestHeaderView *header_view,
730 TnyFolderChange *change,
731 ModestHeaderWindow *header_window)
733 g_return_if_fail (MODEST_IS_HEADER_WINDOW (header_window));
735 update_view (MODEST_HEADER_WINDOW (header_window), change);
739 on_header_activated (ModestHeaderView *header_view,
742 ModestHeaderWindow *header_window)
744 modest_ui_actions_on_header_activated (header_view, header, path, MODEST_WINDOW (header_window));
748 updating_banner_destroyed (gpointer data,
749 GObject *where_the_object_was)
751 ModestHeaderWindowPrivate *priv = NULL;
753 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (data);
755 priv->updating_banner = NULL;
759 show_updating_banner (gpointer user_data)
761 ModestHeaderWindowPrivate *priv = NULL;
763 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (user_data);
765 if (priv->updating_banner == NULL) {
767 /* We're outside the main lock */
768 gdk_threads_enter ();
769 priv->updating_banner =
770 modest_platform_animation_banner (GTK_WIDGET (user_data), NULL,
771 _CS ("ckdg_pb_updating"));
773 /* We need this because banners in Maemo could be
774 destroyed by dialogs so we need to properly update
775 our reference to it */
776 g_object_weak_ref (G_OBJECT (priv->updating_banner),
777 updating_banner_destroyed,
779 gdk_threads_leave ();
783 priv->updating_banner_timeout = 0;
788 * We use this function to show/hide a progress banner showing
789 * "Updating" while the header view is being filled. We're not showing
790 * it unless the update takes more than 2 seconds
792 * If starting = TRUE then the refresh is starting, otherwise it means
793 * that is has just finished
796 on_updating_msg_list (ModestHeaderView *header_view,
800 ModestHeaderWindowPrivate *priv = NULL;
802 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (user_data);
804 /* Remove old timeout */
805 if (priv->updating_banner_timeout > 0) {
806 g_source_remove (priv->updating_banner_timeout);
807 priv->updating_banner_timeout = 0;
810 /* Create a new timeout */
812 priv->updating_banner_timeout =
813 g_timeout_add (2000, show_updating_banner, user_data);
815 /* Remove the banner if exists */
816 if (priv->updating_banner) {
817 gtk_widget_destroy (priv->updating_banner);
818 priv->updating_banner = NULL;
824 set_delete_edit_mode (GtkButton *button,
825 ModestHeaderWindow *self)
827 modest_hildon2_window_set_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_DELETE);
831 set_moveto_edit_mode (GtkButton *button,
832 ModestHeaderWindow *self)
834 modest_hildon2_window_set_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_MOVE);
838 on_expose_event(GtkTreeView *header_view,
839 GdkEventExpose *event,
842 ModestHeaderWindow *self = (ModestHeaderWindow *) user_data;
843 ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
845 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW (self), FALSE);
847 if (priv->autoscroll)
848 hildon_pannable_area_jump_to (HILDON_PANNABLE_AREA (priv->contents_view), 0.0, 0.0);
854 on_map_event(GtkWidget *widget,
858 ModestHeaderWindow *self = (ModestHeaderWindow *) user_data;
859 ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
861 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW (self), FALSE);
863 if (priv->progress_hint) {
864 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
870 on_progress_list_changed (ModestWindowMgr *mgr,
871 ModestHeaderWindow *self)
873 update_progress_hint (self);
877 has_active_operations (ModestHeaderWindow *self)
879 GSList *operations = NULL, *node;
880 ModestMailOperationQueue *queue;
881 gboolean has_active = FALSE;
883 queue = modest_runtime_get_mail_operation_queue ();
884 operations = modest_mail_operation_queue_get_by_source (queue, G_OBJECT (self));
886 for (node = operations; node != NULL; node = g_slist_next (node)) {
887 if (!modest_mail_operation_is_finished (MODEST_MAIL_OPERATION (node->data))) {
894 g_slist_foreach (operations, (GFunc) g_object_unref, NULL);
895 g_slist_free (operations);
902 update_progress_hint (ModestHeaderWindow *self)
904 ModestHeaderWindowPrivate *priv;
906 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
908 priv->progress_hint = FALSE;
910 if (has_active_operations (self)) {
911 priv->progress_hint = TRUE;
913 priv->progress_hint = FALSE;
916 if (!priv->progress_hint && priv->current_store_account) {
917 priv->progress_hint =
918 modest_window_mgr_has_progress_operation_on_account (modest_runtime_get_window_mgr (),
919 priv->current_store_account);
922 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
924 if (GTK_WIDGET_VISIBLE (self)) {
925 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), priv->progress_hint?1:0);
930 modest_header_window_toolbar_on_transfer_mode (ModestHeaderWindow *self)
932 ModestHeaderWindowPrivate *priv= NULL;
934 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW (self), FALSE);
935 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
937 return priv->progress_hint;
941 modest_header_window_transfer_mode_enabled (ModestHeaderWindow *self)
943 ModestHeaderWindowPrivate *priv;
945 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW (self), FALSE);
946 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
948 return priv->progress_hint;
952 on_mail_operation_started (ModestMailOperation *mail_op,
955 ModestHeaderWindow *self;
956 ModestMailOperationTypeOperation op_type;
957 GObject *source = NULL;
959 self = MODEST_HEADER_WINDOW (user_data);
960 op_type = modest_mail_operation_get_type_operation (mail_op);
961 source = modest_mail_operation_get_source(mail_op);
962 if (G_OBJECT (self) == source) {
963 update_progress_hint (self);
965 g_object_unref (source);
969 on_mail_operation_finished (ModestMailOperation *mail_op,
972 ModestHeaderWindow *self;
974 self = MODEST_HEADER_WINDOW (user_data);
976 /* Don't disable the progress hint if there are more pending
977 operations from this window */
978 update_progress_hint (self);
980 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
984 on_queue_changed (ModestMailOperationQueue *queue,
985 ModestMailOperation *mail_op,
986 ModestMailOperationQueueNotification type,
987 ModestHeaderWindow *self)
989 ModestHeaderWindowPrivate *priv;
991 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
993 /* If this operations was created by another window, do nothing */
994 if (!modest_mail_operation_is_mine (mail_op, G_OBJECT(self)))
997 if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_ADDED) {
998 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
1000 "operation-started",
1001 G_CALLBACK (on_mail_operation_started),
1003 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
1005 "operation-finished",
1006 G_CALLBACK (on_mail_operation_finished),
1008 } else if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED) {
1009 priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
1011 "operation-started");
1012 priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
1014 "operation-finished");
1019 modest_header_window_pack_toolbar (ModestHildon2Window *self,
1020 GtkPackType pack_type,
1023 ModestHeaderWindowPrivate *priv;
1025 g_return_if_fail (MODEST_IS_HEADER_WINDOW (self));
1026 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1028 if (pack_type == GTK_PACK_START) {
1029 gtk_box_pack_start (GTK_BOX (priv->top_vbox), toolbar, FALSE, FALSE, 0);
1031 gtk_box_pack_end (GTK_BOX (priv->top_vbox), toolbar, FALSE, FALSE, 0);
1036 edit_mode_changed (ModestHeaderWindow *header_window,
1039 ModestHeaderWindow *self)
1041 ModestHeaderWindowPrivate *priv;
1042 ModestHeaderViewFilter filter = MODEST_HEADER_VIEW_FILTER_NONE;
1044 g_return_if_fail (MODEST_IS_HEADER_WINDOW (self));
1045 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1047 switch (edit_mode_id) {
1048 case EDIT_MODE_COMMAND_MOVE:
1049 filter = MODEST_HEADER_VIEW_FILTER_MOVEABLE;
1051 case EDIT_MODE_COMMAND_DELETE:
1052 filter = MODEST_HEADER_VIEW_FILTER_DELETABLE;
1054 case MODEST_HILDON2_WINDOW_EDIT_MODE_NONE:
1055 filter = MODEST_HEADER_VIEW_FILTER_NONE;
1059 hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->header_view), !enabled);
1061 modest_header_view_set_filter (MODEST_HEADER_VIEW (priv->header_view),
1064 GtkTreeSelection *sel;
1066 /* Unselect all. This will prevent us from keeping a
1067 reference to a TnyObject that we don't want to
1069 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->header_view));
1070 gtk_tree_selection_unselect_all (sel);
1072 modest_header_view_unset_filter (MODEST_HEADER_VIEW (priv->header_view),
1078 on_sort_column_changed (GtkTreeSortable *treesortable,
1081 update_sort_button (MODEST_HEADER_WINDOW (user_data));
1085 update_sort_button (ModestHeaderWindow *self)
1087 ModestHeaderWindowPrivate *priv;
1088 GtkTreeSortable *sortable;
1089 gint current_sort_colid = -1;
1090 GtkSortType current_sort_type;
1091 const gchar *value = NULL;
1093 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1094 sortable = GTK_TREE_SORTABLE (gtk_tree_model_filter_get_model
1095 (GTK_TREE_MODEL_FILTER (gtk_tree_view_get_model (
1096 GTK_TREE_VIEW (priv->header_view)))));
1098 if (!gtk_tree_sortable_get_sort_column_id (sortable,
1099 ¤t_sort_colid, ¤t_sort_type)) {
1100 value = _("mcen_li_sort_sender_date_newest");
1102 switch (current_sort_colid) {
1103 case TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN:
1106 cols = modest_header_view_get_columns (MODEST_HEADER_VIEW (priv->header_view));
1108 gpointer flags_sort_type_pointer;
1109 flags_sort_type_pointer = g_object_get_data (G_OBJECT (cols->data),
1110 MODEST_HEADER_VIEW_FLAG_SORT);
1111 if (GPOINTER_TO_INT (flags_sort_type_pointer) == TNY_HEADER_FLAG_PRIORITY_MASK)
1112 value = _("mcen_li_sort_priority");
1114 value = _("mcen_li_sort_attachment");
1119 case TNY_GTK_HEADER_LIST_MODEL_TO_COLUMN:
1120 case TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN:
1121 if (current_sort_type == GTK_SORT_ASCENDING)
1122 value = _("mcen_li_sort_sender_recipient_az");
1124 value = _("mcen_li_sort_sender_recipient_za");
1126 case TNY_GTK_HEADER_LIST_MODEL_DATE_SENT_TIME_T_COLUMN:
1127 case TNY_GTK_HEADER_LIST_MODEL_DATE_RECEIVED_TIME_T_COLUMN:
1128 if (current_sort_type == GTK_SORT_ASCENDING)
1129 value = _("mcen_li_sort_date_oldest");
1131 value = _("mcen_li_sort_date_newest");
1133 case TNY_GTK_HEADER_LIST_MODEL_SUBJECT_COLUMN:
1134 if (current_sort_type == GTK_SORT_ASCENDING)
1135 value = _("mcen_li_sort_subject_az");
1137 value = _("mcen_li_sort_subject_za");
1139 case TNY_GTK_HEADER_LIST_MODEL_MESSAGE_SIZE_COLUMN:
1140 if (current_sort_type == GTK_SORT_ASCENDING)
1141 value = _("mcen_li_sort_size_smallest");
1143 value = _("mcen_li_sort_size_largest");
1148 hildon_button_set_value (HILDON_BUTTON (priv->sort_button), value?value:"");