mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-30 13:24: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
|
/// No features
|
||||||
NoFeatures = 0,
|
NoFeatures = 0,
|
||||||
/// The dictionary is suitable to query when searching for compound expressions.
|
/// The dictionary is suitable to query when searching for compound expressions.
|
||||||
SuitableForCompoundSearching = 1
|
SuitableForCompoundSearching = 1,
|
||||||
|
WebSite = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_FLAGS( Features, Feature )
|
Q_DECLARE_FLAGS( Features, Feature )
|
||||||
|
|
|
@ -81,6 +81,11 @@ public:
|
||||||
|
|
||||||
void isolateWebCSS( QString & css );
|
void isolateWebCSS( QString & css );
|
||||||
|
|
||||||
|
Features getFeatures() const noexcept override
|
||||||
|
{
|
||||||
|
return Dictionary::WebSite;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void loadIcon() noexcept override;
|
void loadIcon() noexcept override;
|
||||||
|
|
|
@ -341,13 +341,9 @@ void ArticleView::showDefinition( QString const & word,
|
||||||
|
|
||||||
if ( contexts.size() ) {
|
if ( contexts.size() ) {
|
||||||
QBuffer buf;
|
QBuffer buf;
|
||||||
|
|
||||||
buf.open( QIODevice::WriteOnly );
|
buf.open( QIODevice::WriteOnly );
|
||||||
|
|
||||||
QDataStream stream( &buf );
|
QDataStream stream( &buf );
|
||||||
|
|
||||||
stream << contexts;
|
stream << contexts;
|
||||||
|
|
||||||
buf.close();
|
buf.close();
|
||||||
|
|
||||||
Utils::Url::addQueryItem( req, "contexts", QString::fromLatin1( buf.buffer().toBase64() ) );
|
Utils::Url::addQueryItem( req, "contexts", QString::fromLatin1( buf.buffer().toBase64() ) );
|
||||||
|
@ -785,38 +781,9 @@ bool ArticleView::eventFilter( QObject * obj, QEvent * ev )
|
||||||
|
|
||||||
QString ArticleView::getMutedForGroup( unsigned group )
|
QString ArticleView::getMutedForGroup( unsigned group )
|
||||||
{
|
{
|
||||||
if ( dictionaryBarToggled && dictionaryBarToggled->isChecked() ) {
|
auto mutedDicts = getMutedDictionaries( group );
|
||||||
// Dictionary bar is active -- mute the muted dictionaries
|
if ( !mutedDicts.empty() ) {
|
||||||
Instances::Group const * groupInstance = dictionaryGroup->getGroupById( group );
|
return mutedDicts.join( "," );
|
||||||
|
|
||||||
// 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 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !mutedDicts.empty() ) {
|
|
||||||
return mutedDicts.join( "," );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
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() ) ) );
|
QString( "window.location = \"%1\"" ).arg( QString::fromUtf8( url.toEncoded() ) ) );
|
||||||
}
|
}
|
||||||
else {
|
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" ) ) {
|
if ( Utils::Url::hasQueryItem( url, "dictionaries" ) ) {
|
||||||
// Specific dictionary group from full-text search
|
// Specific dictionary group from full-text search
|
||||||
QStringList dictsList = Utils::Url::queryItemValue( url, "dictionaries" ).split( ",", Qt::SkipEmptyParts );
|
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 )
|
void ArticleView::playAudio( QUrl const & url )
|
||||||
{
|
{
|
||||||
audioPlayer->stop();
|
audioPlayer->stop();
|
||||||
qDebug() << "play audio,the link url:" << url;
|
qDebug() << "play audio [url]:" << url;
|
||||||
|
|
||||||
if ( url.scheme() == "bres" || url.scheme() == "gdau" || url.scheme() == "gdvideo"
|
if ( url.scheme() == "bres" || url.scheme() == "gdau" || url.scheme() == "gdvideo"
|
||||||
|| Utils::Url::isAudioUrl( url ) ) {
|
|| Utils::Url::isAudioUrl( url ) ) {
|
||||||
// Download it
|
|
||||||
|
|
||||||
|
// Download it
|
||||||
if ( Utils::Url::isWebAudioUrl( url ) ) {
|
if ( Utils::Url::isWebAudioUrl( url ) ) {
|
||||||
sptr< Dictionary::DataRequest > req = std::make_shared< Dictionary::WebMultimediaDownload >( url, articleNetMgr );
|
sptr< Dictionary::DataRequest > req = std::make_shared< Dictionary::WebMultimediaDownload >( url, articleNetMgr );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue