diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-06-06 10:33:15 -0300 |
---|---|---|
committer | Tomaz Canabrava <tcanabrava@kde.org> | 2013-06-06 10:33:15 -0300 |
commit | c1cf6c02a8a82296840d3a4c6948bc04a5bb5e51 (patch) | |
tree | cc689ef4b77cf3f53445e7f9d93475d71693e305 /qt-ui/subsurfacewebservices.cpp | |
parent | 74d23ed83b0fe4a2270adc41b5a9bd20b7ca5d29 (diff) | |
download | subsurface-c1cf6c02a8a82296840d3a4c6948bc04a5bb5e51.tar.gz |
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 <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui/subsurfacewebservices.cpp')
-rw-r--r-- | qt-ui/subsurfacewebservices.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
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 <QNetworkAccessManager> +#include <QNetworkReply> +#include <QDebug> + +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<QPair<QString,QString> >() << 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(); +} |