+++ /dev/null
--#include "gpscontroller.h"
- #include "gpscontroller_p.h"
-
- #include <QObject>
- #include <QGeoPositionInfo>
- #include <QGeoPositionInfoSource>
- #include <QDebug>
-
- GpsController::GpsController() :
- q( new GpsControllerPrivate() )
- {
- q->init();
- q->startGps();
- }
-
- GpsController::GpsController( GpsControllerPrivate *gpsControllerPrivate ) :
- q( gpsControllerPrivate )
- {
- q->init();
- q->startGps();
- }
-
- GpsController::~GpsController()
- {
- delete q;
- }
-
- void GpsController::getGps()
- {
- Location *location;
- Location *previousLocation = q->mostRecentlyReportedLocation();
-
- if ( q->useFakeLocation() ) {
- location = q->fakeLocation();
- } else {
- location = q->liveLocation();
- }
-
- if ( location != previousLocation ) {
- emit locationChanged( location );
- }
- }
-
- void GpsController::useLiveGps()
- {
- q->setUseFakeLocation( false );
- q->startGps();
- emit locationChanged( q->liveLocation() );
- }
-
- void GpsController::useFakeGps( const QString &fakeLocationLabel )
- {
- qDebug() << "using fake gps (" << fakeLocationLabel << ")";
-
- q->setFakeLocationLabel( fakeLocationLabel );
- Location *fakeLocation = q->fakeLocation();
-
- if ( fakeLocation == 0 ) {
- qDebug() << "invalid fake location label; cannot use fake location";
- } else {
- q->stopGps();
- q->setUseFakeLocation( true );
- emit locationChanged( fakeLocation );
- }
- }
-#include "logic/locations.h"
-
-#include <QObject>
-#include <QGeoPositionInfo>
-#include <QGeoPositionInfoSource>
-#include <QDebug>
-
-GpsController::GpsController(bool started) :
- m_gps(QGeoPositionInfoSource::createDefaultSource(this)),
- m_started(started)
-{
- m_gps->setUpdateInterval(20000);
- connect(m_gps, SIGNAL(positionUpdated(QGeoPositionInfo)),
- this, SLOT(updateLocation(QGeoPositionInfo)));
- connect(m_gps, SIGNAL(updateTimeout()),
- this, SLOT(timeoutRequested()));
- if (m_started) m_gps->startUpdates();
-}
-
-GpsController::~GpsController()
-{
- delete m_gps;
-}
-
-void GpsController::useGPS( bool use)
-{
- if (use) m_gps->startUpdates();
- else m_gps->stopUpdates();
-}
-
-bool GpsController::isStarted() const
-{
- return m_started;
-}
-
-QGeoPositionInfoSource *GpsController::gps() const
-{
- return m_gps;
-}
-
-void GpsController::updateLocation( QGeoPositionInfo positionInfo )
-{
- qDebug() << "GPS location update received";
- Locations *locations = Locations::GetInstance();
-
- //DEBUG
- /*if (locations == 0)
- qDebug() << "Null locations received from getInstance";
- else
- qDebug() << "Locations is not null";
- Location* gpsLoc = locations->getGpsLocation();
- if (gpsLoc == 0)
- qDebug() << "Null gpsLocation received from locations";
- else
- qDebug() << "GPS location is not null.";*/
- //DEBUG ENDED
-
- locations->getGpsLocation()->setLocation(positionInfo);
- //emit(gpsLocationChanged(m_location));
-}
-
-void GpsController::timeoutRequested()
-{
- qDebug() << "GPS sent timeout requested.";
-}
+++ /dev/null
--#ifndef GPSCONTROLLER_H
--#define GPSCONTROLLER_H
--
- #include "location.h"
-
- #include "gpscontroller_p.h"
-
- #include <QObject>
- #include <QGeoPositionInfo>
- #include <QGeoPositionInfoSource>
-
- QTM_USE_NAMESPACE
-
- class GpsController : public QObject
- {
- Q_OBJECT
-
- public:
- GpsController();
- GpsController( GpsControllerPrivate *gpsControllerPrivate );
-
- ~GpsController();
-
- public Q_SLOTS:
- void getGps();
- void useFakeGps( const QString &fakeLocationLabel );
- void useLiveGps();
-
- Q_SIGNALS:
- void locationChanged( Location *newLocation );
-
- private:
- GpsControllerPrivate *q;
- };
-
- #endif // GPSCONTROLLER_H
-#include "logic/location.h"
-
-#include <QObject>
-#include <QGeoPositionInfo>
-#include <QGeoPositionInfoSource>
-
-QTM_USE_NAMESPACE;
-
-class Location;
-
-class GpsController : public QObject
-{
- Q_OBJECT
-
-public:
- GpsController(bool started = true);
-
- ~GpsController();
-
- QGeoPositionInfoSource *gps() const;
- bool isStarted() const;
-
-public Q_SLOTS:
- void useGPS( bool );
-
-Q_SIGNALS:
- void gpsLocationChanged( Location *newLocation );
-
-private Q_SLOTS:
- void updateLocation( QGeoPositionInfo positionInfo );
- void timeoutRequested();
-
-private:
- QGeoPositionInfoSource *m_gps;
- bool m_started;
-};
-
-#endif // GPSCONTROLLER_H
+++ /dev/null
--#include "route_p.h"
--#include "route.h"
--
--#include "routedata.h"
- #include "location.h"
-
- #include <QNetworkAccessManager>
- #include <QNetworkReply>
- #include <QUrl>
- #include <QObject>
- #include <QDebug>
- #include <QStringList>
- #include <QString>
- #include <QXmlStreamReader>
- #include <QWidget>
-
- #include "ytv.h"
-
- Route::Route() :
- q( new RoutePrivate( this ) ),
- manager( new QNetworkAccessManager(this) )
- {
- connect( manager, SIGNAL( finished(QNetworkReply*) ), this, SLOT( replyFinished(QNetworkReply*) ) );
- }
-
- Route::~Route()
- {
- delete manager;
- manager = 0;
- }
-
- void Route::getRoute()
- {
- qDebug() << "getting route from Ytv";
-
- QUrl fullUrl( Ytv::Url );
-
- QStringList a;
- a << q->fromLocation()->x() << q->fromLocation()->y();
- QStringList b;
- b << q->toLocation()->x() << q->toLocation()->y();
-
- fullUrl.addQueryItem( "a", a.join(",") );
- fullUrl.addQueryItem( "b", b.join(",") );
- fullUrl.addQueryItem( "show", QString::number(Ytv::ShowFiveResults) );
- fullUrl.addQueryItem( "walkspeed", QString::number(Ytv::WalkSpeedFast) );
- fullUrl.addQueryItem( "optimize", QString::number(Ytv::OptimizeLeastWalking) );
- fullUrl.addQueryItem( "user", Ytv::Username );
- fullUrl.addQueryItem( "pass", Ytv::Password );
-
- manager->get( QNetworkRequest( fullUrl ) );
- qDebug() << "getting url" << fullUrl.toEncoded();
- qDebug() << "waiting for reply from Ytv";
- emit( busy( true ) );
- }
-
- void Route::replyFinished( QNetworkReply * reply )
- {
- qDebug() << "have reply from Ytv";
- QList<RouteData> routeData = q->parseReply( reply->readAll() );
-
- emit( routeReady( routeData ) );
- emit( busy( false ) );
- }
-
- void Route::setFromLocation( Location *location )
- {
- qDebug() << "setting new From location (" << location->label() << ")";
-
- if ( location && location->isValid() ) {
- qDebug() << "From is valid";
- q->setFromLocation( location );
- if ( q->toValid() ) {
- qDebug() << "To is also valid";
- getRoute();
- } else {
- qDebug() << "To not valid - waiting";
- }
- } else {
- qDebug() << "ERROR:From is not valid";
- qDebug() << "location=" << location;
- if ( location ) {
- qDebug() << "location->isValid()=" << location->isValid();
- }
- }
- }
-
- Location *Route::fromLocation() const
- {
- return q->fromLocation();
- }
-
- void Route::setToLocation( Location *location )
- {
- qDebug() << "setting new To location (" << location->label() << ")";
-
- if ( location && location->isValid() ) {
- qDebug() << "To is valid";
- q->setToLocation( location );
- if ( q->fromValid() ) {
- qDebug() << "From is also valid";
- getRoute();
- } else {
- qDebug() << "From not valid - waiting";
- }
- } else {
- qDebug() << "ERROR:From is not valid";
- qDebug() << "location=" << location;
- if ( location ) {
- qDebug() << "location->isValid()=" << location->isValid();
- }
- }
- }
-
- Location *Route::toLocation() const
- {
- return q->toLocation();
- }
-#include "logic/location.h"
-
-#include <QNetworkAccessManager>
-#include <QNetworkReply>
-#include <QUrl>
-#include <QObject>
-#include <QDebug>
-#include <QStringList>
-#include <QString>
-#include <QXmlStreamReader>
-#include <QWidget>
-
-#include "logic/ytv.h"
-
-Route::Route() :
- q( new RoutePrivate( this ) ),
- manager( new QNetworkAccessManager(this) )
-{
- connect( manager, SIGNAL( finished(QNetworkReply*) ), this, SLOT( replyFinished(QNetworkReply*) ) );
-}
-
-Route::~Route()
-{
- delete manager;
- manager = 0;
-}
-
-void Route::getRoute()
-{
- qDebug() << "getting route from Ytv";
-
- QUrl fullUrl( Ytv::Url );
-
- QStringList a;
- a << q->fromLocation()->x() << q->fromLocation()->y();
- QStringList b;
- b << q->toLocation()->x() << q->toLocation()->y();
-
- fullUrl.addQueryItem( "a", a.join(",") );
- fullUrl.addQueryItem( "b", b.join(",") );
- fullUrl.addQueryItem( "show", QString::number(Ytv::ShowFiveResults) );
- fullUrl.addQueryItem( "walkspeed", QString::number(Ytv::WalkSpeedFast) );
- fullUrl.addQueryItem( "optimize", QString::number(Ytv::OptimizeDefault) );
- fullUrl.addQueryItem( "user", Ytv::Username );
- fullUrl.addQueryItem( "pass", Ytv::Password );
-
- manager->get( QNetworkRequest( fullUrl ) );
- qDebug() << "getting url" << fullUrl.toEncoded();
- qDebug() << "waiting for reply from Ytv";
- emit( busy( true ) );
-}
-
-void Route::replyFinished( QNetworkReply * reply )
-{
- qDebug() << "have reply from Ytv";
- QList<RouteData> routeData = q->parseReply( reply->readAll() );
-
- emit( routeReady( routeData ) );
- emit( busy( false ) );
-}
-
-void Route::setFromLocation( Location *location )
-{
- qDebug() << "setting new From location (" << location->label() << ")";
- this->setLocation(location, true);
-}
-
-void Route::searchRoute()
-{
- if (q->fromValid() && q->toValid())
- {
- qDebug() << "From and To addresses are valid.";
- getRoute();
- }
-}
-
-Location *Route::fromLocation() const
-{
- return q->fromLocation();
-}
-
-void Route::setLocation(Location *location, bool from)
-{
- if (location != 0)
- {
- if (location->isValid())
- {
- qDebug() << "Location is valid";
- if (from) q->setFromLocation( location );
- else q->setToLocation(location);
- } else {
- qDebug() << "Location is not valid. Try again or fix address";
- qDebug() << "Location = " << location;
- //location->resolveAddress(location->address());
- }
- } else {
- qDebug() << "ERROR:Null location pointer given.";
- }
-}
-
-void Route::setToLocation( Location *location )
-{
- qDebug() << "setting new To location (" << location->label() << ")";
- this->setLocation(location, false);
-}
-
-Location *Route::toLocation() const
-{
- return q->toLocation();
-}
+++ /dev/null
--#ifndef ROUTE_H
--#define ROUTE_H
--
--#include "routedata.h"
- #include "location.h"
-
- #include <QObject>
- #include <QNetworkReply>
- #include <QNetworkAccessManager>
-
- class RoutePrivate;
-
- class Route: public QObject
- {
- Q_OBJECT
-
- public:
- Route();
- ~Route();
-
- /*!
- * \brief Gets the route data from the server
- */
- void getRoute();
-
- /*!
- \brief Get the from location
- \return The from location
- */
- Location *fromLocation() const;
-
- /*!
- \brief Get the to location
- \return The to location
- */
- Location *toLocation() const;
-
- public Q_SLOTS:
-
- /*!
- * \brief Sets the from location
- * \param fromLocation The from location
- */
- void setFromLocation( Location *location=0 );
-
- /*!
- * \brief Sets the to location
- * \param toLocation The to location
- */
- void setToLocation( Location *location=0 );
-
- Q_SIGNALS:
- void routeReady( QList<RouteData> );
- void busy( bool busy );
-
- private Q_SLOTS:
- void replyFinished( QNetworkReply* );
-
- private:
- RoutePrivate *q;
- QNetworkAccessManager *manager;
- };
- #endif // ROUTE_H
-#include "logic/location.h"
-
-#include <QObject>
-#include <QNetworkReply>
-#include <QNetworkAccessManager>
-
-class RoutePrivate;
-
-class Route: public QObject
-{
- Q_OBJECT
-
-public:
- Route();
- ~Route();
-
- /*!
- * \brief Gets the route data from the server
- */
- void getRoute();
-
- /*!
- \brief Get the from location
- \return The from location
- */
- Location *fromLocation() const;
-
- /*!
- \brief Get the to location
- \return The to location
- */
- Location *toLocation() const;
-
-public Q_SLOTS:
-
- /*!
- * \brief Sets the from location
- * \param fromLocation The from location
- */
- void setFromLocation( Location *location=0 );
-
- /*!
- * \brief Sets the to location
- * \param toLocation The to location
- */
- void setToLocation( Location *location=0 );
-
- void searchRoute();
-
-Q_SIGNALS:
- void routeReady( QList<RouteData> );
- void busy( bool busy );
-
-private Q_SLOTS:
- void replyFinished( QNetworkReply* );
-
-private:
- void setLocation(Location*, bool from);
-private:
- RoutePrivate *q;
- QNetworkAccessManager *manager;
-};
-#endif // ROUTE_H
+++ /dev/null
--#include "route_p.h"
- #include "location.h"
-
- #include <QXmlStreamReader>
- #include <QDebug>
- #include <QList>
- #include <QFile>
- #include <QStringList>
- #include <QMaemo5InformationBox>
-
- RoutePrivate::RoutePrivate( QObject *parent ) :
- m_fromValid(false),
- m_toValid(false),
- m_fromLocation(0),
- m_toLocation(0)
- {
- Q_UNUSED( parent )
- }
-
- RoutePrivate::~RoutePrivate()
- {
- }
-
- QList<RouteData> RoutePrivate::parseReply( const QByteArray &reply )
- {
- qDebug() << "parsing route";
-
- QList<RouteData> retVal;
- RouteData routeData;
- LegData legData;
-
- QXmlStreamReader xml( reply );
-
- QHash<QString, bool> in;
- QHash<QString, bool> have;
-
- QStringList haveKeys;
- QStringList inKeys;
-
- haveKeys
- << "LINE"
- << "TIME"
- << "TRIP"
- << "DEPARTURE"
- << "ARRIVAL"
- ;
-
- inKeys
- << "ROUTE"
- << "LINE"
- << "STOP"
- << "WALK"
- << "POINT"
- ;
-
- foreach( QString key, haveKeys ) {
- have[ key ] = false;
- }
-
- foreach( QString key, inKeys ) {
- in[ key ] = false;
- }
-
- while ( !xml.atEnd() ) {
- xml.readNext();
-
- QString xmlName = xml.name().toString();
-
- if ( xml.isStartElement() ) {
- if ( inKeys.contains( xmlName ) ) {
- in[ xmlName ] = true;
- //qDebug() << "in[" << xmlName << "] = true";
- }
-
- if ( xmlName == "ROUTE" ) {
- foreach( QString key, haveKeys ) {
- have[ key ] = false;
- }
- }
-
- if ( xmlName == "WALK" ) {
- legData.m_how = "WALK";
- have[ "DEPARTURE" ] = false;
- have[ "ARRIVAL" ] = false;
- have[ "LENGTH" ] = false;
- }
-
- if ( xmlName == "LINE" ) {
- legData.m_how = "LINE";
- QString lineCode( xml.attributes().value("code").toString() );
- legData.m_lineCode = parseJORECode( lineCode );
- have[ "DEPARTURE" ] = false;
- have[ "ARRIVAL" ] = false;
- have[ "LENGTH" ] = false;
- }
- }
-
- if ( xml.isEndElement() ) {
- if ( inKeys.contains( xmlName ) ) {
- in[ xmlName ] = false;
- //qDebug() << "in[" << xmlName << "] = false";
- }
-
- if ( xmlName == "ROUTE" ) {
- retVal.append( routeData );
- routeData.clear();
- }
-
- if ( xmlName == "WALK" || xmlName == "LINE" ) {
- routeData.m_legData.append( legData );
- legData.clear();
- have[ "LENGTH" ] = false;
- }
- }
-
- if ( !have[ "ARRIVAL" ] && ( in[ "WALK" ] || in[ "LINE" ] ) && ( in[ "STOP" ] || in[ "POINT" ] ) && xml.isStartElement() && xmlName == "ARRIVAL" ) {
- QString arrivalTime( xml.attributes().value("time").toString() );
- legData.m_arrivalTime = arrivalTime.rightJustified(4).insert(2,":");
-
- // don't set have[ "ARRIVAL" ] since we want the last one of many STOPs
- }
-
- if ( !have[ "DEPARTURE" ] && in[ "LINE" ] && in[ "STOP" ] && xml.isStartElement() && xmlName == "DEPARTURE" ) {
- QString departureTime( xml.attributes().value("time").toString() );
- legData.m_departureTime = departureTime.rightJustified(4).insert(2,":");
-
- have[ "DEPARTURE" ] = true;
- }
-
- if ( !have[ "DEPARTURE" ] && in[ "WALK" ] && ( in[ "POINT" ] || in[ "STOP" ] ) && xml.isStartElement() && xmlName == "DEPARTURE" ) {
- QString departureTime( xml.attributes().value("time").toString() );
- legData.m_departureTime = departureTime.rightJustified(4).insert(2,":");
-
- have[ "DEPARTURE" ] = true;
- }
-
- if ( !have[ "LENGTH" ] && ( in[ "WALK" ] || in[ "LINE" ] ) && xml.isStartElement() && xmlName == "LENGTH" ) {
- legData.m_tripTime = xml.attributes().value("time").toString();
- legData.m_tripDistance = xml.attributes().value("dist").toString();
-
- have[ "LENGTH" ] = true;
- }
-
- if ( !have[ "TRIP" ] && in[ "ROUTE" ] && xml.isStartElement() && xmlName == "LENGTH" ) {
- routeData.m_tripTime = xml.attributes().value("time").toString();
- routeData.m_tripDistance = xml.attributes().value("dist").toString();
-
- have[ "TRIP" ] = true;
- }
-
- if ( !have[ "LINE" ] && in[ "ROUTE" ] && xml.isStartElement() && xmlName == "LINE" ) {
- QString lineCode( xml.attributes().value("code").toString() );
-
- routeData.m_lineCode = parseJORECode( lineCode );
- have[ "LINE" ] = true;
- }
-
- if ( !have[ "TIME" ] && in[ "ROUTE" ] && in[ "LINE" ] && in[ "STOP" ] && xmlName == "DEPARTURE" ) {
- QString departureTime( xml.attributes().value("time").toString() );
-
- routeData.m_departureTime = departureTime.rightJustified(4).insert(2,":");
- have[ "TIME" ] = true;
- }
-
- }
-
- if ( xml.hasError() ) {
- qDebug() << "xml error:" << xml.errorString();
- }
-
- if ( retVal.isEmpty() ) {
- qDebug() << "no routes found";
- QMaemo5InformationBox::information( 0, "no routes found" );
- }
-
- return retVal;
- }
-
- void RoutePrivate::setFromLocation( Location *location )
- {
- m_fromLocation = location;
- m_fromValid = true;
- }
-
- Location *RoutePrivate::fromLocation() const
- {
- return m_fromLocation;
- }
-
- void RoutePrivate::setToLocation( Location *toLocation )
- {
- m_toLocation = toLocation;
- m_toValid = true;
- }
-
- QString RoutePrivate::parseJORECode( const QString &joreCode ) const
- {
- QString retVal;
-
- QString areaTransportTypeCode( joreCode.mid(0,1) );
- QString lineCode( joreCode.mid(1,3) );
- QString letterVariant( joreCode.mid(4,1) );
- QString letterNumberVariant( joreCode.mid(5,1) );
- QString direction( joreCode.mid(6,1) );
-
- lineCode.setNum( lineCode.toInt() );
-
- retVal = lineCode;
-
- if ( letterVariant != " " ) {
- retVal += letterVariant;
- }
-
- return retVal;
- }
-
- Location *RoutePrivate::toLocation() const
- {
- return m_toLocation;
- }
-
- bool RoutePrivate::fromValid()
- {
- return m_fromValid;
- }
-
- bool RoutePrivate::toValid()
- {
- return m_toValid;
- }
-#include "logic/location.h"
-
-#include <QXmlStreamReader>
-#include <QDebug>
-#include <QList>
-#include <QFile>
-#include <QStringList>
-#ifdef Q_WS_MAEMO_5
-#include <QMaemo5InformationBox>
-#endif
-
-RoutePrivate::RoutePrivate( QObject *parent ) :
- m_fromValid(false),
- m_toValid(false),
- m_fromLocation(0),
- m_toLocation(0)
-{
- Q_UNUSED( parent )
-}
-
-RoutePrivate::~RoutePrivate()
-{
-}
-
-QList<RouteData> RoutePrivate::parseReply( const QByteArray &reply )
-{
- qDebug() << "parsing route";
-
- QList<RouteData> retVal;
- RouteData routeData;
- LegData legData;
-
- QXmlStreamReader xml( reply );
-
- QHash<QString, bool> in;
- QHash<QString, bool> have;
-
- QStringList haveKeys;
- QStringList inKeys;
-
- haveKeys
- << "LINE"
- << "TIME"
- << "TRIP"
- << "DEPARTURE"
- << "ARRIVAL"
- ;
-
- inKeys
- << "ROUTE"
- << "LINE"
- << "STOP"
- << "WALK"
- << "POINT"
- ;
-
- foreach( QString key, haveKeys ) {
- have[ key ] = false;
- }
-
- foreach( QString key, inKeys ) {
- in[ key ] = false;
- }
-
- while ( !xml.atEnd() ) {
- xml.readNext();
-
- QString xmlName = xml.name().toString();
-
- if ( xml.isStartElement() ) {
- if ( inKeys.contains( xmlName ) ) {
- in[ xmlName ] = true;
- //qDebug() << "in[" << xmlName << "] = true";
- }
-
- if ( xmlName == "ROUTE" ) {
- foreach( QString key, haveKeys ) {
- have[ key ] = false;
- }
- }
-
- if ( xmlName == "WALK" ) {
- legData.m_how = "WALK";
- have[ "DEPARTURE" ] = false;
- have[ "ARRIVAL" ] = false;
- have[ "LENGTH" ] = false;
- }
-
- if ( xmlName == "LINE" ) {
- legData.m_how = "LINE";
- QString lineCode( xml.attributes().value("code").toString() );
- legData.m_lineCode = parseJORECode( lineCode );
- have[ "DEPARTURE" ] = false;
- have[ "ARRIVAL" ] = false;
- have[ "LENGTH" ] = false;
- }
- }
-
- if ( xml.isEndElement() ) {
- if ( inKeys.contains( xmlName ) ) {
- in[ xmlName ] = false;
- //qDebug() << "in[" << xmlName << "] = false";
- }
-
- if ( xmlName == "ROUTE" ) {
- retVal.append( routeData );
- routeData.clear();
- }
-
- if ( xmlName == "WALK" || xmlName == "LINE" ) {
- routeData.m_legData.append( legData );
- legData.clear();
- have[ "LENGTH" ] = false;
- }
- }
-
- if ( !have[ "ARRIVAL" ] && ( in[ "WALK" ] || in[ "LINE" ] ) && ( in[ "STOP" ] || in[ "POINT" ] ) && xml.isStartElement() && xmlName == "ARRIVAL" ) {
- QString arrivalTime( xml.attributes().value("time").toString() );
- legData.m_arrivalTime = arrivalTime.rightJustified(4).insert(2,":");
-
- // don't set have[ "ARRIVAL" ] since we want the last one of many STOPs
- }
-
- if ( !have[ "DEPARTURE" ] && in[ "LINE" ] && in[ "STOP" ] && xml.isStartElement() && xmlName == "DEPARTURE" ) {
- QString departureTime( xml.attributes().value("time").toString() );
- legData.m_departureTime = departureTime.rightJustified(4).insert(2,":");
-
- have[ "DEPARTURE" ] = true;
- }
-
- if ( !have[ "DEPARTURE" ] && in[ "WALK" ] && ( in[ "POINT" ] || in[ "STOP" ] ) && xml.isStartElement() && xmlName == "DEPARTURE" ) {
- QString departureTime( xml.attributes().value("time").toString() );
- legData.m_departureTime = departureTime.rightJustified(4).insert(2,":");
-
- have[ "DEPARTURE" ] = true;
- }
-
- if ( !have[ "LENGTH" ] && ( in[ "WALK" ] || in[ "LINE" ] ) && xml.isStartElement() && xmlName == "LENGTH" ) {
- legData.m_tripTime = xml.attributes().value("time").toString();
- legData.m_tripDistance = xml.attributes().value("dist").toString();
-
- have[ "LENGTH" ] = true;
- }
-
- if ( !have[ "TRIP" ] && in[ "ROUTE" ] && xml.isStartElement() && xmlName == "LENGTH" ) {
- routeData.m_tripTime = xml.attributes().value("time").toString();
- routeData.m_tripDistance = xml.attributes().value("dist").toString();
-
- have[ "TRIP" ] = true;
- }
-
- if ( !have[ "LINE" ] && in[ "ROUTE" ] && xml.isStartElement() && xmlName == "LINE" ) {
- QString lineCode( xml.attributes().value("code").toString() );
-
- routeData.m_lineCode = parseJORECode( lineCode );
- have[ "LINE" ] = true;
- }
-
- if ( !have[ "TIME" ] && in[ "ROUTE" ] && in[ "LINE" ] && in[ "STOP" ] && xmlName == "DEPARTURE" ) {
- QString departureTime( xml.attributes().value("time").toString() );
-
- routeData.m_departureTime = departureTime.rightJustified(4).insert(2,":");
- have[ "TIME" ] = true;
- }
-
- }
-
- if ( xml.hasError() ) {
- qDebug() << "xml error:" << xml.errorString();
- }
-
- if ( retVal.isEmpty() ) {
- qDebug() << "no routes found";
-#ifdef Q_WS_MAEMO_5
- QMaemo5InformationBox::information( 0, "no routes found" );
-#endif
- }
-
- return retVal;
-}
-
-void RoutePrivate::setFromLocation( Location *location )
-{
- m_fromLocation = location;
- m_fromValid = true;
-}
-
-Location *RoutePrivate::fromLocation() const
-{
- return m_fromLocation;
-}
-
-void RoutePrivate::setToLocation( Location *toLocation )
-{
- m_toLocation = toLocation;
- m_toValid = true;
-}
-
-QString RoutePrivate::parseJORECode( const QString &joreCode ) const
-{
- QString retVal;
-
- QString areaTransportTypeCode( joreCode.mid(0,1) );
- QString lineCode( joreCode.mid(1,3) );
- QString letterVariant( joreCode.mid(4,1) );
- QString letterNumberVariant( joreCode.mid(5,1) );
- QString direction( joreCode.mid(6,1) );
-
- lineCode.setNum( lineCode.toInt() );
-
- retVal = lineCode;
-
- if ( letterVariant != " " ) {
- retVal += letterVariant;
- }
-
- return retVal;
-}
-
-Location *RoutePrivate::toLocation() const
-{
- return m_toLocation;
-}
-
-bool RoutePrivate::fromValid()
-{
- return m_fromValid;
-}
-
-bool RoutePrivate::toValid()
-{
- return m_toValid;
-}
+++ /dev/null
--#ifndef ROUTE_P_H
--#define ROUTE_P_H
--
--#include "routedata.h"
--
- #include "location.h"
-
- #include <QObject>
-
- class RoutePrivate: public QObject
- {
- Q_OBJECT
-
- public:
- RoutePrivate( QObject *parent=0 );
- ~RoutePrivate();
-
- QList<RouteData> parseReply( const QByteArray &reply );
-
- Q_PROPERTY(Location* fromLocation READ fromLocation WRITE setFromLocation);
- Q_PROPERTY(Location* toLocation READ toLocation WRITE setToLocation);
-
- void setFromLocation( Location *fromLocation );
-
- Location *fromLocation() const;
-
- void setToLocation( Location *toLocation );
-
- Location *toLocation() const;
-
- bool toValid();
- bool fromValid();
-
- private:
- bool m_fromValid;
- bool m_toValid;
- Location *m_fromLocation;
- Location *m_toLocation;
-
- QString parseJORECode( const QString &joreCode ) const;
- };
- #endif // ROUTE_P_H
-#include "logic/location.h"
-
-#include <QObject>
-
-class RoutePrivate: public QObject
-{
- Q_OBJECT
-
-public:
- RoutePrivate( QObject *parent=0 );
- ~RoutePrivate();
-
- QList<RouteData> parseReply( const QByteArray &reply );
-
- Q_PROPERTY(Location* fromLocation READ fromLocation WRITE setFromLocation);
- Q_PROPERTY(Location* toLocation READ toLocation WRITE setToLocation);
-
- void setFromLocation( Location *fromLocation );
-
- Location *fromLocation() const;
-
- void setToLocation( Location *toLocation );
-
- Location *toLocation() const;
-
- bool toValid();
- bool fromValid();
-
-private:
- bool m_fromValid;
- bool m_toValid;
- Location *m_fromLocation;
- Location *m_toLocation;
-
- QString parseJORECode( const QString &joreCode ) const;
-};
-#endif // ROUTE_P_H
+++ /dev/null
--#ifndef ROUTEDATA_H
--#define ROUTEDATA_H
--
--#include <QString>
--#include <QList>
--
--struct LegData
--{
-- LegData() :
-- m_how(),
-- m_tripTime(),
-- m_tripDistance(),
-- m_departureTime(),
-- m_arrivalTime(),
-- m_lineCode()
-- {
-- };
--
-- LegData( QString how, QString tripTime, QString tripDistance, QString departureTime, QString arrivalTime, QString lineCode=QString() ) :
-- m_how(how),
-- m_tripTime(tripTime),
-- m_tripDistance(tripDistance),
-- m_departureTime(departureTime),
-- m_arrivalTime(arrivalTime),
-- m_lineCode(lineCode)
-- {
-- };
--
-- void clear()
-- {
-- m_how = "";
-- m_tripTime = "";
-- m_tripDistance = "";
-- m_departureTime = "";
-- m_arrivalTime = "";
-- m_lineCode = "";
-- };
--
-- QString m_how;
-- QString m_tripTime;
-- QString m_tripDistance;
-- QString m_departureTime;
-- QString m_arrivalTime;
-- QString m_lineCode;
--
--};
--
--struct RouteData
--{
-- RouteData():
-- m_tripTime(),
-- m_tripDistance(),
-- m_departureTime(),
-- m_lineCode(),
-- m_legData()
-- {
-- };
--
-- RouteData( QString tripTime, QString tripDistance, QString departureTime, QString lineCode ):
-- m_tripTime(tripTime),
-- m_tripDistance(tripDistance),
-- m_departureTime(departureTime),
-- m_lineCode(lineCode),
-- m_legData()
-- {
-- };
--
-- RouteData &operator <<(const LegData &legData)
-- {
-- m_legData.append( legData );
-- return *this;
-- };
--
-- void clear()
-- {
-- m_tripTime = "";
-- m_tripDistance = "";
-- m_departureTime = "";
-- m_lineCode = "";
-- m_legData.clear();
-- };
--
-- QString m_tripTime;
-- QString m_tripDistance;
-- QString m_departureTime;
-- QString m_lineCode;
-- QList<LegData> m_legData;
--
--};
--
--#endif // ROUTEDATA_H
+++ /dev/null
--#include "ui.h"
--
- #include "locations.h"
- #include "ytv.h"
-
- #include <QMainWindow>
- #include <QRadioButton>
- #include <QTableWidget>
- #include <QString>
- #include <QRect>
- #include <QButtonGroup>
- #include <QHeaderView>
- #include <QObject>
- #include <QMenuBar>
- #include <QHBoxLayout>
- #include <QVBoxLayout>
- #include <QGridLayout>
- #include <QSizePolicy>
- #include <QInputDialog>
- #include <QDebug>
-
- Ui::Ui() :
- m_centralWidget(0),
- m_destinationButtons(0),
- m_routeStack(0),
- m_usingFakeGps( false ),
- m_fakeLocationLabel( "work" )
- {
- }
-
- Ui::~Ui()
- {
- }
-
- void Ui::setupUi( QMainWindow *mainWindow )
- {
- m_mainWindow = mainWindow;
- m_mainWindow->resize(800,480);
-
- m_menu = mainWindow->menuBar()->addMenu("Settings");
-
- QAction *setHomeAddressAction = new QAction("Set home address", this);
- QAction *setWorkAddressAction = new QAction("Set work address", this);
- m_toggleFakeGpsAction = new QAction("Use fake GPS", this);
- m_menu->addAction(setHomeAddressAction);
- m_menu->addAction(setWorkAddressAction);
- m_menu->addAction(m_toggleFakeGpsAction);
-
- connect(
- setHomeAddressAction, SIGNAL(triggered()),
- this, SLOT(setHomeAddress())
- );
- connect(
- setWorkAddressAction, SIGNAL(triggered()),
- this, SLOT(setWorkAddress())
- );
- connect(
- m_toggleFakeGpsAction, SIGNAL(triggered()),
- this, SLOT(toggleFakeGps())
- );
-
- m_centralWidget = new QWidget( m_mainWindow );
- m_mainWindow->setCentralWidget( m_centralWidget);
-
- QRadioButton *homeButton = new QRadioButton();
- homeButton->setObjectName( QString::fromUtf8("homeButton") );
- homeButton->setText( "GPS->HOME" );
- homeButton->setEnabled(false);
-
- QRadioButton *workButton = new QRadioButton();
- workButton->setObjectName( QString::fromUtf8("workButton") );
- workButton->setText( "GPS->WORK" );
- workButton->setEnabled(false);
-
- m_destinationButtons = new QButtonGroup();
- m_destinationButtons->addButton( homeButton, HomeButtonId );
- m_destinationButtons->addButton( workButton, WorkButtonId );
- m_destinationButtons->setExclusive( true );
-
- m_routeButtons = new QButtonGroup();
- m_routeButtons->setExclusive( true );
- m_routeStack = new QVBoxLayout();
- for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
- QRadioButton *button = new QRadioButton();
- button->setObjectName( "routeButton"+i );
- button->setEnabled( false );
-
- m_routeStack->addWidget( button, i );
- m_routeButtons->addButton( button, i );
- }
- m_routeStack->addStretch();
-
- QStringList headers( QStringList() << "How" << "Time" << "Dist" << "Dep" << "Arr" );
- m_routeDetailTable = new QTableWidget();
- m_routeDetailTable->setColumnCount( headers.count() );
- m_routeDetailTable->setHorizontalHeaderLabels( headers );
- m_routeDetailTable->resizeColumnsToContents();
- m_routeDetailTable->setSelectionMode( QAbstractItemView::NoSelection );
-
- QHBoxLayout *topLayout = new QHBoxLayout();
- topLayout->addLayout( m_routeStack );
- topLayout->addWidget( m_routeDetailTable );
-
- m_buttonLayout = new QGridLayout();
- m_buttonLayout->addWidget( homeButton, 0, 0 );
- m_buttonLayout->addWidget( workButton, 0, 1 );
-
- m_mainLayout = new QVBoxLayout();
- m_mainLayout->addLayout( topLayout );
- m_mainLayout->addLayout( m_buttonLayout );
-
- m_centralWidget->setLayout( m_mainLayout );
- }
-
- void Ui::setHomeAddress()
- {
- setAddress( "home" );
- }
-
- void Ui::setWorkAddress()
- {
- setAddress( "work" );
- }
-
- void Ui::toggleFakeGps()
- {
- m_usingFakeGps = !m_usingFakeGps;
-
- if ( m_usingFakeGps ) {
- useFakeGps();
- } else {
- useLiveGps();
- }
- }
-
- void Ui::useFakeGps()
- {
- emit fakeGpsPressed( m_fakeLocationLabel );
- m_toggleFakeGpsAction->setText( "Use Live GPS" );
- }
-
- void Ui::useLiveGps()
- {
- emit liveGpsPressed();
- m_toggleFakeGpsAction->setText( "Use Fake GPS" );
- }
-
- void Ui::setAddress( const QString &label )
- {
- Locations locations;
- Location *location=locations.location( label );
-
- bool ok;
- QString address = QInputDialog::getText(
- m_centralWidget,
- tr("Enter address for \""+QString(label).toLatin1()+"\""),
- tr("Address"),
- QLineEdit::Normal,
- location->address(),
- &ok
- );
-
- if ( ok ) {
- qDebug() << "new address" << address;
- Locations locations;
- Location *location = locations.location( label );
- qDebug() << "location" << location;
- if ( location ) {
- location->resolveAddress( address );
- }
- }
- }
-
- void Ui::setBusy( bool busy )
- {
- m_mainWindow->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
- }
-#include "logic/locations.h"
-#include "logic/ytv.h"
-
-#include <QMainWindow>
-#include <QRadioButton>
-#include <QTableWidget>
-#include <QString>
-#include <QRect>
-#include <QButtonGroup>
-#include <QHeaderView>
-#include <QObject>
-#include <QMenuBar>
-#include <QHBoxLayout>
-#include <QVBoxLayout>
-#include <QGridLayout>
-#include <QSizePolicy>
-#include <QInputDialog>
-#include <QDebug>
-#include <QMenu>
-#include <QPushButton>
-#ifdef Q_WS_MAEMO_5
-#include <QMaemo5ValueButton>
-#include <QMaemo5ListPickSelector>
-#endif
-#include <QStandardItemModel>
-
-UiClass::UiClass() :
- m_centralWidget(NULL),
- m_routeStack(NULL),
- m_locDisp(NULL)
-{
-}
-
-UiClass::~UiClass()
-{
- delete m_locDisp;
-}
-
-void UiClass::setupUi( QMainWindow *mainWindow )
-{
- m_mainWindow = mainWindow;
-#ifdef Q_WS_MAEMO_5
- m_mainWindow->setAttribute(Qt::WA_Maemo5StackedWindow);
-#endif
- //m_mainWindow->resize(800,480);
-
- m_locDisp = new LocationsDisplayWindow(mainWindow);
-
- m_menu = mainWindow->menuBar();
-
- /*QAction *setHomeAddressAction = new QAction("Set home address", this);
- QAction *setWorkAddressAction = new QAction("Set work address", this);*/
- QAction *modifyLocationsAction = new QAction("Modify locations", this);
- m_UseGpsAction = new QAction("Use GPS", this);
- m_UseGpsAction->setCheckable(true);
- m_UseGpsAction->setChecked(true);
- connect(this->m_UseGpsAction, SIGNAL(toggled(bool)), this, SLOT(setLocations()));
- /*m_menu->addAction(setHomeAddressAction);
- m_menu->addAction(setWorkAddressAction);*/
- m_menu->addAction(m_UseGpsAction);
- m_menu->addAction(modifyLocationsAction);
-
- /*connect(
- setHomeAddressAction, SIGNAL(triggered()),
- this, SLOT(setHomeAddress())
- );
- connect(
- setWorkAddressAction, SIGNAL(triggered()),
- this, SLOT(setWorkAddress())
- );*/
-
- connect(modifyLocationsAction, SIGNAL(triggered()), m_locDisp, SLOT(show()));
-
- Locations* locations = Locations::GetInstance();
- connect(locations, SIGNAL(locationsChanged()), this, SLOT(setLocations()));
-
- m_centralWidget = new QWidget( m_mainWindow );
- m_mainWindow->setCentralWidget( m_centralWidget);
-
- m_locationsModel = new QStandardItemModel(0,1);
- this->setLocations();
-
-#ifdef Q_WS_MAEMO_5
- m_fromButton = new QMaemo5ValueButton(QString::fromUtf8("From"));
- m_fromButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
- QMaemo5ListPickSelector *fromSelector = new QMaemo5ListPickSelector();
- fromSelector->setModel(m_locationsModel);
- m_fromButton->setPickSelector(fromSelector);
-
- m_toButton = new QMaemo5ValueButton(QString::fromUtf8("To"));
- m_toButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
- QMaemo5ListPickSelector *toSelector = new QMaemo5ListPickSelector();
- toSelector->setModel(m_locationsModel);
- m_toButton->setPickSelector(toSelector);
-#endif
-
- m_routeButton = new QPushButton("Route");
-
- m_routeButtons = new QButtonGroup();
- m_routeButtons->setExclusive( true );
- m_routeStack = new QVBoxLayout();
- for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
- QRadioButton *button = new QRadioButton();
- button->setObjectName( "routeButton"+i );
- button->setEnabled( false );
-
- m_routeStack->addWidget( button, i );
- m_routeButtons->addButton( button, i );
- }
- m_routeStack->addStretch();
-
- QStringList headers( QStringList() << "How" << "Time" << "Dist" << "Dep" << "Arr" );
- m_routeDetailTable = new QTableWidget();
- m_routeDetailTable->setColumnCount( headers.count() );
- m_routeDetailTable->setHorizontalHeaderLabels( headers );
- m_routeDetailTable->resizeColumnsToContents();
- m_routeDetailTable->setSelectionMode( QAbstractItemView::NoSelection );
-
- QHBoxLayout *topLayout = new QHBoxLayout();
- topLayout->addLayout( m_routeStack );
- topLayout->addWidget( m_routeDetailTable );
-
- m_buttonLayout = new QGridLayout();
-#ifdef Q_WS_MAEMO_5
- m_buttonLayout->addWidget(m_fromButton, 0, 0);
- m_buttonLayout->addWidget(m_toButton, 0, 1);
-#endif
- m_buttonLayout->addWidget(m_routeButton, 0, 2);
-
- m_mainLayout = new QVBoxLayout();
- m_mainLayout->addLayout( topLayout );
- m_mainLayout->addLayout( m_buttonLayout );
-
- m_centralWidget->setLayout( m_mainLayout );
-}
-
-void UiClass::setLocations()
-{
- qDebug() << "Setting locations for main menu selectors.";
- Locations *locations = Locations::GetInstance();
-
- m_locationsModel->clear();
- QStandardItem *item;
- if (this->m_UseGpsAction->isChecked())
- {
- item = new QStandardItem(QString("GPS"));
- item->setTextAlignment(Qt::AlignCenter);
- item->setEditable(false);
- m_locationsModel->appendRow(item);
- }
-
- for (int index = 1; index <= locations->size(); ++index)
- {
- item = new QStandardItem(locations->getLocation(index)->label());
- item->setTextAlignment(Qt::AlignCenter);
- item->setEditable(false);
- m_locationsModel->appendRow(item);
- }
-}
-
-void UiClass::setHomeAddress()
-{
- setAddress( "home" );
-}
-
-void UiClass::setWorkAddress()
-{
- setAddress( "work" );
-}
-
-void UiClass::setAddress( const QString &label )
-{
- /*Locations locations;
- Location *location=locations.location( label );
-
- bool ok;
- QString address = QInputDialog::getText(
- m_centralWidget,
- tr("Enter address for \""+QString(label).toLatin1()+"\""),
- tr("Address"),
- QLineEdit::Normal,
- location->address(),
- &ok
- );
-
- if ( ok ) {
- qDebug() << "new address" << address;
- Locations locations;
- Location *location = locations.location( label );
- qDebug() << "location" << location;
- if ( location ) {
- //location->resolveAddress( address );
- }
- }*/
-}
-
-/*void Ui::modifyLocations()
-{
- LocationsDisplay
-}*/
-
-void UiClass::setBusy( bool busy )
-{
-#ifdef Q_WS_MAEMO_5
- m_mainWindow->setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
-#endif
-}
+++ /dev/null
--#ifndef UI_H
--#define UI_H
--
--#include <QObject>
-
- class QMainWindow;
- class QWidget;
- class QTableWidget;
- class QButtonGroup;
- class QHBoxLayout;
- class QVBoxLayout;
- class QGridLayout;
- class QMenu;
- class QAction;
- class Location;
-
- class Ui : public QObject
- {
- Q_OBJECT
-
- public:
- Ui();
- ~Ui();
- void setupUi( QMainWindow *mainWindow );
-
- enum {
- HomeButtonId=0,
- WorkButtonId=1
- };
-
- enum {
- ScreenWidth=800,
- ScreenHeight=480
- };
-
- QMainWindow *m_mainWindow;
- QWidget *m_centralWidget;
- QButtonGroup *m_destinationButtons;
- QButtonGroup *m_routeButtons;
- QVBoxLayout *m_routeStack;
- QTableWidget *m_routeDetailTable;
- QVBoxLayout *m_mainLayout;
- QGridLayout *m_buttonLayout;
- QMenu *m_menu;
- QAction *m_toggleFakeGpsAction;
- QAction *m_useLiveGpsAction;
- bool m_usingFakeGps;
- QString m_fakeLocationLabel;
-
- Q_SIGNALS:
- void homeAddressChanged( QString address );
- void workAddressChanged( QString address );
- void fakeGpsPressed( const QString &fakeLocationLabel );
- void liveGpsPressed();
-
- private Q_SLOTS:
- void setHomeAddress();
- void setWorkAddress();
- void toggleFakeGps();
- void setBusy( bool busy );
-
- private:
- void useFakeGps();
- void useLiveGps();
- void setAddress( const QString &label );
- };
- #endif //UI_H
-#include <QStandardItemModel>
-#include <QPushButton>
-#include <QMenuBar>
-#include <QMainWindow>
-#include <QWidget>
-#include <QTableWidget>
-#include <QButtonGroup>
-#include <QHBoxLayout>
-#include <QVBoxLayout>
-#include <QGridLayout>
-#include <QAction>
-#ifdef Q_WS_MAEMO_5
-#include <QMaemo5ValueButton>
-#endif
-
-#include "logic/location.h"
-#include "gui/locationsdisplaywidget.h"
-
-/*class QMainWindow;
-class QWidget;
-class QTableWidget;
-class QButtonGroup;
-class QHBoxLayout;
-class QVBoxLayout;
-class QGridLayout;
-class QMenu;
-class QAction;
-class Location;*/
-
-class UiClass : public QObject
-{
- Q_OBJECT
-
-public:
- UiClass();
- ~UiClass();
- void setupUi( QMainWindow *mainWindow );
-
- enum {
- FromButtonId=0,
- ToButtonId=1,
- RouteButtonId=2
- };
-
- enum {
- ScreenWidth=800,
- ScreenHeight=480
- };
-
- QMainWindow *m_mainWindow;
- QWidget *m_centralWidget;
-#ifdef Q_WS_MAEMO_5
- QMaemo5ValueButton *m_fromButton;
- QMaemo5ValueButton *m_toButton;
-#endif
- QButtonGroup *m_routeButtons;
- QVBoxLayout *m_routeStack;
- QTableWidget *m_routeDetailTable;
- QVBoxLayout *m_mainLayout;
- QGridLayout *m_buttonLayout;
- QMenuBar *m_menu;
- QAction *m_UseGpsAction;
- QStandardItemModel *m_locationsModel;
- QPushButton *m_routeButton;
- LocationsDisplayWidget *m_locDisp;
-
-public slots:
- void setLocations();
-
-Q_SIGNALS:
- void homeAddressChanged( QString address );
- void workAddressChanged( QString address );
-
-private Q_SLOTS:
- void setHomeAddress();
- void setWorkAddress();
- void setBusy( bool busy );
- //void modifyLocations();
-
-
-private:
- void setAddress( const QString &label );
-};
-#endif //UI_H
+++ /dev/null
--#include "uicontroller.h"
--#include "route.h"
--#include "ui.h"
- #include "ytv.h"
- #include "location.h"
- #include "locations.h"
-
- #include <QObject>
- #include <QPushButton>
- #include <QDebug>
- #include <QButtonGroup>
- #include <QRadioButton>
- #include <QVBoxLayout>
- #include <QTableWidgetItem>
-
- UiController::UiController( Ui *ui ) :
- m_routeData(),
- m_destination(),
- m_ui(ui),
- m_currentDestination(-1),
- m_currentRoute(-1)
- {
- Locations locations;
- Location *homeLocation = locations.location( "home" );
- Location *workLocation = locations.location( "work" );
-
- if ( homeLocation==0 ) {
- homeLocation = new Location( "home" );
- locations.addLocation( homeLocation );
- } else if ( homeLocation->isValid() ) {
- setHomeButtonValid();
- }
-
- if ( workLocation==0 ) {
- workLocation = new Location( "work" );
- locations.addLocation( workLocation );
- } else if ( workLocation->isValid() ) {
- setWorkButtonValid();
- }
-
- connect(
- homeLocation, SIGNAL( becomeValid() ),
- this, SLOT( setHomeButtonValid() )
- );
- connect(
- homeLocation, SIGNAL( becomeInValid() ),
- this, SLOT( setHomeButtonInValid() )
- );
- connect(
- homeLocation, SIGNAL( becomeValid() ),
- &locations, SLOT( saveLocation() )
- );
- connect(
- homeLocation, SIGNAL( busy( bool ) ),
- ui, SLOT( setBusy( bool ) )
- );
-
- connect(
- workLocation, SIGNAL( becomeValid() ),
- this, SLOT( setWorkButtonValid() )
- );
- connect(
- workLocation, SIGNAL( becomeInValid() ),
- this, SLOT( setWorkButtonInValid() )
- );
- connect(
- workLocation, SIGNAL( becomeValid() ),
- &locations, SLOT( saveLocation() )
- );
- connect(
- workLocation, SIGNAL( busy( bool ) ),
- ui, SLOT( setBusy( bool ) )
- );
-
- m_destination.append( homeLocation );
- m_destination.append( workLocation );
-
- connect(
- m_ui->m_destinationButtons, SIGNAL( buttonClicked( int ) ),
- this, SLOT( changeDestination( int ) )
- );
-
- connect(
- m_ui->m_routeButtons, SIGNAL( buttonClicked( int ) ),
- this, SLOT( changeRoute( int ) )
- );
- }
-
- UiController::~UiController()
- {
- }
-
- void UiController::setHomeButtonInValid()
- {
- qDebug() << "setting home button invalid";
- setButtonValid( Ui::HomeButtonId, false );
- }
-
- void UiController::setHomeButtonValid()
- {
- qDebug() << "setting home button valid";
- setButtonValid( Ui::HomeButtonId, true );
- }
-
- void UiController::setWorkButtonInValid()
- {
- qDebug() << "setting work button invalid";
- setButtonValid( Ui::WorkButtonId, false );
- }
-
- void UiController::setWorkButtonValid()
- {
- qDebug() << "setting work button valid";
- setButtonValid( Ui::WorkButtonId, true );
- }
-
- void UiController::setButtonValid( int id, bool isValid )
- {
- m_ui->m_destinationButtons->button( id )->setEnabled( isValid );
- }
-
- void UiController::changeDestination( int id )
- {
- bool destinationHasChanged = ( m_currentDestination != id );
- qDebug() << "Destination has changed=" << destinationHasChanged;
- if ( destinationHasChanged ) {
- qDebug() << "Emitting destination changed (" << m_destination[id]->label() << ")";
- emit destinationChanged( m_destination[id] );
- m_currentDestination = id;
- }
-
- // always want to emit this so that the gps position is updated
- // and the user gets new information
- emit buttonClicked();
- }
-
- void UiController::changeRoute( int id )
- {
- bool routeHasChanged = ( m_currentRoute != id );
- if ( routeHasChanged ) {
- displayRouteDetail( id );
- }
- }
-
- void UiController::displayRouteDetail( int id )
- {
- QTableWidget *table = m_ui->m_routeDetailTable;
-
- if ( id < m_routeData.count() ) {
- QList<LegData> &legDataList = m_routeData[ id ].m_legData;
- table->setRowCount( legDataList.count() );
-
- int row=0;
- foreach( LegData thisLegData, legDataList ) {
- QString thisHow = thisLegData.m_how;
-
- bool thisIsLine = ( thisHow == "LINE" );
- if ( thisIsLine ) {
- thisHow = thisLegData.m_lineCode;
- }
-
- QStringList tableStrings;
- tableStrings
- << thisHow
- << thisLegData.m_tripTime
- << thisLegData.m_tripDistance
- << thisLegData.m_departureTime
- << thisLegData.m_arrivalTime;
-
- int col=0;
- foreach( QString thisString, tableStrings ) {
- QTableWidgetItem *newItem = new QTableWidgetItem();
- newItem->setText( thisString );
- table->setItem( row,col, newItem );
- ++col;
- }
-
- ++row;
- }
- } else {
- table->setRowCount( 0 );
- }
-
- table->resizeColumnsToContents();
- }
-
- void UiController::displayRoute( const QList<RouteData> &routeData )
- {
- m_routeData = routeData;
-
- qDebug() << "displaying route";
-
- for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
- QString label;
-
- QWidget *widget = m_ui->m_routeStack->itemAt( i )->widget();
- QRadioButton *button = qobject_cast<QRadioButton *>(widget);
-
- if ( i<routeData.count() ) {
- RouteData thisRouteData = routeData.at(i);
- label = ( QStringList()
- << thisRouteData.m_departureTime
- << thisRouteData.m_lineCode ).join( "/" );
- button->setEnabled( true );
- } else {
- button->setEnabled( false );
- }
-
- if ( i==0 ) {
- button->setChecked( true );
- } else {
- button->setChecked( false );
- }
-
- button->setText( label );
- }
-
- displayRouteDetail( 0 );
- }
-#include "logic/ytv.h"
-#include "logic/location.h"
-#include "logic/locations.h"
-
-#include <QObject>
-#include <QPushButton>
-#include <QDebug>
-#include <QButtonGroup>
-#include <QRadioButton>
-#include <QVBoxLayout>
-#include <QTableWidgetItem>
-#include <QString>
-#ifdef Q_WS_MAEMO_5
-#include <QMaemo5AbstractPickSelector>
-#include <QMaemo5InformationBox>
-#endif
-
-UiController::UiController( UiClass *ui ) :
- m_routeData(),
- m_ui(ui),
- m_currentRoute(-1)
-{
- Locations *locations = Locations::GetInstance();
- /*if (locations->size() == 0)
- {
- locations->addEditLocation(new Location("Home"));
- locations->addEditLocation(new Location("Work"));
- }*/
-
- QObject::connect(m_ui->m_routeButton, SIGNAL(clicked()), this, SLOT(findRoute()));
-#ifdef Q_WS_MAEMO_5
- QObject::connect(this->m_ui->m_fromButton->pickSelector(), SIGNAL(selected(const QString &)), this, SLOT(changeFrom()));
- connect(m_ui->m_toButton->pickSelector(), SIGNAL(selected(const QString &)), this, SLOT(changeTo()));
-#endif
- connect(m_ui->m_routeButtons, SIGNAL(buttonClicked(int)), this, SLOT(displayRouteDetail(int)));
-}
-
-UiController::~UiController()
-{
-}
-
-void UiController::changeRoute( int id )
-{
- bool routeHasChanged = ( m_currentRoute != id );
- if ( routeHasChanged ) {
- displayRouteDetail( id );
- }
-}
-
-void UiController::displayRouteDetail( int id )
-{
- QTableWidget *table = m_ui->m_routeDetailTable;
-
- if ( id < m_routeData.count() ) {
- QList<LegData> &legDataList = m_routeData[ id ].m_legData;
- table->setRowCount( legDataList.count() );
-
- int row=0;
- foreach( LegData thisLegData, legDataList ) {
- QString thisHow = thisLegData.m_how;
-
- bool thisIsLine = ( thisHow == "LINE" );
- if ( thisIsLine ) {
- thisHow = thisLegData.m_lineCode;
- }
-
- QStringList tableStrings;
- tableStrings
- << thisHow
- << thisLegData.m_tripTime
- << thisLegData.m_tripDistance
- << thisLegData.m_departureTime
- << thisLegData.m_arrivalTime;
-
- int col=0;
- foreach( QString thisString, tableStrings ) {
- QTableWidgetItem *newItem = new QTableWidgetItem();
- newItem->setText( thisString );
- table->setItem( row,col, newItem );
- ++col;
- }
-
- ++row;
- }
- } else {
- table->setRowCount( 0 );
- }
-
- table->resizeColumnsToContents();
-}
-
-void UiController::displayRoute( const QList<RouteData> &routeData )
-{
- m_routeData = routeData;
-
- qDebug() << "displaying route";
-
- for ( int i=0; i<Ytv::ShowFiveResults; ++i ) {
- QString label;
-
- QWidget *widget = m_ui->m_routeStack->itemAt( i )->widget();
- QRadioButton *button = qobject_cast<QRadioButton *>(widget);
-
- if ( i<routeData.count() ) {
- RouteData thisRouteData = routeData.at(i);
- label = ( QStringList()
- << thisRouteData.m_departureTime
- << thisRouteData.m_lineCode ).join( "/" );
- button->setEnabled( true );
- } else {
- button->setEnabled( false );
- }
-
- if ( i==0 ) {
- button->setChecked( true );
- } else {
- button->setChecked( false );
- }
-
- button->setText( label );
- }
-
- displayRouteDetail( 0 );
-}
-
-void UiController::findRoute()
-{
- qDebug() << "Route search button clicked";
- emit(routeSearchRequested());
-}
-
-/*void UiController::updateLocationSelectors()
-{
- m_ui->setLocations();
-}*/
-
-void UiController::changeFrom()
-{
- qDebug() << "From selection changed";
- Locations *locations = Locations::GetInstance();
- Location *from;
-
-#ifdef Q_WS_MAEMO_5
- const QString newValue = m_ui->m_fromButton->valueText();
-#else
- const QString newValue = "";
-#endif
- if (newValue == "GPS")
- {
- from = locations->getGpsLocation();
- if (!from->isValid())
- {
- qDebug() << "GPS location is not valid.";
-#ifdef Q_WS_MAEMO_5
- QMaemo5InformationBox::information(this->m_ui->m_mainWindow, "GPS location has not been received yet. Wait a moment.");
-#endif
- //connect(from, SIGNAL(becomeValid()), this, SLOT(gpsBecameValid()));
- return;
- }
- }
- else
- {
- from = locations->getLocation(newValue);
- if (!from)
- qDebug() << "No location with label " << newValue << " was found.";
- }
- if (from)
- {
- qDebug() << "Emitting signal of new from selection";
- emit(fromChanged(from));
- }
-}
-
-void UiController::gpsBecameValid()
-{
-#ifdef Q_WS_MAEMO_5
- QMaemo5InformationBox::information(this->m_ui->m_mainWindow, "GPS location received.");
-#endif
- Location *gps = Locations::GetInstance()->getGpsLocation();
- //disconnect(gps, SIGNAL(becomeValid()), this, SLOT(gpsBecameValid()));
- this->changeFrom();
- this->changeTo();
-}
-
-void UiController::changeTo()
-{
- qDebug() << "To selection changed";
- Locations *locations = Locations::GetInstance();
- Location *to;
-
-#ifdef Q_WS_MAEMO_5
- const QString newValue = m_ui->m_toButton->valueText();
-#else
- const QString newValue = "";
-#endif
- if (newValue == "GPS")
- {
- to = locations->getGpsLocation();
- if (!to->isValid())
- {
- qDebug() << "GPS location is not valid.";
-#ifdef Q_WS_MAEMO_5
- QMaemo5InformationBox::information(this->m_ui->m_mainWindow, "GPS location has not been received yet. Wait a moment.");
-#endif
- //connect(to, SIGNAL(becomeValid()), this, SLOT(gpsBecameValid()));
- return;
- }
- }
- else
- {
- to = locations->getLocation(newValue);
- if (!to)
- qDebug() << "No location with label " << newValue << " was found.";
- }
- if (to)
- {
- qDebug() << "Emitting signal of new to selection";
- emit(toChanged(to));
- }
-}
+++ /dev/null
--#ifndef UICONTROLLER_H
--#define UICONTROLLER_H
--
--#include "routedata.h"
- #include "location.h"
-
- #include <QObject>
-
- class Ui;
-
- class UiController : public QObject
- {
- Q_OBJECT
-
- public:
- UiController( Ui *ui );
- ~UiController();
-
- public Q_SLOTS:
- void displayRoute( const QList<RouteData> &routeData );
-
- Q_SIGNALS:
- void buttonClicked();
- void destinationChanged( Location *newDestination );
-
- private Q_SLOTS:
- void changeDestination( int id );
- void changeRoute( int id );
- void setHomeButtonValid();
- void setWorkButtonValid();
- void setHomeButtonInValid();
- void setWorkButtonInValid();
- void displayRouteDetail( int id );
-
- private:
- void setButtonValid( int id, bool isValid );
-
- private:
- QList<RouteData> m_routeData;
- QList<Location*> m_destination;
- Ui *m_ui;
- int m_currentDestination;
- int m_currentRoute;
- };
- #endif // UICONTROLLER_H
-
-#include "logic/location.h"
-
-#include <QObject>
-
-class UiClass;
-
-class UiController : public QObject
-{
- Q_OBJECT
-
-public:
- UiController( UiClass *ui );
- ~UiController();
-
-public Q_SLOTS:
- void displayRoute( const QList<RouteData> &routeData );
- //void updateLocationSelectors();
- void changeFrom();
- void changeTo();
- void gpsBecameValid();
-
-Q_SIGNALS:
- void routeSearchRequested();
- void fromChanged(Location *newFromLocation);
- void toChanged(Location *newToLocation);
-
-private Q_SLOTS:
- void changeRoute( int id );
- void displayRouteDetail( int id );
- void findRoute();
-
-private:
- QList<RouteData> m_routeData;
- UiClass *m_ui;
- int m_currentRoute;
-};
-#endif // UICONTROLLER_H
-