1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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.
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.
31 #include <glade/glade.h>
32 #include <glib/gi18n.h>
37 #endif /*HAVE_CONFIG_H*/
39 #include "../modest-ui.h"
40 #include "../modest-account-mgr.h"
41 #include "../modest-widget-factory.h"
42 #include "modest-main-window.h"
45 /* 'private'/'protected' functions */
46 static void modest_ui_class_init (ModestUIClass *klass);
47 static void modest_ui_init (ModestUI *obj);
48 static void modest_ui_finalize (GObject *obj);
50 gchar *on_password_requested (TnyAccountIface *, const gchar *, gboolean *);
53 typedef struct _ModestUIPrivate ModestUIPrivate;
54 struct _ModestUIPrivate {
56 ModestAccountMgr *account_mgr;
57 ModestWidgetFactory *widget_factory;
58 ModestTnyAccountStore *account_store;
61 #define MODEST_UI_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
74 static GObjectClass *parent_class = NULL;
78 modest_ui_get_type (void)
80 static GType my_type = 0;
82 static const GTypeInfo my_info = {
83 sizeof(ModestUIClass),
85 NULL, /* base finalize */
86 (GClassInitFunc) modest_ui_class_init,
87 NULL, /* class finalize */
88 NULL, /* class data */
91 (GInstanceInitFunc) modest_ui_init,
94 my_type = g_type_register_static (G_TYPE_OBJECT,
103 modest_ui_class_init (ModestUIClass *klass)
105 GObjectClass *gobject_class;
106 gobject_class = (GObjectClass*) klass;
108 parent_class = g_type_class_peek_parent (klass);
109 gobject_class->finalize = modest_ui_finalize;
111 g_type_class_add_private (gobject_class, sizeof(ModestUIPrivate));
117 modest_ui_init (ModestUI *obj)
119 ModestUIPrivate *priv;
121 priv = MODEST_UI_GET_PRIVATE(obj);
123 priv->account_store = NULL;
124 priv->account_mgr = NULL;
126 priv->widget_factory = NULL;
131 modest_ui_finalize (GObject *obj)
134 ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
136 if (priv->account_store) {
137 g_object_unref (G_OBJECT(priv->account_store));
138 priv->account_store = NULL;
141 if (priv->account_mgr) {
142 g_object_unref (G_OBJECT(priv->account_mgr));
143 priv->account_mgr = NULL;
146 if (priv->widget_factory) {
147 g_object_unref (G_OBJECT(priv->widget_factory));
148 priv->widget_factory = NULL;
152 g_object_unref (G_OBJECT(priv->conf));
159 modest_ui_new (ModestConf *modest_conf)
162 ModestUIPrivate *priv;
164 g_return_val_if_fail (modest_conf, NULL);
166 obj = g_object_new(MODEST_TYPE_UI, NULL);
167 priv = MODEST_UI_GET_PRIVATE(obj);
169 g_object_ref (G_OBJECT(modest_conf));
170 priv->conf = modest_conf;
172 priv->account_mgr = MODEST_ACCOUNT_MGR(modest_account_mgr_new (priv->conf));
173 if (!priv->account_mgr) {
174 g_printerr ("modest: could not create ModestAccountMgr instance\n");
175 g_object_unref (obj);
179 priv->account_store = modest_tny_account_store_new (priv->account_mgr);
180 if (!priv->account_store) {
181 g_printerr ("modest: could not initialze ModestTnyAccountStore instance\n");
185 priv->widget_factory = modest_widget_factory_new (
186 priv->conf, priv->account_store, priv->account_mgr);
187 if (!priv->account_store) {
188 g_printerr ("modest: could not initialize widget factory\n");
192 return MODEST_UI(obj);
197 modest_ui_main_window (ModestUI *modest_ui)
200 ModestUIPrivate *priv;
202 g_return_val_if_fail (modest_ui, NULL);
203 priv = MODEST_UI_GET_PRIVATE(modest_ui);
205 win = modest_main_window_new (priv->conf, priv->account_mgr,
206 priv->widget_factory);
208 g_printerr ("modest: could not create main window\n");