diff options
author | Robert C. Helling <helling@atdotde.de> | 2019-04-14 16:19:23 +0200 |
---|---|---|
committer | bstoeger <32835590+bstoeger@users.noreply.github.com> | 2019-04-16 20:38:19 +0200 |
commit | 52105e521720c87e64dbd2519be7bbe5dc243439 (patch) | |
tree | c8483c1d7163a9bf6b40b6f984467ccfd549c7d9 /desktop-widgets/tab-widgets | |
parent | 0573b19b653d0b4963fe11efdc2303289d2b7994 (diff) | |
download | subsurface-52105e521720c87e64dbd2519be7bbe5dc243439.tar.gz |
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 <helling@atdotde.de>
Diffstat (limited to 'desktop-widgets/tab-widgets')
-rw-r--r-- | desktop-widgets/tab-widgets/TabDivePhotos.cpp | 37 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/TabDivePhotos.h | 1 |
2 files changed, 38 insertions, 0 deletions
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 <QUrl> #include <QMessageBox> #include <QFileInfo> +#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<QString> 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; |