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 <hildon/hildon-pannable-area.h>
32 #include <hildon/hildon-helper.h>
33 #include <modest-window-mgr.h>
34 #include <modest-window-priv.h>
35 #include <modest-signal-mgr.h>
36 #include <modest-runtime.h>
37 #include <modest-platform.h>
38 #include <modest-maemo-utils.h>
39 #include <modest-icon-names.h>
40 #include <modest-ui-constants.h>
41 #include <modest-account-mgr.h>
42 #include <modest-account-mgr-helpers.h>
43 #include <modest-defs.h>
44 #include <modest-widget-memory.h>
45 #include <modest-ui-actions.h>
46 #include <modest-platform.h>
47 #include <modest-text-utils.h>
48 #include <hildon/hildon-button.h>
49 #include <hildon/hildon-program.h>
50 #include <hildon/hildon-banner.h>
51 #include <modest-ui-dimming-rules.h>
52 #include <modest-tny-folder.h>
53 #include <modest-tny-account.h>
54 #include <tny-simple-list.h>
56 #define SHOW_LATEST_SIZE 250
59 CONTENTS_STATE_NONE = 0,
60 CONTENTS_STATE_EMPTY = 1,
61 CONTENTS_STATE_HEADERS = 2
65 EDIT_MODE_COMMAND_MOVE = 1,
66 EDIT_MODE_COMMAND_DELETE = 2,
69 typedef struct _ModestHeaderWindowPrivate ModestHeaderWindowPrivate;
70 struct _ModestHeaderWindowPrivate {
72 GtkWidget *header_view;
73 GtkWidget *empty_view;
74 GtkWidget *contents_view;
76 GtkWidget *new_message_button;
77 GtkWidget *show_more_button;
78 GtkWidget *show_more_button2;
81 ContentsState contents_state;
87 GtkWidget *updating_banner;
88 guint updating_banner_timeout;
92 gulong queue_change_handler;
93 gulong sort_column_handler;
97 gboolean progress_hint;
98 gchar *current_store_account;
101 GtkWidget *sort_button;
109 GtkTreeModel *model_weak_ref;
111 #define MODEST_HEADER_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
112 MODEST_TYPE_HEADER_WINDOW, \
113 ModestHeaderWindowPrivate))
115 /* 'private'/'protected' functions */
116 static void modest_header_window_class_init (ModestHeaderWindowClass *klass);
117 static void modest_header_window_init (ModestHeaderWindow *obj);
118 static void modest_header_window_finalize (GObject *obj);
119 static void modest_header_window_dispose (GObject *obj);
121 static void connect_signals (ModestHeaderWindow *self);
122 static void modest_header_window_disconnect_signals (ModestWindow *self);
124 static void setup_menu (ModestHeaderWindow *self);
125 static GtkWidget *create_empty_view (ModestWindow *self);
126 static GtkWidget *create_header_view (ModestWindow *progress_window,
129 static void update_view (ModestHeaderWindow *self,
130 TnyFolderChange *change);
131 static void set_contents_state (ModestHeaderWindow *window,
132 ContentsState state);
134 static void on_msg_count_changed (ModestHeaderView *header_view,
136 TnyFolderChange *change,
137 ModestHeaderWindow *header_window);
138 static void on_header_activated (ModestHeaderView *header_view,
141 ModestHeaderWindow *header_window);
142 static void on_updating_msg_list (ModestHeaderView *header_view,
145 static void set_delete_edit_mode (GtkButton *button,
146 ModestHeaderWindow *self);
147 static void set_moveto_edit_mode (GtkButton *button,
148 ModestHeaderWindow *self);
149 static gboolean on_expose_event(GtkTreeView *header_view,
150 GdkEventExpose *event,
152 static gboolean on_map_event (GtkWidget *widget,
155 static void on_vertical_movement (HildonPannableArea *area,
156 HildonMovementDirection direction,
157 gdouble x, gdouble y, gpointer user_data);
158 static void on_queue_changed (ModestMailOperationQueue *queue,
159 ModestMailOperation *mail_op,
160 ModestMailOperationQueueNotification type,
161 ModestHeaderWindow *self);
162 static void modest_header_window_pack_toolbar (ModestHildon2Window *self,
163 GtkPackType pack_type,
165 static void edit_mode_changed (ModestHeaderWindow *header_window,
168 ModestHeaderWindow *self);
169 static void on_progress_list_changed (ModestWindowMgr *mgr,
170 ModestHeaderWindow *self);
171 static void update_progress_hint (ModestHeaderWindow *self);
172 static void on_sort_column_changed (GtkTreeSortable *treesortable,
174 static void update_sort_button (ModestHeaderWindow *self);
175 static void on_horizontal_movement (HildonPannableArea *hildonpannable,
180 static void on_header_view_model_destroyed (gpointer user_data,
182 static gboolean on_key_press(GtkWidget *widget,
185 static void modest_header_window_show_more (GtkAction *action, ModestWindow *win);
188 static GtkWindowClass *parent_class = NULL;
190 #define EMPTYVIEW_XALIGN 0.5
191 #define EMPTYVIEW_YALIGN 0.5
192 #define EMPTYVIEW_XSPACE 1.0
193 #define EMPTYVIEW_YSPACE 1.0
197 /************************************************************************/
200 modest_header_window_get_type (void)
202 static GType my_type = 0;
204 static const GTypeInfo my_info = {
205 sizeof(ModestHeaderWindowClass),
206 NULL, /* base init */
207 NULL, /* base finalize */
208 (GClassInitFunc) modest_header_window_class_init,
209 NULL, /* class finalize */
210 NULL, /* class data */
211 sizeof(ModestHeaderWindow),
213 (GInstanceInitFunc) modest_header_window_init,
216 my_type = g_type_register_static (MODEST_TYPE_HILDON2_WINDOW,
217 "ModestHeaderWindow",
224 modest_header_window_class_init (ModestHeaderWindowClass *klass)
226 GObjectClass *gobject_class;
227 gobject_class = (GObjectClass*) klass;
228 ModestWindowClass *modest_window_class = (ModestWindowClass *) klass;
229 ModestHildon2WindowClass *modest_hildon2_window_class = (ModestHildon2WindowClass *) klass;
231 parent_class = g_type_class_peek_parent (klass);
232 gobject_class->finalize = modest_header_window_finalize;
233 gobject_class->dispose = modest_header_window_dispose;
235 g_type_class_add_private (gobject_class, sizeof(ModestHeaderWindowPrivate));
237 modest_window_class->disconnect_signals_func = modest_header_window_disconnect_signals;
238 modest_hildon2_window_class->pack_toolbar_func = modest_header_window_pack_toolbar;
242 modest_header_window_init (ModestHeaderWindow *obj)
244 ModestHeaderWindowPrivate *priv;
246 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(obj);
248 priv->sighandlers = NULL;
250 priv->header_view = NULL;
251 priv->empty_view = NULL;
252 priv->top_vbox = NULL;
253 priv->contents_view = NULL;
254 priv->contents_state = CONTENTS_STATE_NONE;
255 priv->updating_banner = NULL;
256 priv->updating_banner_timeout = 0;
257 priv->autoscroll = TRUE;
258 priv->progress_hint = FALSE;
259 priv->queue_change_handler = 0;
260 priv->sort_column_handler = 0;
261 priv->model_weak_ref = NULL;
262 priv->current_store_account = NULL;
263 priv->sort_button = NULL;
264 priv->new_message_button = NULL;
265 priv->show_more_button = NULL;
266 priv->show_more_button2 = NULL;
269 priv->notify_model = 0;
271 modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(),
273 "applications_email_headerview");
277 modest_header_window_dispose (GObject *obj)
279 ModestHeaderWindowPrivate *priv;
282 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(obj);
284 folder = modest_header_view_get_folder ((ModestHeaderView *) priv->header_view);
286 tny_folder_sync_async (folder, FALSE, NULL, NULL, NULL);
287 g_object_unref (folder);
290 G_OBJECT_CLASS(parent_class)->dispose (obj);
294 modest_header_window_finalize (GObject *obj)
296 ModestHeaderWindowPrivate *priv;
298 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(obj);
300 if (priv->model_weak_ref) {
301 g_object_weak_unref ((GObject *) priv->model_weak_ref,
302 on_header_view_model_destroyed,
304 if (g_signal_handler_is_connected (G_OBJECT (priv->model_weak_ref),
305 priv->sort_column_handler)) {
306 g_signal_handler_disconnect (G_OBJECT (priv->model_weak_ref),
307 priv->sort_column_handler);
309 on_header_view_model_destroyed (obj, (GObject *) priv->model_weak_ref);
312 modest_header_window_disconnect_signals (MODEST_WINDOW (obj));
314 g_object_unref (priv->header_view);
315 g_object_unref (priv->empty_view);
317 if (priv->current_store_account) {
318 g_free (priv->current_store_account);
319 priv->current_store_account = NULL;
322 if (priv->updating_banner_timeout > 0) {
323 g_source_remove (priv->updating_banner_timeout);
324 priv->updating_banner_timeout = 0;
326 if (priv->updating_banner) {
327 gtk_widget_destroy (priv->updating_banner);
328 priv->updating_banner = NULL;
331 G_OBJECT_CLASS(parent_class)->finalize (obj);
335 modest_header_window_disconnect_signals (ModestWindow *self)
337 ModestHeaderWindowPrivate *priv;
339 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
341 if (g_signal_handler_is_connected ((GObject*) priv->header_view, priv->notify_model)) {
342 g_signal_handler_disconnect ((GObject*) priv->header_view, priv->notify_model);
343 priv->notify_model = 0;
346 if (g_signal_handler_is_connected (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
347 priv->queue_change_handler)) {
348 g_signal_handler_disconnect (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
349 priv->queue_change_handler);
350 priv->queue_change_handler = 0;
353 if (priv->header_view) {
354 GtkTreeModel *sortable;
356 sortable = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->header_view));
358 if (g_signal_handler_is_connected (G_OBJECT (sortable),
359 priv->sort_column_handler)) {
360 g_signal_handler_disconnect (G_OBJECT (sortable),
361 priv->sort_column_handler);
362 priv->sort_column_handler = 0;
367 modest_signal_mgr_disconnect_all_and_destroy (priv->sighandlers);
368 priv->sighandlers = NULL;
373 connect_signals (ModestHeaderWindow *self)
375 ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
380 modest_signal_mgr_connect (priv->sighandlers,G_OBJECT(priv->header_view),
382 G_CALLBACK(on_msg_count_changed), self);
384 modest_signal_mgr_connect (priv->sighandlers, G_OBJECT (priv->header_view),
386 G_CALLBACK (on_header_activated), self);
388 modest_signal_mgr_connect (priv->sighandlers,
389 G_OBJECT (priv->header_view),
391 G_CALLBACK (on_updating_msg_list),
394 modest_signal_mgr_connect (priv->sighandlers,
395 G_OBJECT (priv->header_view),
397 G_CALLBACK (on_expose_event),
401 modest_signal_mgr_connect (priv->sighandlers,
404 G_CALLBACK (on_map_event),
408 modest_signal_mgr_connect (priv->sighandlers,
409 G_OBJECT (priv->contents_view),
411 G_CALLBACK (on_vertical_movement),
414 /* Mail Operation Queue */
415 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
416 G_OBJECT (modest_runtime_get_window_mgr ()),
417 "progress-list-changed",
418 G_CALLBACK (on_progress_list_changed), self);
420 modest_signal_mgr_connect (priv->sighandlers,
421 G_OBJECT (priv->new_message_button),
423 G_CALLBACK (modest_ui_actions_on_new_msg), self);
426 modest_signal_mgr_connect (priv->sighandlers,
427 G_OBJECT (priv->show_more_button),
429 G_CALLBACK (modest_header_window_show_more), self);
432 modest_signal_mgr_connect (priv->sighandlers,
433 G_OBJECT (priv->show_more_button2),
435 G_CALLBACK (modest_header_window_show_more), self);
437 /* Delete using horizontal gesture */
438 /* DISABLED because it's unreliabile */
441 modest_signal_mgr_connect (priv->sighandlers,
442 (GObject *) priv->contents_view,
443 "horizontal-movement",
444 G_CALLBACK (on_horizontal_movement),
449 g_signal_connect(G_OBJECT(self), "key-press-event",
450 G_CALLBACK(on_key_press), self);
454 folder_refreshed_cb (ModestMailOperation *mail_op,
458 /* Update the view (folder could be empty) */
459 update_view (MODEST_HEADER_WINDOW (user_data), NULL);
463 tap_and_hold_query_cb (GtkWidget *header_view,
467 ModestHeaderWindow *self;
468 ModestHeaderWindowPrivate *priv;
470 self = (ModestHeaderWindow *) user_data;
471 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
473 if (event->type == GDK_BUTTON_PRESS) {
476 priv->x_coord = ((GdkEventButton*)event)->x;
477 priv->y_coord = ((GdkEventButton*)event)->y;
479 /* Enable/Disable mark as (un)read */
480 header = modest_header_view_get_header_at_pos ((ModestHeaderView *) header_view,
481 priv->x_coord, priv->y_coord);
484 GtkWidget *mark_read_item, *mark_unread_item;
486 /* Show "mark as read" or "mark as unread" */
487 children = gtk_container_get_children (GTK_CONTAINER (priv->csm_menu));
488 mark_read_item = (GtkWidget *) g_list_nth_data (children, 1);
489 mark_unread_item = (GtkWidget *) g_list_nth_data (children, 2);
491 if (tny_header_get_flags (header) & TNY_HEADER_FLAG_SEEN) {
492 gtk_widget_show (mark_unread_item);
493 gtk_widget_hide (mark_read_item);
495 gtk_widget_show (mark_read_item);
496 gtk_widget_hide (mark_unread_item);
498 g_object_unref (header);
500 /* Do not show the CSM if there is no header below */
509 delete_header (GtkWindow *parent,
513 gchar *subject, *msg;
515 subject = tny_header_dup_subject (header);
517 subject = g_strdup (_("mail_va_no_subject"));
519 msg = g_strdup_printf (ngettext("emev_nc_delete_message", "emev_nc_delete_messages", 1),
523 /* Confirmation dialog */
524 response = modest_platform_run_confirmation_dialog (parent, msg);
527 if (response == GTK_RESPONSE_OK) {
528 ModestMailOperation *mail_op;
529 TnyList *header_list;
531 header_list = tny_simple_list_new ();
532 tny_list_append (header_list, (GObject *) header);
533 mail_op = modest_mail_operation_new ((GObject *) parent);
534 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
536 modest_mail_operation_remove_msgs (mail_op, header_list, FALSE);
537 g_object_unref (mail_op);
538 g_object_unref (header_list);
544 on_delete_csm_activated (GtkMenuItem *item,
548 ModestHeaderWindow *self;
549 ModestHeaderWindowPrivate *priv;
551 self = (ModestHeaderWindow *) user_data;
552 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
554 header = modest_header_view_get_header_at_pos ((ModestHeaderView *) priv->header_view,
555 priv->x_coord, priv->y_coord);
557 delete_header ((GtkWindow *) self, header);
558 g_object_unref (header);
563 on_mark_read_csm_activated (GtkMenuItem *item,
567 ModestHeaderWindow *self;
568 ModestHeaderWindowPrivate *priv;
570 self = (ModestHeaderWindow *) user_data;
571 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
573 header = modest_header_view_get_header_at_pos ((ModestHeaderView *) priv->header_view,
574 priv->x_coord, priv->y_coord);
577 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
578 g_object_unref (header);
583 on_mark_unread_csm_activated (GtkMenuItem *item,
587 ModestHeaderWindow *self;
588 ModestHeaderWindowPrivate *priv;
590 self = (ModestHeaderWindow *) user_data;
591 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
593 header = modest_header_view_get_header_at_pos ((ModestHeaderView *) priv->header_view,
594 priv->x_coord, priv->y_coord);
597 tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
598 g_object_unref (header);
603 on_header_view_model_destroyed (gpointer user_data,
606 ModestHeaderWindow *self;
607 ModestHeaderWindowPrivate *priv;
609 self = (ModestHeaderWindow *) user_data;
610 if (!GTK_IS_WIDGET (self))
613 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
614 priv->model_weak_ref = NULL;
616 priv->sort_column_handler = 0;
620 on_header_view_model_changed (GObject *gobject,
624 ModestHeaderWindow *self = (ModestHeaderWindow *) user_data;
625 ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
626 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (gobject));
628 if (priv->model_weak_ref ) {
629 g_object_weak_unref ((GObject *) priv->model_weak_ref,
630 on_header_view_model_destroyed,
632 if (g_signal_handler_is_connected (G_OBJECT (priv->model_weak_ref),
633 priv->sort_column_handler)) {
634 g_signal_handler_disconnect (G_OBJECT (priv->model_weak_ref),
635 priv->sort_column_handler);
637 on_header_view_model_destroyed (self, (GObject *) priv->model_weak_ref);
643 /* Connect the signal. Listen to object destruction to disconnect it */
644 priv->sort_column_handler = g_signal_connect ((GObject *) model,
645 "sort-column-changed",
646 G_CALLBACK (on_sort_column_changed),
648 priv->model_weak_ref = model;
649 g_object_weak_ref ((GObject *) model, on_header_view_model_destroyed, self);
653 create_header_view (ModestWindow *self, TnyFolder *folder)
655 GtkWidget *header_view;
656 GtkWidget *delete_item, *mark_read_item, *mark_unread_item;
657 ModestHeaderWindowPrivate *priv;
659 ModestProtocolType protocol_type;
660 gboolean limit_headers;
662 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
664 header_view = modest_header_view_new (NULL, MODEST_HEADER_VIEW_STYLE_TWOLINES);
666 account = modest_tny_folder_get_account (folder);
667 limit_headers = FALSE;
669 protocol_type = modest_tny_account_get_protocol_type (account);
670 if (modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
672 MODEST_PROTOCOL_REGISTRY_STORE_LIMIT_HEADER_WINDOW)) {
673 limit_headers = TRUE;
676 modest_header_view_set_show_latest (MODEST_HEADER_VIEW (header_view), limit_headers?SHOW_LATEST_SIZE:0);
678 priv->notify_model = g_signal_connect ((GObject*) header_view, "notify::model",
679 G_CALLBACK (on_header_view_model_changed), self);
681 modest_header_view_set_folder (MODEST_HEADER_VIEW (header_view), folder,
682 TRUE, self, folder_refreshed_cb, self);
683 modest_header_view_set_filter (MODEST_HEADER_VIEW (header_view),
684 MODEST_HEADER_VIEW_FILTER_NONE);
685 modest_widget_memory_restore (modest_runtime_get_conf (), G_OBJECT(header_view),
686 MODEST_CONF_HEADER_VIEW_KEY);
688 /* Create CSM menu */
689 priv->csm_menu = gtk_menu_new ();
690 delete_item = gtk_menu_item_new_with_label (_HL("wdgt_bd_delete"));
691 mark_read_item = gtk_menu_item_new_with_label (_("mcen_me_inbox_mark_as_read"));
692 mark_unread_item = gtk_menu_item_new_with_label (_("mcen_me_inbox_mark_as_unread"));
693 gtk_menu_shell_append (GTK_MENU_SHELL (priv->csm_menu), delete_item);
694 gtk_menu_shell_append (GTK_MENU_SHELL (priv->csm_menu), mark_read_item);
695 gtk_menu_shell_append (GTK_MENU_SHELL (priv->csm_menu), mark_unread_item);
696 hildon_gtk_widget_set_theme_size (delete_item, MODEST_EDITABLE_SIZE);
697 hildon_gtk_widget_set_theme_size (mark_unread_item, MODEST_EDITABLE_SIZE);
698 hildon_gtk_widget_set_theme_size (mark_read_item, MODEST_EDITABLE_SIZE);
699 gtk_widget_show_all (priv->csm_menu);
701 /* Connect signals */
702 g_signal_connect ((GObject *) header_view, "tap-and-hold-query",
703 G_CALLBACK (tap_and_hold_query_cb), self);
704 g_signal_connect ((GObject *) delete_item, "activate",
705 G_CALLBACK (on_delete_csm_activated), self);
706 g_signal_connect ((GObject *) mark_read_item, "activate",
707 G_CALLBACK (on_mark_read_csm_activated), self);
708 g_signal_connect ((GObject *) mark_unread_item, "activate",
709 G_CALLBACK (on_mark_unread_csm_activated), self);
711 /* Add tap&hold handling */
712 gtk_widget_tap_and_hold_setup (header_view, priv->csm_menu, NULL, 0);
718 create_empty_view (ModestWindow *self)
720 GtkWidget *viewport = NULL;
721 GtkWidget *label = NULL;
722 GtkWidget *align = NULL;
723 GtkWidget *vbox = NULL;
724 GtkWidget *hbox = NULL;
725 GtkWidget *button = NULL;
726 GdkPixbuf *new_message_pixbuf;
727 ModestHeaderWindowPrivate *priv;
729 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
731 vbox = gtk_vbox_new (0, FALSE);
733 align = gtk_alignment_new(EMPTYVIEW_XALIGN, EMPTYVIEW_YALIGN, EMPTYVIEW_XSPACE, EMPTYVIEW_YSPACE);
734 label = gtk_label_new (_("mcen_ia_nomessages"));
735 hildon_helper_set_logical_font (label, "LargeSystemFont");
736 gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
737 gtk_widget_show (label);
738 gtk_widget_show (align);
739 gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
740 gtk_container_add (GTK_CONTAINER (align), label);
741 gtk_box_pack_end (GTK_BOX (vbox), align, TRUE, TRUE, 0);
743 button = hildon_button_new (MODEST_EDITABLE_SIZE,
744 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
746 hildon_button_set_title (HILDON_BUTTON (button), _("mcen_ti_new_message"));
747 new_message_pixbuf = modest_platform_get_icon ("general_add", MODEST_ICON_SIZE_BIG);
748 hildon_button_set_image (HILDON_BUTTON (button),
749 gtk_image_new_from_pixbuf (new_message_pixbuf));
750 g_object_unref (new_message_pixbuf);
751 gtk_widget_show_all (button);
753 priv->show_more_button2 = hildon_button_new (MODEST_EDITABLE_SIZE, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
754 hildon_button_set_title (HILDON_BUTTON (priv->show_more_button2), _("mcen_va_more"));
755 hildon_button_set_alignment (HILDON_BUTTON (priv->show_more_button2), 0.5, 0.5, 1.0, 1.0);
756 hildon_button_set_title_alignment (HILDON_BUTTON (priv->show_more_button2), 0.5, 0.5);
757 hildon_button_set_value_alignment (HILDON_BUTTON (priv->show_more_button2), 0.5, 0.5);
758 gtk_widget_hide_all (priv->show_more_button2);
760 hbox = gtk_hbox_new (TRUE, 0);
761 gtk_widget_show (hbox);
762 gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
763 gtk_box_pack_start (GTK_BOX (hbox), priv->show_more_button2, TRUE, TRUE, 0);
765 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
767 gtk_widget_show (vbox);
769 g_signal_connect (button,
771 G_CALLBACK (modest_ui_actions_on_new_msg), self);
773 viewport = gtk_viewport_new ((GtkAdjustment *) gtk_adjustment_new (0, 0, 0, 0, 0, 0),
774 (GtkAdjustment *) gtk_adjustment_new (0, 0, 0, 0, 0, 0));
775 gtk_container_add (GTK_CONTAINER (viewport), vbox);
781 on_vertical_movement (HildonPannableArea *area,
782 HildonMovementDirection direction,
783 gdouble x, gdouble y, gpointer user_data)
785 ModestHeaderWindow *self = (ModestHeaderWindow *) user_data;
786 ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
788 priv->autoscroll = FALSE;
793 modest_header_window_new (TnyFolder *folder, const gchar *account_name, const gchar *mailbox)
795 ModestHeaderWindow *self = NULL;
796 ModestHeaderWindowPrivate *priv = NULL;
798 GdkPixbuf *window_icon;
799 ModestAccountMgr *mgr;
800 ModestAccountSettings *settings = NULL;
801 ModestServerAccountSettings *store_settings = NULL;
802 GtkWidget *action_area_box;
803 GdkPixbuf *new_message_pixbuf;
804 GtkWidget *alignment;
805 gchar *account_display_name = NULL;
807 self = MODEST_HEADER_WINDOW(g_object_new(MODEST_TYPE_HEADER_WINDOW, NULL));
808 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
810 priv->contents_view = hildon_pannable_area_new ();
811 alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
812 gtk_alignment_set_padding (GTK_ALIGNMENT (alignment),
813 HILDON_MARGIN_HALF, 0,
814 HILDON_MARGIN_DOUBLE, HILDON_MARGIN_DOUBLE);
816 /* We need to do this here to properly listen for mail
817 operations because create_header_view launches a mail
819 priv->queue_change_handler =
820 g_signal_connect (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
822 G_CALLBACK (on_queue_changed),
825 priv->header_view = create_header_view (MODEST_WINDOW (self), folder);
826 priv->empty_view = create_empty_view (MODEST_WINDOW (self));
828 /* Transform the floating reference in a "hard" reference. We
829 need to do this because the widgets could be added/removed
830 to containers many times so we always need to keep a
831 reference. It could happen also that some widget is never
832 added to any container */
833 g_object_ref_sink (priv->header_view);
834 g_object_ref_sink (priv->empty_view);
836 g_signal_connect (G_OBJECT (self), "edit-mode-changed",
837 G_CALLBACK (edit_mode_changed), (gpointer) self);
839 action_area_box = hildon_tree_view_get_action_area_box (GTK_TREE_VIEW (priv->header_view));
840 priv->new_message_button = hildon_button_new (MODEST_EDITABLE_SIZE, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
842 hildon_button_set_title (HILDON_BUTTON (priv->new_message_button), _("mcen_ti_new_message"));
843 new_message_pixbuf = modest_platform_get_icon ("general_add", MODEST_ICON_SIZE_BIG);
844 hildon_button_set_image (HILDON_BUTTON (priv->new_message_button), gtk_image_new_from_pixbuf (new_message_pixbuf));
845 g_object_unref (new_message_pixbuf);
847 priv->show_more_button = hildon_button_new (MODEST_EDITABLE_SIZE, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
848 hildon_button_set_title (HILDON_BUTTON (priv->show_more_button), _("mcen_va_more"));
849 hildon_button_set_alignment (HILDON_BUTTON (priv->show_more_button), 0.5, 0.5, 1.0, 1.0);
850 hildon_button_set_title_alignment (HILDON_BUTTON (priv->show_more_button), 0.5, 0.5);
851 hildon_button_set_value_alignment (HILDON_BUTTON (priv->show_more_button), 0.5, 0.5);
853 gtk_box_pack_start (GTK_BOX (action_area_box), priv->new_message_button, TRUE, TRUE, 0);
854 gtk_box_pack_start (GTK_BOX (action_area_box), priv->show_more_button, TRUE, TRUE, 0);
855 gtk_widget_show_all (priv->new_message_button);
856 gtk_widget_hide_all (priv->show_more_button);
857 hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->header_view), TRUE);
861 priv->top_vbox = gtk_vbox_new (FALSE, 0);
862 gtk_container_add (GTK_CONTAINER (alignment), priv->contents_view);
863 gtk_box_pack_end (GTK_BOX (priv->top_vbox), alignment, TRUE, TRUE, 0);
865 gtk_container_add (GTK_CONTAINER (self), priv->top_vbox);
867 gtk_widget_show (alignment);
868 gtk_widget_show (priv->contents_view);
869 gtk_widget_show (priv->top_vbox);
871 connect_signals (MODEST_HEADER_WINDOW (self));
873 update_view (self, NULL);
875 /* Get device name */
876 modest_maemo_utils_get_device_name ();
878 app = hildon_program_get_instance ();
879 hildon_program_add_window (app, HILDON_WINDOW (self));
881 /* Set window icon */
882 window_icon = modest_platform_get_icon (MODEST_APP_ICON, MODEST_ICON_SIZE_BIG);
884 gtk_window_set_icon (GTK_WINDOW (self), window_icon);
885 g_object_unref (window_icon);
888 /* Dont't restore settings here,
889 * because it requires a gtk_widget_show(),
890 * and we don't want to do that until later,
891 * so that the UI is not visible for non-menu D-Bus activation.
894 /* setup edit modes */
895 modest_hildon2_window_register_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_DELETE,
896 _("mcen_ti_edit_delete"), _HL("wdgt_bd_delete"),
897 GTK_TREE_VIEW (priv->header_view),
898 GTK_SELECTION_MULTIPLE,
899 EDIT_MODE_CALLBACK (modest_ui_actions_on_edit_mode_delete_message));
900 modest_hildon2_window_register_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_MOVE,
901 _("mcen_ti_edit_move"), _HL("wdgt_bd_move"),
902 GTK_TREE_VIEW (priv->header_view),
903 GTK_SELECTION_MULTIPLE,
904 EDIT_MODE_CALLBACK (modest_ui_actions_on_edit_mode_move_to));
907 modest_window_set_active_account (MODEST_WINDOW (self), account_name);
908 modest_window_set_active_mailbox (MODEST_WINDOW (self), mailbox);
909 mgr = modest_runtime_get_account_mgr ();
910 settings = modest_account_mgr_load_account_settings (mgr, account_name);
912 account_display_name = g_strdup (modest_account_settings_get_display_name (settings));
913 store_settings = modest_account_settings_get_store_settings (settings);
914 if (store_settings) {
915 priv->current_store_account =
916 g_strdup (modest_server_account_settings_get_account_name (store_settings));
917 g_object_unref (store_settings);
919 g_object_unref (settings);
921 /* Set window title */
922 if (TNY_IS_FOLDER (folder)) {
925 if (tny_folder_get_folder_type (folder) == TNY_FOLDER_TYPE_INBOX) {
926 const gchar *box_name;
928 if (box_name == NULL || box_name[0] == '\0') {
929 box_name = account_display_name;
931 folder_name = g_strconcat (_("mcen_me_folder_inbox"), " - ", box_name, NULL);
933 folder_name = modest_tny_folder_get_display_name (folder);
936 gtk_window_set_title (GTK_WINDOW (self), folder_name);
937 g_free (folder_name);
939 g_free (account_display_name);
942 update_progress_hint (self);
943 update_sort_button (self);
945 return MODEST_WINDOW(self);
949 modest_header_window_get_header_view (ModestHeaderWindow *self)
951 ModestHeaderWindowPrivate *priv = NULL;
953 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW(self), FALSE);
955 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
957 return MODEST_HEADER_VIEW (priv->header_view);
960 static void setup_menu (ModestHeaderWindow *self)
962 ModestHeaderWindowPrivate *priv;
964 g_return_if_fail (MODEST_IS_HEADER_WINDOW(self));
965 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
967 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_new_message"), "<Control>n",
968 APP_MENU_CALLBACK (modest_ui_actions_on_new_msg),
969 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_new_msg));
970 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self),
971 dngettext(GETTEXT_PACKAGE,
972 "mcen_me_move_message",
973 "mcen_me_move_messages",
976 APP_MENU_CALLBACK (set_moveto_edit_mode),
977 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_move_to));
978 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_delete_messages"), NULL,
979 APP_MENU_CALLBACK (set_delete_edit_mode),
980 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_delete));
981 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_folder_details"), NULL,
982 APP_MENU_CALLBACK (modest_ui_actions_on_details),
983 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_details));
984 priv->sort_button = hildon_button_new (MODEST_EDITABLE_SIZE,
985 HILDON_BUTTON_ARRANGEMENT_VERTICAL);
986 hildon_button_set_title (HILDON_BUTTON (priv->sort_button), _("mcen_me_sort"));
987 g_signal_connect_after (G_OBJECT (priv->sort_button), "clicked",
988 G_CALLBACK (modest_ui_actions_on_sort), (gpointer) self);
989 hildon_button_set_style(HILDON_BUTTON (priv->sort_button), HILDON_BUTTON_STYLE_PICKER);
990 hildon_button_set_title_alignment (HILDON_BUTTON (priv->sort_button), 0.5, 0.5);
991 hildon_button_set_value_alignment (HILDON_BUTTON (priv->sort_button), 0.5, 0.5);
992 modest_hildon2_window_add_button_to_menu (MODEST_HILDON2_WINDOW (self), GTK_BUTTON (priv->sort_button),
993 modest_ui_dimming_rules_on_sort);
994 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_sendandreceive"), NULL,
995 APP_MENU_CALLBACK (modest_ui_actions_on_send_receive),
996 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_send_receive));
997 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_outbox_cancelsend"), NULL,
998 APP_MENU_CALLBACK (modest_ui_actions_cancel_send),
999 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_cancel_sending_all));
1003 update_view (ModestHeaderWindow *self,
1004 TnyFolderChange *change)
1006 ModestHeaderWindowPrivate *priv = NULL;
1007 gboolean refilter = FALSE;
1008 gboolean folder_empty = FALSE;
1009 gboolean all_marked_as_deleted = FALSE;
1011 gchar *show_more_value;
1015 g_return_if_fail (MODEST_IS_HEADER_WINDOW(self));
1017 /* It could happen when some event is received and the window
1018 was previously closed */
1019 if (!MODEST_IS_HEADER_WINDOW (self))
1022 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1024 folder = modest_header_view_get_folder ((ModestHeaderView *) priv->header_view);
1028 if (change != NULL) {
1029 TnyFolderChangeChanged changed;
1031 changed = tny_folder_change_get_changed (change);
1032 /* If something changes */
1033 if ((changed) & TNY_FOLDER_CHANGE_CHANGED_ALL_COUNT)
1034 all_count = (guint) tny_folder_change_get_new_all_count (change);
1036 all_count = (guint) tny_folder_get_all_count (folder);
1038 folder_empty = (all_count == 0);
1039 if ((changed) & TNY_FOLDER_CHANGE_CHANGED_EXPUNGED_HEADERS)
1042 all_count = (guint) tny_folder_get_all_count (folder);
1043 folder_empty = (all_count == 0);
1045 g_object_unref (folder);
1047 /* Check if all messages are marked to be deleted */
1048 all_marked_as_deleted = modest_header_view_is_empty (MODEST_HEADER_VIEW (priv->header_view));
1049 folder_empty = folder_empty || all_marked_as_deleted;
1051 /* Set style of headers view */
1052 set_contents_state (self, folder_empty?CONTENTS_STATE_EMPTY:CONTENTS_STATE_HEADERS);
1055 modest_header_view_refilter (MODEST_HEADER_VIEW (priv->header_view));
1057 visible = modest_header_view_get_show_latest (MODEST_HEADER_VIEW (priv->header_view));
1059 if (visible > 0 && all_count > 0 && visible < all_count && folder_empty) {
1060 modest_header_view_set_show_latest (MODEST_HEADER_VIEW (priv->header_view), visible + SHOW_LATEST_SIZE);
1063 if (visible > all_count)
1064 visible = all_count;
1065 if (visible == 0 || visible == all_count) {
1066 gtk_widget_hide_all (priv->show_more_button);
1067 gtk_widget_hide_all (priv->show_more_button2);
1069 gtk_widget_show_all (priv->show_more_button);
1070 gtk_widget_show_all (priv->show_more_button2);
1072 show_more_value = g_strdup_printf (_("mcen_va_more_toview"), visible, all_count);
1074 hildon_button_set_value (HILDON_BUTTON (priv->show_more_button),
1076 hildon_button_set_value (HILDON_BUTTON (priv->show_more_button2),
1081 set_contents_state (ModestHeaderWindow *self,
1082 ContentsState state)
1084 ModestHeaderWindowPrivate *priv = NULL;
1086 g_return_if_fail (MODEST_IS_HEADER_WINDOW(self));
1087 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1089 if (priv->contents_state == state)
1092 /* Remove from container the old content */
1093 switch (priv->contents_state) {
1094 case CONTENTS_STATE_EMPTY:
1095 gtk_container_remove (GTK_CONTAINER (priv->contents_view), priv->empty_view);
1097 case CONTENTS_STATE_HEADERS:
1098 gtk_container_remove (GTK_CONTAINER (priv->contents_view), priv->header_view);
1100 case CONTENTS_STATE_NONE:
1104 /* Add the new content */
1106 case CONTENTS_STATE_EMPTY:
1107 gtk_container_add (GTK_CONTAINER (priv->contents_view), priv->empty_view);
1108 gtk_widget_show (priv->empty_view);
1110 case CONTENTS_STATE_HEADERS:
1111 gtk_container_add (GTK_CONTAINER (priv->contents_view), priv->header_view);
1112 gtk_widget_show (priv->header_view);
1114 case CONTENTS_STATE_NONE:
1117 priv->contents_state = state;
1121 on_msg_count_changed (ModestHeaderView *header_view,
1123 TnyFolderChange *change,
1124 ModestHeaderWindow *header_window)
1126 g_return_if_fail (MODEST_IS_HEADER_WINDOW (header_window));
1128 update_view (MODEST_HEADER_WINDOW (header_window), change);
1132 on_header_activated (ModestHeaderView *header_view,
1135 ModestHeaderWindow *header_window)
1137 modest_ui_actions_on_header_activated (header_view, header, path, MODEST_WINDOW (header_window));
1141 updating_banner_destroyed (gpointer data,
1142 GObject *where_the_object_was)
1144 ModestHeaderWindowPrivate *priv = NULL;
1146 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (data);
1148 priv->updating_banner = NULL;
1152 show_updating_banner (gpointer user_data)
1154 ModestHeaderWindowPrivate *priv = NULL;
1156 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (user_data);
1158 if (priv->updating_banner == NULL) {
1160 /* We're outside the main lock */
1161 gdk_threads_enter ();
1162 priv->updating_banner =
1163 modest_platform_animation_banner (GTK_WIDGET (user_data), NULL,
1164 _CS ("ckdg_pb_updating"));
1166 /* We need this because banners in Maemo could be
1167 destroyed by dialogs so we need to properly update
1168 our reference to it */
1169 g_object_weak_ref (G_OBJECT (priv->updating_banner),
1170 updating_banner_destroyed,
1172 gdk_threads_leave ();
1175 /* Remove timeout */
1176 priv->updating_banner_timeout = 0;
1181 * We use this function to show/hide a progress banner showing
1182 * "Updating" while the header view is being filled. We're not showing
1183 * it unless the update takes more than 2 seconds
1185 * If starting = TRUE then the refresh is starting, otherwise it means
1186 * that is has just finished
1189 on_updating_msg_list (ModestHeaderView *header_view,
1193 ModestHeaderWindowPrivate *priv = NULL;
1195 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (user_data);
1197 /* Remove old timeout */
1198 if (priv->updating_banner_timeout > 0) {
1199 g_source_remove (priv->updating_banner_timeout);
1200 priv->updating_banner_timeout = 0;
1203 /* Create a new timeout */
1205 priv->updating_banner_timeout =
1206 g_timeout_add (2000, show_updating_banner, user_data);
1208 /* Remove the banner if exists */
1209 if (priv->updating_banner) {
1210 gtk_widget_destroy (priv->updating_banner);
1211 priv->updating_banner = NULL;
1217 set_delete_edit_mode (GtkButton *button,
1218 ModestHeaderWindow *self)
1220 modest_hildon2_window_set_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_DELETE);
1224 set_moveto_edit_mode (GtkButton *button,
1225 ModestHeaderWindow *self)
1227 modest_hildon2_window_set_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_MOVE);
1231 on_expose_event(GtkTreeView *header_view,
1232 GdkEventExpose *event,
1235 ModestHeaderWindow *self = (ModestHeaderWindow *) user_data;
1236 ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1238 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW (self), FALSE);
1240 if (priv->autoscroll)
1241 hildon_pannable_area_jump_to (HILDON_PANNABLE_AREA (priv->contents_view), 0.0, 0.0);
1247 on_map_event(GtkWidget *widget,
1251 ModestHeaderWindow *self = (ModestHeaderWindow *) user_data;
1252 ModestHeaderWindowPrivate *priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1254 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW (self), FALSE);
1256 if (priv->progress_hint) {
1257 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
1263 on_progress_list_changed (ModestWindowMgr *mgr,
1264 ModestHeaderWindow *self)
1266 update_progress_hint (self);
1270 has_active_operations (ModestHeaderWindow *self)
1272 GSList *operations = NULL, *node;
1273 ModestMailOperationQueue *queue;
1274 gboolean has_active = FALSE;
1276 queue = modest_runtime_get_mail_operation_queue ();
1277 operations = modest_mail_operation_queue_get_by_source (queue, G_OBJECT (self));
1279 for (node = operations; node != NULL; node = g_slist_next (node)) {
1280 if (!modest_mail_operation_is_finished (MODEST_MAIL_OPERATION (node->data))) {
1287 g_slist_foreach (operations, (GFunc) g_object_unref, NULL);
1288 g_slist_free (operations);
1295 update_progress_hint (ModestHeaderWindow *self)
1297 ModestHeaderWindowPrivate *priv;
1299 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1301 priv->progress_hint = FALSE;
1303 if (has_active_operations (self)) {
1304 priv->progress_hint = TRUE;
1306 priv->progress_hint = FALSE;
1309 if (!priv->progress_hint && priv->current_store_account) {
1310 priv->progress_hint =
1311 modest_window_mgr_has_progress_operation_on_account (modest_runtime_get_window_mgr (),
1312 priv->current_store_account);
1315 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
1317 if (GTK_WIDGET_VISIBLE (self)) {
1318 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), priv->progress_hint?1:0);
1323 modest_header_window_toolbar_on_transfer_mode (ModestHeaderWindow *self)
1325 ModestHeaderWindowPrivate *priv= NULL;
1327 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW (self), FALSE);
1328 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1330 return priv->progress_hint;
1334 modest_header_window_transfer_mode_enabled (ModestHeaderWindow *self)
1336 ModestHeaderWindowPrivate *priv;
1338 g_return_val_if_fail (MODEST_IS_HEADER_WINDOW (self), FALSE);
1339 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(self);
1341 return priv->progress_hint;
1345 on_mail_operation_started (ModestMailOperation *mail_op,
1348 ModestHeaderWindow *self;
1349 ModestMailOperationTypeOperation op_type;
1350 GObject *source = NULL;
1352 self = MODEST_HEADER_WINDOW (user_data);
1353 op_type = modest_mail_operation_get_type_operation (mail_op);
1354 source = modest_mail_operation_get_source(mail_op);
1355 if (G_OBJECT (self) == source) {
1356 update_progress_hint (self);
1358 g_object_unref (source);
1362 on_mail_operation_finished (ModestMailOperation *mail_op,
1365 ModestHeaderWindow *self;
1367 self = MODEST_HEADER_WINDOW (user_data);
1369 /* Don't disable the progress hint if there are more pending
1370 operations from this window */
1371 update_progress_hint (self);
1373 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
1377 on_queue_changed (ModestMailOperationQueue *queue,
1378 ModestMailOperation *mail_op,
1379 ModestMailOperationQueueNotification type,
1380 ModestHeaderWindow *self)
1382 ModestHeaderWindowPrivate *priv;
1384 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1386 /* If this operations was created by another window, do nothing */
1387 if (!modest_mail_operation_is_mine (mail_op, G_OBJECT(self)))
1390 if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_ADDED) {
1391 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
1393 "operation-started",
1394 G_CALLBACK (on_mail_operation_started),
1396 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
1398 "operation-finished",
1399 G_CALLBACK (on_mail_operation_finished),
1401 } else if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED) {
1402 priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
1404 "operation-started");
1405 priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
1407 "operation-finished");
1412 modest_header_window_pack_toolbar (ModestHildon2Window *self,
1413 GtkPackType pack_type,
1416 ModestHeaderWindowPrivate *priv;
1418 g_return_if_fail (MODEST_IS_HEADER_WINDOW (self));
1419 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1421 if (pack_type == GTK_PACK_START) {
1422 gtk_box_pack_start (GTK_BOX (priv->top_vbox), toolbar, FALSE, FALSE, 0);
1424 gtk_box_pack_end (GTK_BOX (priv->top_vbox), toolbar, FALSE, FALSE, 0);
1429 edit_mode_changed (ModestHeaderWindow *header_window,
1432 ModestHeaderWindow *self)
1434 ModestHeaderWindowPrivate *priv;
1435 ModestHeaderViewFilter filter = MODEST_HEADER_VIEW_FILTER_NONE;
1437 g_return_if_fail (MODEST_IS_HEADER_WINDOW (self));
1438 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1440 switch (edit_mode_id) {
1441 case EDIT_MODE_COMMAND_MOVE:
1442 filter = MODEST_HEADER_VIEW_FILTER_MOVEABLE;
1444 case EDIT_MODE_COMMAND_DELETE:
1445 filter = MODEST_HEADER_VIEW_FILTER_DELETABLE;
1447 case MODEST_HILDON2_WINDOW_EDIT_MODE_NONE:
1448 filter = MODEST_HEADER_VIEW_FILTER_NONE;
1452 hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->header_view), !enabled);
1454 modest_header_view_set_filter (MODEST_HEADER_VIEW (priv->header_view),
1457 GtkTreeSelection *sel;
1459 /* Unselect all. This will prevent us from keeping a
1460 reference to a TnyObject that we don't want to
1462 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->header_view));
1463 gtk_tree_selection_unselect_all (sel);
1465 modest_header_view_unset_filter (MODEST_HEADER_VIEW (priv->header_view),
1471 on_sort_column_changed (GtkTreeSortable *treesortable,
1474 update_sort_button (MODEST_HEADER_WINDOW (user_data));
1478 update_sort_button (ModestHeaderWindow *self)
1480 ModestHeaderWindowPrivate *priv;
1481 GtkTreeSortable *sortable;
1482 gint current_sort_colid = -1;
1483 GtkSortType current_sort_type;
1484 const gchar *value = NULL;
1486 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1488 /* This could happen as the first time the model is set the
1489 header_view is still not assigned to priv->header_view */
1490 if (!priv->header_view)
1493 sortable = GTK_TREE_SORTABLE (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->header_view)));
1495 if (!gtk_tree_sortable_get_sort_column_id (sortable,
1496 ¤t_sort_colid, ¤t_sort_type)) {
1497 value = _("mcen_li_sort_sender_date_newest");
1499 switch (current_sort_colid) {
1500 case TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN:
1503 cols = modest_header_view_get_columns (MODEST_HEADER_VIEW (priv->header_view));
1505 gpointer flags_sort_type_pointer;
1506 flags_sort_type_pointer = g_object_get_data (G_OBJECT (cols->data),
1507 MODEST_HEADER_VIEW_FLAG_SORT);
1508 if (GPOINTER_TO_INT (flags_sort_type_pointer) == TNY_HEADER_FLAG_PRIORITY_MASK)
1509 value = _("mcen_li_sort_priority");
1511 value = _("mcen_li_sort_attachment");
1516 case TNY_GTK_HEADER_LIST_MODEL_TO_COLUMN:
1517 case TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN:
1518 if (current_sort_type == GTK_SORT_ASCENDING)
1519 value = _("mcen_li_sort_sender_recipient_az");
1521 value = _("mcen_li_sort_sender_recipient_za");
1523 case TNY_GTK_HEADER_LIST_MODEL_DATE_SENT_TIME_T_COLUMN:
1524 case TNY_GTK_HEADER_LIST_MODEL_DATE_RECEIVED_TIME_T_COLUMN:
1525 if (current_sort_type == GTK_SORT_ASCENDING)
1526 value = _("mcen_li_sort_date_oldest");
1528 value = _("mcen_li_sort_date_newest");
1530 case TNY_GTK_HEADER_LIST_MODEL_SUBJECT_COLUMN:
1531 if (current_sort_type == GTK_SORT_ASCENDING)
1532 value = _("mcen_li_sort_subject_az");
1534 value = _("mcen_li_sort_subject_za");
1536 case TNY_GTK_HEADER_LIST_MODEL_MESSAGE_SIZE_COLUMN:
1537 if (current_sort_type == GTK_SORT_ASCENDING)
1538 value = _("mcen_li_sort_size_smallest");
1540 value = _("mcen_li_sort_size_largest");
1545 hildon_button_set_value (HILDON_BUTTON (priv->sort_button), value?value:"");
1549 on_horizontal_movement (HildonPannableArea *hildonpannable,
1555 ModestHeaderWindowPrivate *priv;
1556 gint dest_x, dest_y;
1559 /* Ignore right to left movement */
1560 if (direction == HILDON_MOVEMENT_LEFT)
1563 /* Get the header to delete */
1564 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (user_data);
1566 /* Get tree view coordinates */
1567 if (!gtk_widget_translate_coordinates ((GtkWidget *) hildonpannable,
1575 header = modest_header_view_get_header_at_pos ((ModestHeaderView *) priv->header_view,
1578 delete_header ((GtkWindow *) user_data, header);
1579 g_object_unref (header);
1585 on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
1587 ModestHeaderWindowPrivate *priv;
1588 HildonPannableArea *pannable;
1589 /* FIXME: set scroll_speed depends on for how long the key was pressed */
1590 gint scroll_speed = 3;
1592 if (event->type == GDK_KEY_RELEASE)
1595 priv = MODEST_HEADER_WINDOW_GET_PRIVATE(user_data);
1597 pannable = HILDON_PANNABLE_AREA (priv->contents_view);
1599 switch (event->keyval) {
1602 priv->autoscroll = FALSE;
1603 modest_maemo_utils_scroll_pannable(pannable, 0, -scroll_speed);
1607 priv->autoscroll = FALSE;
1608 modest_maemo_utils_scroll_pannable(pannable, 0, scroll_speed);
1616 modest_header_window_show_more (GtkAction *action, ModestWindow *win)
1618 ModestHeaderWindow *self;
1619 ModestHeaderWindowPrivate *priv = NULL;
1621 self = MODEST_HEADER_WINDOW (win);
1622 priv = MODEST_HEADER_WINDOW_GET_PRIVATE (self);
1623 if (!priv->header_view)
1626 if (modest_header_view_get_not_latest (MODEST_HEADER_VIEW (priv->header_view)) > 0) {
1627 modest_header_view_set_show_latest (MODEST_HEADER_VIEW (priv->header_view),
1628 modest_header_view_get_show_latest (MODEST_HEADER_VIEW (priv->header_view)) +
1630 update_view (self, NULL);