11845a94137d13c2302bd68a523c91f416787ed5
[claws.git] / src / wizard.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2004 Hiroyuki Yamamoto
4  * This file (C) 2004 Colin Leroy
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #  include "config.h"
23 #endif
24
25 #include "defs.h"
26
27 #include <glib.h>
28 #include <glib/gi18n.h>
29 #include <gdk/gdkkeysyms.h>
30 #include <gtk/gtkwidget.h>
31 #include <gtk/gtkvbox.h>
32 #include <gtk/gtkbox.h>
33 #include <gtk/gtktable.h>
34 #include <gtk/gtkentry.h>
35 #include <gtk/gtklabel.h>
36 #include <gtk/gtknotebook.h>
37 #include <gtk/gtktogglebutton.h>
38 #include <gtk/gtkcheckbutton.h>
39 #include <gtk/gtk.h>
40
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <ctype.h>
45
46 #ifdef HAVE_CONFIG_H
47 #  include "config.h"
48 #endif
49
50 #include "utils.h"
51 #include "gtk/menu.h"
52 #include "account.h"
53 #include "prefs_account.h"
54 #include "mainwindow.h"
55 #include "stock_pixmap.h"
56 #include "setup.h"
57 #include "folder.h"
58 #ifdef USE_OPENSSL                      
59 #include "ssl.h"
60 #endif
61 typedef enum
62 {
63         GO_BACK,
64         GO_FORWARD,
65         CANCEL,
66         FINISHED
67 } PageNavigation;
68
69 typedef struct
70 {
71         GtkWidget *window;
72         GSList    *pages;
73         GtkWidget *notebook;
74
75         MainWindow *mainwin;
76         
77         GtkWidget *email;
78         GtkWidget *full_name;
79         GtkWidget *organization;
80
81         GtkWidget *mailbox_name;
82         
83         GtkWidget *smtp_server;
84
85         GtkWidget *recv_type;
86         GtkWidget *recv_label;
87         GtkWidget *recv_server;
88         GtkWidget *recv_username;
89         GtkWidget *recv_password;
90         GtkWidget *recv_username_label;
91         GtkWidget *recv_password_label;
92         GtkWidget *recv_imap_label;
93         GtkWidget *recv_imap_subdir;
94
95 #ifdef USE_OPENSSL
96         GtkWidget *smtp_use_ssl;
97         GtkWidget *recv_use_ssl;
98 #endif
99         
100         gboolean create_mailbox;
101         gboolean finished;
102         gboolean result;
103
104 } WizardWindow;
105
106 static void wizard_write_config(WizardWindow *wizard)
107 {
108         gboolean mailbox_ok = FALSE;
109         PrefsAccount *prefs_account = prefs_account_new();
110         GList *account_list = NULL;
111         GtkWidget *menu, *menuitem;
112         
113         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(wizard->recv_type));
114         menuitem = gtk_menu_get_active(GTK_MENU(menu));
115         prefs_account->protocol = GPOINTER_TO_INT
116                         (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
117
118         if (wizard->create_mailbox && prefs_account->protocol != A_IMAP4) {
119                 mailbox_ok = setup_write_mailbox_path(wizard->mainwin, 
120                                 gtk_entry_get_text(GTK_ENTRY(wizard->mailbox_name)));
121         }
122
123         if (prefs_account->protocol != A_LOCAL)
124                 prefs_account->account_name = g_strdup_printf("%s@%s",
125                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_username)),
126                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
127         else
128                 prefs_account->account_name = g_strdup_printf("%s",
129                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
130
131         prefs_account->name = g_strdup(
132                                 gtk_entry_get_text(GTK_ENTRY(wizard->full_name)));
133         prefs_account->address = g_strdup(
134                                 gtk_entry_get_text(GTK_ENTRY(wizard->email)));
135         prefs_account->organization = g_strdup(
136                                 gtk_entry_get_text(GTK_ENTRY(wizard->organization)));
137         prefs_account->smtp_server = g_strdup(
138                                 gtk_entry_get_text(GTK_ENTRY(wizard->smtp_server)));
139
140         if (prefs_account->protocol != A_LOCAL)
141                 prefs_account->recv_server = g_strdup(
142                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
143         else
144                 prefs_account->local_mbox = g_strdup(
145                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
146
147         prefs_account->userid = g_strdup(
148                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_username)));
149         prefs_account->passwd = g_strdup(
150                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_password)));
151
152 #ifdef USE_OPENSSL                      
153         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_ssl)))
154                 prefs_account->ssl_smtp = SSL_TUNNEL;
155         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->recv_use_ssl))) {
156                 if (prefs_account->protocol == A_IMAP4)
157                         prefs_account->ssl_imap = SSL_TUNNEL;
158                 else
159                         prefs_account->ssl_pop = SSL_TUNNEL;
160         }
161 #endif
162         if (prefs_account->protocol == A_IMAP4) {
163                 gchar *directory = gtk_editable_get_chars(
164                         GTK_EDITABLE(wizard->recv_imap_subdir), 0, -1);
165                 if (directory && strlen(directory)) {
166                         prefs_account->imap_dir = g_strdup(directory);
167                 }
168                 g_free(directory);
169         }
170
171         account_list = g_list_append(account_list, prefs_account);
172         prefs_account_write_config_all(account_list);
173         prefs_account_free(prefs_account);
174         account_read_config_all();
175 }
176
177 static GtkWidget* create_page (WizardWindow *wizard, const char * title)
178 {
179         GtkWidget *w;
180         GtkWidget *vbox;
181         GtkWidget *hbox;
182         GtkWidget *image;
183         char *title_string;
184
185         vbox = gtk_vbox_new (FALSE, 6);
186         gtk_container_set_border_width  (GTK_CONTAINER(vbox), 10);
187
188         /* create the titlebar */
189         hbox = gtk_hbox_new (FALSE, 12);
190         image = stock_pixmap_widget(wizard->window, 
191                                 STOCK_PIXMAP_SYLPHEED_ICON);
192         gtk_box_pack_start (GTK_BOX(hbox), image, FALSE, FALSE, 0);
193         title_string = g_strconcat ("<span size=\"xx-large\" weight=\"ultrabold\">", title ? title : "", "</span>", NULL);
194         w = gtk_label_new (title_string);
195         gtk_label_set_use_markup (GTK_LABEL(w), TRUE);
196         g_free (title_string);
197         gtk_box_pack_start (GTK_BOX(hbox), w, FALSE, FALSE, 0);
198
199         /* pack the titlebar */
200         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
201
202         /* pack the separator */
203         gtk_box_pack_start (GTK_BOX(vbox), gtk_hseparator_new(), FALSE, FALSE, 0);
204
205         /* pack space */
206         w = gtk_alignment_new (0, 0, 0, 0);
207         gtk_widget_set_size_request (w, 0, 6);
208         gtk_box_pack_start (GTK_BOX(vbox), w, FALSE, FALSE, 0);
209
210         return vbox;
211 }
212
213 #define GTK_TABLE_ADD_ROW_AT(table,text,entry,i) {                            \
214         GtkWidget *label = gtk_label_new(text);                               \
215         gtk_table_attach(GTK_TABLE(table), label,                             \
216                          0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            \
217         if (GTK_IS_MISC(label))                                               \
218                 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);              \
219         gtk_table_attach(GTK_TABLE(table), entry,                             \
220                          1,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            \
221 }
222
223 static gchar *get_default_email_addr(void)
224 {
225         gchar *domain_name = g_strdup(get_domain_name());
226         gchar *result;
227         if (strchr(domain_name, '.') != strrchr(domain_name, '.')
228         && strlen(strchr(domain_name, '.')) > 6) {
229                 gchar *tmp = g_strdup(strchr(domain_name, '.')+1);
230                 g_free(domain_name);
231                 domain_name = tmp;
232         }
233         result = g_strdup_printf("%s@%s",
234                                 g_get_user_name(),
235                                 domain_name);
236         g_free(domain_name);
237         return result;
238 }
239
240 static gchar *get_default_server(WizardWindow * wizard, const gchar *type)
241 {
242         gchar *domain_name = g_strdup(get_domain_name());
243         gchar *result;
244         
245         if (strchr(domain_name, '.') != strrchr(domain_name, '.')
246         && strlen(strchr(domain_name, '.')) > 6) {
247                 gchar *tmp = g_strdup(strchr(domain_name, '.')+1);
248                 g_free(domain_name);
249                 domain_name = tmp;
250         } else if (strchr(domain_name, '.') == NULL) {
251                 /* only hostname found, use email suffix */
252                 gchar *mail;
253                 mail = gtk_editable_get_chars(GTK_EDITABLE(wizard->email), 0, -1);
254
255                 if (strlen (mail) && strstr(mail, "@")) {
256                         g_free(domain_name);
257                         domain_name = g_strdup(strstr(mail, "@")+1);
258                 }
259                 g_free(mail);
260         }
261         result = g_strdup_printf("%s.%s",
262                                 type, domain_name);
263         g_free(domain_name);
264         return result;
265 }
266
267 static void wizard_email_changed(GtkWidget *widget, gpointer data)
268 {
269         WizardWindow *wizard = (WizardWindow *)data;
270         RecvProtocol protocol;
271         gchar *text;
272         protocol = GPOINTER_TO_INT
273                 (g_object_get_data(G_OBJECT(wizard->recv_type), MENU_VAL_ID));
274         
275         text = get_default_server(wizard, "smtp");
276         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_server), text);
277         g_free(text);
278
279         if (protocol == A_POP3) {
280                 text = get_default_server(wizard, "pop");
281                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
282                 g_free(text);
283         } else if (protocol == A_IMAP4) {
284                 text = get_default_server(wizard, "imap");
285                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
286                 g_free(text);
287         } else if (protocol == A_LOCAL) {
288                 gchar *mbox = g_strdup_printf("/var/mail/%s", g_get_user_name());
289                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), mbox);
290                 g_free(mbox);
291         }
292 }
293
294 static GtkWidget* user_page (WizardWindow * wizard)
295 {
296         GtkWidget *table = gtk_table_new(3,2, FALSE);
297         gchar *text;
298         gint i = 0;
299         
300         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
301         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
302
303         wizard->full_name = gtk_entry_new();
304         gtk_entry_set_text(GTK_ENTRY(wizard->full_name), g_get_real_name());
305         GTK_TABLE_ADD_ROW_AT(table, _("Your name:"), 
306                              wizard->full_name, i); i++;
307         
308         wizard->email = gtk_entry_new();
309         text = get_default_email_addr();
310         gtk_entry_set_text(GTK_ENTRY(wizard->email), text);
311         g_free(text);
312         GTK_TABLE_ADD_ROW_AT(table, _("Your email address:"), 
313                              wizard->email, i); i++;
314         
315         wizard->organization = gtk_entry_new();
316         GTK_TABLE_ADD_ROW_AT(table, _("Your organization:"), 
317                              wizard->organization, i); i++;
318         
319         g_signal_connect(G_OBJECT(wizard->email), "changed",
320                          G_CALLBACK(wizard_email_changed),
321                          wizard);
322         return table;
323 }
324
325 static GtkWidget* mailbox_page (WizardWindow * wizard)
326 {
327         GtkWidget *table = gtk_table_new(1,2, FALSE);
328         gint i = 0;
329         
330         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
331         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
332
333         wizard->mailbox_name = gtk_entry_new();
334         gtk_entry_set_text(GTK_ENTRY(wizard->mailbox_name), "Mail");
335         GTK_TABLE_ADD_ROW_AT(table, _("Mailbox name:"), 
336                              wizard->mailbox_name, i); i++;
337         
338         return table;
339 }
340
341 static GtkWidget* smtp_page (WizardWindow * wizard)
342 {
343         GtkWidget *table = gtk_table_new(1,2, FALSE);
344         gchar *text;
345         gint i = 0;
346         
347         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
348         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
349
350         wizard->smtp_server = gtk_entry_new();
351         text = get_default_server(wizard, "smtp");
352         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_server), text);
353         g_free(text);
354         GTK_TABLE_ADD_ROW_AT(table, _("SMTP server address:"), 
355                              wizard->smtp_server, i); i++;
356         return table;
357 }
358
359 static void wizard_protocol_changed(GtkMenuItem *menuitem, gpointer data)
360 {
361         WizardWindow *wizard = (WizardWindow *)data;
362         RecvProtocol protocol;
363         gchar *text;
364         protocol = GPOINTER_TO_INT
365                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
366         
367         if (protocol == A_POP3) {
368                 text = get_default_server(wizard, "pop");
369                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
370                 gtk_widget_hide(wizard->recv_imap_label);
371                 gtk_widget_hide(wizard->recv_imap_subdir);
372                 gtk_widget_show(wizard->recv_username);
373                 gtk_widget_show(wizard->recv_password);
374                 gtk_widget_show(wizard->recv_username_label);
375                 gtk_widget_show(wizard->recv_password_label);
376                 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("Server address:"));
377                 g_free(text);
378         } else if (protocol == A_IMAP4) {
379                 text = get_default_server(wizard, "imap");
380                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
381                 gtk_widget_show(wizard->recv_imap_label);
382                 gtk_widget_show(wizard->recv_imap_subdir);
383                 gtk_widget_show(wizard->recv_username);
384                 gtk_widget_show(wizard->recv_password);
385                 gtk_widget_show(wizard->recv_username_label);
386                 gtk_widget_show(wizard->recv_password_label);
387                 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("Server address:"));
388                 g_free(text);
389         } else if (protocol == A_LOCAL) {
390                 gchar *mbox = g_strdup_printf("/var/mail/%s", g_get_user_name());
391                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), mbox);
392                 g_free(mbox);
393                 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("Local mailbox:"));
394                 gtk_widget_hide(wizard->recv_imap_label);
395                 gtk_widget_hide(wizard->recv_imap_subdir);
396                 gtk_widget_hide(wizard->recv_username);
397                 gtk_widget_hide(wizard->recv_password);
398                 gtk_widget_hide(wizard->recv_username_label);
399                 gtk_widget_hide(wizard->recv_password_label);
400         }
401 }
402
403 static GtkWidget* recv_page (WizardWindow * wizard)
404 {
405         GtkWidget *table = gtk_table_new(5,2, FALSE);
406         GtkWidget *menu = gtk_menu_new();
407         GtkWidget *menuitem;
408         gchar *text;
409         gint i = 0;
410         
411         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
412         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
413
414         wizard->recv_type = gtk_option_menu_new();
415         
416         MENUITEM_ADD (menu, menuitem, _("POP3"), A_POP3);
417         g_signal_connect(G_OBJECT(menuitem), "activate",
418                          G_CALLBACK(wizard_protocol_changed),
419                          wizard);
420         MENUITEM_ADD (menu, menuitem, _("IMAP"), A_IMAP4);
421         g_signal_connect(G_OBJECT(menuitem), "activate",
422                          G_CALLBACK(wizard_protocol_changed),
423                          wizard);
424         MENUITEM_ADD (menu, menuitem, _("Local mbox file"), A_LOCAL);
425         g_signal_connect(G_OBJECT(menuitem), "activate",
426                          G_CALLBACK(wizard_protocol_changed),
427                          wizard);
428
429         gtk_option_menu_set_menu (GTK_OPTION_MENU (wizard->recv_type), menu);
430         GTK_TABLE_ADD_ROW_AT(table, _("Server type:"), 
431                              wizard->recv_type, i); i++;
432
433         wizard->recv_server = gtk_entry_new();
434         text = get_default_server(wizard, "pop");
435         gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
436         g_free(text);
437         
438         wizard->recv_label = gtk_label_new(_("Server address:"));
439         gtk_table_attach(GTK_TABLE(table), wizard->recv_label,                        
440                          0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            
441         if (GTK_IS_MISC(wizard->recv_label))                                                  
442                 gtk_misc_set_alignment(GTK_MISC(wizard->recv_label), 1, 0.5);         
443         gtk_table_attach(GTK_TABLE(table), wizard->recv_server,       
444                          1,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            
445         i++;
446         
447         wizard->recv_username = gtk_entry_new();
448         wizard->recv_username_label = gtk_label_new(_("Username:"));
449         gtk_table_attach(GTK_TABLE(table), wizard->recv_username_label,                               
450                          0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            
451         if (GTK_IS_MISC(wizard->recv_username_label))                                                 
452                 gtk_misc_set_alignment(GTK_MISC(wizard->recv_username_label), 1, 0.5);        
453         gtk_table_attach(GTK_TABLE(table), wizard->recv_username,             
454                          1,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            
455         i++;
456         
457         wizard->recv_password = gtk_entry_new();
458         wizard->recv_password_label = gtk_label_new(_("Password:"));
459         gtk_table_attach(GTK_TABLE(table), wizard->recv_password_label,                               
460                          0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            
461         if (GTK_IS_MISC(wizard->recv_password_label))                                                 
462                 gtk_misc_set_alignment(GTK_MISC(wizard->recv_password_label), 1, 0.5);        
463         gtk_table_attach(GTK_TABLE(table), wizard->recv_password,             
464                          1,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            
465         gtk_entry_set_visibility(GTK_ENTRY(wizard->recv_password), FALSE);
466         i++;
467         
468         wizard->recv_imap_subdir = gtk_entry_new();
469         wizard->recv_imap_label = gtk_label_new(_("IMAP server directory:"));
470         
471         gtk_table_attach(GTK_TABLE(table), wizard->recv_imap_label,                           
472                          0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            
473         if (GTK_IS_MISC(wizard->recv_imap_label))                                                     
474                 gtk_misc_set_alignment(GTK_MISC(wizard->recv_imap_label), 1, 0.5);            
475         gtk_table_attach(GTK_TABLE(table), wizard->recv_imap_subdir,          
476                          1,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            
477
478         i++;
479         
480         return table;
481 }
482
483 #ifdef USE_OPENSSL
484 static GtkWidget* ssl_page (WizardWindow * wizard)
485 {
486         GtkWidget *table = gtk_table_new(2,2, FALSE);
487         gint i = 0;
488         
489         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
490         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
491
492         wizard->smtp_use_ssl = gtk_check_button_new_with_label(
493                                         _("Use SSL to connect to SMTP server"));
494         gtk_table_attach(GTK_TABLE(table), wizard->smtp_use_ssl,      
495                          0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0); i++;
496         
497         wizard->recv_use_ssl = gtk_check_button_new_with_label(
498                                         _("Use SSL to connect to receiving server"));
499         gtk_table_attach(GTK_TABLE(table), wizard->recv_use_ssl,      
500                          0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
501         
502         return table;
503 }
504 #endif
505
506 static void
507 wizard_response_cb (GtkDialog * dialog, int response, gpointer data)
508 {
509         WizardWindow * wizard = (WizardWindow *)data;
510         int current_page, num_pages;
511         GtkWidget *menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(wizard->recv_type));
512         GtkWidget *menuitem = gtk_menu_get_active(GTK_MENU(menu));
513         gint protocol = GPOINTER_TO_INT
514                         (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
515         gboolean skip_mailbox_page = FALSE;
516         
517         if (protocol == A_IMAP4) {
518                 skip_mailbox_page = TRUE;
519         }
520         
521         num_pages = g_slist_length(wizard->pages);
522         current_page = gtk_notebook_get_current_page (
523                                 GTK_NOTEBOOK(wizard->notebook));
524         if (response == CANCEL)
525         {
526                 wizard->finished = TRUE;
527                 wizard->result = FALSE;
528                 gtk_widget_destroy (GTK_WIDGET(dialog));
529         }
530         else if (response == FINISHED)
531         {
532                 wizard_write_config(wizard);
533                 wizard->finished = TRUE;
534                 wizard->result = TRUE;
535                 gtk_widget_destroy (GTK_WIDGET(dialog));
536         }
537         else
538         {
539                 if (response == GO_BACK)
540                 {
541                         if (current_page > 0) {
542                                 current_page--;
543                                 if (current_page == 4 && skip_mailbox_page) {
544                                         /* mailbox */
545                                         current_page--;
546                                 }
547                                 gtk_notebook_set_current_page (
548                                         GTK_NOTEBOOK(wizard->notebook), 
549                                         current_page);
550                         }
551                 }
552                 else if (response == GO_FORWARD)
553                 {
554                         if (current_page < (num_pages-1)) {
555                                 current_page++;
556                                 if (current_page == 4 && skip_mailbox_page) {
557                                         /* mailbox */
558                                         current_page++;
559                                 }
560                                 gtk_notebook_set_current_page (
561                                         GTK_NOTEBOOK(wizard->notebook), 
562                                         current_page);
563                         }
564                 }
565
566                 gtk_dialog_set_response_sensitive (dialog, GO_BACK, 
567                                 current_page > 0);
568                 gtk_dialog_set_response_sensitive (dialog, GO_FORWARD, 
569                                 current_page < (num_pages - 1));
570                 gtk_dialog_set_response_sensitive (dialog, FINISHED, 
571                                 current_page == (num_pages - 1));
572                 gtk_dialog_set_response_sensitive (dialog, CANCEL, 
573                                 current_page != (num_pages - 1));
574         }
575 }
576
577
578 gboolean run_wizard(MainWindow *mainwin, gboolean create_mailbox) {
579         WizardWindow *wizard = g_new0(WizardWindow, 1);
580         GtkWidget *page;
581         GtkWidget *widget;
582         gchar     *text;
583         GSList    *cur;
584         gboolean   result;
585         
586         wizard->mainwin = mainwin;
587         wizard->create_mailbox = create_mailbox;
588         
589         gtk_widget_hide(mainwin->window);
590         
591         wizard->window = gtk_dialog_new_with_buttons (_("New User"),
592                         NULL, 0, 
593                         GTK_STOCK_GO_BACK, GO_BACK,
594                         GTK_STOCK_GO_FORWARD, GO_FORWARD,
595                         GTK_STOCK_SAVE, FINISHED,
596                         GTK_STOCK_QUIT, CANCEL,
597                         NULL);
598
599         g_signal_connect(wizard->window, "response", 
600                           G_CALLBACK(wizard_response_cb), wizard);
601         gtk_widget_realize(wizard->window);
602         gtk_dialog_set_default_response(GTK_DIALOG(wizard->window), 
603                         GO_FORWARD);
604         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
605                         GO_BACK, FALSE);
606         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
607                         GO_FORWARD, TRUE);
608         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
609                         FINISHED, FALSE);
610         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
611                         CANCEL, TRUE);
612         
613         wizard->notebook = gtk_notebook_new();
614         gtk_notebook_set_show_tabs(GTK_NOTEBOOK(wizard->notebook), FALSE);
615         gtk_notebook_set_show_border(GTK_NOTEBOOK(wizard->notebook), FALSE);
616         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(wizard->window)->vbox), 
617                             wizard->notebook, TRUE, TRUE, 0);
618         
619         wizard->pages = NULL;
620         
621 /*welcome page: 0 */
622         page = create_page(wizard, _("Welcome to Sylpheed-Claws."));
623         
624         wizard->pages = g_slist_append(wizard->pages, page);
625         widget = stock_pixmap_widget(wizard->window, 
626                                 STOCK_PIXMAP_SYLPHEED_LOGO);
627
628         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
629         
630         text = g_strdup(_("Welcome to Sylpheed-Claws.\n\n"
631                           "It looks like it's the first time you use \n"
632                           "Sylpheed-Claws. So, we'll now define some basic\n"
633                           "information about yourself and your most common\n"
634                           "mail parameters; so that you can begin to use\n"
635                           "Sylpheed-Claws in less than five minutes."));
636         widget = gtk_label_new(text);
637         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
638         g_free(text);
639
640 /* user page: 1 */
641         widget = create_page (wizard, _("About You"));
642         gtk_box_pack_start (GTK_BOX(widget), user_page(wizard), FALSE, FALSE, 0);
643         wizard->pages = g_slist_append(wizard->pages, widget);
644
645 /*smtp page: 2 */
646         widget = create_page (wizard, _("Sending mail"));
647         gtk_box_pack_start (GTK_BOX(widget), smtp_page(wizard), FALSE, FALSE, 0);
648         wizard->pages = g_slist_append(wizard->pages, widget);
649
650 /* recv+auth page: 3 */
651         widget = create_page (wizard, _("Receiving mail"));
652         gtk_box_pack_start (GTK_BOX(widget), recv_page(wizard), FALSE, FALSE, 0);
653         wizard->pages = g_slist_append(wizard->pages, widget);
654
655 /* mailbox page: 4 */
656         if (create_mailbox) {
657                 widget = create_page (wizard, _("Saving mail on disk"));
658                 gtk_box_pack_start (GTK_BOX(widget), mailbox_page(wizard), FALSE, FALSE, 0);
659                 wizard->pages = g_slist_append(wizard->pages, widget);
660         }
661 /* ssl page: 5 */
662 #ifdef USE_OPENSSL
663         widget = create_page (wizard, _("Security"));
664         gtk_box_pack_start (GTK_BOX(widget), ssl_page(wizard), FALSE, FALSE, 0);
665         wizard->pages = g_slist_append(wizard->pages, widget);
666 #endif
667
668 /* done page: 6 */
669         page = create_page(wizard, _("Configuration finished."));
670         
671         wizard->pages = g_slist_append(wizard->pages, page);
672         widget = stock_pixmap_widget(wizard->window, 
673                                 STOCK_PIXMAP_SYLPHEED_LOGO);
674
675         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
676         
677         text = g_strdup(_("Sylpheed-Claws is now ready to run.\n\n"
678                           "Click Save to start."));
679         widget = gtk_label_new(text);
680         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
681         g_free(text);
682
683
684         for (cur = wizard->pages; cur && cur->data; cur = cur->next) {
685                 gtk_notebook_append_page (GTK_NOTEBOOK(wizard->notebook), 
686                                           GTK_WIDGET(cur->data), NULL);
687         }
688         
689         gtk_widget_show_all (wizard->window);
690         gtk_widget_hide(wizard->recv_imap_label);
691         gtk_widget_hide(wizard->recv_imap_subdir);
692
693         while (!wizard->finished)
694                 gtk_main_iteration();
695
696         result = wizard->result;
697         
698         GTK_EVENTS_FLUSH();
699
700         gtk_widget_show(mainwin->window);
701         g_free(wizard);
702
703         return result;
704 }