3 /* insert (c)/licensing information) */
9 #endif /*HAVE_CONFIG_H*/
11 #include "modest-main-window.h"
12 #include "modest-edit-window.h"
14 #include "../modest-ui.h"
15 #include "../modest-window-mgr.h"
16 #include "../modest-account-mgr.h"
19 /* include other impl specific header files */
21 /* 'private'/'protected' functions */
22 static void modest_ui_class_init (ModestUIClass *klass);
23 static void modest_ui_init (ModestUI *obj);
24 static void modest_ui_finalize (GObject *obj);
26 static void modest_ui_window_destroy (GtkWidget *win, gpointer data);
27 static void modest_ui_last_window_closed (GObject *obj, gpointer data);
39 typedef struct _ModestUIPrivate ModestUIPrivate;
40 struct _ModestUIPrivate {
42 ModestConf *modest_conf;
43 ModestAccountMgr *modest_acc_mgr;
44 ModestWindowMgr *modest_window_mgr;
46 GtkWindow *main_window;
47 GSList* *edit_window_list;
50 #define MODEST_UI_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
54 static GObjectClass *parent_class = NULL;
56 /* uncomment the following if you have defined any signals */
57 /* static guint signals[LAST_SIGNAL] = {0}; */
60 modest_ui_get_type (void)
62 static GType my_type = 0;
64 static const GTypeInfo my_info = {
65 sizeof(ModestUIClass),
67 NULL, /* base finalize */
68 (GClassInitFunc) modest_ui_class_init,
69 NULL, /* class finalize */
70 NULL, /* class data */
73 (GInstanceInitFunc) modest_ui_init,
75 my_type = g_type_register_static (G_TYPE_OBJECT,
83 modest_ui_class_init (ModestUIClass *klass)
85 GObjectClass *gobject_class;
86 gobject_class = (GObjectClass*) klass;
88 parent_class = g_type_class_peek_parent (klass);
89 gobject_class->finalize = modest_ui_finalize;
91 g_type_class_add_private (gobject_class, sizeof(ModestUIPrivate));
93 /* signal definitions go here, e.g.: */
94 /* signals[MY_SIGNAL_1] = */
95 /* g_signal_new ("my_signal_1",....); */
96 /* signals[MY_SIGNAL_2] = */
97 /* g_signal_new ("my_signal_2",....); */
102 modest_ui_init (ModestUI *obj)
104 ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
106 priv->modest_acc_mgr = NULL;
107 priv->modest_conf = NULL;
108 priv->modest_window_mgr = NULL;
113 modest_ui_finalize (GObject *obj)
115 ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
117 if (priv->modest_acc_mgr)
118 g_object_unref (priv->modest_acc_mgr);
119 priv->modest_acc_mgr = NULL;
121 if (priv->modest_conf)
122 g_object_unref (priv->modest_conf);
123 priv->modest_conf = NULL;
125 if (priv->modest_window_mgr)
126 g_object_unref (priv->modest_window_mgr);
127 priv->modest_window_mgr = NULL;
131 modest_ui_new (ModestConf *modest_conf)
134 ModestUIPrivate *priv;
135 ModestAccountMgr *modest_acc_mgr;
137 g_return_val_if_fail (modest_conf, NULL);
139 obj = g_object_new(MODEST_TYPE_UI, NULL);
140 priv = MODEST_UI_GET_PRIVATE(obj);
142 modest_acc_mgr = MODEST_ACCOUNT_MGR(modest_account_mgr_new (modest_conf));
143 if (!modest_acc_mgr) {
144 g_warning ("could not create ModestAccountMgr instance");
145 g_object_unref (obj);
149 priv->modest_acc_mgr = modest_acc_mgr;
150 g_object_ref (priv->modest_conf = modest_conf);
152 priv->modest_window_mgr = MODEST_WINDOW_MGR(modest_window_mgr_new());
153 g_signal_connect (priv->modest_window_mgr, "last_window_closed",
154 G_CALLBACK(modest_ui_last_window_closed),
161 modest_ui_show_main_window (ModestUI *modest_ui)
165 ModestUIPrivate *priv;
167 priv = MODEST_UI_GET_PRIVATE(modest_ui);
169 height = modest_conf_get_int (priv->modest_conf,
170 MODEST_CONF_MAIN_WINDOW_HEIGHT,NULL);
171 width = modest_conf_get_int (priv->modest_conf,
172 MODEST_CONF_MAIN_WINDOW_WIDTH,NULL);
174 win = modest_main_window_new (priv->modest_conf,
175 priv->modest_acc_mgr);
177 g_warning ("could not create main window");
181 modest_window_mgr_register (priv->modest_window_mgr,
182 G_OBJECT(win), MODEST_MAIN_WINDOW, 0);
184 g_signal_connect (win, "destroy", G_CALLBACK(modest_ui_window_destroy),
187 gtk_widget_set_usize (GTK_WIDGET(win), height, width);
188 gtk_window_set_title (GTK_WINDOW(win), PACKAGE_STRING);
190 gtk_widget_show (win);
196 modest_ui_show_edit_window (ModestUI *modest_ui, const gchar* to,
197 const gchar* cc, const gchar* bcc,
198 const gchar* subject, const gchar *body,
202 ModestUIPrivate *priv;
204 priv = MODEST_UI_GET_PRIVATE(modest_ui);
205 int height = modest_conf_get_int (priv->modest_conf,
206 MODEST_CONF_EDIT_WINDOW_HEIGHT,NULL);
207 int width = modest_conf_get_int (priv->modest_conf,
208 MODEST_CONF_EDIT_WINDOW_WIDTH,NULL);
210 win = modest_edit_window_new (to, cc, bcc, subject, body, att);
212 g_warning ("could not create edit window");
216 modest_window_mgr_register (priv->modest_window_mgr,
217 G_OBJECT(win), MODEST_EDIT_WINDOW, 0);
219 g_signal_connect (win, "destroy", G_CALLBACK(modest_ui_window_destroy),
222 gtk_widget_set_usize (GTK_WIDGET(win), height, width);
223 gtk_window_set_title (GTK_WINDOW(win),
224 subject ? subject : "Untitled");
226 gtk_widget_show (win);
233 modest_ui_window_destroy (GtkWidget *win, gpointer data)
235 ModestUIPrivate *priv;
237 g_return_if_fail (data);
239 priv = MODEST_UI_GET_PRIVATE((ModestUI*)data);
240 if (!modest_window_mgr_unregister (priv->modest_window_mgr, G_OBJECT(win)))
241 g_warning ("modest window mgr: failed to unregister %p",
247 modest_ui_last_window_closed (GObject *obj, gpointer data)