4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "bcprogressbox.h"
25 #include "condition.h"
27 #include "filesystem.h"
29 #include "indexfile.h"
32 #include "mwindowgui.h"
34 #include "threadindexer.h"
38 // This doesn't appear to be used anymore.
43 ThreadIndexer::ThreadIndexer(MWindow *mwindow, Assets *assets)
46 this->mwindow = mwindow;
47 this->assets = assets;
49 indexfile = new IndexFile(mwindow);
50 interrupt_lock = new Condition(0, "ThreadIndexer::ThreadIndexer");
53 ThreadIndexer::~ThreadIndexer()
56 delete interrupt_lock;
59 void ThreadIndexer::start_build()
65 // build all here to allow editing during build
66 void ThreadIndexer::run()
68 // check locations of each asset
71 char new_filename[1024], old_filename[1024];
73 BC_ProgressBox *progress = 0;
75 for(current_asset = assets->first; current_asset; current_asset = current_asset->next)
77 if(!(test_file = fopen(current_asset->path, "rb")))
80 strcpy(old_filename, current_asset->path);
83 // get location from user
85 sprintf(directory, "~");
86 mwindow->defaults->get("DIRECTORY", directory);
88 char string[1024], name[1024];
90 dir.extract_name(name, old_filename);
91 sprintf(string, _("Where is %s?"), name);
93 LocateFileWindow window(mwindow, directory, string);
94 window.create_objects();
95 int result2 = window.run_window();
97 mwindow->defaults->update("DIRECTORY",
98 window.get_submitted_path());
107 window.get_submitted_path());
110 // update assets containing old location
111 assets->update_old_filename(old_filename, new_filename);
120 // test index of each asset
121 for(current_asset = assets->first;
122 current_asset && !interrupt_flag;
123 current_asset = current_asset->next)
125 // test for an index file already built before creating progress bar
126 if(current_asset->index_status == INDEX_NOTTESTED &&
127 current_asset->audio_data)
129 if(indexfile->open_index(mwindow, current_asset))
135 progress = new BC_ProgressBox(mwindow->gui->get_abs_cursor_x(1),
136 mwindow->gui->get_abs_cursor_y(1),
137 _("Building Indexes..."),
142 // indexfile->create_index(current_asset, 0, progress);
143 if(progress->is_cancelled()) interrupt_flag = 1;
147 if(current_asset->index_status == INDEX_NOTTESTED)
148 current_asset->index_status = INDEX_READY; // index has been tested
149 indexfile->close_index();
154 // progress box is only created when an index is built
157 progress->stop_progress();
162 interrupt_lock->unlock();
165 void ThreadIndexer::interrupt_build()
168 indexfile->interrupt_index();
169 interrupt_lock->lock(" ThreadIndexer::interrupt_build");
170 interrupt_lock->unlock();