Qt 4.8
Public Functions | Public Variables | Properties | List of all members
QFileIconProviderPrivate Class Reference

#include <qfileiconprovider_p.h>

Public Functions

QIcon getIcon (QStyle::StandardPixmap name) const
 
QIcon getWinIcon (const QFileInfo &fi) const
 
 QFileIconProviderPrivate ()
 
void setUseCustomDirectoryIcons (bool enable)
 

Public Variables

const QString homePath
 
QFileIconProviderq_ptr
 

Properties

QIcon cdrom
 
QIcon computer
 
QIcon desktop
 
QIcon directory
 
QIcon directoryLink
 
QIcon file
 
QIcon fileLink
 
QIcon floppy
 
QIcon generic
 
QIcon harddisk
 
QIcon home
 
QIcon network
 
QIcon ram
 
QIcon trashcan
 
bool useCustomDirectoryIcons
 

Detailed Description

Definition at line 54 of file qfileiconprovider_p.h.

Constructors and Destructors

◆ QFileIconProviderPrivate()

QFileIconProviderPrivate::QFileIconProviderPrivate ( )

Definition at line 94 of file qfileiconprovider.cpp.

94  :
95  homePath(QDir::home().absolutePath()), useCustomDirectoryIcons(true)
96 {
97 }
static QDir home()
Returns the user&#39;s home directory.
Definition: qdir.h:212

Functions

◆ getIcon()

QIcon QFileIconProviderPrivate::getIcon ( QStyle::StandardPixmap  name) const

Definition at line 104 of file qfileiconprovider.cpp.

105 {
106  switch (name) {
107  case QStyle::SP_FileIcon:
108  if (file.isNull())
110  return file;
112  if (fileLink.isNull())
114  return fileLink;
115  case QStyle::SP_DirIcon:
116  if (directory.isNull())
118  return directory;
120  if (directoryLink.isNull())
122  return directoryLink;
124  if (harddisk.isNull())
126  return harddisk;
128  if (floppy.isNull())
130  return floppy;
132  if (cdrom.isNull())
134  return cdrom;
136  if (network.isNull())
138  return network;
140  if (computer.isNull())
142  return computer;
144  if (desktop.isNull())
146  return desktop;
148  if (trashcan.isNull())
150  return trashcan;
152  if (home.isNull())
154  return home;
155  default:
156  return QIcon();
157  }
158  return QIcon();
159 }
static QStyle * style()
Returns the application&#39;s style object.
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option=0, const QWidget *widget=0) const
Returns an icon for the given standardIcon.
Definition: qstyle.cpp:2327
const char * name
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ getWinIcon()

QIcon QFileIconProviderPrivate::getWinIcon ( const QFileInfo fi) const

Definition at line 221 of file qfileiconprovider.cpp.

