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 gchar *on_password_requested (TnyAccountIface *, const gchar *, gboolean *);
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));
99 modest_ui_init (ModestUI *obj)
101 ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
103 priv->modest_acc_mgr = NULL;
104 priv->modest_id_mgr = NULL;
105 priv->modest_conf = NULL;
106 priv->modest_window_mgr = NULL;
107 priv->glade_xml = NULL;
108 priv->folder_view = NULL;
109 priv->header_view = NULL;
110 priv->message_view = NULL;
111 priv->current_folder = NULL;
112 priv->program = NULL;
117 modest_ui_finalize (GObject *obj)
119 ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
121 if (priv->modest_acc_mgr)
122 g_object_unref (priv->modest_acc_mgr);
123 priv->modest_acc_mgr = NULL;
125 if (priv->modest_id_mgr)
126 g_object_unref (priv->modest_id_mgr);
127 priv->modest_id_mgr = NULL;
129 if (priv->modest_conf)
130 g_object_unref (priv->modest_conf);
131 priv->modest_conf = NULL;
133 if (priv->modest_window_mgr)
134 g_object_unref (priv->modest_window_mgr);
135 priv->modest_window_mgr = NULL;
140 on_accounts_reloaded (ModestTnyAccountStore *account_store, gpointer user_data)
142 ModestUIPrivate *priv = user_data;
144 g_return_if_fail (MODEST_IS_TNY_FOLDER_TREE_VIEW (priv->folder_view));
145 g_return_if_fail (MODEST_IS_TNY_HEADER_TREE_VIEW (priv->header_view));
147 modest_tny_header_tree_view_set_folder (priv->header_view, NULL);
149 modest_tny_folder_tree_view_update_model(priv->folder_view, account_store);
154 modest_ui_new (ModestConf *modest_conf)
157 ModestUIPrivate *priv;
158 ModestAccountMgr *modest_acc_mgr;
159 ModestIdentityMgr *modest_id_mgr;
160 TnyAccountStoreIface *account_store_iface;
161 GSList *account_names_list;
162 GSList *identities_list;
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 modest_acc_mgr = MODEST_ACCOUNT_MGR(modest_account_mgr_new (modest_conf));
170 if (!modest_acc_mgr) {
171 g_warning ("could not create ModestAccountMgr instance");
172 g_object_unref (obj);
176 modest_id_mgr = MODEST_IDENTITY_MGR(modest_identity_mgr_new (modest_conf));
177 if (!modest_id_mgr) {
178 g_warning ("could not create ModestIdentityMgr instance");
179 g_object_unref (obj);
183 account_store_iface =
184 TNY_ACCOUNT_STORE_IFACE(modest_tny_account_store_new (modest_acc_mgr));
185 if (!account_store_iface) {
186 g_warning ("could not initialze ModestTnyAccountStore");
190 modest_tny_account_store_set_get_pass_func(MODEST_TNY_ACCOUNT_STORE(account_store_iface),
191 on_password_requested);
193 g_signal_connect (account_store_iface, "accounts_reloaded",
194 G_CALLBACK(on_accounts_reloaded), priv);
197 priv->glade_xml = glade_xml_new (MODEST_GLADE, NULL, NULL);
198 if (!priv->glade_xml) {
199 g_warning ("failed to do glade stuff");
200 g_object_unref (obj);
204 /* FIXME: could be used, but doesn't work atm.
205 * glade_xml_signal_autoconnect(priv->glade_xml);
208 priv->modest_acc_mgr = modest_acc_mgr;
209 priv->modest_id_mgr = modest_id_mgr;
210 g_object_ref (priv->modest_conf = modest_conf);
212 priv->account_store = account_store_iface;
214 priv->modest_window_mgr = MODEST_WINDOW_MGR(modest_window_mgr_new());
215 g_signal_connect (priv->modest_window_mgr, "last_window_closed",
216 G_CALLBACK(modest_ui_last_window_closed),
219 account_names_list = modest_account_mgr_server_account_names(modest_acc_mgr,
220 NULL, MODEST_PROTO_TYPE_ANY, NULL, FALSE);
221 identities_list = modest_identity_mgr_identity_names(modest_id_mgr, NULL);
222 if (!(account_names_list != NULL || identities_list != NULL))
223 wizard_account_dialog(MODEST_UI(obj));
224 g_slist_free(account_names_list);
225 g_slist_free(identities_list);
232 modest_ui_last_window_closed (GObject *obj, gpointer data)
234 /* FIXME: Other cleanups todo? Finalize Tinymail? */
240 on_password_requested (TnyAccountIface *account,
244 GtkWidget *passdialog;
246 GtkWidget *infoscroll;
247 GtkWidget *infolabel;
248 GtkWidget *passentry;
249 GtkTextBuffer *infobuffer;
253 passdialog = gtk_dialog_new_with_buttons(_("Password"),
255 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
262 vbox = gtk_vbox_new(FALSE, 0);
264 infobuffer = gtk_text_buffer_new (NULL);
265 gtk_text_buffer_set_text(infobuffer, prompt, -1);
266 infoscroll = gtk_scrolled_window_new(NULL, NULL);
267 infolabel = gtk_text_view_new_with_buffer(infobuffer);
268 gtk_container_add(GTK_CONTAINER(infoscroll), infolabel);
269 passentry = gtk_entry_new();
270 gtk_entry_set_visibility(GTK_ENTRY(passentry), FALSE);
272 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), infoscroll, FALSE, FALSE, 0);
273 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), passentry, FALSE, FALSE, 0);
274 gtk_widget_show_all(passdialog);
276 result = gtk_dialog_run (GTK_DIALOG(passdialog));
279 case GTK_RESPONSE_ACCEPT:
280 retval = g_strdup(gtk_entry_get_text(GTK_ENTRY(passentry)));
284 retval = g_strdup("");;
289 gtk_widget_hide(passdialog);
290 gtk_widget_destroy (passdialog);
291 while (gtk_events_pending()){
292 g_message("iterating over pending events");
293 gtk_main_iteration();
301 on_account_selector_selection_changed (GtkWidget *widget, gpointer user_data)
303 GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
308 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter)) {
309 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter,
310 0, &account_name, -1);
312 account_name="empty";
315 g_message("Value: '%s'\n", account_name);