2005-10-16 [colin] 1.9.15cvs63
[claws.git] / src / wizard.c
index 11845a94137d13c2302bd68a523c91f416787ed5..164b46a1a5340aa58a99dd39e8ca44f9f4dad8d8 100644 (file)
@@ -58,6 +58,8 @@
 #ifdef USE_OPENSSL                     
 #include "ssl.h"
 #endif
+#include "prefs_common.h"
+
 typedef enum
 {
        GO_BACK,
@@ -103,7 +105,108 @@ typedef struct
 
 } WizardWindow;
 
-static void wizard_write_config(WizardWindow *wizard)
+static void initialize_fonts(WizardWindow *wizard)
+{
+       GtkWidget *widget = wizard->email;
+       gint size = pango_font_description_get_size(
+                       widget->style->font_desc)
+                     /PANGO_SCALE;
+       gchar *tmp, *new;
+       
+       tmp = g_strdup(prefs_common.textfont);
+       if (strrchr(tmp, ' ')) {
+               *(strrchr(tmp, ' ')) = '\0';
+               new = g_strdup_printf("%s %d", tmp, size);
+               g_free(prefs_common.textfont);
+               prefs_common.textfont = new;
+       }
+       g_free(tmp);
+       
+       tmp = g_strdup(prefs_common.smallfont);
+       if (strrchr(tmp, ' ')) {
+               *(strrchr(tmp, ' ')) = '\0';
+               new = g_strdup_printf("%s %d", tmp, size);
+               g_free(prefs_common.smallfont);
+               prefs_common.smallfont = new;
+       }
+       g_free(tmp);
+       
+       tmp = g_strdup(prefs_common.normalfont);
+       if (strrchr(tmp, ' ')) {
+               *(strrchr(tmp, ' ')) = '\0';
+               new = g_strdup_printf("%s %d", tmp, size);
+               g_free(prefs_common.normalfont);
+               prefs_common.normalfont = new;
+       }
+       g_free(tmp);
+}
+
+static void write_welcome_email(WizardWindow *wizard)
+{
+       gchar buf_date[64];
+       gchar *body=NULL;
+       const gchar *mailbox = gtk_entry_get_text(GTK_ENTRY(wizard->mailbox_name));
+       Folder *folder = folder_find_from_path(mailbox);
+       FolderItem *inbox = folder ? folder->inbox:NULL;
+       gchar *file = get_tmp_file();
+       
+       get_rfc822_date(buf_date, sizeof(buf_date));
+
+       body = g_strdup_printf(
+               "From: Sylpheed-Claws Team <sylpheed-claws-users@lists.sf.net>\n"
+               "To: %s <%s>\n"
+               "Date: %s\n"
+               "Subject: Welcome to Sylpheed-Claws.\n"
+               "\n"
+               "Welcome to Sylpheed-Claws\n"
+               "-------------------------\n"
+               "\n"
+               "Now that you have set up your account you can fetch your\n"
+               "mail by clicking the 'Get All' button at the left of the\n"
+               "toolbar.\n"
+               "\n"
+               "You can change your Account Preferences by using the menu\n"
+               "entry '/Configuration/Preferences for current account'\n"
+               "and change the general Preferences by using\n"
+               "'/Configuration/Preferences'.\n"
+               "\n"
+               "You can find futher information in the Sylpheed-Claws manual,\n"
+               "which can be accessed by using the menu entry '/Help/Manual'\n"
+               "or online at the URL given below.\n"
+               "\n"
+               "Useful URLs\n"
+               "-----------\n"
+               "Homepage:      <http://claws.sylpheed.org>\n"
+               "Manual:        <http://claws.sylpheed.org/manual/>\n"
+               "FAQ:          <http://claws.sylpheed.org/faq.php>\n"
+               "Themes:        <http://claws.sylpheed.org/themes.php>\n"
+               "Mailing Lists: <http://claws.sylpheed.org/MLs.php>\n"
+               "\n"
+               "LICENSE\n"
+               "-------\n"
+               "Sylpheed-Claws is free software, released under the terms\n"
+               "of the GNU General Public License, version 2 or later, as\n"
+               "published by the Free Software Foundation, 51 Franklin Street,\n"
+               "Fifth Floor, Boston, MA 02110-1301, USA. The license can be\n"
+               "found at <http://www.gnu.org/licenses/gpl.html>.\n"
+               "\n"
+               "DONATIONS\n"
+               "---------\n"
+               "If you wish to donate to the Sylpheed-Claws project you can do\n"
+               "so at <https://sourceforge.net/donate/index.php?group_id=25528>.",             
+               gtk_entry_get_text(GTK_ENTRY(wizard->full_name)),
+               gtk_entry_get_text(GTK_ENTRY(wizard->email)),
+               buf_date);
+       
+       if (inbox && inbox->total_msgs == 0
+        && str_write_to_file(body, file) >= 0) {
+               MsgFlags flags = { MSG_UNREAD|MSG_NEW, 0};
+               folder_item_add_msg(inbox, file, &flags, FALSE);
+       }
+       g_free(body);
+       g_unlink(file); 
+}
+static gboolean wizard_write_config(WizardWindow *wizard)
 {
        gboolean mailbox_ok = FALSE;
        PrefsAccount *prefs_account = prefs_account_new();
@@ -114,12 +217,20 @@ static void wizard_write_config(WizardWindow *wizard)
        menuitem = gtk_menu_get_active(GTK_MENU(menu));
        prefs_account->protocol = GPOINTER_TO_INT
                        (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
-
+       
        if (wizard->create_mailbox && prefs_account->protocol != A_IMAP4) {
                mailbox_ok = setup_write_mailbox_path(wizard->mainwin, 
                                gtk_entry_get_text(GTK_ENTRY(wizard->mailbox_name)));
+       } else
+               mailbox_ok = TRUE;
+
+       if (!mailbox_ok) {
+               gtk_notebook_set_current_page (
+                       GTK_NOTEBOOK(wizard->notebook), 
+                       4);
+               return FALSE;
        }
-
+       
        if (prefs_account->protocol != A_LOCAL)
                prefs_account->account_name = g_strdup_printf("%s@%s",
                                gtk_entry_get_text(GTK_ENTRY(wizard->recv_username)),
@@ -172,6 +283,12 @@ static void wizard_write_config(WizardWindow *wizard)
        prefs_account_write_config_all(account_list);
        prefs_account_free(prefs_account);
        account_read_config_all();
+
+       initialize_fonts(wizard);
+       if (wizard->create_mailbox && prefs_account->protocol != A_IMAP4)
+               write_welcome_email(wizard);
+       
+       return TRUE;
 }
 
 static GtkWidget* create_page (WizardWindow *wizard, const char * title)
@@ -519,19 +636,24 @@ wizard_response_cb (GtkDialog * dialog, int response, gpointer data)
        }
        
        num_pages = g_slist_length(wizard->pages);
+
        current_page = gtk_notebook_get_current_page (
                                GTK_NOTEBOOK(wizard->notebook));
        if (response == CANCEL)
        {
-               wizard->finished = TRUE;
                wizard->result = FALSE;
+               wizard->finished = TRUE;
                gtk_widget_destroy (GTK_WIDGET(dialog));
        }
        else if (response == FINISHED)
        {
-               wizard_write_config(wizard);
-               wizard->finished = TRUE;
+               if (!wizard_write_config(wizard)) {
+                       current_page = gtk_notebook_get_current_page (
+                                       GTK_NOTEBOOK(wizard->notebook));
+                       goto set_sens;
+               }
                wizard->result = TRUE;
+               wizard->finished = TRUE;
                gtk_widget_destroy (GTK_WIDGET(dialog));
        }
        else
@@ -562,7 +684,7 @@ wizard_response_cb (GtkDialog * dialog, int response, gpointer data)
                                        current_page);
                        }
                }
