2013-06-06 13:33:15 +00:00
|
|
|
#ifndef SUBSURFACEWEBSERVICES_H
|
|
|
|
#define SUBSURFACEWEBSERVICES_H
|
|
|
|
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QNetworkReply>
|
2013-11-15 02:57:09 +00:00
|
|
|
#include <QTemporaryFile>
|
2013-11-15 01:47:35 +00:00
|
|
|
#include <QTimer>
|
2013-06-06 14:31:55 +00:00
|
|
|
#include <libxml/tree.h>
|
2013-06-06 13:33:15 +00:00
|
|
|
|
2013-10-25 00:30:21 +00:00
|
|
|
#include "ui_webservices.h"
|
2013-10-03 18:54:25 +00:00
|
|
|
|
2013-06-06 13:33:15 +00:00
|
|
|
class QAbstractButton;
|
|
|
|
class QNetworkReply;
|
2013-11-15 02:57:09 +00:00
|
|
|
class QHttpMultiPart;
|
2013-06-06 13:33:15 +00:00
|
|
|
|
2013-10-25 00:30:21 +00:00
|
|
|
class WebServices : public QDialog{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2013-11-14 22:39:17 +00:00
|
|
|
explicit WebServices(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
2013-10-25 00:30:21 +00:00
|
|
|
void hidePassword();
|
|
|
|
void hideUpload();
|
2013-11-15 02:57:09 +00:00
|
|
|
void hideDownload();
|
2013-10-25 00:30:21 +00:00
|
|
|
|
2013-11-14 22:55:49 +00:00
|
|
|
static QNetworkAccessManager *manager();
|
|
|
|
|
2013-10-25 00:30:21 +00:00
|
|
|
private slots:
|
|
|
|
virtual void startDownload() = 0;
|
2013-10-25 00:52:11 +00:00
|
|
|
virtual void startUpload() = 0;
|
2013-10-25 00:30:21 +00:00
|
|
|
virtual void buttonClicked(QAbstractButton* button) = 0;
|
2013-11-15 01:47:35 +00:00
|
|
|
virtual void downloadTimedOut();
|
2013-10-25 00:30:21 +00:00
|
|
|
|
2013-11-15 00:52:08 +00:00
|
|
|
protected slots:
|
|
|
|
void updateProgress(qint64 current, qint64 total);
|
|
|
|
|
2013-10-25 00:30:21 +00:00
|
|
|
protected:
|
2013-11-15 00:50:46 +00:00
|
|
|
void resetState();
|
2013-11-15 00:52:08 +00:00
|
|
|
void connectSignalsForDownload(QNetworkReply *reply);
|
2013-11-15 02:57:09 +00:00
|
|
|
void connectSignalsForUpload();
|
2013-11-15 00:50:46 +00:00
|
|
|
|
2013-10-25 00:30:21 +00:00
|
|
|
Ui::WebServices ui;
|
|
|
|
QNetworkReply *reply;
|
2013-11-15 01:47:35 +00:00
|
|
|
QTimer timeout;
|
2013-10-25 00:30:21 +00:00
|
|
|
QByteArray downloadedData;
|
2013-12-09 17:23:32 +00:00
|
|
|
QString defaultApplyText;
|
2013-10-25 00:30:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SubsurfaceWebServices : public WebServices {
|
2013-06-06 13:33:15 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static SubsurfaceWebServices* instance();
|
2013-10-25 00:52:11 +00:00
|
|
|
|
2013-06-06 13:33:15 +00:00
|
|
|
private slots:
|
|
|
|
void startDownload();
|
|
|
|
void buttonClicked(QAbstractButton* button);
|
|
|
|
void downloadFinished();
|
|
|
|
void downloadError(QNetworkReply::NetworkError error);
|
2013-10-25 00:52:11 +00:00
|
|
|
void startUpload(){} /*no op*/
|
2013-06-06 13:33:15 +00:00
|
|
|
private:
|
2013-11-14 22:39:17 +00:00
|
|
|
explicit SubsurfaceWebServices(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
2013-06-06 14:31:55 +00:00
|
|
|
void setStatusText(int status);
|
|
|
|
void download_dialog_traverse_xml(xmlNodePtr node, unsigned int *download_status);
|
|
|
|
unsigned int download_dialog_parse_response(const QByteArray& length);
|
2013-06-06 13:33:15 +00:00
|
|
|
};
|
|
|
|
|
2013-10-25 00:52:11 +00:00
|
|
|
class DivelogsDeWebServices : public WebServices {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static DivelogsDeWebServices * instance();
|
2013-11-15 02:57:09 +00:00
|
|
|
void downloadDives();
|
2013-12-05 16:28:28 +00:00
|
|
|
void prepareDivesForUpload();
|
2013-10-25 00:52:11 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void startDownload();
|
|
|
|
void buttonClicked(QAbstractButton* button);
|
2013-11-15 02:57:09 +00:00
|
|
|
void saveToZipFile();
|
|
|
|
void listDownloadFinished();
|
2013-10-25 00:52:11 +00:00
|
|
|
void downloadFinished();
|
2013-11-15 02:57:09 +00:00
|
|
|
void uploadFinished();
|
2013-10-25 00:52:11 +00:00
|
|
|
void downloadError(QNetworkReply::NetworkError error);
|
2013-11-15 02:57:09 +00:00
|
|
|
void uploadError(QNetworkReply::NetworkError error);
|
2013-11-14 22:39:17 +00:00
|
|
|
void startUpload();
|
2013-10-25 00:52:11 +00:00
|
|
|
private:
|
2013-12-05 16:28:28 +00:00
|
|
|
void uploadDives(QIODevice *dldContent);
|
2013-11-14 22:39:17 +00:00
|
|
|
explicit DivelogsDeWebServices (QWidget* parent = 0, Qt::WindowFlags f = 0);
|
2013-10-25 00:52:11 +00:00
|
|
|
void setStatusText(int status);
|
|
|
|
void download_dialog_traverse_xml(xmlNodePtr node, unsigned int *download_status);
|
|
|
|
unsigned int download_dialog_parse_response(const QByteArray& length);
|
2013-11-15 02:57:09 +00:00
|
|
|
|
|
|
|
QHttpMultiPart *multipart;
|
|
|
|
QTemporaryFile zipFile;
|
2013-12-09 17:23:32 +00:00
|
|
|
bool uploadMode;
|
2013-10-25 00:52:11 +00:00
|
|
|
};
|
|
|
|
|
2013-10-03 18:54:25 +00:00
|
|
|
#endif
|