r1053: Add Russian translation.
[cinelerra_cv.git] / cinelerra / threadindexer.C
blob4f5b88761ce736d8a9d3a8d9cb88a0144dacb0ec
1 #include "asset.h"
2 #include "assets.h"
3 #include "bcprogressbox.h"
4 #include "condition.h"
5 #include "bchash.h"
6 #include "filesystem.h"
7 #include "guicast.h"
8 #include "indexfile.h"
9 #include "language.h"
10 #include "loadfile.h"
11 #include "mwindowgui.h"
12 #include "mwindow.h"
13 #include "threadindexer.h"
15 #include <string.h>
21 ThreadIndexer::ThreadIndexer(MWindow *mwindow, Assets *assets)
22  : Thread()
24         this->mwindow = mwindow;
25         this->assets = assets;
26         set_synchronous(0);
27         indexfile = new IndexFile(mwindow);
28         interrupt_lock = new Condition(0, "ThreadIndexer::ThreadIndexer");
31 ThreadIndexer::~ThreadIndexer()
33         delete indexfile;
34         delete interrupt_lock;
37 int ThreadIndexer::start_build()
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", 
76                                 window.get_submitted_path());
78                         if(result2 == 1)
79                         {
80                                 strcpy(new_filename, SILENCE);
81                         }
82                         else
83                         {
84                                 strcpy(new_filename, 
85                                         window.get_submitted_path());
86                         }
88 // update assets containing old location
89                         assets->update_old_filename(old_filename, new_filename);
90                 }
91                 else
92                 {
93                         fclose(test_file);
94                 }
95         }
98 // test index of each asset
99         for(current_asset = assets->first; 
100                 current_asset && !interrupt_flag; 
101                 current_asset = current_asset->next)
102         {
103 // test for an index file already built before creating progress bar
104                 if(current_asset->index_status == INDEX_NOTTESTED && 
105                         current_asset->audio_data)
106                 {
107                         if(indexfile->open_index(mwindow, current_asset))
108                         {
109 // doesn't exist
110 // try to create now
111                                 if(!progress)
112                                 {
113                                         progress = new BC_ProgressBox(mwindow->gui->get_abs_cursor_x(1),
114                                                 mwindow->gui->get_abs_cursor_y(1),
115                                                 _("Building Indexes..."), 
116                                                 1);
117                                         progress->start();
118                                 }
120 //                              indexfile->create_index(mwindow, current_asset, progress);
121                                 if(progress->is_cancelled()) interrupt_flag = 1;
122                         }
123                         else
124                         {
125                                 if(current_asset->index_status == 1) current_asset->index_status = 0;   // index has been tested
126                                 indexfile->close_index();
127                         }
128                 }
129         }
131         if(progress)     // progress box is only createdd when an index is built
132         {       
133                 progress->stop_progress();
134                 delete progress;
135                 progress = 0;
136         }
138         interrupt_lock->unlock();
141 int ThreadIndexer::interrupt_build()
143         interrupt_flag = 1;
144         indexfile->interrupt_index();
145         interrupt_lock->lock(" ThreadIndexer::interrupt_build");
146         interrupt_lock->unlock();