1. Don't show "failed to download" error message while saving resources like "gdau://search/..."

2. Stop search if resource is found
This commit is contained in:
Abs62 2017-04-27 18:04:26 +03:00
parent 9beaf862e8
commit 2085314eb9
2 changed files with 19 additions and 8 deletions

View file

@ -1324,7 +1324,7 @@ vector< ResourceToSaveHandler * > ArticleView::saveResource( const QUrl & url, c
vector< ResourceToSaveHandler * > handlers; vector< ResourceToSaveHandler * > handlers;
sptr< Dictionary::DataRequest > req; sptr< Dictionary::DataRequest > req;
if( url.scheme() == "bres" || url.scheme() == "gico" || url.scheme() == "gdau") if( url.scheme() == "bres" || url.scheme() == "gico" || url.scheme() == "gdau" )
{ {
if ( url.host() == "search" ) if ( url.host() == "search" )
{ {
@ -1357,8 +1357,14 @@ vector< ResourceToSaveHandler * > ArticleView::saveResource( const QUrl & url, c
req = (*activeDicts)[ x ]->getResource( req = (*activeDicts)[ x ]->getResource(
Qt4x5::Url::path( url ).mid( 1 ).toUtf8().data() ); Qt4x5::Url::path( url ).mid( 1 ).toUtf8().data() );
ResourceToSaveHandler * handler = new ResourceToSaveHandler( this, req, fileName ); ResourceToSaveHandler * handler = new ResourceToSaveHandler( this, req, fileName, true );
handlers.push_back( handler ); handlers.push_back( handler );
if( req.get()->isFinished() && req.get()->dataSize() > 0 )
{
// A request was instantly finished with success. Stop search.
return handlers;
}
} }
catch( std::exception & e ) catch( std::exception & e )
{ {
@ -2743,10 +2749,11 @@ QString ArticleView::wordAtPoint( int x, int y )
ResourceToSaveHandler::ResourceToSaveHandler( ResourceToSaveHandler::ResourceToSaveHandler(
ArticleView * view, sptr< Dictionary::DataRequest > req, ArticleView * view, sptr< Dictionary::DataRequest > req,
QString const & fileName ) : QString const & fileName, bool search ) :
QObject( view ), QObject( view ),
req( req ), req( req ),
fileName( fileName ) fileName( fileName ),
search_req( search )
{ {
connect( this, SIGNAL( statusBarMessage( QString, int, QPixmap ) ), connect( this, SIGNAL( statusBarMessage( QString, int, QPixmap ) ),
view, SIGNAL( statusBarMessage( QString, int, QPixmap ) ) ); view, SIGNAL( statusBarMessage( QString, int, QPixmap ) ) );
@ -2797,9 +2804,12 @@ void ResourceToSaveHandler::downloadFinished()
} }
else else
{ {
emit statusBarMessage( if( !search_req )
tr( "ERROR: %1" ).arg( tr( "The referenced resource failed to download." ) ), {
10000, QPixmap( ":/icons/error.png" ) ); emit statusBarMessage(
tr( "ERROR: %1" ).arg( tr( "The referenced resource failed to download." ) ),
10000, QPixmap( ":/icons/error.png" ) );
}
} }
emit done(); emit done();

View file

@ -366,7 +366,7 @@ class ResourceToSaveHandler: public QObject
public: public:
explicit ResourceToSaveHandler( ArticleView * view, sptr< Dictionary::DataRequest > req, explicit ResourceToSaveHandler( ArticleView * view, sptr< Dictionary::DataRequest > req,
QString const & fileName ); QString const & fileName, bool search = false );
signals: signals:
void done(); void done();
@ -378,6 +378,7 @@ private slots:
private: private:
sptr< Dictionary::DataRequest > req; sptr< Dictionary::DataRequest > req;
QString fileName; QString fileName;
bool search_req;
}; };
#endif #endif