MauiKit File Browsing

thumbnailer.cpp
1#include "thumbnailer.h"
2
3#ifdef KIO_AVAILABLE
4#include <KIO/PreviewJob>
5#endif
6
7#include <QDebug>
8#include <QImage>
9#include <QGuiApplication>
10
11QQuickImageResponse *Thumbnailer::requestImageResponse(const QString &id, const QSize &requestedSize)
12{
13 AsyncImageResponse *response = new AsyncImageResponse(id, requestedSize);
14 return response;
15}
16
17AsyncImageResponse::AsyncImageResponse(const QString &id, const QSize &requestedSize)
18 : m_id(id)
19 , m_requestedSize(requestedSize)
20{
21#ifdef KIO_AVAILABLE
22 KIO::PreviewJob::setDefaultDevicePixelRatio(qApp->devicePixelRatio());
24 // qDebug() << plugins << KIO::PreviewJob::defaultPlugins();
25 auto job = new KIO::PreviewJob(KFileItemList() << KFileItem(QUrl::fromUserInput(id)), requestedSize, &plugins);
26
28 m_image = pixmap.toImage();
29 Q_EMIT this->finished();
30 });
31
33 m_error = QStringLiteral("Thumbnail Previewer job failed");
34 this->cancel();
35 Q_EMIT this->finished();
36 });
37
38 job->start();
39#endif
40}
41
42QQuickTextureFactory *AsyncImageResponse::textureFactory() const
43{
45}
46
47QString AsyncImageResponse::errorString() const
48{
49 return m_error;
50}
static QStringList availablePlugins()
void failed(const KFileItem &item)
void gotPreview(const KFileItem &item, const QPixmap &preview)
static void setDefaultDevicePixelRatio(qreal devicePixelRatio)
KGuiItem cancel()
QImage toImage() const const
QQuickTextureFactory * textureFactoryForImage(const QImage &image)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QUrl fromUserInput(const QString &userInput, const QString &workingDirectory, UserInputResolutionOptions options)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:32:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.