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 /* TODO: put in auto* */
40 #include <tny-text-buffer-stream.h>
41 #include <tny-msg-folder.h>
43 #include "../modest-ui.h"
44 #include "../modest-window-mgr.h"
45 #include "../modest-account-mgr.h"
46 #include "../modest-account-mgr.h"
47 #include "../modest-identity-mgr.h"
49 #include "../modest-tny-account-store.h"
50 #include "../modest-tny-folder-tree-view.h"
51 #include "../modest-tny-header-tree-view.h"
52 #include "../modest-tny-msg-view.h"
53 #include "../modest-tny-transport-actions.h"
54 #include "../modest-tny-store-actions.h"
56 #include "../modest-text-utils.h"
57 #include "../modest-tny-msg-actions.h"
59 #include "../modest-editor-window.h"
61 #include "modest-ui-glade.h"
62 #include "modest-ui-wizard.h"
64 /* 'private'/'protected' functions */
65 static void modest_ui_class_init (ModestUIClass *klass);
66 static void modest_ui_init (ModestUI *obj);
67 static void modest_ui_finalize (GObject *obj);
69 //static void modest_ui_window_destroy (GtkWidget *win, GdkEvent *event, gpointer data);
70 static void modest_ui_last_window_closed (GObject *obj, gpointer data);
72 gchar *on_password_requested (TnyAccountIface *, const gchar *, gboolean *);
82 static GObjectClass *parent_class = NULL;
86 modest_ui_get_type (void)
88 static GType my_type = 0;
90 static const GTypeInfo my_info = {
91 sizeof(ModestUIClass),
93 NULL, /* base finalize */
94 (GClassInitFunc) modest_ui_class_init,
95 NULL, /* class finalize */
96 NULL, /* class data */
99 (GInstanceInitFunc) modest_ui_init,
101 my_type = g_type_register_static (G_TYPE_OBJECT,
110 modest_ui_class_init (ModestUIClass *klass)
112 GObjectClass *gobject_class;
113 gobject_class = (GObjectClass*) klass;
115 parent_class = g_type_class_peek_parent (klass);
116 gobject_class->finalize = modest_ui_finalize;
118 g_type_class_add_private (gobject_class, sizeof(ModestUIPrivate));
124 modest_ui_init (ModestUI *obj)
126 ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
128 priv->modest_acc_mgr = NULL;
129 priv->modest_id_mgr = NULL;
130 priv->modest_conf = NULL;
131 priv->modest_window_mgr = NULL;
132 priv->glade_xml = NULL;
133 priv->folder_view = NULL;
134 priv->header_view = NULL;
135 priv->message_view = NULL;
136 priv->current_folder = NULL;
137 priv->program = NULL;
142 modest_ui_finalize (GObject *obj)
144 ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
146 if (priv->modest_acc_mgr)
147 g_object_unref (priv->modest_acc_mgr);
148 priv->modest_acc_mgr = NULL;
150 if (priv->modest_id_mgr)
151 g_object_unref (priv->modest_id_mgr);
152 priv->modest_id_mgr = NULL;
154 if (priv->modest_conf)
155 g_object_unref (priv->modest_conf);
156 priv->modest_conf = NULL;
158 if (priv->modest_window_mgr)
159 g_object_unref (priv->modest_window_mgr);
160 priv->modest_window_mgr = NULL;
165 on_accounts_reloaded (ModestTnyAccountStore *account_store, gpointer user_data)
167 ModestUIPrivate *priv = user_data;
169 g_return_if_fail (MODEST_IS_TNY_FOLDER_TREE_VIEW (priv->folder_view));
170 g_return_if_fail (MODEST_IS_TNY_HEADER_TREE_VIEW (priv->header_view));
172 modest_tny_header_tree_view_set_folder (MODEST_TNY_HEADER_TREE_VIEW(priv->header_view),
175 modest_tny_folder_tree_view_update_model(MODEST_TNY_FOLDER_TREE_VIEW(priv->folder_view),
176 TNY_ACCOUNT_STORE(account_store));
181 modest_ui_new (ModestConf *modest_conf)
184 ModestUIPrivate *priv;
185 ModestAccountMgr *modest_acc_mgr;
186 ModestIdentityMgr *modest_id_mgr;
187 TnyAccountStoreIface *account_store_iface;
188 GSList *account_names_list;
189 GSList *identities_list;
191 g_return_val_if_fail (modest_conf, NULL);
193 obj = g_object_new(MODEST_TYPE_UI, NULL);
194 priv = MODEST_UI_GET_PRIVATE(obj);
196 modest_acc_mgr = MODEST_ACCOUNT_MGR(modest_account_mgr_new (modest_conf));
197 if (!modest_acc_mgr) {
198 g_warning ("could not create ModestAccountMgr instance");
199 g_object_unref (obj);
203 modest_id_mgr = MODEST_IDENTITY_MGR(modest_identity_mgr_new (modest_conf));
204 if (!modest_id_mgr) {
205 g_warning ("could not create ModestIdentityMgr instance");
206 g_object_unref (obj);
210 account_store_iface =
211 TNY_ACCOUNT_STORE_IFACE(modest_tny_account_store_new (modest_acc_mgr));
212 if (!account_store_iface) {
213 g_warning ("could not initialze ModestTnyAccountStore");
217 modest_tny_account_store_set_get_pass_func(MODEST_TNY_ACCOUNT_STORE(account_store_iface),
218 on_password_requested);
220 g_signal_connect (account_store_iface, "accounts_reloaded",
221 G_CALLBACK(on_accounts_reloaded), priv);
224 priv->glade_xml = glade_xml_new (MODEST_GLADE, NULL, NULL);
225 if (!priv->glade_xml) {
226 g_warning ("failed to do glade stuff");
227 g_object_unref (obj);
231 /* FIXME: could be used, but doesn't work atm.
232 * glade_xml_signal_autoconnect(priv->glade_xml);
235 priv->modest_acc_mgr = modest_acc_mgr;
236 priv->modest_id_mgr = modest_id_mgr;
237 g_object_ref (priv->modest_conf = modest_conf);
239 priv->account_store = account_store_iface;
241 priv->modest_window_mgr = MODEST_WINDOW_MGR(modest_window_mgr_new());
242 g_signal_connect (priv->modest_window_mgr, "last_window_closed",
243 G_CALLBACK(modest_ui_last_window_closed),
246 account_names_list = modest_account_mgr_search_server_accounts (modest_acc_mgr,
247 NULL, MODEST_PROTO_TYPE_ANY, NULL, FALSE);
248 identities_list = modest_identity_mgr_identity_names(modest_id_mgr, NULL);
249 if (!(account_names_list != NULL || identities_list != NULL))
250 wizard_account_dialog(MODEST_UI(obj));
251 g_slist_free(account_names_list);
252 g_slist_free(identities_list);
259 modest_ui_last_window_closed (GObject *obj, gpointer data)
261 /* FIXME: Other cleanups todo? Finalize Tinymail? */
267 on_password_requested (TnyAccountIface *account,
271 GtkWidget *passdialog;
273 GtkWidget *infoscroll;
274 GtkWidget *infolabel;
275 GtkWidget *passentry;
276 GtkTextBuffer *infobuffer;
280 passdialog = gtk_dialog_new_with_buttons(_("Password"),
282 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
289 vbox = gtk_vbox_new(FALSE, 0);
291 infobuffer = gtk_text_buffer_new (NULL);
292 gtk_text_buffer_set_text(infobuffer, prompt, -1);
293 infoscroll = gtk_scrolled_window_new(NULL, NULL);
294 infolabel = gtk_text_view_new_with_buffer(infobuffer);
295 gtk_container_add(GTK_CONTAINER(infoscroll), infolabel);
296 passentry = gtk_entry_new();
297 gtk_entry_set_visibility(GTK_ENTRY(passentry), FALSE);
299 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), infoscroll, FALSE, FALSE, 0);
300 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), passentry, FALSE, FALSE, 0);
301 gtk_widget_show_all(passdialog);
303 result = gtk_dialog_run (GTK_DIALOG(passdialog));
306 case GTK_RESPONSE_ACCEPT:
307 retval = g_strdup(gtk_entry_get_text(GTK_ENTRY(passentry)));
311 retval = g_strdup("");;
316 gtk_widget_hide(passdialog);
317 gtk_widget_destroy (passdialog);
318 while (gtk_events_pending()){
319 g_message("iterating over pending events");
320 gtk_main_iteration();
328 on_account_selector_selection_changed (GtkWidget *widget, gpointer user_data)
330 GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
335 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter)) {
336 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter,
337 0, &account_name, -1);
339 account_name="empty";
342 g_message("Value: '%s'\n", account_name);