Friendiqa/source-linux/common/xhr.h

135 lines
4.6 KiB
C
Raw Normal View History

2018-02-19 22:36:00 +01:00
// This file is part of Friendiqa
2019-06-25 20:59:10 +02:00
// https://github.com/lubuwest/Friendiqa
2020-05-24 21:14:23 +02:00
// Copyright (C) 2020 Marco R. <thomasschmidt45@gmx.net>
2018-02-19 22:36:00 +01:00
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations including
// the two.
//
// You must obey the GNU General Public License in all respects for all
// of the code used other than OpenSSL. If you modify file(s) with this
// exception, you may extend this exception to your version of the
// file(s), but you are not obligated to do so. If you do not wish to do
// so, delete this exception statement from your version. If you delete
// this exception statement from all source files in the program, then
// also delete it here.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2017-01-26 21:55:31 +01:00
#ifndef XHR_H
#define XHR_H
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QObject>
2018-02-19 22:36:00 +01:00
#include <QJsonObject>
2018-08-25 16:17:09 +02:00
#include <QNetworkConfiguration>
2017-01-26 21:55:31 +01:00
class XHR : public QObject
{
Q_OBJECT
Q_PROPERTY(QString url READ url WRITE setUrl NOTIFY urlChanged)
Q_PROPERTY(QString login READ login WRITE setLogin NOTIFY loginChanged)
Q_PROPERTY(QString filename READ filename WRITE setFilename NOTIFY filenameChanged)
2018-02-19 22:36:00 +01:00
Q_PROPERTY(QString imagedir READ imagedir WRITE setImagedir NOTIFY imagedirChanged)
Q_PROPERTY(QList<QString> contactlist READ contactlist WRITE setContactlist NOTIFY contactlistChanged)
Q_PROPERTY(QList<QString> filelist READ filelist WRITE setFilelist NOTIFY filelistChanged)
2017-01-26 21:55:31 +01:00
Q_PROPERTY(QString downloadtype READ downloadtype WRITE setDownloadtype NOTIFY downloadtypeChanged)
2020-11-25 21:40:17 +01:00
//Q_PROPERTY(QString networktype READ networktype() NOTIFY networktypeChanged)
2017-01-26 21:55:31 +01:00
public:
static XHR *instance();
explicit XHR(QObject *parent = 0);
QString url() const;
2018-07-01 15:09:21 +02:00
QString api() const;
2017-01-26 21:55:31 +01:00
QString login() const;
QString filename() const;
2018-02-19 22:36:00 +01:00
QList<QString> contactlist() const;
QList<QString> filelist() const;
QString imagedir() const;
2017-01-26 21:55:31 +01:00
QString downloadtype() const;
2020-11-25 21:40:17 +01:00
// QString networktype();
2017-01-26 21:55:31 +01:00
signals:
void urlChanged();
2018-07-01 15:09:21 +02:00
void apiChanged();
2017-01-26 21:55:31 +01:00
void loginChanged();
void filenameChanged();
2018-02-19 22:36:00 +01:00
void contactlistChanged();
void filelistChanged();
void imagedirChanged();
2017-01-26 21:55:31 +01:00
void downloadtypeChanged();
2018-08-25 16:17:09 +02:00
void networktypeChanged();
2018-02-19 22:36:00 +01:00
void downloaded(QString type, QString url, QString filename, int i);
void downloadedjson(QString type, QString url, QString filename, int i,QJsonObject jsonObject);
2019-01-09 22:03:16 +01:00
void success(QByteArray data, QString api);
2018-07-01 15:09:21 +02:00
void error(QString data, QString url,QString api, int code);
2017-01-26 21:55:31 +01:00
public slots:
void setUrl(QString url);
2018-07-01 15:09:21 +02:00
void setApi(QString api);
2017-01-26 21:55:31 +01:00
void setLogin(QString login);
void setDownloadtype(QString downloadtype);
void setFilename(QString filename);
2018-02-19 22:36:00 +01:00
void setContactlist(QList<QString> filename);
void setFilelist(QList<QString> filename);
void setImagedir(QString filename);
2017-01-26 21:55:31 +01:00
void setParam(QString name, QString value);
void setImageFileParam(QString name, QString url);
void clearParams();
void post();
void get();
2018-02-19 22:36:00 +01:00
void getlist();
2017-01-26 21:55:31 +01:00
void download();
2019-06-25 20:59:10 +02:00
2018-08-25 16:17:09 +02:00
// void networktype();
2017-01-26 21:55:31 +01:00
private slots:
void onReplyError(QNetworkReply::NetworkError code);
void onReplySuccess();
void onRequestFinished();
void onReadyRead();
void onSSLError(const QList<QSslError> &errors);
//void updateDownloadProgress(qint64 bytesRead, qint64 totalBytes);
private:
QByteArray buffer;
QString m_url;
2018-07-01 15:09:21 +02:00
QString m_api;
2017-01-26 21:55:31 +01:00
QString m_login;
QString m_filename;
QString m_downloadtype;
2020-11-25 21:40:17 +01:00
// QString m_networktype;
2017-01-26 21:55:31 +01:00
QHash<QString, QString> params;
QHash<QString, QString> files;
2018-02-19 22:36:00 +01:00
QList<QString> m_filelist;
QList<QString> m_contactlist;
QString m_imagedir;
int dlindex;
2017-01-26 21:55:31 +01:00
QNetworkAccessManager manager;
QNetworkRequest request;
QNetworkReply *reply;
2020-11-25 21:40:17 +01:00
//QNetworkConfiguration nc;
2017-01-26 21:55:31 +01:00
QString bufferToString();
};
#endif // XHR_H