/**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtGui module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 or version 3 as published by the Free ** Software Foundation and appearing in the file LICENSE.LGPLv21 and ** LICENSE.LGPLv3 included in the packaging of this file. Please review the ** following information to ensure the GNU Lesser General Public License ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** As a special exception, The Qt Company gives you certain additional ** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qfileiconprovider.h" #include "qfileiconprovider_p.h" #ifndef QT_NO_FILEICONPROVIDER #include #include #include #include #include #include QT_BEGIN_NAMESPACE /*! \class QFileIconProvider \brief The QFileIconProvider class provides file icons for the QDirModel and the QFileSystemModel classes. */ /*! \enum QFileIconProvider::IconType \value Computer \value Desktop \value Trashcan \value Network \value Drive \value Folder \value File */ QFileIconProviderPrivate::QFileIconProviderPrivate() : homePath(QDir::home().absolutePath()), useCustomDirectoryIcons(true) { } void QFileIconProviderPrivate::setUseCustomDirectoryIcons(bool enable) { useCustomDirectoryIcons = enable; } QIcon QFileIconProviderPrivate::getIcon(QStyle::StandardPixmap name) const { switch (name) { case QStyle::SP_FileIcon: if (file.isNull()) file = QApplication::style()->standardIcon(name); return file; case QStyle::SP_FileLinkIcon: if (fileLink.isNull()) fileLink = QApplication::style()->standardIcon(name); return fileLink; case QStyle::SP_DirIcon: if (directory.isNull()) directory = QApplication::style()->standardIcon(name); return directory; case QStyle::SP_DirLinkIcon: if (directoryLink.isNull()) directoryLink = QApplication::style()->standardIcon(name); return directoryLink; case QStyle::SP_DriveHDIcon: if (harddisk.isNull()) harddisk = QApplication::style()->standardIcon(name); return harddisk; case QStyle::SP_DriveFDIcon: if (floppy.isNull()) floppy = QApplication::style()->standardIcon(name); return floppy; case QStyle::SP_DriveCDIcon: if (cdrom.isNull()) cdrom = QApplication::style()->standardIcon(name); return cdrom; case QStyle::SP_DriveNetIcon: if (network.isNull()) network = QApplication::style()->standardIcon(name); return network; case QStyle::SP_ComputerIcon: if (computer.isNull()) computer = QApplication::style()->standardIcon(name); return computer; case QStyle::SP_DesktopIcon: if (desktop.isNull()) desktop = QApplication::style()->standardIcon(name); return desktop; case QStyle::SP_TrashIcon: if (trashcan.isNull()) trashcan = QApplication::style()->standardIcon(name); return trashcan; case QStyle::SP_DirHomeIcon: if (home.isNull()) home = QApplication::style()->standardIcon(name); return home; default: return QIcon(); } return QIcon(); } /*! Constructs a file icon provider. */ QFileIconProvider::QFileIconProvider() : d_ptr(new QFileIconProviderPrivate) { } /*! Destroys the file icon provider. */ QFileIconProvider::~QFileIconProvider() { } /*! Returns an icon set for the given \a type. */ QIcon QFileIconProvider::icon(IconType type) const { Q_D(const QFileIconProvider); switch (type) { case Computer: return d->getIcon(QStyle::SP_ComputerIcon); case Desktop: return d->getIcon(QStyle::SP_DesktopIcon); case Trashcan: return d->getIcon(QStyle::SP_TrashIcon); case Network: return d->getIcon(QStyle::SP_DriveNetIcon); case Drive: return d->getIcon(QStyle::SP_DriveHDIcon); case Folder: return d->getIcon(QStyle::SP_DirIcon); case File: return d->getIcon(QStyle::SP_FileIcon); default: break; }; return QIcon(); } /*! Returns an icon for the file described by \a info. */ QIcon QFileIconProvider::icon(const QFileInfo &info) const { Q_D(const QFileIconProvider); QIcon platformIcon = qt_guiPlatformPlugin()->fileSystemIcon(info); if (!platformIcon.isNull()) return platformIcon; if (info.isRoot()) return d->getIcon(QStyle::SP_DriveHDIcon); if (info.isFile()) { if (info.isSymLink()) return d->getIcon(QStyle::SP_FileLinkIcon); else return d->getIcon(QStyle::SP_FileIcon); } if (info.isDir()) { if (info.isSymLink()) { return d->getIcon(QStyle::SP_DirLinkIcon); } else { if (info.absoluteFilePath() == d->homePath) { return d->getIcon(QStyle::SP_DirHomeIcon); } else { return d->getIcon(QStyle::SP_DirIcon); } } } return QIcon(); } /*! Returns the type of the file described by \a info. */ QString QFileIconProvider::type(const QFileInfo &info) const { if (info.isRoot()) return QApplication::translate("QFileDialog", "Drive"); if (info.isFile()) { if (!info.suffix().isEmpty()) return info.suffix() + QLatin1Char(' ') + QApplication::translate("QFileDialog", "File"); return QApplication::translate("QFileDialog", "File"); } if (info.isDir()) return QApplication::translate("QFileDialog", "Folder", "All other platforms"); // Konqueror - "Folder" // Nautilus - "folder" if (info.isSymLink()) return QApplication::translate("QFileDialog", "Shortcut", "All other platforms"); // Konqueror - "Folder" or "TXT File" i.e. what it is pointing to // Nautilus - "link to folder" or "link to object file", same as Konqueror return QApplication::translate("QFileDialog", "Unknown"); } QT_END_NAMESPACE #endif