-
+set_sens:
                gtk_dialog_set_response_sensitive (dialog, GO_BACK, 
                                current_page > 0);
                gtk_dialog_set_response_sensitive (dialog, GO_FORWARD, 
@@ -574,6 +696,15 @@ wizard_response_cb (GtkDialog * dialog, int response, gpointer data)
        }
 }
 
+static gint wizard_close_cb(GtkWidget *widget, GdkEventAny *event,
+                                gpointer data)
+{
+       WizardWindow *wizard = (WizardWindow *)data;
+       wizard->result = FALSE;
+       wizard->finished = TRUE;
+       
+       return FALSE;
+}
 
 gboolean run_wizard(MainWindow *mainwin, gboolean create_mailbox) {
        WizardWindow *wizard = g_new0(WizardWindow, 1);
@@ -686,7 +817,10 @@ gboolean run_wizard(MainWindow *mainwin, gboolean create_mailbox) {
                                          GTK_WIDGET(cur->data), NULL);
        }
        
+       g_signal_connect(G_OBJECT(wizard->window), "delete_event",
+                        G_CALLBACK(wizard_close_cb), wizard);
        gtk_widget_show_all (wizard->window);
+
        gtk_widget_hide(wizard->recv_imap_label);
        gtk_widget_hide(wizard->recv_imap_subdir);