From 060341adb7b512e0eef454612a95e04bb6fadc40 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Sat, 1 Apr 2023 07:02:42 -0500 Subject: [PATCH] video_thumbnail works to be set in rust Since every slide is asking for their own, we don't need to loop through all slides, we just use the index to put the thumbnail into the right slides and emit data changed. --- src/cpp/slidemodel.cpp | 45 +++++++++++++++++++ src/cpp/slidemodel.h | 1 + .../presenter/PreviewSlideListDelegate.qml | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/cpp/slidemodel.cpp b/src/cpp/slidemodel.cpp index ab72fe5..78fe3a7 100644 --- a/src/cpp/slidemodel.cpp +++ b/src/cpp/slidemodel.cpp @@ -700,6 +700,51 @@ void SlideModel::moveRowFromService(const int &fromIndex, } } +QString SlideModel::thumbnailVideoRust(QString video, int serviceItemId, int index, SlideyMod *slideModel) { + + QDir dir = writeDir.absolutePath() + "/librepresenter/thumbnails"; + QDir absDir = writeDir.absolutePath() + "/librepresenter"; + if (!dir.exists()) { + qDebug() << dir.path() << "does not exist"; + absDir.mkdir("thumbnails"); + } + + QFileInfo vid(video); + QString id; + id.setNum(serviceItemId); + QString vidName(vid.fileName() + "-" + id); + qDebug() << vidName; + QString thumbnail = dir.path() + "/" + vidName + ".webp"; + QFileInfo thumbnailInfo(dir.path() + "/" + vidName + ".jpg"); + qDebug() << thumbnailInfo.filePath() << "FOR" << index; + if (thumbnailInfo.exists()) { + slideModel->addVideoThumbnail("file://" + thumbnailInfo.absoluteFilePath(), serviceItemId, index); + return thumbnailInfo.filePath(); + } + + + QImage image; + QString filename = video.right(video.size() - 7); + image = frameToImage(filename, 576); + if (image.isNull()) { + qDebug() << QStringLiteral("Failed to create thumbnail for file: %1").arg(video); + return "failed"; + } + + qDebug() << "dir location " << writeDir.absolutePath(); + if (!writeDir.mkpath(".")) { + qFatal("Failed to create writable location at %s", qPrintable(writeDir.absolutePath())); + } + + if (!image.save(thumbnailInfo.filePath())) { + qDebug() << QStringLiteral("Failed to save thumbnail for file: %1").arg(video); + } + + slideModel->addVideoThumbnail("file://" + thumbnailInfo.absoluteFilePath(), serviceItemId, index); + + return thumbnailInfo.filePath(); +} + QString SlideModel::thumbnailVideo(QString video, int serviceItemId, int index) { QDir dir = writeDir.absolutePath() + "/librepresenter/thumbnails"; diff --git a/src/cpp/slidemodel.h b/src/cpp/slidemodel.h index 00e3283..b0c8889 100644 --- a/src/cpp/slidemodel.h +++ b/src/cpp/slidemodel.h @@ -86,6 +86,7 @@ public: Q_INVOKABLE QVariantList getItems(); Q_INVOKABLE int findSlideIdFromServItm(int index); Q_INVOKABLE QString thumbnailVideo(QString video, int serviceItemId, int index); + Q_INVOKABLE QString thumbnailVideoRust(QString video, int serviceItemId, int index, SlideyMod *slideModel); QImage frameToImage(const QString &video, int width); diff --git a/src/qml/presenter/PreviewSlideListDelegate.qml b/src/qml/presenter/PreviewSlideListDelegate.qml index 50b49ee..86cc903 100644 --- a/src/qml/presenter/PreviewSlideListDelegate.qml +++ b/src/qml/presenter/PreviewSlideListDelegate.qml @@ -12,7 +12,7 @@ Item { property bool showVidBG Component.onCompleted: { if (model.videoBackground != "") - SlideModel.thumbnailVideo(model.videoBackground, model.serviceItemId, index); + SlideModel.thumbnailVideoRust(model.videoBackground, model.serviceItemId, index, SlideMod); } Rectangle {