2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
4 * This file (C) 2004 Colin Leroy
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.
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.
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.
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>
53 #include "prefs_account.h"
54 #include "mainwindow.h"
55 #include "stock_pixmap.h"
58 #include "alertpanel.h"
62 #include "prefs_common.h"
72 int WELCOME_PAGE = -1;
76 int MAILBOX_PAGE = -1;
90 GtkWidget *organization;
92 GtkWidget *mailbox_name;
94 GtkWidget *smtp_server;
96 GtkWidget *smtp_username;
97 GtkWidget *smtp_password;
98 GtkWidget *smtp_username_label;
99 GtkWidget *smtp_password_label;
101 GtkWidget *recv_type;
102 GtkWidget *recv_label;
103 GtkWidget *recv_server;
104 GtkWidget *recv_username;
105 GtkWidget *recv_password;
106 GtkWidget *recv_username_label;
107 GtkWidget *recv_password_label;
108 GtkWidget *recv_imap_label;
109 GtkWidget *recv_imap_subdir;
112 GtkWidget *smtp_use_ssl;
113 GtkWidget *recv_use_ssl;
116 gboolean create_mailbox;
122 typedef struct _AccountTemplate {
131 RecvProtocol recvtype;
142 static AccountTemplate tmpl;
144 static PrefParam template_params[] = {
145 {"name", "$USERNAME",
146 &tmpl.name, P_STRING, NULL, NULL, NULL},
147 {"domain", "$DEFAULTDOMAIN",
148 &tmpl.domain, P_STRING, NULL, NULL, NULL},
149 {"email", "$NAME_MAIL@$DOMAIN",
150 &tmpl.email, P_STRING, NULL, NULL, NULL},
152 &tmpl.organization, P_STRING, NULL, NULL, NULL},
153 {"smtpserver", "smtp.$DOMAIN",
154 &tmpl.smtpserver, P_STRING, NULL, NULL, NULL},
155 {"smtpauth", "FALSE",
156 &tmpl.smtpauth, P_BOOL, NULL, NULL, NULL},
158 &tmpl.smtpuser, P_STRING, NULL, NULL, NULL},
160 &tmpl.smtppass, P_STRING, NULL, NULL, NULL},
162 &tmpl.recvtype, P_INT, NULL, NULL, NULL},
163 {"recvserver", "pop.$DOMAIN",
164 &tmpl.recvserver, P_STRING, NULL, NULL, NULL},
165 {"recvuser", "$LOGIN",
166 &tmpl.recvuser, P_STRING, NULL, NULL, NULL},
168 &tmpl.recvpass, P_STRING, NULL, NULL, NULL},
170 &tmpl.imapdir, P_STRING, NULL, NULL, NULL},
171 {"mboxfile", "/var/mail/$LOGIN",
172 &tmpl.mboxfile, P_STRING, NULL, NULL, NULL},
174 &tmpl.mailbox, P_STRING, NULL, NULL, NULL},
176 &tmpl.smtpssl, P_BOOL, NULL, NULL, NULL},
178 &tmpl.recvssl, P_BOOL, NULL, NULL, NULL},
179 {NULL, NULL, NULL, P_INT, NULL, NULL, NULL}
183 static gchar *accountrc_tmpl =
184 "[AccountTemplate]\n"
185 "#you can use $DEFAULTDOMAIN here\n"
186 "#domain must be defined before the variables that use it\n"
187 "#by default, domain is extracted from the hostname\n"
190 "#you can use $USERNAME for name (this is the default)\n"
193 "#you can use $LOGIN, $NAME_MAIL and $DOMAIN here \n"
194 "#$NAME_MAIL is the name without uppercase and with dots instead\n"
196 "#the default is $NAME_MAIL@$DOMAIN\n"
199 "#you can use $DOMAIN here\n"
200 "#the default organization is empty\n"
203 "#you can use $DOMAIN here \n"
204 "#the default is stmp.$DOMAIN\n"
207 "#Whether to use smtp authentication\n"
208 "#the default is 0 (no)\n"
212 "#you can use $LOGIN, $NAME_MAIL, $DOMAIN or $EMAIL here\n"
213 "#the default is empty (same as reception username)\n"
217 "#the default is empty (same as reception password)\n"
220 "#recvtype can be:\n"
223 "#5 for a local mbox file\n"
226 "#you can use $DOMAIN here \n"
227 "#the default is {pop,imap}.$DOMAIN\n"
230 "#you can use $LOGIN, $NAME_MAIL, $DOMAIN or $EMAIL here\n"
231 "#default is $LOGIN\n"
234 "#default is empty\n"
237 "#imap dir if imap (relative to the home on the server\n"
238 "#default is empty\n"
241 "#mbox file if local\n"
242 "#you can use $LOGIN here\n"
243 "#default is /var/mail/$LOGIN\n"
246 "#mailbox name if pop3 or local\n"
247 "#relative path from the user's home\n"
248 "#default is \"Mail\"\n"
251 "#whether to use ssl on STMP connections\n"
255 "#whether to use ssl on pop or imap connections\n"
259 static gchar *wizard_get_default_domain_name(void)
261 static gchar *domain_name = NULL;
263 if (domain_name == NULL) {
264 domain_name = g_strdup(get_domain_name());
265 if (strchr(domain_name, '.') != strrchr(domain_name, '.')
266 && strlen(strchr(domain_name, '.')) > 6) {
267 gchar *tmp = g_strdup(strchr(domain_name, '.')+1);
275 static gchar *get_name_for_mail(void)
277 gchar *name = g_strdup(tmpl.name);
281 while(strstr(name, " "))
282 *strstr(name, " ")='.';
287 #define PARSE_DEFAULT(str) { \
288 gchar *tmp = NULL, *new = NULL; \
290 tmp = g_strdup(str); \
291 if (strstr(str, "$USERNAME")) { \
292 tmp = g_strdup(str); \
293 *strstr(tmp, "$USERNAME") = '\0'; \
294 new = g_strconcat(tmp, g_get_real_name(), \
295 strstr(str, "$USERNAME")+strlen("$USERNAME"), \
302 if (strstr(str, "$LOGIN")) { \
303 tmp = g_strdup(str); \
304 *strstr(tmp, "$LOGIN") = '\0'; \
305 new = g_strconcat(tmp, g_get_user_name(), \
306 strstr(str, "$LOGIN")+strlen("$LOGIN"), \
313 if (strstr(str, "$EMAIL")) { \
314 tmp = g_strdup(str); \
315 *strstr(tmp, "$EMAIL") = '\0'; \
316 new = g_strconcat(tmp, tmpl.email, \
317 strstr(str, "$EMAIL")+strlen("$EMAIL"), \
324 if (strstr(str, "$NAME_MAIL")) { \
325 tmp = g_strdup(str); \
326 *strstr(tmp, "$NAME_MAIL") = '\0'; \
327 new = g_strconcat(tmp, get_name_for_mail(), \
328 strstr(str, "$NAME_MAIL")+strlen("$NAME_MAIL"), \
335 if (strstr(str, "$DEFAULTDOMAIN")) { \
336 tmp = g_strdup(str); \
337 *strstr(tmp, "$DEFAULTDOMAIN") = '\0'; \
338 new = g_strconcat(tmp, wizard_get_default_domain_name(), \
339 strstr(str, "$DEFAULTDOMAIN")+strlen("$DEFAULTDOMAIN"), \
346 if (strstr(str, "$DOMAIN")) { \
347 tmp = g_strdup(str); \
348 *strstr(tmp, "$DOMAIN") = '\0'; \
349 new = g_strconcat(tmp, tmpl.domain, \
350 strstr(str, "$DOMAIN")+strlen("$DOMAIN"), \
359 static void wizard_read_defaults(void)
363 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "accountrc.tmpl", NULL);
364 if (!is_file_exist(rcpath)) {
365 str_write_to_file(accountrc_tmpl, rcpath);
368 prefs_read_config(template_params, "AccountTemplate", rcpath, NULL);
370 PARSE_DEFAULT(tmpl.domain);
371 PARSE_DEFAULT(tmpl.name);
372 PARSE_DEFAULT(tmpl.email);
373 PARSE_DEFAULT(tmpl.organization);
374 PARSE_DEFAULT(tmpl.smtpserver);
375 PARSE_DEFAULT(tmpl.smtpuser);
376 PARSE_DEFAULT(tmpl.smtppass);
377 PARSE_DEFAULT(tmpl.recvserver);
378 PARSE_DEFAULT(tmpl.recvuser);
379 PARSE_DEFAULT(tmpl.recvpass);
380 PARSE_DEFAULT(tmpl.imapdir);
381 PARSE_DEFAULT(tmpl.mboxfile);
382 PARSE_DEFAULT(tmpl.mailbox);
385 "%s, %s, %s, %s, %s, %d, %s, %s, %s, %s, %s, %s, %d, %d\n",
386 tmpl.name,tmpl.domain,tmpl.email,tmpl.organization,tmpl.smtpserver,
387 tmpl.recvtype,tmpl.recvserver,tmpl.recvuser,tmpl.recvpass,
388 tmpl.imapdir,tmpl.mboxfile,tmpl.mailbox,tmpl.smtpssl,tmpl.recvssl);
394 static void initialize_fonts(WizardWindow *wizard)
396 GtkWidget *widget = wizard->email;
397 gint size = pango_font_description_get_size(
398 widget->style->font_desc)
402 tmp = g_strdup(prefs_common.textfont);
403 if (strrchr(tmp, ' ')) {
404 *(strrchr(tmp, ' ')) = '\0';
405 new = g_strdup_printf("%s %d", tmp, size);
406 g_free(prefs_common.textfont);
407 prefs_common.textfont = new;
411 tmp = g_strdup(prefs_common.smallfont);
412 if (strrchr(tmp, ' ')) {
413 *(strrchr(tmp, ' ')) = '\0';
414 new = g_strdup_printf("%s %d", tmp, size);
415 g_free(prefs_common.smallfont);
416 prefs_common.smallfont = new;
420 tmp = g_strdup(prefs_common.normalfont);
421 if (strrchr(tmp, ' ')) {
422 *(strrchr(tmp, ' ')) = '\0';
423 new = g_strdup_printf("%s %d", tmp, size);
424 g_free(prefs_common.normalfont);
425 prefs_common.normalfont = new;
430 #define XFACE "+}Axz@~a,-Yx?0Ysa|q}CLRH=89Y]\"')DSX^<6p\"d)'81yx5%G#u^o*7JG&[aPU0h1Ux.vb2yIjH83{5`/bVo|~nn/i83vE^E)qk-4W)_E.4Y=D*qvf/,Ci_=P<iY<M6"
432 static void write_welcome_email(WizardWindow *wizard)
439 const gchar *mailbox = gtk_entry_get_text(GTK_ENTRY(wizard->mailbox_name));
440 Folder *folder = folder_find_from_path(mailbox);
441 FolderItem *inbox = folder ? folder->inbox:NULL;
442 gchar *file = get_tmp_file();
444 get_rfc822_date(buf_date, sizeof(buf_date));
446 subj = g_strdup_printf(_("Welcome to Sylpheed-Claws "));
448 head = g_strdup_printf(
449 "From: %s <sylpheed-claws-users@lists.sf.net>\n"
454 "Content-Type: text/plain; charset=UTF-8\n",
455 _("Sylpheed-Claws Team"),
456 gtk_entry_get_text(GTK_ENTRY(wizard->full_name)),
457 gtk_entry_get_text(GTK_ENTRY(wizard->email)),
458 buf_date, subj, XFACE);
459 body = g_strdup_printf(
461 "Welcome to Sylpheed-Claws\n"
462 "-------------------------\n"
464 "Now that you have set up your account you can fetch your\n"
465 "mail by clicking the 'Get Mail' button at the left of the\n"
468 "You can change your Account Preferences by using the menu\n"
469 "entry '/Configuration/Preferences for current account'\n"
470 "and change the general Preferences by using\n"
471 "'/Configuration/Preferences'.\n"
473 "You can find further information in the Sylpheed-Claws manual,\n"
474 "which can be accessed by using the menu entry '/Help/Manual'\n"
475 "or online at the URL given below.\n"
483 "Mailing Lists: <%s>\n"
487 "Sylpheed-Claws is free software, released under the terms\n"
488 "of the GNU General Public License, version 2 or later, as\n"
489 "published by the Free Software Foundation, 51 Franklin Street,\n"
490 "Fifth Floor, Boston, MA 02110-1301, USA. The license can be\n"
495 "If you wish to donate to the Sylpheed-Claws project you can do\n"
497 HOMEPAGE_URI, MANUAL_URI, FAQ_URI, THEMES_URI, MAILING_LIST_URI,
498 GPL_URI, DONATE_URI);
500 msg = g_strconcat(head, body, NULL);
502 if (inbox && inbox->total_msgs == 0
503 && str_write_to_file(msg, file) >= 0) {
504 MsgFlags flags = { MSG_UNREAD|MSG_NEW, 0};
505 folder_item_add_msg(inbox, file, &flags, FALSE);
515 static gboolean wizard_write_config(WizardWindow *wizard)
517 static gboolean mailbox_ok = FALSE;
518 PrefsAccount *prefs_account = prefs_account_new();
519 GList *account_list = NULL;
520 GtkWidget *menu, *menuitem;
522 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(wizard->recv_type));
523 menuitem = gtk_menu_get_active(GTK_MENU(menu));
524 prefs_account->protocol = GPOINTER_TO_INT
525 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
528 if (wizard->create_mailbox && prefs_account->protocol != A_IMAP4 &&
529 !strlen(gtk_entry_get_text(GTK_ENTRY(wizard->mailbox_name)))) {
530 alertpanel_error(_("Please enter the mailbox name."));
531 g_free(prefs_account);
532 gtk_notebook_set_current_page (
533 GTK_NOTEBOOK(wizard->notebook),
539 if (wizard->create_mailbox && prefs_account->protocol != A_IMAP4) {
540 mailbox_ok = setup_write_mailbox_path(wizard->mainwin,
542 GTK_ENTRY(wizard->mailbox_name)));
548 /* alertpanel done by setup_write_mailbox_path */
549 g_free(prefs_account);
550 gtk_notebook_set_current_page (
551 GTK_NOTEBOOK(wizard->notebook),
556 if (!strlen(gtk_entry_get_text(GTK_ENTRY(wizard->full_name)))
557 || !strlen(gtk_entry_get_text(GTK_ENTRY(wizard->email)))) {
558 alertpanel_error(_("Please enter your name and email address."));
559 g_free(prefs_account);
560 gtk_notebook_set_current_page (
561 GTK_NOTEBOOK(wizard->notebook),
566 if (prefs_account->protocol != A_LOCAL) {
567 if (!strlen(gtk_entry_get_text(GTK_ENTRY(wizard->recv_username)))
568 || !strlen(gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)))) {
569 alertpanel_error(_("Please enter your receiving server "
571 g_free(prefs_account);
572 gtk_notebook_set_current_page (
573 GTK_NOTEBOOK(wizard->notebook),
578 if (!strlen(gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)))) {
579 alertpanel_error(_("Please enter your username."));
580 g_free(prefs_account);
581 gtk_notebook_set_current_page (
582 GTK_NOTEBOOK(wizard->notebook),
588 if (!strlen(gtk_entry_get_text(GTK_ENTRY(wizard->smtp_server)))) {
589 alertpanel_error(_("Please enter your SMTP server."));
590 g_free(prefs_account);
591 gtk_notebook_set_current_page (
592 GTK_NOTEBOOK(wizard->notebook),
597 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->smtp_auth))) {
598 if (prefs_account->protocol == A_LOCAL
599 && !strlen(gtk_entry_get_text(GTK_ENTRY(wizard->smtp_username)))) {
600 alertpanel_error(_("Please enter your SMTP username."));
601 g_free(prefs_account);
602 gtk_notebook_set_current_page (
603 GTK_NOTEBOOK(wizard->notebook),
606 } /* if it's not local we'll use the reception server */
609 if (prefs_account->protocol != A_LOCAL)
610 prefs_account->account_name = g_strdup_printf("%s@%s",
611 gtk_entry_get_text(GTK_ENTRY(wizard->recv_username)),
612 gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
614 prefs_account->account_name = g_strdup_printf("%s",
615 gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
617 prefs_account->name = g_strdup(
618 gtk_entry_get_text(GTK_ENTRY(wizard->full_name)));
619 prefs_account->address = g_strdup(
620 gtk_entry_get_text(GTK_ENTRY(wizard->email)));
621 prefs_account->organization = g_strdup(
622 gtk_entry_get_text(GTK_ENTRY(wizard->organization)));
623 prefs_account->smtp_server = g_strdup(
624 gtk_entry_get_text(GTK_ENTRY(wizard->smtp_server)));
626 if (prefs_account->protocol != A_LOCAL)
627 prefs_account->recv_server = g_strdup(
628 gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
630 prefs_account->local_mbox = g_strdup(
631 gtk_entry_get_text(GTK_ENTRY(wizard->recv_server)));
633 prefs_account->userid = g_strdup(
634 gtk_entry_get_text(GTK_ENTRY(wizard->recv_username)));
635 prefs_account->passwd = g_strdup(
636 gtk_entry_get_text(GTK_ENTRY(wizard->recv_password)));
638 prefs_account->smtp_userid = g_strdup(
639 gtk_entry_get_text(GTK_ENTRY(wizard->smtp_username)));
640 prefs_account->smtp_passwd = g_strdup(
641 gtk_entry_get_text(GTK_ENTRY(wizard->smtp_password)));
642 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->smtp_auth))) {
643 prefs_account->use_smtp_auth = TRUE;
647 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_ssl)))
648 prefs_account->ssl_smtp = SSL_TUNNEL;
649 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wizard->recv_use_ssl))) {
650 if (prefs_account->protocol == A_IMAP4)
651 prefs_account->ssl_imap = SSL_TUNNEL;
653 prefs_account->ssl_pop = SSL_TUNNEL;
656 if (prefs_account->protocol == A_IMAP4) {
657 gchar *directory = gtk_editable_get_chars(
658 GTK_EDITABLE(wizard->recv_imap_subdir), 0, -1);
659 if (directory && strlen(directory)) {
660 prefs_account->imap_dir = g_strdup(directory);
665 account_list = g_list_append(account_list, prefs_account);
666 prefs_account_write_config_all(account_list);
667 prefs_account_free(prefs_account);
668 account_read_config_all();
670 initialize_fonts(wizard);
671 if (wizard->create_mailbox && prefs_account->protocol != A_IMAP4)
672 write_welcome_email(wizard);
677 static GtkWidget* create_page (WizardWindow *wizard, const char * title)
685 vbox = gtk_vbox_new (FALSE, 6);
686 gtk_container_set_border_width (GTK_CONTAINER(vbox), 10);
688 /* create the titlebar */
689 hbox = gtk_hbox_new (FALSE, 12);
690 image = stock_pixmap_widget(wizard->window,
691 STOCK_PIXMAP_SYLPHEED_ICON);
692 gtk_box_pack_start (GTK_BOX(hbox), image, FALSE, FALSE, 0);
693 title_string = g_strconcat ("<span size=\"xx-large\" weight=\"ultrabold\">", title ? title : "", "</span>", NULL);
694 w = gtk_label_new (title_string);
695 gtk_label_set_use_markup (GTK_LABEL(w), TRUE);
696 g_free (title_string);
697 gtk_box_pack_start (GTK_BOX(hbox), w, FALSE, FALSE, 0);
699 /* pack the titlebar */
700 gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
702 /* pack the separator */
703 gtk_box_pack_start (GTK_BOX(vbox), gtk_hseparator_new(), FALSE, FALSE, 0);
706 w = gtk_alignment_new (0, 0, 0, 0);
707 gtk_widget_set_size_request (w, 0, 6);
708 gtk_box_pack_start (GTK_BOX(vbox), w, FALSE, FALSE, 0);
713 #define GTK_TABLE_ADD_ROW_AT(table,text,entry,i) { \
714 GtkWidget *label = gtk_label_new(text); \
715 gtk_table_attach(GTK_TABLE(table), label, \
716 0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0); \
717 gtk_label_set_use_markup(GTK_LABEL(label), TRUE); \
718 if (GTK_IS_MISC(label)) \
719 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); \
720 gtk_table_attach(GTK_TABLE(table), entry, \
721 1,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0); \
724 static gchar *get_default_server(WizardWindow * wizard, const gchar *type)
726 if (!strcmp(type, "smtp")) {
727 if (!tmpl.smtpserver || !strlen(tmpl.smtpserver))
728 return g_strconcat(type, ".", tmpl.domain, NULL);
730 return g_strdup(tmpl.smtpserver);
732 if (!tmpl.recvserver || !strlen(tmpl.recvserver))
733 return g_strconcat(type, ".", tmpl.domain, NULL);
735 return g_strdup(tmpl.recvserver);
739 static gchar *get_default_account(WizardWindow * wizard)
741 gchar *result = NULL;
743 if (!tmpl.recvuser || !strlen(tmpl.recvuser)) {
744 result = gtk_editable_get_chars(
745 GTK_EDITABLE(wizard->email), 0, -1);
747 if (strstr(result, "@")) {
748 *(strstr(result,"@")) = '\0';
751 result = g_strdup(tmpl.recvuser);
756 static gchar *get_default_smtp_account(WizardWindow * wizard)
758 gchar *result = NULL;
760 if (!tmpl.smtpuser || !strlen(tmpl.smtpuser)) {
763 result = g_strdup(tmpl.smtpuser);
768 static void wizard_email_changed(GtkWidget *widget, gpointer data)
770 WizardWindow *wizard = (WizardWindow *)data;
771 RecvProtocol protocol;
773 protocol = GPOINTER_TO_INT
774 (g_object_get_data(G_OBJECT(wizard->recv_type), MENU_VAL_ID));
776 text = get_default_server(wizard, "smtp");
777 gtk_entry_set_text(GTK_ENTRY(wizard->smtp_server), text);
780 text = get_default_account(wizard);
781 gtk_entry_set_text(GTK_ENTRY(wizard->recv_username), text);
784 if (protocol == A_POP3) {
785 text = get_default_server(wizard, "pop");
786 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
788 } else if (protocol == A_IMAP4) {
789 text = get_default_server(wizard, "imap");
790 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
792 } else if (protocol == A_LOCAL) {
793 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), tmpl.mboxfile?tmpl.mboxfile:"");
798 static GtkWidget* user_page (WizardWindow * wizard)
800 GtkWidget *table = gtk_table_new(3,2, FALSE);
803 gtk_table_set_row_spacings(GTK_TABLE(table), 4);
804 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
806 wizard->full_name = gtk_entry_new();
807 gtk_entry_set_text(GTK_ENTRY(wizard->full_name), tmpl.name?tmpl.name:"");
808 GTK_TABLE_ADD_ROW_AT(table, _("<span weight=\"bold\">Your name:</span>"),
809 wizard->full_name, i); i++;
811 wizard->email = gtk_entry_new();
812 gtk_entry_set_text(GTK_ENTRY(wizard->email), tmpl.email?tmpl.email:"");
813 GTK_TABLE_ADD_ROW_AT(table, _("<span weight=\"bold\">Your email address:</span>"),
814 wizard->email, i); i++;
816 wizard->organization = gtk_entry_new();
817 GTK_TABLE_ADD_ROW_AT(table, _("Your organization:"),
818 wizard->organization, i); i++;
819 gtk_entry_set_text(GTK_ENTRY(wizard->organization), tmpl.organization?tmpl.organization:"");
821 g_signal_connect(G_OBJECT(wizard->email), "changed",
822 G_CALLBACK(wizard_email_changed),
827 static GtkWidget* mailbox_page (WizardWindow * wizard)
829 GtkWidget *table = gtk_table_new(1,2, FALSE);
832 gtk_table_set_row_spacings(GTK_TABLE(table), 4);
833 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
835 wizard->mailbox_name = gtk_entry_new();
836 gtk_entry_set_text(GTK_ENTRY(wizard->mailbox_name), tmpl.mailbox?tmpl.mailbox:"");
837 GTK_TABLE_ADD_ROW_AT(table, _("<span weight=\"bold\">Mailbox name:</span>"),
838 wizard->mailbox_name, i); i++;
843 static void smtp_auth_changed (GtkWidget *btn, gpointer data)
845 WizardWindow *wizard = (WizardWindow *)data;
846 gboolean do_auth = gtk_toggle_button_get_active(
847 GTK_TOGGLE_BUTTON(wizard->smtp_auth));
848 gtk_widget_set_sensitive(wizard->smtp_username, do_auth);
849 gtk_widget_set_sensitive(wizard->smtp_username_label, do_auth);
850 gtk_widget_set_sensitive(wizard->smtp_password, do_auth);
851 gtk_widget_set_sensitive(wizard->smtp_password_label, do_auth);
854 static GtkWidget* smtp_page (WizardWindow * wizard)
856 GtkWidget *table = gtk_table_new(1,4, FALSE);
860 gtk_table_set_row_spacings(GTK_TABLE(table), 4);
861 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
863 wizard->smtp_server = gtk_entry_new();
864 text = get_default_server(wizard, "smtp");
865 gtk_entry_set_text(GTK_ENTRY(wizard->smtp_server), text);
867 GTK_TABLE_ADD_ROW_AT(table, _("<span weight=\"bold\">SMTP server address:</span>"),
868 wizard->smtp_server, i); i++;
869 wizard->smtp_auth = gtk_check_button_new_with_label(
870 _("Use authentication"));
871 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->smtp_auth),
873 g_signal_connect(G_OBJECT(wizard->smtp_auth), "toggled",
874 G_CALLBACK(smtp_auth_changed),
876 gtk_table_attach(GTK_TABLE(table), wizard->smtp_auth,
877 0,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0); i++;
879 text = get_default_smtp_account(wizard);
881 wizard->smtp_username = gtk_entry_new();
882 gtk_entry_set_text(GTK_ENTRY(wizard->smtp_username), text);
884 wizard->smtp_username_label = gtk_label_new(_("SMTP username:\n"
885 "<span size=\"small\">(empty to use the same as reception)</span>"));
886 gtk_label_set_use_markup(GTK_LABEL(wizard->smtp_username_label), TRUE);
887 gtk_table_attach(GTK_TABLE(table), wizard->smtp_username_label,
888 0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
889 if (GTK_IS_MISC(wizard->smtp_username_label))
890 gtk_misc_set_alignment(GTK_MISC(wizard->smtp_username_label), 1, 0.5);
891 gtk_table_attach(GTK_TABLE(table), wizard->smtp_username,
892 1,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
894 wizard->smtp_password = gtk_entry_new();
895 gtk_entry_set_text(GTK_ENTRY(wizard->smtp_password), tmpl.smtppass?tmpl.smtppass:"");
896 gtk_entry_set_visibility(GTK_ENTRY(wizard->smtp_password), FALSE);
897 wizard->smtp_password_label = gtk_label_new(_("SMTP password:\n"
898 "<span size=\"small\">(empty to use the same as reception)</span>"));
899 gtk_label_set_use_markup(GTK_LABEL(wizard->smtp_password_label), TRUE);
900 gtk_table_attach(GTK_TABLE(table), wizard->smtp_password_label,
901 0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
902 if (GTK_IS_MISC(wizard->smtp_password_label))
903 gtk_misc_set_alignment(GTK_MISC(wizard->smtp_password_label), 1, 0.5);
904 gtk_table_attach(GTK_TABLE(table), wizard->smtp_password,
905 1,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
907 smtp_auth_changed(NULL, wizard);
911 static void wizard_protocol_change(WizardWindow *wizard, RecvProtocol protocol)
915 if (protocol == A_POP3) {
916 text = get_default_server(wizard, "pop");
917 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
918 gtk_widget_hide(wizard->recv_imap_label);
919 gtk_widget_hide(wizard->recv_imap_subdir);
920 gtk_widget_show(wizard->recv_username);
921 gtk_widget_show(wizard->recv_password);
922 gtk_widget_show(wizard->recv_username_label);
923 gtk_widget_show(wizard->recv_password_label);
924 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("<span weight=\"bold\">Server address:</span>"));
925 gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
927 } else if (protocol == A_IMAP4) {
928 text = get_default_server(wizard, "imap");
929 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
930 gtk_widget_show(wizard->recv_imap_label);
931 gtk_widget_show(wizard->recv_imap_subdir);
932 gtk_widget_show(wizard->recv_username);
933 gtk_widget_show(wizard->recv_password);
934 gtk_widget_show(wizard->recv_username_label);
935 gtk_widget_show(wizard->recv_password_label);
936 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("<span weight=\"bold\">Server address:</span>"));
937 gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
939 } else if (protocol == A_LOCAL) {
940 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), tmpl.mboxfile?tmpl.mboxfile:"");
941 gtk_label_set_text(GTK_LABEL(wizard->recv_label), _("<span weight=\"bold\">Local mailbox:</span>"));
942 gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
943 gtk_widget_hide(wizard->recv_imap_label);
944 gtk_widget_hide(wizard->recv_imap_subdir);
945 gtk_widget_hide(wizard->recv_username);
946 gtk_widget_hide(wizard->recv_password);
947 gtk_widget_hide(wizard->recv_username_label);
948 gtk_widget_hide(wizard->recv_password_label);
952 static void wizard_protocol_changed(GtkMenuItem *menuitem, gpointer data)
954 WizardWindow *wizard = (WizardWindow *)data;
955 RecvProtocol protocol;
956 protocol = GPOINTER_TO_INT
957 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
959 wizard_protocol_change(wizard, protocol);
962 static GtkWidget* recv_page (WizardWindow * wizard)
964 GtkWidget *table = gtk_table_new(5,2, FALSE);
965 GtkWidget *menu = gtk_menu_new();
971 gtk_table_set_row_spacings(GTK_TABLE(table), 4);
972 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
974 wizard->recv_type = gtk_option_menu_new();
976 MENUITEM_ADD (menu, menuitem, _("POP3"), A_POP3);
977 g_signal_connect(G_OBJECT(menuitem), "activate",
978 G_CALLBACK(wizard_protocol_changed),
981 MENUITEM_ADD (menu, menuitem, _("IMAP"), A_IMAP4);
982 g_signal_connect(G_OBJECT(menuitem), "activate",
983 G_CALLBACK(wizard_protocol_changed),
986 MENUITEM_ADD (menu, menuitem, _("Local mbox file"), A_LOCAL);
987 g_signal_connect(G_OBJECT(menuitem), "activate",
988 G_CALLBACK(wizard_protocol_changed),
991 gtk_option_menu_set_menu (GTK_OPTION_MENU (wizard->recv_type), menu);
992 switch(tmpl.recvtype) {
1011 gtk_option_menu_set_history(GTK_OPTION_MENU (wizard->recv_type), index);
1012 GTK_TABLE_ADD_ROW_AT(table, _("<span weight=\"bold\">Server type:</span>"),
1013 wizard->recv_type, i); i++;
1015 wizard->recv_server = gtk_entry_new();
1016 text = get_default_server(wizard, "pop");
1017 gtk_entry_set_text(GTK_ENTRY(wizard->recv_server), text);
1020 wizard->recv_label = gtk_label_new(_("<span weight=\"bold\">Server address:</span>"));
1021 gtk_label_set_use_markup(GTK_LABEL(wizard->recv_label), TRUE);
1022 gtk_table_attach(GTK_TABLE(table), wizard->recv_label,
1023 0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
1024 if (GTK_IS_MISC(wizard->recv_label))
1025 gtk_misc_set_alignment(GTK_MISC(wizard->recv_label), 1, 0.5);
1026 gtk_table_attach(GTK_TABLE(table), wizard->recv_server,
1027 1,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
1030 wizard->recv_username = gtk_entry_new();
1031 wizard->recv_username_label = gtk_label_new(_("<span weight=\"bold\">Username:</span>"));
1032 gtk_label_set_use_markup(GTK_LABEL(wizard->recv_username_label), TRUE);
1033 gtk_table_attach(GTK_TABLE(table), wizard->recv_username_label,
1034 0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
1035 if (GTK_IS_MISC(wizard->recv_username_label))
1036 gtk_misc_set_alignment(GTK_MISC(wizard->recv_username_label), 1, 0.5);
1037 gtk_table_attach(GTK_TABLE(table), wizard->recv_username,
1038 1,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
1041 text = get_default_account(wizard);
1042 gtk_entry_set_text(GTK_ENTRY(wizard->recv_username), text);
1045 wizard->recv_password = gtk_entry_new();
1046 gtk_entry_set_text(GTK_ENTRY(wizard->recv_password), tmpl.recvpass?tmpl.recvpass:"");
1047 wizard->recv_password_label = gtk_label_new(_("Password:"));
1048 gtk_table_attach(GTK_TABLE(table), wizard->recv_password_label,
1049 0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
1050 if (GTK_IS_MISC(wizard->recv_password_label))
1051 gtk_misc_set_alignment(GTK_MISC(wizard->recv_password_label), 1, 0.5);
1052 gtk_table_attach(GTK_TABLE(table), wizard->recv_password,
1053 1,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
1054 gtk_entry_set_visibility(GTK_ENTRY(wizard->recv_password), FALSE);
1057 wizard->recv_imap_subdir = gtk_entry_new();
1058 gtk_entry_set_text(GTK_ENTRY(wizard->recv_imap_subdir), tmpl.imapdir?tmpl.imapdir:"");
1059 wizard->recv_imap_label = gtk_label_new(_("IMAP server directory:"));
1061 gtk_table_attach(GTK_TABLE(table), wizard->recv_imap_label,
1062 0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
1063 if (GTK_IS_MISC(wizard->recv_imap_label))
1064 gtk_misc_set_alignment(GTK_MISC(wizard->recv_imap_label), 1, 0.5);
1065 gtk_table_attach(GTK_TABLE(table), wizard->recv_imap_subdir,
1066 1,2,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
1074 static GtkWidget* ssl_page (WizardWindow * wizard)
1076 GtkWidget *table = gtk_table_new(2,2, FALSE);
1079 gtk_table_set_row_spacings(GTK_TABLE(table), 4);
1080 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
1082 wizard->smtp_use_ssl = gtk_check_button_new_with_label(
1083 _("Use SSL to connect to SMTP server"));
1084 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->smtp_use_ssl),
1086 gtk_table_attach(GTK_TABLE(table), wizard->smtp_use_ssl,
1087 0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0); i++;
1089 wizard->recv_use_ssl = gtk_check_button_new_with_label(
1090 _("Use SSL to connect to receiving server"));
1091 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wizard->recv_use_ssl),
1093 gtk_table_attach(GTK_TABLE(table), wizard->recv_use_ssl,
1094 0,1,i,i+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
1101 wizard_response_cb (GtkDialog * dialog, int response, gpointer data)
1103 WizardWindow * wizard = (WizardWindow *)data;
1104 int current_page, num_pages;
1105 GtkWidget *menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(wizard->recv_type));
1106 GtkWidget *menuitem = gtk_menu_get_active(GTK_MENU(menu));
1107 gint protocol = GPOINTER_TO_INT
1108 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
1109 gboolean skip_mailbox_page = FALSE;
1111 if (protocol == A_IMAP4) {
1112 skip_mailbox_page = TRUE;
1115 num_pages = g_slist_length(wizard->pages);
1117 current_page = gtk_notebook_get_current_page (
1118 GTK_NOTEBOOK(wizard->notebook));
1119 if (response == CANCEL)
1121 wizard->result = FALSE;
1122 wizard->finished = TRUE;
1123 gtk_widget_destroy (GTK_WIDGET(dialog));
1125 else if (response == FINISHED)
1127 if (!wizard_write_config(wizard)) {
1128 current_page = gtk_notebook_get_current_page (
1129 GTK_NOTEBOOK(wizard->notebook));
1132 wizard->result = TRUE;
1133 wizard->finished = TRUE;
1134 gtk_widget_destroy (GTK_WIDGET(dialog));
1138 if (response == GO_BACK)
1140 if (current_page > 0) {
1142 if (current_page == MAILBOX_PAGE && skip_mailbox_page) {
1146 gtk_notebook_set_current_page (
1147 GTK_NOTEBOOK(wizard->notebook),
1151 else if (response == GO_FORWARD)
1153 if (current_page < (num_pages-1)) {
1155 if (current_page == MAILBOX_PAGE && skip_mailbox_page) {
1159 gtk_notebook_set_current_page (
1160 GTK_NOTEBOOK(wizard->notebook),
1165 gtk_dialog_set_response_sensitive (dialog, GO_BACK,
1167 gtk_dialog_set_response_sensitive (dialog, GO_FORWARD,
1168 current_page < (num_pages - 1));
1169 gtk_dialog_set_response_sensitive (dialog, FINISHED,
1170 current_page == (num_pages - 1));
1174 static gint wizard_close_cb(GtkWidget *widget, GdkEventAny *event,
1177 WizardWindow *wizard = (WizardWindow *)data;
1178 wizard->result = FALSE;
1179 wizard->finished = TRUE;
1184 #define PACK_WARNING(text) { \
1185 label = gtk_label_new(text); \
1186 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); \
1187 gtk_box_pack_end(GTK_BOX(widget), label, FALSE, FALSE, 0); \
1190 gboolean run_wizard(MainWindow *mainwin, gboolean create_mailbox) {
1191 WizardWindow *wizard = g_new0(WizardWindow, 1);
1199 wizard->mainwin = mainwin;
1200 wizard->create_mailbox = create_mailbox;
1202 gtk_widget_hide(mainwin->window);
1204 wizard_read_defaults();
1206 wizard->window = gtk_dialog_new_with_buttons (_("Sylpheed-Claws Setup Wizard"),
1208 GTK_STOCK_GO_BACK, GO_BACK,
1209 GTK_STOCK_GO_FORWARD, GO_FORWARD,
1210 GTK_STOCK_SAVE, FINISHED,
1211 GTK_STOCK_CANCEL, CANCEL,
1214 g_signal_connect(wizard->window, "response",
1215 G_CALLBACK(wizard_response_cb), wizard);
1216 gtk_widget_realize(wizard->window);
1217 gtk_dialog_set_default_response(GTK_DIALOG(wizard->window),
1219 gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window),
1221 gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window),
1223 gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window),
1225 gtk_dialog_set_response_sensitive(GTK_DIALOG(wizard->window),
1228 wizard->notebook = gtk_notebook_new();
1229 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(wizard->notebook), FALSE);
1230 gtk_notebook_set_show_border(GTK_NOTEBOOK(wizard->notebook), FALSE);
1231 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(wizard->window)->vbox),
1232 wizard->notebook, TRUE, TRUE, 0);
1234 wizard->pages = NULL;
1236 /*welcome page: 0 */
1238 page = create_page(wizard, _("Welcome to Sylpheed-Claws"));
1240 wizard->pages = g_slist_append(wizard->pages, page);
1241 widget = stock_pixmap_widget(wizard->window,
1242 STOCK_PIXMAP_SYLPHEED_LOGO);
1244 gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1246 text = g_strdup(_("Welcome to the Sylpheed-Claws setup wizard.\n\n"
1247 "We will begin by defining some basic "
1248 "information about you and your most common "
1249 "mail options so that you can start to use "
1250 "Sylpheed-Claws in less than five minutes."));
1251 widget = gtk_label_new(text);
1252 gtk_label_set_line_wrap(GTK_LABEL(widget), TRUE);
1253 gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1259 widget = create_page (wizard, _("About You"));
1260 gtk_box_pack_start (GTK_BOX(widget), user_page(wizard), FALSE, FALSE, 0);
1261 PACK_WARNING(_("Bold fields must be completed"));
1263 wizard->pages = g_slist_append(wizard->pages, widget);
1265 /* recv+auth page: 2 */
1268 widget = create_page (wizard, _("Receiving mail"));
1269 gtk_box_pack_start (GTK_BOX(widget), recv_page(wizard), FALSE, FALSE, 0);
1270 PACK_WARNING(_("Bold fields must be completed"));
1272 wizard->pages = g_slist_append(wizard->pages, widget);
1277 widget = create_page (wizard, _("Sending mail"));
1278 gtk_box_pack_start (GTK_BOX(widget), smtp_page(wizard), FALSE, FALSE, 0);
1279 PACK_WARNING(_("Bold fields must be completed"));
1281 wizard->pages = g_slist_append(wizard->pages, widget);
1283 /* mailbox page: 4 */
1284 if (create_mailbox) {
1287 widget = create_page (wizard, _("Saving mail on disk"));
1288 gtk_box_pack_start (GTK_BOX(widget), mailbox_page(wizard), FALSE, FALSE, 0);
1289 PACK_WARNING(_("Bold fields must be completed"));
1291 wizard->pages = g_slist_append(wizard->pages, widget);
1297 widget = create_page (wizard, _("Security"));
1298 gtk_box_pack_start (GTK_BOX(widget), ssl_page(wizard), FALSE, FALSE, 0);
1299 PACK_WARNING(_("Bold fields must be completed"));
1301 wizard->pages = g_slist_append(wizard->pages, widget);
1307 page = create_page(wizard, _("Configuration finished"));
1309 wizard->pages = g_slist_append(wizard->pages, page);
1310 widget = stock_pixmap_widget(wizard->window,
1311 STOCK_PIXMAP_SYLPHEED_LOGO);
1313 gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1315 text = g_strdup(_("Sylpheed-Claws is now ready.\n\n"
1316 "Click Save to start."));
1317 widget = gtk_label_new(text);
1318 gtk_box_pack_start (GTK_BOX(page), widget, FALSE, FALSE, 0);
1322 for (cur = wizard->pages; cur && cur->data; cur = cur->next) {
1323 gtk_notebook_append_page (GTK_NOTEBOOK(wizard->notebook),
1324 GTK_WIDGET(cur->data), NULL);
1327 g_signal_connect(G_OBJECT(wizard->window), "delete_event",
1328 G_CALLBACK(wizard_close_cb), wizard);
1329 gtk_widget_show_all (wizard->window);
1331 gtk_widget_hide(wizard->recv_imap_label);
1332 gtk_widget_hide(wizard->recv_imap_subdir);
1334 wizard_protocol_change(wizard, tmpl.recvtype);
1336 while (!wizard->finished)
1337 gtk_main_iteration();
1339 result = wizard->result;
1343 gtk_widget_show(mainwin->window);