ba60af09967cfa3e95497215f928b6fa9319f5d0
[claws.git] / src / setup.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999,2000 Hiroyuki Yamamoto
4  *
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 2 of the License, or
8  * (at your option) any later version.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include <stddef.h>
25 #include <glib.h>
26 #include <glib/gi18n.h>
27 #include <gtk/gtkstatusbar.h>
28
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
36
37 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data);
38
39 void setup(MainWindow *mainwin)
40 {
41         gchar *path;
42         
43         path = input_dialog
44                 (_("Mailbox setting"),
45                  _("First, you have to set the location of mailbox.\n"
46                    "You can use existing mailbox in MH format\n"
47                    "if you have the one.\n"
48                    "If you're not sure, just select OK."),
49                  "Mail");
50         setup_write_mailbox_path(mainwin, path);
51         g_free(path);
52 }
53
54 gboolean setup_write_mailbox_path(MainWindow *mainwin, const gchar *path)
55 {
56         Folder *folder;
57         gchar *base;
58
59         if (!path) return FALSE;
60         if (folder_find_from_path(path)) {
61                 g_warning("The mailbox already exists.\n");
62                 return FALSE;
63         }
64
65         base = g_path_get_basename(path);
66         folder = folder_new(mh_get_class(), !strcmp(path, "Mail") ? _("Mailbox") : base, path);
67
68         if (folder->klass->create_tree(folder) < 0) {
69                 alertpanel_error(_("Creation of the mailbox failed.\n"
70                                    "Maybe some files already exist, or you don't have the permission to write there."));
71                 folder_destroy(folder);
72                 g_free(base);
73                 return FALSE;
74         }
75
76         folder_add(folder);
77         folder_set_ui_func(folder, scan_tree_func, mainwin);
78         folder_scan_tree(folder);
79         folder_set_ui_func(folder, NULL, NULL);
80         g_free(base);
81         return TRUE;
82 }
83
84 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
85 {
86         MainWindow *mainwin = (MainWindow *)data;
87         gchar *str;
88
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);
97
98         gtk_statusbar_push(GTK_STATUSBAR(mainwin->statusbar),
99                            mainwin->mainwin_cid, str);
100         gtkut_widget_wait_for_draw(mainwin->hbox_stat);
101         gtk_statusbar_pop(GTK_STATUSBAR(mainwin->statusbar),
102                           mainwin->mainwin_cid);
103         g_free(str);
104 }