summaryrefslogtreecommitdiffstats
path: root/core/uploadDiveShare.cpp
diff options
context:
space:
mode:
authorGravatar jan Iversen <jan@casacondor.com>2019-12-08 11:45:55 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-12-11 11:08:51 -0500
commite8e425edd8c92f4233c578981924c8cde832aba4 (patch)
treebaeb6a03bc8e8b800d0e5335eb82671fdb6ca321 /core/uploadDiveShare.cpp
parent7e12ac262b35bcab05bc4a7e69d8572cba5b7ef1 (diff)
downloadsubsurface-e8e425edd8c92f4233c578981924c8cde832aba4.tar.gz
core: add upload dive-share.com class
This is the framework that mobileExecutable needs, all prepared to move functionality from desktop-widgets (current implementation) into a shared version. Signed-off-by: Jan Iversen <jan@casacondor.com>
Diffstat (limited to 'core/uploadDiveShare.cpp')
-rw-r--r--core/uploadDiveShare.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/core/uploadDiveShare.cpp b/core/uploadDiveShare.cpp
new file mode 100644
index 000000000..67354d084
--- /dev/null
+++ b/core/uploadDiveShare.cpp
@@ -0,0 +1,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);
+}