mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
Kent University Part 2 of 3
.. custom uploader, using CSV. .. requires updating to support custom fields like RPE/ROF but committing whilst trying to resolve a bug related to the FOLDER_ID configuration setting.
This commit is contained in:
@@ -185,6 +185,7 @@ CloudService::compressRide(RideFile*ride, QByteArray &data, QString name)
|
||||
case TCX: spec="tcx"; break;
|
||||
case PWX: spec="pwx"; break;
|
||||
case FIT: spec="fit"; break;
|
||||
case CSV: spec="csv"; break;
|
||||
}
|
||||
|
||||
QFile jsonFile(tempfile.fileName());
|
||||
|
||||
@@ -191,7 +191,7 @@ class CloudService : public QObject {
|
||||
|
||||
CompressionType uploadCompression;
|
||||
CompressionType downloadCompression;
|
||||
enum uploadType { JSON, TCX, PWX, FIT } filetype;
|
||||
enum uploadType { JSON, TCX, PWX, FIT, CSV } filetype;
|
||||
|
||||
bool useMetric; // CloudService know distance or duration metadata (eg Today's Plan)
|
||||
bool useEndDate; // Dates for file entries use end date time not start (weird, I know, but thats how SixCycle work)
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include "Secrets.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#include "RideItem.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
@@ -90,7 +92,13 @@ KentUniversity::KentUniversity(Context *context)
|
||||
}
|
||||
root_ = NULL;
|
||||
|
||||
uploadCompression = none; // gzip
|
||||
downloadCompression = none;
|
||||
filetype = uploadType::CSV;
|
||||
useMetric = true; // distance and duration metadata
|
||||
|
||||
// config
|
||||
settings.clear();
|
||||
settings.insert(Combo1, QString("%1::Scope::drive::drive.appdata::drive.file").arg(GC_UOK_GOOGLE_DRIVE_AUTH_SCOPE));
|
||||
settings.insert(OAuthToken, GC_UOK_GOOGLE_DRIVE_ACCESS_TOKEN);
|
||||
settings.insert(Folder, GC_UOK_GOOGLE_DRIVE_FOLDER);
|
||||
@@ -757,6 +765,79 @@ KentUniversity::FileInfo* KentUniversity::BuildDirectoriesForAthleteDirectory(
|
||||
return fi;
|
||||
}
|
||||
|
||||
KentUniversityUploadDialog::KentUniversityUploadDialog(QWidget *parent, CloudService *store, RideItem *item) : QDialog(parent), store(store), item(item)
|
||||
{
|
||||
// setup the gui!
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
info = new QLabel(QString(tr("Uploading %1 bytes...")).arg(data.size()));
|
||||
layout->addWidget(info);
|
||||
|
||||
progress = new QProgressBar(this);
|
||||
progress->setMaximum(0);
|
||||
progress->setValue(0);
|
||||
layout->addWidget(progress);
|
||||
|
||||
okcancel = new QPushButton(tr("Cancel"));
|
||||
QHBoxLayout *buttons = new QHBoxLayout;
|
||||
buttons->addStretch();
|
||||
buttons->addWidget(okcancel);
|
||||
layout->addLayout(buttons);
|
||||
|
||||
// lets open the store
|
||||
QStringList errors;
|
||||
status = store->open(errors);
|
||||
|
||||
// compress and upload if opened successfully.
|
||||
if (status == true) {
|
||||
|
||||
// get a compressed version
|
||||
store->compressRide(item->ride(), data, QFileInfo(item->fileName).baseName() + ".json");
|
||||
|
||||
// ok, so now we can kickoff the upload
|
||||
status = store->writeFile(data, QFileInfo(item->fileName).baseName() + store->uploadExtension(), item->ride());
|
||||
}
|
||||
|
||||
// if the upload failed in any way, bail out
|
||||
if (status == false) {
|
||||
|
||||
// didn't work dude
|
||||
QMessageBox msgBox;
|
||||
msgBox.setWindowTitle(tr("Upload Failed") + store->uiName());
|
||||
msgBox.setText(tr("Unable to upload, check your configuration in preferences."));
|
||||
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.exec();
|
||||
|
||||
QWidget::hide(); // don't show just yet...
|
||||
QApplication::processEvents();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// get notification when done
|
||||
connect(store, SIGNAL(writeComplete(QString,QString)), this, SLOT(completed(QString,QString)));
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
KentUniversityUploadDialog::exec()
|
||||
{
|
||||
if (status) return QDialog::exec();
|
||||
else {
|
||||
QDialog::accept();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
KentUniversityUploadDialog::completed(QString file, QString message)
|
||||
{
|
||||
info->setText(file + "\n" + message);
|
||||
progress->setMaximum(1);
|
||||
progress->setValue(1);
|
||||
okcancel->setText(tr("OK"));
|
||||
connect(okcancel, SIGNAL(clicked()), this, SLOT(accept()));
|
||||
}
|
||||
|
||||
static bool addKentUniversity() {
|
||||
CloudServiceFactory::instance().addService(new KentUniversity(NULL));
|
||||
|
||||
@@ -121,4 +121,28 @@ class KentUniversity : public GoogleDrive {
|
||||
QMutex mu_;
|
||||
};
|
||||
|
||||
// SPECIAL UPLOADER dialog to upload a single rideitem but ensure
|
||||
// the relevant metadata and data quality is completed.
|
||||
class KentUniversityUploadDialog : public QDialog
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
KentUniversityUploadDialog(QWidget *parent, CloudService *store, RideItem *item);
|
||||
|
||||
QLabel *info; // how much being uploaded / status
|
||||
QProgressBar *progress; // whilst we wait
|
||||
QPushButton *okcancel; // cancel whilst occurring, ok once done
|
||||
|
||||
public slots:
|
||||
int exec();
|
||||
void completed(QString name, QString message);
|
||||
|
||||
private:
|
||||
CloudService *store;
|
||||
RideItem *item;
|
||||
QByteArray data; // compressed data to upload
|
||||
bool status; // did upload get kicked off ok?
|
||||
};
|
||||
#endif // GC_KENT_UNI_H
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
#if QT_VERSION > 0x050000
|
||||
#include "Dropbox.h"
|
||||
#include "GoogleDrive.h"
|
||||
#include "KentUniversity.h"
|
||||
#include "SixCycle.h"
|
||||
#endif
|
||||
#include "AddCloudWizard.h"
|
||||
@@ -2048,8 +2049,17 @@ MainWindow::uploadCloud(QAction *action)
|
||||
{
|
||||
// upload current ride, if we have one
|
||||
if (currentTab->context->ride) {
|
||||
CloudService *db = CloudServiceFactory::instance().newService(action->data().toString(), currentTab->context);
|
||||
CloudService::upload(this, db, currentTab->context->ride);
|
||||
|
||||
if (action->text() == "University of Kent") {
|
||||
#if QT_VERSION > 0x50000
|
||||
CloudService *db = CloudServiceFactory::instance().newService(action->data().toString(), currentTab->context);
|
||||
KentUniversityUploadDialog uploader(this, db, currentTab->context->ride);
|
||||
int ret = uploader.exec();
|
||||
#endif
|
||||
} else {
|
||||
CloudService *db = CloudServiceFactory::instance().newService(action->data().toString(), currentTab->context);
|
||||
CloudService::upload(this, db, currentTab->context->ride);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2237,10 +2247,14 @@ MainWindow::setUploadMenu()
|
||||
if (!s || appsettings->cvalue(currentTab->context->athlete->cyclist, s->activeSettingName(), "false").toString() != "true") continue;
|
||||
|
||||
if (s->capabilities() & CloudService::Upload) {
|
||||
|
||||
// we need the technical name to identify the service to be called
|
||||
QAction *service = new QAction(NULL);
|
||||
service->setText(s->uiName());
|
||||
service->setData(name);
|
||||
|
||||
// Kent doesn't use the standard uploader, we trap for that
|
||||
// in the upload action method
|
||||
uploadMenu->addAction(service);
|
||||
}
|
||||
}
|
||||
@@ -2256,6 +2270,10 @@ MainWindow::setSyncMenu()
|
||||
if (!s || appsettings->cvalue(currentTab->context->athlete->cyclist, s->activeSettingName(), "false").toString() != "true") continue;
|
||||
|
||||
if (s->capabilities() & CloudService::Query) {
|
||||
|
||||
// We don't sync with Kent
|
||||
if (s->id() == "University of Kent") continue;
|
||||
|
||||
// we need the technical name to identify the service to be called
|
||||
QAction *service = new QAction(NULL);
|
||||
service->setText(s->uiName());
|
||||
|
||||
Reference in New Issue
Block a user