1 #include "httpclient.h"
5 #include <QNetworkAccessManager>
6 #include <QNetworkReply>
10 #include <QStringList>
12 #include <QXmlStreamReader>
15 QUrl ytv( "http://api.reittiopas.fi/public-ytv/fi/api/" );
16 QString username( "zouba" );
17 QString password( "caf9r3ee" );
19 QString homeKey( "taivaanvuohentie%207%2Chelsinki" );
20 QString workKey( "it%E4merenkatu%2011%2Chelsinki" );
22 QString workX( "2551042" );
23 QString workY( "6672829" );
24 QString homeX( "2549183" );
25 QString homeY( "6672570" );
28 HttpClient::HttpClient( Ui::MainWindow *ui ) :
29 manager( new QNetworkAccessManager(this) ),
32 connect( manager, SIGNAL( finished(QNetworkReply*) ), this, SLOT( replyFinished(QNetworkReply*) ) );
35 HttpClient::~HttpClient()
41 void HttpClient::get()
50 fullUrl.addQueryItem( "a", a.join(",") );
51 fullUrl.addQueryItem( "b", b.join(",") );
52 fullUrl.addQueryItem( "user", username );
53 fullUrl.addQueryItem( "pass", password );
55 manager->get( QNetworkRequest( fullUrl ) );
58 void HttpClient::replyFinished( QNetworkReply * reply )
60 QXmlStreamReader xml( reply->readAll() );
64 while ( !xml.atEnd() ) {
66 //qDebug() << xml.name();
67 if ( xml.isStartElement() && xml.name() == "LINE" ) {
68 QString lineCode( xml.attributes().value("code").toString() );
70 qDebug() << "line code" << lineCode;
71 ui->BusNoDisplay->setText( lineCode );
75 if ( inLine && xml.name() == "STOP" ) {
78 if ( inLine && inStop && xml.name() == "ARRIVAL" ) {
79 QString arrivalTime( xml.attributes().value("time").toString() );
81 qDebug() << "arrival time" << arrivalTime;
82 ui->TimeDisplay->setText( arrivalTime );
86 if ( xml.isEndElement() && xml.name() == "STOP" ) {
89 if ( xml.isEndElement() && xml.name() == "LINE" ) {
94 if ( xml.hasError() ) {
95 qDebug() << "xml error";