summaryrefslogtreecommitdiffstats
path: root/qt-ui/subsurfacewebservices.cpp
blob: 48e56aa30881fb28336d5aa8eeadb22393622bdb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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();
}