mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
9eb20cf0b6
Here we also add Google as a web dictionary as an initial website example. Sounds there work just fine.
53 lines
1.1 KiB
C++
53 lines
1.1 KiB
C++
#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 )
|
|
{
|
|
return url.scheme() == "http" && Filetype::isNameOfSound( url.path().toUtf8().data() );
|
|
}
|
|
|
|
}
|