File indexing completed on 2025-01-19 03:41:35
0001 // -*- c++ -*- 0002 /* 0003 This file is part of the KDE libraries 0004 SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org> 0005 SPDX-FileCopyrightText: 2000 Carsten Pfeiffer <pfeiffer@kde.org> 0006 SPDX-FileCopyrightText: 2001 Malte Starostik <malte.starostik@t-online.de> 0007 0008 SPDX-License-Identifier: LGPL-2.0-or-later 0009 */ 0010 0011 #ifndef KIO_PREVIEWJOB_H 0012 #define KIO_PREVIEWJOB_H 0013 0014 #include "kiogui_export.h" 0015 #include <kfileitem.h> 0016 #include <kio/job.h> 0017 0018 class QPixmap; 0019 class KPluginMetaData; 0020 0021 namespace KIO 0022 { 0023 class PreviewJobPrivate; 0024 /*! 0025 * @class KIO::PreviewJob previewjob.h <KIO/PreviewJob> 0026 * 0027 * This class catches a preview (thumbnail) for files. 0028 * @short KIO Job to get a thumbnail picture 0029 */ 0030 class KIOGUI_EXPORT PreviewJob : public KIO::Job 0031 { 0032 Q_OBJECT 0033 public: 0034 /** 0035 * Specifies the type of scaling that is applied to the generated preview. 0036 * For HiDPI, pixel density scaling, @see setDevicePixelRatio 0037 * 0038 */ 0039 enum ScaleType { 0040 /** 0041 * The original size of the preview will be returned. Most previews 0042 * will return a size of 256 x 256 pixels. 0043 */ 0044 Unscaled, 0045 /** 0046 * The preview will be scaled to the size specified when constructing 0047 * the PreviewJob. The aspect ratio will be kept. 0048 */ 0049 Scaled, 0050 /** 0051 * The preview will be scaled to the size specified when constructing 0052 * the PreviewJob. The result will be cached for later use. Per default 0053 * ScaledAndCached is set. 0054 */ 0055 ScaledAndCached, 0056 }; 0057 0058 /** 0059 * @param items List of files to create previews for. 0060 * @param size Desired size of the preview. 0061 * @param enabledPlugins If non-zero it defines the list of plugins that 0062 * are considered for generating the preview. If 0063 * enabledPlugins is zero the plugins specified in the 0064 * KConfigGroup "PreviewSettings" are used. 0065 */ 0066 PreviewJob(const KFileItemList &items, const QSize &size, const QStringList *enabledPlugins = nullptr); 0067 0068 ~PreviewJob() override; 0069 0070 /** 0071 * Sets the scale type for the generated preview. Per default 0072 * PreviewJob::ScaledAndCached is set. 0073 * @see PreviewJob::ScaleType 0074 */ 0075 void setScaleType(ScaleType type); 0076 0077 /** 0078 * @return The scale type for the generated preview. 0079 * @see PreviewJob::ScaleType 0080 */ 0081 ScaleType scaleType() const; 0082 0083 /** 0084 * Removes an item from preview processing. Use this if you passed 0085 * an item to filePreview and want to delete it now. 0086 * 0087 * @param url the url of the item that should be removed from the preview queue 0088 */ 0089 void removeItem(const QUrl &url); 0090 0091 /** 0092 * If @p ignoreSize is true, then the preview is always 0093 * generated regardless of the settings 0094 **/ 0095 void setIgnoreMaximumSize(bool ignoreSize = true); 0096 0097 /** 0098 * Sets the sequence index given to the thumb creators. 0099 * Use the sequence index, it is possible to create alternative 0100 * icons for the same item. For example it may allow iterating through 0101 * the items of a directory, or the frames of a video. 0102 * 0103 **/ 0104 void setSequenceIndex(int index); 0105 0106 /** 0107 * Returns the currently set sequence index 0108 * 0109 **/ 0110 int sequenceIndex() const; 0111 0112 /** 0113 * Returns the index at which the thumbs of a ThumbSequenceCreator start 0114 * wrapping around ("looping"). Fractional values may be returned if the 0115 * ThumbSequenceCreator supports sub-integer precision, but frontends 0116 * supporting only integer sequence indices may choose to round it down. 0117 * 0118 * @see ThumbSequenceCreator::sequenceIndexWraparoundPoint() 0119 * @since 5.80 0120 */ 0121 float sequenceIndexWraparoundPoint() const; 0122 0123 /** 0124 * Determines whether the ThumbCreator in use is a ThumbSequenceCreator. 0125 * 0126 * @since 5.80 0127 */ 0128 bool handlesSequences() const; 0129 0130 /** 0131 * Request preview to use the device pixel ratio @p dpr. 0132 * The returned thumbnail may not respect the device pixel ratio requested. 0133 * Use QPixmap::devicePixelRatio to check, or paint as necessary. 0134 * 0135 * @since 5.84 0136 */ 0137 void setDevicePixelRatio(qreal dpr); 0138 0139 /** 0140 * Returns a list of all available preview plugins. The list 0141 * contains the basenames of the plugins' .desktop files (no path, 0142 * no .desktop). 0143 * @return the list of all available plugins 0144 */ 0145 static QStringList availablePlugins(); 0146 0147 /** 0148 * Returns all plugins that are considered when a preview is generated 0149 * The result is internally cached, meaning any further method call will not reload the plugins 0150 * @since 5.90 0151 */ 0152 static QList<KPluginMetaData> availableThumbnailerPlugins(); 0153 0154 /** 0155 * Returns a list of plugins that should be enabled by default, which is all plugins 0156 * Minus the plugins specified in an internal blacklist 0157 * @return the list of plugins that should be enabled by default 0158 * @since 5.40 0159 */ 0160 static QStringList defaultPlugins(); 0161 0162 /** 0163 * Returns a list of all supported MIME types. The list can 0164 * contain entries like text/ * (without the space). 0165 * @return the list of MIME types 0166 */ 0167 static QStringList supportedMimeTypes(); 0168 0169 Q_SIGNALS: 0170 /** 0171 * Emitted when a thumbnail picture for @p item has been successfully 0172 * retrieved. 0173 * @param item the file of the preview 0174 * @param preview the preview image 0175 */ 0176 void gotPreview(const KFileItem &item, const QPixmap &preview); 0177 /** 0178 * Emitted when a thumbnail for @p item could not be created, 0179 * either because a ThumbCreator for its MIME type does not 0180 * exist, or because something went wrong. 0181 * @param item the file that failed 0182 */ 0183 void failed(const KFileItem &item); 0184 0185 protected Q_SLOTS: 0186 void slotResult(KJob *job) override; 0187 0188 private: 0189 Q_DECLARE_PRIVATE(PreviewJob) 0190 0191 public: 0192 /** 0193 * Sets a default device Pixel Ratio used for Previews 0194 * @see setDevicePixelRatio 0195 * 0196 * Defaults to 1 0197 * 0198 * @since 5.84 0199 */ 0200 static void setDefaultDevicePixelRatio(qreal devicePixelRatio); 0201 }; 0202 0203 /** 0204 * Creates a PreviewJob to generate a preview image for the given items. 0205 * @param items List of files to create previews for. 0206 * @param size Desired size of the preview. 0207 * @param enabledPlugins If non-zero it defines the list of plugins that 0208 * are considered for generating the preview. If 0209 * enabledPlugins is zero the plugins specified in the 0210 * KConfigGroup "PreviewSettings" are used. 0211 */ 0212 KIOGUI_EXPORT PreviewJob *filePreview(const KFileItemList &items, const QSize &size, const QStringList *enabledPlugins = nullptr); 0213 } 0214 0215 #endif