r802: Remove renderframfsclient and renderfarmfsserver .h and .C from Makefile.am...
[cinelerra_cv/mob.git] / guicast / bcnewfolder.C
blob0ef4972ac1ca2f86465baab2f6880263c8b1d36b
1 #include "condition.h"
2 #include "bcfilebox.h"
3 #include "bcnewfolder.h"
4 #include "bctitle.h"
5 #include "filesystem.h"
6 #include "language.h"
8 #include <sys/stat.h>
16 BC_NewFolder::BC_NewFolder(int x, int y, BC_FileBox *filebox)
17  : BC_Window(filebox->get_newfolder_title(), 
18         x, 
19         y, 
20         320, 
21         120, 
22         0, 
23         0, 
24         0, 
25         0, 
26         1)
30 BC_NewFolder::~BC_NewFolder()
35 int BC_NewFolder::create_objects()
37         int x = 10, y = 10;
38         add_tool(new BC_Title(x, y, _("Enter the name of the folder:")));
39         y += 20;
40         add_subwindow(textbox = new BC_TextBox(x, y, 300, 1, _("Untitled")));
41         y += 30;
42         add_subwindow(new BC_OKButton(this));
43         x = get_w() - 100;
44         add_subwindow(new BC_CancelButton(this));
45         show_window();
46         return 0;
49 char* BC_NewFolder::get_text()
51         return textbox->get_text();
55 BC_NewFolderThread::BC_NewFolderThread(BC_FileBox *filebox)
56  : Thread(0, 0, 0)
58         this->filebox = filebox;
59         window = 0;
60         change_lock = new Mutex("BC_NewFolderThread::change_lock");
61         completion_lock = new Condition(1, "BC_NewFolderThread::completion_lock");
64 BC_NewFolderThread::~BC_NewFolderThread() 
66         interrupt();
67         delete change_lock;
68         delete completion_lock;
71 void BC_NewFolderThread::run()
73         int x = filebox->get_abs_cursor_x(1);
74         int y = filebox->get_abs_cursor_y(1);
75         change_lock->lock("BC_NewFolderThread::run 1");
76         window = new BC_NewFolder(x, 
77                 y,
78                 filebox);
79         window->create_objects();
80         change_lock->unlock();
83         int result = window->run_window();
85         if(!result)
86         {
87                 char new_folder[BCTEXTLEN];
88                 filebox->fs->join_names(new_folder, filebox->fs->get_current_dir(), window->get_text());
89                 mkdir(new_folder, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
90                 filebox->lock_window("BC_NewFolderThread::run");
91                 filebox->refresh();
92                 filebox->unlock_window();
93         }
95         change_lock->lock("BC_NewFolderThread::run 2");
96         delete window;
97         window = 0;
98         change_lock->unlock();
100         completion_lock->unlock();
103 int BC_NewFolderThread::interrupt()
105         change_lock->lock("BC_NewFolderThread::interrupt");
106         if(window)
107         {
108                 window->lock_window("BC_NewFolderThread::interrupt");
109                 window->set_done(1);
110                 window->unlock_window();
111         }
113         change_lock->unlock();
115         completion_lock->lock("BC_NewFolderThread::interrupt");
116         completion_lock->unlock();
117         return 0;
120 int BC_NewFolderThread::start_new_folder()
122         change_lock->lock();
124         if(window)
125         {
126                 window->lock_window("BC_NewFolderThread::start_new_folder");
127                 window->raise_window();
128                 window->unlock_window();
129                 change_lock->unlock();
130         }
131         else
132         {
133                 change_lock->unlock();
134                 completion_lock->lock("BC_NewFolderThread::start_new_folder");
136                 Thread::start();
137         }
140         return 0;