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) ), connect( baseReply, SIGNAL( error( QNetworkReply::NetworkError) ),
this, SLOT( applyError( QNetworkReply::NetworkError ) ) ); this, SLOT( applyError( QNetworkReply::NetworkError ) ) );
connect( baseReply, SIGNAL( readyRead() ), this, SLOT( readDataFromBase() ) );
// Redirect QNetworkReply signals // Redirect QNetworkReply signals
connect( baseReply, SIGNAL( downloadProgress( qint64, qint64 ) ), connect( baseReply, SIGNAL( downloadProgress( qint64, qint64 ) ),
@ -110,9 +112,6 @@ using std::string;
connect( baseReply, SIGNAL( readChannelFinished() ), this, SIGNAL( readChannelFinished() ) ); connect( baseReply, SIGNAL( readChannelFinished() ), this, SIGNAL( readChannelFinished() ) );
connect( baseReply, SIGNAL( readyRead() ), this, SIGNAL( readyRead() ) );
setOpenMode( QIODevice::ReadOnly ); setOpenMode( QIODevice::ReadOnly );
} }
@ -167,12 +166,38 @@ using std::string;
emit metaDataChanged(); 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 ) void AllowFrameReply::applyError( QNetworkReply::NetworkError code )
{ {
setError( code, baseReply->errorString() ); setError( code, baseReply->errorString() );
emit error( code ); 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 #endif
namespace namespace
@ -331,7 +356,8 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
} }
#if QT_VERSION >= 0x050200 // Qt 5.2+ #if QT_VERSION >= 0x050200 // Qt 5.2+
return new AllowFrameReply( reply ); return op == QNetworkAccessManager::GetOperation
|| op == QNetworkAccessManager::HeadOperation ? new AllowFrameReply( reply ) : reply;
#else #else
return reply; return reply;
#endif #endif

View file

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