4 #include "filesystem.h"
8 #include "mainindexes.h"
9 #include "mainprogress.h"
11 #include "mwindowgui.h"
16 #define _(String) gettext(String)
17 #define gettext_noop(String) String
18 #define N_(String) gettext_noop (String)
20 MainIndexes::MainIndexes(MWindow *mwindow)
23 this->mwindow = mwindow;
27 indexfile = new IndexFile(mwindow);
30 MainIndexes::~MainIndexes()
35 void MainIndexes::add_next_asset(Asset *asset)
40 IndexFile indexfile(mwindow);
42 //printf("MainIndexes::add_next_asset 1 %s\n", asset->path);
43 if(!indexfile.open_index(asset))
45 //printf("MainIndexes::add_next_asset 2\n");
46 asset->index_status = INDEX_READY;
47 indexfile.close_index();
50 // Put copy of asset in stack, not the real thing.
52 //printf("MainIndexes::add_next_asset 3\n");
53 Asset *new_asset = new Asset;
55 // If the asset existed and was overwritten, the status will be READY.
56 new_asset->index_status = INDEX_NOTTESTED;
57 next_assets.append(new_asset);
63 void MainIndexes::delete_current_assets()
65 current_assets.remove_all_objects();
68 void MainIndexes::start_loop()
75 void MainIndexes::stop_loop()
83 void MainIndexes::start_build()
85 //printf("MainIndexes::start_build 1\n");
87 // Locked up when indexes were already being built and an asset was
89 // interrupt_lock.lock();
93 void MainIndexes::interrupt_build()
95 //printf("MainIndexes::interrupt_build 1\n");
97 indexfile->interrupt_index();
98 //printf("MainIndexes::interrupt_build 2\n");
99 interrupt_lock.lock();
100 //printf("MainIndexes::interrupt_build 3\n");
101 interrupt_lock.unlock();
102 //printf("MainIndexes::interrupt_build 4\n");
105 void MainIndexes::load_next_assets()
107 delete_current_assets();
109 // Transfer from new list
111 for(int i = 0; i < next_assets.total; i++)
112 current_assets.append(next_assets.values[i]);
114 // Clear pointers from new list only
115 next_assets.remove_all();
120 void MainIndexes::run()
124 // Wait for new assets to be released
128 //printf("MainIndexes::run 1 %d\n", next_assets.total);
131 //printf("MainIndexes::run 2 %d\n", current_assets.total);
138 // test index of each asset
139 MainProgressBar *progress = 0;
140 for(int i = 0; i < current_assets.total && !interrupt_flag; i++)
142 Asset *current_asset = current_assets.values[i];
143 //printf("MainIndexes::run 3 %s %d %d\n", current_asset->path, current_asset->index_status, current_asset->audio_data);
145 if(current_asset->index_status == INDEX_NOTTESTED &&
146 current_asset->audio_data)
148 //printf("MainIndexes::run 4\n");
152 // Try to create index now.
153 if(indexfile->open_index(current_asset))
155 //printf("MainIndexes::run 5 %p %s %p %p\n", current_asset, current_asset->path, mwindow, mwindow->mainprogress);
158 if(mwindow->gui) mwindow->gui->lock_window();
159 progress = mwindow->mainprogress->start_progress(_("Building Indexes..."), 1);
160 if(mwindow->gui) mwindow->gui->unlock_window();
163 //printf("MainIndexes::run 5 %p %s\n", current_asset, current_asset->path);
165 indexfile->create_index(current_asset, progress);
166 //printf("MainIndexes::run 6 %p %s\n", current_asset, current_asset->path);
167 if(progress->is_cancelled()) interrupt_flag = 1;
168 //printf("MainIndexes::run 7 %p %s\n", current_asset, current_asset->path);
171 // Exists. Update real thing.
173 //printf("MainIndexes::run 8\n");
174 if(current_asset->index_status == INDEX_NOTTESTED)
176 current_asset->index_status = INDEX_READY;
177 if(mwindow->gui) mwindow->gui->lock_window();
178 mwindow->edl->set_index_file(current_asset);
179 if(mwindow->gui) mwindow->gui->unlock_window();
181 indexfile->close_index();
185 //printf("MainIndexes::run 8\n");
187 //printf("MainIndexes::run 9\n");
189 //printf("MainIndexes::run 10\n");
191 if(progress) // progress box is only created when an index is built
193 if(mwindow->gui) mwindow->gui->lock_window();
194 progress->stop_progress();
196 if(mwindow->gui) mwindow->gui->unlock_window();
204 //printf("MainIndexes::run 11\n");
206 interrupt_lock.unlock();