2010-05-29 11:33:04 +00:00
|
|
|
#include "webmultimediadownload.hh"
|
|
|
|
#include "filetype.hh"
|
|
|
|
|
|
|
|
namespace Dictionary {
|
|
|
|
|
|
|
|
WebMultimediaDownload::WebMultimediaDownload( QUrl const & url,
|
|
|
|
QNetworkAccessManager & mgr )
|
|
|
|
{
|
|
|
|
connect( &mgr, SIGNAL(finished(QNetworkReply*)),
|
|
|
|
this, SLOT(replyFinished(QNetworkReply*)), Qt::QueuedConnection );
|
|
|
|
|
|
|
|
reply = mgr.get( QNetworkRequest( url ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebMultimediaDownload::cancel()
|
|
|
|
{
|
|
|
|
reply.reset();
|
|
|
|
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebMultimediaDownload::replyFinished( QNetworkReply * r )
|
|
|
|
{
|
|
|
|
if ( r != reply.get() )
|
|
|
|
return; // Not our reply
|
|
|
|
|
|
|
|
if ( reply->error() == QNetworkReply::NoError )
|
|
|
|
{
|
|
|
|
QByteArray all = reply->readAll();
|
|
|
|
|
|
|
|
Mutex::Lock _( dataMutex );
|
|
|
|
|
|
|
|
data.resize( all.size() );
|
|
|
|
|
|
|
|
memcpy( data.data(), all.data(), all.size() );
|
|
|
|
|
|
|
|
hasAnyData = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
setErrorString( reply->errorString() );
|
|
|
|
|
|
|
|
finish();
|
|
|
|
|
|
|
|
reply.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebMultimediaDownload::isAudioUrl( QUrl const & url )
|
|
|
|
{
|
2010-06-12 20:16:35 +00:00
|
|
|
// Note: we check for forvo sound links explicitly, as they don't have extensions
|
|
|
|
|
|
|
|
return url.scheme() == "http" && (
|
|
|
|
Filetype::isNameOfSound( url.path().toUtf8().data() ) || url.host() == "apifree.forvo.com" );
|
2010-05-29 11:33:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|