2010-06-25 10:08:51 -07:00
|
|
|
//TODO gpl?
|
|
|
|
|
|
2010-06-25 07:05:29 -07:00
|
|
|
#include "zipnetworkreply.h"
|
2010-06-25 10:08:51 -07:00
|
|
|
|
|
|
|
|
#include "odfcontainer.h"
|
|
|
|
|
|
2010-06-25 07:05:29 -07:00
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
|
2010-06-25 10:08:51 -07:00
|
|
|
ZipNetworkReply::ZipNetworkReply(QObject* parent, OdfContainer *odf, const QNetworkRequest &req, const QNetworkAccessManager::Operation op)
|
|
|
|
|
:QNetworkReply(parent)
|
2010-06-25 07:05:29 -07:00
|
|
|
{
|
|
|
|
|
setRequest(req);
|
|
|
|
|
setUrl(req.url());
|
|
|
|
|
setOperation(op);
|
2010-06-25 10:08:51 -07:00
|
|
|
QNetworkReply::open(QIODevice::ReadOnly);
|
2010-06-25 07:05:29 -07:00
|
|
|
|
2010-07-16 14:09:54 +02:00
|
|
|
//the name of the file within the zip, mid(2) removes the './'
|
2010-06-25 10:08:51 -07:00
|
|
|
QString fileName = req.url().toString(QUrl::RemoveScheme);
|
2010-07-16 14:09:54 +02:00
|
|
|
if (fileName.startsWith("./")) {
|
|
|
|
|
fileName = fileName.mid(2);
|
|
|
|
|
}
|
2010-06-25 10:08:51 -07:00
|
|
|
qDebug() << fileName;
|
2010-06-25 07:05:29 -07:00
|
|
|
|
2010-06-25 10:08:51 -07:00
|
|
|
m_file = odf->getFile(fileName, this);
|
|
|
|
|
m_file->open(QIODevice::ReadOnly);
|
|
|
|
|
qint64 fileSize = m_file->size();
|
|
|
|
|
qDebug() << fileSize;
|
|
|
|
|
m_remaining = fileSize;
|
2010-06-25 07:05:29 -07:00
|
|
|
|
|
|
|
|
//setHeader(QNetworkRequest::LastModifiedHeader, fi.lastModified());
|
|
|
|
|
setHeader(QNetworkRequest::ContentLengthHeader, fileSize);
|
|
|
|
|
|
|
|
|
|
QMetaObject::invokeMethod(this, "metaDataChanged", Qt::QueuedConnection);
|
|
|
|
|
QMetaObject::invokeMethod(this, "downloadProgress", Qt::QueuedConnection,
|
|
|
|
|
Q_ARG(qint64, fileSize), Q_ARG(qint64, fileSize));
|
|
|
|
|
QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection);
|
|
|
|
|
QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-25 10:08:51 -07:00
|
|
|
void ZipNetworkReply::close()
|
|
|
|
|
{
|
2010-07-16 14:09:54 +02:00
|
|
|
qDebug() << "close";
|
2010-06-25 10:08:51 -07:00
|
|
|
QNetworkReply::close();
|
|
|
|
|
m_file->close();
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-25 07:05:29 -07:00
|
|
|
void ZipNetworkReply::abort()
|
|
|
|
|
{
|
2010-07-16 14:09:54 +02:00
|
|
|
qDebug() << "abort";
|
2010-06-25 07:05:29 -07:00
|
|
|
QNetworkReply::close();
|
2010-06-25 10:08:51 -07:00
|
|
|
m_file->close();
|
2010-06-25 07:05:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint64 ZipNetworkReply::readData(char *data, qint64 maxSize)
|
|
|
|
|
{
|
2010-06-25 10:08:51 -07:00
|
|
|
qDebug() << "reading " << maxSize;
|
|
|
|
|
qint64 read = m_file->read(data, maxSize);
|
|
|
|
|
qDebug() << "read " << read;
|
|
|
|
|
if (read > 0) {
|
|
|
|
|
m_remaining -= read;
|
|
|
|
|
}
|
|
|
|
|
return read;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint64 ZipNetworkReply::bytesAvailable() const
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "avail " << m_remaining << " + " << QNetworkReply::bytesAvailable();
|
|
|
|
|
return m_remaining + QNetworkReply::bytesAvailable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint64 ZipNetworkReply::size() const
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "size " << m_file->size();
|
|
|
|
|
return m_file->size();
|
2010-06-25 07:05:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|