Enhance location attachment information (accuracy, address)
This commit is contained in:
parent
78e578c5e2
commit
d2df4ddf16
15 changed files with 160 additions and 2 deletions
|
@ -1654,15 +1654,28 @@ Page {
|
||||||
property bool isVoiceNote: false;
|
property bool isVoiceNote: false;
|
||||||
property bool isLocation: false;
|
property bool isLocation: false;
|
||||||
property var locationData: null;
|
property var locationData: null;
|
||||||
|
property var geocodedAddress: qsTr("Unknown address")
|
||||||
property var fileProperties: null;
|
property var fileProperties: null;
|
||||||
property string attachmentDescription: "";
|
property string attachmentDescription: "";
|
||||||
|
|
||||||
|
function getLocationDescription() {
|
||||||
|
return qsTr("Location (%1/%2)").arg(attachmentPreviewRow.locationData.latitude).arg(attachmentPreviewRow.locationData.longitude) + " | "
|
||||||
|
+ qsTr("Accuracy: %1m").arg(attachmentPreviewRow.locationData.horizontalAccuracy) + "\n"
|
||||||
|
+ attachmentPreviewRow.geocodedAddress;
|
||||||
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: fernschreiberUtils
|
target: fernschreiberUtils
|
||||||
onNewPositionInformation: {
|
onNewPositionInformation: {
|
||||||
attachmentPreviewRow.locationData = positionInformation;
|
attachmentPreviewRow.locationData = positionInformation;
|
||||||
if (attachmentPreviewRow.isLocation) {
|
if (attachmentPreviewRow.isLocation) {
|
||||||
attachmentPreviewRow.attachmentDescription = qsTr("Location (%1/%2)").arg(attachmentPreviewRow.locationData.latitude).arg(attachmentPreviewRow.locationData.longitude);
|
attachmentPreviewRow.attachmentDescription = attachmentPreviewRow.getLocationDescription();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onNewGeocodedAddress: {
|
||||||
|
attachmentPreviewRow.geocodedAddress = geocodedAddress;
|
||||||
|
if (attachmentPreviewRow.isLocation) {
|
||||||
|
attachmentPreviewRow.attachmentDescription = attachmentPreviewRow.getLocationDescription();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1695,7 +1708,9 @@ Page {
|
||||||
text: ( attachmentPreviewRow.isVoiceNote || attachmentPreviewRow.isLocation ) ? attachmentPreviewRow.attachmentDescription : ( !!attachmentPreviewRow.fileProperties ? attachmentPreviewRow.fileProperties.fileName || "" : "" );
|
text: ( attachmentPreviewRow.isVoiceNote || attachmentPreviewRow.isLocation ) ? attachmentPreviewRow.attachmentDescription : ( !!attachmentPreviewRow.fileProperties ? attachmentPreviewRow.fileProperties.fileName || "" : "" );
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
|
||||||
maximumLineCount: 1
|
width: parent.width - removeAttachmentsIconButton.width - Theme.paddingMedium
|
||||||
|
maximumLineCount: 2
|
||||||
|
wrapMode: Text.Wrap
|
||||||
truncationMode: TruncationMode.Fade
|
truncationMode: TruncationMode.Fade
|
||||||
color: Theme.secondaryColor
|
color: Theme.secondaryColor
|
||||||
visible: attachmentPreviewRow.isDocument || attachmentPreviewRow.isVoiceNote || attachmentPreviewRow.isLocation
|
visible: attachmentPreviewRow.isDocument || attachmentPreviewRow.isVoiceNote || attachmentPreviewRow.isLocation
|
||||||
|
|
|
@ -26,10 +26,13 @@
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QUrlQuery>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QGeoCoordinate>
|
#include <QGeoCoordinate>
|
||||||
#include <QGeoLocation>
|
#include <QGeoLocation>
|
||||||
#include <QSysInfo>
|
#include <QSysInfo>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
|
||||||
#define DEBUG_MODULE FernschreiberUtils
|
#define DEBUG_MODULE FernschreiberUtils
|
||||||
#include "debuglog.h"
|
#include "debuglog.h"
|
||||||
|
@ -65,6 +68,8 @@ FernschreiberUtils::FernschreiberUtils(QObject *parent) : QObject(parent)
|
||||||
} else {
|
} else {
|
||||||
LOG("Unable to initialize geolocation!");
|
LOG("Unable to initialize geolocation!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->manager = new QNetworkAccessManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
FernschreiberUtils::~FernschreiberUtils()
|
FernschreiberUtils::~FernschreiberUtils()
|
||||||
|
@ -252,6 +257,25 @@ QString FernschreiberUtils::getSailfishOSVersion()
|
||||||
return QSysInfo::productVersion();
|
return QSysInfo::productVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FernschreiberUtils::initiateReverseGeocode(double latitude, double longitude)
|
||||||
|
{
|
||||||
|
LOG("Initiating reverse geocode:" << latitude << longitude);
|
||||||
|
QUrl url = QUrl("https://nominatim.openstreetmap.org/reverse");
|
||||||
|
QUrlQuery urlQuery;
|
||||||
|
urlQuery.addQueryItem("lat", QString::number(latitude));
|
||||||
|
urlQuery.addQueryItem("lon", QString::number(longitude));
|
||||||
|
urlQuery.addQueryItem("format", "json");
|
||||||
|
url.setQuery(urlQuery);
|
||||||
|
QNetworkRequest request(url);
|
||||||
|
request.setHeader(QNetworkRequest::UserAgentHeader, "Fernschreiber (Sailfish OS)");
|
||||||
|
request.setRawHeader(QByteArray("Accept"), QByteArray("application/json"));
|
||||||
|
request.setRawHeader(QByteArray("Accept-Charset"), QByteArray("utf-8"));
|
||||||
|
request.setRawHeader(QByteArray("Connection"), QByteArray("close"));
|
||||||
|
request.setRawHeader(QByteArray("Cache-Control"), QByteArray("max-age=0"));
|
||||||
|
QNetworkReply *reply = manager->get(request);
|
||||||
|
connect(reply, SIGNAL(finished()), this, SLOT(handleReverseGeocodeFinished()));
|
||||||
|
}
|
||||||
|
|
||||||
void FernschreiberUtils::handleAudioRecorderStatusChanged(QMediaRecorder::Status status)
|
void FernschreiberUtils::handleAudioRecorderStatusChanged(QMediaRecorder::Status status)
|
||||||
{
|
{
|
||||||
LOG("Audio recorder status changed:" << status);
|
LOG("Audio recorder status changed:" << status);
|
||||||
|
@ -296,10 +320,28 @@ void FernschreiberUtils::handleGeoPositionUpdated(const QGeoPositionInfo &info)
|
||||||
positionInformation.insert("latitude", geoCoordinate.latitude());
|
positionInformation.insert("latitude", geoCoordinate.latitude());
|
||||||
positionInformation.insert("longitude", geoCoordinate.longitude());
|
positionInformation.insert("longitude", geoCoordinate.longitude());
|
||||||
|
|
||||||
|
this->initiateReverseGeocode(geoCoordinate.latitude(), geoCoordinate.longitude());
|
||||||
|
|
||||||
emit newPositionInformation(positionInformation);
|
emit newPositionInformation(positionInformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FernschreiberUtils::handleReverseGeocodeFinished()
|
||||||
|
{
|
||||||
|
qDebug() << "FernschreiberUtils::handleReverseGeocodeFinished";
|
||||||
|
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
|
||||||
|
reply->deleteLater();
|
||||||
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonDocument jsonDocument = QJsonDocument::fromJson(reply->readAll());
|
||||||
|
qDebug().noquote() << jsonDocument.toJson(QJsonDocument::Indented);
|
||||||
|
if (jsonDocument.isObject()) {
|
||||||
|
QJsonObject responseObject = jsonDocument.object();
|
||||||
|
emit newGeocodedAddress(responseObject.value("display_name").toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FernschreiberUtils::cleanUp()
|
void FernschreiberUtils::cleanUp()
|
||||||
{
|
{
|
||||||
if (this->geoPositionInfoSource) {
|
if (this->geoPositionInfoSource) {
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <QAudioRecorder>
|
#include <QAudioRecorder>
|
||||||
#include <QGeoPositionInfo>
|
#include <QGeoPositionInfo>
|
||||||
#include <QGeoPositionInfoSource>
|
#include <QGeoPositionInfoSource>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
#include "tdlibwrapper.h"
|
#include "tdlibwrapper.h"
|
||||||
|
|
||||||
class FernschreiberUtils : public QObject
|
class FernschreiberUtils : public QObject
|
||||||
|
@ -53,21 +54,25 @@ public:
|
||||||
Q_INVOKABLE void stopGeoLocationUpdates();
|
Q_INVOKABLE void stopGeoLocationUpdates();
|
||||||
Q_INVOKABLE bool supportsGeoLocation();
|
Q_INVOKABLE bool supportsGeoLocation();
|
||||||
Q_INVOKABLE QString getSailfishOSVersion();
|
Q_INVOKABLE QString getSailfishOSVersion();
|
||||||
|
Q_INVOKABLE void initiateReverseGeocode(double latitude, double longitude);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void voiceNoteDurationChanged(qlonglong duration);
|
void voiceNoteDurationChanged(qlonglong duration);
|
||||||
void voiceNoteRecordingStateChanged(VoiceNoteRecordingState state);
|
void voiceNoteRecordingStateChanged(VoiceNoteRecordingState state);
|
||||||
void newPositionInformation(const QVariantMap &positionInformation);
|
void newPositionInformation(const QVariantMap &positionInformation);
|
||||||
|
void newGeocodedAddress(const QString &geocodedAddress);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleAudioRecorderStatusChanged(QMediaRecorder::Status status);
|
void handleAudioRecorderStatusChanged(QMediaRecorder::Status status);
|
||||||
void handleGeoPositionUpdated(const QGeoPositionInfo &info);
|
void handleGeoPositionUpdated(const QGeoPositionInfo &info);
|
||||||
|
void handleReverseGeocodeFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QAudioRecorder audioRecorder;
|
QAudioRecorder audioRecorder;
|
||||||
VoiceNoteRecordingState voiceNoteRecordingState;
|
VoiceNoteRecordingState voiceNoteRecordingState;
|
||||||
|
|
||||||
QGeoPositionInfoSource *geoPositionInfoSource;
|
QGeoPositionInfoSource *geoPositionInfoSource;
|
||||||
|
QNetworkAccessManager *manager;
|
||||||
|
|
||||||
void cleanUp();
|
void cleanUp();
|
||||||
QString getTemporaryDirectoryPath();
|
QString getTemporaryDirectoryPath();
|
||||||
|
|
|
@ -506,6 +506,14 @@
|
||||||
<source>Forward Message</source>
|
<source>Forward Message</source>
|
||||||
<translation>Nachricht weiterleiten</translation>
|
<translation>Nachricht weiterleiten</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown address</source>
|
||||||
|
<translation>Unbekannte Adresse</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Accuracy: %1m</source>
|
||||||
|
<translation>Genauigkeit: %1m</translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ChatSelectionPage</name>
|
<name>ChatSelectionPage</name>
|
||||||
|
|
|
@ -506,6 +506,14 @@
|
||||||
<source>Forward Message</source>
|
<source>Forward Message</source>
|
||||||
<translation>Forward Message</translation>
|
<translation>Forward Message</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown address</source>
|
||||||
|
<translation>Unknown address</translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Accuracy: %1m</source>
|
||||||
|
<translation>Accuracy: %1m</translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ChatSelectionPage</name>
|
<name>ChatSelectionPage</name>
|
||||||
|
|
|
@ -506,6 +506,14 @@
|
||||||
<source>Forward Message</source>
|
<source>Forward Message</source>
|
||||||
<translation>Reenviar mensaje</translation>
|
<translation>Reenviar mensaje</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown address</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Accuracy: %1m</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ChatSelectionPage</name>
|
<name>ChatSelectionPage</name>
|
||||||
|
|
|
@ -506,6 +506,14 @@
|
||||||
<source>Forward Message</source>
|
<source>Forward Message</source>
|
||||||
<translation>Välitä viesti</translation>
|
<translation>Välitä viesti</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown address</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Accuracy: %1m</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ChatSelectionPage</name>
|
<name>ChatSelectionPage</name>
|
||||||
|
|
|
@ -496,6 +496,14 @@
|
||||||
<source>Forward Message</source>
|
<source>Forward Message</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown address</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Accuracy: %1m</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ChatSelectionPage</name>
|
<name>ChatSelectionPage</name>
|
||||||
|
|
|
@ -506,6 +506,14 @@
|
||||||
<source>Forward Message</source>
|
<source>Forward Message</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown address</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Accuracy: %1m</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ChatSelectionPage</name>
|
<name>ChatSelectionPage</name>
|
||||||
|
|
|
@ -516,6 +516,14 @@
|
||||||
<source>Forward Message</source>
|
<source>Forward Message</source>
|
||||||
<translation>Przekaż widomość</translation>
|
<translation>Przekaż widomość</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown address</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Accuracy: %1m</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ChatSelectionPage</name>
|
<name>ChatSelectionPage</name>
|
||||||
|
|
|
@ -516,6 +516,14 @@
|
||||||
<source>Forward Message</source>
|
<source>Forward Message</source>
|
||||||
<translation>Переслать сообщение</translation>
|
<translation>Переслать сообщение</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown address</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Accuracy: %1m</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ChatSelectionPage</name>
|
<name>ChatSelectionPage</name>
|
||||||
|
|
|
@ -516,6 +516,14 @@
|
||||||
<source>Forward Message</source>
|
<source>Forward Message</source>
|
||||||
<translation>Postúpiť správu</translation>
|
<translation>Postúpiť správu</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown address</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Accuracy: %1m</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ChatSelectionPage</name>
|
<name>ChatSelectionPage</name>
|
||||||
|
|
|
@ -506,6 +506,14 @@
|
||||||
<source>Forward Message</source>
|
<source>Forward Message</source>
|
||||||
<translation>Vidarebefordra meddelande</translation>
|
<translation>Vidarebefordra meddelande</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown address</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Accuracy: %1m</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ChatSelectionPage</name>
|
<name>ChatSelectionPage</name>
|
||||||
|
|
|
@ -496,6 +496,14 @@
|
||||||
<source>Forward Message</source>
|
<source>Forward Message</source>
|
||||||
<translation>转发消息</translation>
|
<translation>转发消息</translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown address</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Accuracy: %1m</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ChatSelectionPage</name>
|
<name>ChatSelectionPage</name>
|
||||||
|
|
|
@ -506,6 +506,14 @@
|
||||||
<source>Forward Message</source>
|
<source>Forward Message</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Unknown address</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Accuracy: %1m</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ChatSelectionPage</name>
|
<name>ChatSelectionPage</name>
|
||||||
|
|
Loading…
Reference in a new issue