+zouba (0.7) unstable; urgency=low
+
+ * Changed gps controller to use labels for fake gps instead of a new Location instance.
+
+ -- Max Waterman <davidmaxwaterman@fastmail.co.uk> Mon, 20 Apr 2010 06:27:00 +0200
+
zouba (0.6) unstable; urgency=low
* Changed layout in preparation for multiple routes
-zouba_0.6_armel.deb user/navigation extra
+zouba_0.7_armel.deb user/navigation extra
#include "gpscontroller.h"
#include "gpscontroller_p.h"
+#include "locations.h"
+
#include <QObject>
#include <QGeoPositionInfo>
#include <QGeoPositionInfoSource>
void GpsController::getGps()
{
- if ( q->currentLocation() != 0 ) {
- emit locationChanged( q->currentLocation() );
+ Location *location;
+
+ if ( q->useFakeLocation() ) {
+ Locations *locations = Locations::instance();
+ location = locations->location( q->fakeLocationLabel() );
+ } else {
+ location = q->liveLocation();
}
+
+ emit locationChanged( location );
}
void GpsController::useLiveGps()
{
q->setUseFakeLocation( false );
- q->setCurrentLocation( new Location( "livegps" ) );
q->startGps();
+ emit locationChanged( q->liveLocation() );
}
-void GpsController::useFakeGps( Location *fakeLocation )
+void GpsController::useFakeGps( const QString &fakeLocationLabel )
{
- qDebug() << "using fake gps (" << fakeLocation->label() << ")";
- q->stopGps();
- q->setUseFakeLocation( true );
- q->setCurrentLocation( fakeLocation );
- emit locationChanged( q->currentLocation() );
+ qDebug() << "using fake gps (" << fakeLocationLabel << ")";
+
+ Locations *locations = Locations::instance();
+ Location *fakeLocation = locations->location( fakeLocationLabel );
+
+ if ( fakeLocation == 0 ) {
+ qDebug() << "invalid fake location label; cannot use fake location";
+ } else {
+ q->stopGps();
+ q->setUseFakeLocation( true );
+ q->setFakeLocationLabel( fakeLocationLabel );
+ emit locationChanged( fakeLocation );
+ }
}
public Q_SLOTS:
void getGps();
- void useFakeGps( Location *fakeLocation );
+ void useFakeGps( const QString &fakeLocationLabel );
void useLiveGps();
Q_SIGNALS:
GpsControllerPrivate::GpsControllerPrivate() :
m_gps(0),
- m_currentLocation(0),
+ m_liveLocation( new Location( "livegps" ) ),
+ m_fakeLocationLabel(),
m_useFakeLocation(false)
{
}
{
delete m_gps;
m_gps = 0;
- delete m_currentLocation;
- m_currentLocation = 0;
+ delete m_liveLocation;
+ m_liveLocation = 0;
}
void GpsControllerPrivate::init()
m_gps = gps;
}
-Location *GpsControllerPrivate::currentLocation()
+Location *GpsControllerPrivate::liveLocation()
{
- return m_currentLocation;
+ return m_liveLocation;
}
-void GpsControllerPrivate::setCurrentLocation( Location *location )
+QString GpsControllerPrivate::fakeLocationLabel()
{
- if ( m_currentLocation && m_currentLocation->label() == "livegps" ) {
- delete m_currentLocation;
- m_currentLocation=0;
- }
- m_currentLocation = location;
+ return m_fakeLocationLabel;
+}
+
+void GpsControllerPrivate::setFakeLocationLabel( const QString &label )
+{
+ m_fakeLocationLabel = label;
}
bool GpsControllerPrivate::useFakeLocation()
void GpsControllerPrivate::setUseFakeLocation( bool useFake )
{
- // delete previous GPS if it was live and we're switching to fake
- if ( m_currentLocation && m_currentLocation->label() == "livegps" ) {
- delete m_currentLocation;
- m_currentLocation = 0;
- }
m_useFakeLocation = useFake;
}
void GpsControllerPrivate::updateLocation( QGeoPositionInfo positionInfo )
{
- if ( m_currentLocation && m_currentLocation->label() == "livegps" ) {
- delete m_currentLocation;
- }
- m_currentLocation = new Location( positionInfo, "livegps" );
+ m_liveLocation->setLocation( positionInfo );
}
virtual void stopGps();
virtual void setGps( QGeoPositionInfoSource *gps );
- virtual void setCurrentLocation( Location *location );
+ virtual void setFakeLocationLabel( const QString &label );
virtual void setUseFakeLocation( bool useFake );
virtual QGeoPositionInfoSource *gps();
- virtual Location *currentLocation();
- virtual bool useFakeLocation();
+ virtual Location *liveLocation();
+ virtual QString fakeLocationLabel();
+ virtual bool useFakeLocation();
private Q_SLOTS:
virtual void updateLocation( QGeoPositionInfo positionInfo );
private:
QGeoPositionInfoSource *m_gps;
- Location *m_currentLocation;
+ Location *m_liveLocation;
+ QString m_fakeLocationLabel;
bool m_useFakeLocation;
};
q( new LocationPrivate( label ) ),
manager(0)
{
- qDebug() << "Location::Location( QGeoPositionInfo, label=" << label << " )";
+ setLocation( positionInfo );
+}
+
+void Location::setLocation( const QGeoPositionInfo &positionInfo )
+{
qreal latitude = positionInfo.coordinate().latitude();
qreal longitude = positionInfo.coordinate().longitude();
QString y() const;
+ void setLocation( const QGeoPositionInfo &positionInfo );
+
void setAddress( const QString &address ) const;
QString address() const;
void replyFinished( QNetworkReply * reply );
private:
+
LocationPrivate *q;
QNetworkAccessManager *manager;
int main(int argc, char *argv[] )
{
- qInstallMsgHandler( messageHandler );
+ //qInstallMsgHandler( messageHandler );
QApplication app(argc, argv);
QMainWindow *mainWindow = new QMainWindow;
);
QObject::connect(
- ui, SIGNAL( fakeGpsPressed( Location* ) ),
- gpsController, SLOT( useFakeGps( Location* ) )
+ ui, SIGNAL( fakeGpsPressed( const QString & ) ),
+ gpsController, SLOT( useFakeGps( const QString & ) )
);
QObject::connect(
routeTable(0),
usingFakeGps( false ),
messagesShown( false ),
- fakeLocation()
+ fakeLocationLabel( "work" )
{
- Locations *locations = Locations::instance();
- Location *workLocation = locations->location( "work" );
- fakeLocation = new Location();
- *fakeLocation = *workLocation;
- fakeLocation->setLabel( "fakegps" );
}
Ui::~Ui()
void Ui::useFakeGps()
{
- emit fakeGpsPressed( fakeLocation );
+ emit fakeGpsPressed( fakeLocationLabel );
toggleFakeGpsAction->setText( "Use Live GPS" );
}
QAction *useLiveGpsAction;
bool usingFakeGps;
bool messagesShown;
- Location *fakeLocation;
+ QString fakeLocationLabel;
Q_SIGNALS:
void homeAddressChanged( QString address );
void workAddressChanged( QString address );
- void fakeGpsPressed( Location * );
+ void fakeGpsPressed( const QString &fakeLocationLabel );
void liveGpsPressed();
private Q_SLOTS: