1
https://projects.kde.org/projects/kde/kdelibs/repository/revisions/bda3fc424059a201a20153dd00b85aa26d57de1b
2
commit bda3fc424059a201a20153dd00b85aa26d57de1b
3
Author: Peter Penz <peter.penz19@gmail.com>
4
Date: Sun Feb 20 20:38:14 2011 +0100
6
KIO::PreviewJob: Respect the enabled plugins from "PreviewSettings"
8
Currently KIO::PreviewJob respects the settings "MaximumSize" and "MaximumRemoteSize" from the KConfigGroup "PreviewSettings", but completely ignores the "Plugins" settings. The patch provides a new constructor and does some API cleanups to support the preview-settings. See https://git.reviewboard.kde.org/r/100578/ for more details.
10
diff --git a/kio/kio/previewjob.cpp b/kio/kio/previewjob.cpp
11
--- a/kio/kio/previewjob.cpp
12
+++ b/kio/kio/previewjob.cpp
13
@@ -132,6 +132,7 @@ public:
14
Q_DECLARE_PUBLIC(PreviewJob)
17
+#ifndef KDE_NO_DEPRECATED
18
PreviewJob::PreviewJob( const KFileItemList &items, int width, int height,
19
int iconSize, int iconAlpha, bool scale, bool save,
20
const QStringList *enabledPlugins )
21
@@ -142,7 +143,7 @@ PreviewJob::PreviewJob( const KFileItemList &items, int width, int height,
24
d->initialItems = items;
25
- d->enabledPlugins = enabledPlugins ? *enabledPlugins : QStringList();
26
+ d->enabledPlugins = enabledPlugins ? *enabledPlugins : availablePlugins();
28
d->height = height ? height : width;
29
d->cacheWidth = d->width;
30
@@ -152,7 +153,46 @@ PreviewJob::PreviewJob( const KFileItemList &items, int width, int height,
32
d->bSave = save && scale;
34
- d->thumbRoot = QDir::homePath() + "/.thumbnails/";
35
+ d->thumbRoot = QDir::homePath() + QLatin1String("/.thumbnails/");
36
+ d->ignoreMaximumSize = false;
37
+ d->sequenceIndex = 0;
38
+ d->maximumLocalSize = 0;
39
+ d->maximumRemoteSize = 0;
41
+ // Return to event loop first, determineNextFile() might delete this;
42
+ QTimer::singleShot(0, this, SLOT(startPreview()));
46
+PreviewJob::PreviewJob(const KFileItemList &items,
48
+ const QStringList *enabledPlugins) :
49
+ KIO::Job(*new PreviewJobPrivate)
55
+ d->initialItems = items;
56
+ if (enabledPlugins) {
57
+ d->enabledPlugins = *enabledPlugins;
59
+ const KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
60
+ d->enabledPlugins = globalConfig.readEntry("Plugins", QStringList()
61
+ << "directorythumbnail"
63
+ << "jpegthumbnail");
65
+ d->width = size.width();
66
+ d->height = size.height();
67
+ d->cacheWidth = d->width;
68
+ d->cacheHeight = d->height;
73
+ d->succeeded = false;
74
+ d->thumbRoot = QDir::homePath() + QLatin1String("/.thumbnails/");
75
d->ignoreMaximumSize = false;
77
d->maximumLocalSize = 0;
78
@@ -173,6 +213,60 @@ PreviewJob::~PreviewJob()
82
+void PreviewJob::setOverlayIconSize(int size)
88
+int PreviewJob::overlayIconSize() const
90
+ Q_D(const PreviewJob);
94
+void PreviewJob::setOverlayIconAlpha(int alpha)
97
+ d->iconAlpha = qBound(0, alpha, 255);
100
+int PreviewJob::overlayIconAlpha() const
102
+ Q_D(const PreviewJob);
103
+ return d->iconAlpha;
106
+void PreviewJob::setScaleType(ScaleType type)
118
+ case ScaledAndCached:
127
+PreviewJob::ScaleType PreviewJob::scaleType() const
129
+ Q_D(const PreviewJob);
131
+ return d->bSave ? ScaledAndCached : Scaled;
136
void PreviewJobPrivate::startPreview()
139
@@ -181,7 +275,7 @@ void PreviewJobPrivate::startPreview()
140
QMap<QString, KService::Ptr> mimeMap;
142
for (KService::List::ConstIterator it = plugins.constBegin(); it != plugins.constEnd(); ++it) {
143
- if (enabledPlugins.isEmpty() || enabledPlugins.contains((*it)->desktopEntryName())) {
144
+ if (enabledPlugins.contains((*it)->desktopEntryName())) {
145
const QStringList mimeTypes = (*it)->serviceTypes();
146
for (QStringList::ConstIterator mt = mimeTypes.constBegin(); mt != mimeTypes.constEnd(); ++mt)
147
mimeMap.insert(*mt, *it);
148
@@ -629,6 +723,7 @@ QStringList PreviewJob::supportedMimeTypes()
152
+#ifndef KDE_NO_DEPRECATED
153
PreviewJob *KIO::filePreview( const KFileItemList &items, int width, int height,
154
int iconSize, int iconAlpha, bool scale, bool save,
155
const QStringList *enabledPlugins )
156
@@ -649,6 +744,12 @@ PreviewJob *KIO::filePreview( const KUrl::List &items, int width, int height,
157
return new PreviewJob(fileItems, width, height, iconSize, iconAlpha,
158
scale, save, enabledPlugins);
162
+PreviewJob *KIO::filePreview(const KFileItemList &items, const QSize &size, const QStringList *enabledPlugins)
164
+ return new PreviewJob(items, size, enabledPlugins);
167
#ifndef KDE_NO_DEPRECATED
168
KIO::filesize_t PreviewJob::maximumFileSize()
169
diff --git a/kio/kio/previewjob.h b/kio/kio/previewjob.h
170
--- a/kio/kio/previewjob.h
171
+++ b/kio/kio/previewjob.h
172
@@ -40,6 +40,30 @@ namespace KIO {
176
+ * Specifies the type of scaling that is applied to the generated preview.
181
+ * The original size of the preview will be returned. Most previews
182
+ * will return a size of 256 x 256 pixels.
186
+ * The preview will be scaled to the size specified when constructing
187
+ * the PreviewJob. The aspect ratio will be kept.
191
+ * The preview will be scaled to the size specified when constructing
192
+ * the PreviewJob. The result will be cached for later use. Per default
193
+ * ScaledAndCached is set.
198
+#ifndef KDE_NO_DEPRECATED
200
* Creates a new PreviewJob.
201
* @param items a list of files to create previews for
202
* @param width the desired width
203
@@ -51,15 +75,83 @@ namespace KIO {
204
* @param scale if the image is to be scaled to the requested size or
205
* returned in its original size
206
* @param save if the image should be cached for later use
207
- * @param enabledPlugins if non-zero, this points to a list containing
208
- * the names of the plugins that may be used.
209
+ * @param enabledPlugins If non-zero, this points to a list containing
210
+ * the names of the plugins that may be used. If enabledPlugins is zero
211
+ * all available plugins are used.
213
+ * @deprecated Use PreviewJob(KFileItemList, QSize, QStringList) in combination
214
+ * with the setter-methods instead. Note that the semantics of
215
+ * \p enabledPlugins has been slightly changed.
217
+ KDE_DEPRECATED PreviewJob(const KFileItemList& items, int width, int height,
218
+ int iconSize, int iconAlpha, bool scale, bool save,
219
+ const QStringList *enabledPlugins);
223
+ * @param items List of files to create previews for.
224
+ * @param size Desired size of the preview.
225
+ * @param enabledPlugins If non-zero it defines the list of plugins that
226
+ * are considered for generating the preview. If
227
+ * enabledPlugins is zero the plugins specified in the
228
+ * KConfigGroup "PreviewSettings" are used.
231
- PreviewJob( const KFileItemList& items, int width, int height,
232
- int iconSize, int iconAlpha, bool scale, bool save,
233
- const QStringList *enabledPlugins );
234
+ PreviewJob(const KFileItemList &items,
236
+ const QStringList *enabledPlugins = 0);
238
virtual ~PreviewJob();
241
+ * Sets the size of the MIME-type icon which overlays the preview. If zero
242
+ * is passed no overlay will be shown at all. The setting has no effect if
243
+ * the preview plugin that will be used does not use icon overlays. Per
244
+ * default the size is set to 0.
247
+ void setOverlayIconSize(int size);
250
+ * @return The size of the MIME-type icon which overlays the preview.
251
+ * @see PreviewJob::setOverlayIconSize()
254
+ int overlayIconSize() const;
257
+ * Sets the alpha-value for the MIME-type icon which overlays the preview.
258
+ * The alpha-value may range from 0 (= fully transparent) to 255 (= opaque).
259
+ * Per default the value is set to 70.
260
+ * @see PreviewJob::setOverlayIconSize()
263
+ void setOverlayIconAlpha(int alpha);
266
+ * @return The alpha-value for the MIME-type icon which overlays the preview.
267
+ * Per default 70 is returned.
268
+ * @see PreviewJob::setOverlayIconAlpha()
271
+ int overlayIconAlpha() const;
274
+ * Sets the scale type for the generated preview. Per default
275
+ * PreviewJob::ScaledAndCached is set.
276
+ * @see PreviewJob::ScaleType
279
+ void setScaleType(ScaleType type);
282
+ * @return The scale type for the generated preview.
283
+ * @see PreviewJob::ScaleType
286
+ ScaleType scaleType() const;
289
* Removes an item from preview processing. Use this if you passed
290
* an item to filePreview and want to delete it now.
292
@@ -142,6 +234,7 @@ namespace KIO {
293
Q_DECLARE_PRIVATE(PreviewJob)
296
+#ifndef KDE_NO_DEPRECATED
298
* Creates a PreviewJob to generate or retrieve a preview image
300
@@ -161,8 +254,11 @@ namespace KIO {
301
* the names of the plugins that may be used.
302
* @return the new PreviewJob
303
* @see PreviewJob::availablePlugins()
304
+ * @deprecated Use KIO::filePreview(KFileItemList, QSize, QStringList) in combination
305
+ * with the setter-methods instead. Note that the semantics of
306
+ * \p enabledPlugins has been slightly changed.
308
-KIO_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 = 0 ); // KDE5: use enums instead of bool scale + bool save
309
+ KIO_EXPORT_DEPRECATED 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 = 0 ); // KDE5: use enums instead of bool scale + bool save
312
* Creates a PreviewJob to generate or retrieve a preview image
313
@@ -183,8 +279,24 @@ KIO_EXPORT PreviewJob *filePreview( const KFileItemList &items, int width, int h
314
* the names of the plugins that may be used.
315
* @return the new PreviewJob
316
* @see PreviewJob::availablePlugins()
317
+ * @deprecated Use KIO::filePreview(KFileItemList, QSize, QStringList) in combination
318
+ * with the setter-methods instead. Note that the semantics of
319
+ * \p enabledPlugins has been slightly changed.
321
+ KIO_EXPORT_DEPRECATED PreviewJob *filePreview( const KUrl::List &items, int width, int height = 0, int iconSize = 0, int iconAlpha = 70, bool scale = true, bool save = true, const QStringList *enabledPlugins = 0 );
325
+ * Creates a PreviewJob to generate a preview image for the given items.
326
+ * @param items List of files to create previews for.
327
+ * @param size Desired size of the preview.
328
+ * @param enabledPlugins If non-zero it defines the list of plugins that
329
+ * are considered for generating the preview. If
330
+ * enabledPlugins is zero the plugins specified in the
331
+ * KConfigGroup "PreviewSettings" are used.
334
- KIO_EXPORT PreviewJob *filePreview( const KUrl::List &items, int width, int height = 0, int iconSize = 0, int iconAlpha = 70, bool scale = true, bool save = true, const QStringList *enabledPlugins = 0 );
335
+ KIO_EXPORT PreviewJob *filePreview(const KFileItemList &items, const QSize &size, const QStringList *enabledPlugins = 0);