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-folder-window.h>
31 #include <modest-scrollable.h>
32 #include <modest-window-mgr.h>
33 #include <modest-signal-mgr.h>
34 #include <modest-runtime.h>
35 #include <modest-platform.h>
36 #include <modest-icon-names.h>
37 #include <modest-ui-constants.h>
38 #include <modest-account-mgr.h>
39 #include <modest-account-mgr-helpers.h>
40 #include <modest-defs.h>
41 #include <modest-ui-actions.h>
42 #include <modest-window.h>
43 #ifdef MODEST_TOOLKIT_HILDON2
44 #include <modest-maemo-utils.h>
45 #include <hildon/hildon.h>
47 #include <tny-account-store-view.h>
48 #include <tny-gtk-folder-list-store.h>
49 #include <modest-header-window.h>
50 #include <modest-ui-dimming-rules.h>
51 #include <modest-ui-dimming-manager.h>
52 #include <modest-window-priv.h>
53 #include "modest-text-utils.h"
54 #include "modest-tny-account.h"
55 #include "modest-account-protocol.h"
56 #include <gdk/gdkkeysyms.h>
58 #ifdef MODEST_TOOLKIT_HILDON2
60 EDIT_MODE_COMMAND_MOVE = 1,
61 EDIT_MODE_COMMAND_DELETE = 2,
62 EDIT_MODE_COMMAND_RENAME = 3,
66 /* 'private'/'protected' functions */
67 static void modest_folder_window_class_init (ModestFolderWindowClass *klass);
68 static void modest_folder_window_init (ModestFolderWindow *obj);
69 static void modest_folder_window_finalize (GObject *obj);
70 static void modest_folder_window_dispose (GObject *obj);
72 static void connect_signals (ModestFolderWindow *self);
73 static void modest_folder_window_disconnect_signals (ModestWindow *self);
75 static void on_folder_activated (ModestFolderView *folder_view,
78 static void setup_menu (ModestFolderWindow *self);
80 #ifdef MODEST_TOOLKIT_HILDON2
81 static void set_delete_edit_mode (GtkButton *button,
82 ModestFolderWindow *self);
83 static void set_moveto_edit_mode (GtkButton *button,
84 ModestFolderWindow *self);
85 static void set_rename_edit_mode (GtkButton *button,
86 ModestFolderWindow *self);
88 static void modest_folder_window_pack_toolbar (ModestWindow *self,
89 GtkPackType pack_type,
91 #ifdef MODEST_TOOLKIT_HILDON2
92 static void edit_mode_changed (ModestFolderWindow *folder_window,
95 ModestFolderWindow *self);
97 static void on_progress_list_changed (ModestWindowMgr *mgr,
98 ModestFolderWindow *self);
99 static gboolean on_map_event (GtkWidget *widget,
102 static void update_progress_hint (ModestFolderWindow *self);
103 static void on_queue_changed (ModestMailOperationQueue *queue,
104 ModestMailOperation *mail_op,
105 ModestMailOperationQueueNotification type,
106 ModestFolderWindow *self);
107 static void on_activity_changed (ModestFolderView *view,
109 ModestFolderWindow *folder_window);
110 static void on_visible_account_changed (ModestFolderView *folder_view,
111 const gchar *account_id,
113 static void on_account_changed (TnyAccountStore *account_store,
116 #ifdef MODEST_TOOLKIT_HILDON2
117 static gboolean on_key_press(GtkWidget *widget,
122 typedef struct _ModestFolderWindowPrivate ModestFolderWindowPrivate;
123 struct _ModestFolderWindowPrivate {
125 GtkWidget *folder_view;
127 #ifdef MODEST_TOOLKIT_HILDON2
128 GtkWidget *new_message_button;
134 gchar *current_store_account;
135 gboolean progress_hint;
136 guint queue_change_handler;
138 #define MODEST_FOLDER_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
139 MODEST_TYPE_FOLDER_WINDOW, \
140 ModestFolderWindowPrivate))
143 static GtkWindowClass *parent_class = NULL;
145 /************************************************************************/
148 modest_folder_window_get_type (void)
150 static GType my_type = 0;
152 static const GTypeInfo my_info = {
153 sizeof(ModestFolderWindowClass),
154 NULL, /* base init */
155 NULL, /* base finalize */
156 (GClassInitFunc) modest_folder_window_class_init,
157 NULL, /* class finalize */
158 NULL, /* class data */
159 sizeof(ModestFolderWindow),
161 (GInstanceInitFunc) modest_folder_window_init,
164 my_type = g_type_register_static (
165 #ifdef MODEST_TOOLKIT_HILDON2
166 MODEST_TYPE_HILDON2_WINDOW,
168 MODEST_TYPE_SHELL_WINDOW,
170 "ModestFolderWindow",
177 modest_folder_window_class_init (ModestFolderWindowClass *klass)
179 GObjectClass *gobject_class;
180 gobject_class = (GObjectClass*) klass;
181 ModestWindowClass *modest_window_class = (ModestWindowClass *) klass;
183 parent_class = g_type_class_peek_parent (klass);
184 gobject_class->finalize = modest_folder_window_finalize;
185 gobject_class->dispose = modest_folder_window_dispose;
187 g_type_class_add_private (gobject_class, sizeof(ModestFolderWindowPrivate));
189 modest_window_class->disconnect_signals_func = modest_folder_window_disconnect_signals;
190 modest_window_class->pack_toolbar_func = modest_folder_window_pack_toolbar;
194 modest_folder_window_init (ModestFolderWindow *obj)
196 ModestFolderWindowPrivate *priv;
198 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(obj);
200 priv->sighandlers = NULL;
202 priv->folder_view = NULL;
204 priv->top_vbox = NULL;
206 priv->progress_hint = FALSE;
207 priv->current_store_account = NULL;
208 priv->queue_change_handler = 0;
212 modest_folder_window_finalize (GObject *obj)
214 ModestFolderWindowPrivate *priv;
216 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(obj);
218 if (priv->current_store_account) {
219 g_free (priv->current_store_account);
220 priv->current_store_account = NULL;
223 /* Sanity check: shouldn't be needed, the window mgr should
224 call this function before */
225 modest_folder_window_disconnect_signals (MODEST_WINDOW (obj));
227 G_OBJECT_CLASS(parent_class)->finalize (obj);
231 modest_folder_window_dispose (GObject *obj)
233 ModestFolderWindowPrivate *priv;
235 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(obj);
236 if (priv->folder_view) {
239 list = modest_folder_view_get_model_tny_list (MODEST_FOLDER_VIEW (priv->folder_view));
244 iter = tny_list_create_iterator (list);
245 while (!tny_iterator_is_done (iter)) {
246 GObject *item = tny_iterator_get_current (iter);
248 if (TNY_IS_ACCOUNT (item)) {
249 if (TNY_IS_FOLDER_STORE (item) &&
250 modest_tny_folder_store_is_remote (TNY_FOLDER_STORE (item))) {
251 tny_account_cancel (TNY_ACCOUNT (item));
254 g_object_unref (item);
255 tny_iterator_next (iter);
257 g_object_unref (iter);
260 if (list && TNY_IS_GTK_FOLDER_LIST_STORE (list)) {
261 g_object_run_dispose (G_OBJECT (list));
264 g_object_unref (list);
265 priv->folder_view = NULL;
268 G_OBJECT_CLASS(parent_class)->dispose (obj);
272 modest_folder_window_disconnect_signals (ModestWindow *self)
274 ModestFolderWindowPrivate *priv;
275 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(self);
277 if (g_signal_handler_is_connected (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
278 priv->queue_change_handler))
279 g_signal_handler_disconnect (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
280 priv->queue_change_handler);
282 modest_signal_mgr_disconnect_all_and_destroy (priv->sighandlers);
283 priv->sighandlers = NULL;
287 connect_signals (ModestFolderWindow *self)
289 ModestFolderWindowPrivate *priv;
291 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(self);
294 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
295 G_OBJECT (priv->folder_view), "folder-activated",
296 G_CALLBACK (on_folder_activated), self);
298 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
299 G_OBJECT (modest_runtime_get_window_mgr ()),
300 "progress-list-changed",
301 G_CALLBACK (on_progress_list_changed), self);
303 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
304 G_OBJECT (priv->folder_view),
305 "visible-account-changed",
306 G_CALLBACK (on_visible_account_changed), self);
308 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
309 G_OBJECT (priv->folder_view),
311 G_CALLBACK (on_activity_changed), self);
313 #ifdef MODEST_TOOLKIT_HILDON2
314 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
315 G_OBJECT (priv->new_message_button),
317 G_CALLBACK (modest_ui_actions_on_new_msg), self);
320 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
321 G_OBJECT (modest_runtime_get_account_store()),
323 G_CALLBACK (on_account_changed), self);
326 #ifdef MODEST_TOOLKIT_HILDON2
327 g_signal_connect(G_OBJECT(self), "key-press-event",
328 G_CALLBACK(on_key_press), self);
333 modest_folder_window_new (TnyFolderStoreQuery *query)
335 ModestFolderWindow *self = NULL;
336 ModestFolderWindowPrivate *priv = NULL;
337 GdkPixbuf *window_icon;
338 GtkWidget *scrollable;
339 GtkWidget *top_alignment;
340 #ifdef MODEST_TOOLKIT_HILDON2
341 GtkWidget *live_search;
344 self = MODEST_FOLDER_WINDOW(g_object_new(MODEST_TYPE_FOLDER_WINDOW, NULL));
345 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(self);
347 scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
349 priv->queue_change_handler =
350 g_signal_connect (G_OBJECT (modest_runtime_get_mail_operation_queue ()),
352 G_CALLBACK (on_queue_changed),
355 priv->folder_view = modest_platform_create_folder_view (query);
356 #ifdef MODEST_TOOLKIT_HILDON2
357 live_search = modest_folder_view_setup_live_search (MODEST_FOLDER_VIEW (priv->folder_view));
358 hildon_live_search_widget_hook (HILDON_LIVE_SEARCH (live_search), GTK_WIDGET (self), priv->folder_view);
360 modest_folder_view_set_cell_style (MODEST_FOLDER_VIEW (priv->folder_view),
361 MODEST_FOLDER_VIEW_CELL_STYLE_COMPACT);
362 modest_folder_view_set_filter (MODEST_FOLDER_VIEW (priv->folder_view),
363 MODEST_FOLDER_VIEW_FILTER_HIDE_ACCOUNTS);
365 #ifdef MODEST_TOOLKIT_HILDON2
366 GtkWidget *action_area_box;
367 GdkPixbuf *new_message_pixbuf;
368 g_signal_connect (G_OBJECT (self), "edit-mode-changed",
369 G_CALLBACK (edit_mode_changed), (gpointer) self);
371 action_area_box = hildon_tree_view_get_action_area_box (GTK_TREE_VIEW (priv->folder_view));
372 priv->new_message_button = hildon_button_new (MODEST_EDITABLE_SIZE, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
374 hildon_button_set_title (HILDON_BUTTON (priv->new_message_button), _("mcen_ti_new_message"));
375 new_message_pixbuf = modest_platform_get_icon ("general_add", MODEST_ICON_SIZE_BIG);
376 hildon_button_set_image (HILDON_BUTTON (priv->new_message_button), gtk_image_new_from_pixbuf (new_message_pixbuf));
377 g_object_unref (new_message_pixbuf);
379 gtk_box_pack_start (GTK_BOX (action_area_box), priv->new_message_button, TRUE, TRUE, 0);
380 gtk_widget_show_all (priv->new_message_button);
381 hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->folder_view), TRUE);
386 /* Set account store */
387 tny_account_store_view_set_account_store (TNY_ACCOUNT_STORE_VIEW (priv->folder_view),
388 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
390 priv->top_vbox = gtk_vbox_new (0, FALSE);
391 top_alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
392 gtk_alignment_set_padding (GTK_ALIGNMENT (top_alignment),
393 MODEST_MARGIN_HALF, 0,
394 MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
396 gtk_container_add (GTK_CONTAINER (scrollable), priv->folder_view);
397 gtk_container_add (GTK_CONTAINER (top_alignment), scrollable);
398 #ifdef MODEST_TOOLKIT_HILDON2
399 gtk_box_pack_end (GTK_BOX (priv->top_vbox), live_search, FALSE, FALSE, 0);
401 gtk_box_pack_end (GTK_BOX (priv->top_vbox), top_alignment, TRUE, TRUE, 0);
402 gtk_container_add (GTK_CONTAINER (self), priv->top_vbox);
404 gtk_widget_show (priv->folder_view);
405 gtk_widget_show (scrollable);
406 gtk_widget_show (priv->top_vbox);
407 gtk_widget_show (top_alignment);
409 connect_signals (MODEST_FOLDER_WINDOW (self));
411 /* Get device name */
412 #ifdef MODEST_TOOLKIT_HILDON2
414 modest_maemo_utils_get_device_name ();
416 app = hildon_program_get_instance ();
417 hildon_program_add_window (app, HILDON_WINDOW (self));
420 /* Set window icon */
421 window_icon = modest_platform_get_icon (MODEST_APP_ICON, MODEST_ICON_SIZE_BIG);
423 GtkWindow *toplevel = (GtkWindow *) gtk_widget_get_toplevel ((GtkWidget *) self);
424 gtk_window_set_icon (toplevel, window_icon);
425 g_object_unref (window_icon);
428 /* Dont't restore settings here,
429 * because it requires a gtk_widget_show(),
430 * and we don't want to do that until later,
431 * so that the UI is not visible for non-menu D-Bus activation.
434 /* Register edit modes */
435 #ifdef MODEST_TOOLKIT_HILDON2
436 modest_hildon2_window_register_edit_mode (MODEST_HILDON2_WINDOW (self),
437 EDIT_MODE_COMMAND_DELETE,
438 _("mcen_ti_edit_folder_delete"),
440 GTK_TREE_VIEW (priv->folder_view),
441 GTK_SELECTION_SINGLE,
442 EDIT_MODE_CALLBACK (modest_ui_actions_on_edit_mode_delete_folder));
443 modest_hildon2_window_register_edit_mode (MODEST_HILDON2_WINDOW (self),
444 EDIT_MODE_COMMAND_MOVE,
445 _("mcen_ti_edit_move_folder"),
447 GTK_TREE_VIEW (priv->folder_view),
448 GTK_SELECTION_SINGLE,
449 EDIT_MODE_CALLBACK (modest_ui_actions_on_edit_mode_move_to));
450 modest_hildon2_window_register_edit_mode (MODEST_HILDON2_WINDOW (self),
451 EDIT_MODE_COMMAND_RENAME,
452 _("mcen_ti_edit_rename_folder"),
454 GTK_TREE_VIEW (priv->folder_view),
455 GTK_SELECTION_SINGLE,
456 EDIT_MODE_CALLBACK (modest_ui_actions_on_edit_mode_rename_folder));
459 g_signal_connect (G_OBJECT (self), "map-event",
460 G_CALLBACK (on_map_event),
462 update_progress_hint (self);
464 #ifdef MODEST_TOOLKIT_HILDON2
465 GtkAccelGroup *accel_group;
467 GdkModifierType accel_mods;
469 accel_group = gtk_accel_group_new ();
470 gtk_accelerator_parse ("<Control>n", &accel_key, &accel_mods);
471 gtk_widget_add_accelerator (priv->new_message_button, "clicked", accel_group,
472 accel_key, accel_mods, 0);
473 gtk_window_add_accel_group (GTK_WINDOW (self), accel_group);
476 return MODEST_WINDOW(self);
480 modest_folder_window_get_folder_view (ModestFolderWindow *self)
482 ModestFolderWindowPrivate *priv = NULL;
484 g_return_val_if_fail (MODEST_IS_FOLDER_WINDOW(self), FALSE);
486 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
488 return MODEST_FOLDER_VIEW (priv->folder_view);
492 modest_folder_window_set_account (ModestFolderWindow *self,
493 const gchar *account_name)
495 ModestFolderWindowPrivate *priv = NULL;
496 ModestAccountMgr *mgr;
497 ModestAccountSettings *settings = NULL;
498 ModestServerAccountSettings *store_settings = NULL;
500 g_return_if_fail (MODEST_IS_FOLDER_WINDOW(self));
502 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
504 /* Get account data */
505 mgr = modest_runtime_get_account_mgr ();
507 settings = modest_account_mgr_load_account_settings (mgr, account_name);
511 store_settings = modest_account_settings_get_store_settings (settings);
515 if (priv->current_store_account != NULL)
516 g_free (priv->current_store_account);
517 priv->current_store_account = g_strdup (modest_server_account_settings_get_account_name (store_settings));
519 modest_folder_view_set_account_id_of_visible_server_account
520 (MODEST_FOLDER_VIEW (priv->folder_view),
521 priv->current_store_account);
523 modest_window_set_active_account (MODEST_WINDOW (self), account_name);
524 update_progress_hint (self);
528 g_object_unref (store_settings);
530 g_object_unref (settings);
535 modest_folder_window_set_mailbox (ModestFolderWindow *self,
536 const gchar *mailbox)
538 ModestFolderWindowPrivate *priv = NULL;
540 g_return_if_fail (MODEST_IS_FOLDER_WINDOW(self));
541 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
543 modest_folder_view_set_mailbox (MODEST_FOLDER_VIEW (priv->folder_view), mailbox);
544 modest_window_set_active_mailbox (MODEST_WINDOW (self), mailbox);
548 edit_account (GtkButton *button,
549 ModestFolderWindow *self)
551 const gchar *account_name;
553 account_name = modest_window_get_active_account ((ModestWindow *) self);
554 if (modest_ui_actions_check_for_active_account ((ModestWindow *) self, account_name)) {
555 /* Show the account settings dialog */
556 ModestAccountProtocol *proto;
557 ModestProtocolType proto_type;
560 proto_type = modest_account_mgr_get_store_protocol (modest_runtime_get_account_mgr (),
562 proto = (ModestAccountProtocol *)
563 modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
566 /* Create and show the dialog */
567 if (proto && MODEST_IS_ACCOUNT_PROTOCOL (proto)) {
568 ModestAccountSettingsDialog *dialog =
569 modest_account_protocol_get_account_settings_dialog (proto, account_name);
572 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
573 (GtkWindow *) dialog,
575 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), FALSE);
576 gtk_widget_show (GTK_WIDGET (dialog));
583 setup_menu (ModestFolderWindow *self)
585 g_return_if_fail (MODEST_IS_FOLDER_WINDOW(self));
588 modest_window_add_to_menu (MODEST_WINDOW (self), _("mcen_me_new_folder"), NULL,
589 MODEST_WINDOW_MENU_CALLBACK (modest_ui_actions_on_new_folder),
591 modest_window_add_to_menu (MODEST_WINDOW (self), _("mcen_me_inbox_sendandreceive"), NULL,
592 MODEST_WINDOW_MENU_CALLBACK (modest_ui_actions_on_send_receive),
593 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_send_receive));
594 #ifdef MODEST_TOOLKIT_HILDON2
595 modest_window_add_to_menu (MODEST_WINDOW (self), _("mcen_me_rename_folder"), NULL,
596 MODEST_WINDOW_MENU_CALLBACK (set_rename_edit_mode),
597 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_rename_folder));
598 modest_window_add_to_menu (MODEST_WINDOW (self), _("mcen_me_move_folder"), NULL,
599 MODEST_WINDOW_MENU_CALLBACK (set_moveto_edit_mode),
600 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_folder_window_move_to));
601 modest_window_add_to_menu (MODEST_WINDOW (self), _("mcen_me_delete_folder"), NULL,
602 MODEST_WINDOW_MENU_CALLBACK (set_delete_edit_mode),
603 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_folder_window_delete));
605 modest_window_add_to_menu (MODEST_WINDOW (self), _("mcen_me_rename_folder"), NULL,
606 MODEST_WINDOW_MENU_CALLBACK (modest_ui_actions_on_rename_folder),
608 modest_window_add_to_menu (MODEST_WINDOW (self), _("mcen_me_move_folder"), NULL,
609 MODEST_WINDOW_MENU_CALLBACK (modest_ui_actions_on_move_to),
611 modest_window_add_to_menu (MODEST_WINDOW (self), _("mcen_me_delete_folder"), NULL,
612 MODEST_WINDOW_MENU_CALLBACK (modest_ui_actions_on_delete_folder),
616 modest_window_add_to_menu (MODEST_WINDOW (self), _("mcen_me_outbox_cancelsend"), NULL,
617 MODEST_WINDOW_MENU_CALLBACK (modest_ui_actions_cancel_send),
618 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_cancel_sending_all));
620 modest_window_add_to_menu (MODEST_WINDOW (self),
621 dngettext(GETTEXT_PACKAGE,
622 "mcen_me_edit_account",
623 "mcen_me_edit_accounts",
625 NULL, MODEST_WINDOW_MENU_CALLBACK (edit_account),
626 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_edit_accounts));
630 on_folder_activated (ModestFolderView *folder_view,
634 ModestFolderWindowPrivate *priv = NULL;
635 ModestWindow *headerwin;
636 ModestFolderWindow *self = (ModestFolderWindow *) userdata;
638 g_return_if_fail (MODEST_IS_FOLDER_WINDOW(self));
640 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
642 if (!folder || !TNY_IS_FOLDER (folder))
645 /* We cannot open noselect folders (fake ones) */
646 if (tny_folder_get_caps (folder) & TNY_FOLDER_CAPS_NOSELECT)
649 headerwin = modest_header_window_new (folder,
650 modest_window_get_active_account (MODEST_WINDOW (self)),
651 modest_window_get_active_mailbox (MODEST_WINDOW (self)));
653 if (modest_window_mgr_register_window (modest_runtime_get_window_mgr (),
654 MODEST_WINDOW (headerwin),
655 MODEST_WINDOW (self))) {
656 gtk_widget_show (GTK_WIDGET (headerwin));
658 gtk_widget_destroy (GTK_WIDGET (headerwin));
663 #ifdef MODEST_TOOLKIT_HILDON2
665 set_delete_edit_mode (GtkButton *button,
666 ModestFolderWindow *self)
668 modest_hildon2_window_set_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_DELETE);
672 set_moveto_edit_mode (GtkButton *button,
673 ModestFolderWindow *self)
675 modest_hildon2_window_set_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_MOVE);
679 set_rename_edit_mode (GtkButton *button,
680 ModestFolderWindow *self)
682 modest_hildon2_window_set_edit_mode (MODEST_HILDON2_WINDOW (self), EDIT_MODE_COMMAND_RENAME);
687 modest_folder_window_pack_toolbar (ModestWindow *self,
688 GtkPackType pack_type,
691 ModestFolderWindowPrivate *priv;
693 g_return_if_fail (MODEST_IS_FOLDER_WINDOW (self));
694 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
696 if (pack_type == GTK_PACK_START) {
697 gtk_box_pack_start (GTK_BOX (priv->top_vbox), toolbar, FALSE, FALSE, 0);
699 gtk_box_pack_end (GTK_BOX (priv->top_vbox), toolbar, FALSE, FALSE, 0);
703 #ifdef MODEST_TOOLKIT_HILDON2
705 edit_mode_changed (ModestFolderWindow *folder_window,
708 ModestFolderWindow *self)
710 ModestFolderWindowPrivate *priv;
711 ModestFolderViewFilter filter = MODEST_FOLDER_VIEW_FILTER_NONE;
713 g_return_if_fail (MODEST_IS_FOLDER_WINDOW (self));
714 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
716 switch (edit_mode_id) {
717 case EDIT_MODE_COMMAND_MOVE:
718 filter = MODEST_FOLDER_VIEW_FILTER_MOVEABLE;
720 case EDIT_MODE_COMMAND_DELETE:
721 filter = MODEST_FOLDER_VIEW_FILTER_DELETABLE;
723 case EDIT_MODE_COMMAND_RENAME:
724 filter = MODEST_FOLDER_VIEW_FILTER_RENAMEABLE;
726 case MODEST_HILDON2_WINDOW_EDIT_MODE_NONE:
727 filter = MODEST_FOLDER_VIEW_FILTER_NONE;
731 hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->folder_view), !enabled);
733 modest_folder_view_set_filter (MODEST_FOLDER_VIEW (priv->folder_view),
736 GtkTreeSelection *sel;
738 /* Unselect all. This will prevent us from keeping a
739 reference to a TnyObject that we don't want to
741 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->folder_view));
742 gtk_tree_selection_unselect_all (sel);
744 modest_folder_view_unset_filter (MODEST_FOLDER_VIEW (priv->folder_view),
751 on_map_event (GtkWidget *widget,
755 ModestFolderWindow *self = (ModestFolderWindow *) userdata;
756 ModestFolderWindowPrivate *priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
758 if (priv->progress_hint) {
759 modest_window_show_progress (MODEST_WINDOW (self), TRUE);
766 has_active_operations (ModestFolderWindow *self)
768 GSList *operations = NULL, *node;
769 ModestMailOperationQueue *queue;
770 gboolean has_active = FALSE;
772 queue = modest_runtime_get_mail_operation_queue ();
773 operations = modest_mail_operation_queue_get_by_source (queue, G_OBJECT (self));
775 for (node = operations; node != NULL; node = g_slist_next (node)) {
776 if (!modest_mail_operation_is_finished (MODEST_MAIL_OPERATION (node->data))) {
783 g_slist_foreach (operations, (GFunc) g_object_unref, NULL);
784 g_slist_free (operations);
791 update_progress_hint (ModestFolderWindow *self)
793 ModestFolderWindowPrivate *priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
795 if (has_active_operations (self)) {
796 priv->progress_hint = TRUE;
798 priv->progress_hint = FALSE;
801 if (!priv->progress_hint && priv->current_store_account) {
802 priv->progress_hint = modest_window_mgr_has_progress_operation_on_account (modest_runtime_get_window_mgr (),
803 priv->current_store_account);
806 if (!priv->progress_hint) {
807 priv->progress_hint = modest_folder_view_get_activity (MODEST_FOLDER_VIEW (priv->folder_view));
810 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
812 if (GTK_WIDGET_VISIBLE (self)) {
813 modest_window_show_progress (MODEST_WINDOW (self), priv->progress_hint ? 1:0);
818 on_progress_list_changed (ModestWindowMgr *mgr,
819 ModestFolderWindow *self)
821 update_progress_hint (self);
825 modest_folder_window_transfer_mode_enabled (ModestFolderWindow *self)
827 ModestFolderWindowPrivate *priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
829 return priv->progress_hint;
833 on_mail_operation_started (ModestMailOperation *mail_op,
836 ModestFolderWindow *self;
837 ModestMailOperationTypeOperation op_type;
838 GObject *source = NULL;
840 self = MODEST_FOLDER_WINDOW (user_data);
841 op_type = modest_mail_operation_get_type_operation (mail_op);
842 source = modest_mail_operation_get_source(mail_op);
843 if (G_OBJECT (self) == source) {
844 update_progress_hint (self);
846 g_object_unref (source);
850 on_mail_operation_finished (ModestMailOperation *mail_op,
853 ModestFolderWindow *self;
855 self = MODEST_FOLDER_WINDOW (user_data);
857 /* Don't disable the progress hint if there are more pending
858 operations from this window */
859 update_progress_hint (self);
861 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (self));
865 on_queue_changed (ModestMailOperationQueue *queue,
866 ModestMailOperation *mail_op,
867 ModestMailOperationQueueNotification type,
868 ModestFolderWindow *self)
870 ModestFolderWindowPrivate *priv;
872 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
874 /* If this operations was created by another window, do nothing */
875 if (!modest_mail_operation_is_mine (mail_op, G_OBJECT(self)))
878 if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_ADDED) {
879 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
882 G_CALLBACK (on_mail_operation_started),
884 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
886 "operation-finished",
887 G_CALLBACK (on_mail_operation_finished),
889 } else if (type == MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED) {
890 priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
892 "operation-started");
893 priv->sighandlers = modest_signal_mgr_disconnect (priv->sighandlers,
895 "operation-finished");
900 on_activity_changed (ModestFolderView *view,
902 ModestFolderWindow *folder_window)
904 g_return_if_fail (MODEST_IS_FOLDER_WINDOW (folder_window));
906 update_progress_hint (folder_window);
911 update_window_title (ModestFolderWindow *self,
916 const gchar *mailbox;
918 ModestFolderWindowPrivate *priv;
920 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
922 mailbox = modest_folder_view_get_mailbox (MODEST_FOLDER_VIEW (priv->folder_view));
924 title = g_strdup (mailbox);
926 name = modest_tny_account_get_parent_modest_account_name_for_server_account (account);
927 title = modest_account_mgr_get_display_name (modest_runtime_get_account_mgr(),
931 modest_window_set_title (MODEST_WINDOW (self), title);
934 modest_window_set_title (MODEST_WINDOW (self), _("mcen_ap_name"));
937 modest_window_set_title (MODEST_WINDOW (self), _("mcen_ap_name"));
942 on_visible_account_changed (ModestFolderView *folder_view,
943 const gchar *account_id,
951 account = modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store(),
952 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
955 /* Update window title */
957 update_window_title (MODEST_FOLDER_WINDOW (user_data), account);
958 g_object_unref (account);
963 on_account_changed (TnyAccountStore *account_store,
967 const gchar *acc_id, *visible;
968 ModestFolderWindowPrivate *priv;
970 if (!TNY_IS_STORE_ACCOUNT (account))
973 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (user_data);
975 acc_id = tny_account_get_id (account);
976 visible = modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (priv->folder_view));
978 /* Update title if the visible account is the one that have just changed */
979 if (acc_id && visible && !g_utf8_collate (acc_id, visible))
980 update_window_title (MODEST_FOLDER_WINDOW (user_data), account);
983 #ifdef MODEST_TOOLKIT_HILDON2
985 on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
987 ModestFolderWindowPrivate *priv;
988 ModestScrollable *scrollable;
990 if (event->type == GDK_KEY_RELEASE)
993 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (user_data);
995 scrollable = MODEST_SCROLLABLE (gtk_widget_get_parent (priv->folder_view));
997 switch (event->keyval) {
1000 modest_scrollable_scroll (scrollable, 0, -1);
1004 modest_scrollable_scroll (scrollable, 0, 1);