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;
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" )
{
@ -1357,8 +1357,14 @@ vector< ResourceToSaveHandler * > ArticleView::saveResource( const QUrl & url, c
req = (*activeDicts)[ x ]->getResource(
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 );
if( req.get()->isFinished() && req.get()->dataSize() > 0 )
{
// A request was instantly finished with success. Stop search.
return handlers;
}
}
catch( std::exception & e )
{
@ -2743,10 +2749,11 @@ QString ArticleView::wordAtPoint( int x, int y )
ResourceToSaveHandler::ResourceToSaveHandler(
ArticleView * view, sptr< Dictionary::DataRequest > req,
QString const & fileName ) :
QString const & fileName, bool search ) :
QObject( view ),
req( req ),
fileName( fileName )
fileName( fileName ),
search_req( search )
{
connect( this, SIGNAL( statusBarMessage( QString, int, QPixmap ) ),
view, SIGNAL( statusBarMessage( QString, int, QPixmap ) ) );
@ -2796,11 +2803,14 @@ void ResourceToSaveHandler::downloadFinished()
}
}
else
{
if( !search_req )
{
emit statusBarMessage(
tr( "ERROR: %1" ).arg( tr( "The referenced resource failed to download." ) ),
10000, QPixmap( ":/icons/error.png" ) );
}
}
emit done();
deleteLater();

View file

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