summaryrefslogtreecommitdiffstats
path: root/qt-ui/subsurfacewebservices.h
blob: 2b454ebc7a0450f159b626111c7f9e6d16803ad8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef SUBSURFACEWEBSERVICES_H
#define SUBSURFACEWEBSERVICES_H

#include <QDialog>
#include <QNetworkReply>
#include <QTemporaryFile>
#include <QTimer>
#include <libxml/tree.h>

#include "ui_webservices.h"

class QAbstractButton;
class QHttpMultiPart;

class WebServices : public QDialog {
	Q_OBJECT
public:
	explicit WebServices(QWidget *parent = 0, Qt::WindowFlags f = 0);
	void hidePassword();
	void hideUpload();
	void hideDownload();

	static QNetworkAccessManager *manager();

private
slots:
	virtual void startDownload() = 0;
	virtual void startUpload() = 0;
	virtual void buttonClicked(QAbstractButton *button) = 0;
	virtual void downloadTimedOut();

protected
slots:
	void updateProgress(qint64 current, qint64 total);

protected:
	void resetState();
	void connectSignalsForDownload(QNetworkReply *reply);
	void connectSignalsForUpload();

	Ui::WebServices ui;
	QNetworkReply *reply;
	QTimer timeout;
	QByteArray downloadedData;
	QString defaultApplyText;
	QString userAgent;
};

class SubsurfaceWebServices : public WebServices {
	Q_OBJECT
public:
	explicit SubsurfaceWebServices(QWidget *parent = 0, Qt::WindowFlags f = 0);

private
slots:
	void startDownload();
	void buttonClicked(QAbstractButton *button);
	void downloadFinished();
	void downloadError(QNetworkReply::NetworkError error);
	void startUpload()
	{
	} /*no op*/
private:
	void setStatusText(int status);
	void download_dialog_traverse_xml(xmlNodePtr node, unsigned int *download_status);
	unsigned int download_dialog_parse_response(const QByteArray &length);
};

class DivelogsDeWebServices : public WebServices {
	Q_OBJECT
public:
	static DivelogsDeWebServices *instance();
	void downloadDives();
	void prepareDivesForUpload(bool selected);

private
slots:
	void startDownload();
	void buttonClicked(QAbstractButton *button);
	void saveToZipFile();
	void listDownloadFinished();
	void downloadFinished();
	void uploadFinished();
	void downloadError(QNetworkReply::NetworkError error);
	void uploadError(QNetworkReply::NetworkError error);
	void startUpload();

private:
	void uploadDives(QIODevice *dldContent);
	explicit DivelogsDeWebServices(QWidget *parent = 0, Qt::WindowFlags f = 0);
	void setStatusText(int status);
	bool prepare_dives_for_divelogs(const QString &filename, bool selected);
	void download_dialog_traverse_xml(xmlNodePtr node, unsigned int *download_status);
	unsigned int download_dialog_parse_response(const QByteArray &length);

	QHttpMultiPart *multipart;
	QTemporaryFile zipFile;
	bool uploadMode;
};

class UserSurveyServices : public WebServices {
	Q_OBJECT
public:
	QNetworkReply* sendSurvey(QString values);
	explicit UserSurveyServices(QWidget *parent = 0, Qt::WindowFlags f = 0);
private
slots:
	// need to declare them as no ops or Qt4 is unhappy
	virtual void startDownload() { }
	virtual void startUpload() { }
	virtual void buttonClicked(QAbstractButton *button) { }
};

class CloudStorageAuthenticate : public QObject {
	Q_OBJECT
public:
	QNetworkReply* backend(QString email, QString password, QString pin = "", QString newpasswd = "");
	explicit CloudStorageAuthenticate(QObject *parent);
signals:
	void finishedAuthenticate();
	void passwordChangeSuccessful();
private
slots:
	void uploadError(QNetworkReply::NetworkError error);
	void sslErrors(QList<QSslError> errorList);
	void uploadFinished();
private:
	QNetworkReply *reply;
	QString userAgent;

};

#ifdef __cplusplus
extern "C" {
#endif
extern void set_save_userid_local(short value);
extern void set_userid(char *user_id);
#ifdef __cplusplus
}
#endif

#endif // SUBSURFACEWEBSERVICES_H