From e0b94a04878fa82394d481ee1b13d2c430edbc0d Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Mon, 4 Jan 2021 22:03:04 +0100 Subject: [PATCH] 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(); };