QString KFileItem::iconName() const { if (d->m_useIconNameCache && !d->m_iconName.isEmpty()) { return d->m_iconName; } d->m_iconName = d->m_entry.stringValue( KIO::UDSEntry::UDS_ICON_NAME ); if (!d->m_iconName.isEmpty()) { d->m_useIconNameCache = d->m_bMimeTypeKnown; return d->m_iconName; } bool isLocalUrl; KUrl url = mostLocalUrl(isLocalUrl); KMimeType::Ptr mime = mimeTypePtr(); if (isLocalUrl && mime->is("application/x-desktop")) { d->m_iconName = iconFromDesktopFile(url.toLocalFile()); if (!d->m_iconName.isEmpty()) { d->m_useIconNameCache = d->m_bMimeTypeKnown; return d->m_iconName; } } // KDE5: handle .directory files here too, and get rid of // KFolderMimeType and the url argument in KMimeType::iconName(). d->m_iconName = mime->iconName(url); d->m_useIconNameCache = d->m_bMimeTypeKnown; //kDebug() << "finding icon for" << url << ":" << d->m_iconName; return d->m_iconName; }
QMimeType KFileItem::determineMimeType() const { if (!d) { return QMimeType(); } if (!d->m_mimeType.isValid() || !d->m_bMimeTypeKnown) { QMimeDatabase db; if (isDir()) { d->m_mimeType = db.mimeTypeForName(QStringLiteral("inode/directory")); } else { bool isLocalUrl; const QUrl url = mostLocalUrl(&isLocalUrl); d->m_mimeType = db.mimeTypeForUrl(url); // was: d->m_mimeType = KMimeType::findByUrl( url, d->m_fileMode, isLocalUrl ); // => we are no longer using d->m_fileMode for remote URLs. Q_ASSERT(d->m_mimeType.isValid()); //qDebug() << d << "finding final mimetype for" << url << ":" << d->m_mimeType.name(); } d->m_bMimeTypeKnown = true; } if (d->m_delayedMimeTypes) { // if we delayed getting the iconName up till now, this is the right point in time to do so d->m_delayedMimeTypes = false; d->m_useIconNameCache = false; (void)iconName(); } return d->m_mimeType; }
QString KFileItem::mimeComment() const { const QString displayType = d->m_entry.stringValue( KIO::UDSEntry::UDS_DISPLAY_TYPE ); if (!displayType.isEmpty()) return displayType; KMimeType::Ptr mType = determineMimeType(); bool isLocalUrl; KUrl url = mostLocalUrl(isLocalUrl); KMimeType::Ptr mime = mimeTypePtr(); // This cannot move to kio_file (with UDS_DISPLAY_TYPE) because it needs // the mimetype to be determined, which is done here, and possibly delayed... if (isLocalUrl && mime->is("application/x-desktop")) { KDesktopFile cfg( url.toLocalFile() ); QString comment = cfg.desktopGroup().readEntry( "Comment" ); if (!comment.isEmpty()) return comment; } QString comment = mType->comment( url ); //kDebug() << "finding comment for " << url.url() << " : " << d->m_pMimeType->name(); if (!comment.isEmpty()) return comment; else return mType->name(); }
KFileMetaInfo KFileItem::metaInfo(bool autoget, int what) const { if ((isRegularFile() || isDir()) && autoget && !d->m_metaInfo.isValid()) { bool isLocalUrl; KUrl url(mostLocalUrl(isLocalUrl)); d->m_metaInfo = KFileMetaInfo(url.toLocalFile(), mimetype(), (KFileMetaInfo::What)what); } return d->m_metaInfo; }
// ## where is this used? QPixmap KFileItem::pixmap( int _size, int _state ) const { const QString iconName = d->m_entry.stringValue( KIO::UDSEntry::UDS_ICON_NAME ); if ( !iconName.isEmpty() ) return DesktopIcon(iconName, _size, _state); if (!d->m_pMimeType) { // No mimetype determined yet, go for a fast default icon if (S_ISDIR(d->m_fileMode)) { static const QString * defaultFolderIcon = 0; if ( !defaultFolderIcon ) { const KMimeType::Ptr mimeType = KMimeType::mimeType( "inode/directory" ); if ( mimeType ) defaultFolderIcon = &KGlobal::staticQString( mimeType->iconName() ); else kWarning(7000) << "No mimetype for inode/directory could be found. Check your installation."; } if ( defaultFolderIcon ) return DesktopIcon( *defaultFolderIcon, _size, _state ); } return DesktopIcon( "unknown", _size, _state ); } KMimeType::Ptr mime; // Use guessed mimetype if the main one hasn't been determined for sure if ( !d->m_bMimeTypeKnown && !d->m_guessedMimeType.isEmpty() ) mime = KMimeType::mimeType( d->m_guessedMimeType ); else mime = d->m_pMimeType; // Support for gzipped files: extract mimetype of contained file // See also the relevant code in overlays, which adds the zip overlay. if ( mime->name() == "application/x-gzip" && d->m_url.fileName().endsWith( QLatin1String( ".gz" ) ) ) { KUrl sf; sf.setPath( d->m_url.path().left( d->m_url.path().length() - 3 ) ); //kDebug() << "subFileName=" << subFileName; mime = KMimeType::findByUrl( sf, 0, d->m_bIsLocalUrl ); } bool isLocalUrl; KUrl url = mostLocalUrl(isLocalUrl); QPixmap p = KIconLoader::global()->loadMimeTypeIcon( mime->iconName( url ), KIconLoader::Desktop, _size, _state ); //kDebug() << "finding pixmap for " << url.url() << " : " << mime->name(); if (p.isNull()) kWarning() << "Pixmap not found for mimetype " << d->m_pMimeType->name(); return p; }
KMimeType::Ptr KFileItem::determineMimeType() const { if ( !d->m_pMimeType || !d->m_bMimeTypeKnown ) { bool isLocalUrl; KUrl url = mostLocalUrl(isLocalUrl); d->m_pMimeType = KMimeType::findByUrl( url, d->m_fileMode, isLocalUrl ); Q_ASSERT(d->m_pMimeType); //kDebug() << d << "finding final mimetype for" << url << ":" << d->m_pMimeType->name(); d->m_bMimeTypeKnown = true; } return d->m_pMimeType; }
// KDE5 TODO: merge with comment()? Need to see what lxr says about the usage of both. QString KFileItem::mimeComment() const { if (!d) { return QString(); } const QString displayType = d->m_entry.stringValue(KIO::UDSEntry::UDS_DISPLAY_TYPE); if (!displayType.isEmpty()) { return displayType; } bool isLocalUrl; QUrl url = mostLocalUrl(&isLocalUrl); QMimeType mime = currentMimeType(); // This cannot move to kio_file (with UDS_DISPLAY_TYPE) because it needs // the mimetype to be determined, which is done here, and possibly delayed... if (isLocalUrl && !d->isSlow() && mime.inherits(QStringLiteral("application/x-desktop"))) { KDesktopFile cfg(url.toLocalFile()); QString comment = cfg.desktopGroup().readEntry("Comment"); if (!comment.isEmpty()) { return comment; } } // Support for .directory file in directories if (isLocalUrl && isDir() && isDirectoryMounted(url)) { QUrl u(url); u.setPath(u.path() + QLatin1String("/.directory")); const KDesktopFile cfg(u.toLocalFile()); const QString comment = cfg.readComment(); if (!comment.isEmpty()) { return comment; } } const QString comment = mime.comment(); //qDebug() << "finding comment for " << url.url() << " : " << d->m_mimeType->name(); if (!comment.isEmpty()) { return comment; } else { return mime.name(); } }
KUrl KFileItem::mostLocalUrl() const { bool local = false; return mostLocalUrl(local); }