4 #include <QXmlStreamReader>
9 RoutePrivate::RoutePrivate( QObject *parent ) :
18 RoutePrivate::~RoutePrivate()
22 QList<RouteData> RoutePrivate::parseReply( const QByteArray &reply )
24 qDebug() << "parsing route";
25 QFile file( "/home/user/route.txt" );
26 if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
27 QTextStream out(&file);
31 qDebug() << "Could not open /home/user/route.txt";
35 QList<RouteData> retVal;
38 QXmlStreamReader xml( reply );
40 QHash<QString, bool> in;
41 QHash<QString, bool> have;
43 have[ "LINE" ] = false;
44 have[ "TIME" ] = false;
46 in[ "ROUTE" ] = false;
50 while ( !xml.atEnd() ) {
52 if ( xml.isStartElement() ) {
53 in[ xml.name().toString() ] = true;
55 if ( xml.name() == "ROUTE" ) {
56 have[ "TIME" ] = false;
57 have[ "LINE" ] = false;
61 if ( xml.isEndElement() ) {
62 in[ xml.name().toString() ] = false;
65 if ( !have[ "LINE" ] && in[ "ROUTE" ] && xml.isStartElement() && xml.name() == "LINE" ) {
66 QString lineCode( xml.attributes().value("code").toString() );
68 routeData.lineCode = parseJORECode( lineCode );
69 have[ "LINE" ] = true;
71 if ( have[ "LINE" ] && have[ "TIME" ] ) {
72 retVal.append( routeData );
76 if ( !have[ "TIME" ] && in[ "ROUTE" ] && in[ "LINE" ] && in[ "STOP" ] && xml.name() == "ARRIVAL" ) {
77 QString arrivalTime( xml.attributes().value("time").toString() );
79 routeData.arrivalTime = arrivalTime.rightJustified(4).insert(2,":");
80 have[ "TIME" ] = true;
82 if ( have[ "LINE" ] && have[ "TIME" ] ) {
83 retVal.append( routeData );
89 if ( xml.hasError() ) {
90 qDebug() << "xml error:" << xml.errorString();
93 if ( retVal.isEmpty() ) {
94 qDebug() << "no routes found";
100 void RoutePrivate::setFromLocation( Location *location )
102 m_fromLocation = location;
106 Location *RoutePrivate::fromLocation() const
108 return m_fromLocation;
111 void RoutePrivate::setToLocation( Location *toLocation )
113 m_toLocation = toLocation;
117 QString RoutePrivate::parseJORECode( const QString &joreCode ) const
121 QString areaTransportTypeCode( joreCode.mid(0,1) );
122 QString lineCode( joreCode.mid(1,3) );
123 QString letterVariant( joreCode.mid(4,1) );
124 QString letterNumberVariant( joreCode.mid(5,1) );
125 QString direction( joreCode.mid(6,1) );
127 lineCode.setNum( lineCode.toInt() );
131 if ( letterVariant != " " ) {
132 retVal += letterVariant;
138 Location *RoutePrivate::toLocation() const
143 bool RoutePrivate::fromValid()
148 bool RoutePrivate::toValid()