r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / threadindexer.C
blobaaab7c23cf53e333b8e6ee5d90a100d6125bfac8
1 #include "assets.h"
2 #include "defaults.h"
3 #include "bcprogressbox.h"
4 #include "filesystem.h"
5 #include "indexfile.h"
6 #include "loadfile.h"
7 #include "guicast.h"
8 #include "mwindow.h"
9 #include "mwindowgui.h"
10 #include "threadindexer.h"
12 #include <string.h>
14 #include <libintl.h>
15 #define _(String) gettext(String)
16 #define gettext_noop(String) String
17 #define N_(String) gettext_noop (String)
22 ThreadIndexer::ThreadIndexer(MWindow *mwindow, Assets *assets)
23  : Thread()
25         this->mwindow = mwindow;
26         this->assets = assets;
27         set_synchronous(0);
28         indexfile = new IndexFile(mwindow);
31 ThreadIndexer::~ThreadIndexer()
33         delete indexfile;
36 int ThreadIndexer::start_build()
38         interrupt_lock.lock();
39         interrupt_flag = 0;
40         start();
43 // build all here to allow editing during build
44 void ThreadIndexer::run()
46 // check locations of each asset
47         FILE *test_file;
48         Asset *current_asset;
49         char new_filename[1024], old_filename[1024];
50         int result = 0;
51         BC_ProgressBox *progress = 0;
53         for(current_asset = assets->first; current_asset; current_asset = current_asset->next)
54         {
55                 if(!(test_file = fopen(current_asset->path, "rb")))
56                 {
57 // file doesn't exist
58                         strcpy(old_filename, current_asset->path);
60                         result = 1;
61 // get location from user
62                         char directory[1024];
63                         sprintf(directory, "~");
64                         mwindow->defaults->get("DIRECTORY", directory);
66                         char string[1024], name[1024];
67                         FileSystem dir;
68                         dir.extract_name(name, old_filename);
69                         sprintf(string, _("Where is %s?"), name);
71                         LocateFileWindow window(mwindow, directory, string);
72                         window.create_objects();
73                         int result2 = window.run_window();
75                         mwindow->defaults->update("DIRECTORY", window.get_path());
77                         if(result2 == 1 )
78                         {
79                                 strcpy(new_filename, SILENCE);
80                         }
81                         else
82                         {
83                                 strcpy(new_filename, window.get_path());
84                         }
86 // update assets containing old location
87                         assets->update_old_filename(old_filename, new_filename);
88                 }
89                 else
90                 {
91                         fclose(test_file);
92                 }
93         }
96 // test index of each asset
97         for(current_asset = assets->first; 
98                 current_asset && !interrupt_flag; 
99                 current_asset = current_asset->next)
100         {
101 // test for an index file already built before creating progress bar
102                 if(current_asset->index_status == INDEX_NOTTESTED && 
103                         current_asset->audio_data)
104                 {
105                         if(indexfile->open_index(mwindow, current_asset))
106                         {
107 // doesn't exist
108 // try to create now
109                                 if(!progress)
110                                 {
111                                         progress = new BC_ProgressBox(mwindow->gui->get_abs_cursor_x(),
112                                                 mwindow->gui->get_abs_cursor_y(),
113                                                 _("Building Indexes..."), 
114                                                 1);
115                                         progress->start();
116                                 }
118 //                              indexfile->create_index(mwindow, current_asset, progress);
119                                 if(progress->is_cancelled()) interrupt_flag = 1;
120                         }
121                         else
122                         {
123                                 if(current_asset->index_status == 1) current_asset->index_status = 0;   // index has been tested
124                                 indexfile->close_index();
125                         }
126                 }
127         }
129         if(progress)     // progress box is only createdd when an index is built
130         {       
131                 progress->stop_progress();
132                 delete progress;
133                 progress = 0;
134         }
136         interrupt_lock.unlock();
139 int ThreadIndexer::interrupt_build()
141         interrupt_flag = 1;
142         indexfile->interrupt_index();
143         interrupt_lock.lock();
144         interrupt_lock.unlock();