3 /* insert (c)/licensing information) */
6 #include <glade/glade.h>
7 #include <glib/gi18n.h>
12 #endif /*HAVE_CONFIG_H*/
14 /* TODO: put in auto* */
15 #include <tny-text-buffer-stream.h>
16 #include <tny-msg-folder.h>
18 #include "../modest-ui.h"
19 #include "../modest-window-mgr.h"
20 #include "../modest-account-mgr.h"
21 #include "../modest-account-mgr.h"
22 #include "../modest-identity-mgr.h"
24 #include "../modest-tny-account-store.h"
25 #include "../modest-tny-folder-tree-view.h"
26 #include "../modest-tny-header-tree-view.h"
27 #include "../modest-tny-msg-view.h"
28 #include "../modest-tny-transport-actions.h"
29 #include "../modest-tny-store-actions.h"
31 #include "../modest-text-utils.h"
32 #include "../modest-tny-msg-actions.h"
34 #include "../modest-editor-window.h"
36 #include "modest-ui-glade.h"
37 #include "modest-ui-wizard.h"
39 /* 'private'/'protected' functions */
40 static void modest_ui_class_init (ModestUIClass *klass);
41 static void modest_ui_init (ModestUI *obj);
42 static void modest_ui_finalize (GObject *obj);
44 static void modest_ui_window_destroy (GtkWidget *win, GdkEvent *event, gpointer data);
45 static void modest_ui_last_window_closed (GObject *obj, gpointer data);
47 static void on_password_requested (ModestTnyAccountStore *account_store, const gchar *account_name, gpointer user_data);
50 //static void on_account_settings1_activate (GtkMenuItem *,
62 static GObjectClass *parent_class = NULL;
66 modest_ui_get_type (void)
68 static GType my_type = 0;
70 static const GTypeInfo my_info = {
71 sizeof(ModestUIClass),
73 NULL, /* base finalize */
74 (GClassInitFunc) modest_ui_class_init,
75 NULL, /* class finalize */
76 NULL, /* class data */
79 (GInstanceInitFunc) modest_ui_init,
81 my_type = g_type_register_static (G_TYPE_OBJECT,
90 modest_ui_class_init (ModestUIClass *klass)
92 GObjectClass *gobject_class;
93 gobject_class = (GObjectClass*) klass;
95 parent_class = g_type_class_peek_parent (klass);
96 gobject_class->finalize = modest_ui_finalize;
98 g_type_class_add_private (gobject_class, sizeof(ModestUIPrivate));
100 /* signal definitions go here, e.g.: */
101 /* signals[MY_SIGNAL_1] = */
102 /* g_signal_new ("my_signal_1",....); */
103 /* signals[MY_SIGNAL_2] = */
104 /* g_signal_new ("my_signal_2",....); */
110 modest_ui_init (ModestUI *obj)
112 ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
114 priv->modest_acc_mgr = NULL;
115 priv->modest_id_mgr = NULL;
116 priv->modest_conf = NULL;
117 priv->modest_window_mgr = NULL;
118 priv->glade_xml = NULL;
119 priv->folder_view = NULL;
120 priv->header_view = NULL;
126 modest_ui_finalize (GObject *obj)
128 ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
130 if (priv->modest_acc_mgr)
131 g_object_unref (priv->modest_acc_mgr);
132 priv->modest_acc_mgr = NULL;
134 if (priv->modest_id_mgr)
135 g_object_unref (priv->modest_id_mgr);
136 priv->modest_id_mgr = NULL;
138 if (priv->modest_conf)
139 g_object_unref (priv->modest_conf);
140 priv->modest_conf = NULL;
142 if (priv->modest_window_mgr)
143 g_object_unref (priv->modest_window_mgr);
144 priv->modest_window_mgr = NULL;
149 modest_ui_new (ModestConf *modest_conf)
152 ModestUIPrivate *priv;
153 ModestAccountMgr *modest_acc_mgr;
154 ModestIdentityMgr *modest_id_mgr;
155 TnyAccountStoreIface *account_store_iface;
156 GSList *account_names_list;
157 GSList *identities_list;
159 g_return_val_if_fail (modest_conf, NULL);
161 obj = g_object_new(MODEST_TYPE_UI, NULL);
162 priv = MODEST_UI_GET_PRIVATE(obj);
164 modest_acc_mgr = MODEST_ACCOUNT_MGR(modest_account_mgr_new (modest_conf));
165 if (!modest_acc_mgr) {
166 g_warning ("could not create ModestAccountMgr instance");
167 g_object_unref (obj);
171 modest_id_mgr = MODEST_IDENTITY_MGR(modest_identity_mgr_new (modest_conf));
172 if (!modest_id_mgr) {
173 g_warning ("could not create ModestIdentityMgr instance");
174 g_object_unref (obj);
178 account_store_iface =
179 TNY_ACCOUNT_STORE_IFACE(modest_tny_account_store_new (modest_acc_mgr));
180 if (!account_store_iface) {
181 g_warning ("could not initialze ModestTnyAccountStore");
184 g_signal_connect (account_store_iface, "password_requested",
185 G_CALLBACK(on_password_requested),
189 priv->glade_xml = glade_xml_new (MODEST_GLADE, NULL,NULL);
190 if (!priv->glade_xml) {
191 g_warning ("failed to do glade stuff");
192 g_object_unref (obj);
196 /* FIXME: could be used, but doesn't work atm.
197 * glade_xml_signal_autoconnect(priv->glade_xml);
200 priv->modest_acc_mgr = modest_acc_mgr;
201 priv->modest_id_mgr = modest_id_mgr;
202 g_object_ref (priv->modest_conf = modest_conf);
204 priv->account_store = account_store_iface;
206 priv->modest_window_mgr = MODEST_WINDOW_MGR(modest_window_mgr_new());
207 g_signal_connect (priv->modest_window_mgr, "last_window_closed",
208 G_CALLBACK(modest_ui_last_window_closed),
211 account_names_list=modest_account_mgr_server_account_names(modest_acc_mgr, NULL, MODEST_PROTO_TYPE_ANY, NULL, FALSE);
212 identities_list=modest_identity_mgr_identity_names(modest_id_mgr, NULL);
213 if (!(account_names_list!=NULL || identities_list!=NULL))
214 wizard_account_dialog(MODEST_UI(obj));
215 g_slist_free(account_names_list);
216 g_slist_free(identities_list);
223 modest_ui_last_window_closed (GObject *obj, gpointer data)
225 /* FIXME: Other cleanups todo? Finalize Tinymail? */
231 on_password_requested (ModestTnyAccountStore *account_store,
232 const gchar *account_name, gpointer user_data)
235 GtkWidget *passdialog;
237 GtkWidget *infolabel;
238 GtkWidget *passentry;
240 const gchar *infostring=g_strconcat("Please enter the password for ", account_name, ".", NULL);
242 passdialog = gtk_dialog_new_with_buttons("MyDialog",
244 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
251 vbox=gtk_vbox_new(FALSE, 0);
253 infolabel=gtk_label_new(infostring);
254 passentry=gtk_entry_new();
256 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), infolabel, FALSE, FALSE, 0);
257 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), passentry, FALSE, FALSE, 0);
258 gtk_widget_show_all(passdialog);
260 retval = gtk_dialog_run (GTK_DIALOG(passdialog));
264 case GTK_RESPONSE_ACCEPT:
265 modest_account_mgr_set_server_account_string(modest_tny_account_store_get_accout_mgr(account_store),
268 gtk_entry_get_text(GTK_ENTRY(passentry)),
271 case GTK_RESPONSE_CANCEL:
273 * What happens, if canceled?"
278 gtk_widget_destroy (passdialog);
283 on_account_selector_selection_changed (GtkWidget *widget,
286 GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
291 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter))
293 gtk_tree_model_get(GTK_TREE_MODEL(model),
300 account_name="empty";
303 g_message("Value: '%s'\n", account_name);
310 on_account_settings1_activate (GtkMenuItem *menuitem,
314 GtkWidget *advanced_account_setup;
315 ModestUIPrivate *priv;
317 GSList *account_name_list;
318 GSList *account_name_list_iter;
319 GtkListStore *account_names;
320 GtkTreeIter account_names_iter;
321 GtkWidget *account_selector;
322 GtkCellRenderer *renderer;
325 g_return_if_fail(MODEST_IS_UI(user_data));
326 priv = MODEST_UI_GET_PRIVATE(MODEST_UI(user_data));
328 glade_xml = glade_xml_new(MODEST_GLADE, "mailbox_setup_advanced", NULL);
329 advanced_account_setup = glade_xml_get_widget(glade_xml, "mailbox_setup_advanced");
331 account_name_list=modest_account_mgr_account_names(priv->modest_acc_mgr, NULL);
332 account_names = gtk_list_store_new(1, G_TYPE_STRING);
334 for (account_name_list_iter=account_name_list;
335 account_name_list_iter!=NULL;
336 account_name_list_iter=g_slist_next(account_name_list_iter))
338 gtk_list_store_append(account_names, &account_names_iter);
339 gtk_list_store_set(account_names, &account_names_iter,
340 0, account_name_list_iter->data,
344 g_slist_free(account_name_list);
346 account_selector = glade_xml_get_widget(glade_xml, "account_selector");
347 gtk_combo_box_set_model(GTK_COMBO_BOX(account_selector), GTK_TREE_MODEL(account_names));
349 renderer = gtk_cell_renderer_text_new ();
350 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (account_selector), renderer, TRUE);
351 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (account_selector), renderer,
355 g_signal_connect(GTK_WIDGET(account_selector), "changed",
356 G_CALLBACK(on_account_selector_selection_changed),
357 GTK_WIDGET(advanced_account_setup));
359 gtk_combo_box_set_active(GTK_COMBO_BOX(account_selector), 0);
361 gtk_widget_show_all(GTK_WIDGET(advanced_account_setup));
363 retval=gtk_dialog_run(GTK_DIALOG(advanced_account_setup));
365 g_object_unref(account_names);
367 gtk_widget_destroy(GTK_WIDGET(advanced_account_setup));
369 g_object_unref(glade_xml);