1 /* Copyright (c) 2006, 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-window.h"
31 #include "modest-window-priv.h"
32 #include "modest-ui-actions.h"
33 #include "modest-tny-platform-factory.h"
34 #include "modest-runtime.h"
35 #include "modest-window-mgr.h"
37 /* 'private'/'protected' functions */
38 static void modest_window_class_init (ModestWindowClass *klass);
39 static void modest_window_init (ModestWindow *obj);
40 static void modest_window_finalize (GObject *obj);
42 static void modest_window_set_zoom_default (ModestWindow *window,
44 static gdouble modest_window_get_zoom_default (ModestWindow *window);
45 static gboolean modest_window_zoom_plus_default (ModestWindow *window);
46 static gboolean modest_window_zoom_minus_default (ModestWindow *window);
47 static void modest_window_show_toolbar_default (ModestWindow *window,
48 gboolean show_toolbar);
50 static gboolean on_key_pressed (GtkWidget *self, GdkEventKey *event, gpointer user_data);
59 static GObjectClass *parent_class = NULL;
61 /* uncomment the following if you have defined any signals */
62 /* static guint signals[LAST_SIGNAL] = {0}; */
65 modest_window_get_type (void)
67 static GType my_type = 0;
68 static GType parent_type = 0;
70 static const GTypeInfo my_info = {
71 sizeof(ModestWindowClass),
73 NULL, /* base finalize */
74 (GClassInitFunc) modest_window_class_init,
75 NULL, /* class finalize */
76 NULL, /* class data */
79 (GInstanceInitFunc) modest_window_init,
82 #ifdef MODEST_PLATFORM_MAEMO
83 parent_type = HILDON_TYPE_WINDOW;
85 parent_type = GTK_TYPE_WINDOW;
87 my_type = g_type_register_static (parent_type,
90 G_TYPE_FLAG_ABSTRACT);
96 modest_window_class_init (ModestWindowClass *klass)
98 GObjectClass *gobject_class;
99 gobject_class = (GObjectClass*) klass;
101 parent_class = g_type_class_peek_parent (klass);
102 gobject_class->finalize = modest_window_finalize;
104 klass->set_zoom_func = modest_window_set_zoom_default;
105 klass->get_zoom_func = modest_window_get_zoom_default;
106 klass->zoom_plus_func = modest_window_zoom_plus_default;
107 klass->zoom_minus_func = modest_window_zoom_minus_default;
108 klass->show_toolbar_func = modest_window_show_toolbar_default;
110 g_type_class_add_private (gobject_class, sizeof(ModestWindowPrivate));
114 modest_window_init (ModestWindow *obj)
116 ModestWindowPrivate *priv;
118 priv = MODEST_WINDOW_GET_PRIVATE(obj);
120 priv->ui_manager = NULL;
121 priv->ui_dimming_manager = NULL;
122 priv->toolbar = NULL;
123 priv->menubar = NULL;
125 priv->active_account = NULL;
127 /* Connect signals */
128 g_signal_connect (G_OBJECT (obj),
130 G_CALLBACK (on_key_pressed), NULL);
134 modest_window_finalize (GObject *obj)
136 ModestWindowPrivate *priv;
138 priv = MODEST_WINDOW_GET_PRIVATE(obj);
140 if (priv->ui_manager) {
141 g_object_unref (G_OBJECT(priv->ui_manager));
142 priv->ui_manager = NULL;
144 if (priv->ui_dimming_manager) {
145 g_object_unref (G_OBJECT(priv->ui_dimming_manager));
146 priv->ui_dimming_manager = NULL;
149 g_free (priv->active_account);
151 G_OBJECT_CLASS(parent_class)->finalize (obj);
157 modest_window_get_active_account (ModestWindow *self)
159 g_return_val_if_fail (self, NULL);
161 return MODEST_WINDOW_GET_PRIVATE(self)->active_account;
165 modest_window_set_active_account (ModestWindow *self, const gchar *active_account)
167 ModestWindowPrivate *priv;
169 priv = MODEST_WINDOW_GET_PRIVATE(self);
171 if (active_account == priv->active_account)
174 g_free (priv->active_account);
175 priv->active_account = NULL;
177 priv->active_account = g_strdup (active_account);
182 modest_window_check_dimming_rules (ModestWindow *self)
184 ModestWindowPrivate *priv;
186 g_return_if_fail (MODEST_IS_WINDOW (self));
187 priv = MODEST_WINDOW_GET_PRIVATE(self);
189 modest_ui_dimming_manager_process_dimming_rules (priv->ui_dimming_manager);
193 modest_window_check_dimming_rules_group (ModestWindow *self,
194 const gchar *group_name)
196 ModestWindowPrivate *priv;
198 g_return_if_fail (MODEST_IS_WINDOW (self));
199 priv = MODEST_WINDOW_GET_PRIVATE(self);
201 modest_ui_dimming_manager_process_dimming_rules_group (priv->ui_dimming_manager, group_name);
205 modest_window_get_action (ModestWindow *window,
206 const gchar *action_path)
208 GtkAction *action = NULL;
209 ModestWindowPrivate *priv;
211 g_return_val_if_fail (MODEST_IS_WINDOW (window), NULL);
212 priv = MODEST_WINDOW_GET_PRIVATE(window);
214 action = gtk_ui_manager_get_action (priv->ui_manager, action_path);
220 modest_window_get_action_widget (ModestWindow *window,
221 const gchar *action_path)
223 GtkWidget *widget = NULL;
224 ModestWindowPrivate *priv;
226 g_return_val_if_fail (MODEST_IS_WINDOW (window), NULL);
227 priv = MODEST_WINDOW_GET_PRIVATE(window);
229 widget = gtk_ui_manager_get_widget (priv->ui_manager, action_path);
235 modest_window_set_zoom (ModestWindow *window,
238 MODEST_WINDOW_GET_CLASS (window)->set_zoom_func (window, zoom);
243 modest_window_get_zoom (ModestWindow *window)
245 return MODEST_WINDOW_GET_CLASS (window)->get_zoom_func (window);
249 modest_window_zoom_plus (ModestWindow *window)
251 return MODEST_WINDOW_GET_CLASS (window)->zoom_plus_func (window);
255 modest_window_zoom_minus (ModestWindow *window)
257 return MODEST_WINDOW_GET_CLASS (window)->zoom_minus_func (window);
261 modest_window_show_toolbar (ModestWindow *window,
262 gboolean show_toolbar)
264 MODEST_WINDOW_GET_CLASS (window)->show_toolbar_func (window,
269 /* Default implementations */
272 modest_window_set_zoom_default (ModestWindow *window,
275 g_warning ("modest: You should implement %s", __FUNCTION__);
280 modest_window_get_zoom_default (ModestWindow *window)
282 g_warning ("modest: You should implement %s", __FUNCTION__);
287 modest_window_zoom_plus_default (ModestWindow *window)
289 g_warning ("modest: You should implement %s", __FUNCTION__);
294 modest_window_zoom_minus_default (ModestWindow *window)
296 g_warning ("modest: You should implement %s", __FUNCTION__);
301 modest_window_show_toolbar_default (ModestWindow *window,
302 gboolean show_toolbar)
304 g_warning ("modest: You should implement %s", __FUNCTION__);
310 modest_window_save_state (ModestWindow *window)
312 ModestWindowClass *klass = MODEST_WINDOW_GET_CLASS (window);
313 if (klass->save_state_func)
314 klass->save_state_func (window);
318 on_key_pressed (GtkWidget *self,
322 ModestWindowMgr *mgr = NULL;
324 mgr = modest_runtime_get_window_mgr ();
326 switch (event->keyval) {
328 modest_ui_actions_on_change_fullscreen (NULL, MODEST_WINDOW(self));
331 modest_ui_actions_on_zoom_plus (NULL, MODEST_WINDOW(self));
334 modest_ui_actions_on_zoom_minus (NULL, MODEST_WINDOW(self));
337 if (modest_window_mgr_get_fullscreen_mode (mgr))
338 modest_ui_actions_on_change_fullscreen (NULL, MODEST_WINDOW(self));