Version 0.002 with working Permissions

This commit is contained in:
LubuWest 2016-12-04 18:28:52 +01:00
commit 15e2e8f60a
62 changed files with 924 additions and 1277 deletions

View file

@ -14,7 +14,7 @@ XHR *XHR::instance()
XHR::XHR(QObject *parent) : QObject(parent)
{
// request.setSslConfiguration(QSslConfiguration::defaultConfiguration());
request.setSslConfiguration(QSslConfiguration::defaultConfiguration());
}
void XHR::setUrl(QString url)
@ -79,10 +79,11 @@ void XHR::download()
request.setUrl(requrl);
reply = manager.get(request);
// qDebug() << "reply " << reply->header(QNetworkRequest::LocationHeader)<<reply->header(QNetworkRequest::LastModifiedHeader);
// qDebug() << "request " << request.url();
// qDebug() << "error " << reply->error();
// qDebug() << "request " << request.url();
// reply->ignoreSslErrors();
connect(reply, &QNetworkReply::readyRead,this, &XHR::onRequestFinished);
connect(reply, &QNetworkReply::readyRead,this, &XHR::onReadyRead);
connect(reply,SIGNAL(downloadProgress(qint64,qint64)), this,SLOT(updateDownloadProgress(qint64,qint64)));
connect(reply, &QNetworkReply::finished,this, &XHR::onRequestFinished);
connect(reply, &QNetworkReply::sslErrors, this, &XHR::onSSLError);
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onReplyError(QNetworkReply::NetworkError)));
}
@ -177,17 +178,19 @@ void XHR::onReplySuccess()
void XHR::onRequestFinished()
{
// Save the file here
QByteArray b = reply->readAll();
QImage image = QImage::fromData(b);
if (image.isNull()){qDebug() << "Image empty"<<m_url;}
QFile file(m_filename);
//qDebug() << "buffer downloaded "<<buffer;
//QImage image = QImage::fromData(buffer);
if (buffer.isNull()){qDebug() << "Image empty"<<m_url; buffer.clear(); emit this->error("image empty",1); reply->deleteLater();}
else {QFile file(m_filename);
file.open(QIODevice::WriteOnly);
image.save(&file, "JPG");
b.clear();
//image.save(&file, "JPG");
file.write(buffer);
buffer.clear();
file.close();
// qDebug() << m_url << "File downloaded "<<file.fileName();
//qDebug() << m_url << "File downloaded "<<file.fileName();
emit this->downloaded();
reply->deleteLater();
//reply->deleteLater();
}
}
void XHR::onReadyRead()
@ -196,6 +199,12 @@ void XHR::onReadyRead()
buffer += reply->readAll();
}
void XHR::updateDownloadProgress(qint64 bytesRead, qint64 totalBytes)
{
qDebug() << "Bytes: " << bytesRead<<" / "<<totalBytes;
}
void XHR::onSSLError(const QList<QSslError> &errors)
{
qDebug() << "XHR::onSSLError :" ;

View file

@ -16,10 +16,7 @@ public:
static XHR *instance();
explicit XHR(QObject *parent = 0);
// void setLogin(QString login);
QString url() const;
QString login() const;
QString filename() const;
@ -47,9 +44,9 @@ private slots:
void onReplyError(QNetworkReply::NetworkError code);
void onReplySuccess();
void onRequestFinished();
//void onFileWritten();
void onReadyRead();
void onSSLError(const QList<QSslError> &errors);
void updateDownloadProgress(qint64 bytesRead, qint64 totalBytes);
private:
QByteArray buffer;