Enhance location attachment information (accuracy, address)

This commit is contained in:
Sebastian Wolf 2021-05-27 23:48:50 +02:00
parent 78e578c5e2
commit d2df4ddf16
No known key found for this signature in database
GPG key ID: CEA9522B5F38A90A
15 changed files with 160 additions and 2 deletions

View file

@ -1654,15 +1654,28 @@ Page {
property bool isVoiceNote: false;
property bool isLocation: false;
property var locationData: null;
property var geocodedAddress: qsTr("Unknown address")
property var fileProperties: null;
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 {
target: fernschreiberUtils
onNewPositionInformation: {
attachmentPreviewRow.locationData = positionInformation;
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 || "" : "" );
anchors.verticalCenter: parent.verticalCenter
maximumLineCount: 1
width: parent.width - removeAttachmentsIconButton.width - Theme.paddingMedium
maximumLineCount: 2
wrapMode: Text.Wrap
truncationMode: TruncationMode.Fade
color: Theme.secondaryColor
visible: attachmentPreviewRow.isDocument || attachmentPreviewRow.isVoiceNote || attachmentPreviewRow.isLocation

View file

@ -26,10 +26,13 @@
#include <QDirIterator>
#include <QFile>
#include <QUrl>
#include <QUrlQuery>
#include <QDateTime>
#include <QGeoCoordinate>
#include <QGeoLocation>
#include <QSysInfo>
#include <QNetworkRequest>
#include <QNetworkReply>
#define DEBUG_MODULE FernschreiberUtils
#include "debuglog.h"
@ -65,6 +68,8 @@ FernschreiberUtils::FernschreiberUtils(QObject *parent) : QObject(parent)
} else {
LOG("Unable to initialize geolocation!");
}
this->manager = new QNetworkAccessManager(this);
}
FernschreiberUtils::~FernschreiberUtils()
@ -252,6 +257,25 @@ QString FernschreiberUtils::getSailfishOSVersion()
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)
{
LOG("Audio recorder status changed:" << status);
@ -296,10 +320,28 @@ void FernschreiberUtils::handleGeoPositionUpdated(const QGeoPositionInfo &info)
positionInformation.insert("latitude", geoCoordinate.latitude());
positionInformation.insert("longitude", geoCoordinate.longitude());
this->initiateReverseGeocode(geoCoordinate.latitude(), geoCoordinate.longitude());
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()
{
if (this->geoPositionInfoSource) {

View file

@ -24,6 +24,7 @@
#include <QAudioRecorder>
#include <QGeoPositionInfo>
#include <QGeoPositionInfoSource>
#include <QNetworkAccessManager>
#include "tdlibwrapper.h"
class FernschreiberUtils : public QObject
@ -53,21 +54,25 @@ public:
Q_INVOKABLE void stopGeoLocationUpdates();
Q_INVOKABLE bool supportsGeoLocation();
Q_INVOKABLE QString getSailfishOSVersion();
Q_INVOKABLE void initiateReverseGeocode(double latitude, double longitude);
signals:
void voiceNoteDurationChanged(qlonglong duration);
void voiceNoteRecordingStateChanged(VoiceNoteRecordingState state);
void newPositionInformation(const QVariantMap &positionInformation);
void newGeocodedAddress(const QString &geocodedAddress);
private slots:
void handleAudioRecorderStatusChanged(QMediaRecorder::Status status);
void handleGeoPositionUpdated(const QGeoPositionInfo &info);
void handleReverseGeocodeFinished();
private:
QAudioRecorder audioRecorder;
VoiceNoteRecordingState voiceNoteRecordingState;
QGeoPositionInfoSource *geoPositionInfoSource;
QNetworkAccessManager *manager;
void cleanUp();
QString getTemporaryDirectoryPath();

View file

@ -506,6 +506,14 @@
<source>Forward Message</source>
<translation>Nachricht weiterleiten</translation>
</message>
<message>
<source>Unknown address</source>
<translation>Unbekannte Adresse</translation>
</message>
<message>
<source>Accuracy: %1m</source>
<translation>Genauigkeit: %1m</translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -506,6 +506,14 @@
<source>Forward Message</source>
<translation>Forward Message</translation>
</message>
<message>
<source>Unknown address</source>
<translation>Unknown address</translation>
</message>
<message>
<source>Accuracy: %1m</source>
<translation>Accuracy: %1m</translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -506,6 +506,14 @@
<source>Forward Message</source>
<translation>Reenviar mensaje</translation>
</message>
<message>
<source>Unknown address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Accuracy: %1m</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -506,6 +506,14 @@
<source>Forward Message</source>
<translation>Välitä viesti</translation>
</message>
<message>
<source>Unknown address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Accuracy: %1m</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -496,6 +496,14 @@
<source>Forward Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unknown address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Accuracy: %1m</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -506,6 +506,14 @@
<source>Forward Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unknown address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Accuracy: %1m</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -516,6 +516,14 @@
<source>Forward Message</source>
<translation>Przekaż widomość</translation>
</message>
<message>
<source>Unknown address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Accuracy: %1m</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -516,6 +516,14 @@
<source>Forward Message</source>
<translation>Переслать сообщение</translation>
</message>
<message>
<source>Unknown address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Accuracy: %1m</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -516,6 +516,14 @@
<source>Forward Message</source>
<translation>Postúpiť správu</translation>
</message>
<message>
<source>Unknown address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Accuracy: %1m</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -506,6 +506,14 @@
<source>Forward Message</source>
<translation>Vidarebefordra meddelande</translation>
</message>
<message>
<source>Unknown address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Accuracy: %1m</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -496,6 +496,14 @@
<source>Forward Message</source>
<translation></translation>
</message>
<message>
<source>Unknown address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Accuracy: %1m</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>

View file

@ -506,6 +506,14 @@
<source>Forward Message</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unknown address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Accuracy: %1m</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatSelectionPage</name>