mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
7e12ac262b
commit
e8e425edd8
3 changed files with 118 additions and 0 deletions
|
|
@ -165,6 +165,8 @@ set(SUBSURFACE_CORE_LIB_SRCS
|
||||||
uemis.h
|
uemis.h
|
||||||
units.h
|
units.h
|
||||||
units.c
|
units.c
|
||||||
|
uploadDiveShare.cpp
|
||||||
|
uploadDiveShare.h
|
||||||
version.c
|
version.c
|
||||||
version.h
|
version.h
|
||||||
videoframeextractor.cpp
|
videoframeextractor.cpp
|
||||||
|
|
|
||||||
84
core/uploadDiveShare.cpp
Normal file
84
core/uploadDiveShare.cpp
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
32
core/uploadDiveShare.h
Normal file
32
core/uploadDiveShare.h
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
|
#ifndef UPLOADDIVESHARE_H
|
||||||
|
#define UPLOADDIVESHARE_H
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
|
||||||
|
class uploadDiveShare : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
static uploadDiveShare *instance();
|
||||||
|
void doUpload(bool selected, const QString &uid, bool noPublic);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void slot_updateProgress(qint64 current, qint64 total);
|
||||||
|
void slot_uploadFinished();
|
||||||
|
void slot_uploadTimeout();
|
||||||
|
void slot_uploadError(QNetworkReply::NetworkError error);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void uploadFinish(bool success, const QString &text);
|
||||||
|
void uploadProgress(qreal percentage, qreal total);
|
||||||
|
void uploadStatus(const QString &text);
|
||||||
|
|
||||||
|
private:
|
||||||
|
uploadDiveShare();
|
||||||
|
|
||||||
|
QNetworkReply *reply;
|
||||||
|
QTimer timeout;
|
||||||
|
};
|
||||||
|
#endif // UPLOADDIVESHARE_H
|
||||||
Loading…
Add table
Add a link
Reference in a new issue