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 gboolean on_zoom_minus_plus_not_implemented (ModestWindow *window);
59 static void on_account_activated (GtkTreeView *treeview,
61 GtkTreeViewColumn *column,
62 ModestAccountsWindow *accounts_window);
63 static void add_to_menu (ModestAccountsWindow *self,
67 ModestDimmingRulesGroup *group,
68 GCallback dimming_callback);
69 static void setup_menu (ModestAccountsWindow *self,
70 ModestDimmingRulesGroup *group);
72 static void modest_accounts_window_show_toolbar (ModestWindow *self,
73 gboolean show_toolbar);
74 static gboolean modest_accounts_window_toggle_menu (HildonWindow *window,
78 typedef struct _ModestAccountsWindowPrivate ModestAccountsWindowPrivate;
79 struct _ModestAccountsWindowPrivate {
81 GtkWidget *account_view;
88 osso_display_state_t display_state;
90 #define MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
91 MODEST_TYPE_ACCOUNTS_WINDOW, \
92 ModestAccountsWindowPrivate))
95 static GtkWindowClass *parent_class = NULL;
97 /************************************************************************/
100 modest_accounts_window_get_type (void)
102 static GType my_type = 0;
104 static const GTypeInfo my_info = {
105 sizeof(ModestAccountsWindowClass),
106 NULL, /* base init */
107 NULL, /* base finalize */
108 (GClassInitFunc) modest_accounts_window_class_init,
109 NULL, /* class finalize */
110 NULL, /* class data */
111 sizeof(ModestAccountsWindow),
113 (GInstanceInitFunc) modest_accounts_window_instance_init,
116 my_type = g_type_register_static (MODEST_TYPE_WINDOW,
117 "ModestAccountsWindow",
124 modest_accounts_window_class_init (ModestAccountsWindowClass *klass)
126 GObjectClass *gobject_class;
127 gobject_class = (GObjectClass*) klass;
128 ModestWindowClass *modest_window_class = (ModestWindowClass *) klass;
129 HildonWindowClass *hildon_window_class = (HildonWindowClass *) klass;
131 parent_class = g_type_class_peek_parent (klass);
132 gobject_class->finalize = modest_accounts_window_finalize;
134 g_type_class_add_private (gobject_class, sizeof(ModestAccountsWindowPrivate));
136 hildon_window_class->toggle_menu = modest_accounts_window_toggle_menu;
138 modest_window_class->zoom_minus_func = on_zoom_minus_plus_not_implemented;
139 modest_window_class->zoom_plus_func = on_zoom_minus_plus_not_implemented;
140 modest_window_class->show_toolbar_func = modest_accounts_window_show_toolbar;
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;
152 priv->display_state = OSSO_DISPLAY_ON;
154 priv->account_view = NULL;
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;
190 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(self);
193 priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
194 G_OBJECT (priv->account_view), "row-activated",
195 G_CALLBACK (on_account_activated), self);
199 /* we don't register this in sighandlers, as it should be run after disconnecting all signals,
200 * in destroy stage */
206 osso_display_event_cb (osso_display_state_t state,
209 ModestAccountsWindowPrivate *priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (data);
211 priv->display_state = state;
213 /* Stop blinking if the screen becomes on */
214 if (priv->display_state == OSSO_DISPLAY_ON)
215 modest_platform_remove_new_mail_notifications (TRUE);
219 modest_accounts_window_new (void)
221 ModestAccountsWindow *self = NULL;
222 ModestAccountsWindowPrivate *priv = NULL;
224 GdkPixbuf *window_icon;
226 ModestWindowPrivate *parent_priv = NULL;
227 ModestDimmingRulesGroup *menu_rules_group = NULL;
229 self = MODEST_ACCOUNTS_WINDOW(g_object_new(MODEST_TYPE_ACCOUNTS_WINDOW, NULL));
230 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE(self);
231 parent_priv = MODEST_WINDOW_GET_PRIVATE(self);
233 parent_priv->ui_dimming_manager = modest_ui_dimming_manager_new();
234 menu_rules_group = modest_dimming_rules_group_new (MODEST_DIMMING_RULES_MENU, FALSE);
236 pannable = hildon_pannable_area_new ();
237 priv->account_view = GTK_WIDGET (modest_account_view_new (modest_runtime_get_account_mgr ()));
239 setup_menu (self, menu_rules_group);
241 modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager, menu_rules_group);
242 g_object_unref (menu_rules_group);
244 gtk_container_add (GTK_CONTAINER (pannable), priv->account_view);
245 gtk_container_add (GTK_CONTAINER (self), pannable);
247 gtk_widget_show (priv->account_view);
248 gtk_widget_show (pannable);
250 connect_signals (MODEST_ACCOUNTS_WINDOW (self));
252 /* Load previous osso state, for instance if we are being restored from
254 modest_osso_load_state ();
256 /* Get device name */
257 modest_maemo_utils_get_device_name ();
259 app = hildon_program_get_instance ();
260 hildon_program_add_window (app, HILDON_WINDOW (self));
262 /* Set window icon */
263 window_icon = modest_platform_get_icon (MODEST_APP_ICON, MODEST_ICON_SIZE_BIG);
265 gtk_window_set_icon (GTK_WINDOW (self), window_icon);
266 g_object_unref (window_icon);
269 /* Listen for changes in the screen, we don't want to show a
270 led pattern when the display is on for example */
271 osso_hw_set_display_event_cb (modest_maemo_utils_get_osso_context (),
272 osso_display_event_cb,
275 /* Dont't restore settings here,
276 * because it requires a gtk_widget_show(),
277 * and we don't want to do that until later,
278 * so that the UI is not visible for non-menu D-Bus activation.
281 return MODEST_WINDOW(self);
285 on_zoom_minus_plus_not_implemented (ModestWindow *window)
287 g_return_val_if_fail (MODEST_IS_ACCOUNTS_WINDOW (window), FALSE);
289 hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_cannot_zoom_here"));
295 modest_accounts_window_screen_is_on (ModestAccountsWindow *self)
297 ModestAccountsWindowPrivate *priv = NULL;
299 g_return_val_if_fail (MODEST_IS_ACCOUNTS_WINDOW(self), FALSE);
301 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
303 return (priv->display_state == OSSO_DISPLAY_ON) ? TRUE : FALSE;
307 modest_accounts_window_get_account_view (ModestAccountsWindow *self)
309 ModestAccountsWindowPrivate *priv = NULL;
311 g_return_val_if_fail (MODEST_IS_ACCOUNTS_WINDOW(self), FALSE);
313 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
315 return MODEST_ACCOUNT_VIEW (priv->account_view);
318 static void add_to_menu (ModestAccountsWindow *self,
322 ModestDimmingRulesGroup *group,
323 GCallback dimming_callback)
327 button = gtk_button_new_with_label (label);
328 g_signal_connect_after (G_OBJECT (button), "clicked",
329 callback, (gpointer) self);
330 if (dimming_callback)
331 modest_dimming_rules_group_add_widget_rule (group,
334 MODEST_WINDOW (self));
335 hildon_app_menu_append (menu, GTK_BUTTON (button));
338 static void setup_menu (ModestAccountsWindow *self, ModestDimmingRulesGroup *group)
340 ModestAccountsWindowPrivate *priv = NULL;
342 g_return_if_fail (MODEST_IS_ACCOUNTS_WINDOW(self));
344 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
346 priv->app_menu = hildon_app_menu_new ();
348 /* Settings menu buttons */
349 add_to_menu (self, HILDON_APP_MENU (priv->app_menu), _("TODO: new account"),
350 G_CALLBACK (modest_ui_actions_on_new_account),
352 add_to_menu (self, HILDON_APP_MENU (priv->app_menu), _("TODO: edit accounts"),
353 G_CALLBACK (modest_ui_actions_on_accounts),
355 add_to_menu (self, HILDON_APP_MENU (priv->app_menu), _("mcen_me_inbox_options"),
356 G_CALLBACK (modest_ui_actions_on_settings),
358 add_to_menu (self, HILDON_APP_MENU (priv->app_menu), _("mcen_me_inbox_globalsmtpservers"),
359 G_CALLBACK (modest_ui_actions_on_smtp_servers),
360 group, G_CALLBACK (modest_ui_dimming_rules_on_tools_smtp_servers));
361 add_to_menu (self, HILDON_APP_MENU (priv->app_menu), _("mcen_me_viewer_newemail"),
362 G_CALLBACK (modest_ui_actions_on_new_msg),
363 group, G_CALLBACK (modest_ui_dimming_rules_on_new_msg));
364 add_to_menu (self, HILDON_APP_MENU (priv->app_menu), _("mcen_me_inbox_sendandreceive"),
365 G_CALLBACK (modest_ui_actions_on_send_receive),
366 group, G_CALLBACK (modest_ui_dimming_rules_on_send_receive_all));
367 add_to_menu (self, HILDON_APP_MENU (priv->app_menu), _("mcen_me_outbox_cancelsend"),
368 G_CALLBACK (modest_ui_actions_cancel_send),
369 group, G_CALLBACK (modest_ui_dimming_rules_on_cancel_sending_all));
371 hildon_stackable_window_set_main_menu (HILDON_STACKABLE_WINDOW (self),
372 HILDON_APP_MENU (priv->app_menu));
376 modest_accounts_window_toggle_menu (HildonWindow *window,
380 ModestAccountsWindowPrivate *priv = NULL;
382 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (window);
384 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
386 gtk_widget_queue_resize (priv->app_menu);
388 return HILDON_WINDOW_CLASS (parent_class)->toggle_menu (window, button, time);
394 on_account_activated (GtkTreeView *account_view,
396 GtkTreeViewColumn *column,
397 ModestAccountsWindow *self)
399 ModestAccountsWindowPrivate *priv;
401 GtkWidget *folder_window;
403 priv = MODEST_ACCOUNTS_WINDOW_GET_PRIVATE (self);
405 account_name = modest_account_view_get_path_account (MODEST_ACCOUNT_VIEW (priv->account_view), path);
409 folder_window = GTK_WIDGET (modest_folder_window_new (NULL));
410 modest_window_mgr_register_window (modest_runtime_get_window_mgr (),
411 MODEST_WINDOW (folder_window),
412 MODEST_WINDOW (self));
413 modest_folder_window_set_account (MODEST_FOLDER_WINDOW (folder_window), account_name);
414 gtk_widget_show (folder_window);
415 g_free (account_name);
420 modest_accounts_window_show_toolbar (ModestWindow *self,
421 gboolean show_toolbar)
423 /* Empty implementation, this view does not show any