2007-08-27 [colin] 2.10.0cvs179
[claws.git] / src / setup.c
blob87f23bd7ce9d26d89e56e2a552818c63f8027000
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #endif
24 #include <stddef.h>
25 #include <glib.h>
26 #include <glib/gi18n.h>
27 #include <gtk/gtkstatusbar.h>
29 #include "inputdialog.h"
30 #include "alertpanel.h"
31 #include "mainwindow.h"
32 #include "gtkutils.h"
33 #include "mh.h"
34 #include "wizard.h"
35 #define SETUP_DIALOG_WIDTH 540
37 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data);
39 gboolean setup_write_mailbox_path(MainWindow *mainwin, const gchar *path)
41 Folder *folder;
42 gchar *base;
44 if (!path) return FALSE;
45 if (folder_find_from_path(path)) {
46 g_warning("The mailbox already exists.\n");
47 return FALSE;
50 base = g_path_get_basename(path);
51 folder = folder_new(mh_get_class(), !strcmp(path, "Mail") ? _("Mailbox") : base, path);
53 if (folder->klass->create_tree(folder) < 0) {
54 alertpanel_error(_("Creation of the mailbox failed.\n"
55 "Maybe some files already exist, or you don't have the permission to write there."));
56 folder_destroy(folder);
57 g_free(base);
58 return FALSE;
61 folder_add(folder);
62 folder_set_ui_func(folder, scan_tree_func, mainwin);
63 folder_scan_tree(folder, TRUE);
64 folder_set_ui_func(folder, NULL, NULL);
65 g_free(base);
66 return TRUE;
69 void setup(MainWindow *mainwin)
71 gchar *path;
73 path = input_dialog
74 (_("Mailbox setting"),
75 _("First, you have to set the location of mailbox.\n"
76 "You can use existing mailbox in MH format\n"
77 "if you have the one.\n"
78 "If you're not sure, just select OK."),
79 "Mail");
80 setup_write_mailbox_path(mainwin, path);
81 g_free(path);
84 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
86 MainWindow *mainwin = (MainWindow *)data;
87 gchar *str;
89 if (item->path)
90 str = g_strdup_printf(_("Scanning folder %s%c%s ..."),
91 LOCAL_FOLDER(folder)->rootpath,
92 G_DIR_SEPARATOR,
93 item->path);
94 else
95 str = g_strdup_printf(_("Scanning folder %s ..."),
96 LOCAL_FOLDER(folder)->rootpath);
98 if (mainwin->statusbar)
99 gtk_statusbar_push(GTK_STATUSBAR(mainwin->statusbar),
100 mainwin->mainwin_cid, str);
101 if (mainwin->hbox_stat)
102 gtkut_widget_draw_now(mainwin->hbox_stat);
104 if (mainwin->statusbar)
105 gtk_statusbar_pop(GTK_STATUSBAR(mainwin->statusbar),
106 mainwin->mainwin_cid);
107 g_free(str);