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.
30 #include <glade/glade.h>
31 #include <glib/gi18n.h>
36 #endif /*HAVE_CONFIG_H*/
38 #include "../modest-account-mgr.h"
39 #include "../modest-identity-mgr.h"
41 #include "modest-ui-glade.h"
42 #include "modest-ui-wizard.h"
45 static void wizard_incoming_button_toggled(GtkWidget *button,
48 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(button))==TRUE) {
49 awidget=glade_xml_get_widget(GLADE_XML(userdata), "AWOutUserNameEntry");
50 gtk_widget_set_sensitive(GTK_WIDGET(awidget), FALSE);
51 awidget=glade_xml_get_widget(GLADE_XML(userdata), "AWOutPasswordEntry");
52 gtk_widget_set_sensitive(GTK_WIDGET(awidget), FALSE);
55 awidget=glade_xml_get_widget(GLADE_XML(userdata), "AWOutUserNameEntry");
56 gtk_widget_set_sensitive(GTK_WIDGET(awidget), TRUE);
57 awidget=glade_xml_get_widget(GLADE_XML(userdata), "AWOutPasswordEntry");
58 gtk_widget_set_sensitive(GTK_WIDGET(awidget), TRUE);
62 void wizard_missing_notification(GtkWindow *parent, gchar *info_message) {
63 GtkWidget *DenyDialog;
65 DenyDialog=gtk_message_dialog_new(parent,
72 gtk_dialog_run(GTK_DIALOG(DenyDialog));
74 gtk_widget_destroy(DenyDialog);
77 gchar *get_text_from_combobox (GtkWidget *combobox){
78 /* Remember to free the returned variable after usage! */
80 GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(combobox));
85 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combobox), &iter)) {
86 gtk_tree_model_get(GTK_TREE_MODEL(model),
96 gboolean advance_sanity_check(GladeXML *glade_xml, gint cp) {
100 * all calls to wizard_missing_notification lack the parent window.
105 /* Only needed if the "mailbox name" field is used in the first page of the wizard.
106 * if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWMailboxnameEntry"))))==0)
108 * wizard_missing_notification(NULL, "Please enter mailbox name");
112 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWEMailAddressEntry"))))==0) {
113 wizard_missing_notification(NULL, "Please enter the E-Mail address.");
119 tmptext=gtk_combo_box_get_active_text(GTK_COMBO_BOX(glade_xml_get_widget(glade_xml, "AWMailboxtypeComboBox")));
121 wizard_missing_notification(NULL, "Please select mailbox type.");
125 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWInServerComboEntry"))))==0) {
126 wizard_missing_notification(NULL, "Please specify incoming server adress.");
129 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWUserNameEntry"))))==0) {
130 wizard_missing_notification(NULL, "Please enter user name.");
136 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutServerComboEntry"))))==0) {
137 wizard_missing_notification(NULL, "Please specify outgoing server address.");
140 /* smtp servers may work without a username
141 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(glade_xml, "AWUseIncomingCheckButton")))==FALSE
142 && strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutUserNameEntry"))))==0) {
143 wizard_missing_notification(NULL, "Please enter user name.");
154 gchar *search_unused_account_or_identity_name(gpointer mgr, gchar *draft) {
155 GString *tmpaccount_name;
158 tmpaccount_name=g_string_new("");
159 g_string_printf(tmpaccount_name, "%s", draft);
160 if(MODEST_IS_ACCOUNT_MGR(mgr)) {
161 for(counter=0; modest_account_mgr_account_exists(mgr, tmpaccount_name->str, TRUE, NULL); counter++)
162 g_string_printf(tmpaccount_name, "%s%d", draft, counter);
165 for(counter=0; modest_identity_mgr_identity_exists(mgr, tmpaccount_name->str, NULL); counter++)
166 g_string_printf(tmpaccount_name, "%s%d", draft, counter);
168 return g_string_free(tmpaccount_name, FALSE);
171 gboolean wizard_account_add(GladeXML *glade_xml, ModestUI *modest_ui)
173 ModestAccountMgr *acc_mgr;
174 ModestIdentityMgr *id_mgr;
178 ModestUIPrivate *priv;
183 g_return_val_if_fail (MODEST_IS_UI(modest_ui), FALSE);
184 priv = MODEST_UI_GET_PRIVATE(MODEST_UI(modest_ui));
185 conf = priv->modest_conf;
187 acc_mgr = priv->modest_acc_mgr;
188 id_mgr = priv->modest_id_mgr;
190 tmptext2=get_text_from_combobox(glade_xml_get_widget(glade_xml, "AWMailboxtypeComboBox"));
191 tmptext=g_utf8_strdown(tmptext2, -1);
194 store=search_unused_account_or_identity_name(acc_mgr, "incoming");
195 modest_account_mgr_add_server_account (acc_mgr,
197 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWInServerComboEntry"))),
198 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWUserNameEntry"))),
199 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWPasswordEntry"))),
204 transport=search_unused_account_or_identity_name(acc_mgr, "outgoing");
205 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(glade_xml, "AWUseIncomingCheckButton")))==TRUE)
206 modest_account_mgr_add_server_account (acc_mgr,
208 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutServerComboEntry"))),
209 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWUserNameEntry"))),
210 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWPasswordEntry"))),
213 modest_account_mgr_add_server_account (acc_mgr,
215 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutServerComboEntry"))),
216 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutUserNameEntry"))),
217 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutPasswordEntry"))),
220 identity=search_unused_account_or_identity_name(id_mgr, MODEST_IDENTITY_DEFAULT_IDENTITY);
221 if (!modest_identity_mgr_add_identity (id_mgr,
223 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWRealNameEntry"))),
224 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWEMailAddressEntry"))),
225 "", "", FALSE, transport, FALSE ))
226 g_warning ("failed to add default identity");
234 void wizard_account_dialog(ModestUI *modest_ui)
238 ModestUIPrivate *priv;
239 GtkWidget *finish_button;
240 GtkWidget *back_button;
241 GtkWidget *next_button;
242 GtkWidget *cancel_button;
244 GtkWidget *use_incoming_button;
247 gboolean account_added_successfully=FALSE;
249 g_return_if_fail(MODEST_IS_UI(modest_ui));
250 priv = MODEST_UI_GET_PRIVATE(MODEST_UI(modest_ui));
252 glade_xml = glade_xml_new(MODEST_GLADE, "account_wizard", NULL);
254 dialog = glade_xml_get_widget(glade_xml, "account_wizard");
256 gtk_widget_show_all(dialog);
258 finish_button=glade_xml_get_widget(glade_xml, "AWFinishButton");
259 back_button=glade_xml_get_widget(glade_xml, "AWBackButton");
260 next_button=glade_xml_get_widget(glade_xml, "AWNextButton");
261 cancel_button=glade_xml_get_widget(glade_xml, "AWCancelButton");
262 notebook=glade_xml_get_widget(glade_xml, "AWNotebook");
264 gtk_widget_set_sensitive(finish_button, FALSE);
266 use_incoming_button=glade_xml_get_widget(glade_xml, "AWUseIncomingCheckButton");
267 g_signal_connect(use_incoming_button,
269 G_CALLBACK(wizard_incoming_button_toggled),
272 /* First page not used currently. It's reserved for the account preset. */
273 gtk_notebook_set_current_page (GTK_NOTEBOOK(notebook), 1);
276 cp=gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
279 gtk_widget_set_sensitive(back_button, FALSE);
282 gtk_widget_set_sensitive(back_button, TRUE);
285 gtk_widget_set_sensitive(finish_button, FALSE);
286 gtk_widget_set_sensitive(next_button, TRUE);
289 gtk_widget_set_sensitive(finish_button, TRUE);
290 gtk_widget_set_sensitive(next_button, FALSE);
293 g_error("I'm on page %d of notebook AWNotebook, which shouldn't have happened. Pulling emergency breaks.", cp);
297 result=gtk_dialog_run(GTK_DIALOG(dialog));
301 if (advance_sanity_check(glade_xml, cp)==TRUE)
302 gtk_notebook_next_page(GTK_NOTEBOOK(notebook));
305 gtk_notebook_prev_page(GTK_NOTEBOOK(notebook));
307 case GTK_RESPONSE_ACCEPT:
308 account_added_successfully=wizard_account_add(glade_xml, modest_ui);
311 account_added_successfully=FALSE;
314 while(result!=GTK_RESPONSE_DELETE_EVENT && result!=GTK_RESPONSE_CANCEL && account_added_successfully!=TRUE);
316 gtk_widget_destroy(dialog);
317 g_object_unref(glade_xml);
320 void new_wizard_account (GtkWidget *widget,
323 /* This will probably never be used to modify any existing account. */
324 wizard_account_dialog(MODEST_UI(user_data));