8762843526946a6c29d82fcb7c8a6f77efd2facf
[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 #include <modest-shell-window.h>
33
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);
38
39
40 typedef struct _ModestShellPrivate ModestShellPrivate;
41 struct _ModestShellPrivate {
42         GtkWidget *main_vbox;
43         GtkWidget *notebook;
44 };
45 #define MODEST_SHELL_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
46                                                                       MODEST_TYPE_SHELL, \
47                                                                       ModestShellPrivate))
48 /* globals */
49 static GObjectClass *parent_class = NULL;
50
51 GType
52 modest_shell_get_type (void)
53 {
54         static GType my_type = 0;
55         if (!my_type) {
56                 static const GTypeInfo my_info = {
57                         sizeof(ModestShellClass),
58                         NULL,           /* base init */
59                         NULL,           /* base finalize */
60                         (GClassInitFunc) modest_shell_class_init,
61                         NULL,           /* class finalize */
62                         NULL,           /* class data */
63                         sizeof(ModestShell),
64                         1,              /* n_preallocs */
65                         (GInstanceInitFunc) modest_shell_instance_init,
66                         NULL
67                 };
68                 my_type = g_type_register_static (GTK_TYPE_WINDOW,
69                                                   "ModestShell",
70                                                   &my_info, 0);
71         }
72         return my_type;
73 }
74
75 static void
76 modest_shell_class_init (ModestShellClass *klass)
77 {
78         GObjectClass *gobject_class;
79
80         gobject_class = (GObjectClass*) klass;
81
82         parent_class            = g_type_class_peek_parent (klass);
83         gobject_class->finalize = modest_shell_finalize;
84
85         g_type_class_add_private (gobject_class, sizeof(ModestShellPrivate));
86
87 }
88
89 static void
90 modest_shell_instance_init (ModestShell *obj)
91 {
92         ModestShellPrivate *priv;
93
94         priv = MODEST_SHELL_GET_PRIVATE(obj);
95
96         priv->main_vbox = gtk_vbox_new (FALSE, 0);
97         gtk_widget_show (priv->main_vbox);
98
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);
103 }
104
105 static void
106 modest_shell_finalize (GObject *obj)
107 {
108         G_OBJECT_CLASS(parent_class)->finalize (obj);
109 }
110
111 GtkWidget*
112 modest_shell_new (void)
113 {
114         return (GtkWidget *) g_object_new(MODEST_TYPE_SHELL, NULL);
115 }
116
117 ModestWindow *
118 modest_shell_peek_window (ModestShell *shell)
119 {
120         ModestShellPrivate *priv;
121         gint count;
122
123         priv = MODEST_SHELL_GET_PRIVATE (shell);
124         count = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
125
126         if (count > 0) {
127                 return (ModestWindow *) gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), count - 1);
128         } else {
129                 return NULL;
130         }
131 }
132
133 gboolean
134 modest_shell_delete_window (ModestShell *shell, ModestWindow *window)
135 {
136         ModestShellPrivate *priv;
137         gboolean ret_value;
138
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) {
142                 gint page_num;
143                 
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);
147                 }
148         }
149
150         return ret_value;
151 }
152
153 void
154 modest_shell_add_window (ModestShell *shell, ModestWindow *window)
155 {
156         ModestShellPrivate *priv;
157
158         priv = MODEST_SHELL_GET_PRIVATE (shell);
159         gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), GTK_WIDGET (window), NULL);
160 }
161
162 gint
163 modest_shell_count_windows (ModestShell *shell)
164 {
165         ModestShellPrivate *priv;
166
167         priv = MODEST_SHELL_GET_PRIVATE (shell);
168
169         return gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
170 }
171
172 void
173 modest_shell_set_title (ModestShell *shell, ModestWindow *window, const gchar *title)
174 {
175         ModestShellPrivate *priv;
176
177         priv = MODEST_SHELL_GET_PRIVATE (shell);
178
179         gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (priv->notebook), GTK_WIDGET (window), title);
180 }
181
182 void
183 modest_shell_show_progress (ModestShell *shell, ModestWindow *window, gboolean show)
184 {
185 }
186