r938: Make cinelerra actually read AVI DV+PCM it produces...
[cinelerra_cv/mob.git] / guicast / bcnewfolder.C
blob0970df7f54ccea2e9d27be16d5ca8bf82c293eb2
1 #include "condition.h"
2 #include "bcfilebox.h"
3 #include "bcnewfolder.h"
4 #include "bctitle.h"
5 #include "filesystem.h"
6 #include "language.h"
7 #include "mutex.h"
9 #include <sys/stat.h>
17 BC_NewFolder::BC_NewFolder(int x, int y, BC_FileBox *filebox)
18  : BC_Window(filebox->get_newfolder_title(), 
19         x, 
20         y, 
21         320, 
22         120, 
23         0, 
24         0, 
25         0, 
26         0, 
27         1)
31 BC_NewFolder::~BC_NewFolder()
36 int BC_NewFolder::create_objects()
38         int x = 10, y = 10;
39         add_tool(new BC_Title(x, y, _("Enter the name of the folder:")));
40         y += 20;
41         add_subwindow(textbox = new BC_TextBox(x, y, 300, 1, _("Untitled")));
42         y += 30;
43         add_subwindow(new BC_OKButton(this));
44         x = get_w() - 100;
45         add_subwindow(new BC_CancelButton(this));
46         show_window();
47         return 0;
50 char* BC_NewFolder::get_text()
52         return textbox->get_text();
56 BC_NewFolderThread::BC_NewFolderThread(BC_FileBox *filebox)
57  : Thread(0, 0, 0)
59         this->filebox = filebox;
60         window = 0;
61         change_lock = new Mutex("BC_NewFolderThread::change_lock");
62         completion_lock = new Condition(1, "BC_NewFolderThread::completion_lock");
65 BC_NewFolderThread::~BC_NewFolderThread() 
67         interrupt();
68         delete change_lock;
69         delete completion_lock;
72 void BC_NewFolderThread::run()
74         int x = filebox->get_abs_cursor_x(1);
75         int y = filebox->get_abs_cursor_y(1);
76         change_lock->lock("BC_NewFolderThread::run 1");
77         window = new BC_NewFolder(x, 
78                 y,
79                 filebox);
80         window->create_objects();
81         change_lock->unlock();
84         int result = window->run_window();
86         if(!result)
87         {
88                 char new_folder[BCTEXTLEN];
89                 filebox->fs->join_names(new_folder, filebox->fs->get_current_dir(), window->get_text());
90                 mkdir(new_folder, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
91                 filebox->lock_window("BC_NewFolderThread::run");
92                 filebox->refresh();
93                 filebox->unlock_window();
94         }
96         change_lock->lock("BC_NewFolderThread::run 2");
97         delete window;
98         window = 0;
99         change_lock->unlock();
101         completion_lock->unlock();
104 int BC_NewFolderThread::interrupt()
106         change_lock->lock("BC_NewFolderThread::interrupt");
107         if(window)
108         {
109                 window->lock_window("BC_NewFolderThread::interrupt");
110                 window->set_done(1);
111                 window->unlock_window();
112         }
114         change_lock->unlock();
116         completion_lock->lock("BC_NewFolderThread::interrupt");
117         completion_lock->unlock();
118         return 0;
121 int BC_NewFolderThread::start_new_folder()
123         change_lock->lock();
125         if(window)
126         {
127                 window->lock_window("BC_NewFolderThread::start_new_folder");
128                 window->raise_window();
129                 window->unlock_window();
130                 change_lock->unlock();
131         }
132         else
133         {
134                 change_lock->unlock();
135                 completion_lock->lock("BC_NewFolderThread::start_new_folder");
137                 Thread::start();
138         }
141         return 0;