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()
|
|
|
|
{
|
2013-05-08 14:50:06 +00:00
|
|
|
reply = NULL;
|
2010-05-29 11:33:04 +00:00
|
|
|
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebMultimediaDownload::replyFinished( QNetworkReply * r )
|
|
|
|
{
|
2013-05-08 16:08:34 +00:00
|
|
|
if ( !r || r != reply )
|
2010-05-29 11:33:04 +00:00
|
|
|
return; // Not our reply
|
|
|
|
|
2013-05-08 14:50:06 +00:00
|
|
|
if ( r->error() == QNetworkReply::NoError )
|
2010-05-29 11:33:04 +00:00
|
|
|
{
|
2013-05-08 14:50:06 +00:00
|
|
|
QByteArray all = r->readAll();
|
2010-05-29 11:33:04 +00:00
|
|
|
|
|
|
|
Mutex::Lock _( dataMutex );
|
|
|
|
|
|
|
|
data.resize( all.size() );
|
|
|
|
|
|
|
|
memcpy( data.data(), all.data(), all.size() );
|
|
|
|
|
|
|
|
hasAnyData = true;
|
|
|
|
}
|
|
|
|
else
|
2013-05-08 14:50:06 +00:00
|
|
|
setErrorString( r->errorString() );
|
2010-05-29 11:33:04 +00:00
|
|
|
|
2013-05-08 16:08:34 +00:00
|
|
|
r->deleteLater();
|
2013-05-08 14:50:06 +00:00
|
|
|
reply = NULL;
|
2013-05-08 16:08:34 +00:00
|
|
|
|
|
|
|
finish();
|
2010-05-29 11:33:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-06-24 14:50:14 +00:00
|
|
|
return ( url.scheme() == "http" || url.scheme() == "https" ) && (
|
2010-06-12 20:16:35 +00:00
|
|
|
Filetype::isNameOfSound( url.path().toUtf8().data() ) || url.host() == "apifree.forvo.com" );
|
2010-05-29 11:33:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|