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>
55 #include <tny-simple-list.h>
58 CONTENTS_STATE_NONE = 0,
59 CONTENTS_STATE_EMPTY = 1,
60 CONTENTS_STATE_HEADERS = 2
64 EDIT_MODE_COMMAND_MOVE = 1,
65 EDIT_MODE_COMMAND_DELETE = 2,
68 typedef struct _ModestHeaderWindowPrivate ModestHeaderWindowPrivate;
69 struct _ModestHeaderWindowPrivate {
71 GtkWidget *header_view;
72 GtkWidget *empty_view;
73 GtkWidget *contents_view;
75 GtkWidget *new_message_button;
78 ContentsState contents_state;
86 GtkWidget *updating_banner;
87 guint updating_banner_timeout;
91 gulong queue_change_handler;
94 gboolean progress_hint;
95 gchar *current_store_account;
98 GtkWidget *sort_button;
100 #define MODEST_HEADER_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
101 MODEST_TYPE_HEADER_WINDOW, \
102 ModestHeaderWindowPrivate))
104 /* 'private'/'protected' functions */
105 static void modest_header_window_class_init (ModestHeaderWindowClass *klass);
106 static void modest_header_window_init (ModestHeaderWindow *obj);
107 static void modest_header_window_finalize (GObject *obj);
109 static void connect_signals (ModestHeaderWindow *self);
110 static void modest_header_window_disconnect_signals (ModestWindow *self);
112 static void setup_menu (ModestHeaderWindow *self);
113 static GtkWidget *create_empty_view (ModestWindow *self);
114 static GtkWidget *create_header_view (ModestWindow *progress_window,
117 static void update_view (ModestHeaderWindow *self,
118 TnyFolderChange *change);
119 static void set_contents_state (ModestHeaderWindow *window,
120 ContentsState state);
122 static void on_msg_count_changed (ModestHeaderView *header_view,
124 TnyFolderChange *change,
125 ModestHeaderWindow *header_window);
126 static void on_header_activated (ModestHeaderView *header_view,
129 ModestHeaderWindow *header_window);
130 static void on_updating_msg_list (ModestHeaderView *header_view,
133 static void set_delete_edit_mode (GtkButton *button,
134 ModestHeaderWindow *self);
135 static void set_moveto_edit_mode (GtkButton *button,
136 ModestHeaderWindow *self);
137 static gboolean on_expose_event(GtkTreeView *header_view,
138 GdkEventExpose *event,
140 static gboolean on_map_event (GtkWidget *widget,
143 static void on_vertical_movement (HildonPannableArea *area,
144 HildonMovementDirection direction,
145 gdouble x, gdouble y, gpointer user_data);
146 static void on_queue_changed (ModestMailOperationQueue *queue,
147 ModestMailOperation *mail_op,
148 ModestMailOperationQueueNotification type,
149 ModestHeaderWindow *self);
150 static void modest_header_window_pack_toolbar (ModestHildon2Window *self,
151 GtkPackType pack_type,
153 static void edit_mode_changed (ModestHeaderWindow *header_window,
156 ModestHeaderWindow *self);
157 static void on_progress_list_changed (ModestWindowMgr *mgr,
158 ModestHeaderWindow *self);
159 static void update_progress_hint (ModestHeaderWindow *self);
160 static void on_sort_column_changed (GtkTreeSortable *treesortable,
162 static void update_sort_button (ModestHeaderWindow *self);
163 static void on_horizontal_movement (HildonPannableArea *hildonpannable,
170 static GtkWindowClass *parent_class = NULL;
172 #define EMPTYVIEW_XALIGN 0.5
173 #define EMPTYVIEW_YALIGN 0.5
174 #define EMPTYVIEW_XSPACE 1.0
175 #define EMPTYVIEW_YSPACE 1.0
179 /************************************************************************/
182 modest_header_window_get_type (void)
184 static GType my_type = 0;
186 static const GTypeInfo my_info = {
187 sizeof(ModestHeaderWindowClass),
188 NULL, /* base init */
189 NULL, /* base finalize */
190 (GClassInitFunc) modest_header_window_class_init,
191 NULL, /* class finalize */
192 NULL, /* class data */
193 sizeof(ModestHeaderWindow),
195 (GInstanceInitFunc) modest_header_window_init,
198 my_type = g_type_register_static (MODEST_TYPE_HILDON2_WINDOW,
199 "ModestHeaderWindow",
206 modest_header_window_class_init (ModestHeaderWindowClass *klass)
208 GObjectClass *gobject_class;
209 gobject_class = (GObjectClass*) klass;
210 ModestWindowClass *modest_window_class = (ModestWindowClass *) klass;
211 ModestHildon2WindowClass *modest_hildon2_window_class = (ModestHildon2WindowClass *) klass;
213 parent_class = g_type_class_peek_parent (klass);
214 gobject_class->finalize = modest_header_window_finalize;
216 g_type_class_add_private (gobject_class, sizeof(ModestHeaderWindowPrivate));
218 modest_window_class->disconnect_signals_func = modest_header_window_disconnect_signals;
219 modest_hildon2_window_class->pack_toolbar_func = modest_header_window_pack_toolbar;
223 modest_header_window_init (ModestHeaderWindow *obj)
225 ModestHeaderWindowPrivate *priv;
227 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(obj);
229 priv->sighandlers = NULL;
231 priv->header_view = NULL;
232 priv->empty_view = NULL;
233 priv->top_vbox = NULL;
234 priv->contents_view = NULL;
235 priv->contents_state = CONTENTS_STATE_NONE;
237 priv->updating_banner = NULL;
238 priv->updating_banner_timeout = 0;
239 priv->autoscroll = TRUE;
240 priv->progress_hint = FALSE;
241 priv->queue_change_handler = 0;
242 priv->current_store_account = NULL;
243 priv->sort_button = NULL;
244 priv->new_message_button = NULL;
246 modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(),
248 "applications_email_headerview");
252 modest_header_window_finalize (GObject *obj)
254 ModestHeaderWindowPrivate *priv;
256 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(obj);
258 tny_folder_sync_async (TNY_FOLDER (priv->folder),
259 FALSE, NULL, NULL, NULL);
261 g_object_unref (priv->folder);
262 g_object_unref (priv->header_view);
263 g_object_unref (priv->empty_view);
265 if (priv->current_store_account) {
266 g_free (priv->current_store_account);
267 priv->current_store_account = NULL;
270 /* Sanity check: shouldn't be needed, the window mgr should
271 call this function before */
272 modest_header_window_disconnect_signals (MODEST_WINDOW (obj));
274 if (priv->updating_banner_timeout > 0) {
275 g_source_remove (priv->updating_banner_timeout);
276 priv->updating_banner_timeout = 0;
278 if (priv->updating_banner) {
279 gtk_widget_destroy (priv->updating_banner);
280 priv->updating_banner = NULL;
283 G_OBJECT_CLASS(parent_class)->finalize (obj);
287 modest_header_window_disconnect_signals (ModestWindow *self)
289 ModestHeaderWindowPrivate *priv;
290 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
292 if (g_signal_handler_is_connected (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
293 priv->queue_change_handler))
294 g_signal_handler_disconnect (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
295 priv->queue_change_handler);
297 modest_signal_mgr_disconnect_all_and_destroy (priv->sighandlers);
298 priv->sighandlers = NULL;
303 connect_signals (ModestHeaderWindow *self)
305 ModestHeaderWindowPrivate *priv;
306 GtkTreeSortable *sortable;
308 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
313 modest_signal_mgr_connect (priv->sighandlers,G_OBJECT(priv->header_view),
315 G_CALLBACK(on_msg_count_changed), self);
317 modest_signal_mgr_connect (priv->sighandlers, G_OBJECT (priv->header_view),
319 G_CALLBACK (on_header_activated), self);
321 modest_signal_mgr_connect (priv->sighandlers,
322 G_OBJECT (priv->header_view),
324 G_CALLBACK (on_updating_msg_list),
327 modest_signal_mgr_connect (priv->sighandlers,
328 G_OBJECT (priv->header_view),
330 G_CALLBACK (on_expose_event),
333 sortable = GTK_TREE_SORTABLE (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->header_view)));
336 modest_signal_mgr_connect (priv->sighandlers,
338 "sort-column-changed",
339 G_CALLBACK (on_sort_column_changed),
343 modest_signal_mgr_connect (priv->sighandlers,
346 G_CALLBACK (on_map_event),
350 modest_signal_mgr_connect (priv->sighandlers,
351 G_OBJECT (priv->contents_view),
353 G_CALLBACK (on_vertical_movement),
356 /* Mail Operation Queue */
357 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
358 G_OBJECT (modest_runtime_get_window_mgr ()),
359 "progress-list-changed",
360 G_CALLBACK (on_progress_list_changed), self);
362 modest_signal_mgr_connect (priv->sighandlers,
363 G_OBJECT (priv->new_message_button),
365 G_CALLBACK (modest_ui_actions_on_new_msg), self);
369 modest_signal_mgr_connect (priv->sighandlers,
370 (GObject *) priv->contents_view,
371 "horizontal-movement",
372 G_CALLBACK (on_horizontal_movement),
377 folder_refreshed_cb (ModestMailOperation *mail_op,
381 /* Update the view (folder could be empty) */
382 update_view (MODEST_HEADER_WINDOW (user_data), NULL);
386 create_header_view (ModestWindow *self, TnyFolder *folder)
388 GtkWidget *header_view;
390 header_view = modest_header_view_new (NULL, MODEST_HEADER_VIEW_STYLE_TWOLINES);
391 modest_header_view_set_folder (MODEST_HEADER_VIEW (header_view), folder,
392 TRUE, self, folder_refreshed_cb, self);
393 modest_header_view_set_filter (MODEST_HEADER_VIEW (header_view),
394 MODEST_HEADER_VIEW_FILTER_NONE);
395 modest_widget_memory_restore (modest_runtime_get_conf (), G_OBJECT(header_view),
396 MODEST_CONF_HEADER_VIEW_KEY);
402 create_empty_view (ModestWindow *self)
404 GtkWidget *viewport = NULL;
405 GtkWidget *label = NULL;
406 GtkWidget *align = NULL;
407 GtkWidget *vbox = NULL;
408 GtkWidget *button = NULL;
409 GdkPixbuf *new_message_pixbuf;
411 vbox = gtk_vbox_new (0, FALSE);
413 align = gtk_alignment_new(EMPTYVIEW_XALIGN, EMPTYVIEW_YALIGN, EMPTYVIEW_XSPACE, EMPTYVIEW_YSPACE);
414 label = gtk_label_new (_("mcen_ia_nomessages"));
415 hildon_helper_set_logical_font (label, "LargeSystemFont");
416 gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
417 gtk_widget_show (label);
418 gtk_widget_show (align);
419 gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
420 gtk_container_add (GTK_CONTAINER (align), label);
421 gtk_box_pack_end (GTK_BOX (vbox), align, TRUE, TRUE, 0);
423 button = hildon_button_new (MODEST_EDITABLE_SIZE,
424 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
426 hildon_button_set_title (HILDON_BUTTON (button), _("mcen_ti_new_message"));
427 new_message_pixbuf = modest_platform_get_icon ("general_add", MODEST_ICON_SIZE_BIG);
428 hildon_button_set_image (HILDON_BUTTON (button),
429 gtk_image_new_from_pixbuf (new_message_pixbuf));
430 g_object_unref (new_message_pixbuf);
431 gtk_widget_show_all (button);
432 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
434 gtk_widget_show (vbox);
436 g_signal_connect (button,
438 G_CALLBACK (modest_ui_actions_on_new_msg), self);
440 viewport = gtk_viewport_new ((GtkAdjustment *) gtk_adjustment_new (0, 0, 0, 0, 0, 0),
441 (GtkAdjustment *) gtk_adjustment_new (0, 0, 0, 0, 0, 0));
442 gtk_container_add (GTK_CONTAINER (viewport), vbox);
448 on_vertical_movement (HildonPannableArea *area,
449 HildonMovementDirection direction,
450 gdouble x, gdouble y, gpointer user_data)
452 ModestHeaderWindow *self = (ModestHeaderWindow *) user_data;
453 ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
455 priv->autoscroll = FALSE;
460 modest_header_window_new (TnyFolder *folder, const gchar *account_name, const gchar *mailbox)
462 ModestHeaderWindow *self = NULL;
463 ModestHeaderWindowPrivate *priv = NULL;
465 GdkPixbuf *window_icon;
466 ModestAccountMgr *mgr;
467 ModestAccountSettings *settings = NULL;
468 ModestServerAccountSettings *store_settings = NULL;
469 GtkWidget *action_area_box;
470 GdkPixbuf *new_message_pixbuf;
471 GtkWidget *alignment;
472 gchar *account_display_name = NULL;
474 self = MODEST_HEADER_WINDOW(g_object_new(MODEST_TYPE_HEADER_WINDOW, NULL));
475 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
477 priv->folder = g_object_ref (folder);
479 priv->contents_view = hildon_pannable_area_new ();
480 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
481 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
483 HILDON_MARGIN_DOUBLE, HILDON_MARGIN_DOUBLE);
485 /* We need to do this here to properly listen for mail
486 operations because create_header_view launches a mail
488 priv->queue_change_handler =
489 g_signal_connect (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
491 G_CALLBACK (on_queue_changed),
494 priv->header_view = create_header_view (MODEST_WINDOW (self), folder);
495 priv->empty_view = create_empty_view (MODEST_WINDOW (self));
497 /* Transform the floating reference in a "hard" reference. We
498 need to do this because the widgets could be added/removed
499 to containers many times so we always need to keep a
500 reference. It could happen also that some widget is never
501 added to any container */
502 g_object_ref_sink (priv->header_view);
503 g_object_ref_sink (priv->empty_view);
505 g_signal_connect (G_OBJECT (self), "edit-mode-changed",
506 G_CALLBACK (edit_mode_changed), (gpointer) self);
508 action_area_box = hildon_tree_view_get_action_area_box (GTK_TREE_VIEW (priv->header_view));
509 priv->new_message_button = hildon_button_new (MODEST_EDITABLE_SIZE, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
511 hildon_button_set_title (HILDON_BUTTON (priv->new_message_button), _("mcen_ti_new_message"));
512 new_message_pixbuf = modest_platform_get_icon ("general_add", MODEST_ICON_SIZE_BIG);
513 hildon_button_set_image (HILDON_BUTTON (priv->new_message_button), gtk_image_new_from_pixbuf (new_message_pixbuf));
514 g_object_unref (new_message_pixbuf);
516 gtk_box_pack_start (GTK_BOX (action_area_box), priv->new_message_button, TRUE, TRUE, 0);
517 gtk_widget_show_all (priv->new_message_button);
518 hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->header_view), TRUE);
522 priv->top_vbox = gtk_vbox_new (FALSE, 0);
523 gtk_container_add (GTK_CONTAINER (alignment), priv->contents_view);
524 gtk_box_pack_end (GTK_BOX (priv->top_vbox), alignment, TRUE, TRUE, 0);
526 gtk_container_add (GTK_CONTAINER (self), priv->top_vbox);
528 gtk_widget_show (alignment);
529 gtk_widget_show (priv->contents_view);
530 gtk_widget_show (priv->top_vbox);
532 connect_signals (MODEST_HEADER_WINDOW (self));
534 update_view (self, NULL);
536 /* Load previous osso state, for instance if we are being restored from
538 modest_osso_load_state ();
540 /* Get device name */
541 modest_maemo_utils_get_device_name ();
543 app = hildon_program_get_instance ();
544 hildon_program_add_window (app, HILDON_WINDOW (self));
546 /* Set window icon */
547 window_icon = modest_platform_get_icon (MODEST_APP_ICON, MODEST_ICON_SIZE_BIG);
549 gtk_window_set_icon (GTK_WINDOW (self), window_icon);
550 g_object_unref (window_icon);
553 /* Dont't restore settings here,
554 * because it requires a gtk_widget_show(),
555 * and we don't want to do that until later,
556 * so that the UI is not visible for non-menu D-Bus activation.
559 /* setup edit modes */
560 modest_hildon2_window_register_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_DELETE,
561 _("mcen_ti_edit_delete"), _HL("wdgt_bd_delete"),
562 GTK_TREE_VIEW (priv->header_view),
563 GTK_SELECTION_MULTIPLE,
564 EDIT_MODE_CALLBACK (modest_ui_actions_on_edit_mode_delete_message));
565 modest_hildon2_window_register_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_MOVE,
566 _("mcen_ti_edit_move"), _HL("wdgt_bd_move"),
567 GTK_TREE_VIEW (priv->header_view),
568 GTK_SELECTION_MULTIPLE,
569 EDIT_MODE_CALLBACK (modest_ui_actions_on_edit_mode_move_to));
572 modest_window_set_active_account (MODEST_WINDOW (self), account_name);
573 modest_window_set_active_mailbox (MODEST_WINDOW (self), mailbox);
574 mgr = modest_runtime_get_account_mgr ();
575 settings = modest_account_mgr_load_account_settings (mgr, account_name);
577 account_display_name = g_strdup (modest_account_settings_get_display_name (settings));
578 store_settings = modest_account_settings_get_store_settings (settings);
579 if (store_settings) {
580 priv->current_store_account =
581 g_strdup (modest_server_account_settings_get_account_name (store_settings));
582 g_object_unref (store_settings);
584 g_object_unref (settings);
586 /* Set window title */
587 if (TNY_IS_FOLDER (folder)) {
590 if (tny_folder_get_folder_type (folder) == TNY_FOLDER_TYPE_INBOX) {
591 const gchar *box_name;
593 if (box_name == NULL || box_name[0] == '\0') {
594 box_name = account_display_name;
596 folder_name = g_strconcat (_("mcen_me_folder_inbox"), " - ", box_name, NULL);
598 folder_name = modest_tny_folder_get_display_name (folder);
601 gtk_window_set_title (GTK_WINDOW (self), folder_name);
602 g_free (folder_name);
604 g_free (account_display_name);
607 update_progress_hint (self);
608 update_sort_button (self);
610 return MODEST_WINDOW(self);
614 modest_header_window_get_header_view (ModestHeaderWindow *self)
616 ModestHeaderWindowPrivate *priv = NULL;
618 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW(self), FALSE);
620 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
622 return MODEST_HEADER_VIEW (priv->header_view);
625 static void setup_menu (ModestHeaderWindow *self)
627 ModestHeaderWindowPrivate *priv;
629 g_return_if_fail (MODEST_IS_HEADER_WINDOW(self));
630 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
632 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_new_message"), "<Control>n",
633 APP_MENU_CALLBACK (modest_ui_actions_on_new_msg),
634 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_new_msg));
635 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_move_messages"), NULL,
636 APP_MENU_CALLBACK (set_moveto_edit_mode),
637 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_move_to));
638 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_delete_messages"), NULL,
639 APP_MENU_CALLBACK (set_delete_edit_mode),
640 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_delete));
641 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_folder_details"), NULL,
642 APP_MENU_CALLBACK (modest_ui_actions_on_details),
643 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_details));
644 priv->sort_button = hildon_button_new (MODEST_EDITABLE_SIZE,
645 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
646 hildon_button_set_title (HILDON_BUTTON (priv->sort_button), _("mcen_me_sort"));
647 g_signal_connect (G_OBJECT (priv->sort_button), "clicked",
648 G_CALLBACK (modest_ui_actions_on_sort), (gpointer) self);
649 hildon_button_set_style(HILDON_BUTTON (priv->sort_button), HILDON_BUTTON_STYLE_PICKER);
650 hildon_button_set_title_alignment (HILDON_BUTTON (priv->sort_button), 0.5, 0.5);
651 hildon_button_set_value_alignment (HILDON_BUTTON (priv->sort_button), 0.5, 0.5);
652 modest_hildon2_window_add_button_to_menu (MODEST_HILDON2_WINDOW (self), GTK_BUTTON (priv->sort_button),
653 modest_ui_dimming_rules_on_sort);
654 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_sendandreceive"), NULL,
655 APP_MENU_CALLBACK (modest_ui_actions_on_send_receive),
656 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_send_receive));
657 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_outbox_cancelsend"), NULL,
658 APP_MENU_CALLBACK (modest_ui_actions_cancel_send),
659 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_cancel_sending_all));
663 update_view (ModestHeaderWindow *self,
664 TnyFolderChange *change)
666 ModestHeaderWindowPrivate *priv = NULL;
667 gboolean refilter = FALSE;
668 gboolean folder_empty = FALSE;
669 gboolean all_marked_as_deleted = FALSE;
671 g_return_if_fail (MODEST_IS_HEADER_WINDOW(self));
672 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
673 g_return_if_fail (priv->folder);
675 if (change != NULL) {
676 TnyFolderChangeChanged changed;
678 changed = tny_folder_change_get_changed (change);
679 /* If something changes */
680 if ((changed) & TNY_FOLDER_CHANGE_CHANGED_ALL_COUNT)
681 folder_empty = (((guint) tny_folder_change_get_new_all_count (change)) == 0);
683 folder_empty = (((guint) tny_folder_get_all_count (TNY_FOLDER (priv->folder))) == 0);
685 if ((changed) & TNY_FOLDER_CHANGE_CHANGED_EXPUNGED_HEADERS)
688 folder_empty = (((guint) tny_folder_get_all_count (TNY_FOLDER (priv->folder))) == 0);
691 /* Check if all messages are marked to be deleted */
692 all_marked_as_deleted = modest_header_view_is_empty (MODEST_HEADER_VIEW (priv->header_view));
693 folder_empty = folder_empty || all_marked_as_deleted;
695 /* Set style of headers view */
696 set_contents_state (self, folder_empty?CONTENTS_STATE_EMPTY:CONTENTS_STATE_HEADERS);
699 modest_header_view_refilter (MODEST_HEADER_VIEW (priv->header_view));
703 set_contents_state (ModestHeaderWindow *self,
706 ModestHeaderWindowPrivate *priv = NULL;
708 g_return_if_fail (MODEST_IS_HEADER_WINDOW(self));
709 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
711 if (priv->contents_state == state)
714 /* Remove from container the old content */
715 switch (priv->contents_state) {
716 case CONTENTS_STATE_EMPTY:
717 gtk_container_remove (GTK_CONTAINER (priv->contents_view), priv->empty_view);
719 case CONTENTS_STATE_HEADERS:
720 gtk_container_remove (GTK_CONTAINER (priv->contents_view), priv->header_view);
722 case CONTENTS_STATE_NONE:
726 /* Add the new content */
728 case CONTENTS_STATE_EMPTY:
729 gtk_container_add (GTK_CONTAINER (priv->contents_view), priv->empty_view);
730 gtk_widget_show (priv->empty_view);
732 case CONTENTS_STATE_HEADERS:
733 gtk_container_add (GTK_CONTAINER (priv->contents_view), priv->header_view);
734 gtk_widget_show (priv->header_view);
736 case CONTENTS_STATE_NONE:
739 priv->contents_state = state;
743 on_msg_count_changed (ModestHeaderView *header_view,
745 TnyFolderChange *change,
746 ModestHeaderWindow *header_window)
748 g_return_if_fail (MODEST_IS_HEADER_WINDOW (header_window));
750 update_view (MODEST_HEADER_WINDOW (header_window), change);
754 on_header_activated (ModestHeaderView *header_view,
757 ModestHeaderWindow *header_window)
759 modest_ui_actions_on_header_activated (header_view, header, path, MODEST_WINDOW (header_window));
763 updating_banner_destroyed (gpointer data,
764 GObject *where_the_object_was)
766 ModestHeaderWindowPrivate *priv = NULL;
768 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (data);
770 priv->updating_banner = NULL;
774 show_updating_banner (gpointer user_data)
776 ModestHeaderWindowPrivate *priv = NULL;
778 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (user_data);
780 if (priv->updating_banner == NULL) {
782 /* We're outside the main lock */
783 gdk_threads_enter ();
784 priv->updating_banner =
785 modest_platform_animation_banner (GTK_WIDGET (user_data), NULL,
786 _CS ("ckdg_pb_updating"));
788 /* We need this because banners in Maemo could be
789 destroyed by dialogs so we need to properly update
790 our reference to it */
791 g_object_weak_ref (G_OBJECT (priv->updating_banner),
792 updating_banner_destroyed,
794 gdk_threads_leave ();
798 priv->updating_banner_timeout = 0;
803 * We use this function to show/hide a progress banner showing
804 * "Updating" while the header view is being filled. We're not showing
805 * it unless the update takes more than 2 seconds
807 * If starting = TRUE then the refresh is starting, otherwise it means
808 * that is has just finished
811 on_updating_msg_list (ModestHeaderView *header_view,
815 ModestHeaderWindowPrivate *priv = NULL;
817 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (user_data);
819 /* Remove old timeout */
820 if (priv->updating_banner_timeout > 0) {
821 g_source_remove (priv->updating_banner_timeout);
822 priv->updating_banner_timeout = 0;
825 /* Create a new timeout */
827 priv->updating_banner_timeout =
828 g_timeout_add (2000, show_updating_banner, user_data);
830 /* Remove the banner if exists */
831 if (priv->updating_banner) {
832 gtk_widget_destroy (priv->updating_banner);
833 priv->updating_banner = NULL;
839 set_delete_edit_mode (GtkButton *button,
840 ModestHeaderWindow *self)
842 modest_hildon2_window_set_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_DELETE);
846 set_moveto_edit_mode (GtkButton *button,
847 ModestHeaderWindow *self)
849 modest_hildon2_window_set_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_MOVE);
853 on_expose_event(GtkTreeView *header_view,
854 GdkEventExpose *event,
857 ModestHeaderWindow *self = (ModestHeaderWindow *) user_data;
858 ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
860 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW (self), FALSE);
862 if (priv->autoscroll)
863 hildon_pannable_area_jump_to (HILDON_PANNABLE_AREA (priv->contents_view), 0.0, 0.0);
869 on_map_event(GtkWidget *widget,
873 ModestHeaderWindow *self = (ModestHeaderWindow *) user_data;
874 ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
876 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW (self), FALSE);
878 if (priv->progress_hint) {
879 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
885 on_progress_list_changed (ModestWindowMgr *mgr,
886 ModestHeaderWindow *self)
888 update_progress_hint (self);
892 has_active_operations (ModestHeaderWindow *self)
894 GSList *operations = NULL, *node;
895 ModestMailOperationQueue *queue;
896 gboolean has_active = FALSE;
898 queue = modest_runtime_get_mail_operation_queue ();
899 operations = modest_mail_operation_queue_get_by_source (queue, G_OBJECT (self));
901 for (node = operations; node != NULL; node = g_slist_next (node)) {
902 if (!modest_mail_operation_is_finished (MODEST_MAIL_OPERATION (node->data))) {
909 g_slist_foreach (operations, (GFunc) g_object_unref, NULL);
910 g_slist_free (operations);
917 update_progress_hint (ModestHeaderWindow *self)
919 ModestHeaderWindowPrivate *priv;
921 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
923 priv->progress_hint = FALSE;
925 if (has_active_operations (self)) {
926 priv->progress_hint = TRUE;
928 priv->progress_hint = FALSE;
931 if (!priv->progress_hint && priv->current_store_account) {
932 priv->progress_hint =
933 modest_window_mgr_has_progress_operation_on_account (modest_runtime_get_window_mgr (),
934 priv->current_store_account);
937 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
939 if (GTK_WIDGET_VISIBLE (self)) {
940 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), priv->progress_hint?1:0);
945 modest_header_window_toolbar_on_transfer_mode (ModestHeaderWindow *self)
947 ModestHeaderWindowPrivate *priv= NULL;
949 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW (self), FALSE);
950 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
952 return priv->progress_hint;
956 modest_header_window_transfer_mode_enabled (ModestHeaderWindow *self)
958 ModestHeaderWindowPrivate *priv;
960 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW (self), FALSE);
961 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
963 return priv->progress_hint;
967 on_mail_operation_started (ModestMailOperation *mail_op,
970 ModestHeaderWindow *self;
971 ModestMailOperationTypeOperation op_type;
972 GObject *source = NULL;
974 self = MODEST_HEADER_WINDOW (user_data);
975 op_type = modest_mail_operation_get_type_operation (mail_op);
976 source = modest_mail_operation_get_source(mail_op);
977 if (G_OBJECT (self) == source) {
978 update_progress_hint (self);
980 g_object_unref (source);
984 on_mail_operation_finished (ModestMailOperation *mail_op,
987 ModestHeaderWindow *self;
989 self = MODEST_HEADER_WINDOW (user_data);
991 /* Don't disable the progress hint if there are more pending
992 operations from this window */
993 update_progress_hint (self);
995 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
999 on_queue_changed (ModestMailOperationQueue *queue,
1000 ModestMailOperation *mail_op,
1001 ModestMailOperationQueueNotification type,
1002 ModestHeaderWindow *self)
1004 ModestHeaderWindowPrivate *priv;
1006 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1008 /* If this operations was created by another window, do nothing */
1009 if (!modest_mail_operation_is_mine (mail_op, G_OBJECT(self)))
1012 if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_ADDED) {
1013 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
1015 "operation-started",
1016 G_CALLBACK (on_mail_operation_started),
1018 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
1020 "operation-finished",
1021 G_CALLBACK (on_mail_operation_finished),
1023 } else if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED) {
1024 priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
1026 "operation-started");
1027 priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
1029 "operation-finished");
1034 modest_header_window_pack_toolbar (ModestHildon2Window *self,
1035 GtkPackType pack_type,
1038 ModestHeaderWindowPrivate *priv;
1040 g_return_if_fail (MODEST_IS_HEADER_WINDOW (self));
1041 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1043 if (pack_type == GTK_PACK_START) {
1044 gtk_box_pack_start (GTK_BOX (priv->top_vbox), toolbar, FALSE, FALSE, 0);
1046 gtk_box_pack_end (GTK_BOX (priv->top_vbox), toolbar, FALSE, FALSE, 0);
1051 edit_mode_changed (ModestHeaderWindow *header_window,
1054 ModestHeaderWindow *self)
1056 ModestHeaderWindowPrivate *priv;
1057 ModestHeaderViewFilter filter = MODEST_HEADER_VIEW_FILTER_NONE;
1059 g_return_if_fail (MODEST_IS_HEADER_WINDOW (self));
1060 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1062 switch (edit_mode_id) {
1063 case EDIT_MODE_COMMAND_MOVE:
1064 filter = MODEST_HEADER_VIEW_FILTER_MOVEABLE;
1066 case EDIT_MODE_COMMAND_DELETE:
1067 filter = MODEST_HEADER_VIEW_FILTER_DELETABLE;
1069 case MODEST_HILDON2_WINDOW_EDIT_MODE_NONE:
1070 filter = MODEST_HEADER_VIEW_FILTER_NONE;
1074 hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->header_view), !enabled);
1076 modest_header_view_set_filter (MODEST_HEADER_VIEW (priv->header_view),
1079 GtkTreeSelection *sel;
1081 /* Unselect all. This will prevent us from keeping a
1082 reference to a TnyObject that we don't want to
1084 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->header_view));
1085 gtk_tree_selection_unselect_all (sel);
1087 modest_header_view_unset_filter (MODEST_HEADER_VIEW (priv->header_view),
1093 on_sort_column_changed (GtkTreeSortable *treesortable,
1096 update_sort_button (MODEST_HEADER_WINDOW (user_data));
1100 update_sort_button (ModestHeaderWindow *self)
1102 ModestHeaderWindowPrivate *priv;
1103 GtkTreeSortable *sortable;
1104 gint current_sort_colid = -1;
1105 GtkSortType current_sort_type;
1106 const gchar *value = NULL;
1108 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1109 sortable = GTK_TREE_SORTABLE (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->header_view)));
1111 if (!gtk_tree_sortable_get_sort_column_id (sortable,
1112 ¤t_sort_colid, ¤t_sort_type)) {
1113 value = _("mcen_li_sort_sender_date_newest");
1115 switch (current_sort_colid) {
1116 case TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN:
1119 cols = modest_header_view_get_columns (MODEST_HEADER_VIEW (priv->header_view));
1121 gpointer flags_sort_type_pointer;
1122 flags_sort_type_pointer = g_object_get_data (G_OBJECT (cols->data),
1123 MODEST_HEADER_VIEW_FLAG_SORT);
1124 if (GPOINTER_TO_INT (flags_sort_type_pointer) == TNY_HEADER_FLAG_PRIORITY_MASK)
1125 value = _("mcen_li_sort_priority");
1127 value = _("mcen_li_sort_attachment");
1132 case TNY_GTK_HEADER_LIST_MODEL_TO_COLUMN:
1133 case TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN:
1134 if (current_sort_type == GTK_SORT_ASCENDING)
1135 value = _("mcen_li_sort_sender_recipient_az");
1137 value = _("mcen_li_sort_sender_recipient_za");
1139 case TNY_GTK_HEADER_LIST_MODEL_DATE_SENT_TIME_T_COLUMN:
1140 case TNY_GTK_HEADER_LIST_MODEL_DATE_RECEIVED_TIME_T_COLUMN:
1141 if (current_sort_type == GTK_SORT_ASCENDING)
1142 value = _("mcen_li_sort_date_oldest");
1144 value = _("mcen_li_sort_date_newest");
1146 case TNY_GTK_HEADER_LIST_MODEL_SUBJECT_COLUMN:
1147 if (current_sort_type == GTK_SORT_ASCENDING)
1148 value = _("mcen_li_sort_subject_az");
1150 value = _("mcen_li_sort_subject_za");
1152 case TNY_GTK_HEADER_LIST_MODEL_MESSAGE_SIZE_COLUMN:
1153 if (current_sort_type == GTK_SORT_ASCENDING)
1154 value = _("mcen_li_sort_size_smallest");
1156 value = _("mcen_li_sort_size_largest");
1161 hildon_button_set_value (HILDON_BUTTON (priv->sort_button), value?value:"");
1165 on_horizontal_movement (HildonPannableArea *hildonpannable,
1171 /* ModestHeaderWindowPrivate *priv; */
1172 /* gint dest_x, dest_y; */
1173 /* TnyHeader *header; */
1175 /* /\* Ignore right to left movement *\/ */
1176 /* if (direction == HILDON_MOVEMENT_LEFT) */
1179 /* /\* Get the header to delete *\/ */
1180 /* priv = MODEST_HEADER_WINDOW_GET_PRIVATE (user_data); */
1182 /* /\* Get tree view coordinates *\/ */
1183 /* if (!gtk_widget_translate_coordinates ((GtkWidget *) hildonpannable, */
1184 /* priv->header_view, */
1191 /* header = modest_header_view_get_header_at_pos ((ModestHeaderView *) priv->header_view, */
1192 /* dest_x, dest_y); */
1194 /* gint response; */
1195 /* gchar *subject, *msg; */
1197 /* subject = tny_header_dup_subject (header); */
1199 /* subject = g_strdup (_("mail_va_no_subject")); */
1201 /* msg = g_strdup_printf (ngettext("emev_nc_delete_message", "emev_nc_delete_messages", 1), */
1203 /* g_free (subject); */
1205 /* /\* Confirmation dialog *\/ */
1206 /* response = modest_platform_run_confirmation_dialog ((GtkWindow *) user_data, msg); */
1209 /* if (response == GTK_RESPONSE_OK) { */
1210 /* ModestMailOperation *mail_op; */
1211 /* TnyList *header_list; */
1213 /* header_list = tny_simple_list_new (); */
1214 /* tny_list_append (header_list, (GObject *) header); */
1215 /* mail_op = modest_mail_operation_new ((GObject *) user_data); */
1216 /* modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), */
1218 /* modest_mail_operation_remove_msgs (mail_op, header_list, FALSE); */
1219 /* g_object_unref (mail_op); */
1220 /* g_object_unref (header_list); */
1222 /* g_object_unref (header); */