summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/diveshareexportdialog.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2015-09-03 14:20:19 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-10-30 10:36:49 -0700
commite49d6213ad129284a45d53c3fcdc03249e84efe2 (patch)
tree2946a666ab38af3375e7bb2b8c5dd887d4a7f9a1 /desktop-widgets/diveshareexportdialog.cpp
parent588abd019fb2ed3f607682f2b6c7fe86a7a5bb90 (diff)
downloadsubsurface-e49d6213ad129284a45d53c3fcdc03249e84efe2.tar.gz
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 <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'desktop-widgets/diveshareexportdialog.cpp')
-rw-r--r--desktop-widgets/diveshareexportdialog.cpp141
1 files changed, 141 insertions, 0 deletions
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 <QDesktopServices>
+#include <QSettings>
+
+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<QByteArray> dives = data.split('\n');
+ QByteArray html;
+ html.append("<html><body><table>");
+ for (int i = 0; i < dives.length(); i++ ) {
+ html.append("<tr>");
+ QList<QByteArray> 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("<td>");
+ html.append("<a href=\"" DIVESHARE_BASE_URI "/dive/" + dive_id + "\">");
+
+ //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("</a>");
+ html.append("</td>");
+ html.append("<td>");
+ html.append("<a href=\"" DIVESHARE_BASE_URI "/delete/dive/" + dive_delete + "\">Delete dive</a>");
+ html.append("</td>" );
+
+ html.append("</tr>");
+ }
+
+ html.append("</table></body></html>");
+ 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()));
+}