talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

setup.c (2505B)


      1 /*
      2  * Claws Mail -- a GTK based, lightweight, and fast e-mail client
      3  * Copyright (C) 1999-2022 Hiroyuki Yamamoto and the Claws Mail team
      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 3 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, see <http://www.gnu.org/licenses/>.
     17  */
     18 
     19 #include <stddef.h>
     20 #include <glib.h>
     21 #include <glib/gi18n.h>
     22 #include <gtk/gtk.h>
     23 
     24 #include "inputdialog.h"
     25 #include "alertpanel.h"
     26 #include "mainwindow.h"
     27 #include "gtkutils.h"
     28 #include "mh.h"
     29 
     30 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data);
     31 
     32 gboolean setup_write_mailbox_path(MainWindow *mainwin, const gchar *path)
     33 {
     34 	Folder *folder;
     35 	gchar *base;
     36 
     37 	if (!path) return FALSE;
     38 	if (folder_find_from_path(path)) {
     39 		g_warning("the mailbox already exists");
     40 		return FALSE;
     41 	}
     42 
     43 	base = g_path_get_basename(path);
     44 	folder = folder_new(mh_get_class(), !strcmp(path, "Mail") ? _("Mailbox") : base, path);
     45 
     46 	if (folder->klass->create_tree(folder) < 0) {
     47 		alertpanel_error(_("Creation of the mailbox failed.\n"
     48 				   "Maybe some files already exist, or you don't have the permission to write there."));
     49 		folder_destroy(folder);
     50 		g_free(base);
     51 		return FALSE;
     52 	}
     53 
     54 	folder_add(folder);
     55 	folder_set_ui_func(folder, scan_tree_func, mainwin);
     56 	folder_scan_tree(folder, TRUE);
     57 	folder_set_ui_func(folder, NULL, NULL);
     58 	g_free(base);
     59 	return TRUE;
     60 }
     61 
     62 static void scan_tree_func(Folder *folder, FolderItem *item, gpointer data)
     63 {
     64 	MainWindow *mainwin = (MainWindow *)data;
     65 	gchar *str;
     66 
     67 	if (item->path)
     68 		str = g_strdup_printf(_("Scanning folder %s%c%s..."),
     69 				      LOCAL_FOLDER(folder)->rootpath,
     70 				      G_DIR_SEPARATOR,
     71 				      item->path);
     72 	else
     73 		str = g_strdup_printf(_("Scanning folder %s..."),
     74 				      LOCAL_FOLDER(folder)->rootpath);
     75 
     76 	if (mainwin->statusbar)
     77 		gtk_statusbar_push(GTK_STATUSBAR(mainwin->statusbar),
     78 			   mainwin->mainwin_cid, str);
     79 
     80 	if (mainwin->statusbar)
     81 		gtk_statusbar_pop(GTK_STATUSBAR(mainwin->statusbar),
     82 			  mainwin->mainwin_cid);
     83 	g_free(str);
     84 }