#include "ytv.h"
#include "location.h"
#include "locations.h"
+#include "journey.h"
+#include "journeys.h"
#include <QObject>
#include <QPushButton>
UiController::UiController( Ui *ui ) :
m_routeData(),
- m_destination(),
+ m_journeys(),
m_ui(ui),
- m_currentDestination(-1),
+ m_currentJourney(-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() ) {
+ Journeys journeys;
+ Journey *gpsToHome = journeys.journey( "gps->home" );
+ Journey *gpsToWork = journeys.journey( "gps->work" );
+
+ if ( gpsToHome==0 ) {
+ gpsToHome = new Journey();
+ gpsToHome->setJourney( "gps", "home", "gps->home" );
+
+ journeys.addJourney( gpsToHome );
+ } else if ( gpsToHome->isValid() ) {
setHomeButtonValid();
}
- if ( workLocation==0 ) {
- workLocation = new Location( "work" );
- locations.addLocation( workLocation );
- } else if ( workLocation->isValid() ) {
+ if ( gpsToWork==0 ) {
+ gpsToWork = new Journey();
+ gpsToWork->setJourney( "gps", "work", "gps->work" );
+
+ journeys.addJourney( gpsToWork );
+ } else if ( gpsToWork->isValid() ) {
setWorkButtonValid();
}
connect(
- homeLocation, SIGNAL( becomeValid() ),
+ gpsToHome, SIGNAL( becomeValid() ),
this, SLOT( setHomeButtonValid() )
);
connect(
- homeLocation, SIGNAL( becomeInValid() ),
+ gpsToHome, SIGNAL( becomeInValid() ),
this, SLOT( setHomeButtonInValid() )
);
connect(
- homeLocation, SIGNAL( becomeValid() ),
- &locations, SLOT( saveLocation() )
+ gpsToHome, SIGNAL( becomeValid() ),
+ &journeys, SLOT( saveJourney() )
);
connect(
- homeLocation, SIGNAL( busy( bool ) ),
+ gpsToHome, SIGNAL( busy( bool ) ),
ui, SLOT( setBusy( bool ) )
);
connect(
- workLocation, SIGNAL( becomeValid() ),
+ gpsToWork, SIGNAL( becomeValid() ),
this, SLOT( setWorkButtonValid() )
);
connect(
- workLocation, SIGNAL( becomeInValid() ),
+ gpsToHome, SIGNAL( becomeInValid() ),
this, SLOT( setWorkButtonInValid() )
);
connect(
- workLocation, SIGNAL( becomeValid() ),
- &locations, SLOT( saveLocation() )
+ gpsToHome, SIGNAL( becomeValid() ),
+ &journeys, SLOT( saveJourney() )
);
connect(
- workLocation, SIGNAL( busy( bool ) ),
+ gpsToHome, SIGNAL( busy( bool ) ),
ui, SLOT( setBusy( bool ) )
);
- m_destination.append( homeLocation );
- m_destination.append( workLocation );
+ m_journeys.append( gpsToHome );
+ m_journeys.append( gpsToWork );
connect(
- m_ui->m_destinationButtons, SIGNAL( buttonClicked( int ) ),
+ m_ui->m_journeyButtons, SIGNAL( buttonClicked( int ) ),
this, SLOT( changeDestination( int ) )
);
connect(
- m_ui->m_routeButtons, SIGNAL( buttonClicked( int ) ),
+ m_ui->m_journeyButtons, SIGNAL( buttonClicked( int ) ),
this, SLOT( changeRoute( int ) )
);
}
void UiController::setButtonValid( int id, bool isValid )
{
- m_ui->m_destinationButtons->button( id )->setEnabled( isValid );
+ m_ui->m_journeyButtons->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;
+ bool journeyHasChanged = ( m_currentJourney != id );
+ qDebug() << "Journey has changed=" << journeyHasChanged;
+ if ( journeyHasChanged ) {
+ qDebug() << "Emitting journey changed (" << m_journeys[id]->label() << ")";
+ emit journeyChanged( m_journeys[id] );
+ m_currentJourney = id;
}
// always want to emit this so that the gps position is updated