2017-04-27 20:26:05 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-06-06 10:33:15 -03:00
|
|
|
#ifndef SUBSURFACEWEBSERVICES_H
|
|
|
|
#define SUBSURFACEWEBSERVICES_H
|
|
|
|
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QNetworkReply>
|
2013-11-14 18:57:09 -08:00
|
|
|
#include <QTemporaryFile>
|
2013-11-14 17:47:35 -08:00
|
|
|
#include <QTimer>
|
2013-06-06 11:31:55 -03:00
|
|
|
#include <libxml/tree.h>
|
2013-06-06 10:33:15 -03:00
|
|
|
|
2013-10-24 22:30:21 -02:00
|
|
|
#include "ui_webservices.h"
|
2013-10-03 11:54:25 -07:00
|
|
|
|
2013-06-06 10:33:15 -03:00
|
|
|
class QAbstractButton;
|
2013-11-14 18:57:09 -08:00
|
|
|
class QHttpMultiPart;
|
2013-06-06 10:33:15 -03:00
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
class WebServices : public QDialog {
|
2013-10-24 22:30:21 -02:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-02-27 20:09:57 -08:00
|
|
|
explicit WebServices(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
2013-10-24 22:30:21 -02:00
|
|
|
void hidePassword();
|
|
|
|
void hideUpload();
|
2013-11-14 18:57:09 -08:00
|
|
|
void hideDownload();
|
2013-10-24 22:30:21 -02:00
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
private
|
|
|
|
slots:
|
2013-10-24 22:30:21 -02:00
|
|
|
virtual void startDownload() = 0;
|
2013-10-24 22:52:11 -02:00
|
|
|
virtual void startUpload() = 0;
|
2014-02-27 20:09:57 -08:00
|
|
|
virtual void buttonClicked(QAbstractButton *button) = 0;
|
2013-11-14 17:47:35 -08:00
|
|
|
virtual void downloadTimedOut();
|
2013-10-24 22:30:21 -02:00
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
protected
|
|
|
|
slots:
|
2013-11-14 16:52:08 -08:00
|
|
|
void updateProgress(qint64 current, qint64 total);
|
|
|
|
|
2013-10-24 22:30:21 -02:00
|
|
|
protected:
|
2013-11-14 16:50:46 -08:00
|
|
|
void resetState();
|
2013-11-14 16:52:08 -08:00
|
|
|
void connectSignalsForDownload(QNetworkReply *reply);
|
2013-11-14 18:57:09 -08:00
|
|
|
void connectSignalsForUpload();
|
2013-11-14 16:50:46 -08:00
|
|
|
|
2013-10-24 22:30:21 -02:00
|
|
|
Ui::WebServices ui;
|
|
|
|
QNetworkReply *reply;
|
2013-11-14 17:47:35 -08:00
|
|
|
QTimer timeout;
|
2013-10-24 22:30:21 -02:00
|
|
|
QByteArray downloadedData;
|
2013-12-09 19:23:32 +02:00
|
|
|
QString defaultApplyText;
|
2014-07-31 11:20:11 -07:00
|
|
|
QString userAgent;
|
2013-10-24 22:30:21 -02:00
|
|
|
};
|
|
|
|
|
2013-10-24 22:52:11 -02:00
|
|
|
class DivelogsDeWebServices : public WebServices {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-02-27 20:09:57 -08:00
|
|
|
static DivelogsDeWebServices *instance();
|
2013-11-14 18:57:09 -08:00
|
|
|
void downloadDives();
|
2014-05-20 19:33:32 +03:00
|
|
|
void prepareDivesForUpload(bool selected);
|
2013-10-24 22:52:11 -02:00
|
|
|
|
2014-02-27 20:09:57 -08:00
|
|
|
private
|
|
|
|
slots:
|
2013-10-24 22:52:11 -02:00
|
|
|
void startDownload();
|
2014-02-27 20:09:57 -08:00
|
|
|
void buttonClicked(QAbstractButton *button);
|
2013-11-14 18:57:09 -08:00
|
|
|
void saveToZipFile();
|
|
|
|
void listDownloadFinished();
|
2013-10-24 22:52:11 -02:00
|
|
|
void downloadFinished();
|
2013-11-14 18:57:09 -08:00
|
|
|
void uploadFinished();
|
2013-10-24 22:52:11 -02:00
|
|
|
void downloadError(QNetworkReply::NetworkError error);
|
2013-11-14 18:57:09 -08:00
|
|
|
void uploadError(QNetworkReply::NetworkError error);
|
2013-11-14 14:39:17 -08:00
|
|
|
void startUpload();
|
2014-02-27 20:09:57 -08:00
|
|
|
|
2013-10-24 22:52:11 -02:00
|
|
|
private:
|
2013-12-05 18:28:28 +02:00
|
|
|
void uploadDives(QIODevice *dldContent);
|
2014-02-27 20:09:57 -08:00
|
|
|
explicit DivelogsDeWebServices(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
2013-10-24 22:52:11 -02:00
|
|
|
void setStatusText(int status);
|
2014-03-14 11:26:07 -07:00
|
|
|
bool prepare_dives_for_divelogs(const QString &filename, bool selected);
|
2013-10-24 22:52:11 -02:00
|
|
|
void download_dialog_traverse_xml(xmlNodePtr node, unsigned int *download_status);
|
2014-02-27 20:09:57 -08:00
|
|
|
unsigned int download_dialog_parse_response(const QByteArray &length);
|
2013-11-14 18:57:09 -08:00
|
|
|
|
|
|
|
QHttpMultiPart *multipart;
|
|
|
|
QTemporaryFile zipFile;
|
2013-12-09 19:23:32 +02:00
|
|
|
bool uploadMode;
|
2013-10-24 22:52:11 -02:00
|
|
|
};
|
|
|
|
|
2014-06-30 07:19:22 -07:00
|
|
|
class UserSurveyServices : public WebServices {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-07-16 17:20:21 -03:00
|
|
|
QNetworkReply* sendSurvey(QString values);
|
2014-06-30 07:19:22 -07:00
|
|
|
explicit UserSurveyServices(QWidget *parent = 0, Qt::WindowFlags f = 0);
|
2014-06-30 14:05:02 -07:00
|
|
|
private
|
|
|
|
slots:
|
|
|
|
// need to declare them as no ops or Qt4 is unhappy
|
2018-08-01 11:01:26 +02:00
|
|
|
void startDownload() { }
|
|
|
|
void startUpload() { }
|
|
|
|
void buttonClicked(QAbstractButton *button) { Q_UNUSED(button) }
|
2015-06-04 17:26:30 -07:00
|
|
|
};
|
|
|
|
|
2014-02-11 19:14:46 +01:00
|
|
|
#endif // SUBSURFACEWEBSERVICES_H
|