* Added show toolbar application wide code
[modest] / src / widgets / modest-window.c
1 /* Copyright (c) 2006, 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 "modest-window.h"
31 #include "modest-window-priv.h"
32 #include "modest-tny-platform-factory.h"
33
34 /* 'private'/'protected' functions */
35 static void modest_window_class_init (ModestWindowClass *klass);
36 static void modest_window_init       (ModestWindow *obj);
37 static void modest_window_finalize   (GObject *obj);
38
39 static void        modest_window_set_zoom_default       (ModestWindow *window,
40                                                          gdouble zoom);
41 static gdouble     modest_window_get_zoom_default       (ModestWindow *window);
42 static gboolean    modest_window_zoom_plus_default      (ModestWindow *window);
43 static gboolean    modest_window_zoom_minus_default     (ModestWindow *window);
44 static void        modest_window_create_toolbar_default (ModestWindow *window);
45 static void        modest_window_show_toolbar_default   (ModestWindow *window,
46                                                          gboolean show_toolbar);
47
48 /* list my signals  */
49 enum {
50         LAST_SIGNAL
51 };
52
53 /* globals */
54 static GObjectClass *parent_class = NULL;
55
56 /* uncomment the following if you have defined any signals */
57 /* static guint signals[LAST_SIGNAL] = {0}; */
58
59 GType
60 modest_window_get_type (void)
61 {
62         static GType my_type = 0;
63         static GType parent_type = 0;
64         if (!my_type) {
65                 static const GTypeInfo my_info = {
66                         sizeof(ModestWindowClass),
67                         NULL,           /* base init */
68                         NULL,           /* base finalize */
69                         (GClassInitFunc) modest_window_class_init,
70                         NULL,           /* class finalize */
71                         NULL,           /* class data */
72                         sizeof(ModestWindow),
73                         1,              /* n_preallocs */
74                         (GInstanceInitFunc) modest_window_init,
75                         NULL
76                 };
77 #ifdef MODEST_PLATFORM_MAEMO
78                 parent_type = HILDON_TYPE_WINDOW;
79 #else
80                 parent_type = GTK_TYPE_WINDOW;
81 #endif 
82                 my_type = g_type_register_static (parent_type,
83                                                   "ModestWindow",
84                                                   &my_info, 
85                                                   G_TYPE_FLAG_ABSTRACT);
86         }
87         return my_type;
88 }
89
90 static void
91 modest_window_class_init (ModestWindowClass *klass)
92 {
93         GObjectClass *gobject_class;
94         gobject_class = (GObjectClass*) klass;
95
96         parent_class            = g_type_class_peek_parent (klass);
97         gobject_class->finalize = modest_window_finalize;
98
99         klass->set_zoom_func = modest_window_set_zoom_default;
100         klass->get_zoom_func = modest_window_get_zoom_default;
101         klass->zoom_plus_func = modest_window_zoom_plus_default;
102         klass->zoom_minus_func = modest_window_zoom_minus_default;
103         klass->create_toolbar_func = modest_window_create_toolbar_default;
104         klass->show_toolbar_func = modest_window_show_toolbar_default;
105
106         g_type_class_add_private (gobject_class, sizeof(ModestWindowPrivate));
107 }
108
109 static void
110 modest_window_init (ModestWindow *obj)
111 {
112         ModestWindowPrivate *priv;
113
114         priv = MODEST_WINDOW_GET_PRIVATE(obj);
115
116         priv->ui_manager     = NULL;
117         priv->toolbar        = NULL;
118         priv->menubar        = NULL;
119
120         priv->active_account = NULL;
121 }
122
123 static void
124 modest_window_finalize (GObject *obj)
125 {
126         ModestWindowPrivate *priv;      
127
128         priv = MODEST_WINDOW_GET_PRIVATE(obj);
129
130         if (priv->ui_manager) {
131                 g_object_unref (G_OBJECT(priv->ui_manager));
132                 priv->ui_manager = NULL;
133         }
134
135         g_free (priv->active_account);
136         
137         G_OBJECT_CLASS(parent_class)->finalize (obj);
138 }
139
140
141
142 const gchar*
143 modest_window_get_active_account (ModestWindow *self)
144 {
145         g_return_val_if_fail (self, NULL);
146
147         return MODEST_WINDOW_GET_PRIVATE(self)->active_account;
148 }
149
150 void
151 modest_window_set_active_account (ModestWindow *self, const gchar *active_account)
152 {
153         ModestWindowPrivate *priv;      
154
155         priv = MODEST_WINDOW_GET_PRIVATE(self);
156
157         if (active_account == priv->active_account)
158                 return;
159         else {
160                 g_free (priv->active_account);
161                 priv->active_account = g_strdup (active_account);
162         }
163 }
164
165 void
166 modest_window_set_zoom (ModestWindow *window,
167                         gdouble zoom)
168 {
169         MODEST_WINDOW_GET_CLASS (window)->set_zoom_func (window, zoom);
170         return;
171 }
172
173 gdouble
174 modest_window_get_zoom (ModestWindow *window)
175 {
176         return MODEST_WINDOW_GET_CLASS (window)->get_zoom_func (window);
177 }
178
179 gboolean
180 modest_window_zoom_plus (ModestWindow *window)
181 {
182         return MODEST_WINDOW_GET_CLASS (window)->zoom_plus_func (window);
183 }
184
185 gboolean
186 modest_window_zoom_minus (ModestWindow *window)
187 {
188         return MODEST_WINDOW_GET_CLASS (window)->zoom_minus_func (window);
189 }
190
191 static void 
192 modest_window_create_toolbar (ModestWindow *window)
193 {
194         MODEST_WINDOW_GET_CLASS (window)->create_toolbar_func (window);
195 }
196
197 static void 
198 modest_window_show_toolbar (ModestWindow *window,
199                             gboolean show_toolbar)
200 {
201         MODEST_WINDOW_GET_CLASS (window)->show_toolbar_func (window,
202                                                              show_toolbar);
203 }
204
205 void 
206 modest_window_view_toolbar (ModestWindow *window,
207                             gboolean show_toolbar)
208 {
209         ModestWindowPrivate *priv;      
210
211         priv = MODEST_WINDOW_GET_PRIVATE(window);
212
213         /* Lazy strategy, we create the toolbar just when there is no
214            toolbar and we want to show it */
215         if (!priv->toolbar && show_toolbar)
216                 modest_window_create_toolbar (window);
217
218         if (priv->toolbar)
219                 modest_window_show_toolbar (window, show_toolbar);
220 }
221
222
223 /* Default implementations */
224
225 static void
226 modest_window_set_zoom_default (ModestWindow *window,
227                                 gdouble zoom)
228 {
229         g_warning ("modest: You should implement %s", __FUNCTION__);
230
231 }
232
233 static gdouble
234 modest_window_get_zoom_default (ModestWindow *window)
235 {
236         g_warning ("modest: You should implement %s", __FUNCTION__);
237         return 1.0;
238 }
239
240 static gboolean
241 modest_window_zoom_plus_default (ModestWindow *window)
242 {
243         g_warning ("modest: You should implement %s", __FUNCTION__);
244         return FALSE;
245 }
246
247 static gboolean
248 modest_window_zoom_minus_default (ModestWindow *window)
249 {
250         g_warning ("modest: You should implement %s", __FUNCTION__);
251         return FALSE;
252 }
253
254 static void 
255 modest_window_create_toolbar_default (ModestWindow *window)
256 {
257         g_warning ("modest: You should implement %s", __FUNCTION__);
258 }
259
260 static void 
261 modest_window_show_toolbar_default (ModestWindow *window,
262                                     gboolean show_toolbar)
263 {
264         g_warning ("modest: You should implement %s", __FUNCTION__);
265 }