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 /* modest-ui-wizard.c */
34 #include <glade/glade.h>
35 #include <glib/gi18n.h>
40 #endif /*HAVE_CONFIG_H*/
42 #include "../modest-account-mgr.h"
43 #include "../modest-identity-mgr.h"
45 #include "modest-ui-glade.h"
46 #include "modest-ui-wizard.h"
49 static void wizard_incoming_button_toggled(GtkWidget *button,
52 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(button))==TRUE) {
53 awidget=glade_xml_get_widget(GLADE_XML(userdata), "AWOutUserNameEntry");
54 gtk_widget_set_sensitive(GTK_WIDGET(awidget), FALSE);
55 awidget=glade_xml_get_widget(GLADE_XML(userdata), "AWOutPasswordEntry");
56 gtk_widget_set_sensitive(GTK_WIDGET(awidget), FALSE);
59 awidget=glade_xml_get_widget(GLADE_XML(userdata), "AWOutUserNameEntry");
60 gtk_widget_set_sensitive(GTK_WIDGET(awidget), TRUE);
61 awidget=glade_xml_get_widget(GLADE_XML(userdata), "AWOutPasswordEntry");
62 gtk_widget_set_sensitive(GTK_WIDGET(awidget), TRUE);
66 void wizard_missing_notification(GtkWindow *parent, gchar *info_message) {
67 GtkWidget *DenyDialog;
69 DenyDialog=gtk_message_dialog_new(parent,
76 gtk_dialog_run(GTK_DIALOG(DenyDialog));
78 gtk_widget_destroy(DenyDialog);
81 gchar *get_text_from_combobox (GtkWidget *combobox){
82 /* Remember to free the returned variable after usage! */
84 GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(combobox));
89 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combobox), &iter)) {
90 gtk_tree_model_get(GTK_TREE_MODEL(model),
100 gboolean advance_sanity_check(GladeXML *glade_xml, gint cp) {
104 * all calls to wizard_missing_notification lack the parent window.
109 /* Only needed if the "mailbox name" field is used in the first page of the wizard.
110 * if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWMailboxnameEntry"))))==0)
112 * wizard_missing_notification(NULL, "Please enter mailbox name");
116 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWEMailAddressEntry"))))==0) {
117 wizard_missing_notification(NULL, "Please enter the E-Mail address.");
123 tmptext=gtk_combo_box_get_active_text(GTK_COMBO_BOX(glade_xml_get_widget(glade_xml, "AWMailboxtypeComboBox")));
125 wizard_missing_notification(NULL, "Please select mailbox type.");
129 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWInServerComboEntry"))))==0) {
130 wizard_missing_notification(NULL, "Please specify incoming server adress.");
133 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWUserNameEntry"))))==0) {
134 wizard_missing_notification(NULL, "Please enter user name.");
140 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutServerComboEntry"))))==0) {
141 wizard_missing_notification(NULL, "Please specify outgoing server address.");
144 /* smtp servers may work without a username
145 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(glade_xml, "AWUseIncomingCheckButton")))==FALSE
146 && strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutUserNameEntry"))))==0) {
147 wizard_missing_notification(NULL, "Please enter user name.");
158 gchar *search_unused_account_or_identity_name(gpointer mgr, gchar *draft) {
159 GString *tmpaccount_name;
162 tmpaccount_name=g_string_new("");
163 g_string_printf(tmpaccount_name, "%s", draft);
164 if(MODEST_IS_ACCOUNT_MGR(mgr)) {
165 for(counter=0; modest_account_mgr_server_account_exists(mgr, tmpaccount_name->str, NULL); counter++)
166 g_string_printf(tmpaccount_name, "%s%d", draft, counter);
169 for(counter=0; modest_identity_mgr_identity_exists(mgr, tmpaccount_name->str, NULL); counter++)
170 g_string_printf(tmpaccount_name, "%s%d", draft, counter);
172 return g_string_free(tmpaccount_name, FALSE);
175 gboolean wizard_account_add(GladeXML *glade_xml, ModestUI *modest_ui)
177 ModestAccountMgr *acc_mgr;
178 ModestIdentityMgr *id_mgr;
182 ModestUIPrivate *priv;
187 g_return_val_if_fail (MODEST_IS_UI(modest_ui), FALSE);
188 priv = MODEST_UI_GET_PRIVATE(MODEST_UI(modest_ui));
189 conf = priv->modest_conf;
191 acc_mgr = priv->modest_acc_mgr;
192 id_mgr = priv->modest_id_mgr;
194 tmptext2=get_text_from_combobox(glade_xml_get_widget(glade_xml, "AWMailboxtypeComboBox"));
195 tmptext=g_utf8_strdown(tmptext2, -1);
198 store=search_unused_account_or_identity_name(acc_mgr, "incoming");
199 modest_account_mgr_add_server_account (acc_mgr,
201 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWInServerComboEntry"))),
202 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWUserNameEntry"))),
203 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWPasswordEntry"))),
208 transport=search_unused_account_or_identity_name(acc_mgr, "outgoing");
209 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(glade_xml, "AWUseIncomingCheckButton")))==TRUE)
210 modest_account_mgr_add_server_account (acc_mgr,
212 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutServerComboEntry"))),
213 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWUserNameEntry"))),
214 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWPasswordEntry"))),
217 modest_account_mgr_add_server_account (acc_mgr,
219 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutServerComboEntry"))),
220 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutUserNameEntry"))),
221 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutPasswordEntry"))),
224 identity=search_unused_account_or_identity_name(id_mgr, MODEST_IDENTITY_DEFAULT_IDENTITY);
225 if (!modest_identity_mgr_add_identity (id_mgr,
227 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWRealNameEntry"))),
228 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWEMailAddressEntry"))),
229 "", "", FALSE, transport, FALSE ))
230 g_warning ("failed to add default identity");
238 void wizard_account_dialog(ModestUI *modest_ui)
242 ModestUIPrivate *priv;
243 GtkWidget *finish_button;
244 GtkWidget *back_button;
245 GtkWidget *next_button;
246 GtkWidget *cancel_button;
248 GtkWidget *use_incoming_button;
251 gboolean account_added_successfully=FALSE;
253 g_return_if_fail(MODEST_IS_UI(modest_ui));
254 priv = MODEST_UI_GET_PRIVATE(MODEST_UI(modest_ui));
256 glade_xml = glade_xml_new(MODEST_GLADE, "account_wizard", NULL);
258 dialog = glade_xml_get_widget(glade_xml, "account_wizard");
260 gtk_widget_show_all(dialog);
262 finish_button=glade_xml_get_widget(glade_xml, "AWFinishButton");
263 back_button=glade_xml_get_widget(glade_xml, "AWBackButton");
264 next_button=glade_xml_get_widget(glade_xml, "AWNextButton");
265 cancel_button=glade_xml_get_widget(glade_xml, "AWCancelButton");
266 notebook=glade_xml_get_widget(glade_xml, "AWNotebook");
268 gtk_widget_set_sensitive(finish_button, FALSE);
270 use_incoming_button=glade_xml_get_widget(glade_xml, "AWUseIncomingCheckButton");
271 g_signal_connect(use_incoming_button,
273 G_CALLBACK(wizard_incoming_button_toggled),
276 /* First page not used currently. It's reserved for the account preset. */
277 gtk_notebook_set_current_page (GTK_NOTEBOOK(notebook), 1);
280 cp=gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
283 gtk_widget_set_sensitive(back_button, FALSE);
286 gtk_widget_set_sensitive(back_button, TRUE);
289 gtk_widget_set_sensitive(finish_button, FALSE);
290 gtk_widget_set_sensitive(next_button, TRUE);
293 gtk_widget_set_sensitive(finish_button, TRUE);
294 gtk_widget_set_sensitive(next_button, FALSE);
297 g_error("I'm on page %d of notebook AWNotebook, which shouldn't have happened. Pulling emergency breaks.", cp);
301 result=gtk_dialog_run(GTK_DIALOG(dialog));
305 if (advance_sanity_check(glade_xml, cp)==TRUE)
306 gtk_notebook_next_page(GTK_NOTEBOOK(notebook));
309 gtk_notebook_prev_page(GTK_NOTEBOOK(notebook));
311 case GTK_RESPONSE_ACCEPT:
312 account_added_successfully=wizard_account_add(glade_xml, modest_ui);
315 account_added_successfully=FALSE;
318 while(result!=GTK_RESPONSE_DELETE_EVENT && result!=GTK_RESPONSE_CANCEL && account_added_successfully!=TRUE);
320 gtk_widget_destroy(dialog);
321 g_object_unref(glade_xml);
324 void new_wizard_account (GtkWidget *widget,
327 /* This will probably never be used to modify any existing account. */
328 wizard_account_dialog(MODEST_UI(user_data));