add edit clear submenu/clear hard_edges, fix tessy gl segv, mask toolgui layout,...
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / bcnewfolder.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "condition.h"
23 #include "bcfilebox.h"
24 #include "bcnewfolder.h"
25 #include "bctitle.h"
26 #include "filesystem.h"
27 #include "language.h"
28 #include "mutex.h"
29
30 #include <sys/stat.h>
31
32
33
34
35
36
37
38 BC_NewFolder::BC_NewFolder(int x, int y, BC_FileBox *filebox)
39  : BC_Window(filebox->get_newfolder_title(),
40         x,
41         y,
42         320,
43         120,
44         0,
45         0,
46         0,
47         0,
48         1)
49 {
50 }
51
52 BC_NewFolder::~BC_NewFolder()
53 {
54 }
55
56
57 void BC_NewFolder::create_objects()
58 {
59         lock_window("BC_NewFolder::create_objects");
60         int x = 10, y = 10;
61         add_tool(new BC_Title(x, y, _("Enter the name of the folder:")));
62         y += 20;
63         add_subwindow(textbox = new BC_TextBox(x, y, 300, 1, _("Untitled")));
64         y += 30;
65         add_subwindow(new BC_OKButton(this));
66         x = get_w() - 100;
67         add_subwindow(new BC_CancelButton(this));
68         show_window();
69         unlock_window();
70 }
71
72 const char* BC_NewFolder::get_text()
73 {
74         return textbox->get_text();
75 }
76
77
78 BC_NewFolderThread::BC_NewFolderThread(BC_FileBox *filebox)
79  : Thread(0, 0, 0)
80 {
81         this->filebox = filebox;
82         window = 0;
83         change_lock = new Mutex("BC_NewFolderThread::change_lock");
84         completion_lock = new Condition(1, "BC_NewFolderThread::completion_lock");
85 }
86
87 BC_NewFolderThread::~BC_NewFolderThread()
88 {
89         interrupt();
90         delete change_lock;
91         delete completion_lock;
92 }
93
94 void BC_NewFolderThread::run()
95 {
96         int x = filebox->get_abs_cursor_x(1);
97         int y = filebox->get_abs_cursor_y(1);
98         change_lock->lock("BC_NewFolderThread::run 1");
99         window = new BC_NewFolder(x,
100                 y,
101                 filebox);
102         window->create_objects();
103         change_lock->unlock();
104
105
106         int result = window->run_window();
107
108         if(!result)
109         {
110                 char new_folder[BCTEXTLEN];
111                 filebox->fs->join_names(new_folder, filebox->fs->get_current_dir(), window->get_text());
112                 mkdir(new_folder, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
113                 filebox->lock_window("BC_NewFolderThread::run");
114                 filebox->refresh();
115                 filebox->unlock_window();
116         }
117
118         change_lock->lock("BC_NewFolderThread::run 2");
119         delete window;
120         window = 0;
121         change_lock->unlock();
122
123         completion_lock->unlock();
124 }
125
126 int BC_NewFolderThread::interrupt()
127 {
128         change_lock->lock("BC_NewFolderThread::interrupt");
129         if(window)
130         {
131                 window->lock_window("BC_NewFolderThread::interrupt");
132                 window->set_done(1);
133                 window->unlock_window();
134         }
135
136         change_lock->unlock();
137
138         completion_lock->lock("BC_NewFolderThread::interrupt");
139         completion_lock->unlock();
140         return 0;
141 }
142
143 int BC_NewFolderThread::start_new_folder()
144 {
145         change_lock->lock();
146
147         if(window)
148         {
149                 window->lock_window("BC_NewFolderThread::start_new_folder");
150                 window->raise_window();
151                 window->unlock_window();
152                 change_lock->unlock();
153         }
154         else
155         {
156                 change_lock->unlock();
157                 completion_lock->lock("BC_NewFolderThread::start_new_folder");
158
159                 Thread::start();
160         }
161
162
163         return 0;
164 }
165
166