--- /dev/null
+#include "journey.h"
+
+#include "journey_p.h"
+
+#include <QString>
+#include <QObject>
+#include <QDebug>
+
+QTM_USE_NAMESPACE
+
+Journey::Journey() :
+ q( new JourneyPrivate() )
+{
+}
+
+Journey::~Journey()
+{
+ delete q;
+ q=0;
+}
+
+void Journey::setJourney( const QString &from, const QString &to, const QString &label )
+{
+ q->setFrom( from );
+ q->setTo( to );
+ q->setLabel( label );
+}
+
+QString Journey::from() const
+{
+ return q->from();
+}
+
+QString Journey::to() const
+{
+ return q->to();
+}
+
+void Journey::setLabel( const QString &label ) const
+{
+ q->setLabel( label );
+}
+
+QString Journey::label() const
+{
+ return q->label();
+}
+
+bool Journey::isValid() const
+{
+ return q->isValid();
+}
--- /dev/null
+#ifndef JOURNEY_H
+#define JOURNEY_H
+
+#include "journey_p.h"
+
+#include <QString>
+#include <QObject>
+#include <QNetworkAccessManager>
+#include <QNetworkReply>
+#include <QGeoPositionInfo>
+#include <math.h>
+
+QTM_USE_NAMESPACE
+
+class Journey : public QObject
+{
+Q_OBJECT
+
+public:
+ Journey();
+
+ ~Journey();
+
+
+ void setJourney( const QString &from, const QString &to, const QString &label=QString() );
+
+ QString from() const;
+ QString to() const;
+
+ void setLabel( const QString &label ) const;
+ QString label() const;
+
+ bool isValid() const;
+
+Q_SIGNALS:
+ void becomeValid();
+ void becomeInValid();
+ void busy( bool busy );
+
+private:
+ JourneyPrivate *q;
+};
+
+#endif // JOURNEY_H
--- /dev/null
+#include "locations.h"
+#include "location.h"
+
+#include "journey_p.h"
+
+JourneyPrivate::JourneyPrivate():
+ m_from(),
+ m_to(),
+ m_label()
+{
+}
+
+JourneyPrivate::~JourneyPrivate()
+{
+}
+
+void JourneyPrivate::setFrom( const QString &from )
+{
+ m_from = from;
+
+ setValid( fromAndToAreValid() );
+}
+
+QString JourneyPrivate::from() const
+{
+ return m_from;
+}
+
+void JourneyPrivate::setTo( const QString &to )
+{
+ m_to = to;
+
+ setValid( fromAndToAreValid() );
+}
+
+QString JourneyPrivate::to() const
+{
+ return m_to;
+}
+
+void JourneyPrivate::setLabel( const QString &label )
+{
+ m_label = label;
+}
+
+QString JourneyPrivate::label() const
+{
+ return m_label;
+}
+
+void JourneyPrivate::setValid( bool valid )
+{
+ m_valid = valid;
+}
+
+bool JourneyPrivate::isValid() const
+{
+ return m_valid;
+}
+
+bool JourneyPrivate::fromAndToAreValid() const
+{
+ bool retVal = false;
+
+ Locations locations;
+ Location *fromLocation = locations.location( m_from );
+ Location *toLocation = locations.location( m_to );
+
+ retVal = fromLocation==0 && fromLocation->isValid() &&
+ toLocation==0 && toLocation->isValid();
+
+ return retVal;
+}
--- /dev/null
+#ifndef JOURNEY_P_H
+#define JOURNEY_P_H
+
+#include <QObject>
+#include <QString>
+#include <QByteArray>
+
+class JourneyPrivate : public QObject
+{
+ Q_OBJECT
+
+public:
+ JourneyPrivate();
+ virtual ~JourneyPrivate();
+
+ void setFrom( const QString &from );
+ QString from() const;
+
+ void setTo( const QString &to );
+ QString to() const;
+
+ void setLabel( const QString &label );
+ QString label() const;
+
+ void setValid( bool valid );
+ bool isValid() const;
+
+private:
+ bool fromAndToAreValid() const;
+
+ QString m_from;
+ QString m_to;
+ QString m_label;
+ bool m_valid;
+};
+
+#endif // JOURNEY_P_H
+
--- /dev/null
+#include "journeys.h"
+
+#include <QDebug>
+#include <QHash>
+#include <QSettings>
+#include <QString>
+#include <QStringList>
+#include <QCoreApplication>
+
+QHash<QString,Journey *> Journeys::journeyHash;
+bool Journeys::initialised = false;
+
+Journeys::Journeys()
+{
+ if ( !initialised ) {
+ restoreJourneys();
+ initialised = true;
+ }
+}
+
+Journeys::~Journeys()
+{
+}
+
+bool Journeys::addJourney( Journey *journey )
+{
+ bool succeeded=false;
+
+ saveJourney( journey );
+
+ if ( !journeyHash.contains( journey->label() ) ) {
+ qDebug() << "Adding journey" << journey->label();
+ journeyHash[ journey->label() ] = journey;
+ succeeded = true;
+ } else {
+ qDebug() << "FAILED to add journey" << journey->label();
+ }
+
+ return succeeded;
+}
+
+void Journeys::restoreJourneys()
+{
+ QSettings settings;
+
+ settings.beginGroup( "Journeys" );
+ QStringList labels = settings.childGroups();
+
+ for( int i=0; i<labels.size(); ++i ) {
+ QString label = labels[i];
+ settings.beginGroup( label );
+ QString from = settings.value( "from" ).toString();
+ QString to = settings.value( "to" ).toString();
+ settings.endGroup();
+
+ qDebug() << "restoring" << label;
+ Journey *journey = new Journey();
+ journey->setJourney( from, to, label );
+
+ journeyHash[ label ] = journey;
+ }
+
+ settings.endGroup();
+}
+
+void Journeys::saveJourney( Journey *journey )
+{
+ qDebug() << "Saving journey" << journey->label();
+ QSettings settings;
+ settings.beginGroup( "Journeys" );
+ settings.beginGroup( journey->label() );
+ settings.setValue( "from", journey->from() );
+ settings.setValue( "to", journey->to() );
+ settings.endGroup();
+ settings.endGroup();
+}
+
+void Journeys::saveJourney()
+{
+ Journey *journey = qobject_cast<Journey*>(sender());
+
+ saveJourney( journey );
+}
+
+Journey *Journeys::journey( const QString &label )
+{
+ qDebug() << "requesting journey" << label;
+ Journey *retVal = 0;
+
+ if ( journeyHash.contains( label ) ) {
+ qDebug() << "found journey" << label;
+ retVal = journeyHash[ label ];
+ } else {
+ qDebug() << "didn't find journey" << label;
+ }
+
+ return retVal;
+}
--- /dev/null
+#ifndef JOURNEYS_H
+#define JOURNEYS_H
+
+#include "journey.h"
+
+#include <QHash>
+#include <QString>
+#include <QObject>
+
+class Journeys: public QObject
+{
+ Q_OBJECT
+
+public:
+ Journeys();
+ ~Journeys();
+
+ bool addJourney( Journey *journey );
+
+ Journey *journey( const QString &label );
+
+private:
+ void saveJourney( Journey *journey );
+ void saveJourney();
+ void restoreJourneys();
+ static QHash<QString,Journey *> journeyHash;
+ static bool initialised;
+};
+
+#endif //JOURNEYS_H
LocationPrivate::LocationPrivate( const QString &label ) :
m_label(label),
m_address(),
- m_x(0),
- m_y(0),
+ m_x(),
+ m_y(),
m_valid(false)
{
}
--- /dev/null
+#include "locationpicker.h"
+
+LocationPicker::LocationPicker( QObject *parent )
+ QDialog( parent )
+{
+}
+
+LocationPicker::~LocationPicker()
+{
+}
--- /dev/null
+#ifndef LOCATIONPICKER_H
+#define LOCATIONPICKER_H
+
+class LocationPicker: public QDialog
+{
+ Q_OBJECT
+
+public:
+ LocationPicker( QObject *parent=0 );
+ ~LocationPicker();
+};
+#endif // LOCATIONPICKER_H
Locations::Locations()
{
if ( !initialised ) {
- QCoreApplication::setOrganizationName("ZouBa");
- QCoreApplication::setOrganizationDomain("zouba.yi.org");
- QCoreApplication::setOrganizationName("ZouBa");
-
restoreLocations();
initialised = true;
}
Locations();
~Locations();
- static Locations *instance();
bool addLocation( Location *location );
Location *location( const QString &label );
int main(int argc, char *argv[] )
{
QApplication app(argc, argv);
+ QCoreApplication::setOrganizationName("ZouBa");
+ QCoreApplication::setOrganizationDomain("zouba.yi.org");
+ QCoreApplication::setOrganizationName("ZouBa");
QMainWindow *mainWindow = new QMainWindow;
Ui *ui = new Ui;;
QObject::connect(
uiController, SIGNAL( destinationChanged( Location* ) ),
route, SLOT( setToLocation( Location* ) )
- );
+ );
QObject::connect(
uiController, SIGNAL( buttonClicked() ),
gpsController, SLOT( getGps() )
- );
+ );
QObject::connect(
ui, SIGNAL( fakeGpsPressed( const QString & ) ),
gpsController, SLOT( useFakeGps( const QString & ) )
- );
+ );
QObject::connect(
ui, SIGNAL( liveGpsPressed() ),
gpsController, SLOT( useLiveGps() )
- );
+ );
QObject::connect(
route, SIGNAL( busy( bool ) ),
ui, SLOT( setBusy( bool ) )
- );
+ );
mainWindow->show();
Ui::Ui() :
m_centralWidget(0),
- m_destinationButtons(0),
+ m_journeyButtons(0),
m_routeStack(0),
m_usingFakeGps( false ),
m_fakeLocationLabel( "work" )
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 *gpsToHomeButton = new QRadioButton();
+ gpsToHomeButton->setObjectName( QString::fromUtf8("gpsToHomeButton") );
+ gpsToHomeButton->setText( "GPS->HOME" );
+ gpsToHomeButton->setEnabled(false);
- QRadioButton *workButton = new QRadioButton();
- workButton->setObjectName( QString::fromUtf8("workButton") );
- workButton->setText( "GPS->WORK" );
- workButton->setEnabled(false);
+ QRadioButton *gpstoWorkButton = new QRadioButton();
+ gpstoWorkButton->setObjectName( QString::fromUtf8("gpstoWorkButton") );
+ gpstoWorkButton->setText( "GPS->WORK" );
+ gpstoWorkButton->setEnabled(false);
- m_destinationButtons = new QButtonGroup();
- m_destinationButtons->addButton( homeButton, HomeButtonId );
- m_destinationButtons->addButton( workButton, WorkButtonId );
- m_destinationButtons->setExclusive( true );
+ m_journeyButtons = new QButtonGroup();
+ m_journeyButtons->addButton( gpsToHomeButton, HomeButtonId );
+ m_journeyButtons->addButton( gpstoWorkButton, WorkButtonId );
+ m_journeyButtons->setExclusive( true );
m_routeButtons = new QButtonGroup();
m_routeButtons->setExclusive( true );
topLayout->addWidget( m_routeDetailTable );
m_buttonLayout = new QGridLayout();
- m_buttonLayout->addWidget( homeButton, 0, 0 );
- m_buttonLayout->addWidget( workButton, 0, 1 );
+ m_buttonLayout->addWidget( gpsToHomeButton, 0, 0 );
+ m_buttonLayout->addWidget( gpstoWorkButton, 0, 1 );
m_mainLayout = new QVBoxLayout();
m_mainLayout->addLayout( topLayout );
QMainWindow *m_mainWindow;
QWidget *m_centralWidget;
- QButtonGroup *m_destinationButtons;
+ QButtonGroup *m_journeyButtons;
QButtonGroup *m_routeButtons;
QVBoxLayout *m_routeStack;
QTableWidget *m_routeDetailTable;
#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
#include <QObject>
class Ui;
+class Journey;
class UiController : public QObject
{
Q_SIGNALS:
void buttonClicked();
- void destinationChanged( Location *newDestination );
+ void journeyChanged( Journey *newJourney );
private Q_SLOTS:
void changeDestination( int id );
private:
QList<RouteData> m_routeData;
- QList<Location*> m_destination;
+ QList<Journey*> m_journeys;
Ui *m_ui;
- int m_currentDestination;
+ int m_currentJourney;
int m_currentRoute;
};
#endif // UICONTROLLER_H
location.cpp \
location_p.cpp \
locations.cpp \
+ journey.cpp \
+ journey_p.cpp \
+ journeys.cpp \
gpscontroller.cpp \
gpscontroller_p.cpp \
ui.cpp \
location.h \
location_p.h \
locations.h \
+ journey.h \
+ journey_p.h \
+ journeys.h \
ytv.h \
gpscontroller.h \
gpscontroller_p.h \