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-folder-window.h>
31 #include <modest-osso-state-saving.h>
33 #include <hildon/hildon-pannable-area.h>
34 #include <modest-window-mgr.h>
35 #include <modest-signal-mgr.h>
36 #include <modest-runtime.h>
37 #include <modest-platform.h>
38 #include <modest-maemo-utils.h>
39 #include <modest-icon-names.h>
40 #include <modest-ui-constants.h>
41 #include <modest-defs.h>
42 #include <hildon/hildon-program.h>
43 #include <hildon/hildon-banner.h>
44 #include <tny-account-store-view.h>
46 /* 'private'/'protected' functions */
47 static void modest_folder_window_class_init (ModestFolderWindowClass *klass);
48 static void modest_folder_window_init (ModestFolderWindow *obj);
49 static void modest_folder_window_finalize (GObject *obj);
51 static void connect_signals (ModestFolderWindow *self);
52 static void modest_folder_window_disconnect_signals (ModestWindow *self);
54 static gboolean on_zoom_minus_plus_not_implemented (ModestWindow *window);
56 typedef struct _ModestFolderWindowPrivate ModestFolderWindowPrivate;
57 struct _ModestFolderWindowPrivate {
59 GtkWidget *folder_view;
65 osso_display_state_t display_state;
67 #define MODEST_FOLDER_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
68 MODEST_TYPE_FOLDER_WINDOW, \
69 ModestFolderWindowPrivate))
72 static GtkWindowClass *parent_class = NULL;
74 /************************************************************************/
77 modest_folder_window_get_type (void)
79 static GType my_type = 0;
81 static const GTypeInfo my_info = {
82 sizeof(ModestFolderWindowClass),
84 NULL, /* base finalize */
85 (GClassInitFunc) modest_folder_window_class_init,
86 NULL, /* class finalize */
87 NULL, /* class data */
88 sizeof(ModestFolderWindow),
90 (GInstanceInitFunc) modest_folder_window_init,
93 my_type = g_type_register_static (MODEST_TYPE_WINDOW,
101 modest_folder_window_class_init (ModestFolderWindowClass *klass)
103 GObjectClass *gobject_class;
104 gobject_class = (GObjectClass*) klass;
105 ModestWindowClass *modest_window_class = (ModestWindowClass *) klass;
107 parent_class = g_type_class_peek_parent (klass);
108 gobject_class->finalize = modest_folder_window_finalize;
110 g_type_class_add_private (gobject_class, sizeof(ModestFolderWindowPrivate));
112 modest_window_class->zoom_minus_func = on_zoom_minus_plus_not_implemented;
113 modest_window_class->zoom_plus_func = on_zoom_minus_plus_not_implemented;
114 modest_window_class->disconnect_signals_func = modest_folder_window_disconnect_signals;
118 modest_folder_window_init (ModestFolderWindow *obj)
120 ModestFolderWindowPrivate *priv;
122 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(obj);
124 priv->sighandlers = NULL;
125 priv->display_state = OSSO_DISPLAY_ON;
127 priv->folder_view = NULL;
129 modest_window_mgr_register_help_id (modest_runtime_get_window_mgr(),
131 "applications_email_folderview");
135 modest_folder_window_finalize (GObject *obj)
137 ModestFolderWindowPrivate *priv;
139 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(obj);
141 /* Sanity check: shouldn't be needed, the window mgr should
142 call this function before */
143 modest_folder_window_disconnect_signals (MODEST_WINDOW (obj));
145 G_OBJECT_CLASS(parent_class)->finalize (obj);
149 modest_folder_window_disconnect_signals (ModestWindow *self)
151 ModestFolderWindowPrivate *priv;
152 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(self);
154 modest_signal_mgr_disconnect_all_and_destroy (priv->sighandlers);
155 priv->sighandlers = NULL;
159 connect_signals (ModestFolderWindow *self)
161 ModestFolderWindowPrivate *priv;
163 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(self);
167 /* TODO: connect folder view activate */
171 /* we don't register this in sighandlers, as it should be run after disconnecting all signals,
172 * in destroy stage */
178 osso_display_event_cb (osso_display_state_t state,
181 ModestFolderWindowPrivate *priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (data);
183 priv->display_state = state;
185 /* Stop blinking if the screen becomes on */
186 if (priv->display_state == OSSO_DISPLAY_ON)
187 modest_platform_remove_new_mail_notifications (TRUE);
191 modest_folder_window_new (TnyFolderStoreQuery *query)
193 ModestFolderWindow *self = NULL;
194 ModestFolderWindowPrivate *priv = NULL;
196 GdkPixbuf *window_icon;
199 self = MODEST_FOLDER_WINDOW(g_object_new(MODEST_TYPE_FOLDER_WINDOW, NULL));
200 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE(self);
201 pannable = hildon_pannable_area_new ();
202 priv->folder_view = modest_platform_create_folder_view (query);
204 /* Set account store */
205 tny_account_store_view_set_account_store (TNY_ACCOUNT_STORE_VIEW (priv->folder_view),
206 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
208 gtk_container_add (GTK_CONTAINER (pannable), priv->folder_view);
209 gtk_container_add (GTK_CONTAINER (self), pannable);
211 gtk_widget_show (priv->folder_view);
212 gtk_widget_show (pannable);
214 connect_signals (MODEST_FOLDER_WINDOW (self));
216 /* Load previous osso state, for instance if we are being restored from
218 modest_osso_load_state ();
220 /* Get device name */
221 modest_maemo_utils_get_device_name ();
223 app = hildon_program_get_instance ();
224 hildon_program_add_window (app, HILDON_WINDOW (self));
226 /* Set window icon */
227 window_icon = modest_platform_get_icon (MODEST_APP_ICON, MODEST_ICON_SIZE_BIG);
229 gtk_window_set_icon (GTK_WINDOW (self), window_icon);
230 g_object_unref (window_icon);
233 /* Listen for changes in the screen, we don't want to show a
234 led pattern when the display is on for example */
235 osso_hw_set_display_event_cb (modest_maemo_utils_get_osso_context (),
236 osso_display_event_cb,
239 /* Dont't restore settings here,
240 * because it requires a gtk_widget_show(),
241 * and we don't want to do that until later,
242 * so that the UI is not visible for non-menu D-Bus activation.
245 return MODEST_WINDOW(self);
249 on_zoom_minus_plus_not_implemented (ModestWindow *window)
251 g_return_val_if_fail (MODEST_IS_FOLDER_WINDOW (window), FALSE);
253 hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_cannot_zoom_here"));
259 modest_folder_window_screen_is_on (ModestFolderWindow *self)
261 ModestFolderWindowPrivate *priv = NULL;
263 g_return_val_if_fail (MODEST_IS_FOLDER_WINDOW(self), FALSE);
265 priv = MODEST_FOLDER_WINDOW_GET_PRIVATE (self);
267 return (priv->display_state == OSSO_DISPLAY_ON) ? TRUE : FALSE;