1/*******************************************************************************
2 * Copyright (C) 2008-2009 by Peter Penz <peter.penz@gmx.at> *
3 * *
4 * This library is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Library General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2 of the License, or (at your option) any later version. *
8 * *
9 * This library is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Library General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Library General Public License *
15 * along with this library; see the file COPYING.LIB. If not, write to *
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301, USA. *
18 *******************************************************************************/
19
20#ifndef KFILEPREVIEWGENERATOR_H
21#define KFILEPREVIEWGENERATOR_H
22
23#include <kfile_export.h>
24
25#include <QtCore/QObject>
26
27class KAbstractViewAdapter;
28class KDirModel;
29class QAbstractItemView;
30class QAbstractProxyModel;
31
32/**
33 * @brief Generates previews for files of an item view.
34 *
35 * Per default a preview is generated for each item.
36 * Additionally the clipboard is checked for cut items.
37 * The icon state for cut items gets dimmed automatically.
38 *
39 * The following strategy is used when creating previews:
40 * - The previews for currently visible items are created before
41 * the previews for invisible items.
42 * - If the user changes the visible area by using the scrollbars,
43 * all pending previews get paused. As soon as the user stays
44 * on the same position for a short delay, the previews are
45 * resumed. Also in this case the previews for the visible items
46 * are generated first.
47 *
48 * @since 4.2
49 */
50class KFILE_EXPORT KFilePreviewGenerator : public QObject
51{
52 Q_OBJECT
53
54public:
55 /**
56 * @param parent Item view containing the file items where previews should
57 * be generated. It is mandatory that the item view specifies
58 * an icon size by QAbstractItemView::setIconSize() and that
59 * the model of the view (or the source model of the proxy model)
60 * is an instance of KDirModel. Otherwise no previews will be generated.
61 */
62 KFilePreviewGenerator(QAbstractItemView* parent);
63
64 /** @internal */
65 KFilePreviewGenerator(KAbstractViewAdapter* parent, QAbstractProxyModel* model);
66
67 virtual ~KFilePreviewGenerator();
68
69 /**
70 * If \a show is set to true, a preview is generated for each item. If \a show
71 * is false, the MIME type icon of the item is shown instead. Per default showing
72 * the preview is turned on. Note that it is mandatory that the item view
73 * specifies an icon size by QAbstractItemView::setIconSize(), otherwise
74 * KFilePreviewGenerator::isPreviewShown() will always return false.
75 */
76 void setPreviewShown(bool show);
77 bool isPreviewShown() const;
78
79 /**
80 * @deprecated Use KFilePreviewGenerator::updateIcons() instead.
81 */
82 void updatePreviews();
83
84 /**
85 * Updates the icons for all items. Usually it is only
86 * necessary to invoke this method when the icon size of the abstract item view
87 * has been changed by QAbstractItemView::setIconSize(). Note that this method
88 * should also be invoked if previews have been turned off, as the icons for
89 * cut items must be updated when the icon size has changed.
90 * @since 4.3
91 */
92 void updateIcons();
93
94 /** Cancels all pending previews. */
95 void cancelPreviews();
96
97 /**
98 * Sets the list of enabled thumbnail plugins.
99 * Per default all plugins enabled in the KConfigGroup "PreviewSettings"
100 * are used.
101 *
102 * Note that this method doesn't cause already generated previews
103 * to be regenerated.
104 *
105 * For a list of available plugins, call KServiceTypeTrader::self()->query("ThumbCreator").
106 *
107 * @see enabledPlugins
108 */
109 void setEnabledPlugins(const QStringList& list);
110
111 /**
112 * Returns the list of enabled thumbnail plugins.
113 * @see setEnabledPlugins
114 */
115 QStringList enabledPlugins() const;
116
117private:
118 class Private;
119 Private* const d; /// @internal
120 class LayoutBlocker;
121 class TileSet;
122
123 Q_DISABLE_COPY(KFilePreviewGenerator)
124
125 Q_PRIVATE_SLOT(d, void updateIcons(const KFileItemList&))
126 Q_PRIVATE_SLOT(d, void updateIcons(const QModelIndex&, const QModelIndex&))
127 Q_PRIVATE_SLOT(d, void addToPreviewQueue(const KFileItem&, const QPixmap&))
128 Q_PRIVATE_SLOT(d, void slotPreviewJobFinished(KJob*))
129 Q_PRIVATE_SLOT(d, void updateCutItems())
130 Q_PRIVATE_SLOT(d, void dispatchIconUpdateQueue())
131 Q_PRIVATE_SLOT(d, void pauseIconUpdates())
132 Q_PRIVATE_SLOT(d, void resumeIconUpdates())
133 Q_PRIVATE_SLOT(d, void resolveMimeType())
134 Q_PRIVATE_SLOT(d, void requestSequenceIcon(const QModelIndex&, int))
135 Q_PRIVATE_SLOT(d, void delayedIconUpdate())
136 Q_PRIVATE_SLOT(d, void rowsAboutToBeRemoved(const QModelIndex&, int, int))
137};
138
139#endif
140