From 5e49c32b5339b1b6dbade18948a6b1203ad4f79b Mon Sep 17 00:00:00 2001 From: Abs62 Date: Mon, 12 Dec 2011 20:52:07 +0400 Subject: [PATCH] Add request cancellation --- article_maker.cc | 28 ++++++++++++++++++++++++++-- article_maker.hh | 4 ++-- wordfinder.cc | 2 +- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/article_maker.cc b/article_maker.cc index b249bd9b..91ce4d2f 100644 --- a/article_maker.cc +++ b/article_maker.cc @@ -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(); +} diff --git a/article_maker.hh b/article_maker.hh index 87737f3e..6aa66637 100644 --- a/article_maker.hh +++ b/article_maker.hh @@ -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: diff --git a/wordfinder.cc b/wordfinder.cc index 5e9c070c..c28b1af4 100644 --- a/wordfinder.cc +++ b/wordfinder.cc @@ -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()