mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-05-07 05:23:06 +00:00
Display thumbnails on VFS. Delete exported file after being read.
This commit is contained in:
parent
9f9b624abd
commit
5663045760
5 changed files with 24 additions and 8 deletions
|
|
@ -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<linphone::Content> 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -21,12 +21,14 @@
|
|||
#include "VideoFrameGrabber.hpp"
|
||||
|
||||
#include <QVideoSurfaceFormat>
|
||||
#include <QFile>
|
||||
|
||||
VideoFrameGrabberListener::VideoFrameGrabberListener(){
|
||||
}
|
||||
|
||||
VideoFrameGrabber::VideoFrameGrabber( QObject *parent)
|
||||
VideoFrameGrabber::VideoFrameGrabber(bool deleteFile, QObject *parent)
|
||||
: QAbstractVideoSurface(parent){
|
||||
mDeleteFile = deleteFile;
|
||||
QObject::connect(&player, QOverload<QMediaPlayer::Error>::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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue