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;
243 GtkWidget *box_alignment;
245 self = MODEST_ACCOUNTS_WINDOW(g_object_new(MODEST_TYPE_ACCOUNTS_WINDOW, NULL));
246 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(self);
248 new_message_pixbuf = modest_platform_get_icon ("general_add", MODEST_ICON_SIZE_BIG);
250 box_alignment = gtk_alignment_new (0, 0, 1.0, 1.0);
251 gtk_alignment_set_padding (GTK_ALIGNMENT (box_alignment),
253 HILDON_MARGIN_DOUBLE, HILDON_MARGIN_DOUBLE);
254 priv->box = gtk_vbox_new (FALSE, 0);
256 no_accounts_label = gtk_label_new (_("mcen_ia_noaccounts"));
257 gtk_misc_set_alignment (GTK_MISC (no_accounts_label), 0.5, 0.0);
259 empty_view_new_message_button = hildon_button_new (MODEST_EDITABLE_SIZE, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
260 hildon_button_set_title (HILDON_BUTTON (empty_view_new_message_button), _("mcen_ti_new_message"));
261 hildon_button_set_image (HILDON_BUTTON (empty_view_new_message_button), gtk_image_new_from_pixbuf (new_message_pixbuf));
264 priv->no_accounts_container = gtk_vbox_new (FALSE, 0);
265 gtk_box_pack_start (GTK_BOX (priv->no_accounts_container), empty_view_new_message_button, FALSE, FALSE, 0);
266 gtk_widget_show_all (empty_view_new_message_button);
267 gtk_box_pack_end (GTK_BOX (priv->no_accounts_container), no_accounts_label, TRUE, TRUE, 0);
268 gtk_widget_show (no_accounts_label);
269 gtk_box_pack_start (GTK_BOX (priv->box), priv->no_accounts_container, TRUE, TRUE, 0);
271 g_signal_connect (G_OBJECT (empty_view_new_message_button),
273 G_CALLBACK (modest_ui_actions_on_new_msg), self);
275 priv->pannable = hildon_pannable_area_new ();
276 priv->account_view = GTK_WIDGET (modest_account_view_new (modest_runtime_get_account_mgr ()));
278 action_area_box = hildon_tree_view_get_action_area_box (GTK_TREE_VIEW (priv->account_view));
279 priv->new_message_button = hildon_button_new (0, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
281 hildon_button_set_title (HILDON_BUTTON (priv->new_message_button), _("mcen_ti_new_message"));
282 hildon_button_set_image (HILDON_BUTTON (priv->new_message_button), gtk_image_new_from_pixbuf (new_message_pixbuf));
284 gtk_box_pack_start (GTK_BOX (action_area_box), priv->new_message_button, TRUE, TRUE, 0);
285 gtk_widget_show_all (priv->new_message_button);
286 hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->account_view), TRUE);
288 g_object_unref (new_message_pixbuf);
291 gtk_container_add (GTK_CONTAINER (priv->pannable), priv->account_view);
292 gtk_box_pack_start (GTK_BOX (priv->box), priv->pannable, TRUE, TRUE, 0);
293 gtk_container_add (GTK_CONTAINER (box_alignment), priv->box);
294 gtk_container_add (GTK_CONTAINER (self), box_alignment);
296 gtk_widget_show (priv->account_view);
297 gtk_widget_show (priv->pannable);
298 gtk_widget_show (priv->box);
299 gtk_widget_show (box_alignment);
301 connect_signals (MODEST_ACCOUNTS_WINDOW (self));
303 /* Load previous osso state, for instance if we are being restored from
305 modest_osso_load_state ();
307 /* Get device name */
308 modest_maemo_utils_get_device_name ();
310 app = hildon_program_get_instance ();
311 hildon_program_add_window (app, HILDON_WINDOW (self));
313 /* Set window icon */
314 window_icon = modest_platform_get_icon (MODEST_APP_ICON, MODEST_ICON_SIZE_BIG);
316 gtk_window_set_icon (GTK_WINDOW (self), window_icon);
317 g_object_unref (window_icon);
320 /* Dont't restore settings here,
321 * because it requires a gtk_widget_show(),
322 * and we don't want to do that until later,
323 * so that the UI is not visible for non-menu D-Bus activation.
326 g_signal_connect (G_OBJECT (self), "map-event",
327 G_CALLBACK (_modest_accounts_window_map_event),
329 update_progress_hint (self);
331 row_count_changed (self);
333 accel_group = gtk_accel_group_new ();
334 gtk_accelerator_parse ("<Control>n", &accel_key, &accel_mods);
335 gtk_widget_add_accelerator (priv->new_message_button, "clicked", accel_group,
336 accel_key, accel_mods, 0);
337 gtk_window_add_accel_group (GTK_WINDOW (self), accel_group);
339 return MODEST_WINDOW(self);
343 modest_accounts_window_get_account_view (ModestAccountsWindow *self)
345 ModestAccountsWindowPrivate *priv = NULL;
347 g_return_val_if_fail (MODEST_IS_ACCOUNTS_WINDOW(self), FALSE);
349 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
351 return MODEST_ACCOUNT_VIEW (priv->account_view);
355 setup_menu (ModestAccountsWindow *self)
357 g_return_if_fail (MODEST_IS_ACCOUNTS_WINDOW(self));
359 /* Settings menu buttons */
360 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_new_account"), NULL,
361 APP_MENU_CALLBACK (modest_ui_actions_on_new_account),
363 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_edit_accounts"), NULL,
364 APP_MENU_CALLBACK (modest_ui_actions_on_accounts),
365 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_edit_accounts));
366 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_globalsmtpservers"), NULL,
367 APP_MENU_CALLBACK (modest_ui_actions_on_smtp_servers),
368 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_tools_smtp_servers));
369 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_sendandreceive"), NULL,
370 APP_MENU_CALLBACK (modest_ui_actions_on_send_receive),
371 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_send_receive_all));
372 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_outbox_cancelsend"), NULL,
373 APP_MENU_CALLBACK (modest_ui_actions_cancel_send),
374 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_cancel_sending_all));
375 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_options"), NULL,
376 APP_MENU_CALLBACK (modest_ui_actions_on_settings),
382 on_account_activated (GtkTreeView *account_view,
384 GtkTreeViewColumn *column,
385 ModestAccountsWindow *self)
387 ModestAccountsWindowPrivate *priv;
389 GtkWidget *new_window;
391 ModestProtocolType store_protocol;
392 gboolean mailboxes_protocol;
394 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
396 account_name = modest_account_view_get_path_account (MODEST_ACCOUNT_VIEW (priv->account_view), path);
400 /* If it's a multimailbox container, we have to show the mailboxes window */
401 store_protocol = modest_account_mgr_get_store_protocol (modest_runtime_get_account_mgr (),
404 modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
406 MODEST_PROTOCOL_REGISTRY_MULTI_MAILBOX_PROVIDER_PROTOCOLS);
407 if (mailboxes_protocol) {
408 new_window = GTK_WIDGET (modest_mailboxes_window_new (account_name));
411 new_window = GTK_WIDGET (modest_folder_window_new (NULL));
414 registered = modest_window_mgr_register_window (modest_runtime_get_window_mgr (),
415 MODEST_WINDOW (new_window),
416 MODEST_WINDOW (self));
419 gtk_widget_destroy (new_window);
422 if (!mailboxes_protocol) {
423 modest_folder_window_set_account (MODEST_FOLDER_WINDOW (new_window), account_name);
425 gtk_widget_show (new_window);
427 g_free (account_name);
431 _modest_accounts_window_map_event (GtkWidget *widget,
435 ModestAccountsWindow *self = (ModestAccountsWindow *) userdata;
436 ModestAccountsWindowPrivate *priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
438 if (priv->progress_hint) {
439 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
446 update_progress_hint (ModestAccountsWindow *self)
448 ModestAccountsWindowPrivate *priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
450 priv->progress_hint = modest_window_mgr_has_progress_operation (modest_runtime_get_window_mgr ());
452 if (GTK_WIDGET_VISIBLE (self)) {
453 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), priv->progress_hint?1:0);
458 on_progress_list_changed (ModestWindowMgr *mgr,
459 ModestAccountsWindow *self)
461 update_progress_hint (self);
465 on_row_inserted (GtkTreeModel *tree_model,
470 ModestAccountsWindow *self;
472 self = (ModestAccountsWindow *) user_data;
474 row_count_changed (self);
478 on_row_deleted (GtkTreeModel *tree_model,
482 ModestAccountsWindow *self;
484 self = (ModestAccountsWindow *) user_data;
486 row_count_changed (self);
489 static void row_count_changed (ModestAccountsWindow *self)
491 ModestAccountsWindowPrivate *priv;
495 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
496 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->account_view));
498 count = gtk_tree_model_iter_n_children (model, NULL);
501 gtk_widget_show (priv->no_accounts_container);
503 gtk_widget_hide (priv->no_accounts_container);
505 gtk_container_child_set (GTK_CONTAINER(priv->box), priv->pannable,