mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
opt: add the language variant option for wikipedia dictionaries (#1374)
* opt: add the language variant option for wikipedia dictionaries * fix:default value for 'lang_' parameter * [autofix.ci] apply automated fixes * fix: Should have been 'https' for the wikipedia queries. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
4304fc9aef
commit
853130ddb7
|
@ -2755,6 +2755,10 @@ To find '*', '?', '[', ']' symbols use &
|
|||
<source>Icon</source>
|
||||
<translation>图标</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Language Variant</source>
|
||||
<translation>语言变体</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>MultimediaAudioPlayer</name>
|
||||
|
|
|
@ -354,6 +354,30 @@ MediaWikis makeDefaultMediaWikis( bool enable )
|
|||
MediaWiki( "f3b4ec8531e52ddf5b10d21e4577a7a2", "Greek Wikipedia", "https://el.wikipedia.org/w", false, "" ) );
|
||||
mw.push_back(
|
||||
MediaWiki( "5d45232075d06e002dea72fe3e137da1", "Greek Wiktionary", "https://el.wiktionary.org/w", false, "" ) );
|
||||
mw.push_back( MediaWiki( "c015d60c4949ad75b5b7069c2ff6dc2c",
|
||||
"traditional Chinese Wikipedia",
|
||||
"https://zh.wikipedia.org/w",
|
||||
false,
|
||||
"",
|
||||
"zh-hant" ) );
|
||||
mw.push_back( MediaWiki( "d50828ad6e115bc9d3421b6821543108",
|
||||
"traditional Chinese Wiktionary",
|
||||
"https://zh.wiktionary.org/w",
|
||||
false,
|
||||
"",
|
||||
"zh-hant" ) );
|
||||
mw.push_back( MediaWiki( "438b17b48cbda1a22d317fea37ec3110",
|
||||
"Simplified Chinese Wikipedia",
|
||||
"https://zh.wikipedia.org/w",
|
||||
false,
|
||||
"",
|
||||
"zh-hans" ) );
|
||||
mw.push_back( MediaWiki( "b68b9fb71b5a8c766cc7a5ea8237fc6b",
|
||||
"Simplified Chinese Wiktionary",
|
||||
"https://zh.wiktionary.org/w",
|
||||
false,
|
||||
"",
|
||||
"zh-hans" ) );
|
||||
|
||||
return mw;
|
||||
}
|
||||
|
@ -760,6 +784,7 @@ Class load()
|
|||
w.url = mw.attribute( "url" );
|
||||
w.enabled = ( mw.attribute( "enabled" ) == "1" );
|
||||
w.icon = mw.attribute( "icon" );
|
||||
w.lang = mw.attribute( "lang" );
|
||||
|
||||
c.mediawikis.push_back( w );
|
||||
}
|
||||
|
@ -1527,6 +1552,10 @@ void save( Class const & c )
|
|||
QDomAttr icon = dd.createAttribute( "icon" );
|
||||
icon.setValue( mediawiki.icon );
|
||||
mw.setAttributeNode( icon );
|
||||
|
||||
QDomAttr lang = dd.createAttribute( "lang" );
|
||||
lang.setValue( mediawiki.lang );
|
||||
mw.setAttributeNode( lang );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -455,24 +455,32 @@ struct MediaWiki
|
|||
QString id, name, url;
|
||||
bool enabled;
|
||||
QString icon;
|
||||
QString lang;
|
||||
|
||||
MediaWiki():
|
||||
enabled( false )
|
||||
{
|
||||
}
|
||||
|
||||
MediaWiki( QString const & id_, QString const & name_, QString const & url_, bool enabled_, QString const & icon_ ):
|
||||
MediaWiki( QString const & id_,
|
||||
QString const & name_,
|
||||
QString const & url_,
|
||||
bool enabled_,
|
||||
QString const & icon_,
|
||||
QString const & lang_ = "" ):
|
||||
id( id_ ),
|
||||
name( name_ ),
|
||||
url( url_ ),
|
||||
enabled( enabled_ ),
|
||||
icon( icon_ )
|
||||
icon( icon_ ),
|
||||
lang( lang_ )
|
||||
{
|
||||
}
|
||||
|
||||
bool operator==( MediaWiki const & other ) const
|
||||
{
|
||||
return id == other.id && name == other.name && url == other.url && enabled == other.enabled && icon == other.icon;
|
||||
return id == other.id && name == other.name && url == other.url && enabled == other.enabled && icon == other.icon
|
||||
&& lang == other.lang;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace {
|
|||
class MediaWikiDictionary: public Dictionary::Class
|
||||
{
|
||||
string name;
|
||||
QString url, icon;
|
||||
QString url, icon, lang;
|
||||
QNetworkAccessManager & netMgr;
|
||||
quint32 langId;
|
||||
|
||||
|
@ -36,11 +36,13 @@ public:
|
|||
string const & name_,
|
||||
QString const & url_,
|
||||
QString const & icon_,
|
||||
QString const & lang_,
|
||||
QNetworkAccessManager & netMgr_ ):
|
||||
Dictionary::Class( id, vector< string >() ),
|
||||
name( name_ ),
|
||||
url( url_ ),
|
||||
icon( icon_ ),
|
||||
lang( lang_ ),
|
||||
netMgr( netMgr_ ),
|
||||
langId( 0 )
|
||||
{
|
||||
|
@ -132,7 +134,7 @@ class MediaWikiWordSearchRequest: public MediaWikiWordSearchRequestSlots
|
|||
|
||||
public:
|
||||
|
||||
MediaWikiWordSearchRequest( wstring const &, QString const & url, QNetworkAccessManager & mgr );
|
||||
MediaWikiWordSearchRequest( wstring const &, QString const & url, QString const & lang, QNetworkAccessManager & mgr );
|
||||
|
||||
~MediaWikiWordSearchRequest();
|
||||
|
||||
|
@ -145,6 +147,7 @@ private:
|
|||
|
||||
MediaWikiWordSearchRequest::MediaWikiWordSearchRequest( wstring const & str,
|
||||
QString const & url,
|
||||
QString const & lang,
|
||||
QNetworkAccessManager & mgr ):
|
||||
isCancelling( false )
|
||||
{
|
||||
|
@ -154,6 +157,7 @@ MediaWikiWordSearchRequest::MediaWikiWordSearchRequest( wstring const & str,
|
|||
GlobalBroadcaster::instance()->addWhitelist( reqUrl.host() );
|
||||
|
||||
Utils::Url::addQueryItem( reqUrl, "apprefix", QString::fromStdU32String( str ).replace( '+', "%2B" ) );
|
||||
Utils::Url::addQueryItem( reqUrl, "lang", lang );
|
||||
|
||||
QNetworkRequest req( reqUrl );
|
||||
//millseconds.
|
||||
|
@ -376,12 +380,14 @@ class MediaWikiArticleRequest: public MediaWikiDataRequestSlots
|
|||
typedef std::list< std::pair< QNetworkReply *, bool > > NetReplies;
|
||||
NetReplies netReplies;
|
||||
QString url;
|
||||
QString lang;
|
||||
|
||||
public:
|
||||
|
||||
MediaWikiArticleRequest( wstring const & word,
|
||||
vector< wstring > const & alts,
|
||||
QString const & url,
|
||||
QString const & lang,
|
||||
QNetworkAccessManager & mgr,
|
||||
Class * dictPtr_ );
|
||||
|
||||
|
@ -425,9 +431,11 @@ void MediaWikiArticleRequest::cancel()
|
|||
MediaWikiArticleRequest::MediaWikiArticleRequest( wstring const & str,
|
||||
vector< wstring > const & alts,
|
||||
QString const & url_,
|
||||
QString const & lang_,
|
||||
QNetworkAccessManager & mgr,
|
||||
Class * dictPtr_ ):
|
||||
url( url_ ),
|
||||
lang( lang_ ),
|
||||
dictPtr( dictPtr_ )
|
||||
{
|
||||
connect( &mgr,
|
||||
|
@ -449,6 +457,7 @@ void MediaWikiArticleRequest::addQuery( QNetworkAccessManager & mgr, wstring con
|
|||
QUrl reqUrl( url + "/api.php?action=parse&prop=text|revid|sections&format=xml&redirects" );
|
||||
|
||||
Utils::Url::addQueryItem( reqUrl, "page", QString::fromStdU32String( str ).replace( '+', "%2B" ) );
|
||||
Utils::Url::addQueryItem( reqUrl, "variant", lang );
|
||||
QNetworkRequest req( reqUrl );
|
||||
//millseconds.
|
||||
req.setTransferTimeout( 3000 );
|
||||
|
@ -690,7 +699,7 @@ sptr< WordSearchRequest > MediaWikiDictionary::prefixMatch( wstring const & word
|
|||
return std::make_shared< WordSearchRequestInstant >();
|
||||
}
|
||||
else
|
||||
return std::make_shared< MediaWikiWordSearchRequest >( word, url, netMgr );
|
||||
return std::make_shared< MediaWikiWordSearchRequest >( word, url, lang, netMgr );
|
||||
}
|
||||
|
||||
sptr< DataRequest >
|
||||
|
@ -703,7 +712,7 @@ MediaWikiDictionary::getArticle( wstring const & word, vector< wstring > const &
|
|||
return std::make_shared< DataRequestInstant >( false );
|
||||
}
|
||||
else
|
||||
return std::make_shared< MediaWikiArticleRequest >( word, alts, url, netMgr, this );
|
||||
return std::make_shared< MediaWikiArticleRequest >( word, alts, url, lang, netMgr, this );
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -720,6 +729,7 @@ makeDictionaries( Dictionary::Initializing &, Config::MediaWikis const & wikis,
|
|||
wiki.name.toUtf8().data(),
|
||||
wiki.url,
|
||||
wiki.icon,
|
||||
wiki.lang,
|
||||
mgr ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ Sources::Sources( QWidget * parent, Config::Class const & cfg ):
|
|||
ui.mediaWikis->resizeColumnToContents( 1 );
|
||||
ui.mediaWikis->resizeColumnToContents( 2 );
|
||||
ui.mediaWikis->resizeColumnToContents( 3 );
|
||||
ui.mediaWikis->resizeColumnToContents( 4 );
|
||||
|
||||
ui.webSites->setTabKeyNavigation( true );
|
||||
ui.webSites->setModel( &webSitesModel );
|
||||
|
@ -429,6 +430,8 @@ void MediaWikisModel::addNewWiki()
|
|||
|
||||
w.url = "http://";
|
||||
|
||||
w.lang = "";
|
||||
|
||||
beginInsertRows( QModelIndex(), mediawikis.size(), mediawikis.size() );
|
||||
mediawikis.push_back( w );
|
||||
endInsertRows();
|
||||
|
@ -471,7 +474,7 @@ int MediaWikisModel::columnCount( QModelIndex const & parent ) const
|
|||
if ( parent.isValid() )
|
||||
return 0;
|
||||
else
|
||||
return 4;
|
||||
return 5;
|
||||
}
|
||||
|
||||
QVariant MediaWikisModel::headerData( int section, Qt::Orientation /*orientation*/, int role ) const
|
||||
|
@ -486,6 +489,8 @@ QVariant MediaWikisModel::headerData( int section, Qt::Orientation /*orientation
|
|||
return tr( "Address" );
|
||||
case 3:
|
||||
return tr( "Icon" );
|
||||
case 4:
|
||||
return tr( "Language Variant" );
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -506,6 +511,8 @@ QVariant MediaWikisModel::data( QModelIndex const & index, int role ) const
|
|||
return mediawikis[ index.row() ].url;
|
||||
case 3:
|
||||
return mediawikis[ index.row() ].icon;
|
||||
case 4:
|
||||
return mediawikis[ index.row() ].lang;
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
@ -547,6 +554,10 @@ bool MediaWikisModel::setData( QModelIndex const & index, const QVariant & value
|
|||
mediawikis[ index.row() ].icon = value.toString();
|
||||
dataChanged( index, index );
|
||||
return true;
|
||||
case 4:
|
||||
mediawikis[ index.row() ].lang = value.toString();
|
||||
dataChanged( index, index );
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue