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;
|
|
|
|
class QNetworkReply;
|
2013-11-14 18:57:09 -08:00
|
|
|
class QHttpMultiPart;
|
2013-06-06 10:33:15 -03:00
|
|
|
|
2013-10-24 22:30:21 -02:00
|
|
|
class WebServices : public QDialog{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2013-11-14 14:39:17 -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
|
|
|
|
2013-11-14 14:55:49 -08:00
|
|
|
static QNetworkAccessManager *manager();
|
|
|
|
|
2013-10-24 22:30:21 -02:00
|
|
|
private slots:
|
|
|
|
virtual void startDownload() = 0;
|
2013-10-24 22:52:11 -02:00
|
|
|
virtual void startUpload() = 0;
|
2013-10-24 22:30:21 -02: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
|
|
|
|
2013-11-14 16:52:08 -08:00
|
|
|
protected slots:
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SubsurfaceWebServices : public WebServices {
|
2013-06-06 10:33:15 -03:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static SubsurfaceWebServices* instance();
|
2013-10-24 22:52:11 -02:00
|
|
|
|
2013-06-06 10:33:15 -03:00
|
|
|
private slots:
|
|
|
|
void startDownload();
|
|
|
|
void buttonClicked(QAbstractButton* button);
|
|
|
|
void downloadFinished();
|
|
|
|
void downloadError(QNetworkReply::NetworkError error);
|
2013-10-24 22:52:11 -02:00
|
|
|
void startUpload(){} /*no op*/
|
2013-06-06 10:33:15 -03:00
|
|
|
private:
|
2013-11-14 14:39:17 -08:00
|
|
|
explicit SubsurfaceWebServices(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
2013-06-06 11:31:55 -03: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 10:33:15 -03:00
|
|
|
};
|
|
|
|
|
2013-10-24 22:52:11 -02:00
|
|
|
class DivelogsDeWebServices : public WebServices {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static DivelogsDeWebServices * instance();
|
2013-11-14 18:57:09 -08:00
|
|
|
void downloadDives();
|
|
|
|
void uploadDives(QIODevice *dldContent);
|
2013-10-24 22:52:11 -02:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void startDownload();
|
|
|
|
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();
|
2013-10-24 22:52:11 -02:00
|
|
|
private:
|
2013-11-14 14:39:17 -08:00
|
|
|
explicit DivelogsDeWebServices (QWidget* parent = 0, Qt::WindowFlags f = 0);
|
2013-10-24 22:52:11 -02: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-14 18:57:09 -08:00
|
|
|
|
|
|
|
QHttpMultiPart *multipart;
|
|
|
|
QTemporaryFile zipFile;
|
2013-10-24 22:52:11 -02:00
|
|
|
};
|
|
|
|
|
2013-10-03 11:54:25 -07:00
|
|
|
#endif
|