1 /* Copyright (c) 2009, 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.
31 #include <modest-shell.h>
32 #include <modest-shell-window.h>
34 /* 'private'/'protected' functions */
35 static void modest_shell_class_init (ModestShellClass *klass);
36 static void modest_shell_instance_init (ModestShell *obj);
37 static void modest_shell_finalize (GObject *obj);
40 typedef struct _ModestShellPrivate ModestShellPrivate;
41 struct _ModestShellPrivate {
45 #define MODEST_SHELL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
49 static GObjectClass *parent_class = NULL;
52 modest_shell_get_type (void)
54 static GType my_type = 0;
56 static const GTypeInfo my_info = {
57 sizeof(ModestShellClass),
59 NULL, /* base finalize */
60 (GClassInitFunc) modest_shell_class_init,
61 NULL, /* class finalize */
62 NULL, /* class data */
65 (GInstanceInitFunc) modest_shell_instance_init,
68 my_type = g_type_register_static (GTK_TYPE_WINDOW,
76 modest_shell_class_init (ModestShellClass *klass)
78 GObjectClass *gobject_class;
80 gobject_class = (GObjectClass*) klass;
82 parent_class = g_type_class_peek_parent (klass);
83 gobject_class->finalize = modest_shell_finalize;
85 g_type_class_add_private (gobject_class, sizeof(ModestShellPrivate));
90 modest_shell_instance_init (ModestShell *obj)
92 ModestShellPrivate *priv;
94 priv = MODEST_SHELL_GET_PRIVATE(obj);
96 priv->main_vbox = gtk_vbox_new (FALSE, 0);
97 gtk_widget_show (priv->main_vbox);
99 priv->notebook = gtk_notebook_new ();
100 gtk_widget_show (priv->notebook);
101 gtk_box_pack_start (GTK_BOX (priv->main_vbox), priv->notebook, TRUE, TRUE, 0);
102 gtk_container_add (GTK_CONTAINER (obj), priv->main_vbox);
106 modest_shell_finalize (GObject *obj)
108 G_OBJECT_CLASS(parent_class)->finalize (obj);
112 modest_shell_new (void)
114 return (GtkWidget *) g_object_new(MODEST_TYPE_SHELL, NULL);
118 modest_shell_peek_window (ModestShell *shell)
120 ModestShellPrivate *priv;
123 priv = MODEST_SHELL_GET_PRIVATE (shell);
124 count = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
127 return (ModestWindow *) gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), count - 1);
134 modest_shell_delete_window (ModestShell *shell, ModestWindow *window)
136 ModestShellPrivate *priv;
139 priv = MODEST_SHELL_GET_PRIVATE (shell);
140 g_signal_emit_by_name (G_OBJECT (window), "delete-event", NULL, &ret_value);
141 if (ret_value == FALSE) {
144 page_num = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook), GTK_WIDGET (window));
145 if (page_num != -1) {
146 gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook), page_num);
154 modest_shell_add_window (ModestShell *shell, ModestWindow *window)
156 ModestShellPrivate *priv;
158 priv = MODEST_SHELL_GET_PRIVATE (shell);
159 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), GTK_WIDGET (window), NULL);
163 modest_shell_count_windows (ModestShell *shell)
165 ModestShellPrivate *priv;
167 priv = MODEST_SHELL_GET_PRIVATE (shell);
169 return gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
173 modest_shell_set_title (ModestShell *shell, ModestWindow *window, const gchar *title)
175 ModestShellPrivate *priv;
177 priv = MODEST_SHELL_GET_PRIVATE (shell);
179 gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (priv->notebook), GTK_WIDGET (window), title);
183 modest_shell_show_progress (ModestShell *shell, ModestWindow *window, gboolean show)