mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
*! Fix problems handling audio gdau searches when there are no groups.
*! If article network manager fails to get the requested resource, check that and don't crash.
This commit is contained in:
parent
d1377e28bd
commit
dae521a262
|
@ -181,7 +181,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref )
|
||||||
|
|
||||||
resourceDownloadUrl = url;
|
resourceDownloadUrl = url;
|
||||||
|
|
||||||
if ( url.scheme() == "gdau" && url.host() == "search" && groups.size() )
|
if ( url.scheme() == "gdau" && url.host() == "search" )
|
||||||
{
|
{
|
||||||
// Since searches should be limited to current group, we just do them
|
// Since searches should be limited to current group, we just do them
|
||||||
// here ourselves since otherwise we'd need to pass group id to netmgr
|
// here ourselves since otherwise we'd need to pass group id to netmgr
|
||||||
|
@ -189,36 +189,47 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref )
|
||||||
|
|
||||||
unsigned currentGroup = getGroup( ref );
|
unsigned currentGroup = getGroup( ref );
|
||||||
|
|
||||||
for( unsigned x = 0; x < groups.size(); ++x )
|
std::vector< sptr< Dictionary::Class > > const * activeDicts = 0;
|
||||||
if ( groups[ x ].id == currentGroup )
|
|
||||||
{
|
if ( groups.size() )
|
||||||
for( unsigned y = 0; y < groups[ x ].dictionaries.size(); ++y )
|
{
|
||||||
|
for( unsigned x = 0; x < groups.size(); ++x )
|
||||||
|
if ( groups[ x ].id == currentGroup )
|
||||||
{
|
{
|
||||||
sptr< Dictionary::DataRequest > req =
|
activeDicts = &( groups[ x ].dictionaries );
|
||||||
groups[ x ].dictionaries[ y ]->getResource(
|
break;
|
||||||
url.path().mid( 1 ).toUtf8().data() );
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
activeDicts = &allDictionaries;
|
||||||
|
|
||||||
if ( req->isFinished() && req->dataSize() >= 0 )
|
if ( activeDicts )
|
||||||
{
|
for( unsigned x = 0; x < activeDicts->size(); ++x )
|
||||||
// A request was instantly finished with success.
|
{
|
||||||
// If we've managed to spawn some lingering requests alrady,
|
sptr< Dictionary::DataRequest > req =
|
||||||
// erase them.
|
(*activeDicts)[ x ]->getResource(
|
||||||
resourceDownloadRequests.clear();
|
url.path().mid( 1 ).toUtf8().data() );
|
||||||
|
|
||||||
// Handle the result
|
if ( req->isFinished() && req->dataSize() >= 0 )
|
||||||
resourceDownloadRequests.push_back( req );
|
{
|
||||||
resourceDownloadFinished();
|
// A request was instantly finished with success.
|
||||||
|
// If we've managed to spawn some lingering requests already,
|
||||||
|
// erase them.
|
||||||
|
resourceDownloadRequests.clear();
|
||||||
|
|
||||||
return;
|
// Handle the result
|
||||||
}
|
resourceDownloadRequests.push_back( req );
|
||||||
else
|
resourceDownloadFinished();
|
||||||
if ( !req->isFinished() )
|
|
||||||
{
|
|
||||||
resourceDownloadRequests.push_back( req );
|
|
||||||
|
|
||||||
connect( req.get(), SIGNAL( finished() ),
|
return;
|
||||||
this, SLOT( resourceDownloadFinished() ) );
|
}
|
||||||
}
|
else
|
||||||
|
if ( !req->isFinished() )
|
||||||
|
{
|
||||||
|
resourceDownloadRequests.push_back( req );
|
||||||
|
|
||||||
|
connect( req.get(), SIGNAL( finished() ),
|
||||||
|
this, SLOT( resourceDownloadFinished() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,6 +241,11 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref )
|
||||||
sptr< Dictionary::DataRequest > req =
|
sptr< Dictionary::DataRequest > req =
|
||||||
articleNetMgr.getResource( url, contentType );
|
articleNetMgr.getResource( url, contentType );
|
||||||
|
|
||||||
|
if ( !req.get() )
|
||||||
|
{
|
||||||
|
// Request failed, fail
|
||||||
|
}
|
||||||
|
else
|
||||||
if ( req->isFinished() && req->dataSize() >= 0 )
|
if ( req->isFinished() && req->dataSize() >= 0 )
|
||||||
{
|
{
|
||||||
// Have data ready, handle it
|
// Have data ready, handle it
|
||||||
|
@ -257,6 +273,8 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref )
|
||||||
QMessageBox::critical( this, tr( "GoldenDict" ), tr( "The referenced resource doesn't exist." ) );
|
QMessageBox::critical( this, tr( "GoldenDict" ), tr( "The referenced resource doesn't exist." ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
resourceDownloadFinished(); // Check any requests finished already
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if ( url.scheme() == "http" || url.scheme() == "https" ||
|
if ( url.scheme() == "http" || url.scheme() == "https" ||
|
||||||
|
|
Loading…
Reference in a new issue