Add request cancellation

This commit is contained in:
Abs62 2011-12-12 20:52:07 +04:00
parent 07a8734bca
commit 5e49c32b53
3 changed files with 29 additions and 5 deletions

View file

@ -285,7 +285,7 @@ ArticleRequest::ArticleRequest(
sptr< Dictionary::WordSearchRequest > s = activeDicts[ x ]->findHeadwordsForSynonym( gd::toWString( word ) );
connect( s.get(), SIGNAL( finished() ),
this, SLOT( altSearchFinished() ) );
this, SLOT( altSearchFinished() ), Qt::QueuedConnection );
altSearches.push_back( s );
}
@ -338,7 +338,7 @@ void ArticleRequest::altSearchFinished()
gd::toWString( contexts.value( QString::fromStdString( activeDicts[ x ]->getId() ) ) ) );
connect( r.get(), SIGNAL( finished() ),
this, SLOT( bodyFinished() ) );
this, SLOT( bodyFinished() ), Qt::QueuedConnection );
bodyRequests.push_back( r );
}
@ -812,3 +812,27 @@ std::string ArticleRequest::escapeSpacing( QString const & str )
return spacing.data();
}
void ArticleRequest::cancel()
{
if( isFinished() )
return;
if( !altSearches.empty() )
{
for( list< sptr< Dictionary::WordSearchRequest > >::iterator i =
altSearches.begin(); i != altSearches.end(); ++i )
{
(*i)->cancel();
}
}
if( !bodyRequests.empty() )
{
for( list< sptr< Dictionary::DataRequest > >::iterator i =
bodyRequests.begin(); i != bodyRequests.end(); ++i )
{
(*i)->cancel();
}
}
if( stemmedWordFinder.get() ) stemmedWordFinder->cancel();
finish();
}

View file

@ -110,8 +110,8 @@ public:
std::vector< sptr< Dictionary::Class > > const & activeDicts,
std::string const & header );
virtual void cancel()
{ finish(); } // Add our own requests cancellation here
virtual void cancel();
// { finish(); } // Add our own requests cancellation here
private slots:

View file

@ -24,7 +24,7 @@ WordFinder::WordFinder( QObject * parent ):
updateResultsTimer.setSingleShot( true );
connect( &updateResultsTimer, SIGNAL( timeout() ),
this, SLOT( updateResults() ) );
this, SLOT( updateResults() ), Qt::QueuedConnection );
}
WordFinder::~WordFinder()