222 {
223  QIcon retIcon;
224  static int defaultFolderIIcon = -1;
225 
226  QString key;
227  QPixmap pixmap;
228  // If it's a file, non-{exe,lnk,ico} then we might have it cached already
229  if (isCacheable(fileInfo)) {
230  const QString fileExtension = QLatin1Char('.') + fileInfo.suffix().toUpper();
231  key = QLatin1String("qt_") + fileExtension;
232  QPixmapCache::find(key, pixmap);
233  if (!pixmap.isNull()) {
234  retIcon.addPixmap(pixmap);
235  if (QPixmapCache::find(key + QLatin1Char('l'), pixmap))
236  retIcon.addPixmap(pixmap);
237  return retIcon;
238  }
239  }
240 
241  const bool cacheableDirIcon = fileInfo.isDir() && !fileInfo.isRoot();
242  if (!useCustomDirectoryIcons && defaultFolderIIcon >= 0 && cacheableDirIcon) {
243  // We already have the default folder icon, just return it
244  key = QString::fromLatin1("qt_dir_%1").arg(defaultFolderIIcon);
245  QPixmapCache::find(key, pixmap);
246  if (!pixmap.isNull()) {
247  retIcon.addPixmap(pixmap);
248  if (QPixmapCache::find(key + QLatin1Char('l'), pixmap))
249  retIcon.addPixmap(pixmap);
250  return retIcon;
251  }
252  }
253 
254  /* We don't use the variable, but by storing it statically, we
255  * ensure CoInitialize is only called once. */
256  static HRESULT comInit = CoInitialize(NULL);
257  Q_UNUSED(comInit);
258 
259  SHFILEINFO info;
260  unsigned long val = 0;
261 
262  //Get the small icon
263  unsigned int flags =
264 #ifndef Q_OS_WINCE
265  SHGFI_ICON|SHGFI_SYSICONINDEX|SHGFI_ADDOVERLAYS|SHGFI_OVERLAYINDEX;
266 #else
267  SHGFI_SYSICONINDEX;
268 #endif
269 
270  if (cacheableDirIcon && !useCustomDirectoryIcons) {
271  flags |= SHGFI_USEFILEATTRIBUTES;
272  val = SHGetFileInfo(L"dummy",
273  FILE_ATTRIBUTE_DIRECTORY, &info,
274  sizeof(SHFILEINFO), flags | SHGFI_SMALLICON);
275  } else {
276  val = SHGetFileInfo((const wchar_t *)QDir::toNativeSeparators(fileInfo.filePath()).utf16(),
277  0, &info, sizeof(SHFILEINFO), flags | SHGFI_SMALLICON);
278  }
279 
280  // Even if GetFileInfo returns a valid result, hIcon can be empty in some cases
281  if (val && info.hIcon) {
282  if (fileInfo.isDir() && !fileInfo.isRoot()) {
283  if (!useCustomDirectoryIcons && defaultFolderIIcon < 0)
284  defaultFolderIIcon = info.iIcon;
285  //using the unique icon index provided by windows save us from duplicate keys
286  key = QString::fromLatin1("qt_dir_%1").arg(info.iIcon);
287  QPixmapCache::find(key, pixmap);
288  if (!pixmap.isNull()) {
289  retIcon.addPixmap(pixmap);
290  if (QPixmapCache::find(key + QLatin1Char('l'), pixmap))
291  retIcon.addPixmap(pixmap);
292  DestroyIcon(info.hIcon);
293  return retIcon;
294  }
295  }
296  if (pixmap.isNull()) {
297 #ifndef Q_OS_WINCE
298  pixmap = QPixmap::fromWinHICON(info.hIcon);
299 #else
300  pixmap = QPixmap::fromWinHICON(ImageList_GetIcon((HIMAGELIST) val, info.iIcon, ILD_NORMAL));
301 #endif
302  if (!pixmap.isNull()) {
303  retIcon.addPixmap(pixmap);
304  if (!key.isEmpty())
305  QPixmapCache::insert(key, pixmap);
306  }
307  else {
308  qWarning("QFileIconProviderPrivate::getWinIcon() no small icon found");
309  }
310  }
311  DestroyIcon(info.hIcon);
312  }
313 
314  //Get the big icon
315  val = SHGetFileInfo((const wchar_t *)QDir::toNativeSeparators(fileInfo.filePath()).utf16(),
316  0, &info, sizeof(SHFILEINFO), flags | SHGFI_LARGEICON);
317 
318  if (val && info.hIcon) {
319  if (fileInfo.isDir() && !fileInfo.isRoot()) {
320  //using the unique icon index provided by windows save us from duplicate keys
321  key = QString::fromLatin1("qt_dir_%1").arg(info.iIcon);
322  }
323 #ifndef Q_OS_WINCE
324  pixmap = QPixmap::fromWinHICON(info.hIcon);
325 #else
326  pixmap = QPixmap::fromWinHICON(ImageList_GetIcon((HIMAGELIST) val, info.iIcon, ILD_NORMAL));
327 #endif
328  if (!pixmap.isNull()) {
329  retIcon.addPixmap(pixmap);
330  if (!key.isEmpty())
331  QPixmapCache::insert(key + QLatin1Char('l'), pixmap);
332  }
333  else {
334  qWarning("QFileIconProviderPrivate::getWinIcon() no large icon found");
335  }
336  DestroyIcon(info.hIcon);
337  }
338  return retIcon;
339 }
static bool isCacheable(const QFileInfo &fi)
static mach_timebase_info_data_t info
void addPixmap(const QPixmap &pixmap, Mode mode=Normal, State state=Off)
Adds pixmap to the icon, as a specialization for mode and state.
Definition: qicon.cpp:814
#define SHGFI_OVERLAYINDEX
static QPixmap fromWinHICON(HICON hicon)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define CoInitialize(x)
static QPixmap * find(const QString &key)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
Q_CORE_EXPORT void qWarning(const char *,...)
#define SHGFI_ADDOVERLAYS
long HRESULT
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
int key
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
static QString toNativeSeparators(const QString &pathName)
Returns pathName with the &#39;/&#39; separators converted to separators that are appropriate for the underly...
Definition: qdir.cpp:812
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ setUseCustomDirectoryIcons()

