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_combobox (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)
61 * all calls to wizard_missing_notification lack the parent window.
67 /* Only needed if the "mailbox name" field is used in the first page of the wizard.
68 * if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWMailboxnameEntry"))))==0)
70 * wizard_missing_notification(NULL, "Please enter mailbox name");
74 tmptext=gtk_combo_box_get_active_text(GTK_COMBO_BOX(glade_xml_get_widget(glade_xml, "AWMailboxtypeComboBox")));
77 wizard_missing_notification(NULL, "Please select mailbox type.");
84 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWUserNameEntry"))))==0)
86 wizard_missing_notification(NULL, "Please enter user name.");
89 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWEMailAddressEntry"))))==0)
91 wizard_missing_notification(NULL, "Please enter the E-Mail address.");
97 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWInServerComboEntry"))))==0)
99 wizard_missing_notification(NULL, "Please specify incoming server adress.");
102 if (strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutServerComboEntry"))))==0)
104 wizard_missing_notification(NULL, "Please specify outgoing server address.");
114 gboolean wizard_account_add(GladeXML *glade_xml, ModestUI *modest_ui)
116 ModestAccountMgr *acc_mgr;
117 ModestIdentityMgr *id_mgr;
118 const gchar *account_name="default";
119 ModestUIPrivate *priv;
123 g_return_val_if_fail (MODEST_IS_UI(modest_ui), FALSE);
124 priv = MODEST_UI_GET_PRIVATE(MODEST_UI(modest_ui));
125 conf = priv->modest_conf;
128 acc_mgr = MODEST_ACCOUNT_MGR(modest_account_mgr_new (conf));
130 g_warning ("failed to instantiate account mgr");
134 if (modest_account_mgr_account_exists (acc_mgr, account_name, NULL)) {
135 if (!modest_account_mgr_remove_account(acc_mgr, account_name, NULL)) {
136 g_warning ("could not delete existing account");
140 if (!modest_account_mgr_add_account (acc_mgr, account_name, "defaultstore", "defaulttransport", NULL))
141 g_warning ("failed to add default account");
144 tmptext=get_text_from_combobox(glade_xml_get_widget(glade_xml, "AWMailboxtypeComboBox"));
145 modest_account_mgr_add_server_account (acc_mgr, "defaultstore",
146 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWInServerComboEntry"))),
147 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWUserNameEntry"))),
151 modest_account_mgr_add_server_account (acc_mgr, "defaulttransport",
152 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWOutServerComboEntry"))),
158 id_mgr = MODEST_IDENTITY_MGR(modest_identity_mgr_new (conf));
159 if (modest_identity_mgr_identity_exists(id_mgr, "defaultidentity", NULL)) {
160 if (!modest_identity_mgr_remove_identity(id_mgr, "defaultidentity", NULL)) {
161 g_warning ("could not delete existing default identity");
164 if (!modest_identity_mgr_add_identity (id_mgr,
165 MODEST_IDENTITY_DEFAULT_IDENTITY,
166 gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(glade_xml, "AWEMailAddressEntry"))),
167 "", "", FALSE, NULL, FALSE ))
168 g_warning ("failed to add default identity");
170 g_object_unref (G_OBJECT(acc_mgr));
171 g_object_unref (G_OBJECT(id_mgr));
176 void wizard_account_dialog(ModestUI *modest_ui)
180 ModestUIPrivate *priv;
181 GtkWidget *FinishButton;
182 GtkWidget *BackButton;
183 GtkWidget *NextButton;
184 GtkWidget *CancelButton;
188 gboolean account_added_successfully=FALSE;
190 g_return_if_fail(MODEST_IS_UI(modest_ui));
191 priv = MODEST_UI_GET_PRIVATE(MODEST_UI(modest_ui));
193 glade_xml = glade_xml_new(MODEST_GLADE, "account_wizard", NULL);
195 dialog = glade_xml_get_widget(glade_xml, "account_wizard");
197 gtk_widget_show_all(dialog);
199 FinishButton=glade_xml_get_widget(glade_xml, "AWFinishButton");
200 BackButton=glade_xml_get_widget(glade_xml, "AWBackButton");
201 NextButton=glade_xml_get_widget(glade_xml, "AWNextButton");
202 CancelButton=glade_xml_get_widget(glade_xml, "AWCancelButton");
203 Notebook=glade_xml_get_widget(glade_xml, "AWNotebook");
205 gtk_widget_set_sensitive(FinishButton, FALSE);
209 cp=gtk_notebook_get_current_page(GTK_NOTEBOOK(Notebook));
213 gtk_widget_set_sensitive(BackButton, FALSE);
216 gtk_widget_set_sensitive(BackButton, TRUE);
219 gtk_widget_set_sensitive(FinishButton, FALSE);
220 gtk_widget_set_sensitive(NextButton, TRUE);
223 gtk_widget_set_sensitive(FinishButton, TRUE);
224 gtk_widget_set_sensitive(NextButton, FALSE);
227 g_error("I'm on page %d of notebook AWNotebook, which shouldn't have happened. Pulling emergency breaks.", cp);
231 result=gtk_dialog_run(GTK_DIALOG(dialog));
236 if (advance_sanity_check(NULL, glade_xml, cp)==TRUE)
237 gtk_notebook_next_page(GTK_NOTEBOOK(Notebook));
240 gtk_notebook_prev_page(GTK_NOTEBOOK(Notebook));
242 case GTK_RESPONSE_ACCEPT:
243 account_added_successfully=wizard_account_add(glade_xml, modest_ui);
246 account_added_successfully=FALSE;
249 while(result!=GTK_RESPONSE_DELETE_EVENT && result!=GTK_RESPONSE_CANCEL && account_added_successfully!=TRUE);
251 gtk_widget_destroy(dialog);
252 g_object_unref(glade_xml);
255 void new_wizard_account (GtkWidget *widget,
258 /* This will probably never be used to modify any existing account. */
259 wizard_account_dialog(MODEST_UI(user_data));