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 <hildon/hildon-helper.h>
36 #include <modest-ui-actions.h>
37 #include <modest-window-mgr.h>
38 #include <modest-signal-mgr.h>
39 #include <modest-runtime.h>
40 #include <modest-platform.h>
41 #include <hildon/hildon-program.h>
42 #include <hildon/hildon-button.h>
43 #include <modest-maemo-utils.h>
44 #include <modest-icon-names.h>
45 #include <modest-defs.h>
46 #include <modest-folder-window.h>
47 #include <modest-ui-dimming-rules.h>
48 #include <modest-ui-dimming-manager.h>
49 #include <modest-window-priv.h>
50 #include <modest-ui-constants.h>
51 #include <modest-account-mgr-helpers.h>
52 #include <modest-mailboxes-window.h>
55 /* 'private'/'protected' functions */
56 static void modest_accounts_window_class_init (ModestAccountsWindowClass *klass);
57 static void modest_accounts_window_instance_init (ModestAccountsWindow *obj);
58 static void modest_accounts_window_finalize (GObject *obj);
60 static void connect_signals (ModestAccountsWindow *self);
61 static void modest_accounts_window_disconnect_signals (ModestWindow *self);
63 static void on_account_activated (GtkTreeView *treeview,
65 GtkTreeViewColumn *column,
66 ModestAccountsWindow *accounts_window);
67 static void on_progress_list_changed (ModestWindowMgr *mgr,
68 ModestAccountsWindow *self);
69 static void setup_menu (ModestAccountsWindow *self);
70 static gboolean _modest_accounts_window_map_event (GtkWidget *widget,
73 static void update_progress_hint (ModestAccountsWindow *self);
74 static void on_row_inserted (GtkTreeModel *tree_model,
78 static void on_row_deleted (GtkTreeModel *tree_model,
81 static void row_count_changed (ModestAccountsWindow *self);
83 typedef struct _ModestAccountsWindowPrivate ModestAccountsWindowPrivate;
84 struct _ModestAccountsWindowPrivate {
88 GtkWidget *account_view;
89 GtkWidget *no_accounts_container;
90 GtkWidget *new_message_button;
95 gboolean progress_hint;
97 #define MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
98 MODEST_TYPE_ACCOUNTS_WINDOW, \
99 ModestAccountsWindowPrivate))
102 static GtkWindowClass *parent_class = NULL;
104 /************************************************************************/
107 modest_accounts_window_get_type (void)
109 static GType my_type = 0;
111 static const GTypeInfo my_info = {
112 sizeof(ModestAccountsWindowClass),
113 NULL, /* base init */
114 NULL, /* base finalize */
115 (GClassInitFunc) modest_accounts_window_class_init,
116 NULL, /* class finalize */
117 NULL, /* class data */
118 sizeof(ModestAccountsWindow),
120 (GInstanceInitFunc) modest_accounts_window_instance_init,
123 my_type = g_type_register_static (MODEST_TYPE_HILDON2_WINDOW,
124 "ModestAccountsWindow",
131 modest_accounts_window_class_init (ModestAccountsWindowClass *klass)
133 GObjectClass *gobject_class;
134 gobject_class = (GObjectClass*) klass;
135 ModestWindowClass *modest_window_class = (ModestWindowClass *) klass;
137 parent_class = g_type_class_peek_parent (klass);
138 gobject_class->finalize = modest_accounts_window_finalize;
140 g_type_class_add_private (gobject_class, sizeof(ModestAccountsWindowPrivate));
142 modest_window_class->disconnect_signals_func = modest_accounts_window_disconnect_signals;
146 modest_accounts_window_instance_init (ModestAccountsWindow *obj)
148 ModestAccountsWindowPrivate *priv;
150 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(obj);
152 priv->sighandlers = NULL;
154 priv->account_view = NULL;
155 priv->progress_hint = FALSE;
157 modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(),
159 "applications_email_accountsview");
163 modest_accounts_window_finalize (GObject *obj)
165 ModestAccountsWindowPrivate *priv;
167 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(obj);
169 /* Sanity check: shouldn't be needed, the window mgr should
170 call this function before */
171 modest_accounts_window_disconnect_signals (MODEST_WINDOW (obj));
173 G_OBJECT_CLASS(parent_class)->finalize (obj);
177 modest_accounts_window_disconnect_signals (ModestWindow *self)
179 ModestAccountsWindowPrivate *priv;
180 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(self);
182 modest_signal_mgr_disconnect_all_and_destroy (priv->sighandlers);
183 priv->sighandlers = NULL;
187 connect_signals (ModestAccountsWindow *self)
189 ModestAccountsWindowPrivate *priv;
192 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(self);
196 modest_signal_mgr_connect (priv->sighandlers,
197 G_OBJECT (priv->account_view), "row-activated",
198 G_CALLBACK (on_account_activated), self);
201 modest_signal_mgr_connect (priv->sighandlers,
202 G_OBJECT (modest_runtime_get_window_mgr ()),
203 "progress-list-changed",
204 G_CALLBACK (on_progress_list_changed), self);
206 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->account_view));
209 modest_signal_mgr_connect (priv->sighandlers,
212 G_CALLBACK (on_row_inserted), self);
215 modest_signal_mgr_connect (priv->sighandlers,
218 G_CALLBACK (on_row_deleted), self);
221 modest_signal_mgr_connect (priv->sighandlers,
222 G_OBJECT (priv->new_message_button),
224 G_CALLBACK (modest_ui_actions_on_new_msg), self);
226 /* we don't register this in sighandlers, as it should be run
227 * after disconnecting all signals, in destroy stage */
231 modest_accounts_window_new (void)
233 ModestAccountsWindow *self = NULL;
234 ModestAccountsWindowPrivate *priv = NULL;
236 GdkPixbuf *window_icon;
237 GdkPixbuf *new_message_pixbuf;
238 GtkWidget *action_area_box;
240 GdkModifierType accel_mods;
241 GtkAccelGroup *accel_group;
242 GtkWidget *no_accounts_label;
243 GtkWidget *empty_view_new_message_button;
244 GtkWidget *box_alignment;
246 self = MODEST_ACCOUNTS_WINDOW(g_object_new(MODEST_TYPE_ACCOUNTS_WINDOW, NULL));
247 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(self);
249 new_message_pixbuf = modest_platform_get_icon ("general_add", MODEST_ICON_SIZE_BIG);
251 box_alignment = gtk_alignment_new (0, 0, 1.0, 1.0);
252 gtk_alignment_set_padding (GTK_ALIGNMENT (box_alignment),
254 HILDON_MARGIN_DOUBLE, HILDON_MARGIN_DOUBLE);
255 priv->box = gtk_vbox_new (FALSE, 0);
257 no_accounts_label = gtk_label_new (_("mcen_ia_noaccounts"));
259 gtk_misc_set_alignment (GTK_MISC (no_accounts_label), 0.5, 0.5);
260 hildon_helper_set_logical_font (no_accounts_label, "LargeSystemFont");
262 empty_view_new_message_button = hildon_button_new (MODEST_EDITABLE_SIZE, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
263 hildon_button_set_title (HILDON_BUTTON (empty_view_new_message_button), _("mcen_ti_new_message"));
264 hildon_button_set_image (HILDON_BUTTON (empty_view_new_message_button), gtk_image_new_from_pixbuf (new_message_pixbuf));
267 priv->no_accounts_container = gtk_vbox_new (FALSE, 0);
268 gtk_box_pack_start (GTK_BOX (priv->no_accounts_container), empty_view_new_message_button, FALSE, FALSE, 0);
269 gtk_widget_show_all (empty_view_new_message_button);
270 gtk_box_pack_end (GTK_BOX (priv->no_accounts_container), no_accounts_label, TRUE, TRUE, 0);
271 gtk_widget_show (no_accounts_label);
272 gtk_box_pack_start (GTK_BOX (priv->box), priv->no_accounts_container, TRUE, TRUE, 0);
274 g_signal_connect (G_OBJECT (empty_view_new_message_button),
276 G_CALLBACK (modest_ui_actions_on_new_msg), self);
278 priv->pannable = hildon_pannable_area_new ();
279 priv->account_view = GTK_WIDGET (modest_account_view_new (modest_runtime_get_account_mgr ()));
281 action_area_box = hildon_tree_view_get_action_area_box (GTK_TREE_VIEW (priv->account_view));
282 priv->new_message_button = hildon_button_new (0, HILDON_BUTTON_ARRANGEMENT_HORIZONTAL);
284 hildon_button_set_title (HILDON_BUTTON (priv->new_message_button), _("mcen_ti_new_message"));
285 hildon_button_set_image (HILDON_BUTTON (priv->new_message_button), gtk_image_new_from_pixbuf (new_message_pixbuf));
287 gtk_box_pack_start (GTK_BOX (action_area_box), priv->new_message_button, TRUE, TRUE, 0);
288 gtk_widget_show_all (priv->new_message_button);
289 hildon_tree_view_set_action_area_visible (GTK_TREE_VIEW (priv->account_view), TRUE);
291 g_object_unref (new_message_pixbuf);
294 gtk_container_add (GTK_CONTAINER (priv->pannable), priv->account_view);
295 gtk_box_pack_start (GTK_BOX (priv->box), priv->pannable, TRUE, TRUE, 0);
296 gtk_container_add (GTK_CONTAINER (box_alignment), priv->box);
297 gtk_container_add (GTK_CONTAINER (self), box_alignment);
299 gtk_widget_show (priv->account_view);
300 gtk_widget_show (priv->pannable);
301 gtk_widget_show (priv->box);
302 gtk_widget_show (box_alignment);
304 connect_signals (MODEST_ACCOUNTS_WINDOW (self));
306 /* Load previous osso state, for instance if we are being restored from
308 modest_osso_load_state ();
310 /* Get device name */
311 modest_maemo_utils_get_device_name ();
313 app = hildon_program_get_instance ();
314 hildon_program_add_window (app, HILDON_WINDOW (self));
316 /* Set window icon */
317 window_icon = modest_platform_get_icon (MODEST_APP_ICON, MODEST_ICON_SIZE_BIG);
319 gtk_window_set_icon (GTK_WINDOW (self), window_icon);
320 g_object_unref (window_icon);
323 /* Dont't restore settings here,
324 * because it requires a gtk_widget_show(),
325 * and we don't want to do that until later,
326 * so that the UI is not visible for non-menu D-Bus activation.
329 g_signal_connect (G_OBJECT (self), "map-event",
330 G_CALLBACK (_modest_accounts_window_map_event),
332 update_progress_hint (self);
334 row_count_changed (self);
336 accel_group = gtk_accel_group_new ();
337 gtk_accelerator_parse ("<Control>n", &accel_key, &accel_mods);
338 gtk_widget_add_accelerator (priv->new_message_button, "clicked", accel_group,
339 accel_key, accel_mods, 0);
340 gtk_window_add_accel_group (GTK_WINDOW (self), accel_group);
342 return MODEST_WINDOW(self);
346 modest_accounts_window_get_account_view (ModestAccountsWindow *self)
348 ModestAccountsWindowPrivate *priv = NULL;
350 g_return_val_if_fail (MODEST_IS_ACCOUNTS_WINDOW(self), FALSE);
352 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
354 return MODEST_ACCOUNT_VIEW (priv->account_view);
358 setup_menu (ModestAccountsWindow *self)
360 g_return_if_fail (MODEST_IS_ACCOUNTS_WINDOW(self));
362 /* Settings menu buttons */
363 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_new_account"), NULL,
364 APP_MENU_CALLBACK (modest_ui_actions_on_new_account),
366 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_edit_accounts"), NULL,
367 APP_MENU_CALLBACK (modest_ui_actions_on_accounts),
368 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_edit_accounts));
369 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_globalsmtpservers"), NULL,
370 APP_MENU_CALLBACK (modest_ui_actions_on_smtp_servers),
371 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_tools_smtp_servers));
372 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_sendandreceive"), NULL,
373 APP_MENU_CALLBACK (modest_ui_actions_on_send_receive),
374 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_send_receive_all));
375 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_outbox_cancelsend"), NULL,
376 APP_MENU_CALLBACK (modest_ui_actions_cancel_send),
377 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_cancel_sending_all));
378 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_options"), NULL,
379 APP_MENU_CALLBACK (modest_ui_actions_on_settings),
385 on_account_activated (GtkTreeView *account_view,
387 GtkTreeViewColumn *column,
388 ModestAccountsWindow *self)
390 ModestAccountsWindowPrivate *priv;
392 GtkWidget *new_window;
394 ModestProtocolType store_protocol;
395 gboolean mailboxes_protocol;
397 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
399 account_name = modest_account_view_get_path_account (MODEST_ACCOUNT_VIEW (priv->account_view), path);
403 /* If it's a multimailbox container, we have to show the mailboxes window */
404 store_protocol = modest_account_mgr_get_store_protocol (modest_runtime_get_account_mgr (),
407 modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
409 MODEST_PROTOCOL_REGISTRY_MULTI_MAILBOX_PROVIDER_PROTOCOLS);
410 if (mailboxes_protocol) {
411 new_window = GTK_WIDGET (modest_mailboxes_window_new (account_name));
414 new_window = GTK_WIDGET (modest_folder_window_new (NULL));
417 registered = modest_window_mgr_register_window (modest_runtime_get_window_mgr (),
418 MODEST_WINDOW (new_window),
419 MODEST_WINDOW (self));
422 gtk_widget_destroy (new_window);
425 if (!mailboxes_protocol) {
426 modest_folder_window_set_account (MODEST_FOLDER_WINDOW (new_window), account_name);
428 gtk_widget_show (new_window);
430 g_free (account_name);
434 _modest_accounts_window_map_event (GtkWidget *widget,
438 ModestAccountsWindow *self = (ModestAccountsWindow *) userdata;
439 ModestAccountsWindowPrivate *priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
441 if (priv->progress_hint) {
442 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
449 update_progress_hint (ModestAccountsWindow *self)
451 ModestAccountsWindowPrivate *priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
453 priv->progress_hint = modest_window_mgr_has_progress_operation (modest_runtime_get_window_mgr ());
455 if (GTK_WIDGET_VISIBLE (self)) {
456 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), priv->progress_hint?1:0);
461 on_progress_list_changed (ModestWindowMgr *mgr,
462 ModestAccountsWindow *self)
464 update_progress_hint (self);
468 on_row_inserted (GtkTreeModel *tree_model,
473 ModestAccountsWindow *self;
475 self = (ModestAccountsWindow *) user_data;
477 row_count_changed (self);
481 on_row_deleted (GtkTreeModel *tree_model,
485 ModestAccountsWindow *self;
487 self = (ModestAccountsWindow *) user_data;
489 row_count_changed (self);
492 static void row_count_changed (ModestAccountsWindow *self)
494 ModestAccountsWindowPrivate *priv;
498 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
499 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->account_view));
501 count = gtk_tree_model_iter_n_children (model, NULL);
504 gtk_widget_show (priv->no_accounts_container);
506 gtk_widget_hide (priv->no_accounts_container);
508 gtk_container_child_set (GTK_CONTAINER(priv->box), priv->pannable,