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