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"
16 #include "modest-ui-glade.h"
17 #include "modest-ui-wizard.h"
19 void wizard_missing_notification(GtkWindow *parent, gchar *info_message)
21 GtkWidget *DenyDialog;
23 DenyDialog=gtk_message_dialog_new(parent,
30 gtk_dialog_run(GTK_DIALOG(DenyDialog));
32 gtk_widget_destroy(DenyDialog);
35 gchar *get_text_from_combo_box (GtkWidget *combobox)
37 /* Remember to free the returned variable after usage! */
39 GtkTreeModel *model = gtk_combo_box_get_model(GTK_COMBO_BOX(combobox));
44 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combobox), &iter))
46 gtk_tree_model_get(GTK_TREE_MODEL(model),
56 gboolean advance_sanity_check(GtkWindow *parent, GladeXML *glade_xml, gint cp)
58 GtkDialog *DenyDialog;
62 * all calls to wizard_missing_notification lack the parent window.
68 /* Only needed if the "mailbox name" field is used in the first page of the wizard.
69 * if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWMailboxnameEntry"))))==0)
71 * wizard_missing_notification(NULL, "Please enter mailbox name");
75 tmptext=gtk_combo_box_get_active_text(GTK_COMBO_BOX(glade_xml_get_widget(glade_xml, "AWMailboxtypeComboBox")));
78 wizard_missing_notification(NULL, "Please select mailbox type.");
85 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWUserNameEntry"))))==0)
87 wizard_missing_notification(NULL, "Please enter user name.");
90 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWEMailAddressEntry"))))==0)
92 wizard_missing_notification(NULL, "Please enter the E-Mail address.");
98 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWInServerComboEntry"))))==0)
100 wizard_missing_notification(NULL, "Please specify incoming server adress.");
103 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutServerComboEntry"))))==0)
105 wizard_missing_notification(NULL, "Please specify outgoing server address.");
115 void on_new_account1_activate (GtkMenuItem *menuitem,
120 ModestUIPrivate *priv;
121 GtkWidget *FinishButton;
122 GtkWidget *BackButton;
123 GtkWidget *NextButton;
124 GtkWidget *CancelButton;
129 gint finishallowed=0;
131 priv = MODEST_UI_GET_PRIVATE(MODEST_UI(user_data));
133 glade_xml = glade_xml_new(MODEST_GLADE, "account_wizard", NULL);
135 dialog = glade_xml_get_widget(glade_xml, "account_wizard");
137 gtk_widget_show_all(dialog);
139 FinishButton=glade_xml_get_widget(glade_xml, "AWFinishButton");
140 BackButton=glade_xml_get_widget(glade_xml, "AWBackButton");
141 NextButton=glade_xml_get_widget(glade_xml, "AWNextButton");
142 CancelButton=glade_xml_get_widget(glade_xml, "AWCancelButton");
143 Notebook=glade_xml_get_widget(glade_xml, "AWNotebook");
145 gtk_widget_set_sensitive(FinishButton, FALSE);
149 cp=gtk_notebook_get_current_page(GTK_NOTEBOOK(Notebook));
153 gtk_widget_set_sensitive(BackButton, FALSE);
156 gtk_widget_set_sensitive(BackButton, TRUE);
159 gtk_widget_set_sensitive(FinishButton, FALSE);
160 gtk_widget_set_sensitive(NextButton, TRUE);
163 gtk_widget_set_sensitive(FinishButton, TRUE);
164 gtk_widget_set_sensitive(NextButton, FALSE);
167 g_error("I'm on page %d of notebook AWNotebook, which shouldn't have happened. Pulling Emeregency breaks.", cp);
171 result=gtk_dialog_run(GTK_DIALOG(dialog));
176 if (advance_sanity_check(NULL, glade_xml, cp)==TRUE)
177 gtk_notebook_next_page(GTK_NOTEBOOK(Notebook));
180 gtk_notebook_prev_page(GTK_NOTEBOOK(Notebook));
184 while(result!=GTK_RESPONSE_DELETE_EVENT && result!=GTK_RESPONSE_ACCEPT && result!=GTK_RESPONSE_CANCEL);
186 if (result==GTK_RESPONSE_ACCEPT)
188 ModestAccountMgr *acc_mgr;
189 ModestIdentityMgr *id_mgr;
190 const gchar *account_name="default";
191 ModestConf *conf=priv->modest_conf;
193 g_return_if_fail (conf);
195 acc_mgr = MODEST_ACCOUNT_MGR(modest_account_mgr_new (conf));
197 g_warning ("failed to instantiate account mgr");
201 if (modest_account_mgr_account_exists (acc_mgr, account_name, NULL)) {
202 if (!modest_account_mgr_remove_account(acc_mgr, account_name, NULL)) {
203 g_warning ("could not delete existing account");
207 if (!modest_account_mgr_add_account (acc_mgr, account_name, "defaultstore", "defaulttransport", NULL))
208 g_warning ("failed to add default account");
211 modest_account_mgr_add_server_account (acc_mgr, "defaultstore",
212 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWInServerComboEntry"))),
213 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWUserNameEntry"))),
215 gtk_combo_box_get_active_text (GTK_COMBO_BOX(glade_xml_get_widget(glade_xml, "AWMailboxtypeComboBox"))));
216 modest_account_mgr_add_server_account (acc_mgr, "defaulttransport",
217 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutServerComboEntry"))),
223 id_mgr = MODEST_IDENTITY_MGR(modest_identity_mgr_new (conf));
224 if (modest_identity_mgr_identity_exists(id_mgr, "defaultidentity", NULL)) {
225 if (!modest_identity_mgr_remove_identity(id_mgr, "defaultidentity", NULL)) {
226 g_warning ("could not delete existing default identity");
229 if (!modest_identity_mgr_add_identity (id_mgr,
230 MODEST_IDENTITY_DEFAULT_IDENTITY,
231 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWEMailAddressEntry"))),
232 "", "", FALSE, NULL, FALSE ))
233 g_warning ("failed to add default identity");
235 g_object_unref (G_OBJECT(acc_mgr));
236 g_object_unref (G_OBJECT(id_mgr));
240 gtk_widget_destroy(dialog);
241 g_object_unref(glade_xml);