7 #include <QNetworkAccessManager>
8 #include <QNetworkReply>
12 #include <QStringList>
14 #include <QXmlStreamReader>
19 q( new RoutePrivate( this ) ),
20 manager( new QNetworkAccessManager(this) )
22 connect( manager, SIGNAL( finished(QNetworkReply*) ), this, SLOT( replyFinished(QNetworkReply*) ) );
31 void Route::getRoute()
33 qDebug() << "getting route from Ytv";
35 QUrl fullUrl( Ytv::Url );
38 a << q->fromLocation().x() << q->fromLocation().y();
40 b << q->toLocation().x() << q->toLocation().y();
42 fullUrl.addQueryItem( "a", a.join(",") );
43 fullUrl.addQueryItem( "b", b.join(",") );
44 fullUrl.addQueryItem( "show", QString::number(Ytv::FiveResults) );
45 fullUrl.addQueryItem( "walkspeed", QString::number(Ytv::Fast) );
46 fullUrl.addQueryItem( "user", Ytv::Username );
47 fullUrl.addQueryItem( "pass", Ytv::Password );
49 manager->get( QNetworkRequest( fullUrl ) );
50 qDebug() << "waiting for reply from Ytv";
53 void Route::replyFinished( QNetworkReply * reply )
55 qDebug() << "have reply from Ytv";
56 QList<RouteData> routeData = q->parseReply( reply->readAll() );
58 emit( routeReady( routeData ) );
61 void Route::setFromLocation( const Location &location )
63 qDebug() << "setting new From location";
65 if ( location.isValid() ) {
66 q->setFromLocation( location );
71 Location *locationPtr = qobject_cast<Location*>(sender());
73 q->setFromLocation( *locationPtr );
78 qDebug() << "locationPtr is zero - cast didn't work";
83 const Location &Route::fromLocation()
85 return q->fromLocation();
88 void Route::setToLocation( const Location &location )
90 qDebug() << "setting new To location";
92 if ( location.isValid() ) {
93 qDebug() << "To is valid";
94 q->setToLocation( location );
95 if ( q->fromValid() ) {
96 qDebug() << "From is also valid";
99 qDebug() << "From not valid - waiting";
102 qDebug() << "To is not valid";
103 qDebug() << "getting To from signal sender";
104 Location *locationPtr = qobject_cast<Location*>(sender());
106 q->setToLocation( *locationPtr );
107 if ( q->fromValid() ) {
108 qDebug() << "From is also valid";
111 qDebug() << "From not valid - waiting";
114 qDebug() << "locationPtr is zero; cast failed";
119 const Location &Route::toLocation()
121 return q->toLocation();
124 void Route::toggleDirection()
126 Location oldFromLocation = fromLocation();
127 setFromLocation( toLocation() );
128 setToLocation( oldFromLocation );