2015-11-11 10:50:55 -08:00
|
|
|
#ifndef GPSLOCATION_H
|
|
|
|
#define GPSLOCATION_H
|
|
|
|
|
2015-11-11 15:19:09 -08:00
|
|
|
#include "units.h"
|
2015-11-11 10:52:52 -08:00
|
|
|
#include <QObject>
|
2015-11-11 10:50:55 -08:00
|
|
|
#include <QGeoCoordinate>
|
2015-11-11 10:52:52 -08:00
|
|
|
#include <QGeoPositionInfoSource>
|
|
|
|
#include <QGeoPositionInfo>
|
2015-11-11 15:19:09 -08:00
|
|
|
#include <QSettings>
|
2015-11-13 17:21:43 -08:00
|
|
|
#include <QNetworkReply>
|
2016-01-09 14:07:58 -08:00
|
|
|
#include <QMap>
|
2015-11-11 10:50:55 -08:00
|
|
|
|
2016-01-07 00:08:00 -08:00
|
|
|
struct gpsTracker {
|
|
|
|
degrees_t latitude;
|
|
|
|
degrees_t longitude;
|
2016-01-09 14:07:58 -08:00
|
|
|
qint64 when;
|
2016-01-07 00:08:00 -08:00
|
|
|
QString name;
|
2016-01-09 14:07:58 -08:00
|
|
|
int idx;
|
2016-01-07 00:08:00 -08:00
|
|
|
};
|
|
|
|
|
2016-01-11 06:14:45 -08:00
|
|
|
class GpsLocation : QObject {
|
2015-11-11 10:52:52 -08:00
|
|
|
Q_OBJECT
|
2015-11-11 10:50:55 -08:00
|
|
|
public:
|
2015-11-18 18:10:58 -08:00
|
|
|
GpsLocation(void (*showMsgCB)(const char *msg), QObject *parent);
|
2015-12-02 14:30:47 -08:00
|
|
|
~GpsLocation();
|
|
|
|
static GpsLocation *instance();
|
2016-01-10 19:34:21 -08:00
|
|
|
bool applyLocations();
|
2015-11-13 09:17:13 -08:00
|
|
|
int getGpsNum() const;
|
2015-11-18 13:14:19 -08:00
|
|
|
QString getUserid(QString user, QString passwd);
|
2015-11-18 18:56:50 -08:00
|
|
|
bool hasLocationsSource();
|
2016-01-01 17:21:30 -08:00
|
|
|
QString currentPosition();
|
2015-11-11 10:52:52 -08:00
|
|
|
|
2016-01-09 14:07:58 -08:00
|
|
|
QMap<qint64, gpsTracker> currentGPSInfo() const;
|
2016-01-08 13:11:49 -02:00
|
|
|
|
2015-11-11 10:52:52 -08:00
|
|
|
private:
|
|
|
|
QGeoPositionInfo lastPos;
|
2015-11-30 10:58:18 -08:00
|
|
|
QGeoPositionInfoSource *getGpsSource();
|
2016-01-01 17:19:28 -08:00
|
|
|
QGeoPositionInfoSource *m_GpsSource;
|
2015-11-11 11:16:59 -08:00
|
|
|
void status(QString msg);
|
2015-11-13 11:55:39 -08:00
|
|
|
QSettings *geoSettings;
|
2015-11-13 17:21:43 -08:00
|
|
|
QNetworkReply *reply;
|
2015-11-18 14:44:07 -08:00
|
|
|
QString userAgent;
|
2015-11-18 18:10:58 -08:00
|
|
|
void (*showMessageCB)(const char *msg);
|
2015-12-02 14:30:47 -08:00
|
|
|
static GpsLocation *m_Instance;
|
2016-01-01 17:20:30 -08:00
|
|
|
bool waitingForPosition;
|
2016-01-09 14:07:58 -08:00
|
|
|
QMap<qint64, gpsTracker> m_trackers;
|
2016-01-10 17:39:13 -08:00
|
|
|
QList<gpsTracker> m_deletedTrackers;
|
2016-01-10 17:22:20 -08:00
|
|
|
void loadFromStorage();
|
2016-01-10 17:39:13 -08:00
|
|
|
void addFixToStorage(gpsTracker >);
|
2016-01-10 17:22:20 -08:00
|
|
|
void replaceFixToStorage(gpsTracker >);
|
2016-01-10 17:39:13 -08:00
|
|
|
void deleteFixFromStorage(gpsTracker >);
|
|
|
|
void deleteFixesFromServer();
|
2015-11-11 10:50:55 -08:00
|
|
|
|
|
|
|
public slots:
|
2015-11-11 12:34:56 -08:00
|
|
|
void serviceEnable(bool toggle);
|
2015-11-11 10:52:52 -08:00
|
|
|
void newPosition(QGeoPositionInfo pos);
|
|
|
|
void updateTimeout();
|
2015-11-13 17:21:43 -08:00
|
|
|
void uploadToServer();
|
2016-01-07 21:32:24 -08:00
|
|
|
void downloadFromServer();
|
2015-11-13 17:21:43 -08:00
|
|
|
void postError(QNetworkReply::NetworkError error);
|
2015-11-18 13:14:19 -08:00
|
|
|
void getUseridError(QNetworkReply::NetworkError error);
|
2015-11-13 17:20:45 -08:00
|
|
|
void clearGpsData();
|
2016-01-09 14:07:58 -08:00
|
|
|
void deleteGpsFix(qint64 when);
|
2015-11-11 10:50:55 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GPSLOCATION_H
|