Websites(Qt 5.2+): Fix some urls handling

This commit is contained in:
Abs62 2017-03-24 17:05:22 +03:00
parent 747185c490
commit 85ddcc507d
2 changed files with 35 additions and 10 deletions

View file

@ -82,6 +82,8 @@ using std::string;
connect( baseReply, SIGNAL( error( QNetworkReply::NetworkError) ),
this, SLOT( applyError( QNetworkReply::NetworkError ) ) );
connect( baseReply, SIGNAL( readyRead() ), this, SLOT( readDataFromBase() ) );
// Redirect QNetworkReply signals
connect( baseReply, SIGNAL( downloadProgress( qint64, qint64 ) ),
@ -110,9 +112,6 @@ using std::string;
connect( baseReply, SIGNAL( readChannelFinished() ), this, SIGNAL( readChannelFinished() ) );
connect( baseReply, SIGNAL( readyRead() ), this, SIGNAL( readyRead() ) );
setOpenMode( QIODevice::ReadOnly );
}
@ -167,12 +166,38 @@ using std::string;
emit metaDataChanged();
}
void AllowFrameReply::setReadBufferSize( qint64 size )
{
QNetworkReply::setReadBufferSize( size );
baseReply->setReadBufferSize( size );
}
qint64 AllowFrameReply::bytesAvailable() const
{
return buffer.size() + QNetworkReply::bytesAvailable();
}
void AllowFrameReply::applyError( QNetworkReply::NetworkError code )
{
setError( code, baseReply->errorString() );
emit error( code );
}
void AllowFrameReply::readDataFromBase()
{
QByteArray data = baseReply->readAll();
buffer += data;
emit readyRead();
}
qint64 AllowFrameReply::readData( char * data, qint64 maxSize )
{
qint64 size = qMin( maxSize, qint64( buffer.size() ) );
memcpy( data, buffer.data(), size );
buffer.remove( 0, size );
return size;
}
#endif
namespace
@ -331,7 +356,8 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
}
#if QT_VERSION >= 0x050200 // Qt 5.2+
return new AllowFrameReply( reply );
return op == QNetworkAccessManager::GetOperation
|| op == QNetworkAccessManager::HeadOperation ? new AllowFrameReply( reply ) : reply;
#else
return reply;
#endif

View file

@ -59,6 +59,7 @@ class AllowFrameReply : public QNetworkReply
Q_OBJECT
private:
QNetworkReply * baseReply;
QByteArray buffer;
AllowFrameReply();
AllowFrameReply( AllowFrameReply const & );
@ -69,16 +70,14 @@ public:
{ delete baseReply; }
// QNetworkReply virtual functions
void setReadBufferSize( qint64 size )
{ baseReply->setReadBufferSize( size ); }
void setReadBufferSize( qint64 size );
void close()
{ baseReply->close(); }
// QIODevice virtual functions
qint64 bytesAvailable() const;
bool atEnd() const
{ return baseReply->atEnd(); }
qint64 bytesAvailable() const
{ return baseReply->bytesAvailable(); }
qint64 bytesToWrite() const
{ return baseReply->bytesToWrite(); }
bool canReadLine() const
@ -97,6 +96,7 @@ public slots:
// Own AllowFrameReply slots
void applyMetaData();
void applyError( QNetworkReply::NetworkError code );
void readDataFromBase();
// Redirect QNetworkReply slots
virtual void abort()
@ -114,8 +114,7 @@ protected:
{ configuration = baseReply->sslConfiguration(); }
// QIODevice virtual functions
qint64 readData( char * data, qint64 maxSize )
{ return baseReply->read( data, maxSize ); }
qint64 readData( char * data, qint64 maxSize );
qint64 readLineData( char * data, qint64 maxSize )
{ return baseReply->readLine( data, maxSize ); }
qint64 writeData( const char * data, qint64 maxSize )