From 52105e521720c87e64dbd2519be7bbe5dc243439 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Sun, 14 Apr 2019 16:19:23 +0200 Subject: Write dive data as video subtitles This commit adds an entry to the dive media context menu which offers to write a subtitle file. This creates an .ass file for the selected videos. In an attempt to to clutter the screen too much, don't show irrelevant entries (zero temperature or NDL and show TTS only for dives with stops). VLC is able to show these subtitles directly, they can be integrated into the video file with ffmpeg. Signed-off-by: Robert C. Helling --- desktop-widgets/tab-widgets/TabDivePhotos.cpp | 37 +++++++++++++++++++++++++++ desktop-widgets/tab-widgets/TabDivePhotos.h | 1 + 2 files changed, 38 insertions(+) (limited to 'desktop-widgets/tab-widgets') diff --git a/desktop-widgets/tab-widgets/TabDivePhotos.cpp b/desktop-widgets/tab-widgets/TabDivePhotos.cpp index de65f2e89..fc84e1972 100644 --- a/desktop-widgets/tab-widgets/TabDivePhotos.cpp +++ b/desktop-widgets/tab-widgets/TabDivePhotos.cpp @@ -11,6 +11,8 @@ #include #include #include +#include "core/save-profiledata.h" +#include "core/membuffer.h" //TODO: Remove those in the future. #include "../mainwindow.h" @@ -57,6 +59,7 @@ void TabDivePhotos::contextMenuEvent(QContextMenuEvent *event) popup.addAction(tr("Delete all media files"), this, SLOT(removeAllPhotos())); popup.addAction(tr("Open folder of selected media files"), this, SLOT(openFolderOfSelectedFiles())); popup.addAction(tr("Recalculate selected thumbnails"), this, SLOT(recalculateSelectedThumbnails())); + popup.addAction(tr("Save dive data as subtitles"), this, SLOT(saveSubtitles())); popup.exec(event->globalPos()); event->accept(); } @@ -106,6 +109,40 @@ void TabDivePhotos::recalculateSelectedThumbnails() Thumbnailer::instance()->calculateThumbnails(getSelectedFilenames()); } +void TabDivePhotos::saveSubtitles() +{ + QVector selectedPhotos; + if (!ui->photosView->selectionModel()->hasSelection()) + return; + QModelIndexList indexes = ui->photosView->selectionModel()->selectedRows(); + if (indexes.count() == 0) + indexes = ui->photosView->selectionModel()->selectedIndexes(); + selectedPhotos.reserve(indexes.count()); + for (const auto &photo: indexes) { + if (photo.isValid()) { + QString fileUrl = photo.data(Qt::DisplayPropertyRole).toString(); + if (!fileUrl.isEmpty()) { + QFileInfo fi = QFileInfo(fileUrl); + QFile subtitlefile; + subtitlefile.setFileName(QString(fi.path()) + "/" + fi.completeBaseName() + ".ass"); + int offset = photo.data(Qt::UserRole + 1).toInt(); + int duration = photo.data(Qt::UserRole + 2).toInt(); + // Only videos have non-zero duration + if (!duration) + continue; + struct membuffer b = { 0 }; + save_subtitles_buffer(&b, &displayed_dive, offset, duration); + char *data = detach_buffer(&b); + subtitlefile.open(QIODevice::WriteOnly); + subtitlefile.write(data, strlen(data)); + subtitlefile.close(); + free(data); + } + + } + } +} + //TODO: This looks overly wrong. We shouldn't call MainWindow to retrieve the DiveList to add Images. void TabDivePhotos::addPhotosFromFile() { diff --git a/desktop-widgets/tab-widgets/TabDivePhotos.h b/desktop-widgets/tab-widgets/TabDivePhotos.h index f172df180..1078e1ca2 100644 --- a/desktop-widgets/tab-widgets/TabDivePhotos.h +++ b/desktop-widgets/tab-widgets/TabDivePhotos.h @@ -29,6 +29,7 @@ private slots: void recalculateSelectedThumbnails(); void openFolderOfSelectedFiles(); void changeZoomLevel(int delta); + void saveSubtitles(); private: Ui::TabDivePhotos *ui; -- cgit v1.2.3-70-g09d2