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