예제 #1
0
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())
#ifdef Q_WS_WIN
        return QApplication::translate("QFileDialog", "File Folder", "Match Windows Explorer");
#else
        return QApplication::translate("QFileDialog", "Folder", "All other platforms");
#endif
    // Windows   - "File Folder"
    // OS X      - "Folder"
    // Konqueror - "Folder"
    // Nautilus  - "folder"

    if (info.isSymLink())
#ifdef Q_OS_MAC
        return QApplication::translate("QFileDialog", "Alias", "Mac OS X Finder");
#else
        return QApplication::translate("QFileDialog", "Shortcut", "All other platforms");
#endif
    // OS X      - "Alias"
    // Windows   - "Shortcut"
    // 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");
}
예제 #2
0
QIcon QFileIconProviderEx::icon(const QFileInfo &info) const
{
	if(info.isFile())
	{
		return m_emptyIcon;
	}
	else if(info.isRoot())
	{
		switch(GetDriveType(QWCHAR(QDir::toNativeSeparators(info.absoluteFilePath()))))
		{
		case DRIVE_CDROM:
			return m_cdromIcon;
			break;
		case DRIVE_REMOVABLE:
			return m_floppyIcon;
			break;
		case DRIVE_REMOTE:
			return m_networkIcon;
			break;
		default:
			return m_driveIcon;
			break;
		}
	}
	else
	{
		const QString filePath = info.filePath();
		if(m_homeDir.compare(filePath, Qt::CaseInsensitive) == 0)
		{
			return m_homeIcon;
		}
		else if(m_desktopDir.compare(filePath, Qt::CaseInsensitive) == 0)
		{
			return m_desktopIcon;
		}
		else if(m_musicDir.compare(filePath, Qt::CaseInsensitive) == 0)
		{
			return m_musicIcon;
		}
		else if(m_moviesDir.compare(filePath, Qt::CaseInsensitive) == 0)
		{
			return m_moviesIcon;
		}
		else if(m_picturesDir.compare(filePath, Qt::CaseInsensitive) == 0)
		{
			return m_picturesIcon;
		}
		else if(m_installDir.compare(filePath, Qt::CaseInsensitive) == 0)
		{
			return m_heartIcon;
		}
		else
		{
			return  m_folderIcon;
		}
	}
}
QVariant SimpleFSModel::nameData(const QFileInfo &fileInfo, int role) const
{
    switch (role)
    {
        case Qt::DisplayRole:
        {
            if (fileInfo.isRoot())
                return fileInfo.absoluteFilePath();
            else
                return fileInfo.fileName();
        }
        case Qt::DecorationRole:
        {
            return metaProvider_->icon(fileInfo);
        }
        default:
        {
            return QVariant();
        }
    }

    Q_UNREACHABLE();
}
예제 #4
0
static QVariant loadDir(const QFileInfo &fi)
{
    QString str;
    QTextStream s(&str, QIODevice::WriteOnly);

    s << "<HTML>\n";
    s << " <HEAD>\n";
    s << "  <TITLE>" << Qt::escape(QDir::toNativeSeparators(fi.filePath())) << "</TITLE>\n";
    s << " </HEAD>\n";
    s << " <BODY>\n";
    s << "<H1>" << Qt::escape(QDir::toNativeSeparators(fi.filePath())) << "</H1>\n";
    s << "<HR><PRE>\n";

    if (!fi.isRoot())
        s << "<IMG SRC=\":/icons16/go-up.png\" ALT=\"[UP]\"> <A HREF=\""
          << QUrl::fromLocalFile(fi.path()).toString() << "\">..</A>\n";

    QString dirsep = QDir::toNativeSeparators("/");
    QDir d(fi.filePath());
    const QFileInfoList list = d.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot,
                                               QDir::Name | QDir::IgnoreCase);
    foreach (const QFileInfo &entry, list)
        if (entry.isDir())
            s << "<IMG SRC=\":/icons16/folder.png\" ALT=\"[DIR]\"> <A HREF=\""
              << QUrl::fromLocalFile(entry.filePath()).toString()
              << "\">" << Qt::escape(entry.fileName()) << dirsep << "</A>\n";
        else
            s << "<IMG SRC=\":/icons16/file.png\" ALT=\"[FILE]\"> <A HREF=\""
              << QUrl::fromLocalFile(entry.filePath()).toString()
              << "\">" << Qt::escape(entry.fileName()) << "</A>\n";

    s << "</PRE><HR>\n";
    s << "</BODY></HTML>\n";

    return str;
}
예제 #5
0
QIcon QFileIconProvider::icon(const QFileInfo &info) const
{
    Q_D(const QFileIconProvider);

    QIcon platformIcon = qt_guiPlatformPlugin()->fileSystemIcon(info);
    if (!platformIcon.isNull())
        return platformIcon;

#if defined(Q_WS_X11) && !defined(QT_NO_STYLE_GTK)
    if (X11->desktopEnvironment == DE_GNOME) {
        QIcon gtkIcon = QGtkStylePrivate::getFilesystemIcon(info);
        if (!gtkIcon.isNull())
            return gtkIcon;
    }
#endif

#ifdef Q_WS_MAC
    QIcon retIcon = d->getMacIcon(info);
    if (!retIcon.isNull())
        return retIcon;
#elif defined Q_WS_WIN
    QIcon icon = d->getWinIcon(info);
    if (!icon.isNull())
        return icon;
#elif defined Q_WS_HAIKU
    QIcon icon = d->getHaikuIcon(info);
    if (!icon.isNull())
        return icon;
#endif
    if (info.isRoot())
#if defined (Q_WS_WIN) && !defined(Q_WS_WINCE)
    {
        UINT type = GetDriveType((wchar_t *)info.absoluteFilePath().utf16());

        switch (type) {
        case DRIVE_REMOVABLE:
            return d->getIcon(QStyle::SP_DriveFDIcon);
        case DRIVE_FIXED:
            return d->getIcon(QStyle::SP_DriveHDIcon);
        case DRIVE_REMOTE:
            return d->getIcon(QStyle::SP_DriveNetIcon);
        case DRIVE_CDROM:
            return d->getIcon(QStyle::SP_DriveCDIcon);
        case DRIVE_RAMDISK:
        case DRIVE_UNKNOWN:
        case DRIVE_NO_ROOT_DIR:
        default:
            return d->getIcon(QStyle::SP_DriveHDIcon);
        }
    }
#else
    return d->getIcon(QStyle::SP_DriveHDIcon);
#endif
    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();
}
예제 #6
0
QIcon QFileIconProviderPrivate::getWinIcon(const QFileInfo &fileInfo) const
{
    QIcon retIcon;
    static int defaultFolderIIcon = -1;

    QString key;
    QPixmap pixmap;
    // If it's a file, non-{exe,lnk,ico} then we might have it cached already
    if (isCacheable(fileInfo)) {
        const QString fileExtension = QLatin1Char('.') + fileInfo.suffix().toUpper();
        key = QLatin1String("qt_") + fileExtension;
        QPixmapCache::find(key, pixmap);
        if (!pixmap.isNull()) {
            retIcon.addPixmap(pixmap);
            if (QPixmapCache::find(key + QLatin1Char('l'), pixmap))
                retIcon.addPixmap(pixmap);
            return retIcon;
        }
    }

    const bool cacheableDirIcon = fileInfo.isDir() && !fileInfo.isRoot();
    if (!useCustomDirectoryIcons && defaultFolderIIcon >= 0 && cacheableDirIcon) {
        // We already have the default folder icon, just return it
        key = QString::fromLatin1("qt_dir_%1").arg(defaultFolderIIcon);
        QPixmapCache::find(key, pixmap);
        if (!pixmap.isNull()) {
            retIcon.addPixmap(pixmap);
            if (QPixmapCache::find(key + QLatin1Char('l'), pixmap))
                retIcon.addPixmap(pixmap);
            return retIcon;
        }
    }

    /* We don't use the variable, but by storing it statically, we
     * ensure CoInitialize is only called once. */
    static HRESULT comInit = CoInitialize(NULL);
    Q_UNUSED(comInit);

    SHFILEINFO info;
    unsigned long val = 0;

    //Get the small icon
    unsigned int flags =
#ifndef Q_OS_WINCE
        SHGFI_ICON|SHGFI_SYSICONINDEX|SHGFI_ADDOVERLAYS|SHGFI_OVERLAYINDEX;
#else
        SHGFI_SYSICONINDEX;
#endif

    if (cacheableDirIcon && !useCustomDirectoryIcons) {
        flags |= SHGFI_USEFILEATTRIBUTES;
        val = SHGetFileInfo(L"dummy",
                            FILE_ATTRIBUTE_DIRECTORY, &info,
                            sizeof(SHFILEINFO), flags | SHGFI_SMALLICON);
    } else {
        val = SHGetFileInfo((const wchar_t *)QDir::toNativeSeparators(fileInfo.filePath()).utf16(),
                            0, &info, sizeof(SHFILEINFO), flags | SHGFI_SMALLICON);
    }

    // Even if GetFileInfo returns a valid result, hIcon can be empty in some cases
    if (val && info.hIcon) {
        if (fileInfo.isDir() && !fileInfo.isRoot()) {
            if (!useCustomDirectoryIcons && defaultFolderIIcon < 0)
                defaultFolderIIcon = info.iIcon;
            //using the unique icon index provided by windows save us from duplicate keys
            key = QString::fromLatin1("qt_dir_%1").arg(info.iIcon);
            QPixmapCache::find(key, pixmap);
            if (!pixmap.isNull()) {
                retIcon.addPixmap(pixmap);
                if (QPixmapCache::find(key + QLatin1Char('l'), pixmap))
                    retIcon.addPixmap(pixmap);
                DestroyIcon(info.hIcon);
                return retIcon;
            }
        }
        if (pixmap.isNull()) {
#ifndef Q_OS_WINCE
            pixmap = QPixmap::fromWinHICON(info.hIcon);
#else
            pixmap = QPixmap::fromWinHICON(ImageList_GetIcon((HIMAGELIST) val, info.iIcon, ILD_NORMAL));
#endif
            if (!pixmap.isNull()) {
                retIcon.addPixmap(pixmap);
                if (!key.isEmpty())
                    QPixmapCache::insert(key, pixmap);
            }
            else {
              qWarning("QFileIconProviderPrivate::getWinIcon() no small icon found");
            }
        }
        DestroyIcon(info.hIcon);
    }

    //Get the big icon
    val = SHGetFileInfo((const wchar_t *)QDir::toNativeSeparators(fileInfo.filePath()).utf16(),
                0, &info, sizeof(SHFILEINFO), flags | SHGFI_LARGEICON);

    if (val && info.hIcon) {
        if (fileInfo.isDir() && !fileInfo.isRoot()) {
            //using the unique icon index provided by windows save us from duplicate keys
            key = QString::fromLatin1("qt_dir_%1").arg(info.iIcon);
        }
#ifndef Q_OS_WINCE
        pixmap = QPixmap::fromWinHICON(info.hIcon);
#else
        pixmap = QPixmap::fromWinHICON(ImageList_GetIcon((HIMAGELIST) val, info.iIcon, ILD_NORMAL));
#endif
        if (!pixmap.isNull()) {
            retIcon.addPixmap(pixmap);
            if (!key.isEmpty())
                QPixmapCache::insert(key + QLatin1Char('l'), pixmap);
        }
        else {
            qWarning("QFileIconProviderPrivate::getWinIcon() no large icon found");
        }
        DestroyIcon(info.hIcon);
    }
    return retIcon;
}