98d9dacbd2f9251aa8550b81860c68d479d591e7
[modest] / src / gtk / modest-shell.c
1 /* Copyright (c) 2009, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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.
16  *
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.
28  */
29
30 #include <string.h>
31 #include <modest-shell.h>
32
33 /* 'private'/'protected' functions */
34 static void modest_shell_class_init (ModestShellClass *klass);
35 static void modest_shell_instance_init (ModestShell *obj);
36 static void modest_shell_finalize   (GObject *obj);
37
38
39 typedef struct _ModestShellPrivate ModestShellPrivate;
40 struct _ModestShellPrivate {
41         GtkWidget *main_vbox;
42         GtkWidget *notebook;
43 };
44 #define MODEST_SHELL_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
45                                                                       MODEST_TYPE_SHELL, \
46                                                                       ModestShellPrivate))
47 /* globals */
48 static GObjectClass *parent_class = NULL;
49
50 GType
51 modest_shell_get_type (void)
52 {
53         static GType my_type = 0;
54         if (!my_type) {
55                 static const GTypeInfo my_info = {
56                         sizeof(ModestShellClass),
57                         NULL,           /* base init */
58                         NULL,           /* base finalize */
59                         (GClassInitFunc) modest_shell_class_init,
60                         NULL,           /* class finalize */
61                         NULL,           /* class data */
62                         sizeof(ModestShell),
63                         1,              /* n_preallocs */
64                         (GInstanceInitFunc) modest_shell_instance_init,
65                         NULL
66                 };
67                 my_type = g_type_register_static (GTK_TYPE_WINDOW,
68                                                   "ModestShell",
69                                                   &my_info, 0);
70         }
71         return my_type;
72 }
73
74 static void
75 modest_shell_class_init (ModestShellClass *klass)
76 {
77         GObjectClass *gobject_class;
78
79         gobject_class = (GObjectClass*) klass;
80
81         parent_class            = g_type_class_peek_parent (klass);
82         gobject_class->finalize = modest_shell_finalize;
83
84         g_type_class_add_private (gobject_class, sizeof(ModestShellPrivate));
85
86 }
87
88 static void
89 modest_shell_instance_init (ModestShell *obj)
90 {
91         ModestShellPrivate *priv;
92
93         priv = MODEST_SHELL_GET_PRIVATE(obj);
94
95         priv->main_vbox = gtk_vbox_new (FALSE, 0);
96         gtk_widget_show (priv->main_vbox);
97
98         priv->notebook = gtk_notebook_new ();
99         gtk_widget_show (priv->notebook);
100         gtk_box_pack_start (GTK_BOX (priv->main_vbox), priv->notebook, TRUE, TRUE, 0);
101         gtk_container_add (GTK_CONTAINER (obj), priv->main_vbox);
102 }
103
104 static void
105 modest_shell_finalize (GObject *obj)
106 {
107         G_OBJECT_CLASS(parent_class)->finalize (obj);
108 }
109
110 GtkWidget*
111 modest_shell_new (void)
112 {
113         return (GtkWidget *) g_object_new(MODEST_TYPE_SHELL, NULL);
114 }
115
116 ModestWindow *
117 modest_shell_peek_window (ModestShell *shell)
118 {
119         ModestShellPrivate *priv;
120         gint count;
121
122         priv = MODEST_SHELL_GET_PRIVATE (shell);
123         count = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
124
125         if (count > 0) {
126                 return (ModestWindow *) gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), count - 1);
127         } else {
128                 return NULL;
129         }
130 }
131
132 gboolean
133 modest_shell_delete_window (ModestShell *shell, ModestWindow *window)
134 {
135         ModestShellPrivate *priv;
136         gboolean ret_value;
137
138         priv = MODEST_SHELL_GET_PRIVATE (shell);
139         g_signal_emit_by_name (G_OBJECT (window), "delete-event", NULL, &ret_value);
140         if (ret_value == FALSE) {
141                 gint page_num;
142                 
143                 page_num = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook), GTK_WIDGET (window));
144                 if (page_num != -1) {
145                         gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook), page_num);
146                 }
147         }
148
149         return ret_value;
150 }
151
152 void
153 modest_shell_add_window (ModestShell *shell, ModestWindow *window)
154 {
155         ModestShellPrivate *priv;
156
157         priv = MODEST_SHELL_GET_PRIVATE (shell);
158         gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), GTK_WIDGET (window), NULL);
159 }
160
161 gint
162 modest_shell_count_windows (ModestShell *shell)
163 {
164         ModestShellPrivate *priv;
165
166         priv = MODEST_SHELL_GET_PRIVATE (shell);
167
168         return gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
169 }
170
171 void
172 modest_shell_set_title (ModestShell *shell, ModestShellWindow *window, const gchar *title)
173 {
174         ModestShellPrivate *priv;
175
176         priv = MODEST_SHELL_GET_PRIVATE (shell);
177
178         gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (priv->notebook), GTK_WIDGET (window), title);
179 }
180
181 void
182 modest_shell_show_progress (ModestShell *shell, ModestShellWindow *window, gboolean show)
183 {
184 }
185