193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
194 // ============================================================================= |
194 // ============================================================================= |
195 void FileLoader::start() { |
195 void FileLoader::start() { |
196 setDone( false ); |
196 setDone( false ); |
197 setProgress( 0 ); |
197 setProgress( 0 ); |
198 abortflag = false; |
198 setAborted( false ); |
199 |
199 |
200 if( concurrent() ) { |
200 if( concurrent() ) { |
|
201 g_aborted = false; |
|
202 |
201 // Show a progress dialog if we're loading the main file here and move |
203 // Show a progress dialog if we're loading the main file here and move |
202 // the actual work to a separate thread as this can be a rather intensive |
204 // the actual work to a separate thread as this can be a rather intensive |
203 // operation and if we don't respond quickly enough, the program can be |
205 // operation and if we don't respond quickly enough, the program can be |
204 // deemed inresponsive.. which is a bad thing. |
206 // deemed inresponsive.. which is a bad thing. |
205 dlg = new OpenProgressDialog (g_win); |
207 dlg = new OpenProgressDialog (g_win); |
206 dlg->setNumLines( lines().size() ); |
208 dlg->setNumLines( lines().size() ); |
207 dlg->setModal( true ); |
209 dlg->setModal( true ); |
208 dlg->show(); |
210 dlg->show(); |
209 |
211 |
210 // Connect the loader in so we can show updates |
212 // Connect the loader in so we can show updates |
211 connect( this, SIGNAL( workDone() ), dlg, SLOT( accept() )); } |
213 connect( this, SIGNAL( workDone() ), dlg, SLOT( accept() )); |
212 else |
214 connect( dlg, SIGNAL( rejected() ), this, SLOT( abort() )); |
|
215 } else |
213 dlg = null; |
216 dlg = null; |
214 |
217 |
215 work( 0 ); |
218 work( 0 ); |
216 } |
219 } |
217 |
220 |
218 void FileLoader::work( ulong i ) { |
221 void FileLoader::work( ulong i ) { |
219 print( "%1: %2\n", this, i ); |
222 if( aborted() ) { |
220 |
|
221 if( abortflag ) { |
|
222 // We were flagged for abortion, so abort. |
223 // We were flagged for abortion, so abort. |
223 for( LDObject* obj : m_objs ) |
224 for( LDObject* obj : m_objs ) |
224 delete obj; |
225 delete obj; |
225 |
226 |
226 m_objs.clear(); |
227 m_objs.clear(); |
227 abortflag = false; |
228 setDone( true ); |
228 return; |
229 return; |
229 } |
230 } |
230 |
231 |
231 ulong max = i + 300; |
232 ulong max = i + 300; |
232 for( ; i < max && i < lines().size(); ++i ) { |
233 for( ; i < max && i < lines().size(); ++i ) { |
263 else |
264 else |
264 work( i + 1 ); |
265 work( i + 1 ); |
265 } |
266 } |
266 } |
267 } |
267 |
268 |
|
269 void FileLoader::abort() { |
|
270 setAborted( true ); |
|
271 |
|
272 if( concurrent() ) |
|
273 g_aborted = true; |
|
274 } |
|
275 |
268 // ============================================================================= |
276 // ============================================================================= |
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
270 // ============================================================================= |
278 // ============================================================================= |
271 vector<LDObject*> loadFileContents (File* f, ulong* numWarnings, bool* ok) { |
279 vector<LDObject*> loadFileContents (File* f, ulong* numWarnings, bool* ok) { |
272 vector<str> lines; |
280 vector<str> lines; |
273 vector<LDObject*> objs; |
281 vector<LDObject*> objs; |
274 g_aborted = false; |
|
275 |
282 |
276 if( numWarnings ) |
283 if( numWarnings ) |
277 *numWarnings = 0; |
284 *numWarnings = 0; |
278 |
285 |
279 // Calculate the amount of lines |
286 // Calculate the amount of lines |
290 while( loader->done() == false ) |
297 while( loader->done() == false ) |
291 qApp->processEvents(); |
298 qApp->processEvents(); |
292 |
299 |
293 // If we wanted the success value, supply that now |
300 // If we wanted the success value, supply that now |
294 if( ok ) |
301 if( ok ) |
295 *ok = loader->done(); |
302 *ok = !loader->aborted(); |
296 |
303 |
297 objs = loader->objs(); |
304 objs = loader->objs(); |
298 return objs; |
305 return objs; |
299 } |
306 } |
300 |
307 |