Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

bcnewfolder.C

Go to the documentation of this file.
00001 #include "condition.h"
00002 #include "bcfilebox.h"
00003 #include "bcnewfolder.h"
00004 #include "bctitle.h"
00005 #include "filesystem.h"
00006 #include "language.h"
00007 
00008 #include <sys/stat.h>
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 BC_NewFolder::BC_NewFolder(int x, int y, BC_FileBox *filebox)
00017  : BC_Window(filebox->get_newfolder_title(), 
00018         x, 
00019         y, 
00020         320, 
00021         120, 
00022         0, 
00023         0, 
00024         0, 
00025         0, 
00026         1)
00027 {
00028 }
00029 
00030 BC_NewFolder::~BC_NewFolder()
00031 {
00032 }
00033 
00034 
00035 int BC_NewFolder::create_objects()
00036 {
00037         int x = 10, y = 10;
00038         add_tool(new BC_Title(x, y, _("Enter the name of the folder:")));
00039         y += 20;
00040         add_subwindow(textbox = new BC_TextBox(x, y, 300, 1, _("Untitled")));
00041         y += 30;
00042         add_subwindow(new BC_OKButton(this));
00043         x = get_w() - 100;
00044         add_subwindow(new BC_CancelButton(this));
00045         show_window();
00046         return 0;
00047 }
00048 
00049 char* BC_NewFolder::get_text()
00050 {
00051         return textbox->get_text();
00052 }
00053 
00054 
00055 BC_NewFolderThread::BC_NewFolderThread(BC_FileBox *filebox)
00056  : Thread(0, 0, 0)
00057 {
00058         this->filebox = filebox;
00059         window = 0;
00060         change_lock = new Mutex("BC_NewFolderThread::change_lock");
00061         completion_lock = new Condition(1, "BC_NewFolderThread::completion_lock");
00062 }
00063 
00064 BC_NewFolderThread::~BC_NewFolderThread() 
00065 {
00066         interrupt();
00067         delete change_lock;
00068         delete completion_lock;
00069 }
00070 
00071 void BC_NewFolderThread::run()
00072 {
00073         int x = filebox->get_abs_cursor_x(1);
00074         int y = filebox->get_abs_cursor_y(1);
00075         change_lock->lock("BC_NewFolderThread::run 1");
00076         window = new BC_NewFolder(x, 
00077                 y,
00078                 filebox);
00079         window->create_objects();
00080         change_lock->unlock();
00081 
00082 
00083         int result = window->run_window();
00084 
00085         if(!result)
00086         {
00087                 char new_folder[BCTEXTLEN];
00088                 filebox->fs->join_names(new_folder, filebox->fs->get_current_dir(), window->get_text());
00089                 mkdir(new_folder, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
00090                 filebox->lock_window("BC_NewFolderThread::run");
00091                 filebox->refresh();
00092                 filebox->unlock_window();
00093         }
00094 
00095         change_lock->lock("BC_NewFolderThread::run 2");
00096         delete window;
00097         window = 0;
00098         change_lock->unlock();
00099 
00100         completion_lock->unlock();
00101 }
00102 
00103 int BC_NewFolderThread::interrupt()
00104 {
00105         change_lock->lock("BC_NewFolderThread::interrupt");
00106         if(window)
00107         {
00108                 window->lock_window("BC_NewFolderThread::interrupt");
00109                 window->set_done(1);
00110                 window->unlock_window();
00111         }
00112 
00113         change_lock->unlock();
00114 
00115         completion_lock->lock("BC_NewFolderThread::interrupt");
00116         completion_lock->unlock();
00117         return 0;
00118 }
00119 
00120 int BC_NewFolderThread::start_new_folder()
00121 {
00122         change_lock->lock();
00123 
00124         if(window)
00125         {
00126                 window->lock_window("BC_NewFolderThread::start_new_folder");
00127                 window->raise_window();
00128                 window->unlock_window();
00129                 change_lock->unlock();
00130         }
00131         else
00132         {
00133                 change_lock->unlock();
00134                 completion_lock->lock("BC_NewFolderThread::start_new_folder");
00135 
00136                 Thread::start();
00137         }
00138 
00139 
00140         return 0;
00141 }
00142 
00143 

Generated on Sun Jan 8 13:26:32 2006 for Guicast-svn by  doxygen 1.4.4