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 "../widgets/modest-folder-view.h"
51 #include "../widgets/modest-header-view.h"
52 #include "../widgets/modest-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);
68 static void modest_ui_last_window_closed (GObject *obj, gpointer data);
70 gchar *on_password_requested (TnyAccountIface *, const gchar *, gboolean *);
80 static GObjectClass *parent_class = NULL;
84 modest_ui_get_type (void)
86 static GType my_type = 0;
88 static const GTypeInfo my_info = {
89 sizeof(ModestUIClass),
91 NULL, /* base finalize */
92 (GClassInitFunc) modest_ui_class_init,
93 NULL, /* class finalize */
94 NULL, /* class data */
97 (GInstanceInitFunc) modest_ui_init,
99 my_type = g_type_register_static (G_TYPE_OBJECT,
108 modest_ui_class_init (ModestUIClass *klass)
110 GObjectClass *gobject_class;
111 gobject_class = (GObjectClass*) klass;
113 parent_class = g_type_class_peek_parent (klass);
114 gobject_class->finalize = modest_ui_finalize;
116 g_type_class_add_private (gobject_class, sizeof(ModestUIPrivate));
122 modest_ui_init (ModestUI *obj)
124 ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
126 priv->modest_acc_mgr = NULL;
127 priv->modest_id_mgr = NULL;
128 priv->modest_conf = NULL;
129 priv->modest_window_mgr = NULL;
130 priv->glade_xml = NULL;
131 priv->folder_view = NULL;
132 priv->header_view = NULL;
133 priv->message_view = NULL;
134 priv->current_folder = NULL;
139 modest_ui_finalize (GObject *obj)
141 ModestUIPrivate *priv = MODEST_UI_GET_PRIVATE(obj);
143 if (priv->modest_acc_mgr)
144 g_object_unref (priv->modest_acc_mgr);
145 priv->modest_acc_mgr = NULL;
147 if (priv->modest_id_mgr)
148 g_object_unref (priv->modest_id_mgr);
149 priv->modest_id_mgr = NULL;
151 if (priv->modest_conf)
152 g_object_unref (priv->modest_conf);
153 priv->modest_conf = NULL;
155 if (priv->modest_window_mgr)
156 g_object_unref (priv->modest_window_mgr);
157 priv->modest_window_mgr = NULL;
162 on_accounts_reloaded (ModestTnyAccountStore *account_store, gpointer user_data)
164 ModestUIPrivate *priv = user_data;
166 g_return_if_fail (MODEST_IS_FOLDER_VIEW (priv->folder_view));
167 g_return_if_fail (MODEST_IS_HEADER_VIEW (priv->header_view));
169 modest_header_view_set_folder (MODEST_HEADER_VIEW(priv->header_view),
172 // modest_folder_view_update_model(MODEST_FOLDER_VIEW(priv->folder_view),
173 // TNY_ACCOUNT_STORE_IFACE(account_store));
178 modest_ui_new (ModestConf *modest_conf)
181 ModestUIPrivate *priv;
182 ModestAccountMgr *modest_acc_mgr;
183 ModestIdentityMgr *modest_id_mgr;
184 TnyAccountStoreIface *account_store_iface;
185 GSList *account_names_list, *cursor;
186 GSList *identities_list;
188 g_return_val_if_fail (modest_conf, NULL);
190 obj = g_object_new(MODEST_TYPE_UI, NULL);
191 priv = MODEST_UI_GET_PRIVATE(obj);
193 modest_acc_mgr = MODEST_ACCOUNT_MGR(modest_account_mgr_new (modest_conf));
194 if (!modest_acc_mgr) {
195 g_warning ("could not create ModestAccountMgr instance");
196 g_object_unref (obj);
200 modest_id_mgr = MODEST_IDENTITY_MGR(modest_identity_mgr_new (modest_conf));
201 if (!modest_id_mgr) {
202 g_warning ("could not create ModestIdentityMgr instance");
203 g_object_unref (obj);
207 account_store_iface =
208 TNY_ACCOUNT_STORE_IFACE(modest_tny_account_store_new (modest_acc_mgr));
209 if (!account_store_iface) {
210 g_warning ("could not initialze ModestTnyAccountStore");
214 //modest_tny_account_store_set_get_pass_func(MODEST_TNY_ACCOUNT_STORE(account_store_iface),
215 // on_password_requested);
217 g_signal_connect (account_store_iface, "accounts_reloaded",
218 G_CALLBACK(on_accounts_reloaded), priv);
221 priv->glade_xml = glade_xml_new (MODEST_GLADE, NULL, NULL);
222 if (!priv->glade_xml) {
223 g_warning ("failed to do glade stuff");
224 g_object_unref (obj);
228 /* FIXME: could be used, but doesn't work atm.
229 * glade_xml_signal_autoconnect(priv->glade_xml);
232 priv->modest_acc_mgr = modest_acc_mgr;
233 priv->modest_id_mgr = modest_id_mgr;
234 g_object_ref (priv->modest_conf = modest_conf);
236 priv->account_store = account_store_iface;
238 priv->modest_window_mgr = MODEST_WINDOW_MGR(modest_window_mgr_new());
239 g_signal_connect (priv->modest_window_mgr, "last_window_closed",
240 G_CALLBACK(modest_ui_last_window_closed),
243 account_names_list = modest_account_mgr_search_server_accounts(modest_acc_mgr,
244 NULL, MODEST_PROTO_TYPE_ANY,
246 identities_list = modest_identity_mgr_identity_names(modest_id_mgr, NULL);
247 if (!(account_names_list != NULL || identities_list != NULL))
248 wizard_account_dialog(MODEST_UI(obj));
250 cursor = account_names_list;
252 g_free (cursor->data);
253 cursor = cursor->next;
255 g_slist_free(account_names_list);
258 cursor = identities_list;
260 g_free (cursor->data);
261 cursor = cursor->next;
263 g_slist_free(identities_list);
265 return MODEST_UI(obj);
270 modest_ui_last_window_closed (GObject *obj, gpointer data)
272 /* FIXME: Other cleanups todo? Finalize Tinymail? */
278 on_password_requested (TnyAccountIface *account,
282 GtkWidget *passdialog;
284 GtkWidget *infoscroll;
285 GtkWidget *infolabel;
286 GtkWidget *passentry;
287 GtkTextBuffer *infobuffer;
291 passdialog = gtk_dialog_new_with_buttons(_("Password"),
293 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
300 vbox = gtk_vbox_new(FALSE, 0);
302 infobuffer = gtk_text_buffer_new (NULL);
303 gtk_text_buffer_set_text(infobuffer, prompt, -1);
304 infoscroll = gtk_scrolled_window_new(NULL, NULL);
305 infolabel = gtk_text_view_new_with_buffer(infobuffer);
306 gtk_container_add(GTK_CONTAINER(infoscroll), infolabel);
307 passentry = gtk_entry_new();
308 gtk_entry_set_visibility(GTK_ENTRY(passentry), FALSE);
310 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), infoscroll, FALSE, FALSE, 0);
311 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(passdialog)->vbox), passentry, FALSE, FALSE, 0);
312 gtk_widget_show_all(passdialog);
314 result = gtk_dialog_run (GTK_DIALOG(passdialog));
317 case GTK_RESPONSE_ACCEPT:
318 retval = g_strdup(gtk_entry_get_text(GTK_ENTRY(passentry)));
322 retval = g_strdup("");;
327 gtk_widget_hide(passdialog);
328 gtk_widget_destroy(passdialog);
329 while (gtk_events_pending()){
330 gtk_main_iteration();
338 on_account_selector_selection_changed (GtkWidget *widget, gpointer user_data)
340 GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
345 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter)) {
346 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter,
347 0, &account_name, -1);
349 account_name="empty";