KIO

previewjob.h
1 // -*- c++ -*-
2 /*
3  This file is part of the KDE libraries
4  SPDX-FileCopyrightText: 2000 David Faure <[email protected]>
5  SPDX-FileCopyrightText: 2000 Carsten Pfeiffer <[email protected]>
6  SPDX-FileCopyrightText: 2001 Malte Starostik <[email protected]>
7 
8  SPDX-License-Identifier: LGPL-2.0-or-later
9 */
10 
11 #ifndef KIO_PREVIEWJOB_H
12 #define KIO_PREVIEWJOB_H
13 
14 #include "kiowidgets_export.h"
15 #include <kfileitem.h>
16 #include <kio/job.h>
17 
18 class QPixmap;
19 class KPluginMetaData;
20 
21 namespace KIO
22 {
23 class PreviewJobPrivate;
24 /*!
25  * @class KIO::PreviewJob previewjob.h <KIO/PreviewJob>
26  *
27  * This class catches a preview (thumbnail) for files.
28  * @short KIO Job to get a thumbnail picture
29  */
30 class KIOWIDGETS_EXPORT PreviewJob : public KIO::Job
31 {
32  Q_OBJECT
33 public:
34  /**
35  * Specifies the type of scaling that is applied to the generated preview.
36  * For HiDPI, pixel density scaling, @see setDevicePixelRatio
37  *
38  * @since 4.7
39  */
40  enum ScaleType {
41  /**
42  * The original size of the preview will be returned. Most previews
43  * will return a size of 256 x 256 pixels.
44  */
46  /**
47  * The preview will be scaled to the size specified when constructing
48  * the PreviewJob. The aspect ratio will be kept.
49  */
51  /**
52  * The preview will be scaled to the size specified when constructing
53  * the PreviewJob. The result will be cached for later use. Per default
54  * ScaledAndCached is set.
55  */
57  };
58 
59 #if KIOWIDGETS_ENABLE_DEPRECATED_SINCE(4, 7)
60  /**
61  * Creates a new PreviewJob.
62  * @param items a list of files to create previews for
63  * @param width the desired width
64  * @param height the desired height, 0 to use the @p width
65  * @param iconSize the size of the MIME type icon to overlay over the
66  * preview or zero to not overlay an icon. This has no effect if the
67  * preview plugin that will be used doesn't use icon overlays.
68  * @param iconAlpha transparency to use for the icon overlay
69  * @param scale if the image is to be scaled to the requested size or
70  * returned in its original size
71  * @param save if the image should be cached for later use
72  * @param enabledPlugins If non-zero, this points to a list containing
73  * the names of the plugins that may be used. If enabledPlugins is zero
74  * all available plugins are used.
75  *
76  * @deprecated Since 4.7, use PreviewJob(const KFileItemList&, const QSize&, const QStringList*) in combination
77  * with the setter-methods instead. Note that the semantics of
78  * \p enabledPlugins has been slightly changed.
79  */
80  KIOWIDGETS_DEPRECATED_VERSION(4, 7, "Use PreviewJob(const KFileItemList&, const QSize&, const QStringList*)")
81  PreviewJob(const KFileItemList &items, int width, int height, int iconSize, int iconAlpha, bool scale, bool save, const QStringList *enabledPlugins);
82 #endif
83 
84  /**
85  * @param items List of files to create previews for.
86  * @param size Desired size of the preview.
87  * @param enabledPlugins If non-zero it defines the list of plugins that
88  * are considered for generating the preview. If
89  * enabledPlugins is zero the plugins specified in the
90  * KConfigGroup "PreviewSettings" are used.
91  * @since 4.7
92  */
93  PreviewJob(const KFileItemList &items, const QSize &size, const QStringList *enabledPlugins = nullptr);
94 
95  ~PreviewJob() override;
96 
97 #if KIOWIDGETS_ENABLE_DEPRECATED_SINCE(5, 102)
98  /**
99  * Sets the size of the MIME-type icon which overlays the preview. If zero
100  * is passed no overlay will be shown at all. The setting has no effect if
101  * the preview plugin that will be used does not use icon overlays. Per
102  * default the size is set to 0.
103  * @since 4.7
104  *
105  * @deprecated since 5.102, not implemented.
106  */
107  KIOWIDGETS_DEPRECATED_VERSION(5, 102, "Not implemented")
108  void setOverlayIconSize(int size);
109 #endif
110 
111 #if KIOWIDGETS_ENABLE_DEPRECATED_SINCE(5, 102)
112  /**
113  * @return The size of the MIME-type icon which overlays the preview.
114  * @see PreviewJob::setOverlayIconSize()
115  * @since 4.7
116  *
117  * @deprecated since 5.102, not implemented.
118  */
119  KIOWIDGETS_DEPRECATED_VERSION(5, 102, "Not implemented")
120  int overlayIconSize() const;
121 #endif
122 
123 #if KIOWIDGETS_ENABLE_DEPRECATED_SINCE(5, 102)
124  /**
125  * Sets the alpha-value for the MIME-type icon which overlays the preview.
126  * The alpha-value may range from 0 (= fully transparent) to 255 (= opaque).
127  * Per default the value is set to 70.
128  * @see PreviewJob::setOverlayIconSize()
129  * @since 4.7
130  *
131  * @deprecated since 5.102, not implemented.
132  */
133  KIOWIDGETS_DEPRECATED_VERSION(5, 102, "Not implemented")
134  void setOverlayIconAlpha(int alpha);
135 #endif
136 
137 #if KIOWIDGETS_ENABLE_DEPRECATED_SINCE(5, 102)
138  /**
139  * @return The alpha-value for the MIME-type icon which overlays the preview.
140  * Per default 70 is returned.
141  * @see PreviewJob::setOverlayIconAlpha()
142  * @since 4.7
143  *
144  * @deprecated since 5.102, not implemented.
145  */
146  KIOWIDGETS_DEPRECATED_VERSION(5, 102, "Not implemented")
147  int overlayIconAlpha() const;
148 #endif
149 
150  /**
151  * Sets the scale type for the generated preview. Per default
152  * PreviewJob::ScaledAndCached is set.
153  * @see PreviewJob::ScaleType
154  * @since 4.7
155  */
156  void setScaleType(ScaleType type);
157 
158  /**
159  * @return The scale type for the generated preview.
160  * @see PreviewJob::ScaleType
161  * @since 4.7
162  */
163  ScaleType scaleType() const;
164 
165  /**
166  * Removes an item from preview processing. Use this if you passed
167  * an item to filePreview and want to delete it now.
168  *
169  * @param url the url of the item that should be removed from the preview queue
170  */
171  void removeItem(const QUrl &url);
172 
173  /**
174  * If @p ignoreSize is true, then the preview is always
175  * generated regardless of the settings
176  **/
177  void setIgnoreMaximumSize(bool ignoreSize = true);
178 
179  /**
180  * Sets the sequence index given to the thumb creators.
181  * Use the sequence index, it is possible to create alternative
182  * icons for the same item. For example it may allow iterating through
183  * the items of a directory, or the frames of a video.
184  *
185  * @since 4.3
186  **/
187  void setSequenceIndex(int index);
188 
189  /**
190  * Returns the currently set sequence index
191  *
192  * @since 4.3
193  **/
194  int sequenceIndex() const;
195 
196  /**
197  * Returns the index at which the thumbs of a ThumbSequenceCreator start
198  * wrapping around ("looping"). Fractional values may be returned if the
199  * ThumbSequenceCreator supports sub-integer precision, but frontends
200  * supporting only integer sequence indices may choose to round it down.
201  *
202  * @see ThumbSequenceCreator::sequenceIndexWraparoundPoint()
203  * @since 5.80
204  */
205  float sequenceIndexWraparoundPoint() const;
206 
207  /**
208  * Determines whether the ThumbCreator in use is a ThumbSequenceCreator.
209  *
210  * @since 5.80
211  */
212  bool handlesSequences() const;
213 
214 #if KIOWIDGETS_ENABLE_DEPRECATED_SINCE(5, 86)
215  /**
216  * Request preview to use the device pixel ratio @p dpr.
217  * The returned thumbnail may not respect the device pixel ratio requested.
218  * Use QPixmap::devicePixelRatio to check, or paint as necessary.
219  *
220  * @since 5.80
221  * @deprecated Since 5.86, use setDevicePixelRatio(qreal dpr) instead
222  */
223  KIOWIDGETS_DEPRECATED_VERSION(5, 86, "Use setDevicePixelRatio(qreal dpr)")
224  void setDevicePixelRatio(int dpr);
225 #endif
226 
227  /**
228  * Request preview to use the device pixel ratio @p dpr.
229  * The returned thumbnail may not respect the device pixel ratio requested.
230  * Use QPixmap::devicePixelRatio to check, or paint as necessary.
231  *
232  * @since 5.84
233  */
234  void setDevicePixelRatio(qreal dpr);
235 
236  /**
237  * Returns a list of all available preview plugins. The list
238  * contains the basenames of the plugins' .desktop files (no path,
239  * no .desktop).
240  * @return the list of all available plugins
241  */
242  static QStringList availablePlugins();
243 
244  /**
245  * Returns all plugins that are considered when a preview is generated
246  * The result is internally cached, meaning any further method call will not reload the plugins
247  * @since 5.90
248  */
249  static QVector<KPluginMetaData> availableThumbnailerPlugins();
250 
251  /**
252  * Returns a list of plugins that should be enabled by default, which is all plugins
253  * Minus the plugins specified in an internal blacklist
254  * @return the list of plugins that should be enabled by default
255  * @since 5.40
256  */
257  static QStringList defaultPlugins();
258 
259  /**
260  * Returns a list of all supported MIME types. The list can
261  * contain entries like text/ * (without the space).
262  * @return the list of MIME types
263  */
264  static QStringList supportedMimeTypes();
265 
266 #if KIOWIDGETS_ENABLE_DEPRECATED_SINCE(4, 5)
267  /**
268  * Returns the default "maximum file size", in bytes, used by PreviewJob.
269  * This is useful for applications providing a GUI for letting the user change the size.
270  * @since 4.1
271  * @deprecated Since 4.5, PreviewJob uses different maximum file sizes dependent on the URL.
272  * The returned file size is only valid for local URLs.
273  */
274  KIOWIDGETS_DEPRECATED_VERSION(4, 5, "See API dox")
275  static KIO::filesize_t maximumFileSize();
276 #endif
277 
278 Q_SIGNALS:
279  /**
280  * Emitted when a thumbnail picture for @p item has been successfully
281  * retrieved.
282  * @param item the file of the preview
283  * @param preview the preview image
284  */
285  void gotPreview(const KFileItem &item, const QPixmap &preview);
286  /**
287  * Emitted when a thumbnail for @p item could not be created,
288  * either because a ThumbCreator for its MIME type does not
289  * exist, or because something went wrong.
290  * @param item the file that failed
291  */
292  void failed(const KFileItem &item);
293 
294 protected Q_SLOTS:
295  void slotResult(KJob *job) override;
296 
297 private:
298  Q_DECLARE_PRIVATE(PreviewJob)
299 
300 public:
301 #if KIOWIDGETS_ENABLE_DEPRECATED_SINCE(5, 86)
302  /**
303  * Sets a default device Pixel Ratio used for Previews
304  * @see setDevicePixelRatio
305  *
306  * Defaults to 1
307  *
308  * @since 5.80
309  * @deprecated Since 5.86, use setDefaultDevicePixelRatio(qreal dpr) instead
310  */
311  KIOWIDGETS_DEPRECATED_VERSION(5, 86, "Use setDefaultDevicePixelRatio(qreal dpr)")
312  static void setDefaultDevicePixelRatio(int devicePixelRatio);
313 #endif
314 
315  /**
316  * Sets a default device Pixel Ratio used for Previews
317  * @see setDevicePixelRatio
318  *
319  * Defaults to 1
320  *
321  * @since 5.84
322  */
323  static void setDefaultDevicePixelRatio(qreal devicePixelRatio);
324 };
325 
326 #if KIOWIDGETS_ENABLE_DEPRECATED_SINCE(4, 7)
327 /**
328  * Creates a PreviewJob to generate or retrieve a preview image
329  * for the given URL.
330  *
331  * @param items files to get previews for
332  * @param width the maximum width to use
333  * @param height the maximum height to use, if this is 0, the same
334  * value as width is used.
335  * @param iconSize the size of the MIME type icon to overlay over the
336  * preview or zero to not overlay an icon. This has no effect if the
337  * preview plugin that will be used doesn't use icon overlays.
338  * @param iconAlpha transparency to use for the icon overlay
339  * @param scale if the image is to be scaled to the requested size or
340  * returned in its original size
341  * @param save if the image should be cached for later use
342  * @param enabledPlugins if non-zero, this points to a list containing
343  * the names of the plugins that may be used.
344  * @return the new PreviewJob
345  * @see PreviewJob::availablePlugins()
346  * @deprecated Since 4.7, use KIO::filePreview(const KFileItemList&, const QSize&, const QStringList*) in combination
347  * with the setter-methods instead. Note that the semantics of
348  * \p enabledPlugins has been slightly changed.
349  */
350 KIOWIDGETS_EXPORT
351 KIOWIDGETS_DEPRECATED_VERSION(4, 7, "Use KIO::filePreview(const KFileItemList &, const QSize &, const QStringList *")
352 PreviewJob *filePreview(const KFileItemList &items,
353  int width,
354  int height = 0,
355  int iconSize = 0,
356  int iconAlpha = 70,
357  bool scale = true,
358  bool save = true,
359  const QStringList *enabledPlugins = nullptr); // KDE5: use enums instead of bool scale + bool save
360 #endif
361 
362 #if KIOWIDGETS_ENABLE_DEPRECATED_SINCE(4, 7)
363 /**
364  * Creates a PreviewJob to generate or retrieve a preview image
365  * for the given URL.
366  *
367  * @param items files to get previews for
368  * @param width the maximum width to use
369  * @param height the maximum height to use, if this is 0, the same
370  * value as width is used.
371  * @param iconSize the size of the MIME type icon to overlay over the
372  * preview or zero to not overlay an icon. This has no effect if the
373  * preview plugin that will be used doesn't use icon overlays.
374  * @param iconAlpha transparency to use for the icon overlay
375  * @param scale if the image is to be scaled to the requested size or
376  * returned in its original size
377  * @param save if the image should be cached for later use
378  * @param enabledPlugins if non-zero, this points to a list containing
379  * the names of the plugins that may be used.
380  * @return the new PreviewJob
381  * @see PreviewJob::availablePlugins()
382  * @deprecated Since 4.7, use KIO::filePreview(const KFileItemList&, const QSize&, const QStringList*) in combination
383  * with the setter-methods instead. Note that the semantics of
384  * \p enabledPlugins has been slightly changed.
385  */
386 KIOWIDGETS_EXPORT
387 KIOWIDGETS_DEPRECATED_VERSION(4, 7, "Use KIO::filePreview(const KFileItemList &, const QSize &, const QStringList *")
388 PreviewJob *filePreview(const QList<QUrl> &items,
389  int width,
390  int height = 0,
391  int iconSize = 0,
392  int iconAlpha = 70,
393  bool scale = true,
394  bool save = true,
395  const QStringList *enabledPlugins = nullptr);
396 #endif
397 
398 /**
399  * Creates a PreviewJob to generate a preview image for the given items.
400  * @param items List of files to create previews for.
401  * @param size Desired size of the preview.
402  * @param enabledPlugins If non-zero it defines the list of plugins that
403  * are considered for generating the preview. If
404  * enabledPlugins is zero the plugins specified in the
405  * KConfigGroup "PreviewSettings" are used.
406  * @since 4.7
407  */
408 KIOWIDGETS_EXPORT PreviewJob *filePreview(const KFileItemList &items, const QSize &size, const QStringList *enabledPlugins = nullptr);
409 }
410 
411 #endif
qulonglong filesize_t
64-bit file size
Definition: global.h:39
@ Scaled
The preview will be scaled to the size specified when constructing the PreviewJob.
Definition: previewjob.h:50
@ Unscaled
The original size of the preview will be returned.
Definition: previewjob.h:45
KIO Job to get a thumbnail picture.
Definition: previewjob.h:30
A namespace for KIO globals.
ScaleType
Specifies the type of scaling that is applied to the generated preview.
Definition: previewjob.h:40
KIOWIDGETS_EXPORT PreviewJob * filePreview(const KFileItemList &items, int width, int height=0, int iconSize=0, int iconAlpha=70, bool scale=true, bool save=true, const QStringList *enabledPlugins=nullptr)
Creates a PreviewJob to generate or retrieve a preview image for the given URL.
@ ScaledAndCached
The preview will be scaled to the size specified when constructing the PreviewJob.
Definition: previewjob.h:56
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Dec 2 2023 03:52:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.