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