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

threadindexer.C

Go to the documentation of this file.
00001 #include "asset.h"
00002 #include "assets.h"
00003 #include "bcprogressbox.h"
00004 #include "condition.h"
00005 #include "defaults.h"
00006 #include "filesystem.h"
00007 #include "guicast.h"
00008 #include "indexfile.h"
00009 #include "language.h"
00010 #include "loadfile.h"
00011 #include "mwindowgui.h"
00012 #include "mwindow.h"
00013 #include "threadindexer.h"
00014 
00015 #include <string.h>
00016 
00017 
00018 
00019 
00020 
00021 ThreadIndexer::ThreadIndexer(MWindow *mwindow, Assets *assets)
00022  : Thread()
00023 {
00024         this->mwindow = mwindow;
00025         this->assets = assets;
00026         set_synchronous(0);
00027         indexfile = new IndexFile(mwindow);
00028         interrupt_lock = new Condition(0, "ThreadIndexer::ThreadIndexer");
00029 }
00030 
00031 ThreadIndexer::~ThreadIndexer()
00032 {
00033         delete indexfile;
00034         delete interrupt_lock;
00035 }
00036 
00037 int ThreadIndexer::start_build()
00038 {
00039         interrupt_flag = 0;
00040         start();
00041 }
00042 
00043 // build all here to allow editing during build
00044 void ThreadIndexer::run()
00045 {
00046 // check locations of each asset
00047         FILE *test_file;
00048         Asset *current_asset;
00049         char new_filename[1024], old_filename[1024];
00050         int result = 0;
00051         BC_ProgressBox *progress = 0;
00052 
00053         for(current_asset = assets->first; current_asset; current_asset = current_asset->next)
00054         {
00055                 if(!(test_file = fopen(current_asset->path, "rb")))
00056                 {
00057 // file doesn't exist
00058                         strcpy(old_filename, current_asset->path);
00059 
00060                         result = 1;
00061 // get location from user
00062                         char directory[1024];
00063                         sprintf(directory, "~");
00064                         mwindow->defaults->get("DIRECTORY", directory);
00065 
00066                         char string[1024], name[1024];
00067                         FileSystem dir;
00068                         dir.extract_name(name, old_filename);
00069                         sprintf(string, _("Where is %s?"), name);
00070 
00071                         LocateFileWindow window(mwindow, directory, string);
00072                         window.create_objects();
00073                         int result2 = window.run_window();
00074 
00075                         mwindow->defaults->update("DIRECTORY", 
00076                                 window.get_submitted_path());
00077 
00078                         if(result2 == 1)
00079                         {
00080                                 strcpy(new_filename, SILENCE);
00081                         }
00082                         else
00083                         {
00084                                 strcpy(new_filename, 
00085                                         window.get_submitted_path());
00086                         }
00087 
00088 // update assets containing old location
00089                         assets->update_old_filename(old_filename, new_filename);
00090                 }
00091                 else
00092                 {
00093                         fclose(test_file);
00094                 }
00095         }
00096 
00097 
00098 // test index of each asset
00099         for(current_asset = assets->first; 
00100                 current_asset && !interrupt_flag; 
00101                 current_asset = current_asset->next)
00102         {
00103 // test for an index file already built before creating progress bar
00104                 if(current_asset->index_status == INDEX_NOTTESTED && 
00105                         current_asset->audio_data)
00106                 {
00107                         if(indexfile->open_index(mwindow, current_asset))
00108                         {
00109 // doesn't exist
00110 // try to create now
00111                                 if(!progress)
00112                                 {
00113                                         progress = new BC_ProgressBox(mwindow->gui->get_abs_cursor_x(1),
00114                                                 mwindow->gui->get_abs_cursor_y(1),
00115                                                 _("Building Indexes..."), 
00116                                                 1);
00117                                         progress->start();
00118                                 }
00119 
00120 //                              indexfile->create_index(mwindow, current_asset, progress);
00121                                 if(progress->is_cancelled()) interrupt_flag = 1;
00122                         }
00123                         else
00124                         {
00125                                 if(current_asset->index_status == 1) current_asset->index_status = 0;   // index has been tested
00126                                 indexfile->close_index();
00127                         }
00128                 }
00129         }
00130 
00131         if(progress)     // progress box is only createdd when an index is built
00132         {       
00133                 progress->stop_progress();
00134                 delete progress;
00135                 progress = 0;
00136         }
00137 
00138         interrupt_lock->unlock();
00139 }
00140 
00141 int ThreadIndexer::interrupt_build()
00142 {
00143         interrupt_flag = 1;
00144         indexfile->interrupt_index();
00145         interrupt_lock->lock(" ThreadIndexer::interrupt_build");
00146         interrupt_lock->unlock();
00147 }
00148 

Generated on Sun Jan 8 13:39:00 2006 for Cinelerra-svn by  doxygen 1.4.4