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 <modest-maemo-utils.h>
42 #include <modest-icon-names.h>
43 #include <modest-defs.h>
44 #include <modest-folder-window.h>
45 #include <modest-ui-dimming-rules.h>
46 #include <modest-ui-dimming-manager.h>
47 #include <modest-window-priv.h>
50 /* 'private'/'protected' functions */
51 static void modest_accounts_window_class_init (ModestAccountsWindowClass *klass);
52 static void modest_accounts_window_instance_init (ModestAccountsWindow *obj);
53 static void modest_accounts_window_finalize (GObject *obj);
55 static void connect_signals (ModestAccountsWindow *self);
56 static void modest_accounts_window_disconnect_signals (ModestWindow *self);
58 static void on_account_activated (GtkTreeView *treeview,
60 GtkTreeViewColumn *column,
61 ModestAccountsWindow *accounts_window);
62 static void on_progress_list_changed (ModestWindowMgr *mgr,
63 ModestAccountsWindow *self);
64 static void setup_menu (ModestAccountsWindow *self);
65 static gboolean _modest_accounts_window_map_event (GtkWidget *widget,
68 static void update_progress_hint (ModestAccountsWindow *self);
69 static void on_row_inserted (GtkTreeModel *tree_model,
73 static void on_row_deleted (GtkTreeModel *tree_model,
76 static void row_count_changed (ModestAccountsWindow *self);
78 typedef struct _ModestAccountsWindowPrivate ModestAccountsWindowPrivate;
79 struct _ModestAccountsWindowPrivate {
81 GtkWidget *account_view;
82 GtkWidget *no_accounts_label;
87 gboolean progress_hint;
89 #define MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
90 MODEST_TYPE_ACCOUNTS_WINDOW, \
91 ModestAccountsWindowPrivate))
94 static GtkWindowClass *parent_class = NULL;
96 /************************************************************************/
99 modest_accounts_window_get_type (void)
101 static GType my_type = 0;
103 static const GTypeInfo my_info = {
104 sizeof(ModestAccountsWindowClass),
105 NULL, /* base init */
106 NULL, /* base finalize */
107 (GClassInitFunc) modest_accounts_window_class_init,
108 NULL, /* class finalize */
109 NULL, /* class data */
110 sizeof(ModestAccountsWindow),
112 (GInstanceInitFunc) modest_accounts_window_instance_init,
115 my_type = g_type_register_static (MODEST_TYPE_HILDON2_WINDOW,
116 "ModestAccountsWindow",
123 modest_accounts_window_class_init (ModestAccountsWindowClass *klass)
125 GObjectClass *gobject_class;
126 gobject_class = (GObjectClass*) klass;
127 ModestWindowClass *modest_window_class = (ModestWindowClass *) klass;
129 parent_class = g_type_class_peek_parent (klass);
130 gobject_class->finalize = modest_accounts_window_finalize;
132 g_type_class_add_private (gobject_class, sizeof(ModestAccountsWindowPrivate));
134 modest_window_class->disconnect_signals_func = modest_accounts_window_disconnect_signals;
138 modest_accounts_window_instance_init (ModestAccountsWindow *obj)
140 ModestAccountsWindowPrivate *priv;
142 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(obj);
144 priv->sighandlers = NULL;
146 priv->account_view = NULL;
147 priv->progress_hint = FALSE;
149 modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(),
151 "applications_email_accountsview");
155 modest_accounts_window_finalize (GObject *obj)
157 ModestAccountsWindowPrivate *priv;
159 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(obj);
161 /* Sanity check: shouldn't be needed, the window mgr should
162 call this function before */
163 modest_accounts_window_disconnect_signals (MODEST_WINDOW (obj));
165 G_OBJECT_CLASS(parent_class)->finalize (obj);
169 modest_accounts_window_disconnect_signals (ModestWindow *self)
171 ModestAccountsWindowPrivate *priv;
172 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(self);
174 modest_signal_mgr_disconnect_all_and_destroy (priv->sighandlers);
175 priv->sighandlers = NULL;
179 connect_signals (ModestAccountsWindow *self)
181 ModestAccountsWindowPrivate *priv;
184 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(self);
188 modest_signal_mgr_connect (priv->sighandlers,
189 G_OBJECT (priv->account_view), "row-activated",
190 G_CALLBACK (on_account_activated), self);
193 modest_signal_mgr_connect (priv->sighandlers,
194 G_OBJECT (modest_runtime_get_window_mgr ()),
195 "progress-list-changed",
196 G_CALLBACK (on_progress_list_changed), self);
198 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->account_view));
201 modest_signal_mgr_connect (priv->sighandlers,
204 G_CALLBACK (on_row_inserted), self);
207 modest_signal_mgr_connect (priv->sighandlers,
210 G_CALLBACK (on_row_deleted), self);
212 /* we don't register this in sighandlers, as it should be run
213 * after disconnecting all signals, in destroy stage */
217 modest_accounts_window_new (void)
219 ModestAccountsWindow *self = NULL;
220 ModestAccountsWindowPrivate *priv = NULL;
222 GdkPixbuf *window_icon;
226 self = MODEST_ACCOUNTS_WINDOW(g_object_new(MODEST_TYPE_ACCOUNTS_WINDOW, NULL));
227 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(self);
229 box = gtk_vbox_new (FALSE, 0);
231 priv->no_accounts_label = gtk_label_new (_("mcen_ia_noaccounts"));
232 gtk_misc_set_alignment (GTK_MISC (priv->no_accounts_label), 0.5, 0.0);
233 gtk_box_pack_start (GTK_BOX (box), priv->no_accounts_label, TRUE, TRUE, 0);
235 pannable = hildon_pannable_area_new ();
236 priv->account_view = GTK_WIDGET (modest_account_view_new (modest_runtime_get_account_mgr ()));
240 gtk_container_add (GTK_CONTAINER (pannable), priv->account_view);
241 gtk_box_pack_start (GTK_BOX (box), pannable, TRUE, TRUE, 0);
242 gtk_container_add (GTK_CONTAINER (self), box);
244 gtk_widget_show (priv->account_view);
245 gtk_widget_show (pannable);
246 gtk_widget_show (box);
248 connect_signals (MODEST_ACCOUNTS_WINDOW (self));
250 /* Load previous osso state, for instance if we are being restored from
252 modest_osso_load_state ();
254 /* Get device name */
255 modest_maemo_utils_get_device_name ();
257 app = hildon_program_get_instance ();
258 hildon_program_add_window (app, HILDON_WINDOW (self));
260 /* Set window icon */
261 window_icon = modest_platform_get_icon (MODEST_APP_ICON, MODEST_ICON_SIZE_BIG);
263 gtk_window_set_icon (GTK_WINDOW (self), window_icon);
264 g_object_unref (window_icon);
267 /* Dont't restore settings here,
268 * because it requires a gtk_widget_show(),
269 * and we don't want to do that until later,
270 * so that the UI is not visible for non-menu D-Bus activation.
273 g_signal_connect (G_OBJECT (self), "map-event",
274 G_CALLBACK (_modest_accounts_window_map_event),
276 update_progress_hint (self);
278 row_count_changed (self);
281 return MODEST_WINDOW(self);
285 modest_accounts_window_get_account_view (ModestAccountsWindow *self)
287 ModestAccountsWindowPrivate *priv = NULL;
289 g_return_val_if_fail (MODEST_IS_ACCOUNTS_WINDOW(self), FALSE);
291 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
293 return MODEST_ACCOUNT_VIEW (priv->account_view);
297 setup_menu (ModestAccountsWindow *self)
299 g_return_if_fail (MODEST_IS_ACCOUNTS_WINDOW(self));
301 /* Settings menu buttons */
302 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_new_account"), NULL,
303 APP_MENU_CALLBACK (modest_ui_actions_on_new_account),
305 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_edit_accounts"), NULL,
306 APP_MENU_CALLBACK (modest_ui_actions_on_accounts),
308 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_globalsmtpservers"), NULL,
309 APP_MENU_CALLBACK (modest_ui_actions_on_smtp_servers),
310 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_tools_smtp_servers));
311 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_sendandreceive"), NULL,
312 APP_MENU_CALLBACK (modest_ui_actions_on_send_receive),
313 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_send_receive_all));
314 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_outbox_cancelsend"), NULL,
315 APP_MENU_CALLBACK (modest_ui_actions_cancel_send),
316 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_cancel_sending_all));
317 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_inbox_options"), NULL,
318 APP_MENU_CALLBACK (modest_ui_actions_on_settings),
320 modest_hildon2_window_add_to_menu (MODEST_HILDON2_WINDOW (self), _("mcen_me_new_message"), "<Control>n",
321 APP_MENU_CALLBACK (modest_ui_actions_on_new_msg),
322 MODEST_DIMMING_CALLBACK (modest_ui_dimming_rules_on_new_msg));
327 on_account_activated (GtkTreeView *account_view,
329 GtkTreeViewColumn *column,
330 ModestAccountsWindow *self)
332 ModestAccountsWindowPrivate *priv;
334 GtkWidget *folder_window;
337 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
339 account_name = modest_account_view_get_path_account (MODEST_ACCOUNT_VIEW (priv->account_view), path);
343 folder_window = GTK_WIDGET (modest_folder_window_new (NULL));
344 registered = modest_window_mgr_register_window (modest_runtime_get_window_mgr (),
345 MODEST_WINDOW (folder_window),
346 MODEST_WINDOW (self));
349 gtk_widget_destroy (folder_window);
350 folder_window = NULL;
352 modest_folder_window_set_account (MODEST_FOLDER_WINDOW (folder_window), account_name);
353 gtk_widget_show (folder_window);
355 g_free (account_name);
359 _modest_accounts_window_map_event (GtkWidget *widget,
363 ModestAccountsWindow *self = (ModestAccountsWindow *) userdata;
364 ModestAccountsWindowPrivate *priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
366 if (priv->progress_hint) {
367 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
374 update_progress_hint (ModestAccountsWindow *self)
376 ModestAccountsWindowPrivate *priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
378 priv->progress_hint = modest_window_mgr_has_progress_operation (modest_runtime_get_window_mgr ());
380 if (GTK_WIDGET_VISIBLE (self)) {
381 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), priv->progress_hint?1:0);
386 on_progress_list_changed (ModestWindowMgr *mgr,
387 ModestAccountsWindow *self)
389 update_progress_hint (self);
393 on_row_inserted (GtkTreeModel *tree_model,
398 ModestAccountsWindow *self;
400 self = (ModestAccountsWindow *) user_data;
402 row_count_changed (self);
406 on_row_deleted (GtkTreeModel *tree_model,
410 ModestAccountsWindow *self;
412 self = (ModestAccountsWindow *) user_data;
414 row_count_changed (self);
417 static void row_count_changed (ModestAccountsWindow *self)
419 ModestAccountsWindowPrivate *priv;
423 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
424 model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->account_view));
426 count = gtk_tree_model_iter_n_children (model, NULL);
429 gtk_widget_hide (priv->account_view);
430 gtk_widget_show (priv->no_accounts_label);
432 gtk_widget_hide (priv->no_accounts_label);
433 gtk_widget_show (priv->account_view);