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-shell-banner.h>
31 #include <modest-gtk-window-mgr.h>
32 #include <modest-runtime.h>
33 #include <glib-object.h>
35 #define _DEFAULT_TIMEOUT 5000
37 /* 'private'/'protected' functions */
38 static void modest_shell_banner_class_init (gpointer klass, gpointer class_data);
39 static void modest_shell_banner_instance_init (GTypeInstance *instance, gpointer g_class);
40 static void modest_shell_banner_dispose (GObject *obj);
41 static void modest_shell_banner_finalize (GObject *obj);
42 static gboolean _on_timeout (ModestShellBanner *self);
44 typedef struct _ModestShellBannerPrivate ModestShellBannerPrivate;
45 struct _ModestShellBannerPrivate {
49 #define MODEST_SHELL_BANNER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
50 MODEST_TYPE_SHELL_BANNER, \
51 ModestShellBannerPrivate))
54 static GtkFrameClass *parent_class = NULL;
56 /* uncomment the following if you have defined any signals */
57 /* static guint signals[LAST_SIGNAL] = {0}; */
59 /************************************************************************/
62 modest_shell_banner_get_type (void)
64 static GType my_type = 0;
66 static const GTypeInfo my_info = {
67 sizeof(ModestShellBannerClass),
69 NULL, /* base finalize */
70 (GClassInitFunc) modest_shell_banner_class_init,
71 NULL, /* class finalize */
72 NULL, /* class data */
73 sizeof(ModestShellBanner),
75 (GInstanceInitFunc) modest_shell_banner_instance_init,
78 my_type = g_type_register_static (GTK_TYPE_FRAME,
86 modest_shell_banner_class_init (gpointer klass, gpointer class_data)
88 GObjectClass *gobject_class;
89 gobject_class = (GObjectClass*) klass;
91 parent_class = g_type_class_peek_parent (klass);
92 gobject_class->dispose = modest_shell_banner_dispose;
93 gobject_class->finalize = modest_shell_banner_finalize;
95 g_type_class_add_private (gobject_class, sizeof(ModestShellBannerPrivate));
101 modest_shell_banner_dispose (GObject *obj)
103 ModestShellBannerPrivate *priv;
104 priv = MODEST_SHELL_BANNER_GET_PRIVATE (obj);
105 if (priv->timeout_id) {
106 g_source_remove (priv->timeout_id);
107 priv->timeout_id = 0;
109 G_OBJECT_CLASS(parent_class)->dispose (obj);
113 modest_shell_banner_finalize (GObject *obj)
115 G_OBJECT_CLASS(parent_class)->finalize (obj);
119 modest_shell_banner_instance_init (GTypeInstance *instance, gpointer g_class)
121 ModestShellBannerPrivate *priv;
124 ModestShellBanner *self = (ModestShellBanner *) instance;
125 priv = MODEST_SHELL_BANNER_GET_PRIVATE (self);
127 gtk_frame_set_shadow_type (GTK_FRAME (self), GTK_SHADOW_OUT);
128 priv->label = gtk_label_new (NULL);
129 gtk_misc_set_alignment (GTK_MISC (priv->label), 0.5, 0.5);
130 gtk_widget_show (priv->label);
132 hbox = gtk_hbox_new (FALSE, 0);
133 gtk_box_pack_start (GTK_BOX (hbox), priv->label, TRUE, TRUE, 0);
134 gtk_widget_show (hbox);
136 gtk_container_add (GTK_CONTAINER (self), hbox);
140 modest_shell_banner_new (GtkWidget *parent)
142 return modest_shell_banner_new_with_timeout (parent, _DEFAULT_TIMEOUT);
146 modest_shell_banner_new_with_timeout (GtkWidget *parent, gint timeout)
150 ModestShellBannerPrivate *priv;
152 self = g_object_new (MODEST_TYPE_SHELL_BANNER, NULL);
153 priv = MODEST_SHELL_BANNER_GET_PRIVATE (self);
156 toplevel = gtk_widget_get_toplevel (parent);
160 if (toplevel == NULL) {
162 shell = modest_gtk_window_mgr_get_shell (MODEST_GTK_WINDOW_MGR (modest_runtime_get_window_mgr ()));
163 modest_shell_add_banner (MODEST_SHELL (shell), MODEST_SHELL_BANNER (self));
164 } else if (MODEST_IS_SHELL (toplevel)) {
165 modest_shell_add_banner (MODEST_SHELL (toplevel), MODEST_SHELL_BANNER (self));
166 } else if (GTK_IS_DIALOG (toplevel)) {
167 gtk_container_add (GTK_CONTAINER (GTK_DIALOG (toplevel)->vbox), self);
168 gtk_container_child_set (GTK_CONTAINER (GTK_DIALOG (toplevel)->vbox), self,
169 "position", 0, NULL);
172 gtk_widget_show (self);
175 priv->timeout_id = g_timeout_add (timeout, (GSourceFunc) _on_timeout, self);
177 priv->timeout_id = 0;
183 modest_shell_banner_set_icon (ModestShellBanner *self, const gchar *icon_name)
189 modest_shell_banner_set_text (ModestShellBanner *self, const gchar *label)
191 ModestShellBannerPrivate *priv;
193 priv = MODEST_SHELL_BANNER_GET_PRIVATE (self);
195 gtk_label_set_text (GTK_LABEL (priv->label), label);
199 modest_shell_banner_set_animation (ModestShellBanner *self, const gchar *animation_name)
205 _on_timeout (ModestShellBanner *self)
207 ModestShellBannerPrivate *priv;
209 priv = MODEST_SHELL_BANNER_GET_PRIVATE (self);
210 if (priv->timeout_id) {
211 priv->timeout_id = 0;
213 gtk_widget_destroy (GTK_WIDGET (self));