Make Forvo support translatable.

We achieve this by making ForvoArticleRequest a proper Q_OBJECT.
This commit is contained in:
Konstantin Isakov 2010-11-23 02:50:30 +03:00
parent 95dbffbcb7
commit a5a2b4d67e
2 changed files with 73 additions and 77 deletions

111
forvo.cc
View file

@ -70,40 +70,53 @@ public:
throw( std::exception ); 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; // Don't make excessively large queries -- they're fruitless anyway
string word;
bool finished;
NetReply( sptr< QNetworkReply > const & reply_, string const & word_ ): return new DataRequestInstant( false );
reply( reply_ ), word( word_ ), finished( false ) }
{} else
}; return new ForvoArticleRequest( word, alts, apiKey, languageCode, getId(),
netMgr );
}
typedef std::list< NetReply > NetReplies; QIcon ForvoDictionary::getIcon() throw()
NetReplies netReplies; {
QString apiKey, languageCode; // Experimental code to generate icon -- but the flags clutter the interface too
string dictionaryId; // 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, if ( !flag.isNull() )
QString const & apiKey_, {
QString const & languageCode_, QImage img( ":/icons/forvo_icon_base.png" );
string const & dictionaryId_,
QNetworkAccessManager & mgr );
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() void ForvoArticleRequest::cancel()
{ {
@ -342,54 +355,6 @@ void ForvoArticleRequest::requestFinished( QNetworkReply * r )
update(); 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( vector< sptr< Dictionary::Class > > makeDictionaries(
Dictionary::Initializing &, Dictionary::Initializing &,
Config::Forvo const & forvo, Config::Forvo const & forvo,

View file

@ -7,12 +7,15 @@
#include "dictionary.hh" #include "dictionary.hh"
#include "config.hh" #include "config.hh"
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include "wstring.hh"
#include <QNetworkReply>
/// Support for Forvo pronunciations, based on its API. /// Support for Forvo pronunciations, based on its API.
namespace Forvo { namespace Forvo {
using std::vector; using std::vector;
using std::string; using std::string;
using gd::wstring;
vector< sptr< Dictionary::Class > > makeDictionaries( vector< sptr< Dictionary::Class > > makeDictionaries(
Dictionary::Initializing &, Dictionary::Initializing &,
@ -21,14 +24,42 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
throw( std::exception ); throw( std::exception );
/// Exposed here for moc /// Exposed here for moc
class ForvoDataRequestSlots: public Dictionary::DataRequest class ForvoArticleRequest: public Dictionary::DataRequest
{ {
Q_OBJECT 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 * );
}; };
} }