diff --git a/src/article_netmgr.cc b/src/article_netmgr.cc index 720fe5bd..ee820eff 100644 --- a/src/article_netmgr.cc +++ b/src/article_netmgr.cc @@ -258,29 +258,25 @@ sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource( QUrl c contentType = mineType.name(); string id = url.host().toStdString(); - bool search = ( id == "search" ); - - if ( !search ) { - for ( const auto & dictionary : dictionaries ) { - if ( dictionary->getId() == id ) { - if ( url.scheme() == "gico" ) { - QByteArray bytes; - QBuffer buffer( &bytes ); - buffer.open( QIODevice::WriteOnly ); - dictionary->getIcon().pixmap( 64 ).save( &buffer, "PNG" ); - buffer.close(); - sptr< Dictionary::DataRequestInstant > ico = std::make_shared< Dictionary::DataRequestInstant >( true ); - ico->getData().resize( bytes.size() ); - memcpy( &( ico->getData().front() ), bytes.data(), bytes.size() ); - return ico; - } - try { - return dictionary->getResource( Utils::Url::path( url ).mid( 1 ).toUtf8().data() ); - } - catch ( std::exception & e ) { - gdWarning( "getResource request error (%s) in \"%s\"\n", e.what(), dictionary->getName().c_str() ); - return {}; - } + for ( const auto & dictionary : dictionaries ) { + if ( dictionary->getId() == id ) { + if ( url.scheme() == "gico" ) { + QByteArray bytes; + QBuffer buffer( &bytes ); + buffer.open( QIODevice::WriteOnly ); + dictionary->getIcon().pixmap( 64 ).save( &buffer, "PNG" ); + buffer.close(); + sptr< Dictionary::DataRequestInstant > ico = std::make_shared< Dictionary::DataRequestInstant >( true ); + ico->getData().resize( bytes.size() ); + memcpy( &( ico->getData().front() ), bytes.data(), bytes.size() ); + return ico; + } + try { + return dictionary->getResource( Utils::Url::path( url ).mid( 1 ).toUtf8().data() ); + } + catch ( std::exception & e ) { + gdWarning( "getResource request error (%s) in \"%s\"\n", e.what(), dictionary->getName().c_str() ); + return {}; } } } diff --git a/src/dict/dsl.cc b/src/dict/dsl.cc index 7dca49b4..ee001748 100644 --- a/src/dict/dsl.cc +++ b/src/dict/dsl.cc @@ -851,18 +851,11 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node ) string n = resourceDir1 + filename; if ( Filetype::isNameOfSound( filename ) ) { - // If we have the file here, do the exact reference to this dictionary. - // Otherwise, make a global 'search' one. - - bool search = !File::exists( n ) && !File::exists( resourceDir2 + filename ) - && !File::exists( getContainingFolder().toStdString() + Utils::Fs::separator() + filename ) - && ( !resourceZip.isOpen() || !resourceZip.hasFile( Utf8::decode( filename ) ) ); - QUrl url; url.setScheme( "gdau" ); - url.setHost( QString::fromUtf8( search ? "search" : getId().c_str() ) ); + url.setHost( QString::fromUtf8( getId().c_str() ) ); url.setPath( Utils::Url::ensureLeadingSlash( QString::fromUtf8( filename.c_str() ) ) ); - if ( search && idxHeader.hasSoundDictionaryName ) { + if ( idxHeader.hasSoundDictionaryName ) { Utils::Url::setFragment( url, QString::fromUtf8( preferredSoundDictionary.c_str() ) ); } diff --git a/src/dict/xdxf2html.cc b/src/dict/xdxf2html.cc index bb86ce7d..e3ce30c5 100644 --- a/src/dict/xdxf2html.cc +++ b/src/dict/xdxf2html.cc @@ -654,24 +654,9 @@ string convert( string const & in, QDomElement el_script = dd.createElement( "script" ); QDomNode parent = el.parentNode(); if ( !parent.isNull() ) { - bool search = false; - if ( type == STARDICT ) { - string n = dictPtr->getContainingFolder().toStdString() + Utils::Fs::separator() + string( "res" ) - + Utils::Fs::separator() + filename; - search = !File::exists( n ) - && ( !resourceZip || !resourceZip->isOpen() || !resourceZip->hasFile( Utf8::decode( filename ) ) ); - } - else { - string n = dictPtr->getDictionaryFilenames()[ 0 ] + ".files" + Utils::Fs::separator() + filename; - search = !File::exists( n ) - && !File::exists( dictPtr->getContainingFolder().toStdString() + Utils::Fs::separator() + filename ) - && ( !resourceZip || !resourceZip->isOpen() || !resourceZip->hasFile( Utf8::decode( filename ) ) ); - } - - QUrl url; url.setScheme( "gdau" ); - url.setHost( QString::fromUtf8( search ? "search" : dictPtr->getId().c_str() ) ); + url.setHost( QString::fromUtf8( dictPtr->getId().c_str() ) ); url.setPath( Utils::Url::ensureLeadingSlash( QString::fromUtf8( filename.c_str() ) ) ); el_script.setAttribute( "type", "text/javascript" ); diff --git a/src/ui/articleview.cc b/src/ui/articleview.cc index df32714d..5002748b 100644 --- a/src/ui/articleview.cc +++ b/src/ui/articleview.cc @@ -1050,79 +1050,6 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, QString const & connect( req.get(), &Dictionary::Request::finished, this, &ArticleView::resourceDownloadFinished ); } - else if ( url.scheme() == "gdau" && url.host() == "search" ) { - // 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 - // and it should've been having knowledge of the current groups, too. - - unsigned currentGroup = getGroup( ref ); - - std::vector< sptr< Dictionary::Class > > const * activeDicts = - dictionaryGroup->getActiveDictionaries( currentGroup ); - - if ( activeDicts ) { - unsigned preferred = UINT_MAX; - if ( url.hasFragment() ) { - // Find sound in the preferred dictionary - QString preferredName = Utils::Url::fragment( url ); - try { - for ( unsigned x = 0; x < activeDicts->size(); ++x ) { - if ( preferredName.compare( QString::fromUtf8( ( *activeDicts )[ x ]->getName().c_str() ) ) == 0 ) { - preferred = x; - sptr< Dictionary::DataRequest > req = - ( *activeDicts )[ x ]->getResource( url.path().mid( 1 ).toUtf8().data() ); - - resourceDownloadRequests.push_back( req ); - - if ( !req->isFinished() ) { - // Queued loading - connect( req.get(), &Dictionary::Request::finished, this, &ArticleView::resourceDownloadFinished ); - } - else { - // Immediate loading - if ( req->dataSize() > 0 ) { - // Resource already found, stop next search - resourceDownloadFinished(); - return; - } - } - break; - } - } - } - catch ( std::exception & e ) { - emit statusBarMessage( tr( "ERROR: %1" ).arg( e.what() ), 10000, QPixmap( ":/icons/error.svg" ) ); - } - } - for ( unsigned x = 0; x < activeDicts->size(); ++x ) { - try { - if ( x == preferred ) { - continue; - } - - sptr< Dictionary::DataRequest > req = - ( *activeDicts )[ x ]->getResource( url.path().mid( 1 ).toUtf8().data() ); - - resourceDownloadRequests.push_back( req ); - - if ( !req->isFinished() ) { - // Queued loading - connect( req.get(), &Dictionary::Request::finished, this, &ArticleView::resourceDownloadFinished ); - } - else { - // Immediate loading - if ( req->dataSize() > 0 ) { - // Resource already found, stop next search - break; - } - } - } - catch ( std::exception & e ) { - emit statusBarMessage( tr( "ERROR: %1" ).arg( e.what() ), 10000, QPixmap( ":/icons/error.svg" ) ); - } - } - } - } else { // Normal resource download QString contentType; @@ -1224,75 +1151,12 @@ ResourceToSaveHandler * ArticleView::saveResource( const QUrl & url, const QUrl sptr< Dictionary::DataRequest > req; if ( url.scheme() == "bres" || url.scheme() == "gico" || url.scheme() == "gdau" || url.scheme() == "gdvideo" ) { - if ( url.host() == "search" ) { - // 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 - // and it should've been having knowledge of the current groups, too. + // Normal resource download + QString contentType; + req = articleNetMgr.getResource( url, contentType ); - unsigned currentGroup = getGroup( ref ); - - std::vector< sptr< Dictionary::Class > > const * activeDicts = - dictionaryGroup->getActiveDictionaries( currentGroup ); - - if ( activeDicts ) { - unsigned preferred = UINT_MAX; - if ( url.hasFragment() && url.scheme() == "gdau" ) { - // Find sound in the preferred dictionary - QString preferredName = Utils::Url::fragment( url ); - for ( unsigned x = 0; x < activeDicts->size(); ++x ) { - try { - if ( preferredName.compare( QString::fromUtf8( ( *activeDicts )[ x ]->getName().c_str() ) ) == 0 ) { - preferred = x; - sptr< Dictionary::DataRequest > data_request = - ( *activeDicts )[ x ]->getResource( url.path().mid( 1 ).toUtf8().data() ); - - handler->addRequest( data_request ); - - if ( data_request->isFinished() && data_request->dataSize() > 0 ) { - handler->downloadFinished(); - return handler; - } - break; - } - } - catch ( std::exception & e ) { - gdWarning( "getResource request error (%s) in \"%s\"\n", - e.what(), - ( *activeDicts )[ x ]->getName().c_str() ); - } - } - } - for ( unsigned x = 0; x < activeDicts->size(); ++x ) { - try { - if ( x == preferred ) { - continue; - } - - req = ( *activeDicts )[ x ]->getResource( Utils::Url::path( url ).mid( 1 ).toUtf8().data() ); - - handler->addRequest( req ); - - if ( req->isFinished() && req->dataSize() > 0 ) { - // Resource already found, stop next search - break; - } - } - catch ( std::exception & e ) { - gdWarning( "getResource request error (%s) in \"%s\"\n", - e.what(), - ( *activeDicts )[ x ]->getName().c_str() ); - } - } - } - } - else { - // Normal resource download - QString contentType; - req = articleNetMgr.getResource( url, contentType ); - - if ( req.get() ) { - handler->addRequest( req ); - } + if ( req.get() ) { + handler->addRequest( req ); } } else {