void QFileIconProviderPrivate::setUseCustomDirectoryIcons ( bool  enable)

Definition at line 99 of file qfileiconprovider.cpp.

100 {
101  useCustomDirectoryIcons = enable;
102 }

Properties

◆ cdrom

QIcon QFileIconProviderPrivate::cdrom
mutableprivate

Definition at line 78 of file qfileiconprovider_p.h.

Referenced by getIcon().

◆ computer

QIcon QFileIconProviderPrivate::computer
mutableprivate

Definition at line 81 of file qfileiconprovider_p.h.

Referenced by getIcon().

◆ desktop

QIcon QFileIconProviderPrivate::desktop
mutableprivate

Definition at line 82 of file qfileiconprovider_p.h.

Referenced by getIcon().

◆ directory

QIcon QFileIconProviderPrivate::directory
mutableprivate

Definition at line 74 of file qfileiconprovider_p.h.

Referenced by getIcon().

◆ directoryLink

QIcon QFileIconProviderPrivate::directoryLink
mutableprivate

Definition at line 75 of file qfileiconprovider_p.h.

Referenced by getIcon().

◆ file

QIcon QFileIconProviderPrivate::file
mutableprivate

Definition at line 72 of file qfileiconprovider_p.h.

Referenced by getIcon().

◆ fileLink

QIcon QFileIconProviderPrivate::fileLink
mutableprivate

Definition at line 73 of file qfileiconprovider_p.h.

Referenced by getIcon().

◆ floppy

QIcon QFileIconProviderPrivate::floppy
mutableprivate

Definition at line 77 of file qfileiconprovider_p.h.

Referenced by getIcon().

◆ generic

QIcon QFileIconProviderPrivate::generic
mutableprivate

Definition at line 84 of file qfileiconprovider_p.h.

◆ harddisk

QIcon QFileIconProviderPrivate::harddisk
mutableprivate

Definition at line 76 of file qfileiconprovider_p.h.

Referenced by getIcon().

◆ home

QIcon QFileIconProviderPrivate::home
mutableprivate

Definition at line 85 of file qfileiconprovider_p.h.

Referenced by getIcon().

◆ homePath

const QString QFileIconProviderPrivate::homePath

Definition at line 68 of file qfileiconprovider_p.h.

◆ network

QIcon QFileIconProviderPrivate::network
mutableprivate

Definition at line 80 of file qfileiconprovider_p.h.

Referenced by getIcon().

◆ q_ptr

QFileIconProvider* QFileIconProviderPrivate::q_ptr

Definition at line 67 of file qfileiconprovider_p.h.

◆ ram

QIcon QFileIconProviderPrivate::ram
mutableprivate

Definition at line 79 of file qfileiconprovider_p.h.

◆ trashcan

QIcon QFileIconProviderPrivate::trashcan
mutableprivate

Definition at line 83 of file qfileiconprovider_p.h.

Referenced by getIcon().

◆ useCustomDirectoryIcons

bool QFileIconProviderPrivate::useCustomDirectoryIcons
private

Definition at line 71 of file qfileiconprovider_p.h.

Referenced by setUseCustomDirectoryIcons().


The documentation for this class was generated from the following files: