From 4cdb80c4cd3836fdbacf50f62e9c76f0efca244b Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Sun, 21 Sep 2014 16:11:58 +0200 Subject: Export to DiveShare Adds the possibility of exporting dives to DiveShare. Signed-off-by: Salvo 'LtWorf' Tomaselli Signed-off-by: Dirk Hohndel --- qt-ui/divelogexportdialog.cpp | 5 + qt-ui/divelogexportdialog.ui | 10 ++ qt-ui/diveshareexportdialog.cpp | 142 +++++++++++++++++++++ qt-ui/diveshareexportdialog.h | 34 +++++ qt-ui/diveshareexportdialog.ui | 268 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 459 insertions(+) create mode 100644 qt-ui/diveshareexportdialog.cpp create mode 100644 qt-ui/diveshareexportdialog.h create mode 100644 qt-ui/diveshareexportdialog.ui (limited to 'qt-ui') diff --git a/qt-ui/divelogexportdialog.cpp b/qt-ui/divelogexportdialog.cpp index 3f9373a4f..6b847a425 100644 --- a/qt-ui/divelogexportdialog.cpp +++ b/qt-ui/divelogexportdialog.cpp @@ -9,6 +9,7 @@ #include "mainwindow.h" #include "divelogexportdialog.h" +#include "diveshareexportdialog.h" #include "ui_divelogexportdialog.h" #include "subsurfacewebservices.h" #include "worldmap-save.h" @@ -70,6 +71,8 @@ void DiveLogExportDialog::showExplanation() ui->description->setText(tr("Comma separated values that include the most relevant information of the dive profile.")); } else if (ui->exportDivelogs->isChecked()) { ui->description->setText(tr("Send the dive data to divelogs.de website.")); + } else if (ui->exportDiveshare->isChecked()) { + ui->description->setText(tr("Send the dive data to dive-share.appspot.com website")); } else if (ui->exportWorldMap->isChecked()) { ui->description->setText(tr("HTML export of the dive locations, visualized on a world map.")); } else if (ui->exportSubsurfaceXML->isChecked()) { @@ -245,6 +248,8 @@ void DiveLogExportDialog::on_buttonBox_accepted() tr("CSV files (*.csv *.CSV)")); } else if (ui->exportDivelogs->isChecked()) { DivelogsDeWebServices::instance()->prepareDivesForUpload(ui->exportSelected->isChecked()); + } else if (ui->exportDiveshare->isChecked()) { + DiveShareExportDialog::instance()->prepareDivesForUpload(ui->exportSelected->isChecked()); } else if (ui->exportWorldMap->isChecked()) { filename = QFileDialog::getSaveFileName(this, tr("Export world map"), lastDir, tr("HTML files (*.html)")); diff --git a/qt-ui/divelogexportdialog.ui b/qt-ui/divelogexportdialog.ui index b54d2eac6..aaa485eb3 100644 --- a/qt-ui/divelogexportdialog.ui +++ b/qt-ui/divelogexportdialog.ui @@ -153,6 +153,16 @@ + + + + DiveShare + + + exportGroup + + + diff --git a/qt-ui/diveshareexportdialog.cpp b/qt-ui/diveshareexportdialog.cpp new file mode 100644 index 000000000..8f817ae63 --- /dev/null +++ b/qt-ui/diveshareexportdialog.cpp @@ -0,0 +1,142 @@ +#include "diveshareexportdialog.h" +#include "ui_diveshareexportdialog.h" +#include "mainwindow.h" +#include "save-html.h" +#include "qt-ui/usersurvey.h" +#include "qt-ui/subsurfacewebservices.h" + +#include +#include +#include + +DiveShareExportDialog::DiveShareExportDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::DiveShareExportDialog), + reply(NULL) +{ + ui->setupUi(this); +} + +DiveShareExportDialog::~DiveShareExportDialog() +{ + delete ui; + delete reply; +} + +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", UserSurvey::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())); +} diff --git a/qt-ui/diveshareexportdialog.h b/qt-ui/diveshareexportdialog.h new file mode 100644 index 000000000..85dadf5f1 --- /dev/null +++ b/qt-ui/diveshareexportdialog.h @@ -0,0 +1,34 @@ +#ifndef DIVESHAREEXPORTDIALOG_H +#define DIVESHAREEXPORTDIALOG_H + +#include +#include +#include + +#define DIVESHARE_WEBSITE "dive-share.appspot.com" +#define DIVESHARE_BASE_URI "http://" DIVESHARE_WEBSITE + +namespace Ui { +class DiveShareExportDialog; +} + +class DiveShareExportDialog : public QDialog +{ + Q_OBJECT +public: + explicit DiveShareExportDialog(QWidget *parent = 0); + ~DiveShareExportDialog(); + static DiveShareExportDialog *instance(); + void prepareDivesForUpload(bool); +private: + Ui::DiveShareExportDialog *ui; + bool exportSelected; + QNetworkReply *reply; +private +slots: + void UIDFromBrowser(); + void doUpload(); + void finishedSlot(); +}; + +#endif // DIVESHAREEXPORTDIALOG_H diff --git a/qt-ui/diveshareexportdialog.ui b/qt-ui/diveshareexportdialog.ui new file mode 100644 index 000000000..051f4f3e2 --- /dev/null +++ b/qt-ui/diveshareexportdialog.ui @@ -0,0 +1,268 @@ + + + DiveShareExportDialog + + + + 0 + 0 + 320 + 309 + + + + Dialog + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + + + + + + User ID + + + + + + + + + + + + + + + + + true + + + + + + + Get UserID + + + + + + + + + <html><head/><body><p><span style=" font-size:20pt; font-weight:600; color:#ff8000;">⚠</span> Not using a UserID means that you will need to manually keep bookmarks to your dives, to find them again.</p></body></html> + + + Qt::AutoText + + + true + + + + + + + Private dives will not appear in "related dives" lists, and will only be accessible if their URL is known. + + + Keep dives private + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Upload dive data + + + false + + + true + + + + + + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + + + true + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://www.google.com"><span style=" text-decoration: underline; color:#0000ff;">asd</span></a></p></body></html> + + + true + + + + + + + 24 + + + + + + + + + + Qt::Vertical + + + + 20 + 68 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel + + + + + + + + + buttonBox + rejected() + DiveShareExportDialog + reject() + + + 97 + 299 + + + 286 + 252 + + + + + getUIDbutton + clicked() + DiveShareExportDialog + UIDFromBrowser() + + + 223 + 29 + + + 159 + 215 + + + + + doUploadButton + clicked() + DiveShareExportDialog + doUpload() + + + 223 + 120 + + + 159 + 215 + + + + + cmdClear + clicked() + txtUID + clear() + + + 148 + 36 + + + 105 + 27 + + + + + buttonBox + accepted() + DiveShareExportDialog + accept() + + + 159 + 288 + + + 159 + 154 + + + + + + getUID() + doUpload() + + -- cgit v1.2.3-70-g09d2