From c1cf6c02a8a82296840d3a4c6948bc04a5bb5e51 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 6 Jun 2013 10:33:15 -0300 Subject: [PATCH] Added initial support for download dive info from the subsurface web service. Added initial support for download dive info from subsurface web service, the current code only downloads and output the xml downloaded in the debug area. Now I need to parse things up and plug the unplugged stuff. Signed-off-by: Tomaz Canabrava --- Configure.mk | 2 +- Makefile | 2 + qt-ui/mainwindow.cpp | 4 +- qt-ui/subsurfacewebservices.cpp | 59 ++++++++++++++++++ qt-ui/subsurfacewebservices.h | 31 ++++++++++ qt-ui/subsurfacewebservices.ui | 106 ++++++++++++++++++++++++++++++++ 6 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 qt-ui/subsurfacewebservices.cpp create mode 100644 qt-ui/subsurfacewebservices.h create mode 100644 qt-ui/subsurfacewebservices.ui diff --git a/Configure.mk b/Configure.mk index a09fcbbf1..a532d4138 100644 --- a/Configure.mk +++ b/Configure.mk @@ -106,7 +106,7 @@ ifeq ($(strip $(QMAKE)),) $(error Could not find qmake or qmake-qt4 in $$PATH for the Qt4 version they failed) endif - QT_MODULES = QtGui QtSvg + QT_MODULES = QtGui QtSvg QtNetwork QT_CORE = QtCore MOC = $(shell $(PKGCONFIG) --variable=moc_location QtCore) UIC = $(shell $(PKGCONFIG) --variable=uic_location QtGui) diff --git a/Makefile b/Makefile index e870fa3b9..ab4c8b2ef 100644 --- a/Makefile +++ b/Makefile @@ -48,6 +48,7 @@ HEADERS = \ qt-ui/downloadfromdivecomputer.h \ qt-ui/preferences.h \ qt-ui/simplewidgets.h \ + qt-ui/subsurfacewebservices.h \ SOURCES = \ @@ -80,6 +81,7 @@ SOURCES = \ qt-ui/downloadfromdivecomputer.cpp \ qt-ui/preferences.cpp \ qt-ui/simplewidgets.cpp \ + qt-ui/subsurfacewebservices.cpp \ $(RESFILE) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 3c550439b..f4d634d7f 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -28,6 +28,7 @@ #include "models.h" #include "downloadfromdivecomputer.h" #include "preferences.h" +#include "subsurfacewebservices.h" static MainWindow* instance = 0; @@ -181,7 +182,8 @@ void MainWindow::on_actionDownloadDC_triggered() void MainWindow::on_actionDownloadWeb_triggered() { - qDebug("actionDownloadWeb");} + SubsurfaceWebServices::instance()->runDialog(); +} void MainWindow::on_actionEditDeviceNames_triggered() { diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp new file mode 100644 index 000000000..48e56aa30 --- /dev/null +++ b/qt-ui/subsurfacewebservices.cpp @@ -0,0 +1,59 @@ +#include "subsurfacewebservices.h" +#include "ui_subsurfacewebservices.h" +#include +#include +#include + +SubsurfaceWebServices* SubsurfaceWebServices::instance() +{ + static SubsurfaceWebServices *self = new SubsurfaceWebServices(); + return self; +} + +SubsurfaceWebServices::SubsurfaceWebServices(QWidget* parent, Qt::WindowFlags f) +: ui( new Ui::SubsurfaceWebServices()){ + ui->setupUi(this); + connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*))); + connect(ui->download, SIGNAL(clicked(bool)), this, SLOT(startDownload())); +} + +void SubsurfaceWebServices::buttonClicked(QAbstractButton* button) +{ + +} + +void SubsurfaceWebServices::startDownload() +{ + QUrl url("http://api.hohndel.org/api/dive/get/"); + url.setQueryItems( QList >() << qMakePair(QString("login"), ui->userID->text())); + qDebug() << url; + + QNetworkAccessManager *manager = new QNetworkAccessManager(this); + QNetworkRequest request; + request.setUrl(url); + request.setRawHeader("Accept", "text/xml"); + reply = manager->get(request); + ui->progressBar->setRange(0,0); + connect(reply, SIGNAL(finished()), this, SLOT(downloadFinished())); + connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError))); +} + +void SubsurfaceWebServices::downloadFinished() +{ + ui->progressBar->setRange(0,1); + QByteArray result = reply->readAll(); + qDebug() << result; + ui->status->setText(tr("Download Finished")); +} + +void SubsurfaceWebServices::downloadError(QNetworkReply::NetworkError error) +{ + ui->progressBar->setRange(0,1); + ui->status->setText(QString::number((int)QNetworkRequest::HttpStatusCodeAttribute)); +} + + +void SubsurfaceWebServices::runDialog() +{ + show(); +} diff --git a/qt-ui/subsurfacewebservices.h b/qt-ui/subsurfacewebservices.h new file mode 100644 index 000000000..ffcc28f82 --- /dev/null +++ b/qt-ui/subsurfacewebservices.h @@ -0,0 +1,31 @@ +#ifndef SUBSURFACEWEBSERVICES_H +#define SUBSURFACEWEBSERVICES_H + +#include +#include + +namespace Ui{ + class SubsurfaceWebServices; +}; +class QAbstractButton; +class QNetworkReply; + +class SubsurfaceWebServices : public QDialog { + Q_OBJECT +public: + static SubsurfaceWebServices* instance(); + void runDialog(); + +private slots: + void startDownload(); + void buttonClicked(QAbstractButton* button); + void downloadFinished(); + void downloadError(QNetworkReply::NetworkError error); + +private: + explicit SubsurfaceWebServices(QWidget* parent = 0, Qt::WindowFlags f = 0); + Ui::SubsurfaceWebServices *ui; + QNetworkReply *reply; +}; + +#endif \ No newline at end of file diff --git a/qt-ui/subsurfacewebservices.ui b/qt-ui/subsurfacewebservices.ui new file mode 100644 index 000000000..e1232dc38 --- /dev/null +++ b/qt-ui/subsurfacewebservices.ui @@ -0,0 +1,106 @@ + + + SubsurfaceWebServices + + + + 0 + 0 + 399 + 104 + + + + Download Location Data + + + + + + 0 + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok + + + + + + + Download + + + + + + + Enter your ID here + + + + + + + User ID + + + + + + + Status: + + + + + + + + + + + + + + + + buttonBox + accepted() + SubsurfaceWebServices + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + SubsurfaceWebServices + reject() + + + 316 + 260 + + + 286 + 274 + + + + +