#include "gpscontroller.h"
+#include "gpscontroller_p.h"
#include <QObject>
#include <QGeoPositionInfo>
#include <QGeoPositionInfoSource>
#include <QDebug>
-QTM_USE_NAMESPACE
-
GpsController::GpsController() :
- m_location( QGeoPositionInfoSource::createDefaultSource(this) ),
- m_currentLocation(0),
- m_useFakeLocation(false)
+ q( new GpsControllerPrivate() )
{
- connect(
- m_location, SIGNAL( positionUpdated( QGeoPositionInfo ) ),
- this, SLOT( updateLocation( QGeoPositionInfo ) )
- );
-
- m_location->startUpdates();
+ q->init();
+ q->startGps();
}
-GpsController::~GpsController()
+GpsController::GpsController( GpsControllerPrivate *gpsControllerPrivate ) :
+ q( gpsControllerPrivate )
{
- delete m_location;
- m_location = 0;
- delete m_currentLocation;
- m_currentLocation = 0;
+ q->init();
+ q->startGps();
}
-void GpsController::updateLocation( QGeoPositionInfo positionInfo )
+GpsController::~GpsController()
{
- delete m_currentLocation;
- m_currentLocation = new Location( positionInfo );
+ delete q;
}
void GpsController::getGps()
{
- if ( m_currentLocation != 0 ) {
- emit locationChanged( m_currentLocation );
+ if ( q->currentLocation() != 0 ) {
+ emit locationChanged( q->currentLocation() );
}
}
void GpsController::useLiveGps()
{
- m_location->startUpdates();
- m_useFakeLocation=false;
- m_currentLocation=0;
+ q->setUseFakeLocation( false );
+ q->setCurrentLocation(0);
+ q->startGps();
}
void GpsController::useFakeGps( Location *fakeLocation )
{
- m_location->stopUpdates();
- m_useFakeLocation=true;
- delete m_currentLocation;
- m_currentLocation = new Location( *fakeLocation );
- emit locationChanged( m_currentLocation );
+ q->stopGps();
+ q->setUseFakeLocation( true );
+ q->setCurrentLocation( fakeLocation );
+ emit locationChanged( q->currentLocation() );
}
#include "location.h"
+#include "gpscontroller_p.h"
+
#include <QObject>
#include <QGeoPositionInfo>
#include <QGeoPositionInfoSource>
public:
GpsController();
+ GpsController( GpsControllerPrivate *gpsControllerPrivate );
~GpsController();
public Q_SLOTS:
- void updateLocation( QGeoPositionInfo positionInfo );
void getGps();
void useFakeGps( Location *fakeLocation );
void useLiveGps();
void locationChanged( Location *newLocation );
private:
- QGeoPositionInfoSource *m_location;
- Location *m_currentLocation;
- bool m_useFakeLocation;
+ GpsControllerPrivate *q;
};
#endif // GPSCONTROLLER_H
--- /dev/null
+#include "gpscontroller_p.h"
+
+#include "location.h"
+
+#include <QObject>
+#include <QGeoPositionInfo>
+#include <QGeoPositionInfoSource>
+#include <QDebug>
+
+QTM_USE_NAMESPACE
+
+GpsControllerPrivate::GpsControllerPrivate() :
+ m_gps(0),
+ m_currentLocation(0),
+ m_useFakeLocation(false)
+{
+}
+
+GpsControllerPrivate::~GpsControllerPrivate()
+{
+ delete m_gps;
+ m_gps = 0;
+ delete m_currentLocation;
+ m_currentLocation = 0;
+}
+
+void GpsControllerPrivate::init()
+{
+ m_gps = QGeoPositionInfoSource::createDefaultSource(this);
+ connect(
+ m_gps, SIGNAL( positionUpdated( QGeoPositionInfo ) ),
+ this, SLOT( updateLocation( QGeoPositionInfo ) )
+ );
+}
+
+void GpsControllerPrivate::startGps()
+{
+ m_gps->startUpdates();
+}
+
+void GpsControllerPrivate::stopGps()
+{
+ m_gps->stopUpdates();
+}
+
+QGeoPositionInfoSource *GpsControllerPrivate::gps()
+{
+ return m_gps;
+}
+
+void GpsControllerPrivate::setGps( QGeoPositionInfoSource *gps )
+{
+ m_gps = gps;
+}
+
+Location *GpsControllerPrivate::currentLocation()
+{
+ return m_currentLocation;
+}
+
+void GpsControllerPrivate::setCurrentLocation( Location *location )
+{
+ delete m_currentLocation;
+ m_currentLocation = location;
+}
+
+bool GpsControllerPrivate::useFakeLocation()
+{
+ return m_useFakeLocation;
+}
+
+void GpsControllerPrivate::setUseFakeLocation( bool useFake )
+{
+ m_useFakeLocation = useFake;
+}
+
+void GpsControllerPrivate::updateLocation( QGeoPositionInfo positionInfo )
+{
+ if ( !m_useFakeLocation ) {
+ delete m_currentLocation;
+ m_currentLocation = new Location( positionInfo );
+ }
+}
+
--- /dev/null
+#ifndef GPSCONTROLLER_P_H
+#define GPSCONTROLLER_P_H
+
+#include <QGeoPositionInfo>
+#include <QGeoPositionInfoSource>
+
+QTM_USE_NAMESPACE
+
+class Location;
+
+class GpsControllerPrivate : public QObject
+{
+ Q_OBJECT
+
+public:
+ GpsControllerPrivate();
+ ~GpsControllerPrivate();
+
+ virtual void init();
+ virtual void startGps();
+ virtual void stopGps();
+
+ virtual void setGps( QGeoPositionInfoSource *gps );
+ virtual void setCurrentLocation( Location *location );
+ virtual void setUseFakeLocation( bool useFake );
+
+ virtual QGeoPositionInfoSource *gps();
+ virtual Location *currentLocation();
+ virtual bool useFakeLocation();
+
+private Q_SLOTS:
+ virtual void updateLocation( QGeoPositionInfo positionInfo );
+
+private:
+ QGeoPositionInfoSource *m_gps;
+ Location *m_currentLocation;
+ bool m_useFakeLocation;
+};
+
+#endif //GPSCONTROLLER_P_H
qDebug() << "To not valid - waiting";
}
} else {
- qDebug() << "From is not valid";
- qDebug() << "getting From from signal sender";
- location = qobject_cast<Location*>(sender());
- if ( location ) {
- q->setFromLocation( location );
- if ( q->toValid() ) {
- qDebug() << "To is also valid";
- getRoute();
- } else {
- qDebug() << "To not valid - waiting";
- }
- } else {
- qDebug() << "location is zero - cast didn't work";
- }
+ qDebug() << "ERROR:From is not valid";
}
}
}
} else {
qDebug() << "To is not valid";
- qDebug() << "getting To from signal sender";
- Location *location = qobject_cast<Location*>(sender());
- if ( location ) {
- q->setToLocation( location );
- if ( q->fromValid() ) {
- qDebug() << "From is also valid";
- getRoute();
- } else {
- qDebug() << "From not valid - waiting";
- }
- } else {
- qDebug() << "location is zero; cast failed";
- }
+ qDebug() << "ERROR:location is zero; cast failed";
}
}
--- /dev/null
+#############################################################################
+# Makefile for building: ut_gpscontroller
+# Generated by qmake (2.01a) (Qt 4.6.2) on: Wed Apr 14 08:39:47 2010
+# Project: ut_gpscontroller.pro
+# Template: app
+# Command: /usr/bin/qmake -unix -o Makefile ut_gpscontroller.pro
+#############################################################################
+
+####### Compiler, tools and options
+
+CC = gcc
+CXX = g++
+DEFINES = -DQT_GL_NO_SCISSOR_TEST -DQT_DEFAULT_TEXTURE_GLYPH_CACHE_WIDTH=1024 -DQT_TESTLIB_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED
+CFLAGS = -pipe -g -D_REENTRANT -Wall -W $(DEFINES)
+CXXFLAGS = -pipe -g -D_REENTRANT -Wall -W $(DEFINES)
+INCPATH = -I/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/linux-g++-maemo5 -I. -I/targets/FREMANTLE_ARMEL/usr/include/QtCore -I/targets/FREMANTLE_ARMEL/usr/include/QtNetwork -I/targets/FREMANTLE_ARMEL/usr/include/QtGui -I/targets/FREMANTLE_ARMEL/usr/include/QtTest -I/targets/FREMANTLE_ARMEL/usr/include -I../../src -I.
+LINK = g++
+LFLAGS = -Wl,-rpath-link,/usr/lib -Wl,-rpath,/usr/lib
+LIBS = $(SUBLIBS) -L/usr/lib /usr/lib/libQtLocation.so -lQtTest -L/usr/lib -lQtGui -L/usr/X11R6/lib -lQtNetwork -lQtDBus -lQtXml -lQtCore -lpthread
+AR = ar cqs
+RANLIB =
+QMAKE = /usr/bin/qmake
+TAR = tar -cf
+COMPRESS = gzip -9f
+COPY = cp -f
+SED = sed
+COPY_FILE = $(COPY)
+COPY_DIR = $(COPY) -r
+STRIP = strip
+INSTALL_FILE = install -m 644 -p
+INSTALL_DIR = $(COPY_DIR)
+INSTALL_PROGRAM = install -m 755 -p
+DEL_FILE = rm -f
+SYMLINK = ln -f -s
+DEL_DIR = rmdir
+MOVE = mv -f
+CHK_DIR_EXISTS= test -d
+MKDIR = mkdir -p
+
+####### Output directory
+
+OBJECTS_DIR = ./
+
+####### Files
+
+SOURCES = ut_gpscontroller.cpp \
+ ../../src/gpscontroller.cpp \
+ ../../src/gpscontroller_p.cpp \
+ ../../src/location.cpp \
+ ../../src/location_p.cpp moc_ut_gpscontroller.cpp \
+ moc_gpscontroller.cpp \
+ moc_gpscontroller_p.cpp \
+ moc_location.cpp \
+ moc_location_p.cpp
+OBJECTS = ut_gpscontroller.o \
+ gpscontroller.o \
+ gpscontroller_p.o \
+ location.o \
+ location_p.o \
+ moc_ut_gpscontroller.o \
+ moc_gpscontroller.o \
+ moc_gpscontroller_p.o \
+ moc_location.o \
+ moc_location_p.o
+DIST = /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/common/unix.conf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/common/linux.conf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/qconfig.pri \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/qt_functions.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/qt_config.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/default_pre.prf \
+ ../tests.pri \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/debug.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/default_post.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/qt.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/unix/thread.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/moc.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/warn_on.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/resources.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/uic.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/yacc.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/lex.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/include_source_dir.prf \
+ ut_gpscontroller.pro
+QMAKE_TARGET = ut_gpscontroller
+DESTDIR =
+TARGET = ut_gpscontroller
+
+first: all
+####### Implicit rules
+
+.SUFFIXES: .o .c .cpp .cc .cxx .C
+
+.cpp.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
+
+.cc.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
+
+.cxx.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
+
+.C.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
+
+.c.o:
+ $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
+
+####### Build rules
+
+all: Makefile $(TARGET)
+
+$(TARGET): $(OBJECTS)
+ $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
+
+Makefile: ut_gpscontroller.pro /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/linux-g++-maemo5/qmake.conf /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/common/unix.conf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/common/linux.conf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/qconfig.pri \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/qt_functions.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/qt_config.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/default_pre.prf \
+ ../tests.pri \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/debug.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/default_post.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/qt.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/unix/thread.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/moc.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/warn_on.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/resources.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/uic.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/yacc.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/lex.prf \
+ /targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/include_source_dir.prf \
+ /usr/lib/libQtTest.prl \
+ /usr/lib/libQtCore.prl \
+ /usr/lib/libQtGui.prl \
+ /usr/lib/libQtNetwork.prl \
+ /usr/lib/libQtDBus.prl \
+ /usr/lib/libQtXml.prl
+ $(QMAKE) -unix -o Makefile ut_gpscontroller.pro
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/common/unix.conf:
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/common/linux.conf:
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/qconfig.pri:
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/qt_functions.prf:
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/qt_config.prf:
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/exclusive_builds.prf:
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/default_pre.prf:
+../tests.pri:
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/debug.prf:
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/default_post.prf:
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/qt.prf:
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/unix/thread.prf:
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/moc.prf:
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/warn_on.prf:
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/resources.prf:
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/uic.prf:
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/yacc.prf:
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/lex.prf:
+/targets/FREMANTLE_ARMEL/usr/share/qt4/mkspecs/features/include_source_dir.prf:
+/usr/lib/libQtTest.prl:
+/usr/lib/libQtCore.prl:
+/usr/lib/libQtGui.prl:
+/usr/lib/libQtNetwork.prl:
+/usr/lib/libQtDBus.prl:
+/usr/lib/libQtXml.prl:
+qmake: FORCE
+ @$(QMAKE) -unix -o Makefile ut_gpscontroller.pro
+
+dist:
+ @$(CHK_DIR_EXISTS) .tmp/ut_gpscontroller1.0.0 || $(MKDIR) .tmp/ut_gpscontroller1.0.0
+ $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/ut_gpscontroller1.0.0/ && $(COPY_FILE) --parents ut_gpscontroller.h ../../src/gpscontroller.h ../../src/gpscontroller_p.h ../../src/location.h ../../src/location_p.h .tmp/ut_gpscontroller1.0.0/ && $(COPY_FILE) --parents ut_gpscontroller.cpp ../../src/gpscontroller.cpp ../../src/gpscontroller_p.cpp ../../src/location.cpp ../../src/location_p.cpp .tmp/ut_gpscontroller1.0.0/ && (cd `dirname .tmp/ut_gpscontroller1.0.0` && $(TAR) ut_gpscontroller1.0.0.tar ut_gpscontroller1.0.0 && $(COMPRESS) ut_gpscontroller1.0.0.tar) && $(MOVE) `dirname .tmp/ut_gpscontroller1.0.0`/ut_gpscontroller1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/ut_gpscontroller1.0.0
+
+
+clean:compiler_clean
+ -$(DEL_FILE) $(OBJECTS)
+ -$(DEL_FILE) *~ core *.core
+
+
+####### Sub-libraries
+
+distclean: clean
+ -$(DEL_FILE) $(TARGET)
+ -$(DEL_FILE) Makefile
+
+
+mocclean: compiler_moc_header_clean compiler_moc_source_clean
+
+mocables: compiler_moc_header_make_all compiler_moc_source_make_all
+
+compiler_moc_header_make_all: moc_ut_gpscontroller.cpp moc_gpscontroller.cpp moc_gpscontroller_p.cpp moc_location.cpp moc_location_p.cpp
+compiler_moc_header_clean:
+ -$(DEL_FILE) moc_ut_gpscontroller.cpp moc_gpscontroller.cpp moc_gpscontroller_p.cpp moc_location.cpp moc_location_p.cpp
+moc_ut_gpscontroller.cpp: ut_gpscontroller.h
+ /usr/bin/moc $(DEFINES) $(INCPATH) ut_gpscontroller.h -o moc_ut_gpscontroller.cpp
+
+moc_gpscontroller.cpp: ../../src/location.h \
+ ../../src/location_p.h \
+ ../../src/gpscontroller_p.h \
+ ../../src/gpscontroller.h
+ /usr/bin/moc $(DEFINES) $(INCPATH) ../../src/gpscontroller.h -o moc_gpscontroller.cpp
+
+moc_gpscontroller_p.cpp: ../../src/gpscontroller_p.h
+ /usr/bin/moc $(DEFINES) $(INCPATH) ../../src/gpscontroller_p.h -o moc_gpscontroller_p.cpp
+
+moc_location.cpp: ../../src/location_p.h \
+ ../../src/location.h
+ /usr/bin/moc $(DEFINES) $(INCPATH) ../../src/location.h -o moc_location.cpp
+
+moc_location_p.cpp: ../../src/location_p.h
+ /usr/bin/moc $(DEFINES) $(INCPATH) ../../src/location_p.h -o moc_location_p.cpp
+
+compiler_rcc_make_all:
+compiler_rcc_clean:
+compiler_image_collection_make_all: qmake_image_collection.cpp
+compiler_image_collection_clean:
+ -$(DEL_FILE) qmake_image_collection.cpp
+compiler_moc_source_make_all:
+compiler_moc_source_clean:
+compiler_uic_make_all:
+compiler_uic_clean:
+compiler_yacc_decl_make_all:
+compiler_yacc_decl_clean:
+compiler_yacc_impl_make_all:
+compiler_yacc_impl_clean:
+compiler_lex_make_all:
+compiler_lex_clean:
+compiler_clean: compiler_moc_header_clean
+
+####### Compile
+
+ut_gpscontroller.o: ut_gpscontroller.cpp ut_gpscontroller.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o ut_gpscontroller.o ut_gpscontroller.cpp
+
+gpscontroller.o: ../../src/gpscontroller.cpp ../../src/gpscontroller.h \
+ ../../src/location.h \
+ ../../src/location_p.h \
+ ../../src/gpscontroller_p.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o gpscontroller.o ../../src/gpscontroller.cpp
+
+gpscontroller_p.o: ../../src/gpscontroller_p.cpp ../../src/gpscontroller_p.h \
+ ../../src/location.h \
+ ../../src/location_p.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o gpscontroller_p.o ../../src/gpscontroller_p.cpp
+
+location.o: ../../src/location.cpp ../../src/location.h \
+ ../../src/location_p.h \
+ ../../src/ytv.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o location.o ../../src/location.cpp
+
+location_p.o: ../../src/location_p.cpp ../../src/location_p.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o location_p.o ../../src/location_p.cpp
+
+moc_ut_gpscontroller.o: moc_ut_gpscontroller.cpp
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_ut_gpscontroller.o moc_ut_gpscontroller.cpp
+
+moc_gpscontroller.o: moc_gpscontroller.cpp
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_gpscontroller.o moc_gpscontroller.cpp
+
+moc_gpscontroller_p.o: moc_gpscontroller_p.cpp
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_gpscontroller_p.o moc_gpscontroller_p.cpp
+
+moc_location.o: moc_location.cpp
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_location.o moc_location.cpp
+
+moc_location_p.o: moc_location_p.cpp
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_location_p.o moc_location_p.cpp
+
+####### Install
+
+install: FORCE
+
+uninstall: FORCE
+
+FORCE:
+
--- /dev/null
+#include <QObject>
+#include <QtDebug>
+#include "ut_gpscontroller.h"
+
+#include "gpscontroller.h"
+#include "gpscontroller_p.h"
+
+class MyGpsControllerPrivate: public GpsControllerPrivate
+{
+public:
+ MyGpsControllerPrivate();
+ ~MyGpsControllerPrivate();
+
+ void init();
+ void startGps();
+ void stopGps();
+
+ void setGps( QGeoPositionInfoSource *gps );
+ void setCurrentLocation( Location *location );
+ void setUseFakeLocation( bool useFake );
+ void updateLocation();
+
+ QGeoPositionInfoSource *gps();
+ Location *currentLocation();
+ bool useFakeLocation();
+
+ bool m_gpsOn;
+ Location *m_currentLocation;
+ bool m_useFakeLocation;
+};
+
+MyGpsControllerPrivate::MyGpsControllerPrivate() :
+ m_gpsOn(false),
+ m_currentLocation(0),
+ m_useFakeLocation(false)
+{
+}
+
+MyGpsControllerPrivate::~MyGpsControllerPrivate()
+{
+ delete m_currentLocation;
+ m_currentLocation=0;
+}
+
+void MyGpsControllerPrivate::init()
+{
+}
+
+void MyGpsControllerPrivate::startGps()
+{
+ m_gpsOn=true;
+}
+
+void MyGpsControllerPrivate::stopGps()
+{
+ m_gpsOn=false;
+}
+
+QGeoPositionInfoSource *MyGpsControllerPrivate::gps()
+{
+ return 0;
+}
+
+void MyGpsControllerPrivate::setGps( QGeoPositionInfoSource *gps )
+{
+ Q_UNUSED( gps );
+}
+
+Location *MyGpsControllerPrivate::currentLocation()
+{
+ return m_currentLocation;
+}
+
+void MyGpsControllerPrivate::setCurrentLocation( Location *location )
+{
+ m_currentLocation = location;
+}
+
+bool MyGpsControllerPrivate::useFakeLocation()
+{
+ return m_useFakeLocation;
+}
+
+void MyGpsControllerPrivate::setUseFakeLocation( bool useFake )
+{
+ m_useFakeLocation = useFake;
+}
+
+void MyGpsControllerPrivate::updateLocation()
+{
+ if ( !m_useFakeLocation ) {
+ delete m_currentLocation;
+ m_currentLocation = new Location();
+ }
+}
+
+void Ut_GpsController::init()
+{
+ qRegisterMetaType<Location *>( "Location*" );
+
+ m_subject_p = new MyGpsControllerPrivate();
+ m_subject = new GpsController( m_subject_p ); // private ownership transferred
+}
+
+void Ut_GpsController::cleanup()
+{
+ delete m_subject;
+ m_subject = 0;
+}
+
+void Ut_GpsController::initTestCase()
+{
+}
+
+void Ut_GpsController::cleanupTestCase()
+{
+}
+
+void Ut_GpsController::testGetGpsWithNoGpsUpdates()
+{
+ QSignalSpy spy(m_subject, SIGNAL(locationChanged(Location*)));
+
+ // this should start the gps,
+ // but since there's been no update from the GPS, there should be
+ // no signal
+ m_subject->getGps();
+
+ QCOMPARE(m_subject_p->m_gpsOn, true);
+ QCOMPARE(spy.count(), 0);
+}
+
+void Ut_GpsController::testGetGpsWithGpsUpdates()
+{
+ QSignalSpy spy(m_subject, SIGNAL(locationChanged(Location*)));
+
+ m_subject_p->updateLocation(); // pretend GPS has given an update
+
+ // make test call
+ m_subject->getGps();
+
+ // check effect
+ QCOMPARE(m_subject_p->m_gpsOn, true);
+ QCOMPARE(spy.count(), 1);
+ QList<QVariant> arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).value<Location*>(), m_subject_p->m_currentLocation);
+ QVERIFY(m_subject_p->m_currentLocation != 0);
+}
+
+void Ut_GpsController::testFakeGps()
+{
+ QSignalSpy spy(m_subject, SIGNAL(locationChanged(Location*)));
+
+ m_subject_p->updateLocation(); // pretend GPS has given an update
+ Location *gpsLocation = m_subject_p->m_currentLocation; // position from GPS
+ Location *fakeLocation = new Location();
+
+ // make test call
+ m_subject->useFakeGps( fakeLocation ); // ownership -> m_subject
+ m_subject->getGps();
+
+ // check effect
+ QList<QVariant> arguments;
+
+ // gps should be off
+ QCOMPARE(m_subject_p->m_gpsOn, false);
+
+ // should get two signals, one from useFakeGps() and one from getGps()
+ QVERIFY2(spy.count()==2, "Should receive two signals" );
+
+ // both args should be the fake gps position supplied to useFakeGps()
+ arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).value<Location*>(), m_subject_p->m_currentLocation);
+ arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).value<Location*>(), m_subject_p->m_currentLocation);
+ QCOMPARE(m_subject_p->m_currentLocation, fakeLocation);
+
+ // should not be the gpsLocation or zero
+ QVERIFY(m_subject_p->m_currentLocation != gpsLocation);
+ QVERIFY(m_subject_p->m_currentLocation != 0);
+
+ // switch back to GPS
+ m_subject->useLiveGps();
+ m_subject->getGps();
+
+ // gps should be on
+ QCOMPARE(m_subject_p->m_gpsOn, true);
+
+ // should be zero
+ QVERIFY(m_subject_p->m_currentLocation == 0);
+
+ // should not get any signals because useFakeGps sets the location to 0
+ QVERIFY2(spy.count()==0, "should not receive any signals" );
+
+ // fake a GPS update
+ m_subject_p->updateLocation(); // pretend GPS has given an update
+
+ // get GPS location
+ m_subject->getGps();
+
+ // check effect
+ QCOMPARE(spy.count(), 1);
+ arguments = spy.takeFirst();
+ QCOMPARE(arguments.at(0).value<Location*>(), m_subject_p->m_currentLocation);
+ QVERIFY(m_subject_p->m_currentLocation != 0);
+}
+
+QTEST_APPLESS_MAIN(Ut_GpsController)
--- /dev/null
+#ifndef UT_GPSCONTROLLER_H
+#define UT_GPSCONTROLLER_H
+
+#include <QtTest/QtTest>
+#include <QObject>
+
+class GpsController;
+class MyGpsControllerPrivate;
+class Location;
+
+Q_DECLARE_METATYPE(GpsController*);
+Q_DECLARE_METATYPE(MyGpsControllerPrivate*);
+Q_DECLARE_METATYPE(Location*);
+
+class Ut_GpsController : public QObject
+{
+Q_OBJECT
+
+public:
+
+private slots:
+ void init();
+ void cleanup();
+ void initTestCase();
+ void cleanupTestCase();
+ void testGetGpsWithNoGpsUpdates();
+ void testGetGpsWithGpsUpdates();
+ void testFakeGps();
+
+private:
+ GpsController *m_subject;
+ MyGpsControllerPrivate *m_subject_p;
+};
+#endif // UT_GPSCONTROLLER_H
--- /dev/null
+include( ../tests.pri )
+CONFIG += \
+ qt \
+ debug \
+ mobility \
+
+MOBILITY = \
+ location \
+ bearer \
+
+QT += \
+ testlib \
+ network \
+
+INCLUDEPATH += \
+ $$ZOUBASRC \
+
+DEPENDPATH += $INCLUDEPATH
+
+TEMPLATE = app
+
+LIBS += \
+ /usr/lib/libQtLocation.so \
+
+SOURCES = \
+ ut_gpscontroller.cpp \
+ $$ZOUBASRC/gpscontroller.cpp \
+ $$ZOUBASRC/gpscontroller_p.cpp \
+ $$ZOUBASRC/location.cpp \
+ $$ZOUBASRC/location_p.cpp \
+
+HEADERS += \
+ ut_gpscontroller.h \
+ $$ZOUBASRC/gpscontroller.h \
+ $$ZOUBASRC/gpscontroller_p.h \
+ $$ZOUBASRC/location.h \
+ $$ZOUBASRC/location_p.h \
+
location_p.cpp \
locations.cpp \
gpscontroller.cpp \
+ gpscontroller_p.cpp \
ui.cpp \
messagetable.cpp \
messagehandler.cpp \
locations.h \
ytv.h \
gpscontroller.h \
+ gpscontroller_p.h \
ui.h \
messagetable.h \
messagehandler.h \
-FORMS +=
+FORMS +=
LEXSOURCES += #LEXS#
YACCSOURCES += #YACCS#
TEMPLATE = app
DEPENDPATH +=
VPATH += src uis
-CONFIG -=
+CONFIG -=
CONFIG += debug qt mobility
MOBILITY += location bearer
QT=core gui network