7472c97985e7e35e40b406e30a93f7b29e93f56c
[ptas] / zouba / qt / route_p.cpp
1 #include "route_p.h"
2 #include "location.h"
3
4 #include <QXmlStreamReader>
5 #include <QDebug>
6
7 RoutePrivate::RoutePrivate( QObject *parent ) :
8     m_fromLocation(0,0),
9     m_toLocation(0,0)
10 {
11   Q_UNUSED( parent )
12 }
13
14 RoutePrivate::~RoutePrivate()
15 {
16 }
17
18 RouteData RoutePrivate::parseReply( const QByteArray &reply )
19 {
20   RouteData retVal;
21
22   QXmlStreamReader xml( reply );
23
24   bool inLine = false;
25   bool inStop = false;
26   while ( !xml.atEnd() ) {
27     xml.readNext();
28     if ( xml.isStartElement() && xml.name() == "LINE" ) {
29       QString lineCode( xml.attributes().value("code").toString() );
30
31       retVal.lineCode = lineCode;
32
33       inLine = true;
34     } else
35     if ( inLine && xml.name() == "STOP" ) {
36       inStop = true;
37     } else
38     if ( inLine && inStop && xml.name() == "ARRIVAL" ) {
39       QString arrivalTime( xml.attributes().value("time").toString() );
40
41       retVal.arrivalTime = arrivalTime;
42
43       inLine = false;
44     } else
45     if ( xml.isEndElement() && xml.name() == "STOP" ) {
46       inStop = false;
47     } else
48     if ( xml.isEndElement() && xml.name() == "LINE" ) {
49       inLine = false;
50     }
51   }
52
53   if ( xml.hasError() ) {
54     qDebug() << "xml error";
55   }
56
57   return retVal;
58 }
59
60 void RoutePrivate::setFromLocation( Location fromLocation )
61 {
62   m_fromLocation = fromLocation;
63 }
64
65 Location RoutePrivate::fromLocation()
66 {
67   return m_fromLocation;
68 }
69
70 void RoutePrivate::setToLocation( Location toLocation )
71 {
72   m_toLocation = toLocation;
73 }
74
75 QString RoutePrivate::parseJOREcode( const QString &joreCode ) const
76 {
77     QString areaTransportTypeCode( joreCode.mid(0,1) );
78     QString lineCode( joreCode.mid(1,4) );
79     QString letterVariant( joreCode.mid(5,1) );
80     QString letterNumberVariant( joreCode.mid(6,1) );
81     QString direction( joreCode.mid(7,1) );
82     
83     return lineCode+letterVariant;
84 }
85
86 Location RoutePrivate::toLocation()
87 {
88   return m_toLocation;
89 }