mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
Location service: consistent way to output information
qDebug is nice when testing on the desktop, but it has to go to the message area on an Android device to make things easy. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
9195f247c4
commit
e7b2f04bec
4 changed files with 28 additions and 17 deletions
|
@ -1,4 +1,5 @@
|
|||
#include "qt-mobile/gpslocation.h"
|
||||
#include "qt-mobile/qmlmanager.h"
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
|
@ -6,27 +7,34 @@ GpsLocation::GpsLocation(QObject *parent)
|
|||
{
|
||||
QGeoPositionInfoSource *gpsSource = QGeoPositionInfoSource::createDefaultSource(parent);
|
||||
if (gpsSource != 0) {
|
||||
qDebug() << "have position source" << gpsSource->sourceName();
|
||||
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()));
|
||||
lastPos = gpsSource->lastKnownPosition();
|
||||
gpsSource->requestUpdate(1000);
|
||||
gpsSource->startUpdates();
|
||||
QGeoCoordinate lastCoord = lastPos.coordinate();
|
||||
if (lastCoord.isValid()) {
|
||||
qDebug() << lastCoord.toString();
|
||||
status(msg + lastCoord.toString());
|
||||
} else {
|
||||
qDebug() << "invalid last position";
|
||||
status(msg + "invalid last position");
|
||||
}
|
||||
} else {
|
||||
qDebug() << "don't have GPS source";
|
||||
status("don't have GPS source");
|
||||
}
|
||||
}
|
||||
void GpsLocation::newPosition(QGeoPositionInfo pos)
|
||||
{
|
||||
qDebug() << "received new position" << pos.coordinate().toString();
|
||||
QString msg("received new position %1");
|
||||
status(qPrintable(msg.arg(pos.coordinate().toString())));
|
||||
}
|
||||
|
||||
void GpsLocation::updateTimeout()
|
||||
{
|
||||
qDebug() << "request to get new position timed out";
|
||||
status("request to get new position timed out");
|
||||
}
|
||||
|
||||
void GpsLocation::status(QString msg)
|
||||
{
|
||||
qDebug() << msg;
|
||||
qmlUiShowMessage(qPrintable(msg));
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ public:
|
|||
|
||||
private:
|
||||
QGeoPositionInfo lastPos;
|
||||
void status(QString msg);
|
||||
|
||||
signals:
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "qthelper.h"
|
||||
#include "qt-gui.h"
|
||||
|
||||
static void showMessage(const char *errorString)
|
||||
void qmlUiShowMessage(const char *errorString)
|
||||
{
|
||||
if (qqWindowObject && !qqWindowObject->setProperty("messageText", QVariant(errorString)))
|
||||
qDebug() << "couldn't set property messageText to" << errorString;
|
||||
|
@ -55,11 +55,11 @@ void QMLManager::savePreferences()
|
|||
|
||||
void QMLManager::loadDives()
|
||||
{
|
||||
showMessage("Loading dives...");
|
||||
qmlUiShowMessage("Loading dives...");
|
||||
appendTextToLog("Loading dives...");
|
||||
QString url;
|
||||
if (getCloudURL(url)) {
|
||||
showMessage(get_error_string());
|
||||
qmlUiShowMessage(get_error_string());
|
||||
appendTextToLog(get_error_string());
|
||||
return;
|
||||
}
|
||||
|
@ -69,12 +69,12 @@ void QMLManager::loadDives()
|
|||
int error = parse_file(fileNamePrt.data());
|
||||
if (!error) {
|
||||
report_error("filename is now %s", fileNamePrt.data());
|
||||
showMessage(get_error_string());
|
||||
qmlUiShowMessage(get_error_string());
|
||||
appendTextToLog(get_error_string());
|
||||
set_filename(fileNamePrt.data(), true);
|
||||
appendTextToLog(fileNamePrt.data());
|
||||
} else {
|
||||
showMessage(get_error_string());
|
||||
qmlUiShowMessage(get_error_string());
|
||||
appendTextToLog(get_error_string());
|
||||
}
|
||||
process_dives(false, false);
|
||||
|
@ -116,21 +116,21 @@ void QMLManager::commitChanges(QString diveId, QString suit, QString buddy, QStr
|
|||
|
||||
void QMLManager::saveChanges()
|
||||
{
|
||||
showMessage("Saving dives.");
|
||||
qmlUiShowMessage("Saving dives.");
|
||||
QString fileName;
|
||||
if (getCloudURL(fileName)) {
|
||||
showMessage(get_error_string());
|
||||
qmlUiShowMessage(get_error_string());
|
||||
appendTextToLog(get_error_string());
|
||||
return;
|
||||
}
|
||||
|
||||
if (save_dives(fileName.toUtf8().data())) {
|
||||
showMessage(get_error_string());
|
||||
qmlUiShowMessage(get_error_string());
|
||||
appendTextToLog(get_error_string());
|
||||
return;
|
||||
}
|
||||
|
||||
showMessage("Dives saved.");
|
||||
qmlUiShowMessage("Dives saved.");
|
||||
appendTextToLog("Dive saved.");
|
||||
set_filename(fileName.toUtf8().data(), true);
|
||||
mark_divelist_changed(false);
|
||||
|
@ -138,7 +138,7 @@ void QMLManager::saveChanges()
|
|||
|
||||
void QMLManager::addDive()
|
||||
{
|
||||
showMessage("Adding new dive.");
|
||||
qmlUiShowMessage("Adding new dive.");
|
||||
appendTextToLog("Adding new dive.");
|
||||
DiveListModel::instance()->startAddDive();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
void qmlUiShowMessage(const char *errorString);
|
||||
|
||||
class QMLManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
Loading…
Add table
Reference in a new issue