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-accounts-window.h>
31 #include <modest-osso-state-saving.h>
33 #include <hildon/hildon-pannable-area.h>
34 #include <hildon/hildon-banner.h>
35 #include <modest-ui-actions.h>
36 #include <modest-window-mgr.h>
37 #include <modest-signal-mgr.h>
38 #include <modest-runtime.h>
39 #include <modest-platform.h>
40 #include <hildon/hildon-program.h>
41 #include <hildon/hildon-button.h>
42 #include <modest-maemo-utils.h>
43 #include <modest-icon-names.h>
44 #include <modest-defs.h>
45 #include <modest-folder-window.h>
46 #include <modest-ui-dimming-rules.h>
47 #include <modest-ui-dimming-manager.h>
48 #include <modest-window-priv.h>
49 #include <modest-ui-constants.h>
50 #include <modest-account-mgr-helpers.h>
51 #include <modest-mailboxes-window.h>
54 /* 'private'/'protected' functions */
55 static void modest_accounts_window_class_init (ModestAccountsWindowClass *klass);
56 static void modest_accounts_window_instance_init (ModestAccountsWindow *obj);
57 static void modest_accounts_window_finalize (GObject *obj);
59 static void connect_signals (ModestAccountsWindow *self);
60 static void modest_accounts_window_disconnect_signals (ModestWindow *self);
62 static void on_account_activated (GtkTreeView *treeview,
64 GtkTreeViewColumn *column,
65 ModestAccountsWindow *accounts_window);
66 static void on_progress_list_changed (ModestWindowMgr *mgr,
67 ModestAccountsWindow *self);
68 static void setup_menu (ModestAccountsWindow *self);
69 static gboolean _modest_accounts_window_map_event (GtkWidget *widget,
72 static void update_progress_hint (ModestAccountsWindow *self);
73 static void on_row_inserted (GtkTreeModel *tree_model,
77 static void on_row_deleted (GtkTreeModel *tree_model,
80 static void row_count_changed (ModestAccountsWindow *self);
82 typedef struct _ModestAccountsWindowPrivate ModestAccountsWindowPrivate;
83 struct _ModestAccountsWindowPrivate {
87 GtkWidget *account_view;
88 GtkWidget *no_accounts_container;
89 GtkWidget *new_message_button;
94 gboolean progress_hint;
96 #define MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
97 MODEST_TYPE_ACCOUNTS_WINDOW, \
98 ModestAccountsWindowPrivate))
101 static GtkWindowClass *parent_class = NULL;
103 /************************************************************************/
106 modest_accounts_window_get_type (void)
108 static GType my_type = 0;
110 static const GTypeInfo my_info = {
111 sizeof(ModestAccountsWindowClass),
112 NULL, /* base init */
113 NULL, /* base finalize */
114 (GClassInitFunc) modest_accounts_window_class_init,
115 NULL, /* class finalize */
116 NULL, /* class data */
117 sizeof(ModestAccountsWindow),
119 (GInstanceInitFunc) modest_accounts_window_instance_init,
122 my_type = g_type_register_static (MODEST_TYPE_HILDON2_WINDOW,
123 "ModestAccountsWindow",
130 modest_accounts_window_class_init (ModestAccountsWindowClass *klass)
132 GObjectClass *gobject_class;
133 gobject_class = (GObjectClass*) klass;
134 ModestWindowClass *modest_window_class = (ModestWindowClass *) klass;
136 parent_class = g_type_class_peek_parent (klass);
137 gobject_class->finalize = modest_accounts_window_finalize;
139 g_type_class_add_private (gobject_class, sizeof(ModestAccountsWindowPrivate));
141 modest_window_class->disconnect_signals_func = modest_accounts_window_disconnect_signals;
145 modest_accounts_window_instance_init (ModestAccountsWindow *obj)
147 ModestAccountsWindowPrivate *priv;
149 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(obj);
151 priv->sighandlers = NULL;
153 priv->account_view = NULL;
154 priv->progress_hint = FALSE;
156 modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(),
158 "applications_email_accountsview");
162 modest_accounts_window_finalize (GObject *obj)
164 ModestAccountsWindowPrivate *priv;
166 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(obj);
168 /* Sanity check: shouldn't be needed, the window mgr should
169 call this function before */
170 modest_accounts_window_disconnect_signals (MODEST_WINDOW (obj));
172 G_OBJECT_CLASS(parent_class)->finalize (obj);
176 modest_accounts_window_disconnect_signals (ModestWindow *self)
178 ModestAccountsWindowPrivate *priv;
179 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(self);
181 modest_signal_mgr_disconnect_all_and_destroy (priv->sighandlers);
182 priv->sighandlers = NULL;
186 connect_signals (ModestAccountsWindow *self)
188 ModestAccountsWindowPrivate *priv;
191 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(self);
195 modest_signal_mgr_connect (priv->sighandlers,
196 G_OBJECT (priv->account_view), "row-activated",
197 G_CALLBACK (on_account_activated), self);
200 modest_signal_mgr_connect (priv->sighandlers,
201 G_OBJECT (modest_runtime_get_window_mgr ()),
202 "progress-list-changed",
203 G_CALLBACK (on_progress_list_changed), self);
205 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->account_view));
208 modest_signal_mgr_connect (priv->sighandlers,
211 G_CALLBACK (on_row_inserted), self);
214 modest_signal_mgr_connect (priv->sighandlers,
217 G_CALLBACK (on_row_deleted), self);
220 modest_signal_mgr_connect (priv->sighandlers,
221 G_OBJECT (priv->new_message_button),
223 G_CALLBACK (modest_ui_actions_on_new_msg), self);
225 /* we don't register this in sighandlers, as it should be run
226 * after disconnecting all signals, in destroy stage */
230 modest_accounts_window_new (void)
232 ModestAccountsWindow *self = NULL;
233 ModestAccountsWindowPrivate *priv = NULL;
235 GdkPixbuf *window_icon;
236 GdkPixbuf *new_message_pixbuf;
237 GtkWidget *action_area_box;
239 GdkModifierType accel_mods;
240 GtkAccelGroup *accel_group;
241 GtkWidget *no_accounts_label;
242 GtkWidget *empty_view_new_message_button;
244 self = MODEST_ACCOUNTS_WINDOW(g_object_new(MODEST_TYPE_ACCOUNTS_WINDOW, NULL));
245 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(self);
247 new_message_pixbuf = modest_platform_get_icon ("general_add", MODEST_ICON_SIZE_BIG);
249 priv->box = gtk_vbox_new (FALSE, 0);
251 no_accounts_label = gtk_label_new (_("mcen_ia_noaccounts"));
252 gtk_misc_set_alignment (GTK_MISC (no_accounts_label), 0.5, 0.0);
254 empty_view_new_message_button = hildon_button_new (MODEST_EDITABLE_SIZE, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
255 hildon_button_set_title (HILDON_BUTTON (empty_view_new_message_button), _("mcen_ti_new_message"));
256 hildon_button_set_image (HILDON_BUTTON (empty_view_new_message_button), gtk_image_new_from_pixbuf (new_message_pixbuf));
259 priv->no_accounts_container = gtk_vbox_new (FALSE, 0);
260 gtk_box_pack_start (GTK_BOX (priv->no_accounts_container), empty_view_new_message_button, FALSE, FALSE, 0);
261 gtk_widget_show_all (empty_view_new_message_button);
262 gtk_box_pack_end (GTK_BOX (priv->no_accounts_container), no_accounts_label, TRUE, TRUE, 0);
263 gtk_widget_show (no_accounts_label);
264 gtk_box_pack_start (GTK_BOX (priv->box), priv->no_accounts_container, TRUE, TRUE, 0);
266 g_signal_connect (G_OBJECT (empty_view_new_message_button),
268 G_CALLBACK (modest_ui_actions_on_new_msg), self);
270 priv->pannable = hildon_pannable_area_new ();
271 priv->account_view = GTK_WIDGET (modest_account_view_new (modest_runtime_get_account_mgr ()));
273 action_area_box = hildon_tree_view_get_action_area_box (GTK_TREE_VIEW (priv->account_view));
274 priv->new_message_button = hildon_button_new (0, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
276 hildon_button_set_title (HILDON_BUTTON (priv->new_message_button), _("mcen_ti_new_message"));
277 hildon_button_set_image (HILDON_BUTTON (priv->new_message_button), gtk_image_new_from_pixbuf (new_message_pixbuf));
279 gtk_box_pack_start (GTK_BOX (action_area_box), priv->new_message_button, TRUE, TRUE, 0);
280 gtk_widget_show_all (priv->new_message_button);
281 hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->account_view), TRUE);
283 g_object_unref (new_message_pixbuf);
286 gtk_container_add (GTK_CONTAINER (priv->pannable), priv->account_view);
287 gtk_box_pack_start (GTK_BOX (priv->box), priv->pannable, TRUE, TRUE, 0);
288 gtk_container_add (GTK_CONTAINER (self), priv->box);
290 gtk_widget_show (priv->account_view);
291 gtk_widget_show (priv->pannable);
292 gtk_widget_show (priv->box);
294 connect_signals (MODEST_ACCOUNTS_WINDOW (self));
296 /* Load previous osso state, for instance if we are being restored from
298 modest_osso_load_state ();
300 /* Get device name */
301 modest_maemo_utils_get_device_name ();
303 app = hildon_program_get_instance ();
304 hildon_program_add_window (app, HILDON_WINDOW (self));
306 /* Set window icon */
307 window_icon = modest_platform_get_icon (MODEST_APP_ICON, MODEST_ICON_SIZE_BIG);
309 gtk_window_set_icon (GTK_WINDOW (self), window_icon);
310 g_object_unref (window_icon);
313 /* Dont't restore settings here,
314 * because it requires a gtk_widget_show(),
315 * and we don't want to do that until later,
316 * so that the UI is not visible for non-menu D-Bus activation.
319 g_signal_connect (G_OBJECT (self), "map-event",
320 G_CALLBACK (_modest_accounts_window_map_event),
322 update_progress_hint (self);
324 row_count_changed (self);
326 accel_group = gtk_accel_group_new ();
327 gtk_accelerator_parse ("<Control>n", &accel_key, &accel_mods);
328 gtk_widget_add_accelerator (priv->new_message_button, "clicked", accel_group,
329 accel_key, accel_mods, 0);
330 gtk_window_add_accel_group (GTK_WINDOW (self), accel_group);
332 return MODEST_WINDOW(self);
336 modest_accounts_window_get_account_view (ModestAccountsWindow *self)
338 ModestAccountsWindowPrivate *priv = NULL;
340 g_return_val_if_fail (MODEST_IS_ACCOUNTS_WINDOW(self), FALSE);
342 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
344 return MODEST_ACCOUNT_VIEW (priv->account_view);
348 setup_menu (ModestAccountsWindow *self)
350 g_return_if_fail (MODEST_IS_ACCOUNTS_WINDOW(self));
352 /* Settings menu buttons */
353 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_new_account"), NULL,
354 APP_MENU_CALLBACK (modest_ui_actions_on_new_account),
356 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_edit_accounts"), NULL,
357 APP_MENU_CALLBACK (modest_ui_actions_on_accounts),
358 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_edit_accounts));
359 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_globalsmtpservers"), NULL,
360 APP_MENU_CALLBACK (modest_ui_actions_on_smtp_servers),
361 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_tools_smtp_servers));
362 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_sendandreceive"), NULL,
363 APP_MENU_CALLBACK (modest_ui_actions_on_send_receive),
364 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_send_receive_all));
365 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_outbox_cancelsend"), NULL,
366 APP_MENU_CALLBACK (modest_ui_actions_cancel_send),
367 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_cancel_sending_all));
368 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_options"), NULL,
369 APP_MENU_CALLBACK (modest_ui_actions_on_settings),
375 on_account_activated (GtkTreeView *account_view,
377 GtkTreeViewColumn *column,
378 ModestAccountsWindow *self)
380 ModestAccountsWindowPrivate *priv;
382 GtkWidget *new_window;
384 ModestProtocolType store_protocol;
385 gboolean mailboxes_protocol;
387 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
389 account_name = modest_account_view_get_path_account (MODEST_ACCOUNT_VIEW (priv->account_view), path);
393 /* If it's a multimailbox container, we have to show the mailboxes window */
394 store_protocol = modest_account_mgr_get_store_protocol (modest_runtime_get_account_mgr (),
397 modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
399 MODEST_PROTOCOL_REGISTRY_MULTI_MAILBOX_PROVIDER_PROTOCOLS);
400 if (mailboxes_protocol) {
401 new_window = GTK_WIDGET (modest_mailboxes_window_new (account_name));
404 new_window = GTK_WIDGET (modest_folder_window_new (NULL));
407 registered = modest_window_mgr_register_window (modest_runtime_get_window_mgr (),
408 MODEST_WINDOW (new_window),
409 MODEST_WINDOW (self));
412 gtk_widget_destroy (new_window);
415 if (!mailboxes_protocol) {
416 modest_folder_window_set_account (MODEST_FOLDER_WINDOW (new_window), account_name);
418 gtk_widget_show (new_window);
420 g_free (account_name);
424 _modest_accounts_window_map_event (GtkWidget *widget,
428 ModestAccountsWindow *self = (ModestAccountsWindow *) userdata;
429 ModestAccountsWindowPrivate *priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
431 if (priv->progress_hint) {
432 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
439 update_progress_hint (ModestAccountsWindow *self)
441 ModestAccountsWindowPrivate *priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
443 priv->progress_hint = modest_window_mgr_has_progress_operation (modest_runtime_get_window_mgr ());
445 if (GTK_WIDGET_VISIBLE (self)) {
446 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), priv->progress_hint?1:0);
451 on_progress_list_changed (ModestWindowMgr *mgr,
452 ModestAccountsWindow *self)
454 update_progress_hint (self);
458 on_row_inserted (GtkTreeModel *tree_model,
463 ModestAccountsWindow *self;
465 self = (ModestAccountsWindow *) user_data;
467 row_count_changed (self);
471 on_row_deleted (GtkTreeModel *tree_model,
475 ModestAccountsWindow *self;
477 self = (ModestAccountsWindow *) user_data;
479 row_count_changed (self);
482 static void row_count_changed (ModestAccountsWindow *self)
484 ModestAccountsWindowPrivate *priv;
488 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
489 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->account_view));
491 count = gtk_tree_model_iter_n_children (model, NULL);
494 gtk_widget_show (priv->no_accounts_container);
496 gtk_widget_hide (priv->no_accounts_container);
498 gtk_container_child_set (GTK_CONTAINER(priv->box), priv->pannable,