Moved the from and to locations out of HttpClient into main, and added set/get method...
[ptas] / zouba / qt / httpclient_p.cpp
1 #include "httpclient_p.h"
2 #include "location.h"
3
4 #include <QXmlStreamReader>
5 #include <QDebug>
6
7 HttpClientPrivate::HttpClientPrivate( QObject *parent ) :
8     m_fromLocation(0,0),
9     m_toLocation(0,0)
10 {
11 }
12
13 HttpClientPrivate::~HttpClientPrivate()
14 {
15 }
16
17 RouteData HttpClientPrivate::parseReply( const QByteArray &reply )
18 {
19   RouteData retVal;
20
21   QXmlStreamReader xml( reply );
22
23   bool inLine = false;
24   bool inStop = false;
25   while ( !xml.atEnd() ) {
26     xml.readNext();
27     if ( xml.isStartElement() && xml.name() == "LINE" ) {
28       QString lineCode( xml.attributes().value("code").toString() );
29
30       retVal.lineCode = lineCode;
31
32       inLine = true;
33     } else
34     if ( inLine && xml.name() == "STOP" ) {
35       inStop = true;
36     } else
37     if ( inLine && inStop && xml.name() == "ARRIVAL" ) {
38       QString arrivalTime( xml.attributes().value("time").toString() );
39
40       retVal.arrivalTime = arrivalTime;
41
42       inLine = false;
43     } else
44     if ( xml.isEndElement() && xml.name() == "STOP" ) {
45       inStop = false;
46     } else
47     if ( xml.isEndElement() && xml.name() == "LINE" ) {
48       inLine = false;
49     }
50   }
51
52   if ( xml.hasError() ) {
53     qDebug() << "xml error";
54   }
55
56   return retVal;
57 }
58
59 void HttpClientPrivate::setFromLocation( Location fromLocation )
60 {
61   m_fromLocation = fromLocation;
62 }
63
64 Location HttpClientPrivate::fromLocation()
65 {
66   return m_fromLocation;
67 }
68
69 void HttpClientPrivate::setToLocation( Location toLocation )
70 {
71   m_toLocation = toLocation;
72 }
73
74 Location HttpClientPrivate::toLocation()
75
76 {
77   return m_toLocation;
78 }