forked from lubuwest/Friendiqa
version v0.6.7 with moderation
This commit is contained in:
parent
5f8edccdfe
commit
48a70b8395
46 changed files with 2106 additions and 1026 deletions
|
@ -49,7 +49,7 @@ XHR *XHR::instance()
|
|||
|
||||
XHR::XHR(QObject *parent) : QObject(parent)
|
||||
{
|
||||
request.setSslConfiguration(QSslConfiguration::defaultConfiguration());
|
||||
//request.setSslConfiguration(QSslConfiguration::defaultConfiguration());
|
||||
}
|
||||
|
||||
void XHR::setUrl(QString url)
|
||||
|
@ -174,6 +174,7 @@ void XHR::clearParams()
|
|||
void XHR::download()
|
||||
{
|
||||
QUrl requrl(m_url);
|
||||
QNetworkRequest request;
|
||||
if(m_downloadtype=="picturelist"){
|
||||
QByteArray loginData = m_login.toLocal8Bit().toBase64();
|
||||
QString headerData = "Basic " + loginData;
|
||||
|
@ -205,6 +206,7 @@ void XHR::get()
|
|||
requrl.setQuery(query);
|
||||
QByteArray loginData = m_login.toLocal8Bit().toBase64();
|
||||
QString headerData = "Basic " + loginData;
|
||||
QNetworkRequest request;
|
||||
request.setRawHeader("Authorization", headerData.toLocal8Bit());
|
||||
request.setUrl(requrl);
|
||||
reply = manager.get(request);
|
||||
|
@ -224,7 +226,7 @@ void XHR::getlist()
|
|||
XHR::setUrl(m_filelist.at(dlindex));}
|
||||
else {
|
||||
XHR::setUrl(m_filelist.at(dlindex));}
|
||||
qDebug() << "start download" << m_url;
|
||||
//qDebug() << "start download" << m_url;
|
||||
XHR::download();
|
||||
} else {dlindex=0;m_downloadtype="";m_contactlist.clear();m_filelist.clear();}
|
||||
}
|
||||
|
@ -238,11 +240,8 @@ void XHR::post()
|
|||
QHashIterator<QString, QString> iparams(params);
|
||||
while(iparams.hasNext()) {
|
||||
iparams.next();
|
||||
//qDebug() << "\t add param " << iparams.key() << " : " << iparams.value();
|
||||
QHttpPart textPart;
|
||||
textPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"" + iparams.key() + "\""));
|
||||
|
||||
|
||||
textPart.setBody(iparams.value().toUtf8());
|
||||
multiPart->append(textPart);
|
||||
}
|
||||
|
@ -251,7 +250,7 @@ void XHR::post()
|
|||
if (files.contains("media")){
|
||||
uimg.setAngle(files.value("angle").toInt());
|
||||
uimg.setSource(files.value("media"));
|
||||
|
||||
//qDebug() << "\t add media " << files.value("media") << " : " << files.value("angle").toInt();
|
||||
QHttpPart imagePart;
|
||||
imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(uimg.mimetype()));
|
||||
imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"media\"; filename=\""+uimg.filename()+"\""));
|
||||
|
@ -261,8 +260,8 @@ void XHR::post()
|
|||
|
||||
QByteArray loginData = m_login.toLocal8Bit().toBase64();
|
||||
QString headerData = "Basic " + loginData;
|
||||
QNetworkRequest request;
|
||||
request.setRawHeader(QByteArray("Authorization"), headerData.toLocal8Bit());
|
||||
|
||||
request.setUrl(m_url+m_api);
|
||||
reply = manager.post(request, multiPart);
|
||||
qDebug() << "\t request sent";
|
||||
|
@ -273,6 +272,26 @@ void XHR::post()
|
|||
qDebug() << "\t reply signals connected";
|
||||
}
|
||||
|
||||
void XHR::postJSON()
|
||||
{
|
||||
if (params.contains("JSON")){
|
||||
QByteArray mJSON=params.value("JSON").toUtf8();
|
||||
QByteArray loginData = m_login.toLocal8Bit().toBase64();
|
||||
QString headerData = "Basic " + loginData;
|
||||
QNetworkRequest request;
|
||||
request.setRawHeader(QByteArray("Authorization"), headerData.toLocal8Bit());
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader,"application/json; charset=UTF-8");
|
||||
request.setUrl(m_url+m_api);
|
||||
reply = manager.post(request, mJSON);
|
||||
qDebug() << "\t request sent";
|
||||
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);
|
||||
qDebug() << "\t reply signals connected";
|
||||
}
|
||||
}
|
||||
|
||||
void XHR::onReplyError(QNetworkReply::NetworkError code)
|
||||
{
|
||||
qDebug() << code;
|
||||
|
@ -304,7 +323,7 @@ void XHR::onRequestFinished()
|
|||
QString helpfilename=jsonObject["filename"].toString();
|
||||
QString helpfile=helpfilename.left(helpfilename.lastIndexOf("."));
|
||||
QString filesuffix="";
|
||||
if (jsonObject["type"].toString()=="image/jpeg"){filesuffix=".jpg";}
|
||||
if (jsonObject["type"].toString()=="image/jpeg" || jsonObject["type"].toString()=="image/jpg"){filesuffix=".jpg";}
|
||||
else if (jsonObject["type"].toString()=="image/png"){filesuffix=".png";}
|
||||
else {filesuffix="";}
|
||||
if (helpfilename==""){// check if file has any filename
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue