mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
opt: refactor code in articleview (#1888)
Some checks are pending
SonarCloud / Build and analyze (push) Waiting to run
Some checks are pending
SonarCloud / Build and analyze (push) Waiting to run
refactor code --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
6b33178829
commit
3909b59d9f
|
@ -291,7 +291,8 @@ enum Feature {
|
|||
/// No features
|
||||
NoFeatures = 0,
|
||||
/// The dictionary is suitable to query when searching for compound expressions.
|
||||
SuitableForCompoundSearching = 1
|
||||
SuitableForCompoundSearching = 1,
|
||||
WebSite = 2
|
||||
};
|
||||
|
||||
Q_DECLARE_FLAGS( Features, Feature )
|
||||
|
|
|
@ -81,6 +81,11 @@ public:
|
|||
|
||||
void isolateWebCSS( QString & css );
|
||||
|
||||
Features getFeatures() const noexcept override
|
||||
{
|
||||
return Dictionary::WebSite;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void loadIcon() noexcept override;
|
||||
|
|
|
@ -341,13 +341,9 @@ void ArticleView::showDefinition( QString const & word,
|
|||
|
||||
if ( contexts.size() ) {
|
||||
QBuffer buf;
|
||||
|
||||
buf.open( QIODevice::WriteOnly );
|
||||
|
||||
QDataStream stream( &buf );
|
||||
|
||||
stream << contexts;
|
||||
|
||||
buf.close();
|
||||
|
||||
Utils::Url::addQueryItem( req, "contexts", QString::fromLatin1( buf.buffer().toBase64() ) );
|
||||
|
@ -785,39 +781,10 @@ bool ArticleView::eventFilter( QObject * obj, QEvent * ev )
|
|||
|
||||
QString ArticleView::getMutedForGroup( unsigned group )
|
||||
{
|
||||
if ( dictionaryBarToggled && dictionaryBarToggled->isChecked() ) {
|
||||
// Dictionary bar is active -- mute the muted dictionaries
|
||||
Instances::Group const * groupInstance = dictionaryGroup->getGroupById( group );
|
||||
|
||||
// Find muted dictionaries for current group
|
||||
Config::Group const * grp = cfg.getGroup( group );
|
||||
Config::MutedDictionaries const * mutedDictionaries;
|
||||
if ( group == Instances::Group::AllGroupId ) {
|
||||
mutedDictionaries = popupView ? &cfg.popupMutedDictionaries : &cfg.mutedDictionaries;
|
||||
}
|
||||
else {
|
||||
mutedDictionaries = grp ? ( popupView ? &grp->popupMutedDictionaries : &grp->mutedDictionaries ) : nullptr;
|
||||
}
|
||||
if ( !mutedDictionaries ) {
|
||||
return {};
|
||||
}
|
||||
|
||||
QStringList mutedDicts;
|
||||
|
||||
if ( groupInstance ) {
|
||||
for ( const auto & dictionarie : groupInstance->dictionaries ) {
|
||||
QString id = QString::fromStdString( dictionarie->getId() );
|
||||
|
||||
if ( mutedDictionaries->contains( id ) ) {
|
||||
mutedDicts.append( id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto mutedDicts = getMutedDictionaries( group );
|
||||
if ( !mutedDicts.empty() ) {
|
||||
return mutedDicts.join( "," );
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -1013,14 +980,6 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, QString const &
|
|||
QString( "window.location = \"%1\"" ).arg( QString::fromUtf8( url.toEncoded() ) ) );
|
||||
}
|
||||
else {
|
||||
if ( Utils::Url::hasQueryItem( ref, "dictionaries" ) ) {
|
||||
// Specific dictionary group from full-text search
|
||||
QStringList dictsList = Utils::Url::queryItemValue( ref, "dictionaries" ).split( ",", Qt::SkipEmptyParts );
|
||||
|
||||
showDefinition( url.path().mid( 1 ), dictsList, getGroup( ref ), false );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( Utils::Url::hasQueryItem( url, "dictionaries" ) ) {
|
||||
// Specific dictionary group from full-text search
|
||||
QStringList dictsList = Utils::Url::queryItemValue( url, "dictionaries" ).split( ",", Qt::SkipEmptyParts );
|
||||
|
@ -1135,16 +1094,15 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, QString const &
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void ArticleView::playAudio( QUrl const & url )
|
||||
{
|
||||
audioPlayer->stop();
|
||||
qDebug() << "play audio,the link url:" << url;
|
||||
qDebug() << "play audio [url]:" << url;
|
||||
|
||||
if ( url.scheme() == "bres" || url.scheme() == "gdau" || url.scheme() == "gdvideo"
|
||||
|| Utils::Url::isAudioUrl( url ) ) {
|
||||
// Download it
|
||||
|
||||
// Download it
|
||||
if ( Utils::Url::isWebAudioUrl( url ) ) {
|
||||
sptr< Dictionary::DataRequest > req = std::make_shared< Dictionary::WebMultimediaDownload >( url, articleNetMgr );
|
||||
|
||||
|
|
Loading…
Reference in a new issue