3 #include "bcprogressbox.h"
6 #include "filesystem.h"
11 #include "mwindowgui.h"
13 #include "threadindexer.h"
21 ThreadIndexer::ThreadIndexer(MWindow *mwindow, Assets *assets)
24 this->mwindow = mwindow;
25 this->assets = assets;
27 indexfile = new IndexFile(mwindow);
28 interrupt_lock = new Condition(0, "ThreadIndexer::ThreadIndexer");
31 ThreadIndexer::~ThreadIndexer()
34 delete interrupt_lock;
37 int ThreadIndexer::start_build()
43 // build all here to allow editing during build
44 void ThreadIndexer::run()
46 // check locations of each asset
49 char new_filename[1024], old_filename[1024];
51 BC_ProgressBox *progress = 0;
53 for(current_asset = assets->first; current_asset; current_asset = current_asset->next)
55 if(!(test_file = fopen(current_asset->path, "rb")))
58 strcpy(old_filename, current_asset->path);
61 // get location from user
63 sprintf(directory, "~");
64 mwindow->defaults->get("DIRECTORY", directory);
66 char string[1024], name[1024];
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());
80 strcpy(new_filename, SILENCE);
85 window.get_submitted_path());
88 // update assets containing old location
89 assets->update_old_filename(old_filename, new_filename);
98 // test index of each asset
99 for(current_asset = assets->first;
100 current_asset && !interrupt_flag;
101 current_asset = current_asset->next)
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)
107 if(indexfile->open_index(mwindow, current_asset))
113 progress = new BC_ProgressBox(mwindow->gui->get_abs_cursor_x(1),
114 mwindow->gui->get_abs_cursor_y(1),
115 _("Building Indexes..."),
120 // indexfile->create_index(mwindow, current_asset, progress);
121 if(progress->is_cancelled()) interrupt_flag = 1;
125 if(current_asset->index_status == 1) current_asset->index_status = 0; // index has been tested
126 indexfile->close_index();
131 if(progress) // progress box is only createdd when an index is built
133 progress->stop_progress();
138 interrupt_lock->unlock();
141 int ThreadIndexer::interrupt_build()
144 indexfile->interrupt_index();
145 interrupt_lock->lock(" ThreadIndexer::interrupt_build");
146 interrupt_lock->unlock();