* src/modest-ui-actions.[ch]:
[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
45
46 /* list my signals  */
47 enum {
48         LAST_SIGNAL
49 };
50
51 /* globals */
52 static GObjectClass *parent_class = NULL;
53
54 /* uncomment the following if you have defined any signals */
55 /* static guint signals[LAST_SIGNAL] = {0}; */
56
57 GType
58 modest_window_get_type (void)
59 {
60         static GType my_type = 0;
61         static GType parent_type = 0;
62         if (!my_type) {
63                 static const GTypeInfo my_info = {
64                         sizeof(ModestWindowClass),
65                         NULL,           /* base init */
66                         NULL,           /* base finalize */
67                         (GClassInitFunc) modest_window_class_init,
68                         NULL,           /* class finalize */
69                         NULL,           /* class data */
70                         sizeof(ModestWindow),
71                         1,              /* n_preallocs */
72                         (GInstanceInitFunc) modest_window_init,
73                         NULL
74                 };
75 #ifdef MODEST_PLATFORM_MAEMO
76                 parent_type = HILDON_TYPE_WINDOW;
77 #else
78                 parent_type = GTK_TYPE_WINDOW;
79 #endif 
80                 my_type = g_type_register_static (parent_type,
81                                                   "ModestWindow",
82                                                   &my_info, 
83                                                   G_TYPE_FLAG_ABSTRACT);
84         }
85         return my_type;
86 }
87
88 static void
89 modest_window_class_init (ModestWindowClass *klass)
90 {
91         GObjectClass *gobject_class;
92         gobject_class = (GObjectClass*) klass;
93
94         parent_class            = g_type_class_peek_parent (klass);
95         gobject_class->finalize = modest_window_finalize;
96
97         klass->set_zoom_func = modest_window_set_zoom_default;
98         klass->get_zoom_func = modest_window_get_zoom_default;
99         klass->zoom_plus_func = modest_window_zoom_plus_default;
100         klass->zoom_minus_func = modest_window_zoom_minus_default;
101
102         g_type_class_add_private (gobject_class, sizeof(ModestWindowPrivate));
103 }
104
105 static void
106 modest_window_init (ModestWindow *obj)
107 {
108         ModestWindowPrivate *priv;
109
110         priv = MODEST_WINDOW_GET_PRIVATE(obj);
111
112         priv->ui_manager     = NULL;
113         priv->toolbar        = NULL;
114         priv->menubar        = NULL;
115
116         priv->active_account = NULL;
117 }
118
119 static void
120 modest_window_finalize (GObject *obj)
121 {
122         ModestWindowPrivate *priv;      
123
124         priv = MODEST_WINDOW_GET_PRIVATE(obj);
125
126         if (priv->ui_manager) {
127                 g_object_unref (G_OBJECT(priv->ui_manager));
128                 priv->ui_manager = NULL;
129         }
130
131         g_free (priv->active_account);
132         
133         G_OBJECT_CLASS(parent_class)->finalize (obj);
134 }
135
136
137
138 const gchar*
139 modest_window_get_active_account (ModestWindow *self)
140 {
141         g_return_val_if_fail (self, NULL);
142
143         return MODEST_WINDOW_GET_PRIVATE(self)->active_account;
144 }
145
146 void
147 modest_window_set_active_account (ModestWindow *self, const gchar *active_account)
148 {
149         ModestWindowPrivate *priv;      
150
151         priv = MODEST_WINDOW_GET_PRIVATE(self);
152
153         if (active_account == priv->active_account)
154                 return;
155         else {
156                 g_free (priv->active_account);
157                 priv->active_account = g_strdup (active_account);
158         }
159 }
160
161 void
162 modest_window_set_zoom (ModestWindow *window,
163                         gdouble zoom)
164 {
165         MODEST_WINDOW_GET_CLASS (window)->set_zoom_func (window, zoom);
166         return;
167 }
168
169 gdouble
170 modest_window_get_zoom (ModestWindow *window)
171 {
172         return MODEST_WINDOW_GET_CLASS (window)->get_zoom_func (window);
173 }
174
175 gboolean
176 modest_window_zoom_plus (ModestWindow *window)
177 {
178         return MODEST_WINDOW_GET_CLASS (window)->zoom_plus_func (window);
179 }
180
181 gboolean
182 modest_window_zoom_minus (ModestWindow *window)
183 {
184         return MODEST_WINDOW_GET_CLASS (window)->zoom_minus_func (window);
185 }
186
187 static void
188 modest_window_set_zoom_default (ModestWindow *window,
189                                 gdouble zoom)
190 {
191         return;
192 }
193
194 static gdouble
195 modest_window_get_zoom_default (ModestWindow *window)
196 {
197         return 1.0;
198 }
199
200 static gboolean
201 modest_window_zoom_plus_default (ModestWindow *window)
202 {
203         return FALSE;
204 }
205
206 static gboolean
207 modest_window_zoom_minus_default (ModestWindow *window)
208 {
209         return FALSE;
210 }