Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/itemviews/qfileiconprovider.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
5 | ** | - | ||||||||||||||||||||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||||||||
7 | ** | - | ||||||||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
16 | ** | - | ||||||||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
25 | ** | - | ||||||||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
29 | ** | - | ||||||||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
31 | ** | - | ||||||||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||
34 | #include "qfileiconprovider.h" | - | ||||||||||||||||||||||||
35 | #include "qfileiconprovider_p.h" | - | ||||||||||||||||||||||||
36 | - | |||||||||||||||||||||||||
37 | #include <qapplication.h> | - | ||||||||||||||||||||||||
38 | #include <qdir.h> | - | ||||||||||||||||||||||||
39 | #include <qpixmapcache.h> | - | ||||||||||||||||||||||||
40 | #include <private/qfunctions_p.h> | - | ||||||||||||||||||||||||
41 | #include <private/qguiapplication_p.h> | - | ||||||||||||||||||||||||
42 | #include <private/qicon_p.h> | - | ||||||||||||||||||||||||
43 | #include <qpa/qplatformintegration.h> | - | ||||||||||||||||||||||||
44 | #include <qpa/qplatformservices.h> | - | ||||||||||||||||||||||||
45 | #include <qpa/qplatformtheme.h> | - | ||||||||||||||||||||||||
46 | - | |||||||||||||||||||||||||
47 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
48 | # include <qt_windows.h> | - | ||||||||||||||||||||||||
49 | # ifndef Q_OS_WINRT | - | ||||||||||||||||||||||||
50 | # include <commctrl.h> | - | ||||||||||||||||||||||||
51 | # include <objbase.h> | - | ||||||||||||||||||||||||
52 | # endif | - | ||||||||||||||||||||||||
53 | #endif | - | ||||||||||||||||||||||||
54 | - | |||||||||||||||||||||||||
55 | #if defined(Q_OS_UNIX) && !defined(QT_NO_STYLE_GTK) | - | ||||||||||||||||||||||||
56 | # include <private/qgtkstyle_p_p.h> | - | ||||||||||||||||||||||||
57 | #endif | - | ||||||||||||||||||||||||
58 | - | |||||||||||||||||||||||||
59 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
60 | - | |||||||||||||||||||||||||
61 | static bool isCacheable(const QFileInfo &fi); | - | ||||||||||||||||||||||||
62 | - | |||||||||||||||||||||||||
63 | class QFileIconEngine : public QPixmapIconEngine | - | ||||||||||||||||||||||||
64 | { | - | ||||||||||||||||||||||||
65 | public: | - | ||||||||||||||||||||||||
66 | QFileIconEngine(const QFileInfo &info, QFileIconProvider::Options opts) | - | ||||||||||||||||||||||||
67 | : QPixmapIconEngine(), m_fileInfo(info), m_fipOpts(opts) | - | ||||||||||||||||||||||||
68 | { } never executed: end of block | 0 | ||||||||||||||||||||||||
69 | - | |||||||||||||||||||||||||
70 | QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) Q_DECL_OVERRIDE | - | ||||||||||||||||||||||||
71 | { | - | ||||||||||||||||||||||||
72 | Q_UNUSED(mode); | - | ||||||||||||||||||||||||
73 | Q_UNUSED(state); | - | ||||||||||||||||||||||||
74 | QPixmap pixmap; | - | ||||||||||||||||||||||||
75 | - | |||||||||||||||||||||||||
76 | if (!size.isValid())
| 0 | ||||||||||||||||||||||||
77 | return pixmap; never executed: return pixmap; | 0 | ||||||||||||||||||||||||
78 | - | |||||||||||||||||||||||||
79 | const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme(); | - | ||||||||||||||||||||||||
80 | if (!theme)
| 0 | ||||||||||||||||||||||||
81 | return pixmap; never executed: return pixmap; | 0 | ||||||||||||||||||||||||
82 | - | |||||||||||||||||||||||||
83 | const QString &keyBase = QLatin1String("qt_.") + m_fileInfo.suffix().toUpper(); | - | ||||||||||||||||||||||||
84 | - | |||||||||||||||||||||||||
85 | bool cacheable = isCacheable(m_fileInfo); | - | ||||||||||||||||||||||||
86 | if (cacheable) {
| 0 | ||||||||||||||||||||||||
87 | QPixmapCache::find(keyBase + QString::number(size.width()), pixmap); | - | ||||||||||||||||||||||||
88 | if (!pixmap.isNull())
| 0 | ||||||||||||||||||||||||
89 | return pixmap; never executed: return pixmap; | 0 | ||||||||||||||||||||||||
90 | } never executed: end of block | 0 | ||||||||||||||||||||||||
91 | - | |||||||||||||||||||||||||
92 | QPlatformTheme::IconOptions iconOptions; | - | ||||||||||||||||||||||||
93 | if (m_fipOpts & QFileIconProvider::DontUseCustomDirectoryIcons)
| 0 | ||||||||||||||||||||||||
94 | iconOptions |= QPlatformTheme::DontUseCustomDirectoryIcons; never executed: iconOptions |= QPlatformTheme::DontUseCustomDirectoryIcons; | 0 | ||||||||||||||||||||||||
95 | - | |||||||||||||||||||||||||
96 | pixmap = theme->fileIconPixmap(m_fileInfo, size, iconOptions); | - | ||||||||||||||||||||||||
97 | if (!pixmap.isNull()) {
| 0 | ||||||||||||||||||||||||
98 | if (cacheable)
| 0 | ||||||||||||||||||||||||
99 | QPixmapCache::insert(keyBase + QString::number(size.width()), pixmap); never executed: QPixmapCache::insert(keyBase + QString::number(size.width()), pixmap); | 0 | ||||||||||||||||||||||||
100 | } never executed: end of block | 0 | ||||||||||||||||||||||||
101 | - | |||||||||||||||||||||||||
102 | return pixmap; never executed: return pixmap; | 0 | ||||||||||||||||||||||||
103 | } | - | ||||||||||||||||||||||||
104 | - | |||||||||||||||||||||||||
105 | QList<QSize> availableSizes(QIcon::Mode mode = QIcon::Normal, QIcon::State state = QIcon::Off) const Q_DECL_OVERRIDE | - | ||||||||||||||||||||||||
106 | { | - | ||||||||||||||||||||||||
107 | Q_UNUSED(mode); | - | ||||||||||||||||||||||||
108 | Q_UNUSED(state); | - | ||||||||||||||||||||||||
109 | static QList<QSize> sizes; | - | ||||||||||||||||||||||||
110 | static QPlatformTheme *theme = 0; | - | ||||||||||||||||||||||||
111 | if (!theme) {
| 0 | ||||||||||||||||||||||||
112 | theme = QGuiApplicationPrivate::platformTheme(); | - | ||||||||||||||||||||||||
113 | if (!theme)
| 0 | ||||||||||||||||||||||||
114 | return sizes; never executed: return sizes; | 0 | ||||||||||||||||||||||||
115 | - | |||||||||||||||||||||||||
116 | QList<int> themeSizes = theme->themeHint(QPlatformTheme::IconPixmapSizes).value<QList<int> >(); | - | ||||||||||||||||||||||||
117 | if (themeSizes.isEmpty())
| 0 | ||||||||||||||||||||||||
118 | return sizes; never executed: return sizes; | 0 | ||||||||||||||||||||||||
119 | - | |||||||||||||||||||||||||
120 | sizes.reserve(themeSizes.count()); | - | ||||||||||||||||||||||||
121 | foreach (int size, themeSizes) | - | ||||||||||||||||||||||||
122 | sizes << QSize(size, size); never executed: sizes << QSize(size, size); | 0 | ||||||||||||||||||||||||
123 | } never executed: end of block | 0 | ||||||||||||||||||||||||
124 | return sizes; never executed: return sizes; | 0 | ||||||||||||||||||||||||
125 | } | - | ||||||||||||||||||||||||
126 | - | |||||||||||||||||||||||||
127 | QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) Q_DECL_OVERRIDE | - | ||||||||||||||||||||||||
128 | { | - | ||||||||||||||||||||||||
129 | const QList<QSize> &sizes = availableSizes(mode, state); | - | ||||||||||||||||||||||||
130 | const int numberSizes = sizes.length(); | - | ||||||||||||||||||||||||
131 | if (numberSizes == 0)
| 0 | ||||||||||||||||||||||||
132 | return QSize(); never executed: return QSize(); | 0 | ||||||||||||||||||||||||
133 | - | |||||||||||||||||||||||||
134 | // Find the smallest available size whose area is still larger than the input | - | ||||||||||||||||||||||||
135 | // size. Otherwise, use the largest area available size. (We don't assume the | - | ||||||||||||||||||||||||
136 | // platform theme sizes are sorted, hence the extra logic.) | - | ||||||||||||||||||||||||
137 | const int sizeArea = size.width() * size.height(); | - | ||||||||||||||||||||||||
138 | QSize actualSize = sizes.first(); | - | ||||||||||||||||||||||||
139 | int actualArea = actualSize.width() * actualSize.height(); | - | ||||||||||||||||||||||||
140 | for (int i = 1; i < numberSizes; ++i) {
| 0 | ||||||||||||||||||||||||
141 | const QSize &s = sizes.at(i); | - | ||||||||||||||||||||||||
142 | const int a = s.width() * s.height(); | - | ||||||||||||||||||||||||
143 | if ((sizeArea <= a && a < actualArea) || (actualArea < sizeArea && actualArea < a)) {
| 0 | ||||||||||||||||||||||||
144 | actualSize = s; | - | ||||||||||||||||||||||||
145 | actualArea = a; | - | ||||||||||||||||||||||||
146 | } never executed: end of block | 0 | ||||||||||||||||||||||||
147 | } never executed: end of block | 0 | ||||||||||||||||||||||||
148 | - | |||||||||||||||||||||||||
149 | if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height()))
| 0 | ||||||||||||||||||||||||
150 | actualSize.scale(size, Qt::KeepAspectRatio); never executed: actualSize.scale(size, Qt::KeepAspectRatio); | 0 | ||||||||||||||||||||||||
151 | - | |||||||||||||||||||||||||
152 | return actualSize; never executed: return actualSize; | 0 | ||||||||||||||||||||||||
153 | } | - | ||||||||||||||||||||||||
154 | - | |||||||||||||||||||||||||
155 | private: | - | ||||||||||||||||||||||||
156 | QFileInfo m_fileInfo; | - | ||||||||||||||||||||||||
157 | QFileIconProvider::Options m_fipOpts; | - | ||||||||||||||||||||||||
158 | }; | - | ||||||||||||||||||||||||
159 | - | |||||||||||||||||||||||||
160 | - | |||||||||||||||||||||||||
161 | /*! | - | ||||||||||||||||||||||||
162 | \class QFileIconProvider | - | ||||||||||||||||||||||||
163 | - | |||||||||||||||||||||||||
164 | \inmodule QtWidgets | - | ||||||||||||||||||||||||
165 | - | |||||||||||||||||||||||||
166 | \brief The QFileIconProvider class provides file icons for the QDirModel and the QFileSystemModel classes. | - | ||||||||||||||||||||||||
167 | */ | - | ||||||||||||||||||||||||
168 | - | |||||||||||||||||||||||||
169 | /*! | - | ||||||||||||||||||||||||
170 | \enum QFileIconProvider::IconType | - | ||||||||||||||||||||||||
171 | \value Computer | - | ||||||||||||||||||||||||
172 | \value Desktop | - | ||||||||||||||||||||||||
173 | \value Trashcan | - | ||||||||||||||||||||||||
174 | \value Network | - | ||||||||||||||||||||||||
175 | \value Drive | - | ||||||||||||||||||||||||
176 | \value Folder | - | ||||||||||||||||||||||||
177 | \value File | - | ||||||||||||||||||||||||
178 | */ | - | ||||||||||||||||||||||||
179 | - | |||||||||||||||||||||||||
180 | - | |||||||||||||||||||||||||
181 | /*! | - | ||||||||||||||||||||||||
182 | \enum QFileIconProvider::Option | - | ||||||||||||||||||||||||
183 | \since 5.2 | - | ||||||||||||||||||||||||
184 | - | |||||||||||||||||||||||||
185 | \value DontUseCustomDirectoryIcons Always use the default directory icon. | - | ||||||||||||||||||||||||
186 | Some platforms allow the user to set a different icon. Custom icon lookup | - | ||||||||||||||||||||||||
187 | cause a big performance impact over network or removable drives. | - | ||||||||||||||||||||||||
188 | */ | - | ||||||||||||||||||||||||
189 | - | |||||||||||||||||||||||||
190 | QFileIconProviderPrivate::QFileIconProviderPrivate(QFileIconProvider *q) : | - | ||||||||||||||||||||||||
191 | q_ptr(q), homePath(QDir::home().absolutePath()) | - | ||||||||||||||||||||||||
192 | { | - | ||||||||||||||||||||||||
193 | } never executed: end of block | 0 | ||||||||||||||||||||||||
194 | - | |||||||||||||||||||||||||
195 | QIcon QFileIconProviderPrivate::getIcon(QStyle::StandardPixmap name) const | - | ||||||||||||||||||||||||
196 | { | - | ||||||||||||||||||||||||
197 | switch (name) { | - | ||||||||||||||||||||||||
198 | case QStyle::SP_FileIcon: never executed: case QStyle::SP_FileIcon: | 0 | ||||||||||||||||||||||||
199 | if (file.isNull())
| 0 | ||||||||||||||||||||||||
200 | file = QApplication::style()->standardIcon(name); never executed: file = QApplication::style()->standardIcon(name); | 0 | ||||||||||||||||||||||||
201 | return file; never executed: return file; | 0 | ||||||||||||||||||||||||
202 | case QStyle::SP_FileLinkIcon: never executed: case QStyle::SP_FileLinkIcon: | 0 | ||||||||||||||||||||||||
203 | if (fileLink.isNull())
| 0 | ||||||||||||||||||||||||
204 | fileLink = QApplication::style()->standardIcon(name); never executed: fileLink = QApplication::style()->standardIcon(name); | 0 | ||||||||||||||||||||||||
205 | return fileLink; never executed: return fileLink; | 0 | ||||||||||||||||||||||||
206 | case QStyle::SP_DirIcon: never executed: case QStyle::SP_DirIcon: | 0 | ||||||||||||||||||||||||
207 | if (directory.isNull())
| 0 | ||||||||||||||||||||||||
208 | directory = QApplication::style()->standardIcon(name); never executed: directory = QApplication::style()->standardIcon(name); | 0 | ||||||||||||||||||||||||
209 | return directory; never executed: return directory; | 0 | ||||||||||||||||||||||||
210 | case QStyle::SP_DirLinkIcon: never executed: case QStyle::SP_DirLinkIcon: | 0 | ||||||||||||||||||||||||
211 | if (directoryLink.isNull())
| 0 | ||||||||||||||||||||||||
212 | directoryLink = QApplication::style()->standardIcon(name); never executed: directoryLink = QApplication::style()->standardIcon(name); | 0 | ||||||||||||||||||||||||
213 | return directoryLink; never executed: return directoryLink; | 0 | ||||||||||||||||||||||||
214 | case QStyle::SP_DriveHDIcon: never executed: case QStyle::SP_DriveHDIcon: | 0 | ||||||||||||||||||||||||
215 | if (harddisk.isNull())
| 0 | ||||||||||||||||||||||||
216 | harddisk = QApplication::style()->standardIcon(name); never executed: harddisk = QApplication::style()->standardIcon(name); | 0 | ||||||||||||||||||||||||
217 | return harddisk; never executed: return harddisk; | 0 | ||||||||||||||||||||||||
218 | case QStyle::SP_DriveFDIcon: never executed: case QStyle::SP_DriveFDIcon: | 0 | ||||||||||||||||||||||||
219 | if (floppy.isNull())
| 0 | ||||||||||||||||||||||||
220 | floppy = QApplication::style()->standardIcon(name); never executed: floppy = QApplication::style()->standardIcon(name); | 0 | ||||||||||||||||||||||||
221 | return floppy; never executed: return floppy; | 0 | ||||||||||||||||||||||||
222 | case QStyle::SP_DriveCDIcon: never executed: case QStyle::SP_DriveCDIcon: | 0 | ||||||||||||||||||||||||
223 | if (cdrom.isNull())
| 0 | ||||||||||||||||||||||||
224 | cdrom = QApplication::style()->standardIcon(name); never executed: cdrom = QApplication::style()->standardIcon(name); | 0 | ||||||||||||||||||||||||
225 | return cdrom; never executed: return cdrom; | 0 | ||||||||||||||||||||||||
226 | case QStyle::SP_DriveNetIcon: never executed: case QStyle::SP_DriveNetIcon: | 0 | ||||||||||||||||||||||||
227 | if (network.isNull())
| 0 | ||||||||||||||||||||||||
228 | network = QApplication::style()->standardIcon(name); never executed: network = QApplication::style()->standardIcon(name); | 0 | ||||||||||||||||||||||||
229 | return network; never executed: return network; | 0 | ||||||||||||||||||||||||
230 | case QStyle::SP_ComputerIcon: never executed: case QStyle::SP_ComputerIcon: | 0 | ||||||||||||||||||||||||
231 | if (computer.isNull())
| 0 | ||||||||||||||||||||||||
232 | computer = QApplication::style()->standardIcon(name); never executed: computer = QApplication::style()->standardIcon(name); | 0 | ||||||||||||||||||||||||
233 | return computer; never executed: return computer; | 0 | ||||||||||||||||||||||||
234 | case QStyle::SP_DesktopIcon: never executed: case QStyle::SP_DesktopIcon: | 0 | ||||||||||||||||||||||||
235 | if (desktop.isNull())
| 0 | ||||||||||||||||||||||||
236 | desktop = QApplication::style()->standardIcon(name); never executed: desktop = QApplication::style()->standardIcon(name); | 0 | ||||||||||||||||||||||||
237 | return desktop; never executed: return desktop; | 0 | ||||||||||||||||||||||||
238 | case QStyle::SP_TrashIcon: never executed: case QStyle::SP_TrashIcon: | 0 | ||||||||||||||||||||||||
239 | if (trashcan.isNull())
| 0 | ||||||||||||||||||||||||
240 | trashcan = QApplication::style()->standardIcon(name); never executed: trashcan = QApplication::style()->standardIcon(name); | 0 | ||||||||||||||||||||||||
241 | return trashcan; never executed: return trashcan; | 0 | ||||||||||||||||||||||||
242 | case QStyle::SP_DirHomeIcon: never executed: case QStyle::SP_DirHomeIcon: | 0 | ||||||||||||||||||||||||
243 | if (home.isNull())
| 0 | ||||||||||||||||||||||||
244 | home = QApplication::style()->standardIcon(name); never executed: home = QApplication::style()->standardIcon(name); | 0 | ||||||||||||||||||||||||
245 | return home; never executed: return home; | 0 | ||||||||||||||||||||||||
246 | default: never executed: default: | 0 | ||||||||||||||||||||||||
247 | return QIcon(); never executed: return QIcon(); | 0 | ||||||||||||||||||||||||
248 | } | - | ||||||||||||||||||||||||
249 | return QIcon(); dead code: return QIcon(); | - | ||||||||||||||||||||||||
250 | } | - | ||||||||||||||||||||||||
251 | - | |||||||||||||||||||||||||
252 | /*! | - | ||||||||||||||||||||||||
253 | Constructs a file icon provider. | - | ||||||||||||||||||||||||
254 | */ | - | ||||||||||||||||||||||||
255 | - | |||||||||||||||||||||||||
256 | QFileIconProvider::QFileIconProvider() | - | ||||||||||||||||||||||||
257 | : d_ptr(new QFileIconProviderPrivate(this)) | - | ||||||||||||||||||||||||
258 | { | - | ||||||||||||||||||||||||
259 | } never executed: end of block | 0 | ||||||||||||||||||||||||
260 | - | |||||||||||||||||||||||||
261 | /*! | - | ||||||||||||||||||||||||
262 | Destroys the file icon provider. | - | ||||||||||||||||||||||||
263 | - | |||||||||||||||||||||||||
264 | */ | - | ||||||||||||||||||||||||
265 | - | |||||||||||||||||||||||||
266 | QFileIconProvider::~QFileIconProvider() | - | ||||||||||||||||||||||||
267 | { | - | ||||||||||||||||||||||||
268 | } | - | ||||||||||||||||||||||||
269 | - | |||||||||||||||||||||||||
270 | /*! | - | ||||||||||||||||||||||||
271 | \since 5.2 | - | ||||||||||||||||||||||||
272 | Sets \a options that affect the icon provider. | - | ||||||||||||||||||||||||
273 | \sa options() | - | ||||||||||||||||||||||||
274 | */ | - | ||||||||||||||||||||||||
275 | - | |||||||||||||||||||||||||
276 | void QFileIconProvider::setOptions(QFileIconProvider::Options options) | - | ||||||||||||||||||||||||
277 | { | - | ||||||||||||||||||||||||
278 | Q_D(QFileIconProvider); | - | ||||||||||||||||||||||||
279 | d->options = options; | - | ||||||||||||||||||||||||
280 | } never executed: end of block | 0 | ||||||||||||||||||||||||
281 | - | |||||||||||||||||||||||||
282 | /*! | - | ||||||||||||||||||||||||
283 | \since 5.2 | - | ||||||||||||||||||||||||
284 | Returns all the options that affect the icon provider. | - | ||||||||||||||||||||||||
285 | By default, all options are disabled. | - | ||||||||||||||||||||||||
286 | \sa setOptions() | - | ||||||||||||||||||||||||
287 | */ | - | ||||||||||||||||||||||||
288 | - | |||||||||||||||||||||||||
289 | QFileIconProvider::Options QFileIconProvider::options() const | - | ||||||||||||||||||||||||
290 | { | - | ||||||||||||||||||||||||
291 | Q_D(const QFileIconProvider); | - | ||||||||||||||||||||||||
292 | return d->options; never executed: return d->options; | 0 | ||||||||||||||||||||||||
293 | } | - | ||||||||||||||||||||||||
294 | - | |||||||||||||||||||||||||
295 | /*! | - | ||||||||||||||||||||||||
296 | Returns an icon set for the given \a type. | - | ||||||||||||||||||||||||
297 | */ | - | ||||||||||||||||||||||||
298 | - | |||||||||||||||||||||||||
299 | QIcon QFileIconProvider::icon(IconType type) const | - | ||||||||||||||||||||||||
300 | { | - | ||||||||||||||||||||||||
301 | Q_D(const QFileIconProvider); | - | ||||||||||||||||||||||||
302 | switch (type) { | - | ||||||||||||||||||||||||
303 | case Computer: never executed: case Computer: | 0 | ||||||||||||||||||||||||
304 | return d->getIcon(QStyle::SP_ComputerIcon); never executed: return d->getIcon(QStyle::SP_ComputerIcon); | 0 | ||||||||||||||||||||||||
305 | case Desktop: never executed: case Desktop: | 0 | ||||||||||||||||||||||||
306 | return d->getIcon(QStyle::SP_DesktopIcon); never executed: return d->getIcon(QStyle::SP_DesktopIcon); | 0 | ||||||||||||||||||||||||
307 | case Trashcan: never executed: case Trashcan: | 0 | ||||||||||||||||||||||||
308 | return d->getIcon(QStyle::SP_TrashIcon); never executed: return d->getIcon(QStyle::SP_TrashIcon); | 0 | ||||||||||||||||||||||||
309 | case Network: never executed: case Network: | 0 | ||||||||||||||||||||||||
310 | return d->getIcon(QStyle::SP_DriveNetIcon); never executed: return d->getIcon(QStyle::SP_DriveNetIcon); | 0 | ||||||||||||||||||||||||
311 | case Drive: never executed: case Drive: | 0 | ||||||||||||||||||||||||
312 | return d->getIcon(QStyle::SP_DriveHDIcon); never executed: return d->getIcon(QStyle::SP_DriveHDIcon); | 0 | ||||||||||||||||||||||||
313 | case Folder: never executed: case Folder: | 0 | ||||||||||||||||||||||||
314 | return d->getIcon(QStyle::SP_DirIcon); never executed: return d->getIcon(QStyle::SP_DirIcon); | 0 | ||||||||||||||||||||||||
315 | case File: never executed: case File: | 0 | ||||||||||||||||||||||||
316 | return d->getIcon(QStyle::SP_FileIcon); never executed: return d->getIcon(QStyle::SP_FileIcon); | 0 | ||||||||||||||||||||||||
317 | default: never executed: default: | 0 | ||||||||||||||||||||||||
318 | break; never executed: break; | 0 | ||||||||||||||||||||||||
319 | }; | - | ||||||||||||||||||||||||
320 | return QIcon(); never executed: return QIcon(); | 0 | ||||||||||||||||||||||||
321 | } | - | ||||||||||||||||||||||||
322 | - | |||||||||||||||||||||||||
323 | static bool isCacheable(const QFileInfo &fi) | - | ||||||||||||||||||||||||
324 | { | - | ||||||||||||||||||||||||
325 | if (!fi.isFile())
| 0 | ||||||||||||||||||||||||
326 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
327 | - | |||||||||||||||||||||||||
328 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
329 | // On windows it's faster to just look at the file extensions. QTBUG-13182 | - | ||||||||||||||||||||||||
330 | const QString fileExtension = fi.suffix(); | - | ||||||||||||||||||||||||
331 | // Will return false for .exe, .lnk and .ico extensions | - | ||||||||||||||||||||||||
332 | return fileExtension.compare(QLatin1String("exe"), Qt::CaseInsensitive) && | - | ||||||||||||||||||||||||
333 | fileExtension.compare(QLatin1String("lnk"), Qt::CaseInsensitive) && | - | ||||||||||||||||||||||||
334 | fileExtension.compare(QLatin1String("ico"), Qt::CaseInsensitive); | - | ||||||||||||||||||||||||
335 | #else | - | ||||||||||||||||||||||||
336 | return !fi.isExecutable() && !fi.isSymLink(); never executed: return !fi.isExecutable() && !fi.isSymLink();
| 0 | ||||||||||||||||||||||||
337 | #endif | - | ||||||||||||||||||||||||
338 | } | - | ||||||||||||||||||||||||
339 | - | |||||||||||||||||||||||||
340 | QIcon QFileIconProviderPrivate::getIcon(const QFileInfo &fi) const | - | ||||||||||||||||||||||||
341 | { | - | ||||||||||||||||||||||||
342 | const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme(); | - | ||||||||||||||||||||||||
343 | if (!theme)
| 0 | ||||||||||||||||||||||||
344 | return QIcon(); never executed: return QIcon(); | 0 | ||||||||||||||||||||||||
345 | - | |||||||||||||||||||||||||
346 | QList<int> sizes = theme->themeHint(QPlatformTheme::IconPixmapSizes).value<QList<int> >(); | - | ||||||||||||||||||||||||
347 | if (sizes.isEmpty())
| 0 | ||||||||||||||||||||||||
348 | return QIcon(); never executed: return QIcon(); | 0 | ||||||||||||||||||||||||
349 | - | |||||||||||||||||||||||||
350 | return QIcon(new QFileIconEngine(fi, options)); never executed: return QIcon(new QFileIconEngine(fi, options)); | 0 | ||||||||||||||||||||||||
351 | } | - | ||||||||||||||||||||||||
352 | - | |||||||||||||||||||||||||
353 | /*! | - | ||||||||||||||||||||||||
354 | Returns an icon for the file described by \a info. | - | ||||||||||||||||||||||||
355 | */ | - | ||||||||||||||||||||||||
356 | - | |||||||||||||||||||||||||
357 | QIcon QFileIconProvider::icon(const QFileInfo &info) const | - | ||||||||||||||||||||||||
358 | { | - | ||||||||||||||||||||||||
359 | Q_D(const QFileIconProvider); | - | ||||||||||||||||||||||||
360 | - | |||||||||||||||||||||||||
361 | #if defined(Q_OS_UNIX) && !defined(QT_NO_STYLE_GTK) | - | ||||||||||||||||||||||||
362 | const QByteArray desktopEnvironment = QGuiApplicationPrivate::platformIntegration()->services()->desktopEnvironment(); | - | ||||||||||||||||||||||||
363 | if (desktopEnvironment != QByteArrayLiteral("KDE")) { never executed: return ba;
| 0 | ||||||||||||||||||||||||
364 | QIcon gtkIcon = QGtkStylePrivate::getFilesystemIcon(info); | - | ||||||||||||||||||||||||
365 | if (!gtkIcon.isNull())
| 0 | ||||||||||||||||||||||||
366 | return gtkIcon; never executed: return gtkIcon; | 0 | ||||||||||||||||||||||||
367 | } never executed: end of block | 0 | ||||||||||||||||||||||||
368 | #endif | - | ||||||||||||||||||||||||
369 | - | |||||||||||||||||||||||||
370 | QIcon retIcon = d->getIcon(info); | - | ||||||||||||||||||||||||
371 | if (!retIcon.isNull())
| 0 | ||||||||||||||||||||||||
372 | return retIcon; never executed: return retIcon; | 0 | ||||||||||||||||||||||||
373 | - | |||||||||||||||||||||||||
374 | if (info.isRoot())
| 0 | ||||||||||||||||||||||||
375 | #if defined (Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
376 | { | - | ||||||||||||||||||||||||
377 | UINT type = GetDriveType((wchar_t *)info.absoluteFilePath().utf16()); | - | ||||||||||||||||||||||||
378 | - | |||||||||||||||||||||||||
379 | switch (type) { | - | ||||||||||||||||||||||||
380 | case DRIVE_REMOVABLE: | - | ||||||||||||||||||||||||
381 | return d->getIcon(QStyle::SP_DriveFDIcon); | - | ||||||||||||||||||||||||
382 | case DRIVE_FIXED: | - | ||||||||||||||||||||||||
383 | return d->getIcon(QStyle::SP_DriveHDIcon); | - | ||||||||||||||||||||||||
384 | case DRIVE_REMOTE: | - | ||||||||||||||||||||||||
385 | return d->getIcon(QStyle::SP_DriveNetIcon); | - | ||||||||||||||||||||||||
386 | case DRIVE_CDROM: | - | ||||||||||||||||||||||||
387 | return d->getIcon(QStyle::SP_DriveCDIcon); | - | ||||||||||||||||||||||||
388 | case DRIVE_RAMDISK: | - | ||||||||||||||||||||||||
389 | case DRIVE_UNKNOWN: | - | ||||||||||||||||||||||||
390 | case DRIVE_NO_ROOT_DIR: | - | ||||||||||||||||||||||||
391 | default: | - | ||||||||||||||||||||||||
392 | return d->getIcon(QStyle::SP_DriveHDIcon); | - | ||||||||||||||||||||||||
393 | } | - | ||||||||||||||||||||||||
394 | } | - | ||||||||||||||||||||||||
395 | #else | - | ||||||||||||||||||||||||
396 | return d->getIcon(QStyle::SP_DriveHDIcon); never executed: return d->getIcon(QStyle::SP_DriveHDIcon); | 0 | ||||||||||||||||||||||||
397 | #endif | - | ||||||||||||||||||||||||
398 | - | |||||||||||||||||||||||||
399 | if (info.isFile()) {
| 0 | ||||||||||||||||||||||||
400 | if (info.isSymLink())
| 0 | ||||||||||||||||||||||||
401 | return d->getIcon(QStyle::SP_FileLinkIcon); never executed: return d->getIcon(QStyle::SP_FileLinkIcon); | 0 | ||||||||||||||||||||||||
402 | else | - | ||||||||||||||||||||||||
403 | return d->getIcon(QStyle::SP_FileIcon); never executed: return d->getIcon(QStyle::SP_FileIcon); | 0 | ||||||||||||||||||||||||
404 | } | - | ||||||||||||||||||||||||
405 | if (info.isDir()) {
| 0 | ||||||||||||||||||||||||
406 | if (info.isSymLink()) {
| 0 | ||||||||||||||||||||||||
407 | return d->getIcon(QStyle::SP_DirLinkIcon); never executed: return d->getIcon(QStyle::SP_DirLinkIcon); | 0 | ||||||||||||||||||||||||
408 | } else { | - | ||||||||||||||||||||||||
409 | if (info.absoluteFilePath() == d->homePath) {
| 0 | ||||||||||||||||||||||||
410 | return d->getIcon(QStyle::SP_DirHomeIcon); never executed: return d->getIcon(QStyle::SP_DirHomeIcon); | 0 | ||||||||||||||||||||||||
411 | } else { | - | ||||||||||||||||||||||||
412 | return d->getIcon(QStyle::SP_DirIcon); never executed: return d->getIcon(QStyle::SP_DirIcon); | 0 | ||||||||||||||||||||||||
413 | } | - | ||||||||||||||||||||||||
414 | } | - | ||||||||||||||||||||||||
415 | } | - | ||||||||||||||||||||||||
416 | return QIcon(); never executed: return QIcon(); | 0 | ||||||||||||||||||||||||
417 | } | - | ||||||||||||||||||||||||
418 | - | |||||||||||||||||||||||||
419 | /*! | - | ||||||||||||||||||||||||
420 | Returns the type of the file described by \a info. | - | ||||||||||||||||||||||||
421 | */ | - | ||||||||||||||||||||||||
422 | - | |||||||||||||||||||||||||
423 | QString QFileIconProvider::type(const QFileInfo &info) const | - | ||||||||||||||||||||||||
424 | { | - | ||||||||||||||||||||||||
425 | if (info.isRoot())
| 0 | ||||||||||||||||||||||||
426 | return QApplication::translate("QFileDialog", "Drive"); never executed: return QApplication::translate("QFileDialog", "Drive"); | 0 | ||||||||||||||||||||||||
427 | if (info.isFile()) {
| 0 | ||||||||||||||||||||||||
428 | if (!info.suffix().isEmpty()) {
| 0 | ||||||||||||||||||||||||
429 | //: %1 is a file name suffix, for example txt | - | ||||||||||||||||||||||||
430 | return QApplication::translate("QFileDialog", "%1 File").arg(info.suffix()); never executed: return QApplication::translate("QFileDialog", "%1 File").arg(info.suffix()); | 0 | ||||||||||||||||||||||||
431 | } | - | ||||||||||||||||||||||||
432 | return QApplication::translate("QFileDialog", "File"); never executed: return QApplication::translate("QFileDialog", "File"); | 0 | ||||||||||||||||||||||||
433 | } | - | ||||||||||||||||||||||||
434 | - | |||||||||||||||||||||||||
435 | if (info.isDir())
| 0 | ||||||||||||||||||||||||
436 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
437 | return QApplication::translate("QFileDialog", "File Folder", "Match Windows Explorer"); | - | ||||||||||||||||||||||||
438 | #else | - | ||||||||||||||||||||||||
439 | return QApplication::translate("QFileDialog", "Folder", "All other platforms"); never executed: return QApplication::translate("QFileDialog", "Folder", "All other platforms"); | 0 | ||||||||||||||||||||||||
440 | #endif | - | ||||||||||||||||||||||||
441 | // Windows - "File Folder" | - | ||||||||||||||||||||||||
442 | // OS X - "Folder" | - | ||||||||||||||||||||||||
443 | // Konqueror - "Folder" | - | ||||||||||||||||||||||||
444 | // Nautilus - "folder" | - | ||||||||||||||||||||||||
445 | - | |||||||||||||||||||||||||
446 | if (info.isSymLink())
| 0 | ||||||||||||||||||||||||
447 | #ifdef Q_OS_MAC | - | ||||||||||||||||||||||||
448 | return QApplication::translate("QFileDialog", "Alias", "OS X Finder"); | - | ||||||||||||||||||||||||
449 | #else | - | ||||||||||||||||||||||||
450 | return QApplication::translate("QFileDialog", "Shortcut", "All other platforms"); never executed: return QApplication::translate("QFileDialog", "Shortcut", "All other platforms"); | 0 | ||||||||||||||||||||||||
451 | #endif | - | ||||||||||||||||||||||||
452 | // OS X - "Alias" | - | ||||||||||||||||||||||||
453 | // Windows - "Shortcut" | - | ||||||||||||||||||||||||
454 | // Konqueror - "Folder" or "TXT File" i.e. what it is pointing to | - | ||||||||||||||||||||||||
455 | // Nautilus - "link to folder" or "link to object file", same as Konqueror | - | ||||||||||||||||||||||||
456 | - | |||||||||||||||||||||||||
457 | return QApplication::translate("QFileDialog", "Unknown"); never executed: return QApplication::translate("QFileDialog", "Unknown"); | 0 | ||||||||||||||||||||||||
458 | } | - | ||||||||||||||||||||||||
459 | - | |||||||||||||||||||||||||
460 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |