From e49d6213ad129284a45d53c3fcdc03249e84efe2 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 3 Sep 2015 14:20:19 -0300 Subject: Move qt-ui to desktop-widgets Since we have now destkop and mobile versions, 'qt-ui' was a very poor name choice for a folder that contains only destkop-enabled widgets. Also, move the graphicsview-common.h/cpp to subsurface-core because it doesn't depend on qgraphicsview, it merely implements all the colors that we use throughout Subsurface, and we will use colors on both desktop and mobile versions Same thing applies for metrics.h/cpp Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/diveshareexportdialog.cpp | 141 ++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 desktop-widgets/diveshareexportdialog.cpp (limited to 'desktop-widgets/diveshareexportdialog.cpp') diff --git a/desktop-widgets/diveshareexportdialog.cpp b/desktop-widgets/diveshareexportdialog.cpp new file mode 100644 index 000000000..9fe6eefd6 --- /dev/null +++ b/desktop-widgets/diveshareexportdialog.cpp @@ -0,0 +1,141 @@ +#include "diveshareexportdialog.h" +#include "ui_diveshareexportdialog.h" +#include "mainwindow.h" +#include "save-html.h" +#include "subsurfacewebservices.h" +#include "helpers.h" + +#include +#include + +DiveShareExportDialog::DiveShareExportDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::DiveShareExportDialog), + reply(NULL), + exportSelected(false) +{ + ui->setupUi(this); +} + +DiveShareExportDialog::~DiveShareExportDialog() +{ + delete ui; +} + +void DiveShareExportDialog::UIDFromBrowser() +{ + QDesktopServices::openUrl(QUrl(DIVESHARE_BASE_URI "/secret")); +} + +DiveShareExportDialog *DiveShareExportDialog::instance() +{ + static DiveShareExportDialog *self = new DiveShareExportDialog(MainWindow::instance()); + self->setAttribute(Qt::WA_QuitOnClose, false); + self->ui->txtResult->setHtml(""); + self->ui->buttonBox->setStandardButtons(QDialogButtonBox::Cancel); + return self; +} + +void DiveShareExportDialog::prepareDivesForUpload(bool selected) +{ + exportSelected = selected; + ui->frameConfigure->setVisible(true); + ui->frameResults->setVisible(false); + + QSettings settings; + if (settings.contains("diveshareExport/uid")) + ui->txtUID->setText(settings.value("diveshareExport/uid").toString()); + + if (settings.contains("diveshareExport/private")) + ui->chkPrivate->setChecked(settings.value("diveshareExport/private").toBool()); + + show(); +} + +static QByteArray generate_html_list(const QByteArray &data) +{ + QList dives = data.split('\n'); + QByteArray html; + html.append(""); + for (int i = 0; i < dives.length(); i++ ) { + html.append(""); + QList dive_details = dives[i].split(','); + if (dive_details.length() < 3) + continue; + + QByteArray dive_id = dive_details[0]; + QByteArray dive_delete = dive_details[1]; + + html.append(""); + html.append("" ); + + html.append(""); + } + + html.append("
"); + html.append(""); + + //Title gets separated too, this puts it back together + const char *sep = ""; + for (int t = 2; t < dive_details.length(); t++) { + html.append(sep); + html.append(dive_details[t]); + sep = ","; + } + + html.append(""); + html.append(""); + html.append("Delete dive"); + html.append("
"); + return html; +} + +void DiveShareExportDialog::finishedSlot() +{ + ui->progressBar->setVisible(false); + if (reply->error() != 0) { + ui->buttonBox->setStandardButtons(QDialogButtonBox::Cancel); + ui->txtResult->setText(reply->errorString()); + } else { + ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok); + ui->txtResult->setHtml(generate_html_list(reply->readAll())); + } + + reply->deleteLater(); +} + +void DiveShareExportDialog::doUpload() +{ + //Store current settings + QSettings settings; + settings.setValue("diveshareExport/uid", ui->txtUID->text()); + settings.setValue("diveshareExport/private", ui->chkPrivate->isChecked()); + + //Change UI into results mode + ui->frameConfigure->setVisible(false); + ui->frameResults->setVisible(true); + ui->progressBar->setVisible(true); + ui->progressBar->setRange(0, 0); + + //generate json + struct membuffer buf = { 0 }; + export_list(&buf, NULL, exportSelected, false); + QByteArray json_data(buf.buffer, buf.len); + free_buffer(&buf); + + //Request to server + QNetworkRequest request; + + if (ui->chkPrivate->isChecked()) + request.setUrl(QUrl(DIVESHARE_BASE_URI "/upload?private=true")); + else + request.setUrl(QUrl(DIVESHARE_BASE_URI "/upload")); + + request.setRawHeader("User-Agent", getUserAgent().toUtf8()); + if (ui->txtUID->text().length() != 0) + request.setRawHeader("X-UID", ui->txtUID->text().toUtf8()); + + reply = WebServices::manager()->put(request, json_data); + + QObject::connect(reply, SIGNAL(finished()), this, SLOT(finishedSlot())); +} -- cgit v1.2.3-70-g09d2