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);
57 static GObjectClass *parent_class = NULL;
61 modest_ui_get_type (void)
63 static GType my_type = 0;
65 static const GTypeInfo my_info = {
66 sizeof(ModestUIClass),
68 NULL, /* base finalize */
69 (GClassInitFunc) modest_ui_class_init,
70 NULL, /* class finalize */
71 NULL, /* class data */
74 (GInstanceInitFunc) modest_ui_init,
76 my_type = g_type_register_static (G_TYPE_OBJECT,
85 modest_ui_class_init (ModestUIClass *klass)
87 GObjectClass *gobject_class;
88 gobject_class = (GObjectClass*) klass;
90 parent_class = g_type_class_peek_parent (klass);
91 gobject_class->finalize = modest_ui_finalize;
93 g_type_class_add_private (gobject_class, sizeof(ModestUIPrivate));
95 /* signal definitions go here, e.g.: */
96 /* signals[MY_SIGNAL_1] = */
97 /* g_signal_new ("my_signal_1",....); */
98 /* signals[MY_SIGNAL_2] = */
99 /* g_signal_new ("my_signal_2",....); */
105 modest_ui_init (ModestUI *obj)
107 ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
109 priv->modest_acc_mgr = NULL;
110 priv->modest_id_mgr = NULL;
111 priv->modest_conf = NULL;
112 priv->modest_window_mgr = NULL;
113 priv->glade_xml = NULL;
114 priv->folder_view = NULL;
115 priv->header_view = NULL;
121 modest_ui_finalize (GObject *obj)
123 ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
125 if (priv->modest_acc_mgr)
126 g_object_unref (priv->modest_acc_mgr);
127 priv->modest_acc_mgr = NULL;
129 if (priv->modest_id_mgr)
130 g_object_unref (priv->modest_id_mgr);
131 priv->modest_id_mgr = NULL;
133 if (priv->modest_conf)
134 g_object_unref (priv->modest_conf);
135 priv->modest_conf = NULL;
137 if (priv->modest_window_mgr)
138 g_object_unref (priv->modest_window_mgr);
139 priv->modest_window_mgr = NULL;
144 modest_ui_new (ModestConf *modest_conf)
147 ModestUIPrivate *priv;
148 ModestAccountMgr *modest_acc_mgr;
149 ModestIdentityMgr *modest_id_mgr;
150 TnyAccountStoreIface *account_store_iface;
151 GSList *account_names_list;
152 GSList *identities_list;
154 g_return_val_if_fail (modest_conf, NULL);
156 obj = g_object_new(MODEST_TYPE_UI, NULL);
157 priv = MODEST_UI_GET_PRIVATE(obj);
159 modest_acc_mgr = MODEST_ACCOUNT_MGR(modest_account_mgr_new (modest_conf));
160 if (!modest_acc_mgr) {
161 g_warning ("could not create ModestAccountMgr instance");
162 g_object_unref (obj);
166 modest_id_mgr = MODEST_IDENTITY_MGR(modest_identity_mgr_new (modest_conf));
167 if (!modest_id_mgr) {
168 g_warning ("could not create ModestIdentityMgr instance");
169 g_object_unref (obj);
173 account_store_iface =
174 TNY_ACCOUNT_STORE_IFACE(modest_tny_account_store_new (modest_acc_mgr));
175 if (!account_store_iface) {
176 g_warning ("could not initialze ModestTnyAccountStore");
179 g_signal_connect (account_store_iface, "password_requested",
180 G_CALLBACK(on_password_requested),
184 priv->glade_xml = glade_xml_new (MODEST_GLADE, NULL,NULL);
185 if (!priv->glade_xml) {
186 g_warning ("failed to do glade stuff");
187 g_object_unref (obj);
191 /* FIXME: could be used, but doesn't work atm.
192 * glade_xml_signal_autoconnect(priv->glade_xml);
195 priv->modest_acc_mgr = modest_acc_mgr;
196 priv->modest_id_mgr = modest_id_mgr;
197 g_object_ref (priv->modest_conf = modest_conf);
199 priv->account_store = account_store_iface;
201 priv->modest_window_mgr = MODEST_WINDOW_MGR(modest_window_mgr_new());
202 g_signal_connect (priv->modest_window_mgr, "last_window_closed",
203 G_CALLBACK(modest_ui_last_window_closed),
206 account_names_list=modest_account_mgr_server_account_names(modest_acc_mgr, NULL, MODEST_PROTO_TYPE_ANY, NULL, FALSE);
207 identities_list=modest_identity_mgr_identity_names(modest_id_mgr, NULL);
208 if (!(account_names_list!=NULL || identities_list!=NULL))
209 wizard_account_dialog(MODEST_UI(obj));
210 g_slist_free(account_names_list);
211 g_slist_free(identities_list);
218 modest_ui_last_window_closed (GObject *obj, gpointer data)
220 /* FIXME: Other cleanups todo? Finalize Tinymail? */
226 on_password_requested (ModestTnyAccountStore *account_store,
227 const gchar *account_name, gpointer user_data)
230 GtkWidget *passdialog;
232 GtkWidget *infolabel;
233 GtkWidget *passentry;
235 const gchar *infostring=g_strconcat("Please enter the password for ", account_name, ".", NULL);
237 passdialog = gtk_dialog_new_with_buttons("MyDialog",
239 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
246 vbox=gtk_vbox_new(FALSE, 0);
248 infolabel=gtk_label_new(infostring);
249 passentry=gtk_entry_new();
251 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), infolabel, FALSE, FALSE, 0);
252 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), passentry, FALSE, FALSE, 0);
253 gtk_widget_show_all(passdialog);
255 retval = gtk_dialog_run (GTK_DIALOG(passdialog));
259 case GTK_RESPONSE_ACCEPT:
260 modest_account_mgr_set_server_account_string(modest_tny_account_store_get_accout_mgr(account_store),
263 gtk_entry_get_text(GTK_ENTRY(passentry)),
266 case GTK_RESPONSE_CANCEL:
268 * What happens, if canceled?"
273 gtk_widget_destroy (passdialog);
278 on_account_selector_selection_changed (GtkWidget *widget,
281 GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
286 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter))
288 gtk_tree_model_get(GTK_TREE_MODEL(model),
295 account_name="empty";
298 g_message("Value: '%s'\n", account_name);