From 56630457603ff5340cd47a2d8c6f217def9f4474 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Wed, 26 Jul 2023 09:20:41 +0200 Subject: [PATCH] Display thumbnails on VFS. Delete exported file after being read. --- .../src/components/other/images/ImageModel.cpp | 16 ++++++++++++---- .../src/components/other/images/ImageModel.hpp | 2 +- .../other/images/VideoFrameGrabber.cpp | 8 +++++++- .../other/images/VideoFrameGrabber.hpp | 4 +++- linphone-app/src/utils/Utils.cpp | 2 +- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/linphone-app/src/components/other/images/ImageModel.cpp b/linphone-app/src/components/other/images/ImageModel.cpp index 3ecc417e4..53aad3eab 100644 --- a/linphone-app/src/components/other/images/ImageModel.cpp +++ b/linphone-app/src/components/other/images/ImageModel.cpp @@ -121,22 +121,30 @@ QImage ImageModel::createThumbnail(const QString& path, QImage originalImage){ return thumbnail; } -void ImageModel::retrieveImageAsync(const QString& path, VideoFrameGrabberListener* requester){ +void ImageModel::retrieveImageAsync(QString path, VideoFrameGrabberListener* requester){ QImage thumbnail; if(QFileInfo(path).isFile()){ + bool removeExportedFile = CoreManager::getInstance()->getSettingsModel()->getVfsEncrypted(); + if(removeExportedFile) { + std::shared_ptr content = linphone::Factory::get()->createContentFromFile(Utils::appStringToCoreString(path)); + path = Utils::coreStringToAppString(content->exportPlainFile()); + } QImage originalImage(path); if( originalImage.isNull()){// Try to determine format from headers QImageReader reader(path); reader.setDecideFormatFromContent(true); QByteArray format = reader.format(); - if(!format.isEmpty()) + if(!format.isEmpty()){ originalImage = QImage(path, format); - else if(Utils::isVideo(path)){ - VideoFrameGrabber *grabber = new VideoFrameGrabber(); + }else if(Utils::isVideo(path)){ + VideoFrameGrabber *grabber = new VideoFrameGrabber(removeExportedFile); + removeExportedFile = false; connect(grabber, &VideoFrameGrabber::grabFinished, requester, &VideoFrameGrabberListener::imageGrabbed); grabber->requestFrame(path); } } + if(removeExportedFile) + QFile(path).remove(); if(!originalImage.isNull()){ emit requester->imageGrabbed(originalImage); } diff --git a/linphone-app/src/components/other/images/ImageModel.hpp b/linphone-app/src/components/other/images/ImageModel.hpp index dce74b17b..6cf14220a 100644 --- a/linphone-app/src/components/other/images/ImageModel.hpp +++ b/linphone-app/src/components/other/images/ImageModel.hpp @@ -52,7 +52,7 @@ public: Q_INVOKABLE void setUrl(const QUrl& url); static QImage createThumbnail(const QString& path, QImage originalImage); // Build the thumbnail from an image. - static void retrieveImageAsync(const QString& path, VideoFrameGrabberListener* requester); // Get an image from the path. When it is ready, the signal imageGrabbed() is send to the listener. It can be direct if this is not a media file. + static void retrieveImageAsync(QString path, VideoFrameGrabberListener* requester); // Get an image from the path. When it is ready, the signal imageGrabbed() is send to the listener. It can be direct if this is not a media file. signals: void pathChanged(); diff --git a/linphone-app/src/components/other/images/VideoFrameGrabber.cpp b/linphone-app/src/components/other/images/VideoFrameGrabber.cpp index ec828c923..be13cecd1 100644 --- a/linphone-app/src/components/other/images/VideoFrameGrabber.cpp +++ b/linphone-app/src/components/other/images/VideoFrameGrabber.cpp @@ -21,12 +21,14 @@ #include "VideoFrameGrabber.hpp" #include +#include VideoFrameGrabberListener::VideoFrameGrabberListener(){ } -VideoFrameGrabber::VideoFrameGrabber( QObject *parent) +VideoFrameGrabber::VideoFrameGrabber(bool deleteFile, QObject *parent) : QAbstractVideoSurface(parent){ + mDeleteFile = deleteFile; QObject::connect(&player, QOverload::of(&QMediaPlayer::error), this, [this](QMediaPlayer::Error error) mutable{ end(); }, Qt::DirectConnection); @@ -59,6 +61,10 @@ VideoFrameGrabber::VideoFrameGrabber( QObject *parent) player.setVideoOutput(this); } +VideoFrameGrabber::~VideoFrameGrabber(){ + if(mDeleteFile) + QFile(mPath).remove(); +} void VideoFrameGrabber::requestFrame(const QString& path){ mLoadedMedia = false; diff --git a/linphone-app/src/components/other/images/VideoFrameGrabber.hpp b/linphone-app/src/components/other/images/VideoFrameGrabber.hpp index e7e0fc8d8..e65488319 100644 --- a/linphone-app/src/components/other/images/VideoFrameGrabber.hpp +++ b/linphone-app/src/components/other/images/VideoFrameGrabber.hpp @@ -38,7 +38,8 @@ signals: class VideoFrameGrabber : public QAbstractVideoSurface { Q_OBJECT public: - VideoFrameGrabber(QObject *parent = 0); + VideoFrameGrabber(bool deleteFile = false, QObject *parent = 0); + ~VideoFrameGrabber(); void requestFrame(const QString& path); // Function to call. @@ -55,6 +56,7 @@ public: QMediaPlayer player; bool mLoadedMedia = false; bool mResultSent = false; + bool mDeleteFile = false; QString mPath; QImage mResult; diff --git a/linphone-app/src/utils/Utils.cpp b/linphone-app/src/utils/Utils.cpp index 23f2d0a6b..e758f3af1 100644 --- a/linphone-app/src/utils/Utils.cpp +++ b/linphone-app/src/utils/Utils.cpp @@ -613,7 +613,7 @@ bool Utils::isAnimatedImage(const QString& path){ bool Utils::isImage(const QString& path){ if(path.isEmpty()) return false; QFileInfo info(path); - if( !info.exists()){ + if( !info.exists() || CoreManager::getInstance()->getSettingsModel()->getVfsEncrypted()){ return QMimeDatabase().mimeTypeForFile(info, QMimeDatabase::MatchExtension).name().contains("image/"); }else if(!QMimeDatabase().mimeTypeForFile(info).name().contains("image/")) return false;