Qt 4.8
Public Types | Public Functions | Properties | Friends | List of all members
QFileIconProvider Class Reference

The QFileIconProvider class provides file icons for the QDirModel and the QFileSystemModel classes. More...

#include <qfileiconprovider.h>

Public Types

enum  IconType {
  Computer, Desktop, Trashcan, Network,
  Drive, Folder, File
}
 

Public Functions

virtual QIcon icon (IconType type) const
 Returns an icon set for the given type. More...
 
virtual QIcon icon (const QFileInfo &info) const
 Returns an icon for the file described by info. More...
 
 QFileIconProvider ()
 Constructs a file icon provider. More...
 
virtual QString type (const QFileInfo &info) const
 Returns the type of the file described by info. More...
 
virtual ~QFileIconProvider ()
 Destroys the file icon provider. More...
 

Properties

QScopedPointer< QFileIconProviderPrivated_ptr
 

Friends

class QFileDialog
 

Detailed Description

The QFileIconProvider class provides file icons for the QDirModel and the QFileSystemModel classes.

Definition at line 59 of file qfileiconprovider.h.

Enumerations

◆ IconType

  • Computer
  • Desktop
  • Trashcan
  • Network
  • Drive
  • Folder
  • File
Enumerator
Computer 
Desktop 
Trashcan 
Network 
Drive 
Folder 
File 

Definition at line 64 of file qfileiconprovider.h.

Constructors and Destructors

◆ QFileIconProvider()

QFileIconProvider::QFileIconProvider ( )

Constructs a file icon provider.

Definition at line 165 of file qfileiconprovider.cpp.

167 {
168 }
QScopedPointer< QFileIconProviderPrivate > d_ptr

◆ ~QFileIconProvider()

QFileIconProvider::~QFileIconProvider ( )
virtual

Destroys the file icon provider.

Definition at line 175 of file qfileiconprovider.cpp.

176 {
177 }

Functions

◆ icon() [1/2]

QIcon QFileIconProvider::icon ( IconType  type) const
virtual

Returns an icon set for the given type.

Definition at line 183 of file qfileiconprovider.cpp.

Referenced by QFileInfoGatherer::getInfo(), icon(), QUrlModel::setUrl(), and QFileSystemModelPrivate::QFileSystemNode::updateIcon().

184 {
185  Q_D(const QFileIconProvider);
186  switch (type) {
187  case Computer:
188  return d->getIcon(QStyle::SP_ComputerIcon);
189  case Desktop:
190  return d->getIcon(QStyle::SP_DesktopIcon);
191  case Trashcan:
192  return d->getIcon(QStyle::SP_TrashIcon);
193  case Network:
194  return d->getIcon(QStyle::SP_DriveNetIcon);
195  case Drive:
196  return d->getIcon(QStyle::SP_DriveHDIcon);
197  case Folder:
198  return d->getIcon(QStyle::SP_DirIcon);
199  case File:
200  return d->getIcon(QStyle::SP_FileIcon);
201  default:
202  break;
203  };
204  return QIcon();
205 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
virtual QString type(const QFileInfo &info) const
Returns the type of the file described by info.
The QFileIconProvider class provides file icons for the QDirModel and the QFileSystemModel classes...
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ icon() [2/2]

QIcon QFileIconProvider::icon ( const QFileInfo info) const
virtual

Returns an icon for the file described by info.

Definition at line 410 of file qfileiconprovider.cpp.

411 {
412  Q_D(const QFileIconProvider);
413 
414  QIcon platformIcon = qt_guiPlatformPlugin()->fileSystemIcon(info);
415  if (!platformIcon.isNull())
416  return platformIcon;
417 
418 #if defined(Q_WS_X11) && !defined(QT_NO_STYLE_GTK)
419  if (X11->desktopEnvironment == DE_GNOME) {
421  if (!gtkIcon.isNull())
422  return gtkIcon;
423  }
424 #endif
425 
426 #ifdef Q_WS_MAC
427  QIcon retIcon = d->getMacIcon(info);
428  if (!retIcon.isNull())
429  return retIcon;
430 #elif defined Q_WS_WIN
431  QIcon icon = d->getWinIcon(info);
432  if (!icon.isNull())
433  return icon;
434 #endif
435  if (info.isRoot())
436 #if defined (Q_WS_WIN) && !defined(Q_WS_WINCE)
437  {
438  UINT type = GetDriveType((wchar_t *)info.absoluteFilePath().utf16());
439 
440  switch (type) {
441  case DRIVE_REMOVABLE:
442  return d->getIcon(QStyle::SP_DriveFDIcon);
443  case DRIVE_FIXED:
444  return d->getIcon(QStyle::SP_DriveHDIcon);
445  case DRIVE_REMOTE:
446  return d->getIcon(QStyle::SP_DriveNetIcon);
447  case DRIVE_CDROM:
448  return d->getIcon(QStyle::SP_DriveCDIcon);
449  case DRIVE_RAMDISK:
450  case DRIVE_UNKNOWN:
451  case DRIVE_NO_ROOT_DIR:
452  default:
453  return d->getIcon(QStyle::SP_DriveHDIcon);
454  }
455  }
456 #else
457  return d->getIcon(QStyle::SP_DriveHDIcon);
458 #endif
459  if (info.isFile()) {
460  if (info.isSymLink())
461  return d->getIcon(QStyle::SP_FileLinkIcon);
462  else
463  return d->getIcon(QStyle::SP_FileIcon);
464  }
465  if (info.isDir()) {
466  if (info.isSymLink()) {
467  return d->getIcon(QStyle::SP_DirLinkIcon);
468  } else {
469  if (info.absoluteFilePath() == d->homePath) {
470  return d->getIcon(QStyle::SP_DirHomeIcon);
471  } else {
472  return d->getIcon(QStyle::SP_DirIcon);
473  }
474  }
475  }
476  return QIcon();
477 }
double d
Definition: qnumeric_p.h:62
#define Q_WS_WIN
Defined on Windows.
Definition: qglobal.h:921
virtual QIcon icon(IconType type) const
Returns an icon set for the given type.
QString absoluteFilePath() const
Returns an absolute path including the file name.
Definition: qfileinfo.cpp:534
QGuiPlatformPlugin * qt_guiPlatformPlugin()
Return (an construct if necesseray) the Gui Platform plugin.
#define X11
Definition: qt_x11_p.h:724
#define Q_D(Class)
Definition: qglobal.h:2482
virtual QString type(const QFileInfo &info) const
Returns the type of the file described by info.
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
Definition: qfileinfo.cpp:990
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
The QFileIconProvider class provides file icons for the QDirModel and the QFileSystemModel classes...
static QIcon getFilesystemIcon(const QFileInfo &)
bool isRoot() const
Returns true if the object points to a directory or to a symbolic link to a directory, and that directory is the root directory; otherwise returns false.
Definition: qfileinfo.cpp:1062
bool isFile() const
Returns true if this object points to a file or to a symbolic link to a file.
Definition: qfileinfo.cpp:971
#define Q_WS_WINCE
Definition: qglobal.h:895
virtual QIcon fileSystemIcon(const QFileInfo &)
bool isSymLink() const
Returns true if this object points to a symbolic link (or to a shortcut on Windows); otherwise return...
Definition: qfileinfo.cpp:1044
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ type()

QString QFileIconProvider::type ( const QFileInfo info) const
virtual

Returns the type of the file described by info.

Definition at line 483 of file qfileiconprovider.cpp.

Referenced by QFileInfoGatherer::getInfo(), icon(), QFileSystemModelPrivate::QFileSystemNode::retranslateStrings(), and QDirModelPrivate::type().

484 {
485  if (info.isRoot())
486  return QApplication::translate("QFileDialog", "Drive");
487  if (info.isFile()) {
488  if (!info.suffix().isEmpty())
489  return info.suffix() + QLatin1Char(' ') + QApplication::translate("QFileDialog", "File");
490  return QApplication::translate("QFileDialog", "File");
491  }
492 
493  if (info.isDir())
494 #ifdef Q_WS_WIN
495  return QApplication::translate("QFileDialog", "File Folder", "Match Windows Explorer");
496 #else
497  return QApplication::translate("QFileDialog", "Folder", "All other platforms");
498 #endif
499  // Windows - "File Folder"
500  // OS X - "Folder"
501  // Konqueror - "Folder"
502  // Nautilus - "folder"
503 
504  if (info.isSymLink())
505 #ifdef Q_OS_MAC
506  return QApplication::translate("QFileDialog", "Alias", "Mac OS X Finder");
507 #else
508  return QApplication::translate("QFileDialog", "Shortcut", "All other platforms");
509 #endif
510  // OS X - "Alias"
511  // Windows - "Shortcut"
512  // Konqueror - "Folder" or "TXT File" i.e. what it is pointing to
513  // Nautilus - "link to folder" or "link to object file", same as Konqueror
514 
515  return QApplication::translate("QFileDialog", "Unknown");
516 }
#define Q_WS_WIN
Defined on Windows.
Definition: qglobal.h:921
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
#define Q_OS_MAC
Defined on MAC OS (synonym for Darwin).
Definition: qglobal.h:274
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
Definition: qfileinfo.cpp:990
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
bool isRoot() const
Returns true if the object points to a directory or to a symbolic link to a directory, and that directory is the root directory; otherwise returns false.
Definition: qfileinfo.cpp:1062
QString suffix() const
Returns the suffix of the file.
Definition: qfileinfo.cpp:834
bool isFile() const
Returns true if this object points to a file or to a symbolic link to a file.
Definition: qfileinfo.cpp:971
bool isSymLink() const
Returns true if this object points to a symbolic link (or to a shortcut on Windows); otherwise return...
Definition: qfileinfo.cpp:1044
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

Friends and Related Functions

◆ QFileDialog

friend class QFileDialog
friend

Definition at line 73 of file qfileiconprovider.h.

Properties

◆ d_ptr

QScopedPointer<QFileIconProviderPrivate> QFileIconProvider::d_ptr
private

Definition at line 71 of file qfileiconprovider.h.


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