2005-10-08 [colin] 1.9.15cvs24
[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 gboolean 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         } else
122                 mailbox_ok = TRUE;
123
124         if (!mailbox_ok) {
125                 gtk_notebook_set_current_page (
126                         GTK_NOTEBOOK(wizard->notebook), 
127                         4);
128                 return FALSE;
129         }
130         
131         if (prefs_account->protocol != A_LOCAL)
132                 prefs_account->account_name = g_strdup_printf("%s@%s",
133                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_username)),
134                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
135         else
136                 prefs_account->account_name = g_strdup_printf("%s",
137                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
138
139         prefs_account->name = g_strdup(
140                                 gtk_entry_get_text(GTK_ENTRY(wizard->full_name)));
141         prefs_account->address = g_strdup(
142                                 gtk_entry_get_text(GTK_ENTRY(wizard->email)));
143         prefs_account->organization = g_strdup(
144                                 gtk_entry_get_text(GTK_ENTRY(wizard->organization)));
145         prefs_account->smtp_server = g_strdup(
146                                 gtk_entry_get_text(GTK_ENTRY(wizard->smtp_server)));
147
148         if (prefs_account->protocol != A_LOCAL)
149                 prefs_account->recv_server = g_strdup(
150                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
151         else
152                 prefs_account->local_mbox = g_strdup(
153                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
154
155         prefs_account->userid = g_strdup(
156                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_username)));
157         prefs_account->passwd = g_strdup(
158                                 gtk_entry_get_text(GTK_ENTRY(wizard->recv_password)));
159
160 #ifdef USE_OPENSSL                      
161         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_ssl)))
162                 prefs_account->ssl_smtp = SSL_TUNNEL;
163         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->recv_use_ssl))) {
164                 if (prefs_account->protocol == A_IMAP4)
165                         prefs_account->ssl_imap = SSL_TUNNEL;
166                 else
167                         prefs_account->ssl_pop = SSL_TUNNEL;
168         }
169 #endif
170         if (prefs_account->protocol == A_IMAP4) {
171                 gchar *directory = gtk_editable_get_chars(
172                         GTK_EDITABLE(wizard->recv_imap_subdir), 0, -1);
173                 if (directory && strlen(directory)) {
174                         prefs_account->imap_dir = g_strdup(directory);
175                 }
176                 g_free(directory);
177         }
178
179         account_list = g_list_append(account_list, prefs_account);
180         prefs_account_write_config_all(account_list);
181         prefs_account_free(prefs_account);
182         account_read_config_all();
183         
184         return TRUE;
185 }
186
187 static GtkWidget* create_page (WizardWindow *wizard, const char * title)
188 {
189         GtkWidget *w;
190         GtkWidget *vbox;
191         GtkWidget *hbox;
192         GtkWidget *image;
193         char *title_string;
194
195         vbox = gtk_vbox_new (FALSE, 6);
196         gtk_container_set_border_width  (GTK_CONTAINER(vbox), 10);
197
198         /* create the titlebar */
199         hbox = gtk_hbox_new (FALSE, 12);
200         image = stock_pixmap_widget(wizard->window, 
201                                 STOCK_PIXMAP_SYLPHEED_ICON);
202         gtk_box_pack_start (GTK_BOX(hbox), image, FALSE, FALSE, 0);
203         title_string = g_strconcat ("<span size=\"xx-large\" weight=\"ultrabold\">", title ? title : "", "</span>", NULL);
204         w = gtk_label_new (title_string);
205         gtk_label_set_use_markup (GTK_LABEL(w), TRUE);
206         g_free (title_string);
207         gtk_box_pack_start (GTK_BOX(hbox), w, FALSE, FALSE, 0);
208
209         /* pack the titlebar */
210         gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
211
212         /* pack the separator */
213         gtk_box_pack_start (GTK_BOX(vbox), gtk_hseparator_new(), FALSE, FALSE, 0);
214
215         /* pack space */
216         w = gtk_alignment_new (0, 0, 0, 0);
217         gtk_widget_set_size_request (w, 0, 6);
218         gtk_box_pack_start (GTK_BOX(vbox), w, FALSE, FALSE, 0);
219
220         return vbox;
221 }
222
223 #define GTK_TABLE_ADD_ROW_AT(table,text,entry,i) {                            \
224         GtkWidget *label = gtk_label_new(text);                               \
225         gtk_table_attach(GTK_TABLE(table), label,                             \
226                          0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            \
227         if (GTK_IS_MISC(label))                                               \
228                 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);              \
229         gtk_table_attach(GTK_TABLE(table), entry,                             \
230                          1,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            \
231 }
232
233 static gchar *get_default_email_addr(void)
234 {
235         gchar *domain_name = g_strdup(get_domain_name());
236         gchar *result;
237         if (strchr(domain_name, '.') != strrchr(domain_name, '.')
238         && strlen(strchr(domain_name, '.')) > 6) {
239                 gchar *tmp = g_strdup(strchr(domain_name, '.')+1);
240                 g_free(domain_name);
241                 domain_name = tmp;
242         }
243         result = g_strdup_printf("%s@%s",
244                                 g_get_user_name(),
245                                 domain_name);
246         g_free(domain_name);
247         return result;
248 }
249
250 static gchar *get_default_server(WizardWindow * wizard, const gchar *type)
251 {
252         gchar *domain_name = g_strdup(get_domain_name());
253         gchar *result;
254         
255         if (strchr(domain_name, '.') != strrchr(domain_name, '.')
256         && strlen(strchr(domain_name, '.')) > 6) {
257                 gchar *tmp = g_strdup(strchr(domain_name, '.')+1);
258                 g_free(domain_name);
259                 domain_name = tmp;
260         } else if (strchr(domain_name, '.') == NULL) {
261                 /* only hostname found, use email suffix */
262                 gchar *mail;
263                 mail = gtk_editable_get_chars(GTK_EDITABLE(wizard->email), 0, -1);
264
265                 if (strlen (mail) && strstr(mail, "@")) {
266                         g_free(domain_name);
267                         domain_name = g_strdup(strstr(mail, "@")+1);
268                 }
269                 g_free(mail);
270         }
271         result = g_strdup_printf("%s.%s",
272                                 type, domain_name);
273         g_free(domain_name);
274         return result;
275 }
276
277 static void wizard_email_changed(GtkWidget *widget, gpointer data)
278 {
279         WizardWindow *wizard = (WizardWindow *)data;
280         RecvProtocol protocol;
281         gchar *text;
282         protocol = GPOINTER_TO_INT
283                 (g_object_get_data(G_OBJECT(wizard->recv_type), MENU_VAL_ID));
284         
285         text = get_default_server(wizard, "smtp");
286         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_server), text);
287         g_free(text);
288
289         if (protocol == A_POP3) {
290                 text = get_default_server(wizard, "pop");
291                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
292                 g_free(text);
293         } else if (protocol == A_IMAP4) {
294                 text = get_default_server(wizard, "imap");
295                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
296                 g_free(text);
297         } else if (protocol == A_LOCAL) {
298                 gchar *mbox = g_strdup_printf("/var/mail/%s", g_get_user_name());
299                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), mbox);
300                 g_free(mbox);
301         }
302 }
303
304 static GtkWidget* user_page (WizardWindow * wizard)
305 {
306         GtkWidget *table = gtk_table_new(3,2, FALSE);
307         gchar *text;
308         gint i = 0;
309         
310         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
311         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
312
313         wizard->full_name = gtk_entry_new();
314         gtk_entry_set_text(GTK_ENTRY(wizard->full_name), g_get_real_name());
315         GTK_TABLE_ADD_ROW_AT(table, _("Your name:"), 
316                              wizard->full_name, i); i++;
317         
318         wizard->email = gtk_entry_new();
319         text = get_default_email_addr();
320         gtk_entry_set_text(GTK_ENTRY(wizard->email), text);
321         g_free(text);
322         GTK_TABLE_ADD_ROW_AT(table, _("Your email address:"), 
323                              wizard->email, i); i++;
324         
325         wizard->organization = gtk_entry_new();
326         GTK_TABLE_ADD_ROW_AT(table, _("Your organization:"), 
327                              wizard->organization, i); i++;
328         
329         g_signal_connect(G_OBJECT(wizard->email), "changed",
330                          G_CALLBACK(wizard_email_changed),
331                          wizard);
332         return table;
333 }
334
335 static GtkWidget* mailbox_page (WizardWindow * wizard)
336 {
337         GtkWidget *table = gtk_table_new(1,2, FALSE);
338         gint i = 0;
339         
340         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
341         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
342
343         wizard->mailbox_name = gtk_entry_new();
344         gtk_entry_set_text(GTK_ENTRY(wizard->mailbox_name), "Mail");
345         GTK_TABLE_ADD_ROW_AT(table, _("Mailbox name:"), 
346                              wizard->mailbox_name, i); i++;
347         
348         return table;
349 }
350
351 static GtkWidget* smtp_page (WizardWindow * wizard)
352 {
353         GtkWidget *table = gtk_table_new(1,2, FALSE);
354         gchar *text;
355         gint i = 0;
356         
357         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
358         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
359
360         wizard->smtp_server = gtk_entry_new();
361         text = get_default_server(wizard, "smtp");
362         gtk_entry_set_text(GTK_ENTRY(wizard->smtp_server), text);
363         g_free(text);
364         GTK_TABLE_ADD_ROW_AT(table, _("SMTP server address:"), 
365                              wizard->smtp_server, i); i++;
366         return table;
367 }
368
369 static void wizard_protocol_changed(GtkMenuItem *menuitem, gpointer data)
370 {
371         WizardWindow *wizard = (WizardWindow *)data;
372         RecvProtocol protocol;
373         gchar *text;
374         protocol = GPOINTER_TO_INT
375                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
376         
377         if (protocol == A_POP3) {
378                 text = get_default_server(wizard, "pop");
379                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
380                 gtk_widget_hide(wizard->recv_imap_label);
381                 gtk_widget_hide(wizard->recv_imap_subdir);
382                 gtk_widget_show(wizard->recv_username);
383                 gtk_widget_show(wizard->recv_password);
384                 gtk_widget_show(wizard->recv_username_label);
385                 gtk_widget_show(wizard->recv_password_label);
386                 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("Server address:"));
387                 g_free(text);
388         } else if (protocol == A_IMAP4) {
389                 text = get_default_server(wizard, "imap");
390                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
391                 gtk_widget_show(wizard->recv_imap_label);
392                 gtk_widget_show(wizard->recv_imap_subdir);
393                 gtk_widget_show(wizard->recv_username);
394                 gtk_widget_show(wizard->recv_password);
395                 gtk_widget_show(wizard->recv_username_label);
396                 gtk_widget_show(wizard->recv_password_label);
397                 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("Server address:"));
398                 g_free(text);
399         } else if (protocol == A_LOCAL) {
400                 gchar *mbox = g_strdup_printf("/var/mail/%s", g_get_user_name());
401                 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), mbox);
402                 g_free(mbox);
403                 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("Local mailbox:"));
404                 gtk_widget_hide(wizard->recv_imap_label);
405                 gtk_widget_hide(wizard->recv_imap_subdir);
406                 gtk_widget_hide(wizard->recv_username);
407                 gtk_widget_hide(wizard->recv_password);
408                 gtk_widget_hide(wizard->recv_username_label);
409                 gtk_widget_hide(wizard->recv_password_label);
410         }
411 }
412
413 static GtkWidget* recv_page (WizardWindow * wizard)
414 {
415         GtkWidget *table = gtk_table_new(5,2, FALSE);
416         GtkWidget *menu = gtk_menu_new();
417         GtkWidget *menuitem;
418         gchar *text;
419         gint i = 0;
420         
421         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
422         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
423
424         wizard->recv_type = gtk_option_menu_new();
425         
426         MENUITEM_ADD (menu, menuitem, _("POP3"), A_POP3);
427         g_signal_connect(G_OBJECT(menuitem), "activate",
428                          G_CALLBACK(wizard_protocol_changed),
429                          wizard);
430         MENUITEM_ADD (menu, menuitem, _("IMAP"), A_IMAP4);
431         g_signal_connect(G_OBJECT(menuitem), "activate",
432                          G_CALLBACK(wizard_protocol_changed),
433                          wizard);
434         MENUITEM_ADD (menu, menuitem, _("Local mbox file"), A_LOCAL);
435         g_signal_connect(G_OBJECT(menuitem), "activate",
436                          G_CALLBACK(wizard_protocol_changed),
437                          wizard);
438
439         gtk_option_menu_set_menu (GTK_OPTION_MENU (wizard->recv_type), menu);
440         GTK_TABLE_ADD_ROW_AT(table, _("Server type:"), 
441                              wizard->recv_type, i); i++;
442
443         wizard->recv_server = gtk_entry_new();
444         text = get_default_server(wizard, "pop");
445         gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
446         g_free(text);
447         
448         wizard->recv_label = gtk_label_new(_("Server address:"));
449         gtk_table_attach(GTK_TABLE(table), wizard->recv_label,                        
450                          0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            
451         if (GTK_IS_MISC(wizard->recv_label))                                                  
452                 gtk_misc_set_alignment(GTK_MISC(wizard->recv_label), 1, 0.5);         
453         gtk_table_attach(GTK_TABLE(table), wizard->recv_server,       
454                          1,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            
455         i++;
456         
457         wizard->recv_username = gtk_entry_new();
458         wizard->recv_username_label = gtk_label_new(_("Username:"));
459         gtk_table_attach(GTK_TABLE(table), wizard->recv_username_label,                               
460                          0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            
461         if (GTK_IS_MISC(wizard->recv_username_label))                                                 
462                 gtk_misc_set_alignment(GTK_MISC(wizard->recv_username_label), 1, 0.5);        
463         gtk_table_attach(GTK_TABLE(table), wizard->recv_username,             
464                          1,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            
465         i++;
466         
467         wizard->recv_password = gtk_entry_new();
468         wizard->recv_password_label = gtk_label_new(_("Password:"));
469         gtk_table_attach(GTK_TABLE(table), wizard->recv_password_label,                               
470                          0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            
471         if (GTK_IS_MISC(wizard->recv_password_label))                                                 
472                 gtk_misc_set_alignment(GTK_MISC(wizard->recv_password_label), 1, 0.5);        
473         gtk_table_attach(GTK_TABLE(table), wizard->recv_password,             
474                          1,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            
475         gtk_entry_set_visibility(GTK_ENTRY(wizard->recv_password), FALSE);
476         i++;
477         
478         wizard->recv_imap_subdir = gtk_entry_new();
479         wizard->recv_imap_label = gtk_label_new(_("IMAP server directory:"));
480         
481         gtk_table_attach(GTK_TABLE(table), wizard->recv_imap_label,                           
482                          0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            
483         if (GTK_IS_MISC(wizard->recv_imap_label))                                                     
484                 gtk_misc_set_alignment(GTK_MISC(wizard->recv_imap_label), 1, 0.5);            
485         gtk_table_attach(GTK_TABLE(table), wizard->recv_imap_subdir,          
486                          1,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);            
487
488         i++;
489         
490         return table;
491 }
492
493 #ifdef USE_OPENSSL
494 static GtkWidget* ssl_page (WizardWindow * wizard)
495 {
496         GtkWidget *table = gtk_table_new(2,2, FALSE);
497         gint i = 0;
498         
499         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
500         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
501
502         wizard->smtp_use_ssl = gtk_check_button_new_with_label(
503                                         _("Use SSL to connect to SMTP server"));
504         gtk_table_attach(GTK_TABLE(table), wizard->smtp_use_ssl,      
505                          0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0); i++;
506         
507         wizard->recv_use_ssl = gtk_check_button_new_with_label(
508                                         _("Use SSL to connect to receiving server"));
509         gtk_table_attach(GTK_TABLE(table), wizard->recv_use_ssl,      
510                          0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
511         
512         return table;
513 }
514 #endif
515
516 static void
517 wizard_response_cb (GtkDialog * dialog, int response, gpointer data)
518 {
519         WizardWindow * wizard = (WizardWindow *)data;
520         int current_page, num_pages;
521         GtkWidget *menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(wizard->recv_type));
522         GtkWidget *menuitem = gtk_menu_get_active(GTK_MENU(menu));
523         gint protocol = GPOINTER_TO_INT
524                         (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
525         gboolean skip_mailbox_page = FALSE;
526         
527         if (protocol == A_IMAP4) {
528                 skip_mailbox_page = TRUE;
529         }
530         
531         num_pages = g_slist_length(wizard->pages);
532
533         current_page = gtk_notebook_get_current_page (
534                                 GTK_NOTEBOOK(wizard->notebook));
535         if (response == CANCEL)
536         {
537                 wizard->finished = TRUE;
538                 wizard->result = FALSE;
539                 gtk_widget_destroy (GTK_WIDGET(dialog));
540         }
541         else if (response == FINISHED)
542         {
543                 if (!wizard_write_config(wizard)) {
544                         current_page = gtk_notebook_get_current_page (
545                                         GTK_NOTEBOOK(wizard->notebook));
546                         goto set_sens;
547                 }
548                 wizard->finished = TRUE;
549                 wizard->result = TRUE;
550                 gtk_widget_destroy (GTK_WIDGET(dialog));
551         }
552         else
553         {
554                 if (response == GO_BACK)
555                 {
556                         if (current_page > 0) {
557                                 current_page--;
558                                 if (current_page == 4 && skip_mailbox_page) {
559                                         /* mailbox */
560                                         current_page--;
561                                 }
562                                 gtk_notebook_set_current_page (
563                                         GTK_NOTEBOOK(wizard->notebook), 
564                                         current_page);
565                         }
566                 }
567                 else if (response == GO_FORWARD)
568                 {
569                         if (current_page < (num_pages-1)) {
570                                 current_page++;
571                                 if (current_page == 4 && skip_mailbox_page) {
572                                         /* mailbox */
573                                         current_page++;
574                                 }
575                                 gtk_notebook_set_current_page (
576                                         GTK_NOTEBOOK(wizard->notebook), 
577                                         current_page);
578                         }
579                 }
580 set_sens:
581                 gtk_dialog_set_response_sensitive (dialog, GO_BACK, 
582                                 current_page > 0);
583                 gtk_dialog_set_response_sensitive (dialog, GO_FORWARD, 
584                                 current_page < (num_pages - 1));
585                 gtk_dialog_set_response_sensitive (dialog, FINISHED, 
586                                 current_page == (num_pages - 1));
587                 gtk_dialog_set_response_sensitive (dialog, CANCEL, 
588                                 current_page != (num_pages - 1));
589         }
590 }
591
592
593 gboolean run_wizard(MainWindow *mainwin, gboolean create_mailbox) {
594         WizardWindow *wizard = g_new0(WizardWindow, 1);
595         GtkWidget *page;
596         GtkWidget *widget;
597         gchar     *text;
598         GSList    *cur;
599         gboolean   result;
600         
601         wizard->mainwin = mainwin;
602         wizard->create_mailbox = create_mailbox;
603         
604         gtk_widget_hide(mainwin->window);
605         
606         wizard->window = gtk_dialog_new_with_buttons (_("New User"),
607                         NULL, 0, 
608                         GTK_STOCK_GO_BACK, GO_BACK,
609                         GTK_STOCK_GO_FORWARD, GO_FORWARD,
610                         GTK_STOCK_SAVE, FINISHED,
611                         GTK_STOCK_QUIT, CANCEL,
612                         NULL);
613
614         g_signal_connect(wizard->window, "response", 
615                           G_CALLBACK(wizard_response_cb), wizard);
616         gtk_widget_realize(wizard->window);
617         gtk_dialog_set_default_response(GTK_DIALOG(wizard->window), 
618                         GO_FORWARD);
619         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
620                         GO_BACK, FALSE);
621         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
622                         GO_FORWARD, TRUE);
623         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
624                         FINISHED, FALSE);
625         gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window), 
626                         CANCEL, TRUE);
627         
628         wizard->notebook = gtk_notebook_new();
629         gtk_notebook_set_show_tabs(GTK_NOTEBOOK(wizard->notebook), FALSE);
630         gtk_notebook_set_show_border(GTK_NOTEBOOK(wizard->notebook), FALSE);
631         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(wizard->window)->vbox), 
632                             wizard->notebook, TRUE, TRUE, 0);
633         
634         wizard->pages = NULL;
635         
636 /*welcome page: 0 */
637         page = create_page(wizard, _("Welcome to Sylpheed-Claws."));
638         
639         wizard->pages = g_slist_append(wizard->pages, page);
640         widget = stock_pixmap_widget(wizard->window, 
641                                 STOCK_PIXMAP_SYLPHEED_LOGO);
642
643         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
644         
645         text = g_strdup(_("Welcome to Sylpheed-Claws.\n\n"
646                           "It looks like it's the first time you use \n"
647                           "Sylpheed-Claws. So, we'll now define some basic\n"
648                           "information about yourself and your most common\n"
649                           "mail parameters; so that you can begin to use\n"
650                           "Sylpheed-Claws in less than five minutes."));
651         widget = gtk_label_new(text);
652         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
653         g_free(text);
654
655 /* user page: 1 */
656         widget = create_page (wizard, _("About You"));
657         gtk_box_pack_start (GTK_BOX(widget), user_page(wizard), FALSE, FALSE, 0);
658         wizard->pages = g_slist_append(wizard->pages, widget);
659
660 /*smtp page: 2 */
661         widget = create_page (wizard, _("Sending mail"));
662         gtk_box_pack_start (GTK_BOX(widget), smtp_page(wizard), FALSE, FALSE, 0);
663         wizard->pages = g_slist_append(wizard->pages, widget);
664
665 /* recv+auth page: 3 */
666         widget = create_page (wizard, _("Receiving mail"));
667         gtk_box_pack_start (GTK_BOX(widget), recv_page(wizard), FALSE, FALSE, 0);
668         wizard->pages = g_slist_append(wizard->pages, widget);
669
670 /* mailbox page: 4 */
671         if (create_mailbox) {
672                 widget = create_page (wizard, _("Saving mail on disk"));
673                 gtk_box_pack_start (GTK_BOX(widget), mailbox_page(wizard), FALSE, FALSE, 0);
674                 wizard->pages = g_slist_append(wizard->pages, widget);
675         }
676 /* ssl page: 5 */
677 #ifdef USE_OPENSSL
678         widget = create_page (wizard, _("Security"));
679         gtk_box_pack_start (GTK_BOX(widget), ssl_page(wizard), FALSE, FALSE, 0);
680         wizard->pages = g_slist_append(wizard->pages, widget);
681 #endif
682
683 /* done page: 6 */
684         page = create_page(wizard, _("Configuration finished."));
685         
686         wizard->pages = g_slist_append(wizard->pages, page);
687         widget = stock_pixmap_widget(wizard->window, 
688                                 STOCK_PIXMAP_SYLPHEED_LOGO);
689
690         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
691         
692         text = g_strdup(_("Sylpheed-Claws is now ready to run.\n\n"
693                           "Click Save to start."));
694         widget = gtk_label_new(text);
695         gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
696         g_free(text);
697
698
699         for (cur = wizard->pages; cur && cur->data; cur = cur->next) {
700                 gtk_notebook_append_page (GTK_NOTEBOOK(wizard->notebook), 
701                                           GTK_WIDGET(cur->data), NULL);
702         }
703         
704         gtk_widget_show_all (wizard->window);
705         gtk_widget_hide(wizard->recv_imap_label);
706         gtk_widget_hide(wizard->recv_imap_subdir);
707
708         while (!wizard->finished)
709                 gtk_main_iteration();
710
711         result = wizard->result;
712         
713         GTK_EVENTS_FLUSH();
714
715         gtk_widget_show(mainwin->window);
716         g_free(wizard);
717
718         return result;
719 }