mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 19:13:24 +00:00
Subsurface-mobile: don't create the GPS source until it is needed
This should accelerate the startup of the UI a little more. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
f6ae8bf3ea
commit
2311bc2378
2 changed files with 24 additions and 10 deletions
|
@ -19,25 +19,39 @@ GpsLocation::GpsLocation(void (*showMsgCB)(const char *), QObject *parent)
|
|||
// create a QSettings object that's separate from the main application settings
|
||||
geoSettings = new QSettings(QSettings::NativeFormat, QSettings::UserScope,
|
||||
QString("org.subsurfacedivelog"), QString("subsurfacelocation"), this);
|
||||
gpsSource = QGeoPositionInfoSource::createDefaultSource(parent);
|
||||
if (gpsSource != 0) {
|
||||
QString msg = QString("have position source %1").arg(gpsSource->sourceName());
|
||||
connect(gpsSource, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(newPosition(QGeoPositionInfo)));
|
||||
connect(gpsSource, SIGNAL(updateTimeout()), this, SLOT(updateTimeout()));
|
||||
gpsSource->setUpdateInterval(5 * 60 * 1000); // 5 minutes so the device doesn't drain the battery
|
||||
} else {
|
||||
status("don't have GPS source");
|
||||
}
|
||||
userAgent = getUserAgent();
|
||||
}
|
||||
|
||||
QGeoPositionInfoSource *GpsLocation::getGpsSource()
|
||||
{
|
||||
static QGeoPositionInfoSource *gpsSource = NULL;
|
||||
static bool initGpsSource = false;
|
||||
|
||||
if (!initGpsSource) {
|
||||
gpsSource = QGeoPositionInfoSource::createDefaultSource(this);
|
||||
initGpsSource = true;
|
||||
if (gpsSource != 0) {
|
||||
status("created GPS source");
|
||||
QString msg = QString("have position source %1").arg(gpsSource->sourceName());
|
||||
connect(gpsSource, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(newPosition(QGeoPositionInfo)));
|
||||
connect(gpsSource, SIGNAL(updateTimeout()), this, SLOT(updateTimeout()));
|
||||
gpsSource->setUpdateInterval(5 * 60 * 1000); // 5 minutes so the device doesn't drain the battery
|
||||
} else {
|
||||
status("don't have GPS source");
|
||||
}
|
||||
}
|
||||
return gpsSource;
|
||||
}
|
||||
|
||||
bool GpsLocation::hasLocationsSource()
|
||||
{
|
||||
QGeoPositionInfoSource *gpsSource = getGpsSource();
|
||||
return gpsSource != 0 && (gpsSource->supportedPositioningMethods() & QGeoPositionInfoSource::SatellitePositioningMethods);
|
||||
}
|
||||
|
||||
void GpsLocation::serviceEnable(bool toggle)
|
||||
{
|
||||
QGeoPositionInfoSource *gpsSource = getGpsSource();
|
||||
if (!gpsSource) {
|
||||
if (toggle)
|
||||
status("Can't start location service, no location source available");
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
|
||||
private:
|
||||
QGeoPositionInfo lastPos;
|
||||
QGeoPositionInfoSource *gpsSource;
|
||||
QGeoPositionInfoSource *getGpsSource();
|
||||
void status(QString msg);
|
||||
QSettings *geoSettings;
|
||||
QNetworkReply *reply;
|
||||
|
|
Loading…
Add table
Reference in a new issue