* Added ModestWindow object
[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 /* list my signals  */
39 enum {
40         LAST_SIGNAL
41 };
42
43 /* globals */
44 static GObjectClass *parent_class = NULL;
45
46 /* uncomment the following if you have defined any signals */
47 /* static guint signals[LAST_SIGNAL] = {0}; */
48
49 GType
50 modest_window_get_type (void)
51 {
52         static GType my_type = 0;
53         static GType parent_type = 0;
54         if (!my_type) {
55                 static const GTypeInfo my_info = {
56                         sizeof(ModestWindowClass),
57                         NULL,           /* base init */
58                         NULL,           /* base finalize */
59                         (GClassInitFunc) modest_window_class_init,
60                         NULL,           /* class finalize */
61                         NULL,           /* class data */
62                         sizeof(ModestWindow),
63                         1,              /* n_preallocs */
64                         (GInstanceInitFunc) modest_window_init,
65                         NULL
66                 };
67 #if MODEST_PLATFORM_ID==1   /* gtk */
68                 parent_type = GTK_TYPE_WINDOW;
69 #elif MODEST_PLATFORM_ID==2   /* hildon (maemo) */
70                 parent_type = HILDON_TYPE_WINDOW;
71 #endif
72                 my_type = g_type_register_static (parent_type,
73                                                   "ModestWindow",
74                                                   &my_info, 
75                                                   G_TYPE_FLAG_ABSTRACT);
76         }
77         return my_type;
78 }
79
80 static void
81 modest_window_class_init (ModestWindowClass *klass)
82 {
83         GObjectClass *gobject_class;
84         gobject_class = (GObjectClass*) klass;
85
86         parent_class            = g_type_class_peek_parent (klass);
87         gobject_class->finalize = modest_window_finalize;
88
89         g_type_class_add_private (gobject_class, sizeof(ModestWindowPrivate));
90 }
91
92 static void
93 modest_window_init (ModestWindow *obj)
94 {
95         ModestWindowPrivate *priv;
96
97         priv = MODEST_WINDOW_GET_PRIVATE(obj);
98
99         priv->plat_factory  = modest_tny_platform_factory_get_instance ();
100         priv->ui_manager    = NULL;
101         priv->account_store = NULL;
102
103         priv->toolbar       = NULL;
104         priv->menubar       = NULL;
105 }
106
107 static void
108 modest_window_finalize (GObject *obj)
109 {
110         ModestWindowPrivate *priv;      
111
112         priv = MODEST_WINDOW_GET_PRIVATE(obj);
113
114         if (priv->ui_manager) {
115                 g_object_unref (G_OBJECT(priv->ui_manager));
116                 priv->ui_manager = NULL;
117         }
118         if (priv->account_store) {
119                 g_object_unref (G_OBJECT(priv->account_store));
120                 priv->account_store = NULL;
121         }
122
123         G_OBJECT_CLASS(parent_class)->finalize (obj);
124 }
125
126 TnyAccountStore * 
127 modest_window_get_account_store (ModestWindow *window)
128 {
129         ModestWindowPrivate *priv;
130         
131         g_return_val_if_fail (MODEST_IS_WINDOW (window), NULL);
132
133         priv = MODEST_WINDOW_GET_PRIVATE (window);
134
135         return g_object_ref (priv->account_store);
136 }
137
138 ModestWidgetFactory *
139 modest_window_get_widget_factory (ModestWindow *window)
140 {
141         ModestWindowPrivate *priv;
142         
143         g_return_val_if_fail (MODEST_IS_WINDOW (window), NULL);
144
145         priv = MODEST_WINDOW_GET_PRIVATE (window);
146
147         return g_object_ref (priv->widget_factory);
148 }