# HG changeset patch # User Santeri Piippo # Date 1373410224 -10800 # Node ID e8ef9fb4721bfa5d28c06e5b10d69db54457bb96 # Parent 843b3dbbd84931c19c87bfb2067014f2a4e765fb make aborting work in the new setup diff -r 843b3dbbd849 -r e8ef9fb4721b src/file.cpp --- a/src/file.cpp Wed Jul 10 01:40:59 2013 +0300 +++ b/src/file.cpp Wed Jul 10 01:50:24 2013 +0300 @@ -195,9 +195,11 @@ void FileLoader::start() { setDone( false ); setProgress( 0 ); - abortflag = false; + setAborted( false ); if( concurrent() ) { + g_aborted = false; + // Show a progress dialog if we're loading the main file here and move // the actual work to a separate thread as this can be a rather intensive // operation and if we don't respond quickly enough, the program can be @@ -208,23 +210,22 @@ dlg->show(); // Connect the loader in so we can show updates - connect( this, SIGNAL( workDone() ), dlg, SLOT( accept() )); } - else + connect( this, SIGNAL( workDone() ), dlg, SLOT( accept() )); + connect( dlg, SIGNAL( rejected() ), this, SLOT( abort() )); + } else dlg = null; work( 0 ); } void FileLoader::work( ulong i ) { - print( "%1: %2\n", this, i ); - - if( abortflag ) { + if( aborted() ) { // We were flagged for abortion, so abort. for( LDObject* obj : m_objs ) delete obj; m_objs.clear(); - abortflag = false; + setDone( true ); return; } @@ -265,13 +266,19 @@ } } +void FileLoader::abort() { + setAborted( true ); + + if( concurrent() ) + g_aborted = true; +} + // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= vector loadFileContents (File* f, ulong* numWarnings, bool* ok) { vector lines; vector objs; - g_aborted = false; if( numWarnings ) *numWarnings = 0; @@ -292,7 +299,7 @@ // If we wanted the success value, supply that now if( ok ) - *ok = loader->done(); + *ok = !loader->aborted(); objs = loader->objs(); return objs; diff -r 843b3dbbd849 -r e8ef9fb4721b src/file.h --- a/src/file.h Wed Jul 10 01:40:59 2013 +0300 +++ b/src/file.h Wed Jul 10 01:50:24 2013 +0300 @@ -154,13 +154,14 @@ READ_PROPERTY( vector, objs, setObjects ) READ_PROPERTY( bool, done, setDone ) READ_PROPERTY( ulong, progress, setProgress ) + READ_PROPERTY( bool, aborted, setAborted ) PROPERTY( vector, lines, setLines ) PROPERTY( ulong*, warningsPointer, setWarningsPointer ) PROPERTY( bool, concurrent, setConcurrent ) -public: - bool abortflag; +public slots: void start(); + void abort(); private: OpenProgressDialog* dlg;