3 #include "bcprogressbox.h"
4 #include "filesystem.h"
9 #include "mwindowgui.h"
10 #include "threadindexer.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)
25 this->mwindow = mwindow;
26 this->assets = assets;
28 indexfile = new IndexFile(mwindow);
31 ThreadIndexer::~ThreadIndexer()
36 int ThreadIndexer::start_build()
38 interrupt_lock.lock();
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", window.get_path());
79 strcpy(new_filename, SILENCE);
83 strcpy(new_filename, window.get_path());
86 // update assets containing old location
87 assets->update_old_filename(old_filename, new_filename);
96 // test index of each asset
97 for(current_asset = assets->first;
98 current_asset && !interrupt_flag;
99 current_asset = current_asset->next)
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)
105 if(indexfile->open_index(mwindow, current_asset))
111 progress = new BC_ProgressBox(mwindow->gui->get_abs_cursor_x(),
112 mwindow->gui->get_abs_cursor_y(),
113 _("Building Indexes..."),
118 // indexfile->create_index(mwindow, current_asset, progress);
119 if(progress->is_cancelled()) interrupt_flag = 1;
123 if(current_asset->index_status == 1) current_asset->index_status = 0; // index has been tested
124 indexfile->close_index();
129 if(progress) // progress box is only createdd when an index is built
131 progress->stop_progress();
136 interrupt_lock.unlock();
139 int ThreadIndexer::interrupt_build()
142 indexfile->interrupt_index();
143 interrupt_lock.lock();
144 interrupt_lock.unlock();