mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
Make Forvo support translatable.
We achieve this by making ForvoArticleRequest a proper Q_OBJECT.
This commit is contained in:
parent
95dbffbcb7
commit
a5a2b4d67e
111
forvo.cc
111
forvo.cc
|
@ -70,40 +70,53 @@ public:
|
|||
throw( std::exception );
|
||||
};
|
||||
|
||||
class ForvoArticleRequest: public ForvoDataRequestSlots
|
||||
sptr< DataRequest > ForvoDictionary::getArticle( wstring const & word,
|
||||
vector< wstring > const & alts,
|
||||
wstring const & )
|
||||
throw( std::exception )
|
||||
{
|
||||
struct NetReply
|
||||
if ( word.size() > 80 )
|
||||
{
|
||||
sptr< QNetworkReply > reply;
|
||||
string word;
|
||||
bool finished;
|
||||
// Don't make excessively large queries -- they're fruitless anyway
|
||||
|
||||
NetReply( sptr< QNetworkReply > const & reply_, string const & word_ ):
|
||||
reply( reply_ ), word( word_ ), finished( false )
|
||||
{}
|
||||
};
|
||||
return new DataRequestInstant( false );
|
||||
}
|
||||
else
|
||||
return new ForvoArticleRequest( word, alts, apiKey, languageCode, getId(),
|
||||
netMgr );
|
||||
}
|
||||
|
||||
typedef std::list< NetReply > NetReplies;
|
||||
NetReplies netReplies;
|
||||
QString apiKey, languageCode;
|
||||
string dictionaryId;
|
||||
QIcon ForvoDictionary::getIcon() throw()
|
||||
{
|
||||
// Experimental code to generate icon -- but the flags clutter the interface too
|
||||
// much and we're better with a single icon.
|
||||
#if 0
|
||||
if ( languageCode.size() == 2 )
|
||||
{
|
||||
QString countryCode = Language::countryCodeForId( LangCoder::code2toInt( languageCode.toAscii().data() ) );
|
||||
|
||||
public:
|
||||
if ( countryCode.size() )
|
||||
{
|
||||
QImage flag( QString( ":/flags/%1.png" ).arg( countryCode.toLower() ) );
|
||||
|
||||
ForvoArticleRequest( wstring const & word, vector< wstring > const & alts,
|
||||
QString const & apiKey_,
|
||||
QString const & languageCode_,
|
||||
string const & dictionaryId_,
|
||||
QNetworkAccessManager & mgr );
|
||||
if ( !flag.isNull() )
|
||||
{
|
||||
QImage img( ":/icons/forvo_icon_base.png" );
|
||||
|
||||
virtual void cancel();
|
||||
{
|
||||
QPainter painter( &img );
|
||||
painter.drawImage( QPoint( 5, 7 ), flag );
|
||||
}
|
||||
|
||||
private:
|
||||
return QIcon( QPixmap::fromImage( img ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return QIcon( ":/icons/forvo.png" );
|
||||
}
|
||||
|
||||
void addQuery( QNetworkAccessManager & mgr, wstring const & word );
|
||||
|
||||
virtual void requestFinished( QNetworkReply * );
|
||||
};
|
||||
}
|
||||
|
||||
void ForvoArticleRequest::cancel()
|
||||
{
|
||||
|
@ -342,54 +355,6 @@ void ForvoArticleRequest::requestFinished( QNetworkReply * r )
|
|||
update();
|
||||
}
|
||||
|
||||
sptr< DataRequest > ForvoDictionary::getArticle( wstring const & word,
|
||||
vector< wstring > const & alts,
|
||||
wstring const & )
|
||||
throw( std::exception )
|
||||
{
|
||||
if ( word.size() > 80 )
|
||||
{
|
||||
// Don't make excessively large queries -- they're fruitless anyway
|
||||
|
||||
return new DataRequestInstant( false );
|
||||
}
|
||||
else
|
||||
return new ForvoArticleRequest( word, alts, apiKey, languageCode, getId(),
|
||||
netMgr );
|
||||
}
|
||||
|
||||
QIcon ForvoDictionary::getIcon() throw()
|
||||
{
|
||||
// Experimental code to generate icon -- but the flags clutter the interface too
|
||||
// much and we're better with a single icon.
|
||||
#if 0
|
||||
if ( languageCode.size() == 2 )
|
||||
{
|
||||
QString countryCode = Language::countryCodeForId( LangCoder::code2toInt( languageCode.toAscii().data() ) );
|
||||
|
||||
if ( countryCode.size() )
|
||||
{
|
||||
QImage flag( QString( ":/flags/%1.png" ).arg( countryCode.toLower() ) );
|
||||
|
||||
if ( !flag.isNull() )
|
||||
{
|
||||
QImage img( ":/icons/forvo_icon_base.png" );
|
||||
|
||||
{
|
||||
QPainter painter( &img );
|
||||
painter.drawImage( QPoint( 5, 7 ), flag );
|
||||
}
|
||||
|
||||
return QIcon( QPixmap::fromImage( img ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return QIcon( ":/icons/forvo.png" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
vector< sptr< Dictionary::Class > > makeDictionaries(
|
||||
Dictionary::Initializing &,
|
||||
Config::Forvo const & forvo,
|
||||
|
|
39
forvo.hh
39
forvo.hh
|
@ -7,12 +7,15 @@
|
|||
#include "dictionary.hh"
|
||||
#include "config.hh"
|
||||
#include <QNetworkAccessManager>
|
||||
#include "wstring.hh"
|
||||
#include <QNetworkReply>
|
||||
|
||||
/// Support for Forvo pronunciations, based on its API.
|
||||
namespace Forvo {
|
||||
|
||||
using std::vector;
|
||||
using std::string;
|
||||
using gd::wstring;
|
||||
|
||||
vector< sptr< Dictionary::Class > > makeDictionaries(
|
||||
Dictionary::Initializing &,
|
||||
|
@ -21,14 +24,42 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
|
|||
throw( std::exception );
|
||||
|
||||
/// Exposed here for moc
|
||||
class ForvoDataRequestSlots: public Dictionary::DataRequest
|
||||
class ForvoArticleRequest: public Dictionary::DataRequest
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected slots:
|
||||
struct NetReply
|
||||
{
|
||||
sptr< QNetworkReply > reply;
|
||||
string word;
|
||||
bool finished;
|
||||
|
||||
virtual void requestFinished( QNetworkReply * )
|
||||
{}
|
||||
NetReply( sptr< QNetworkReply > const & reply_, string const & word_ ):
|
||||
reply( reply_ ), word( word_ ), finished( false )
|
||||
{}
|
||||
};
|
||||
|
||||
typedef std::list< NetReply > NetReplies;
|
||||
NetReplies netReplies;
|
||||
QString apiKey, languageCode;
|
||||
string dictionaryId;
|
||||
|
||||
public:
|
||||
|
||||
ForvoArticleRequest( wstring const & word, vector< wstring > const & alts,
|
||||
QString const & apiKey_,
|
||||
QString const & languageCode_,
|
||||
string const & dictionaryId_,
|
||||
QNetworkAccessManager & mgr );
|
||||
|
||||
virtual void cancel();
|
||||
|
||||
private:
|
||||
|
||||
void addQuery( QNetworkAccessManager & mgr, wstring const & word );
|
||||
|
||||
private slots:
|
||||
virtual void requestFinished( QNetworkReply * );
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue