Updated.
[situare] / src / gps / gpsposition.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Jussi Laitinen - jussi.laitinen@ixonos.com
6
7    Situare is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License
9    version 2 as published by the Free Software Foundation.
10
11    Situare is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with Situare; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19    USA.
20 */
21
22 #include <QGeoPositionInfoSource>
23 #include <QNmeaPositionInfoSource>
24 #include <QFile>
25 #include <QDir>
26 #include <QApplication>
27 #include <QDebug>
28
29 #include "gpsposition.h"
30
31 GPSPosition::GPSPosition(QObject *parent)
32     : QObject(parent)
33 {
34     m_gpsSource = 0; //QGeoPositionInfoSource::createDefaultSource(this);
35
36 //    if (!m_gpsSource) {
37         QNmeaPositionInfoSource *nmeaSource = new QNmeaPositionInfoSource(QNmeaPositionInfoSource::SimulationMode, this);
38         QFile *logFile = new QFile(":/res/dummy/nmealog.txt", this);
39         nmeaSource->setDevice(logFile);
40         m_gpsSource = nmeaSource;
41 //    }
42
43     m_gpsSource->setUpdateInterval(5000);
44
45     connect(m_gpsSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
46             this, SLOT(positionUpdated(QGeoPositionInfo)));
47     connect(m_gpsSource, SIGNAL(updateTimeout()), this, SLOT(updateTimeout()));
48 }
49
50 GPSPosition::~GPSPosition()
51 {
52     stop();
53 }
54
55 void GPSPosition::start()
56 {
57     if (m_gpsSource)
58         m_gpsSource->startUpdates();
59 }
60
61 void GPSPosition::stop()
62 {
63     if (m_gpsSource)
64         m_gpsSource->stopUpdates();
65 }
66
67 void GPSPosition::requestUpdate()
68 {
69
70 }
71
72 void GPSPosition::positionUpdated(QGeoPositionInfo positionInfo)
73 {
74     qDebug() << __PRETTY_FUNCTION__ << " " << positionInfo;
75
76     emit position(QPointF(positionInfo.coordinate().longitude(),
77                           positionInfo.coordinate().latitude()));
78 }
79
80 void GPSPosition::updateTimeout()
81 {
82     qDebug() << __PRETTY_FUNCTION__;
83 }