From 9662df3c74f9708fb9558b9842aadfeb12fb3cd7 Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Thu, 31 Dec 2020 19:12:50 +0100 Subject: [PATCH 1/8] Start with voice notes --- harbour-fernschreiber.pro | 1 + qml/components/VoiceNoteOverlay.qml | 72 +++++++++++++++++++++ qml/pages/ChatPage.qml | 28 +++++++- translations/harbour-fernschreiber-de.ts | 7 ++ translations/harbour-fernschreiber-en.ts | 7 ++ translations/harbour-fernschreiber-es.ts | 7 ++ translations/harbour-fernschreiber-fi.ts | 7 ++ translations/harbour-fernschreiber-hu.ts | 7 ++ translations/harbour-fernschreiber-it.ts | 7 ++ translations/harbour-fernschreiber-pl.ts | 7 ++ translations/harbour-fernschreiber-ru.ts | 7 ++ translations/harbour-fernschreiber-sv.ts | 7 ++ translations/harbour-fernschreiber-zh_CN.ts | 7 ++ translations/harbour-fernschreiber.ts | 7 ++ 14 files changed, 176 insertions(+), 2 deletions(-) create mode 100644 qml/components/VoiceNoteOverlay.qml diff --git a/harbour-fernschreiber.pro b/harbour-fernschreiber.pro index f751a28..4c1e850 100644 --- a/harbour-fernschreiber.pro +++ b/harbour-fernschreiber.pro @@ -58,6 +58,7 @@ DISTFILES += qml/harbour-fernschreiber.qml \ qml/components/ReplyMarkupButtons.qml \ qml/components/StickerPicker.qml \ qml/components/PhotoTextsListItem.qml \ + qml/components/VoiceNoteOverlay.qml \ qml/components/WebPagePreview.qml \ qml/components/chatInformationPage/ChatInformationEditArea.qml \ qml/components/chatInformationPage/ChatInformationPageContent.qml \ diff --git a/qml/components/VoiceNoteOverlay.qml b/qml/components/VoiceNoteOverlay.qml new file mode 100644 index 0000000..fb2b92a --- /dev/null +++ b/qml/components/VoiceNoteOverlay.qml @@ -0,0 +1,72 @@ +/* + Copyright (C) 2020 Sebastian J. Wolf and other contributors + + This file is part of Fernschreiber. + + Fernschreiber is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Fernschreiber is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Fernschreiber. If not, see . +*/ +import QtQuick 2.6 +import Sailfish.Silica 1.0 +import "../components" +import "../js/twemoji.js" as Emoji + +Item { + id: voiceNoteOverlayItem + anchors.fill: parent + + Rectangle { + id: stickerPickerOverlayBackground + anchors.fill: parent + + color: Theme.overlayBackgroundColor + opacity: Theme.opacityHigh + } + + Flickable { + id: voiceNoteFlickable + anchors.fill: parent + anchors.margins: Theme.paddingMedium + + Behavior on opacity { NumberAnimation {} } + + contentHeight: voiceNoteColumn.height + clip: true + + Column { + id: voiceNoteColumn + spacing: Theme.paddingMedium + width: voiceNoteFlickable.width + + InfoLabel { + text: qsTr("Record a Voice Note") + } + + Image { + id: recorderImage + source: "image://theme/icon-l-recorder" + anchors { + horizontalCenter: parent.horizontalCenter + } + + fillMode: Image.PreserveAspectFit + asynchronous: true + width: Theme.itemSizeLarge + height: Theme.itemSizeLarge + } + + } + } + +} + diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index 961d643..dc1c50f 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -621,7 +621,7 @@ Page { contentWidth: width PullDownMenu { - visible: chatInformation.id !== chatPage.myUserId && !stickerPickerLoader.active && !messageOverlayLoader.active + visible: chatInformation.id !== chatPage.myUserId && !stickerPickerLoader.active && !voiceNoteOverlayLoader.active && !messageOverlayLoader.active MenuItem { id: closeSecretChatMenuItem visible: chatPage.isSecretChat && chatPage.secretChatDetails.state["@type"] !== "secretChatStateClosed" @@ -874,7 +874,7 @@ Page { id: chatView visible: !blurred - property bool blurred: messageOverlayLoader.item + property bool blurred: messageOverlayLoader.item || stickerPickerLoader.item || voiceNoteOverlayLoader.item anchors.fill: parent opacity: chatPage.loading ? 0 : 1 @@ -1132,6 +1132,15 @@ Page { } } + Loader { + id: voiceNoteOverlayLoader + active: false + asynchronous: true + width: parent.width + height: active ? parent.height : 0 + source: "../components/VoiceNoteOverlay.qml" + } + } Column { @@ -1216,6 +1225,19 @@ Page { }) } } + IconButton { + visible: chatPage.hasSendPrivilege("can_send_media_messages") + icon.source: "image://theme/icon-m-mic" + icon.sourceSize { + width: Theme.iconSizeMedium + height: Theme.iconSizeMedium + } + highlighted: down || voiceNoteOverlayLoader.active + onClicked: { + voiceNoteOverlayLoader.active = !voiceNoteOverlayLoader.active; + stickerPickerLoader.active = false; + } + } IconButton { visible: chatPage.hasSendPrivilege("can_send_media_messages") icon.source: "image://theme/icon-m-document" @@ -1243,6 +1265,7 @@ Page { highlighted: down || stickerPickerLoader.active onClicked: { stickerPickerLoader.active = !stickerPickerLoader.active; + voiceNoteOverlayLoader.active = false; } } IconButton { @@ -1528,6 +1551,7 @@ Page { if (attachmentOptionsRow.isNeeded) { attachmentOptionsRow.isNeeded = false; stickerPickerLoader.active = false; + voiceNoteOverlayLoader.active = false; } else { attachmentOptionsRow.isNeeded = true; } diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts index 489527b..e871efc 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -1418,6 +1418,13 @@ Download fehlgeschlagen. + + VoiceNoteOverlay + + Record a Voice Note + + + WebPagePreview diff --git a/translations/harbour-fernschreiber-en.ts b/translations/harbour-fernschreiber-en.ts index 701afc6..6e943e0 100644 --- a/translations/harbour-fernschreiber-en.ts +++ b/translations/harbour-fernschreiber-en.ts @@ -1418,6 +1418,13 @@ Download failed. + + VoiceNoteOverlay + + Record a Voice Note + + + WebPagePreview diff --git a/translations/harbour-fernschreiber-es.ts b/translations/harbour-fernschreiber-es.ts index 828b71c..06060e9 100644 --- a/translations/harbour-fernschreiber-es.ts +++ b/translations/harbour-fernschreiber-es.ts @@ -1399,6 +1399,13 @@ Error al bajar + + VoiceNoteOverlay + + Record a Voice Note + + + WebPagePreview diff --git a/translations/harbour-fernschreiber-fi.ts b/translations/harbour-fernschreiber-fi.ts index 0882c32..83349c7 100644 --- a/translations/harbour-fernschreiber-fi.ts +++ b/translations/harbour-fernschreiber-fi.ts @@ -1419,6 +1419,13 @@ Lataus epäonnistui. + + VoiceNoteOverlay + + Record a Voice Note + + + WebPagePreview diff --git a/translations/harbour-fernschreiber-hu.ts b/translations/harbour-fernschreiber-hu.ts index 7ca1400..cbe6a16 100644 --- a/translations/harbour-fernschreiber-hu.ts +++ b/translations/harbour-fernschreiber-hu.ts @@ -1399,6 +1399,13 @@ A letöltés nem sikerült. + + VoiceNoteOverlay + + Record a Voice Note + + + WebPagePreview diff --git a/translations/harbour-fernschreiber-it.ts b/translations/harbour-fernschreiber-it.ts index 3c2baf9..85f802a 100644 --- a/translations/harbour-fernschreiber-it.ts +++ b/translations/harbour-fernschreiber-it.ts @@ -1418,6 +1418,13 @@ Download non riuscito. + + VoiceNoteOverlay + + Record a Voice Note + + + WebPagePreview diff --git a/translations/harbour-fernschreiber-pl.ts b/translations/harbour-fernschreiber-pl.ts index c2b925d..92fdc5f 100644 --- a/translations/harbour-fernschreiber-pl.ts +++ b/translations/harbour-fernschreiber-pl.ts @@ -1437,6 +1437,13 @@ Nieudane pobieranie + + VoiceNoteOverlay + + Record a Voice Note + + + WebPagePreview diff --git a/translations/harbour-fernschreiber-ru.ts b/translations/harbour-fernschreiber-ru.ts index 72454c2..481f829 100644 --- a/translations/harbour-fernschreiber-ru.ts +++ b/translations/harbour-fernschreiber-ru.ts @@ -1437,6 +1437,13 @@ Ошибка скачивания. + + VoiceNoteOverlay + + Record a Voice Note + + + WebPagePreview diff --git a/translations/harbour-fernschreiber-sv.ts b/translations/harbour-fernschreiber-sv.ts index c649561..e3d44d2 100644 --- a/translations/harbour-fernschreiber-sv.ts +++ b/translations/harbour-fernschreiber-sv.ts @@ -1418,6 +1418,13 @@ Nerladdning misslyckades. + + VoiceNoteOverlay + + Record a Voice Note + + + WebPagePreview diff --git a/translations/harbour-fernschreiber-zh_CN.ts b/translations/harbour-fernschreiber-zh_CN.ts index 8e4f8f9..c938305 100644 --- a/translations/harbour-fernschreiber-zh_CN.ts +++ b/translations/harbour-fernschreiber-zh_CN.ts @@ -1399,6 +1399,13 @@ 下载失败 + + VoiceNoteOverlay + + Record a Voice Note + + + WebPagePreview diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index 8005242..b9adc5e 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -1418,6 +1418,13 @@ Download failed. + + VoiceNoteOverlay + + Record a Voice Note + + + WebPagePreview From d38f56b9fe300ee8aab1db1bf5f6b91ca613fe67 Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Sat, 2 Jan 2021 00:15:25 +0100 Subject: [PATCH 2/8] Recording Vorbis files works & connected to UI --- harbour-fernschreiber.pro | 2 +- qml/components/VoiceNoteOverlay.qml | 145 ++++++++++++++++++-- qml/pages/ChatPage.qml | 5 + src/fernschreiberutils.cpp | 104 +++++++++++++- src/fernschreiberutils.h | 46 ++++++- src/harbour-fernschreiber.cpp | 1 + translations/harbour-fernschreiber-de.ts | 24 ++++ translations/harbour-fernschreiber-en.ts | 24 ++++ translations/harbour-fernschreiber-es.ts | 24 ++++ translations/harbour-fernschreiber-fi.ts | 24 ++++ translations/harbour-fernschreiber-hu.ts | 24 ++++ translations/harbour-fernschreiber-it.ts | 24 ++++ translations/harbour-fernschreiber-pl.ts | 24 ++++ translations/harbour-fernschreiber-ru.ts | 24 ++++ translations/harbour-fernschreiber-sv.ts | 24 ++++ translations/harbour-fernschreiber-zh_CN.ts | 24 ++++ translations/harbour-fernschreiber.ts | 24 ++++ 17 files changed, 555 insertions(+), 12 deletions(-) diff --git a/harbour-fernschreiber.pro b/harbour-fernschreiber.pro index 4c1e850..5823b5a 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 +QT += core dbus sql multimedia DEFINES += QT_STATICPLUGIN diff --git a/qml/components/VoiceNoteOverlay.qml b/qml/components/VoiceNoteOverlay.qml index fb2b92a..66dcb4f 100644 --- a/qml/components/VoiceNoteOverlay.qml +++ b/qml/components/VoiceNoteOverlay.qml @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Sebastian J. Wolf and other contributors + Copyright (C) 2020-21 Sebastian J. Wolf and other contributors This file is part of Fernschreiber. @@ -18,13 +18,74 @@ */ import QtQuick 2.6 import Sailfish.Silica 1.0 +import WerkWolf.Fernschreiber 1.0 import "../components" import "../js/twemoji.js" as Emoji +import "../js/debug.js" as Debug Item { id: voiceNoteOverlayItem anchors.fill: parent + property int recordingState: fernschreiberUtils.getVoiceNoteRecordingState(); + property int recordingDuration: 0; + + function handleRecordingState() { + switch (recordingState) { + case FernschreiberUtilities.Unavailable: + recordingStateLabel.text = qsTr("Unavailable"); + break; + case FernschreiberUtilities.Stopped: + recordingStateLabel.text = qsTr("Stopped"); + break; + case FernschreiberUtilities.Starting: + recordingStateLabel.text = qsTr("Starting"); + break; + case FernschreiberUtilities.Recording: + recordingStateLabel.text = qsTr("Recording"); + break; + case FernschreiberUtilities.Stopping: + recordingStateLabel.text = qsTr("Stopping"); + break; + } + } + + function getTwoDigitString(numberToBeConverted) { + var numberString = "00"; + if (numberToBeConverted > 0 && numberToBeConverted < 10) { + numberString = "0" + String(numberToBeConverted); + } + if (numberToBeConverted >= 10) { + numberString = String(numberToBeConverted); + } + return numberString; + } + + function handleRecordingDuration() { + var minutes = Math.floor(recordingDuration / 60); + var seconds = recordingDuration % 60; + recordingDurationLabel.text = getTwoDigitString(minutes) + ":" + getTwoDigitString(seconds); + } + + Component.onCompleted: { + handleRecordingState(); + handleRecordingDuration(); + } + + Connections { + target: fernschreiberUtils + onVoiceNoteDurationChanged: { + Debug.log("New duration received: " + duration); + recordingDuration = Math.round(duration / 1000); + handleRecordingDuration(); + } + onVoiceNoteRecordingStateChanged: { + Debug.log("New state received: " + state); + recordingState = state; + handleRecordingState(); + } + } + Rectangle { id: stickerPickerOverlayBackground anchors.fill: parent @@ -52,17 +113,85 @@ Item { text: qsTr("Record a Voice Note") } - Image { - id: recorderImage - source: "image://theme/icon-l-recorder" + Label { + wrapMode: Text.Wrap + width: parent.width - ( 2 * Theme.horizontalPageMargin ) + horizontalAlignment: Text.AlignHCenter + text: qsTr("Press the button to start recording") + font.pixelSize: Theme.fontSizeMedium anchors { horizontalCenter: parent.horizontalCenter } + } - fillMode: Image.PreserveAspectFit - asynchronous: true - width: Theme.itemSizeLarge - height: Theme.itemSizeLarge + Item { + width: Theme.iconSizeExtraLarge + height: Theme.iconSizeExtraLarge + anchors { + horizontalCenter: parent.horizontalCenter + } + Rectangle { + color: Theme.primaryColor + opacity: Theme.opacityOverlay + width: Theme.iconSizeExtraLarge + height: Theme.iconSizeExtraLarge + anchors.centerIn: parent + radius: width / 2 + } + + Rectangle { + id: recordButton + color: "red" + width: Theme.iconSizeExtraLarge * 0.6 + height: Theme.iconSizeExtraLarge * 0.6 + anchors.centerIn: parent + radius: width / 2 + MouseArea { + anchors.fill: parent + onClicked: { + recordButton.visible = false; + fernschreiberUtils.startRecordingVoiceNote(); + } + } + } + + Rectangle { + id: stopButton + visible: !recordButton.visible + color: Theme.overlayBackgroundColor + width: Theme.iconSizeExtraLarge * 0.4 + height: Theme.iconSizeExtraLarge * 0.4 + anchors.centerIn: parent + MouseArea { + anchors.fill: parent + onClicked: { + recordButton.visible = true; + fernschreiberUtils.stopRecordingVoiceNote(); + } + } + } + } + + Label { + id: recordingStateLabel + wrapMode: Text.Wrap + width: parent.width - ( 2 * Theme.horizontalPageMargin ) + horizontalAlignment: Text.AlignHCenter + font.pixelSize: Theme.fontSizeMedium + anchors { + horizontalCenter: parent.horizontalCenter + } + } + + Label { + id: recordingDurationLabel + wrapMode: Text.Wrap + width: parent.width - ( 2 * Theme.horizontalPageMargin ) + horizontalAlignment: Text.AlignHCenter + font.pixelSize: Theme.fontSizeMedium + anchors { + horizontalCenter: parent.horizontalCenter + } } } diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index f5f0aeb..0cdbb6f 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -1145,6 +1145,11 @@ Page { width: parent.width height: active ? parent.height : 0 source: "../components/VoiceNoteOverlay.qml" + onActiveChanged: { + if (!active) { + fernschreiberUtils.stopRecordingVoiceNote(); + } + } } } diff --git a/src/fernschreiberutils.cpp b/src/fernschreiberutils.cpp index b75734a..d079d59 100644 --- a/src/fernschreiberutils.cpp +++ b/src/fernschreiberutils.cpp @@ -1,10 +1,57 @@ -#include "fernschreiberutils.h" +/* + Copyright (C) 2020-21 Sebastian J. Wolf and other contributors + This file is part of Fernschreiber. + + Fernschreiber is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Fernschreiber is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Fernschreiber. If not, see . +*/ + +#include "fernschreiberutils.h" #include #include +#include +#include +#include +#include +#include + +#define DEBUG_MODULE FernschreiberUtils +#include "debuglog.h" FernschreiberUtils::FernschreiberUtils(QObject *parent) : QObject(parent) { + LOG("Initializing audio recorder..."); + + QString temporaryDirectoryPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + + "/harbour-fernschreiber"; + QDir temporaryDirectory(temporaryDirectoryPath); + if (!temporaryDirectory.exists()) { + temporaryDirectory.mkpath(temporaryDirectoryPath); + } + + QAudioEncoderSettings encoderSettings; + encoderSettings.setCodec("audio/vorbis"); + encoderSettings.setChannelCount(1); + encoderSettings.setQuality(QMultimedia::LowQuality); + this->audioRecorder.setEncodingSettings(encoderSettings); + this->audioRecorder.setContainerFormat("ogg"); + this->audioRecorder.setOutputLocation(QUrl::fromLocalFile(temporaryDirectoryPath + "/voicenote.ogg")); + + QMediaRecorder::Status audioRecorderStatus = this->audioRecorder.status(); + this->handleAudioRecorderStatusChanged(audioRecorderStatus); + + connect(&audioRecorder, SIGNAL(durationChanged(qlonglong)), this, SIGNAL(voiceNoteDurationChanged(qlonglong))); + connect(&audioRecorder, SIGNAL(statusChanged(QMediaRecorder::Status)), this, SLOT(handleAudioRecorderStatusChanged(QMediaRecorder::Status))); } @@ -128,3 +175,58 @@ QString FernschreiberUtils::getUserName(const QVariantMap &userInformation) const QString lastName = userInformation.value("last_name").toString(); return QString(firstName + " " + lastName).trimmed(); } + +void FernschreiberUtils::startRecordingVoiceNote() +{ + LOG("Start recording voice note..."); + QString voiceNotePath = this->voiceNotePath(); + LOG("Using temporary file at " << voiceNotePath); + if (QFile::exists(voiceNotePath)) { + LOG("Removing old temporary file..."); + QFile::remove(voiceNotePath); + } + this->audioRecorder.setVolume(1); + this->audioRecorder.record(); +} + +void FernschreiberUtils::stopRecordingVoiceNote() +{ + LOG("Stop recording voice note..."); + this->audioRecorder.stop(); +} + +QString FernschreiberUtils::voiceNotePath() +{ + return this->audioRecorder.outputLocation().toLocalFile(); +} + +FernschreiberUtils::VoiceNoteRecordingState FernschreiberUtils::getVoiceNoteRecordingState() +{ + return this->voiceNoteRecordingState; +} + +void FernschreiberUtils::handleAudioRecorderStatusChanged(QMediaRecorder::Status status) +{ + LOG("Audio recorder status changed:" << status); + switch (status) { + case QMediaRecorder::UnavailableStatus: + case QMediaRecorder::UnloadedStatus: + case QMediaRecorder::LoadingStatus: + this->voiceNoteRecordingState = VoiceNoteRecordingState::Unavailable; + break; + case QMediaRecorder::LoadedStatus: + case QMediaRecorder::PausedStatus: + this->voiceNoteRecordingState = VoiceNoteRecordingState::Stopped; + break; + case QMediaRecorder::StartingStatus: + this->voiceNoteRecordingState = VoiceNoteRecordingState::Starting; + break; + case QMediaRecorder::FinalizingStatus: + this->voiceNoteRecordingState = VoiceNoteRecordingState::Stopping; + break; + case QMediaRecorder::RecordingStatus: + this->voiceNoteRecordingState = VoiceNoteRecordingState::Recording; + break; + } + emit voiceNoteRecordingStateChanged(this->voiceNoteRecordingState); +} diff --git a/src/fernschreiberutils.h b/src/fernschreiberutils.h index 35fc8a0..16e80c3 100644 --- a/src/fernschreiberutils.h +++ b/src/fernschreiberutils.h @@ -1,7 +1,27 @@ +/* + Copyright (C) 2020-21 Sebastian J. Wolf and other contributors + + This file is part of Fernschreiber. + + Fernschreiber is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Fernschreiber is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Fernschreiber. If not, see . +*/ + #ifndef FERNSCHREIBERUTILS_H #define FERNSCHREIBERUTILS_H #include +#include #include "tdlibwrapper.h" class FernschreiberUtils : public QObject @@ -10,12 +30,34 @@ class FernschreiberUtils : public QObject public: explicit FernschreiberUtils(QObject *parent = nullptr); + enum VoiceNoteRecordingState { + Unavailable, + Stopped, + Starting, + Recording, + Stopping + }; + Q_ENUM(VoiceNoteRecordingState) + static QString getMessageShortText(TDLibWrapper *tdLibWrapper, const QVariantMap &messageContent, const bool isChannel, const qlonglong currentUserId, const QVariantMap &messageSender); static QString getUserName(const QVariantMap &userInformation); -signals: + Q_INVOKABLE void startRecordingVoiceNote(); + Q_INVOKABLE void stopRecordingVoiceNote(); + Q_INVOKABLE QString voiceNotePath(); + Q_INVOKABLE VoiceNoteRecordingState getVoiceNoteRecordingState(); + +signals: + void voiceNoteDurationChanged(qlonglong duration); + void voiceNoteRecordingStateChanged(VoiceNoteRecordingState state); + +private slots: + void handleAudioRecorderStatusChanged(QMediaRecorder::Status status); + +private: + QAudioRecorder audioRecorder; + VoiceNoteRecordingState voiceNoteRecordingState; -public slots: }; #endif // FERNSCHREIBERUTILS_H diff --git a/src/harbour-fernschreiber.cpp b/src/harbour-fernschreiber.cpp index 6efdf5d..0852fea 100644 --- a/src/harbour-fernschreiber.cpp +++ b/src/harbour-fernschreiber.cpp @@ -82,6 +82,7 @@ int main(int argc, char *argv[]) FernschreiberUtils *fernschreiberUtils = new FernschreiberUtils(view.data()); context->setContextProperty("fernschreiberUtils", fernschreiberUtils); + qmlRegisterUncreatableType(uri, 1, 0, "FernschreiberUtilities", QString()); DBusAdaptor *dBusAdaptor = tdLibWrapper->getDBusAdaptor(); context->setContextProperty("dBusAdaptor", dBusAdaptor); diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts index 10db4a5..6894a9e 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -1438,6 +1438,30 @@ Record a Voice Note + + Press the button to start recording + + + + Unavailable + + + + Stopped + + + + Starting + + + + Recording + + + + Stopping + + WebPagePreview diff --git a/translations/harbour-fernschreiber-en.ts b/translations/harbour-fernschreiber-en.ts index ffaad43..e474f3f 100644 --- a/translations/harbour-fernschreiber-en.ts +++ b/translations/harbour-fernschreiber-en.ts @@ -1438,6 +1438,30 @@ Record a Voice Note + + Press the button to start recording + + + + Unavailable + + + + Stopped + + + + Starting + + + + Recording + + + + Stopping + + WebPagePreview diff --git a/translations/harbour-fernschreiber-es.ts b/translations/harbour-fernschreiber-es.ts index 57c7541..5f812e5 100644 --- a/translations/harbour-fernschreiber-es.ts +++ b/translations/harbour-fernschreiber-es.ts @@ -1417,6 +1417,30 @@ Record a Voice Note + + Press the button to start recording + + + + Unavailable + + + + Stopped + + + + Starting + + + + Recording + + + + Stopping + + WebPagePreview diff --git a/translations/harbour-fernschreiber-fi.ts b/translations/harbour-fernschreiber-fi.ts index 2739023..cb1004c 100644 --- a/translations/harbour-fernschreiber-fi.ts +++ b/translations/harbour-fernschreiber-fi.ts @@ -1439,6 +1439,30 @@ Record a Voice Note + + Press the button to start recording + + + + Unavailable + + + + Stopped + + + + Starting + + + + Recording + + + + Stopping + + WebPagePreview diff --git a/translations/harbour-fernschreiber-hu.ts b/translations/harbour-fernschreiber-hu.ts index 630f4ae..a160d2d 100644 --- a/translations/harbour-fernschreiber-hu.ts +++ b/translations/harbour-fernschreiber-hu.ts @@ -1417,6 +1417,30 @@ Record a Voice Note + + Press the button to start recording + + + + Unavailable + + + + Stopped + + + + Starting + + + + Recording + + + + Stopping + + WebPagePreview diff --git a/translations/harbour-fernschreiber-it.ts b/translations/harbour-fernschreiber-it.ts index 5c18e4c..d0319bc 100644 --- a/translations/harbour-fernschreiber-it.ts +++ b/translations/harbour-fernschreiber-it.ts @@ -1438,6 +1438,30 @@ Record a Voice Note + + Press the button to start recording + + + + Unavailable + + + + Stopped + + + + Starting + + + + Recording + + + + Stopping + + WebPagePreview diff --git a/translations/harbour-fernschreiber-pl.ts b/translations/harbour-fernschreiber-pl.ts index dd55b46..fc7f215 100644 --- a/translations/harbour-fernschreiber-pl.ts +++ b/translations/harbour-fernschreiber-pl.ts @@ -1459,6 +1459,30 @@ Record a Voice Note + + Press the button to start recording + + + + Unavailable + + + + Stopped + + + + Starting + + + + Recording + + + + Stopping + + WebPagePreview diff --git a/translations/harbour-fernschreiber-ru.ts b/translations/harbour-fernschreiber-ru.ts index 0edb938..d3b4699 100644 --- a/translations/harbour-fernschreiber-ru.ts +++ b/translations/harbour-fernschreiber-ru.ts @@ -1459,6 +1459,30 @@ Record a Voice Note + + Press the button to start recording + + + + Unavailable + + + + Stopped + + + + Starting + + + + Recording + + + + Stopping + + WebPagePreview diff --git a/translations/harbour-fernschreiber-sv.ts b/translations/harbour-fernschreiber-sv.ts index 2a159af..0bbb2e4 100644 --- a/translations/harbour-fernschreiber-sv.ts +++ b/translations/harbour-fernschreiber-sv.ts @@ -1438,6 +1438,30 @@ Record a Voice Note + + Press the button to start recording + + + + Unavailable + + + + Stopped + + + + Starting + + + + Recording + + + + Stopping + + WebPagePreview diff --git a/translations/harbour-fernschreiber-zh_CN.ts b/translations/harbour-fernschreiber-zh_CN.ts index 44d8a9e..437b5d8 100644 --- a/translations/harbour-fernschreiber-zh_CN.ts +++ b/translations/harbour-fernschreiber-zh_CN.ts @@ -1417,6 +1417,30 @@ Record a Voice Note + + Press the button to start recording + + + + Unavailable + + + + Stopped + + + + Starting + + + + Recording + + + + Stopping + + WebPagePreview diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index f0b5aa4..5664771 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -1438,6 +1438,30 @@ Record a Voice Note + + Press the button to start recording + + + + Unavailable + + + + Stopped + + + + Starting + + + + Recording + + + + Stopping + + WebPagePreview From 5213084fb1c641c1aa2d12031b880aba10d573e9 Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Sat, 2 Jan 2021 17:22:09 +0100 Subject: [PATCH 3/8] Sending voice notes seems to work... --- qml/components/VoiceNoteOverlay.qml | 22 ++++++++++++++-- qml/pages/ChatPage.qml | 14 ++++++++--- src/fernschreiberutils.cpp | 23 +++++++++++------ src/fernschreiberutils.h | 5 +++- src/tdlibwrapper.cpp | 24 ++++++++++++++++++ src/tdlibwrapper.h | 1 + translations/harbour-fernschreiber-de.ts | 24 ++++++++++++------ translations/harbour-fernschreiber-en.ts | 28 +++++++++++++-------- translations/harbour-fernschreiber-es.ts | 16 +++++++++--- translations/harbour-fernschreiber-fi.ts | 16 +++++++++--- translations/harbour-fernschreiber-hu.ts | 16 +++++++++--- translations/harbour-fernschreiber-it.ts | 16 +++++++++--- translations/harbour-fernschreiber-pl.ts | 16 +++++++++--- translations/harbour-fernschreiber-ru.ts | 16 +++++++++--- translations/harbour-fernschreiber-sv.ts | 16 +++++++++--- translations/harbour-fernschreiber-zh_CN.ts | 16 +++++++++--- translations/harbour-fernschreiber.ts | 16 +++++++++--- 17 files changed, 218 insertions(+), 67 deletions(-) diff --git a/qml/components/VoiceNoteOverlay.qml b/qml/components/VoiceNoteOverlay.qml index 66dcb4f..423bdfb 100644 --- a/qml/components/VoiceNoteOverlay.qml +++ b/qml/components/VoiceNoteOverlay.qml @@ -29,14 +29,15 @@ Item { property int recordingState: fernschreiberUtils.getVoiceNoteRecordingState(); property int recordingDuration: 0; + property bool recordingDone: false; function handleRecordingState() { switch (recordingState) { case FernschreiberUtilities.Unavailable: recordingStateLabel.text = qsTr("Unavailable"); break; - case FernschreiberUtilities.Stopped: - recordingStateLabel.text = qsTr("Stopped"); + case FernschreiberUtilities.Ready: + recordingStateLabel.text = qsTr("Ready"); break; case FernschreiberUtilities.Starting: recordingStateLabel.text = qsTr("Starting"); @@ -167,6 +168,7 @@ Item { onClicked: { recordButton.visible = true; fernschreiberUtils.stopRecordingVoiceNote(); + recordingDone = true; } } } @@ -194,6 +196,22 @@ Item { } } + Button { + visible: recordingDone + anchors { + horizontalCenter: parent.horizontalCenter + } + text: qsTr("Use recording") + onClicked: { + attachmentOptionsRow.isNeeded = false; + attachmentPreviewRow.isVoiceNote = true; + attachmentPreviewRow.attachmentDescription = qsTr("Voice Note (%1)").arg(recordingDurationLabel.text); + attachmentPreviewRow.visible = true; + controlSendButton(); + voiceNoteOverlayLoader.active = false; + } + } + } } diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index 0cdbb6f..b652072 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -211,14 +211,17 @@ Page { attachmentPreviewRow.isPicture = false; attachmentPreviewRow.isVideo = false; attachmentPreviewRow.isDocument = false; + attachmentPreviewRow.isVoiceNote = false; attachmentPreviewRow.fileProperties = {}; + attachmentPreviewRow.attachmentDescription = ""; } function controlSendButton() { if (newMessageTextField.text.length !== 0 || attachmentPreviewRow.isPicture || attachmentPreviewRow.isDocument - || attachmentPreviewRow.isVideo) { + || attachmentPreviewRow.isVideo + || attachmentPreviewRow.isVoiceNote) { newMessageSendButton.enabled = true; } else { newMessageSendButton.enabled = false; @@ -239,6 +242,9 @@ Page { if (attachmentPreviewRow.isDocument) { tdLibWrapper.sendDocumentMessage(chatInformation.id, attachmentPreviewRow.fileProperties.filePath, newMessageTextField.text, newMessageColumn.replyToMessageId); } + if (attachmentPreviewRow.isVoiceNote) { + tdLibWrapper.sendVoiceNoteMessage(chatInformation.id, fernschreiberUtils.voiceNotePath(), newMessageTextField.text, newMessageColumn.replyToMessageId); + } clearAttachmentPreviewRow(); } else { tdLibWrapper.sendTextMessage(chatInformation.id, newMessageTextField.text, newMessageColumn.replyToMessageId); @@ -1300,7 +1306,9 @@ Page { property bool isPicture: false; property bool isVideo: false; property bool isDocument: false; + property bool isVoiceNote: false; property var fileProperties:({}); + property string attachmentDescription: ""; IconButton { id: removeAttachmentsIconButton @@ -1327,13 +1335,13 @@ Page { Label { id: attachmentPreviewText font.pixelSize: Theme.fontSizeSmall - text: typeof attachmentPreviewRow.fileProperties !== "undefined" ? attachmentPreviewRow.fileProperties.fileName || "" : ""; + text: attachmentPreviewRow.isVoiceNote ? attachmentPreviewRow.attachmentDescription : ( typeof attachmentPreviewRow.fileProperties !== "undefined" ? attachmentPreviewRow.fileProperties.fileName || "" : "" ); anchors.verticalCenter: parent.verticalCenter maximumLineCount: 1 truncationMode: TruncationMode.Fade color: Theme.secondaryColor - visible: attachmentPreviewRow.isDocument + visible: attachmentPreviewRow.isDocument || attachmentPreviewRow.isVoiceNote } } diff --git a/src/fernschreiberutils.cpp b/src/fernschreiberutils.cpp index d079d59..0d56554 100644 --- a/src/fernschreiberutils.cpp +++ b/src/fernschreiberutils.cpp @@ -55,6 +55,11 @@ FernschreiberUtils::FernschreiberUtils(QObject *parent) : QObject(parent) } +FernschreiberUtils::~FernschreiberUtils() +{ + this->cleanUp(); +} + QString FernschreiberUtils::getMessageShortText(TDLibWrapper *tdLibWrapper, const QVariantMap &messageContent, const bool isChannel, const qlonglong currentUserId, const QVariantMap &messageSender) { if (messageContent.isEmpty()) { @@ -179,12 +184,7 @@ QString FernschreiberUtils::getUserName(const QVariantMap &userInformation) void FernschreiberUtils::startRecordingVoiceNote() { LOG("Start recording voice note..."); - QString voiceNotePath = this->voiceNotePath(); - LOG("Using temporary file at " << voiceNotePath); - if (QFile::exists(voiceNotePath)) { - LOG("Removing old temporary file..."); - QFile::remove(voiceNotePath); - } + this->cleanUp(); this->audioRecorder.setVolume(1); this->audioRecorder.record(); } @@ -216,7 +216,7 @@ void FernschreiberUtils::handleAudioRecorderStatusChanged(QMediaRecorder::Status break; case QMediaRecorder::LoadedStatus: case QMediaRecorder::PausedStatus: - this->voiceNoteRecordingState = VoiceNoteRecordingState::Stopped; + this->voiceNoteRecordingState = VoiceNoteRecordingState::Ready; break; case QMediaRecorder::StartingStatus: this->voiceNoteRecordingState = VoiceNoteRecordingState::Starting; @@ -230,3 +230,12 @@ void FernschreiberUtils::handleAudioRecorderStatusChanged(QMediaRecorder::Status } emit voiceNoteRecordingStateChanged(this->voiceNoteRecordingState); } + +void FernschreiberUtils::cleanUp() +{ + QString voiceNotePath = this->voiceNotePath(); + if (QFile::exists(voiceNotePath)) { + LOG("Removing old temporary file..."); + QFile::remove(voiceNotePath); + } +} diff --git a/src/fernschreiberutils.h b/src/fernschreiberutils.h index 16e80c3..74d7378 100644 --- a/src/fernschreiberutils.h +++ b/src/fernschreiberutils.h @@ -29,10 +29,11 @@ class FernschreiberUtils : public QObject Q_OBJECT public: explicit FernschreiberUtils(QObject *parent = nullptr); + ~FernschreiberUtils(); enum VoiceNoteRecordingState { Unavailable, - Stopped, + Ready, Starting, Recording, Stopping @@ -58,6 +59,8 @@ private: QAudioRecorder audioRecorder; VoiceNoteRecordingState voiceNoteRecordingState; + void cleanUp(); + }; #endif // FERNSCHREIBERUTILS_H diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index fe436c8..a791319 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -473,6 +473,30 @@ void TDLibWrapper::sendDocumentMessage(const QString &chatId, const QString &fil this->sendRequest(requestObject); } +void TDLibWrapper::sendVoiceNoteMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId) +{ + LOG("Sending voice note message" << chatId << filePath << message << 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, "inputMessageVoiceNote"); + QVariantMap formattedText; + formattedText.insert("text", message); + formattedText.insert(_TYPE, "formattedText"); + inputMessageContent.insert("caption", formattedText); + QVariantMap documentInputFile; + documentInputFile.insert(_TYPE, "inputFileLocal"); + documentInputFile.insert("path", filePath); + inputMessageContent.insert("voice_note", documentInputFile); + + 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 c24941b..026bb69 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -139,6 +139,7 @@ public: Q_INVOKABLE void sendPhotoMessage(const QString &chatId, const QString &filePath, const QString &message, const QString &replyToMessageId = "0"); 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 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 6894a9e..6f36201 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -1436,31 +1436,39 @@ VoiceNoteOverlay Record a Voice Note - + Eine Sprachnachricht aufzeichnen Press the button to start recording - + Drücken Sie den Knopf, um die Aufzeichnung zu starten Unavailable - + Nicht verfügbar - Stopped - + Ready + Bereit Starting - + Startet Recording - + Zeichnet auf Stopping - + Stoppt + + + Use recording + Aufzeichnung verwenden + + + Voice Note (%1) + Sprachnachricht (%1) diff --git a/translations/harbour-fernschreiber-en.ts b/translations/harbour-fernschreiber-en.ts index e474f3f..d7e1769 100644 --- a/translations/harbour-fernschreiber-en.ts +++ b/translations/harbour-fernschreiber-en.ts @@ -1436,31 +1436,39 @@ VoiceNoteOverlay Record a Voice Note - + Record a Voice Note Press the button to start recording - + Press the button to start recording Unavailable - - - - Stopped - + Unavailable Starting - + Starting Recording - + Recording Stopping - + Stopping + + + Use recording + Use recording + + + Voice Note (%1) + Voice Note (%1) + + + Ready + Ready diff --git a/translations/harbour-fernschreiber-es.ts b/translations/harbour-fernschreiber-es.ts index 5f812e5..75b4911 100644 --- a/translations/harbour-fernschreiber-es.ts +++ b/translations/harbour-fernschreiber-es.ts @@ -1425,10 +1425,6 @@ Unavailable - - Stopped - - Starting @@ -1441,6 +1437,18 @@ Stopping + + Use recording + + + + Voice Note (%1) + + + + Ready + + WebPagePreview diff --git a/translations/harbour-fernschreiber-fi.ts b/translations/harbour-fernschreiber-fi.ts index cb1004c..e2eaba2 100644 --- a/translations/harbour-fernschreiber-fi.ts +++ b/translations/harbour-fernschreiber-fi.ts @@ -1447,10 +1447,6 @@ Unavailable - - Stopped - - Starting @@ -1463,6 +1459,18 @@ Stopping + + Use recording + + + + Voice Note (%1) + + + + Ready + + WebPagePreview diff --git a/translations/harbour-fernschreiber-hu.ts b/translations/harbour-fernschreiber-hu.ts index a160d2d..ed24a74 100644 --- a/translations/harbour-fernschreiber-hu.ts +++ b/translations/harbour-fernschreiber-hu.ts @@ -1425,10 +1425,6 @@ Unavailable - - Stopped - - Starting @@ -1441,6 +1437,18 @@ Stopping + + Use recording + + + + Voice Note (%1) + + + + Ready + + WebPagePreview diff --git a/translations/harbour-fernschreiber-it.ts b/translations/harbour-fernschreiber-it.ts index d0319bc..7bc968a 100644 --- a/translations/harbour-fernschreiber-it.ts +++ b/translations/harbour-fernschreiber-it.ts @@ -1446,10 +1446,6 @@ Unavailable - - Stopped - - Starting @@ -1462,6 +1458,18 @@ Stopping + + Use recording + + + + Voice Note (%1) + + + + Ready + + WebPagePreview diff --git a/translations/harbour-fernschreiber-pl.ts b/translations/harbour-fernschreiber-pl.ts index fc7f215..b6ba872 100644 --- a/translations/harbour-fernschreiber-pl.ts +++ b/translations/harbour-fernschreiber-pl.ts @@ -1467,10 +1467,6 @@ Unavailable - - Stopped - - Starting @@ -1483,6 +1479,18 @@ Stopping + + Use recording + + + + Voice Note (%1) + + + + Ready + + WebPagePreview diff --git a/translations/harbour-fernschreiber-ru.ts b/translations/harbour-fernschreiber-ru.ts index d3b4699..68f8e57 100644 --- a/translations/harbour-fernschreiber-ru.ts +++ b/translations/harbour-fernschreiber-ru.ts @@ -1467,10 +1467,6 @@ Unavailable - - Stopped - - Starting @@ -1483,6 +1479,18 @@ Stopping + + Use recording + + + + Voice Note (%1) + + + + Ready + + WebPagePreview diff --git a/translations/harbour-fernschreiber-sv.ts b/translations/harbour-fernschreiber-sv.ts index 0bbb2e4..81e5a0a 100644 --- a/translations/harbour-fernschreiber-sv.ts +++ b/translations/harbour-fernschreiber-sv.ts @@ -1446,10 +1446,6 @@ Unavailable - - Stopped - - Starting @@ -1462,6 +1458,18 @@ Stopping + + Use recording + + + + Voice Note (%1) + + + + Ready + + WebPagePreview diff --git a/translations/harbour-fernschreiber-zh_CN.ts b/translations/harbour-fernschreiber-zh_CN.ts index 437b5d8..fa3ccfe 100644 --- a/translations/harbour-fernschreiber-zh_CN.ts +++ b/translations/harbour-fernschreiber-zh_CN.ts @@ -1425,10 +1425,6 @@ Unavailable - - Stopped - - Starting @@ -1441,6 +1437,18 @@ Stopping + + Use recording + + + + Voice Note (%1) + + + + Ready + + WebPagePreview diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index 5664771..74e0ed6 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -1446,10 +1446,6 @@ Unavailable - - Stopped - - Starting @@ -1462,6 +1458,18 @@ Stopping + + Use recording + + + + Voice Note (%1) + + + + Ready + + WebPagePreview From be404d0e55eb6367c86338e37675afd848b3de22 Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Sat, 2 Jan 2021 18:08:33 +0100 Subject: [PATCH 4/8] Put attachment row in a Flickable --- qml/components/VoiceNoteOverlay.qml | 2 +- qml/pages/ChatPage.qml | 211 +++++++++++++++------------- 2 files changed, 116 insertions(+), 97 deletions(-) diff --git a/qml/components/VoiceNoteOverlay.qml b/qml/components/VoiceNoteOverlay.qml index 423bdfb..aed1e53 100644 --- a/qml/components/VoiceNoteOverlay.qml +++ b/qml/components/VoiceNoteOverlay.qml @@ -203,7 +203,7 @@ Item { } text: qsTr("Use recording") onClicked: { - attachmentOptionsRow.isNeeded = false; + attachmentOptionsFlickable.isNeeded = false; attachmentPreviewRow.isVoiceNote = true; attachmentPreviewRow.attachmentDescription = qsTr("Voice Note (%1)").arg(recordingDurationLabel.text); attachmentPreviewRow.visible = true; diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index b652072..91a1c37 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -1120,7 +1120,7 @@ Page { Debug.log("Sticker picked: " + stickerId); tdLibWrapper.sendStickerMessage(chatInformation.id, stickerId); stickerPickerLoader.active = false; - attachmentOptionsRow.isNeeded = false; + attachmentOptionsFlickable.isNeeded = false; } } @@ -1197,104 +1197,123 @@ Page { visible: false } - Row { - id: attachmentOptionsRow + Flickable { + id: attachmentOptionsFlickable + property bool isNeeded: false - visible: height > 0 - height: isNeeded ? implicitHeight : 0 - anchors.right: parent.right + + onIsNeededChanged: { + console.log("HÖHE: " + attachmentOptionsRow.height); + } + width: parent.width - layoutDirection: Qt.RightToLeft - spacing: Theme.paddingMedium - clip: true + height: isNeeded ? attachmentOptionsRow.height : 0 Behavior on height { SmoothedAnimation { duration: 200 } } - IconButton { - visible: chatPage.hasSendPrivilege("can_send_media_messages") - icon.source: "image://theme/icon-m-image" - onClicked: { - var picker = pageStack.push("Sailfish.Pickers.ImagePickerPage", { - allowedOrientations: chatPage.allowedOrientations - }) - picker.selectedContentPropertiesChanged.connect(function(){ - attachmentOptionsRow.isNeeded = false; - Debug.log("Selected document: ", picker.selectedContentProperties.filePath ); - attachmentPreviewRow.fileProperties = picker.selectedContentProperties; - attachmentPreviewRow.isPicture = true; - attachmentPreviewRow.visible = true; - controlSendButton(); - }) - } - } - IconButton { - visible: chatPage.hasSendPrivilege("can_send_media_messages") - icon.source: "image://theme/icon-m-video" - onClicked: { - var picker = pageStack.push("Sailfish.Pickers.VideoPickerPage", { - allowedOrientations: chatPage.allowedOrientations - }) - picker.selectedContentPropertiesChanged.connect(function(){ - attachmentOptionsRow.isNeeded = false; - Debug.log("Selected video: ", picker.selectedContentProperties.filePath ); - attachmentPreviewRow.fileProperties = picker.selectedContentProperties; - attachmentPreviewRow.isVideo = true; - attachmentPreviewRow.visible = true; - controlSendButton(); - }) - } - } - IconButton { - visible: chatPage.hasSendPrivilege("can_send_media_messages") - icon.source: "image://theme/icon-m-mic" - icon.sourceSize { - width: Theme.iconSizeMedium - height: Theme.iconSizeMedium - } - highlighted: down || voiceNoteOverlayLoader.active - onClicked: { - voiceNoteOverlayLoader.active = !voiceNoteOverlayLoader.active; - stickerPickerLoader.active = false; - } - } - IconButton { - visible: chatPage.hasSendPrivilege("can_send_media_messages") - icon.source: "image://theme/icon-m-document" - onClicked: { - var picker = pageStack.push("Sailfish.Pickers.FilePickerPage", { - allowedOrientations: chatPage.allowedOrientations - }) - picker.selectedContentPropertiesChanged.connect(function(){ - attachmentOptionsRow.isNeeded = false; - Debug.log("Selected document: ", picker.selectedContentProperties.filePath ); - attachmentPreviewRow.fileProperties = picker.selectedContentProperties; - attachmentPreviewRow.isDocument = true; - attachmentPreviewRow.visible = true; - controlSendButton(); - }) - } - } - IconButton { - visible: chatPage.hasSendPrivilege("can_send_other_messages") - icon.source: "../../images/icon-m-sticker.svg" - icon.sourceSize { - width: Theme.iconSizeMedium - height: Theme.iconSizeMedium - } - highlighted: down || stickerPickerLoader.active - onClicked: { - stickerPickerLoader.active = !stickerPickerLoader.active; - voiceNoteOverlayLoader.active = false; - } - } - IconButton { - visible: !(chatPage.isPrivateChat || chatPage.isSecretChat) && chatPage.hasSendPrivilege("can_send_polls") - icon.source: "image://theme/icon-m-question" - onClicked: { - pageStack.push(Qt.resolvedUrl("../pages/PollCreationPage.qml"), { "chatId" : chatInformation.id, groupName: chatInformation.title}); - attachmentOptionsRow.isNeeded = false; + visible: height > 0 + contentHeight: attachmentOptionsRow.height + contentWidth: Math.max(parent.width, attachmentOptionsRow.width) + clip: true + + Row { + id: attachmentOptionsRow + + height: attachImageIconButton.height + + anchors.right: parent.right + layoutDirection: Qt.RightToLeft + spacing: Theme.paddingMedium + + IconButton { + id: attachImageIconButton + visible: chatPage.hasSendPrivilege("can_send_media_messages") + icon.source: "image://theme/icon-m-image" + onClicked: { + var picker = pageStack.push("Sailfish.Pickers.ImagePickerPage", { + allowedOrientations: chatPage.allowedOrientations + }) + picker.selectedContentPropertiesChanged.connect(function(){ + attachmentOptionsFlickable.isNeeded = false; + Debug.log("Selected document: ", picker.selectedContentProperties.filePath ); + attachmentPreviewRow.fileProperties = picker.selectedContentProperties; + attachmentPreviewRow.isPicture = true; + attachmentPreviewRow.visible = true; + controlSendButton(); + }) + } + } + IconButton { + visible: chatPage.hasSendPrivilege("can_send_media_messages") + icon.source: "image://theme/icon-m-video" + onClicked: { + var picker = pageStack.push("Sailfish.Pickers.VideoPickerPage", { + allowedOrientations: chatPage.allowedOrientations + }) + picker.selectedContentPropertiesChanged.connect(function(){ + attachmentOptionsFlickable.isNeeded = false; + Debug.log("Selected video: ", picker.selectedContentProperties.filePath ); + attachmentPreviewRow.fileProperties = picker.selectedContentProperties; + attachmentPreviewRow.isVideo = true; + attachmentPreviewRow.visible = true; + controlSendButton(); + }) + } + } + IconButton { + visible: chatPage.hasSendPrivilege("can_send_media_messages") + icon.source: "image://theme/icon-m-mic" + icon.sourceSize { + width: Theme.iconSizeMedium + height: Theme.iconSizeMedium + } + highlighted: down || voiceNoteOverlayLoader.active + onClicked: { + voiceNoteOverlayLoader.active = !voiceNoteOverlayLoader.active; + stickerPickerLoader.active = false; + } + } + IconButton { + visible: chatPage.hasSendPrivilege("can_send_media_messages") + icon.source: "image://theme/icon-m-document" + onClicked: { + var picker = pageStack.push("Sailfish.Pickers.FilePickerPage", { + allowedOrientations: chatPage.allowedOrientations + }) + picker.selectedContentPropertiesChanged.connect(function(){ + attachmentOptionsFlickable.isNeeded = false; + Debug.log("Selected document: ", picker.selectedContentProperties.filePath ); + attachmentPreviewRow.fileProperties = picker.selectedContentProperties; + attachmentPreviewRow.isDocument = true; + attachmentPreviewRow.visible = true; + controlSendButton(); + }) + } + } + IconButton { + visible: chatPage.hasSendPrivilege("can_send_other_messages") + icon.source: "../../images/icon-m-sticker.svg" + icon.sourceSize { + width: Theme.iconSizeMedium + height: Theme.iconSizeMedium + } + highlighted: down || stickerPickerLoader.active + onClicked: { + stickerPickerLoader.active = !stickerPickerLoader.active; + voiceNoteOverlayLoader.active = false; + } + } + IconButton { + visible: !(chatPage.isPrivateChat || chatPage.isSecretChat) && chatPage.hasSendPrivilege("can_send_polls") + icon.source: "image://theme/icon-m-question" + onClicked: { + pageStack.push(Qt.resolvedUrl("../pages/PollCreationPage.qml"), { "chatId" : chatInformation.id, groupName: chatInformation.title}); + attachmentOptionsFlickable.isNeeded = false; + } } } + } + Row { id: attachmentPreviewRow visible: false @@ -1564,17 +1583,17 @@ Page { IconButton { id: attachmentIconButton - icon.source: "image://theme/icon-m-attach?" + (attachmentOptionsRow.isNeeded ? Theme.highlightColor : Theme.primaryColor) + icon.source: "image://theme/icon-m-attach?" + (attachmentOptionsFlickable.isNeeded ? Theme.highlightColor : Theme.primaryColor) anchors.bottom: parent.bottom anchors.bottomMargin: Theme.paddingSmall enabled: !attachmentPreviewRow.visible onClicked: { - if (attachmentOptionsRow.isNeeded) { - attachmentOptionsRow.isNeeded = false; + if (attachmentOptionsFlickable.isNeeded) { + attachmentOptionsFlickable.isNeeded = false; stickerPickerLoader.active = false; voiceNoteOverlayLoader.active = false; } else { - attachmentOptionsRow.isNeeded = true; + attachmentOptionsFlickable.isNeeded = true; } } } From 1b83fddfe6166dc70e1406acd1b1c3ee27cdc548 Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Sat, 2 Jan 2021 19:57:36 +0100 Subject: [PATCH 5/8] No strange debug logging ;) --- qml/pages/ChatPage.qml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index 91a1c37..0cb5641 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -1202,10 +1202,6 @@ Page { property bool isNeeded: false - onIsNeededChanged: { - console.log("HÖHE: " + attachmentOptionsRow.height); - } - width: parent.width height: isNeeded ? attachmentOptionsRow.height : 0 Behavior on height { SmoothedAnimation { duration: 200 } } From 2b634471dcf8bebef8a184473c4ed56ffecb7a1a Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Sun, 3 Jan 2021 01:22:30 +0100 Subject: [PATCH 6/8] Sending locations seems to work as well... --- harbour-fernschreiber.pro | 2 +- qml/pages/ChatPage.qml | 45 +++++++++++++++-- src/fernschreiberutils.cpp | 54 +++++++++++++++++++++ src/fernschreiberutils.h | 9 ++++ src/tdlibwrapper.cpp | 26 ++++++++++ src/tdlibwrapper.h | 1 + translations/harbour-fernschreiber-de.ts | 8 +++ translations/harbour-fernschreiber-en.ts | 8 +++ translations/harbour-fernschreiber-es.ts | 8 +++ translations/harbour-fernschreiber-fi.ts | 8 +++ translations/harbour-fernschreiber-hu.ts | 8 +++ translations/harbour-fernschreiber-it.ts | 8 +++ translations/harbour-fernschreiber-pl.ts | 8 +++ translations/harbour-fernschreiber-ru.ts | 8 +++ translations/harbour-fernschreiber-sv.ts | 8 +++ translations/harbour-fernschreiber-zh_CN.ts | 8 +++ translations/harbour-fernschreiber.ts | 8 +++ 17 files changed, 220 insertions(+), 5 deletions(-) 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 From 81ffb53062d2e3f8b42723760b4ece886083d1a2 Mon Sep 17 00:00:00 2001 From: John Gibbon Date: Sun, 3 Jan 2021 22:32:26 +0100 Subject: [PATCH 7/8] Use OpacityRamp to hint at scrollable attachmentsOptions --- qml/pages/ChatPage.qml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index c320ab5..6999863 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -1174,7 +1174,6 @@ Page { spacing: Theme.paddingSmall topPadding: Theme.paddingSmall anchors.horizontalCenter: parent.horizontalCenter - clip: true visible: height > 0 width: parent.width - ( 2 * Theme.horizontalPageMargin ) height: isNeeded ? implicitHeight : 0 @@ -1210,13 +1209,23 @@ Page { id: attachmentOptionsFlickable property bool isNeeded: false - width: parent.width + width: chatPage.width + x: -Theme.horizontalPageMargin height: isNeeded ? attachmentOptionsRow.height : 0 Behavior on height { SmoothedAnimation { duration: 200 } } visible: height > 0 contentHeight: attachmentOptionsRow.height - contentWidth: Math.max(parent.width, attachmentOptionsRow.width) - clip: true + contentWidth: Math.max(width, attachmentOptionsRow.width) + property bool fadeRight: (attachmentOptionsRow.width-contentX) > width + property bool fadeLeft: !fadeRight && contentX > 0 + layer.enabled: fadeRight || fadeLeft + layer.effect: OpacityRampEffectBase { + direction: attachmentOptionsFlickable.fadeRight ? OpacityRamp.LeftToRight : OpacityRamp.RightToLeft + source: attachmentOptionsFlickable + slope: 1 + 6 * (chatPage.width) / Screen.width + offset: 1 - 1 / slope + } + Row { id: attachmentOptionsRow @@ -1226,6 +1235,8 @@ Page { anchors.right: parent.right layoutDirection: Qt.RightToLeft spacing: Theme.paddingMedium + leftPadding: Theme.horizontalPageMargin + rightPadding: Theme.horizontalPageMargin IconButton { id: attachImageIconButton From e0b94a04878fa82394d481ee1b13d2c430edbc0d Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Mon, 4 Jan 2021 22:03:04 +0100 Subject: [PATCH 8/8] One dedicated file per voice note recording --- qml/components/VoiceNoteOverlay.qml | 3 +++ src/fernschreiberutils.cpp | 26 +++++++++++++++++++------- src/fernschreiberutils.h | 1 + 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/qml/components/VoiceNoteOverlay.qml b/qml/components/VoiceNoteOverlay.qml index aed1e53..cbec5a9 100644 --- a/qml/components/VoiceNoteOverlay.qml +++ b/qml/components/VoiceNoteOverlay.qml @@ -151,6 +151,9 @@ Item { anchors.fill: parent onClicked: { recordButton.visible = false; + recordingDone = false; + recordingDuration = 0; + handleRecordingDuration(); fernschreiberUtils.startRecordingVoiceNote(); } } diff --git a/src/fernschreiberutils.cpp b/src/fernschreiberutils.cpp index 5542cf4..3237982 100644 --- a/src/fernschreiberutils.cpp +++ b/src/fernschreiberutils.cpp @@ -23,8 +23,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -35,7 +37,7 @@ FernschreiberUtils::FernschreiberUtils(QObject *parent) : QObject(parent) { LOG("Initializing audio recorder..."); - QString temporaryDirectoryPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + + "/harbour-fernschreiber"; + QString temporaryDirectoryPath = this->getTemporaryDirectoryPath(); QDir temporaryDirectory(temporaryDirectoryPath); if (!temporaryDirectory.exists()) { temporaryDirectory.mkpath(temporaryDirectoryPath); @@ -47,7 +49,6 @@ FernschreiberUtils::FernschreiberUtils(QObject *parent) : QObject(parent) encoderSettings.setQuality(QMultimedia::LowQuality); this->audioRecorder.setEncodingSettings(encoderSettings); this->audioRecorder.setContainerFormat("ogg"); - this->audioRecorder.setOutputLocation(QUrl::fromLocalFile(temporaryDirectoryPath + "/voicenote.ogg")); QMediaRecorder::Status audioRecorderStatus = this->audioRecorder.status(); this->handleAudioRecorderStatusChanged(audioRecorderStatus); @@ -194,7 +195,8 @@ QString FernschreiberUtils::getUserName(const QVariantMap &userInformation) void FernschreiberUtils::startRecordingVoiceNote() { LOG("Start recording voice note..."); - this->cleanUp(); + QDateTime thisIsNow = QDateTime::currentDateTime(); + this->audioRecorder.setOutputLocation(QUrl::fromLocalFile(this->getTemporaryDirectoryPath() + "/voicenote-" + thisIsNow.toString("yyyy-MM-dd-HH-mm-ss") + ".ogg")); this->audioRecorder.setVolume(1); this->audioRecorder.record(); } @@ -287,9 +289,19 @@ void FernschreiberUtils::cleanUp() if (this->geoPositionInfoSource) { this->geoPositionInfoSource->stopUpdates(); } - QString voiceNotePath = this->voiceNotePath(); - if (QFile::exists(voiceNotePath)) { - LOG("Removing old temporary file..."); - QFile::remove(voiceNotePath); + QString temporaryDirectoryPath = this->getTemporaryDirectoryPath(); + QDirIterator temporaryDirectoryIterator(temporaryDirectoryPath, QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks, QDirIterator::Subdirectories); + while (temporaryDirectoryIterator.hasNext()) { + QString nextFilePath = temporaryDirectoryIterator.next(); + if (QFile::remove(nextFilePath)) { + LOG("Temporary file removed " << nextFilePath); + } else { + LOG("Error removing temporary file " << nextFilePath); + } } } + +QString FernschreiberUtils::getTemporaryDirectoryPath() +{ + return QStandardPaths::writableLocation(QStandardPaths::TempLocation) + + "/harbour-fernschreiber"; +} diff --git a/src/fernschreiberutils.h b/src/fernschreiberutils.h index 6c7f043..ce3bc3b 100644 --- a/src/fernschreiberutils.h +++ b/src/fernschreiberutils.h @@ -69,6 +69,7 @@ private: QGeoPositionInfoSource *geoPositionInfoSource; void cleanUp(); + QString getTemporaryDirectoryPath(); };