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-platform.h>
31 #include "modest-marshal.h"
32 #include <modest-defs.h>
33 #include <modest-ui-dimming-rules.h>
34 #include <modest-ui-dimming-manager.h>
35 #include <modest-window-priv.h>
36 #include <modest-shell-window.h>
37 #include <modest-ui-actions.h>
38 #include "modest-text-utils.h"
40 /* 'private'/'protected' functions */
41 static void modest_shell_window_class_init (gpointer klass, gpointer class_data);
42 static void modest_shell_window_instance_init (GTypeInstance *instance, gpointer g_class);
43 static void modest_shell_window_dispose (GObject *obj);
45 static gboolean on_zoom_minus_plus_not_implemented (ModestWindow *window);
46 static void modest_shell_window_show_progress (ModestWindow *window,
48 static void setup_menu (ModestShellWindow *self);
50 static void modest_shell_window_show_toolbar (ModestWindow *self,
51 gboolean show_toolbar);
52 static void modest_shell_window_add_toolbar (ModestWindow *self,
54 static void modest_shell_window_add_to_menu (ModestWindow *window,
56 const gchar *accelerator,
57 ModestWindowMenuCallback callback,
58 ModestDimmingCallback dimming_callback);
59 static void modest_shell_window_add_item_to_menu (ModestWindow *window,
61 ModestDimmingCallback dimming_callback);
62 static void modest_shell_window_set_title (ModestWindow *self,
65 typedef struct _ModestShellWindowPrivate ModestShellWindowPrivate;
66 struct _ModestShellWindowPrivate {
69 ModestDimmingRulesGroup *app_menu_dimming_group;
70 GtkAccelGroup *accel_group;
73 #define MODEST_SHELL_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
74 MODEST_TYPE_SHELL_WINDOW, \
75 ModestShellWindowPrivate))
78 static GtkWindowClass *parent_class = NULL;
80 /* uncomment the following if you have defined any signals */
81 static guint signals[LAST_SIGNAL] = {0};
83 /************************************************************************/
86 modest_shell_window_get_type (void)
88 static GType my_type = 0;
90 static const GTypeInfo my_info = {
91 sizeof(ModestShellWindowClass),
93 NULL, /* base finalize */
94 (GClassInitFunc) modest_shell_window_class_init,
95 NULL, /* class finalize */
96 NULL, /* class data */
97 sizeof(ModestShellWindow),
99 (GInstanceInitFunc) modest_shell_window_instance_init,
102 my_type = g_type_register_static (MODEST_TYPE_WINDOW,
110 modest_shell_window_class_init (gpointer klass, gpointer class_data)
112 GObjectClass *gobject_class;
113 gobject_class = (GObjectClass*) klass;
114 ModestWindowClass *modest_window_class = (ModestWindowClass *) klass;
115 HildonWindowClass *hildon_window_class = (HildonWindowClass *) klass;
117 parent_class = g_type_class_peek_parent (klass);
118 gobject_class->dispose = modest_shell_window_dispose;
120 g_type_class_add_private (gobject_class, sizeof(ModestShellWindowPrivate));
122 modest_window_class->zoom_minus_func = on_zoom_minus_plus_not_implemented;
123 modest_window_class->zoom_plus_func = on_zoom_minus_plus_not_implemented;
124 modest_window_class->show_toolbar_func = modest_shell_window_show_toolbar;
125 modest_window_class->add_toolbar_func = modest_shell_window_add_toolbar;
126 modest_window_class->add_to_menu_func = modest_shell_window_add_to_menu;
127 modest_window_class->add_item_to_menu_func = modest_shell_window_add_item_to_menu;
128 modest_window_class->set_title_func = modest_shell_window_set_title;
129 modest_window_class->show_progress_func = modest_shell_window_show_progress;
134 modest_shell_window_dispose (GObject *obj)
136 ModestShellWindowPrivate *priv;
138 priv = MODEST_SHELL_WINDOW_GET_PRIVATE(obj);
140 if (priv->app_menu_dimming_group) {
141 g_object_unref (priv->app_menu_dimming_group);
142 priv->app_menu_dimming_group = NULL;
145 G_OBJECT_CLASS(parent_class)->dispose (obj);
149 modest_shell_window_instance_init (GTypeInstance *instance, gpointer g_class)
151 ModestShellWindow *self = NULL;
152 ModestWindowPrivate *parent_priv = NULL;
153 ModestShellWindowPrivate *priv = NULL;
155 self = (ModestShellWindow *) instance;
156 parent_priv = MODEST_WINDOW_GET_PRIVATE (self);
157 priv = MODEST_SHELL_WINDOW_GET_PRIVATE (self);
159 priv->accel_group = gtk_accel_group_new ();
161 priv->app_menu_dimming_group = modest_dimming_rules_group_new (MODEST_DIMMING_RULES_MENU, FALSE);
162 gtk_window_add_accel_group (GTK_WINDOW (self), priv->accel_group);
166 modest_ui_dimming_manager_insert_rules_group (parent_priv->ui_dimming_manager,
167 priv->app_menu_dimming_group);
169 /* Dont't restore settings here,
170 * because it requires a gtk_widget_show(),
171 * and we don't want to do that until later,
172 * so that the UI is not visible for non-menu D-Bus activation.
177 on_zoom_minus_plus_not_implemented (ModestWindow *window)
179 g_return_val_if_fail (MODEST_IS_SHELL_WINDOW (window), FALSE);
181 modest_platform_information_banner (NULL, NULL, _CS("ckct_ib_cannot_zoom_here"));
185 modest_shell_window_add_item_to_menu (ModestWindow *self,
187 ModestDimmingCallback dimming_callback)
189 ModestShellWindowPrivate *priv;
192 g_return_if_fail (MODEST_IS_SHELL_WINDOW(self));
193 g_return_if_fail (GTK_IS_BUTTON (button));
194 priv = MODEST_SHELL_WINDOW_GET_PRIVATE (self);
196 modest_ui_dimming_manager_set_widget_dimming_mode (GTK_WIDGET (button),
197 MODEST_UI_DIMMING_MODE_HIDE);
199 if (dimming_callback)
200 modest_dimming_rules_group_add_widget_rule (priv->app_menu_dimming_group,
202 (GCallback) dimming_callback,
203 MODEST_WINDOW (self));
204 menu = modest_shell_get_menu (MODEST_SHELL (priv->shell), self);
205 gtk_menu_shell_append (GTK_MENU_SHELL (menu), button);
207 gtk_widget_show (GTK_WIDGET (button));
211 modest_shell_window_add_to_menu (ModestWindow *self,
213 const gchar *accelerator,
214 ModestWindowMenuCallback callback,
215 ModestDimmingCallback dimming_callback)
217 ModestShellWindowPrivate *priv = NULL;
218 GtkWidget *menu_item;
221 g_return_if_fail (MODEST_IS_SHELL_WINDOW(self));
222 g_return_if_fail (label && label[0] != '\0');
223 g_return_if_fail (callback != NULL);
225 priv = MODEST_SHELL_WINDOW_GET_PRIVATE (self);
227 menu_item = gtk_menu_item_new_with_label (label);
228 g_signal_connect_after (G_OBJECT (button), "activate-item",
229 G_CALLBACK (callback), (gpointer) self);
231 if (accelerator != NULL) {
233 GdkModifierType accel_mods;
235 gtk_accelerator_parse (accelerator, &accel_key, &accel_mods);
236 gtk_widget_add_accelerator (menu_item, "clicked", priv->accel_group,
237 accel_key, accel_mods, 0);
240 menu = modest_shell_get_menu (MODEST_SHELL (priv->shell), MODEST_WINDOW (self));
241 gtk_menu_shell_append (GTK_MENU (menu), menu_item);
245 modest_shell_window_show_toolbar (ModestWindow *self,
246 gboolean show_toolbar)
248 /* Empty implementation: Hildon 2.2 implementation
249 * doesn't switch toolbar visibility */
253 modest_shell_window_add_toolbar (ModestWindow *self,
256 gtk_box_pack_end (GTK_BOX (self), toolbar, FALSE, FALSE, 0);
260 modest_shell_window_set_title (ModestWindow *self,
263 ModestShellWindowPrivate *priv = NULL;
265 priv = MODEST_SHELL_WINDOW_GET_PRIVATE (self);
266 modest_shell_set_title (MODEST_SHELL (priv->shell),
267 MODEST_WINDOW (self),
272 modest_shell_window_show_progress (ModestWindow *self,
275 modest_shell_show_progress (MODEST_SHELL (priv->shell),
281 modest_shell_window_set_shell (ModestShellWindow *self,
284 ModestShellWindowPrivate *priv = NULL;
286 priv = MODEST_SHELL_WINDOW_GET_PRIVATE (self);
289 modest_shell_delete_window (MODEST_SHELL (shell), MODEST_WINDOW (self));
290 g_object_unref (priv->shell);
293 priv->shell = g_object_ref (shell);