diff --git a/harbour-fernschreiber.pro b/harbour-fernschreiber.pro index 5823b5a..a99ffc0 100644 --- a/harbour-fernschreiber.pro +++ b/harbour-fernschreiber.pro @@ -16,7 +16,7 @@ CONFIG += sailfishapp sailfishapp_i18n PKGCONFIG += nemonotifications-qt5 zlib -QT += core dbus sql multimedia +QT += core dbus sql multimedia positioning DEFINES += QT_STATICPLUGIN diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index 77de0cb..c320ab5 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -212,8 +212,11 @@ Page { attachmentPreviewRow.isVideo = false; attachmentPreviewRow.isDocument = false; attachmentPreviewRow.isVoiceNote = false; + attachmentPreviewRow.isLocation = false; attachmentPreviewRow.fileProperties = {}; + attachmentPreviewRow.locationData = {}; attachmentPreviewRow.attachmentDescription = ""; + fernschreiberUtils.stopGeoLocationUpdates(); } function controlSendButton() { @@ -221,7 +224,8 @@ Page { || attachmentPreviewRow.isPicture || attachmentPreviewRow.isDocument || attachmentPreviewRow.isVideo - || attachmentPreviewRow.isVoiceNote) { + || attachmentPreviewRow.isVoiceNote + || attachmentPreviewRow.isLocation) { newMessageSendButton.enabled = true; } else { newMessageSendButton.enabled = false; @@ -245,6 +249,9 @@ Page { if (attachmentPreviewRow.isVoiceNote) { tdLibWrapper.sendVoiceNoteMessage(chatInformation.id, fernschreiberUtils.voiceNotePath(), newMessageTextField.text, newMessageColumn.replyToMessageId); } + if (attachmentPreviewRow.isLocation) { + tdLibWrapper.sendLocationMessage(chatInformation.id, attachmentPreviewRow.locationData.latitude, attachmentPreviewRow.locationData.longitude, attachmentPreviewRow.locationData.horizontalAccuracy, newMessageColumn.replyToMessageId); + } clearAttachmentPreviewRow(); } else { tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId); @@ -257,6 +264,7 @@ Page { controlSendButton(); newMessageInReplyToRow.inReplyToMessage = null; newMessageColumn.editMessageId = "0"; + fernschreiberUtils.stopGeoLocationUpdates(); } function getWordBoundaries(text, cursorPosition) { @@ -386,6 +394,7 @@ Page { if (chatPage.canSendMessages) { tdLibWrapper.setChatDraftMessage(chatInformation.id, 0, newMessageColumn.replyToMessageId, newMessageTextField.text); } + fernschreiberUtils.stopGeoLocationUpdates(); tdLibWrapper.closeChat(chatInformation.id); } @@ -1201,7 +1210,6 @@ Page { id: attachmentOptionsFlickable property bool isNeeded: false - width: parent.width height: isNeeded ? attachmentOptionsRow.height : 0 Behavior on height { SmoothedAnimation { duration: 200 } } @@ -1305,6 +1313,22 @@ Page { attachmentOptionsFlickable.isNeeded = false; } } + IconButton { + visible: fernschreiberUtils.supportsGeoLocation() && newMessageTextField.text === "" + icon.source: "image://theme/icon-m-location" + icon.sourceSize { + width: Theme.iconSizeMedium + height: Theme.iconSizeMedium + } + onClicked: { + fernschreiberUtils.startGeoLocationUpdates(); + attachmentOptionsFlickable.isNeeded = false; + attachmentPreviewRow.isLocation = true; + attachmentPreviewRow.attachmentDescription = qsTr("Location: Obtaining position..."); + attachmentPreviewRow.visible = true; + controlSendButton(); + } + } } } @@ -1322,9 +1346,21 @@ Page { property bool isVideo: false; property bool isDocument: false; property bool isVoiceNote: false; + property bool isLocation: false; + property var locationData: ({}); property var fileProperties:({}); property string attachmentDescription: ""; + Connections { + target: fernschreiberUtils + onNewPositionInformation: { + attachmentPreviewRow.locationData = positionInformation; + if (attachmentPreviewRow.isLocation) { + attachmentPreviewRow.attachmentDescription = qsTr("Location (%1/%2)").arg(attachmentPreviewRow.locationData.latitude).arg(attachmentPreviewRow.locationData.longitude); + } + } + } + IconButton { id: removeAttachmentsIconButton icon.source: "image://theme/icon-m-clear" @@ -1350,13 +1386,13 @@ Page { Label { id: attachmentPreviewText font.pixelSize: Theme.fontSizeSmall - text: attachmentPreviewRow.isVoiceNote ? attachmentPreviewRow.attachmentDescription : ( typeof attachmentPreviewRow.fileProperties !== "undefined" ? attachmentPreviewRow.fileProperties.fileName || "" : "" ); + text: ( attachmentPreviewRow.isVoiceNote || attachmentPreviewRow.isLocation ) ? attachmentPreviewRow.attachmentDescription : ( typeof attachmentPreviewRow.fileProperties !== "undefined" ? attachmentPreviewRow.fileProperties.fileName || "" : "" ); anchors.verticalCenter: parent.verticalCenter maximumLineCount: 1 truncationMode: TruncationMode.Fade color: Theme.secondaryColor - visible: attachmentPreviewRow.isDocument || attachmentPreviewRow.isVoiceNote + visible: attachmentPreviewRow.isDocument || attachmentPreviewRow.isVoiceNote || attachmentPreviewRow.isLocation } } @@ -1558,6 +1594,7 @@ Page { labelVisible: false textLeftMargin: 0 textTopMargin: 0 + enabled: !attachmentPreviewRow.isLocation EnterKey.onClicked: { if (appSettings.sendByEnter) { sendMessage(); diff --git a/src/fernschreiberutils.cpp b/src/fernschreiberutils.cpp index 0d56554..5542cf4 100644 --- a/src/fernschreiberutils.cpp +++ b/src/fernschreiberutils.cpp @@ -25,6 +25,8 @@ #include #include #include +#include +#include #define DEBUG_MODULE FernschreiberUtils #include "debuglog.h" @@ -53,6 +55,14 @@ FernschreiberUtils::FernschreiberUtils(QObject *parent) : QObject(parent) connect(&audioRecorder, SIGNAL(durationChanged(qlonglong)), this, SIGNAL(voiceNoteDurationChanged(qlonglong))); connect(&audioRecorder, SIGNAL(statusChanged(QMediaRecorder::Status)), this, SLOT(handleAudioRecorderStatusChanged(QMediaRecorder::Status))); + this->geoPositionInfoSource = QGeoPositionInfoSource::createDefaultSource(this); + if (this->geoPositionInfoSource) { + LOG("Geolocation successfully initialized..."); + this->geoPositionInfoSource->setUpdateInterval(5000); + connect(geoPositionInfoSource, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(handleGeoPositionUpdated(QGeoPositionInfo))); + } else { + LOG("Unable to initialize geolocation!"); + } } FernschreiberUtils::~FernschreiberUtils() @@ -205,6 +215,25 @@ FernschreiberUtils::VoiceNoteRecordingState FernschreiberUtils::getVoiceNoteReco return this->voiceNoteRecordingState; } +void FernschreiberUtils::startGeoLocationUpdates() +{ + if (this->geoPositionInfoSource) { + this->geoPositionInfoSource->startUpdates(); + } +} + +void FernschreiberUtils::stopGeoLocationUpdates() +{ + if (this->geoPositionInfoSource) { + this->geoPositionInfoSource->stopUpdates(); + } +} + +bool FernschreiberUtils::supportsGeoLocation() +{ + return this->geoPositionInfoSource; +} + void FernschreiberUtils::handleAudioRecorderStatusChanged(QMediaRecorder::Status status) { LOG("Audio recorder status changed:" << status); @@ -231,8 +260,33 @@ void FernschreiberUtils::handleAudioRecorderStatusChanged(QMediaRecorder::Status emit voiceNoteRecordingStateChanged(this->voiceNoteRecordingState); } +void FernschreiberUtils::handleGeoPositionUpdated(const QGeoPositionInfo &info) +{ + LOG("Geo position was updated"); + QVariantMap positionInformation; + if (info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) { + positionInformation.insert("horizontalAccuracy", info.attribute(QGeoPositionInfo::HorizontalAccuracy)); + } else { + positionInformation.insert("horizontalAccuracy", 0); + } + if (info.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) { + positionInformation.insert("verticalAccuracy", info.attribute(QGeoPositionInfo::VerticalAccuracy)); + } else { + positionInformation.insert("verticalAccuracy", 0); + } + QGeoCoordinate geoCoordinate = info.coordinate(); + positionInformation.insert("latitude", geoCoordinate.latitude()); + positionInformation.insert("longitude", geoCoordinate.longitude()); + + + emit newPositionInformation(positionInformation); +} + void FernschreiberUtils::cleanUp() { + if (this->geoPositionInfoSource) { + this->geoPositionInfoSource->stopUpdates(); + } QString voiceNotePath = this->voiceNotePath(); if (QFile::exists(voiceNotePath)) { LOG("Removing old temporary file..."); diff --git a/src/fernschreiberutils.h b/src/fernschreiberutils.h index 74d7378..6c7f043 100644 --- a/src/fernschreiberutils.h +++ b/src/fernschreiberutils.h @@ -22,6 +22,8 @@ #include #include +#include +#include #include "tdlibwrapper.h" class FernschreiberUtils : public QObject @@ -47,18 +49,25 @@ public: Q_INVOKABLE void stopRecordingVoiceNote(); Q_INVOKABLE QString voiceNotePath(); Q_INVOKABLE VoiceNoteRecordingState getVoiceNoteRecordingState(); + Q_INVOKABLE void startGeoLocationUpdates(); + Q_INVOKABLE void stopGeoLocationUpdates(); + Q_INVOKABLE bool supportsGeoLocation(); signals: void voiceNoteDurationChanged(qlonglong duration); void voiceNoteRecordingStateChanged(VoiceNoteRecordingState state); + void newPositionInformation(const QVariantMap &positionInformation); private slots: void handleAudioRecorderStatusChanged(QMediaRecorder::Status status); + void handleGeoPositionUpdated(const QGeoPositionInfo &info); private: QAudioRecorder audioRecorder; VoiceNoteRecordingState voiceNoteRecordingState; + QGeoPositionInfoSource *geoPositionInfoSource; + void cleanUp(); }; diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index a791319..3ef9049 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -497,6 +497,32 @@ void TDLibWrapper::sendVoiceNoteMessage(const QString &chatId, const QString &fi this->sendRequest(requestObject); } +void TDLibWrapper::sendLocationMessage(const QString &chatId, double latitude, double longitude, double horizontalAccuracy, const QString &replyToMessageId) +{ + LOG("Sending location message" << chatId << latitude << longitude << horizontalAccuracy << replyToMessageId); + QVariantMap requestObject; + requestObject.insert(_TYPE, "sendMessage"); + requestObject.insert(CHAT_ID, chatId); + if (replyToMessageId != "0") { + requestObject.insert("reply_to_message_id", replyToMessageId); + } + QVariantMap inputMessageContent; + inputMessageContent.insert(_TYPE, "inputMessageLocation"); + QVariantMap location; + location.insert("latitude", latitude); + location.insert("longitude", longitude); + location.insert("horizontal_accuracy", horizontalAccuracy); + location.insert(_TYPE, "location"); + inputMessageContent.insert("location", location); + + inputMessageContent.insert("live_period", 0); + inputMessageContent.insert("heading", 0); + inputMessageContent.insert("proximity_alert_radius", 0); + + requestObject.insert("input_message_content", inputMessageContent); + this->sendRequest(requestObject); +} + void TDLibWrapper::sendStickerMessage(const QString &chatId, const QString &fileId, const QString &replyToMessageId) { LOG("Sending sticker message" << chatId << fileId << replyToMessageId); diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index 026bb69..efb0003 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -140,6 +140,7 @@ public: Q_INVOKABLE void sendVideoMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0"); Q_INVOKABLE void sendDocumentMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0"); Q_INVOKABLE void sendVoiceNoteMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0"); + Q_INVOKABLE void sendLocationMessage(const QString &chatId, double latitude, double longitude, double horizontalAccuracy, const QString &replyToMessageId = "0"); Q_INVOKABLE void sendStickerMessage(const QString &chatId, const QString &fileId, const QString &replyToMessageId = "0"); Q_INVOKABLE void sendPollMessage(const QString &chatId, const QString &question, const QVariantList &options, bool anonymous, int correctOption, bool multiple, const QString &replyToMessageId = "0"); Q_INVOKABLE void forwardMessages(const QString &chatId, const QString &fromChatId, const QVariantList &messageIds, bool sendCopy, bool removeCaption); diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts index 93b93ed..3df91af 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -411,6 +411,14 @@ Search in chat... Im Chat suchen... + + Location: Obtaining position... + Standort: Erlange Position... + + + Location (%1/%2) + Standort (%1/%2) + ChatSelectionPage diff --git a/translations/harbour-fernschreiber-en.ts b/translations/harbour-fernschreiber-en.ts index cc31755..2bf84b3 100644 --- a/translations/harbour-fernschreiber-en.ts +++ b/translations/harbour-fernschreiber-en.ts @@ -411,6 +411,14 @@ Search in chat... Search in chat... + + Location: Obtaining position... + Location: Obtaining position... + + + Location (%1/%2) + Location (%1/%2) + ChatSelectionPage diff --git a/translations/harbour-fernschreiber-es.ts b/translations/harbour-fernschreiber-es.ts index b0f503b..947c059 100644 --- a/translations/harbour-fernschreiber-es.ts +++ b/translations/harbour-fernschreiber-es.ts @@ -401,6 +401,14 @@ Search in chat... Buscar + + Location: Obtaining position... + + + + Location (%1/%2) + + ChatSelectionPage diff --git a/translations/harbour-fernschreiber-fi.ts b/translations/harbour-fernschreiber-fi.ts index 7dba3f2..ef90362 100644 --- a/translations/harbour-fernschreiber-fi.ts +++ b/translations/harbour-fernschreiber-fi.ts @@ -411,6 +411,14 @@ Search in chat... + + Location: Obtaining position... + + + + Location (%1/%2) + + ChatSelectionPage diff --git a/translations/harbour-fernschreiber-hu.ts b/translations/harbour-fernschreiber-hu.ts index 1fd9edd..4211f99 100644 --- a/translations/harbour-fernschreiber-hu.ts +++ b/translations/harbour-fernschreiber-hu.ts @@ -401,6 +401,14 @@ Search in chat... + + Location: Obtaining position... + + + + Location (%1/%2) + + ChatSelectionPage diff --git a/translations/harbour-fernschreiber-it.ts b/translations/harbour-fernschreiber-it.ts index b6d15bf..2075ad3 100644 --- a/translations/harbour-fernschreiber-it.ts +++ b/translations/harbour-fernschreiber-it.ts @@ -411,6 +411,14 @@ Search in chat... + + Location: Obtaining position... + + + + Location (%1/%2) + + ChatSelectionPage diff --git a/translations/harbour-fernschreiber-pl.ts b/translations/harbour-fernschreiber-pl.ts index 8ed7d43..c283ef8 100644 --- a/translations/harbour-fernschreiber-pl.ts +++ b/translations/harbour-fernschreiber-pl.ts @@ -421,6 +421,14 @@ Search in chat... + + Location: Obtaining position... + + + + Location (%1/%2) + + ChatSelectionPage diff --git a/translations/harbour-fernschreiber-ru.ts b/translations/harbour-fernschreiber-ru.ts index 204913c..c7d41d8 100644 --- a/translations/harbour-fernschreiber-ru.ts +++ b/translations/harbour-fernschreiber-ru.ts @@ -421,6 +421,14 @@ Search in chat... + + Location: Obtaining position... + + + + Location (%1/%2) + + ChatSelectionPage diff --git a/translations/harbour-fernschreiber-sv.ts b/translations/harbour-fernschreiber-sv.ts index 0833bb6..aac3e03 100644 --- a/translations/harbour-fernschreiber-sv.ts +++ b/translations/harbour-fernschreiber-sv.ts @@ -411,6 +411,14 @@ Search in chat... Sök i chatten... + + Location: Obtaining position... + + + + Location (%1/%2) + + ChatSelectionPage diff --git a/translations/harbour-fernschreiber-zh_CN.ts b/translations/harbour-fernschreiber-zh_CN.ts index 7f836e9..d7942a8 100644 --- a/translations/harbour-fernschreiber-zh_CN.ts +++ b/translations/harbour-fernschreiber-zh_CN.ts @@ -401,6 +401,14 @@ Search in chat... + + Location: Obtaining position... + + + + Location (%1/%2) + + ChatSelectionPage diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index 5f03298..9390ff5 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -411,6 +411,14 @@ Search in chat... + + Location: Obtaining position... + + + + Location (%1/%2) + + ChatSelectionPage