summaryrefslogtreecommitdiffstats
path: root/core/uploadDiveShare.cpp
blob: 67354d084fe6882b0ea10420690429b01e79848c (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
// SPDX-License-Identifier: GPL-2.0
#include "uploadDiveShare.h"
#include <QDebug>
#include "core/membuffer.h"
#include "core/settings/qPrefCloudStorage.h"
#include "core/qthelper.h"
#include "core/cloudstorage.h"
#include "core/save-html.h"
#include "core/errorhelper.h"


uploadDiveShare *uploadDiveShare::instance()
{
	static uploadDiveShare *self = new uploadDiveShare;

	return self;
}


uploadDiveShare::uploadDiveShare():
	reply(NULL)
{
	timeout.setSingleShot(true);
}


void uploadDiveShare::doUpload(bool selected, const QString &uid, bool noPublic)
{
}


void uploadDiveShare::slot_updateProgress(qint64 current, qint64 total)
{
	if (!reply)
		return;
	if (total <= 0 || current <= 0)
		return;

	// Calculate percentage
	// And signal whoever wants to know
	qreal percentage = (float)current / (float)total;
	emit uploadProgress(percentage, 1.0);

	// reset the timer: 30 seconds after we last got any data
	timeout.start();
}


void uploadDiveShare::slot_uploadFinished()
{
	reply->deleteLater();
	timeout.stop();
	if (reply->error() != 0)  {
		emit uploadFinish(false, reply->errorString());
	} else {
		emit uploadFinish(true, tr("Upload successful"));
	}
}


void uploadDiveShare::slot_uploadTimeout()
{
	timeout.stop();
	if (reply) {
		reply->deleteLater();
		reply = NULL;
	}
	QString err(tr("divelogs.de not responding"));
	report_error(err.toUtf8());
	emit uploadFinish(false, err);
}


void uploadDiveShare::slot_uploadError(QNetworkReply::NetworkError error)
{
	timeout.stop();
	if (reply) {
		reply->deleteLater();
		reply = NULL;
	}
	QString err(tr("network error %1").arg(error));
	report_error(err.toUtf8());
	emit uploadFinish(false, err);
}