Fix bug #3574: Template addressing
[claws.git] / src / setup.c
blob552d8607537304f18a07009b3ead46c933e5b36c
1 /*
2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2012 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 #include "claws-features.h"
23 #endif
25 #include <stddef.h>
26 #include <glib.h>
27 #include <glib/gi18n.h>
28 #include <gtk/gtk.h>
30 #include "inputdialog.h"
31 #include "alertpanel.h"
32 #include "mainwindow.h"
33 #include "gtkutils.h"
34 #include "mh.h"
35 #include "wizard.h"
36 #define SETUP_DIALOG_WIDTH 540
38 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data);
40 gboolean setup_write_mailbox_path(MainWindow *mainwin, const gchar *path)
42 Folder *folder;
43 gchar *base;
45 if (!path) return FALSE;
46 if (folder_find_from_path(path)) {
47 g_warning("The mailbox already exists.");
48 return FALSE;
51 base = g_path_get_basename(path);
52 folder = folder_new(mh_get_class(), !strcmp(path, "Mail") ? _("Mailbox") : base, path);
54 if (folder->klass->create_tree(folder) < 0) {
55 alertpanel_error(_("Creation of the mailbox failed.\n"
56 "Maybe some files already exist, or you don't have the permission to write there."));
57 folder_destroy(folder);
58 g_free(base);
59 return FALSE;
62 folder_add(folder);
63 folder_set_ui_func(folder, scan_tree_func, mainwin);
64 folder_scan_tree(folder, TRUE);
65 folder_set_ui_func(folder, NULL, NULL);
66 g_free(base);
67 return TRUE;
70 void setup(MainWindow *mainwin)
72 gchar *path;
74 path = input_dialog
75 (_("Mailbox setting"),
76 _("First, you have to set the location of mailbox.\n"
77 "You can use existing mailbox in MH format\n"
78 "if you have the one.\n"
79 "If you're not sure, just select OK."),
80 "Mail");
81 setup_write_mailbox_path(mainwin, path);
82 g_free(path);
85 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
87 MainWindow *mainwin = (MainWindow *)data;
88 gchar *str;
90 if (item->path)
91 str = g_strdup_printf(_("Scanning folder %s%c%s..."),
92 LOCAL_FOLDER(folder)->rootpath,
93 G_DIR_SEPARATOR,
94 item->path);
95 else
96 str = g_strdup_printf(_("Scanning folder %s..."),
97 LOCAL_FOLDER(folder)->rootpath);
99 if (mainwin->statusbar)
100 gtk_statusbar_push(GTK_STATUSBAR(mainwin->statusbar),
101 mainwin->mainwin_cid, str);
102 if (mainwin->hbox_stat)
103 gtkut_widget_draw_now(mainwin->hbox_stat);
105 if (mainwin->statusbar)
106 gtk_statusbar_pop(GTK_STATUSBAR(mainwin->statusbar),
107 mainwin->mainwin_cid);
108 g_free(str);