Version 0.002 with working Favorite Combobox

This commit is contained in:
LubuWest 2016-11-14 13:28:23 +01:00
commit 571c9046d0
42 changed files with 1948 additions and 814 deletions

View file

@ -1,4 +1,4 @@
#include "xhr.h"
#include "xhr.h"
#include <QHttpPart>
#include <QTextCodec>
@ -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)
@ -32,6 +32,15 @@ void XHR::setLogin(QString login)
emit loginChanged();
}
}
void XHR::setFilename(QString filename)
{
if (filename!=m_filename) {
m_filename = filename;
emit filenameChanged();
}
}
QString XHR::url() const
{
return m_url;
@ -42,6 +51,11 @@ QString XHR::login() const
return m_login;
}
QString XHR::filename() const
{
return m_filename;
}
void XHR::setParam(QString name, QString value)
{
params.insert(name, value);
@ -58,6 +72,21 @@ void XHR::clearParams()
params.clear();
}
void XHR::download()
{
QUrl requrl(m_url);
// qDebug() << "start download of " << requrl;
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();
// reply->ignoreSslErrors();
connect(reply, &QNetworkReply::readyRead,this, &XHR::onRequestFinished);
connect(reply, &QNetworkReply::sslErrors, this, &XHR::onSSLError);
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onReplyError(QNetworkReply::NetworkError)));
}
void XHR::get()
{
QUrlQuery query;
@ -82,7 +111,7 @@ void XHR::get()
connect(reply, &QNetworkReply::finished, this, &XHR::onReplySuccess);
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onReplyError(QNetworkReply::NetworkError)));
connect(reply, &QNetworkReply::readyRead, this, &XHR::onReadyRead);
connect(reply, &QNetworkReply::sslErrors, this, &XHR::onSSLError);
}
void XHR::post()
@ -145,6 +174,22 @@ void XHR::onReplySuccess()
reply->deleteLater();
}
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);
file.open(QIODevice::WriteOnly);
image.save(&file, "JPG");
b.clear();
file.close();
// qDebug() << m_url << "File downloaded "<<file.fileName();
emit this->downloaded();
reply->deleteLater();
}
void XHR::onReadyRead()
{
qDebug() << ".";