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 <hildon/hildon-banner.h>
31 #include <modest-platform.h>
32 #include <hildon/hildon-program.h>
33 #include <modest-maemo-utils.h>
34 #include <modest-defs.h>
35 #include <modest-ui-dimming-rules.h>
36 #include <modest-ui-dimming-manager.h>
37 #include <modest-window-priv.h>
38 #include <modest-hildon2-window.h>
39 #include <modest-ui-actions.h>
41 /* 'private'/'protected' functions */
42 static void modest_hildon2_window_class_init (gpointer klass, gpointer class_data);
43 static void modest_hildon2_window_instance_init (GTypeInstance *instance, gpointer g_class);
44 static void modest_hildon2_window_finalize (GObject *obj);
46 static gboolean on_zoom_minus_plus_not_implemented (ModestWindow *window);
47 static void setup_menu (ModestHildon2Window *self);
49 static void modest_hildon2_window_show_toolbar (ModestWindow *self,
50 gboolean show_toolbar);
51 static gboolean modest_hildon2_window_toggle_menu (HildonWindow *window,
55 typedef struct _ModestHildon2WindowPrivate ModestHildon2WindowPrivate;
56 struct _ModestHildon2WindowPrivate {
59 ModestDimmingRulesGroup *app_menu_dimming_group;
62 #define MODEST_HILDON2_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
63 MODEST_TYPE_HILDON2_WINDOW, \
64 ModestHildon2WindowPrivate))
67 static GtkWindowClass *parent_class = NULL;
69 /************************************************************************/
72 modest_hildon2_window_get_type (void)
74 static GType my_type = 0;
76 static const GTypeInfo my_info = {
77 sizeof(ModestHildon2WindowClass),
79 NULL, /* base finalize */
80 (GClassInitFunc) modest_hildon2_window_class_init,
81 NULL, /* class finalize */
82 NULL, /* class data */
83 sizeof(ModestHildon2Window),
85 (GInstanceInitFunc) modest_hildon2_window_instance_init,
88 my_type = g_type_register_static (MODEST_TYPE_WINDOW,
89 "ModestHildon2Window",
96 modest_hildon2_window_class_init (gpointer klass, gpointer class_data)
98 GObjectClass *gobject_class;
99 gobject_class = (GObjectClass*) klass;
100 ModestWindowClass *modest_window_class = (ModestWindowClass *) klass;
101 HildonWindowClass *hildon_window_class = (HildonWindowClass *) klass;
103 parent_class = g_type_class_peek_parent (klass);
104 gobject_class->finalize = modest_hildon2_window_finalize;
106 g_type_class_add_private (gobject_class, sizeof(ModestHildon2WindowPrivate));
108 hildon_window_class->toggle_menu = modest_hildon2_window_toggle_menu;
110 modest_window_class->zoom_minus_func = on_zoom_minus_plus_not_implemented;
111 modest_window_class->zoom_plus_func = on_zoom_minus_plus_not_implemented;
112 modest_window_class->show_toolbar_func = modest_hildon2_window_show_toolbar;
116 modest_hildon2_window_finalize (GObject *obj)
118 ModestHildon2WindowPrivate *priv;
120 priv = MODEST_HILDON2_WINDOW_GET_PRIVATE(obj);
122 g_object_unref (priv->app_menu_dimming_group);
123 priv->app_menu_dimming_group = NULL;
125 G_OBJECT_CLASS(parent_class)->finalize (obj);
129 modest_hildon2_window_instance_init (GTypeInstance *instance, gpointer g_class)
131 ModestHildon2Window *self = NULL;
132 ModestWindowPrivate *parent_priv = NULL;
133 ModestHildon2WindowPrivate *priv = NULL;
135 self = (ModestHildon2Window *) instance;
136 parent_priv = MODEST_WINDOW_GET_PRIVATE (self);
137 priv = MODEST_HILDON2_WINDOW_GET_PRIVATE (self);
139 parent_priv->ui_dimming_manager = modest_ui_dimming_manager_new();
140 priv->app_menu_dimming_group = modest_dimming_rules_group_new (MODEST_DIMMING_RULES_MENU, FALSE);
144 modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager,
145 priv->app_menu_dimming_group);
147 /* Dont't restore settings here,
148 * because it requires a gtk_widget_show(),
149 * and we don't want to do that until later,
150 * so that the UI is not visible for non-menu D-Bus activation.
155 on_zoom_minus_plus_not_implemented (ModestWindow *window)
157 g_return_val_if_fail (MODEST_IS_HILDON2_WINDOW (window), FALSE);
159 hildon_banner_show_information (NULL, NULL, dgettext("hildon-common-strings", "ckct_ib_cannot_zoom_here"));
165 modest_hildon2_window_add_button_to_menu (ModestHildon2Window *self,
167 ModestDimmingCallback dimming_callback)
169 ModestHildon2WindowPrivate *priv;
171 g_return_if_fail (MODEST_IS_HILDON2_WINDOW(self));
172 g_return_if_fail (GTK_IS_BUTTON (button));
173 priv = MODEST_HILDON2_WINDOW_GET_PRIVATE (self);
175 if (dimming_callback)
176 modest_dimming_rules_group_add_widget_rule (priv->app_menu_dimming_group,
178 (GCallback) dimming_callback,
179 MODEST_WINDOW (self));
180 hildon_app_menu_append (HILDON_APP_MENU (priv->app_menu), GTK_BUTTON (button));
184 modest_hildon2_window_add_to_menu (ModestHildon2Window *self,
186 ModestHildon2AppMenuCallback callback,
187 ModestDimmingCallback dimming_callback)
189 ModestHildon2WindowPrivate *priv = NULL;
192 g_return_if_fail (MODEST_IS_HILDON2_WINDOW(self));
193 g_return_if_fail (label && label[0] != '\0');
194 g_return_if_fail (callback != NULL);
196 priv = MODEST_HILDON2_WINDOW_GET_PRIVATE (self);
198 button = gtk_button_new_with_label (label);
199 g_signal_connect_after (G_OBJECT (button), "clicked",
200 G_CALLBACK (callback), (gpointer) self);
202 modest_hildon2_window_add_button_to_menu (self, GTK_BUTTON (button), dimming_callback);
205 static void setup_menu (ModestHildon2Window *self)
207 ModestHildon2WindowPrivate *priv = NULL;
209 g_return_if_fail (MODEST_IS_HILDON2_WINDOW(self));
211 priv = MODEST_HILDON2_WINDOW_GET_PRIVATE (self);
213 priv->app_menu = hildon_app_menu_new ();
215 /* we expect that the app menu is filled in children using the expected
216 * add_to_menu methods */
218 hildon_stackable_window_set_main_menu (HILDON_STACKABLE_WINDOW (self),
219 HILDON_APP_MENU (priv->app_menu));
223 modest_hildon2_window_toggle_menu (HildonWindow *window,
227 ModestHildon2WindowPrivate *priv = NULL;
229 priv = MODEST_HILDON2_WINDOW_GET_PRIVATE (window);
231 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
233 gtk_widget_queue_resize (priv->app_menu);
235 return HILDON_WINDOW_CLASS (parent_class)->toggle_menu (window, button, time);
239 modest_hildon2_window_show_toolbar (ModestWindow *self,
240 gboolean show_toolbar)
242 /* Empty implementation: Hildon 2.2 implementation
243 * doesn't switch toolbar visibility */