1 /* modest-ui-wizard.c */
3 /* insert (c)/licensing information) */
6 #include <glade/glade.h>
7 #include <glib/gi18n.h>
12 #endif /*HAVE_CONFIG_H*/
14 #include "../modest-account-mgr.h"
15 #include "../modest-identity-mgr.h"
17 #include "modest-ui-glade.h"
18 #include "modest-ui-wizard.h"
21 static void wizard_incoming_button_toggled(GtkWidget *button,
24 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(button))==TRUE) {
25 awidget=glade_xml_get_widget(GLADE_XML(userdata), "AWOutUserNameEntry");
26 gtk_widget_set_sensitive(GTK_WIDGET(awidget), FALSE);
27 awidget=glade_xml_get_widget(GLADE_XML(userdata), "AWOutPasswordEntry");
28 gtk_widget_set_sensitive(GTK_WIDGET(awidget), FALSE);
31 awidget=glade_xml_get_widget(GLADE_XML(userdata), "AWOutUserNameEntry");
32 gtk_widget_set_sensitive(GTK_WIDGET(awidget), TRUE);
33 awidget=glade_xml_get_widget(GLADE_XML(userdata), "AWOutPasswordEntry");
34 gtk_widget_set_sensitive(GTK_WIDGET(awidget), TRUE);
38 void wizard_missing_notification(GtkWindow *parent, gchar *info_message) {
39 GtkWidget *DenyDialog;
41 DenyDialog=gtk_message_dialog_new(parent,
48 gtk_dialog_run(GTK_DIALOG(DenyDialog));
50 gtk_widget_destroy(DenyDialog);
53 gchar *get_text_from_combobox (GtkWidget *combobox){
54 /* Remember to free the returned variable after usage! */
56 GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(combobox));
61 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combobox), &iter)) {
62 gtk_tree_model_get(GTK_TREE_MODEL(model),
72 gboolean advance_sanity_check(GtkWindow *parent, GladeXML *glade_xml, gint cp) {
76 * all calls to wizard_missing_notification lack the parent window.
81 /* Only needed if the "mailbox name" field is used in the first page of the wizard.
82 * if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWMailboxnameEntry"))))==0)
84 * wizard_missing_notification(NULL, "Please enter mailbox name");
88 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWEMailAddressEntry"))))==0) {
89 wizard_missing_notification(NULL, "Please enter the E-Mail address.");
95 tmptext=gtk_combo_box_get_active_text(GTK_COMBO_BOX(glade_xml_get_widget(glade_xml, "AWMailboxtypeComboBox")));
97 wizard_missing_notification(NULL, "Please select mailbox type.");
101 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWInServerComboEntry"))))==0) {
102 wizard_missing_notification(NULL, "Please specify incoming server adress.");
105 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWUserNameEntry"))))==0) {
106 wizard_missing_notification(NULL, "Please enter user name.");
112 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutServerComboEntry"))))==0) {
113 wizard_missing_notification(NULL, "Please specify outgoing server address.");
116 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(glade_xml, "AWUseIncomingCheckButton")))==FALSE
117 && strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutUserNameEntry"))))==0) {
118 wizard_missing_notification(NULL, "Please enter user name.");
129 gchar *search_unused_account_or_identity_name(gpointer mgr, gchar *draft) {
130 GString *tmpaccount_name;
133 tmpaccount_name=g_string_new("");
134 g_string_printf(tmpaccount_name, "%s", draft);
135 if(MODEST_IS_ACCOUNT_MGR(mgr)) {
136 for(counter=0; modest_account_mgr_server_account_exists(mgr, tmpaccount_name->str, NULL); counter++)
137 g_string_printf(tmpaccount_name, "%s%d", draft, counter);
140 for(counter=0; modest_identity_mgr_identity_exists(mgr, tmpaccount_name->str, NULL); counter++)
141 g_string_printf(tmpaccount_name, "%s%d", draft, counter);
143 return g_string_free(tmpaccount_name, FALSE);
146 gboolean wizard_account_add(GladeXML *glade_xml, ModestUI *modest_ui)
148 ModestAccountMgr *acc_mgr;
149 ModestIdentityMgr *id_mgr;
153 ModestUIPrivate *priv;
158 g_return_val_if_fail (MODEST_IS_UI(modest_ui), FALSE);
159 priv = MODEST_UI_GET_PRIVATE(MODEST_UI(modest_ui));
160 conf = priv->modest_conf;
162 acc_mgr = priv->modest_acc_mgr;
163 id_mgr = priv->modest_id_mgr;
165 tmptext2=get_text_from_combobox(glade_xml_get_widget(glade_xml, "AWMailboxtypeComboBox"));
166 tmptext=g_utf8_strdown(tmptext2, -1);
169 store=search_unused_account_or_identity_name(acc_mgr, "incoming");
170 modest_account_mgr_add_server_account (acc_mgr,
172 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWInServerComboEntry"))),
173 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWUserNameEntry"))),
174 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWPasswordEntry"))),
179 transport=search_unused_account_or_identity_name(acc_mgr, "outgoing");
180 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(glade_xml, "AWUseIncomingCheckButton")))==TRUE)
181 modest_account_mgr_add_server_account (acc_mgr,
183 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutServerComboEntry"))),
184 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWUserNameEntry"))),
185 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWPasswordEntry"))),
188 modest_account_mgr_add_server_account (acc_mgr,
190 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutServerComboEntry"))),
191 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutUserNameEntry"))),
192 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutPasswordEntry"))),
195 identity=search_unused_account_or_identity_name(id_mgr, MODEST_IDENTITY_DEFAULT_IDENTITY);
196 if (!modest_identity_mgr_add_identity (id_mgr,
198 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWEMailAddressEntry"))),
199 "", "", FALSE, transport, FALSE ))
200 g_warning ("failed to add default identity");
208 void wizard_account_dialog(ModestUI *modest_ui)
212 ModestUIPrivate *priv;
213 GtkWidget *finish_button;
214 GtkWidget *back_button;
215 GtkWidget *next_button;
216 GtkWidget *cancel_button;
218 GtkWidget *use_incoming_button;
221 gboolean account_added_successfully=FALSE;
223 g_return_if_fail(MODEST_IS_UI(modest_ui));
224 priv = MODEST_UI_GET_PRIVATE(MODEST_UI(modest_ui));
226 glade_xml = glade_xml_new(MODEST_GLADE, "account_wizard", NULL);
228 dialog = glade_xml_get_widget(glade_xml, "account_wizard");
230 gtk_widget_show_all(dialog);
232 finish_button=glade_xml_get_widget(glade_xml, "AWFinishButton");
233 back_button=glade_xml_get_widget(glade_xml, "AWBackButton");
234 next_button=glade_xml_get_widget(glade_xml, "AWNextButton");
235 cancel_button=glade_xml_get_widget(glade_xml, "AWCancelButton");
236 notebook=glade_xml_get_widget(glade_xml, "AWNotebook");
238 gtk_widget_set_sensitive(finish_button, FALSE);
240 use_incoming_button=glade_xml_get_widget(glade_xml, "AWUseIncomingCheckButton");
241 g_signal_connect(use_incoming_button,
243 G_CALLBACK(wizard_incoming_button_toggled),
246 /* First page not used currently. It's reserved for the account preset. */
247 gtk_notebook_set_current_page (GTK_NOTEBOOK(notebook), 1);
250 cp=gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
253 gtk_widget_set_sensitive(back_button, FALSE);
256 gtk_widget_set_sensitive(back_button, TRUE);
259 gtk_widget_set_sensitive(finish_button, FALSE);
260 gtk_widget_set_sensitive(next_button, TRUE);
263 gtk_widget_set_sensitive(finish_button, TRUE);
264 gtk_widget_set_sensitive(next_button, FALSE);
267 g_error("I'm on page %d of notebook AWNotebook, which shouldn't have happened. Pulling emergency breaks.", cp);
271 result=gtk_dialog_run(GTK_DIALOG(dialog));
275 if (advance_sanity_check(NULL, glade_xml, cp)==TRUE)
276 gtk_notebook_next_page(GTK_NOTEBOOK(notebook));
279 gtk_notebook_prev_page(GTK_NOTEBOOK(notebook));
281 case GTK_RESPONSE_ACCEPT:
282 account_added_successfully=wizard_account_add(glade_xml, modest_ui);
285 account_added_successfully=FALSE;
288 while(result!=GTK_RESPONSE_DELETE_EVENT && result!=GTK_RESPONSE_CANCEL && account_added_successfully!=TRUE);
290 gtk_widget_destroy(dialog);
291 g_object_unref(glade_xml);
294 void new_wizard_account (GtkWidget *widget,
297 /* This will probably never be used to modify any existing account. */
298 wizard_account_dialog(MODEST_UI(user_data));