4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "condition.h"
23 #include "bcfilebox.h"
24 #include "bcnewfolder.h"
26 #include "filesystem.h"
38 BC_NewFolder::BC_NewFolder(int x, int y, BC_FileBox *filebox)
39 : BC_Window(filebox->get_newfolder_title(),
52 BC_NewFolder::~BC_NewFolder()
57 void BC_NewFolder::create_objects()
60 add_tool(new BC_Title(x, y, _("Enter the name of the folder:")));
62 add_subwindow(textbox = new BC_TextBox(x, y, 300, 1, _("Untitled")));
64 add_subwindow(new BC_OKButton(this));
66 add_subwindow(new BC_CancelButton(this));
70 const char* BC_NewFolder::get_text()
72 return textbox->get_text();
76 BC_NewFolderThread::BC_NewFolderThread(BC_FileBox *filebox)
79 this->filebox = filebox;
81 change_lock = new Mutex("BC_NewFolderThread::change_lock");
82 completion_lock = new Condition(1, "BC_NewFolderThread::completion_lock");
85 BC_NewFolderThread::~BC_NewFolderThread()
89 delete completion_lock;
92 void BC_NewFolderThread::run()
94 int x = filebox->get_abs_cursor_x(1);
95 int y = filebox->get_abs_cursor_y(1);
96 change_lock->lock("BC_NewFolderThread::run 1");
97 window = new BC_NewFolder(x,
100 window->create_objects();
101 change_lock->unlock();
104 int result = window->run_window();
108 char new_folder[BCTEXTLEN];
109 filebox->fs->join_names(new_folder, filebox->fs->get_current_dir(), window->get_text());
110 mkdir(new_folder, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
111 filebox->lock_window("BC_NewFolderThread::run");
113 filebox->unlock_window();
116 change_lock->lock("BC_NewFolderThread::run 2");
119 change_lock->unlock();
121 completion_lock->unlock();
124 int BC_NewFolderThread::interrupt()
126 change_lock->lock("BC_NewFolderThread::interrupt");
129 window->lock_window("BC_NewFolderThread::interrupt");
131 window->unlock_window();
134 change_lock->unlock();
136 completion_lock->lock("BC_NewFolderThread::interrupt");
137 completion_lock->unlock();
141 int BC_NewFolderThread::start_new_folder()
147 window->lock_window("BC_NewFolderThread::start_new_folder");
148 window->raise_window();
149 window->unlock_window();
150 change_lock->unlock();
154 change_lock->unlock();
155 completion_lock->lock("BC_NewFolderThread::start_new_folder");