mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kio: rework KIO::pixmapForUrl() to use KFileItem
for overlays and overall icon consistency (where possible, KHistoryComboBox still cannot use it) Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
02557d5dc4
commit
cd0bf16803
6 changed files with 29 additions and 44 deletions
|
@ -38,8 +38,7 @@
|
|||
|
||||
static QPixmap kPixmapForUrl(const QString &item, const int height)
|
||||
{
|
||||
#warning implement icon for KUrl/QUrl into KIconLoader?
|
||||
// the logic is the same as in KIO::pixmapForUrl() but kdeui cannot depend on kio
|
||||
// kdeui cannot depend on kio
|
||||
const QString iconName = KMimeType::iconNameForUrl(KUrl(item));
|
||||
return KIconLoader::global()->loadMimeTypeIcon(iconName, KIconLoader::Desktop, height);
|
||||
}
|
||||
|
@ -380,7 +379,8 @@ void KHistoryComboBox::insertItems( const QStringList& items )
|
|||
|
||||
while ( it != itEnd ) {
|
||||
const QString item = *it;
|
||||
if ( !item.isEmpty() ) { // only insert non-empty items);
|
||||
if ( !item.isEmpty() ) {
|
||||
// only insert non-empty items);
|
||||
addItem( kPixmapForUrl(item, iconSize().height()), item );
|
||||
}
|
||||
++it;
|
||||
|
|
|
@ -60,7 +60,7 @@ public:
|
|||
* @p parent the parent-widget for the dialog
|
||||
*
|
||||
* If you leave the icon empty, the default icon for the given url will be
|
||||
* used (KMimeType::pixmapForUrl()).
|
||||
* used (KMimeType::iconNameForUrl()).
|
||||
*/
|
||||
static bool getInformation( bool allowGlobal, KUrl& url,
|
||||
QString& label, QString& icon,
|
||||
|
@ -83,7 +83,7 @@ public:
|
|||
* @p parent the parent-widget for the dialog
|
||||
*
|
||||
* If you leave the icon empty, the default icon for the given url will be
|
||||
* used (KMimeType::pixmapForUrl()).
|
||||
* used (KMimeType::iconNameForUrl()).
|
||||
*/
|
||||
KFilePlaceEditDialog(bool allowGlobal, const KUrl& url,
|
||||
const QString& label, const QString &icon,
|
||||
|
|
|
@ -326,11 +326,11 @@ KFileWidget::KFileWidget( const KUrl& _startDir, QWidget *parent )
|
|||
KUrlComboBox *pathCombo = d->urlNavigator->editor();
|
||||
u.setPath(QDir::rootPath());
|
||||
pathCombo->addDefaultUrl(u,
|
||||
KIO::pixmapForUrl(u, 0, KIconLoader::Small),
|
||||
KIO::pixmapForUrl(u, KIconLoader::Small),
|
||||
u.toLocalFile());
|
||||
|
||||
u.setPath(QDir::homePath());
|
||||
pathCombo->addDefaultUrl(u, KIO::pixmapForUrl(u, 0, KIconLoader::Small),
|
||||
pathCombo->addDefaultUrl(u, KIO::pixmapForUrl(u, KIconLoader::Small),
|
||||
u.path(KUrl::AddTrailingSlash));
|
||||
|
||||
KUrl docPath;
|
||||
|
@ -339,13 +339,13 @@ KFileWidget::KFileWidget( const KUrl& _startDir, QWidget *parent )
|
|||
QDir(docPath.path(KUrl::AddTrailingSlash)).exists() )
|
||||
{
|
||||
pathCombo->addDefaultUrl( docPath,
|
||||
KIO::pixmapForUrl( docPath, 0, KIconLoader::Small ),
|
||||
KIO::pixmapForUrl( docPath, KIconLoader::Small ),
|
||||
docPath.path(KUrl::AddTrailingSlash));
|
||||
}
|
||||
|
||||
u.setPath( KGlobalSettings::desktopPath() );
|
||||
pathCombo->addDefaultUrl(u,
|
||||
KIO::pixmapForUrl(u, 0, KIconLoader::Small),
|
||||
KIO::pixmapForUrl(u, KIconLoader::Small),
|
||||
u.path(KUrl::AddTrailingSlash));
|
||||
|
||||
d->ops = new KDirOperator(KUrl(), d->opsWidget);
|
||||
|
@ -1165,19 +1165,17 @@ void KFileWidgetPrivate::removeDummyHistoryEntry()
|
|||
void KFileWidgetPrivate::setLocationText(const KUrl& url)
|
||||
{
|
||||
if (!url.isEmpty()) {
|
||||
QPixmap mimeTypeIcon = KIconLoader::global()->loadMimeTypeIcon( KMimeType::iconNameForUrl( url ), KIconLoader::Small );
|
||||
QPixmap urlIcon = KIO::pixmapForUrl( url, KIconLoader::Small );
|
||||
if (url.hasPath()) {
|
||||
if (!url.directory().isEmpty())
|
||||
{
|
||||
if (!url.directory().isEmpty()) {
|
||||
KUrl u(url);
|
||||
u.setPath(u.directory());
|
||||
q->setUrl(u, false);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
q->setUrl(url.path(), false);
|
||||
}
|
||||
}
|
||||
setDummyHistoryEntry(url.fileName() , mimeTypeIcon);
|
||||
setDummyHistoryEntry(url.fileName(), urlIcon);
|
||||
} else {
|
||||
removeDummyHistoryEntry();
|
||||
}
|
||||
|
@ -1219,8 +1217,7 @@ void KFileWidgetPrivate::setLocationText( const KUrl::List& urlList )
|
|||
|
||||
setDummyHistoryEntry( urls, QPixmap(), false );
|
||||
} else if ( urlList.count() == 1 ) {
|
||||
const QPixmap mimeTypeIcon = KIconLoader::global()->loadMimeTypeIcon( KMimeType::iconNameForUrl( urlList[0] ), KIconLoader::Small );
|
||||
setDummyHistoryEntry( relativePathOrUrl(currUrl, urlList[0]), mimeTypeIcon );
|
||||
setDummyHistoryEntry( relativePathOrUrl(currUrl, urlList[0]), KIO::pixmapForUrl(urlList[0], KIconLoader::Small));
|
||||
} else {
|
||||
removeDummyHistoryEntry();
|
||||
}
|
||||
|
|
|
@ -23,13 +23,14 @@
|
|||
#include <config.h>
|
||||
|
||||
#include <kglobalsettings.h>
|
||||
#include <kdebug.h>
|
||||
#include <klocale.h>
|
||||
#include <kglobal.h>
|
||||
#include <kiconloader.h>
|
||||
#include <kprotocolmanager.h>
|
||||
#include <kmimetype.h>
|
||||
#include <kdynamicjobtracker.h>
|
||||
#include <kfileitem.h>
|
||||
#include <kdebug.h>
|
||||
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/qdatetime.h>
|
||||
|
@ -976,16 +977,13 @@ KIO_EXPORT QByteArray KIO::rawErrorDetail(int errorCode, const QString &errorTex
|
|||
}
|
||||
|
||||
/***************************************************************
|
||||
*
|
||||
* Utility functions
|
||||
*
|
||||
***************************************************************/
|
||||
|
||||
QPixmap KIO::pixmapForUrl( const KUrl & _url, mode_t _mode, KIconLoader::Group _group,
|
||||
int _force_size, int _state, QString * _path )
|
||||
QPixmap KIO::pixmapForUrl(const KUrl &url, KIconLoader::Group group,
|
||||
int force_size, int state, QString *path)
|
||||
{
|
||||
const QString iconName = KMimeType::iconNameForUrl( _url, _mode );
|
||||
return KIconLoader::global()->loadMimeTypeIcon( iconName, _group, _force_size, _state, QStringList(), _path );
|
||||
const KFileItem fileitem(url);
|
||||
return KIconLoader::global()->loadIcon(fileitem.iconName(), group, force_size, state, fileitem.overlays(), path);
|
||||
}
|
||||
|
||||
KJobTrackerInterface *KIO::getJobTracker()
|
||||
|
|
|
@ -239,23 +239,16 @@ namespace KIO
|
|||
/**
|
||||
* Convenience method to find the pixmap for a URL.
|
||||
*
|
||||
* Call this one when you don't know the mimetype.
|
||||
*
|
||||
* @param _url URL for the file.
|
||||
* @param _mode the mode of the file. The mode may modify the icon
|
||||
* with overlays that show special properties of the
|
||||
* icon. Use 0 for default
|
||||
* @param _group The icon group where the icon is going to be used.
|
||||
* @param _force_size Override globally configured icon size.
|
||||
* Use 0 for the default size
|
||||
* @param _state The icon state, one of: KIconLoader::DefaultState,
|
||||
* @param url URL for the file.
|
||||
* @param group The icon group where the icon is going to be used.
|
||||
* @param force_size Override globally configured icon size. Use 0 for the default size
|
||||
* @param state The icon state, one of: KIconLoader::DefaultState,
|
||||
* KIconLoader::ActiveState or KIconLoader::DisabledState.
|
||||
* @param _path Output parameter to get the full path. Seldom needed.
|
||||
* Ignored if 0
|
||||
* @param path Output parameter to get the full path, seldom needed.
|
||||
* @return the pixmap of the URL, can be a default icon if not found
|
||||
*/
|
||||
KIO_EXPORT QPixmap pixmapForUrl( const KUrl & _url, mode_t _mode = 0, KIconLoader::Group _group = KIconLoader::Desktop,
|
||||
int _force_size = 0, int _state = 0, QString * _path = 0 );
|
||||
KIO_EXPORT QPixmap pixmapForUrl(const KUrl &url, KIconLoader::Group group = KIconLoader::Desktop,
|
||||
int force_size = 0, int state = 0, QString *path = nullptr);
|
||||
|
||||
KIO_EXPORT KJobTrackerInterface *getJobTracker();
|
||||
|
||||
|
|
|
@ -723,7 +723,6 @@ bool KFileItem::isFile() const
|
|||
return !isDir();
|
||||
}
|
||||
|
||||
|
||||
QString KFileItem::getStatusBarInfo() const
|
||||
{
|
||||
if (!d) {
|
||||
|
@ -800,8 +799,7 @@ bool KFileItem::cmp(const KFileItem &item) const
|
|||
&& d->m_entry.stringValue(KIO::UDSEntry::UDS_ICON_NAME) == item.d->m_entry.stringValue(KIO::UDSEntry::UDS_ICON_NAME)
|
||||
);
|
||||
|
||||
// Don't compare the mimetypes here. They might not be known, and we don't want to
|
||||
// do the slow operation of determining them here.
|
||||
// Don't compare the mimetypes here
|
||||
}
|
||||
|
||||
bool KFileItem::operator==(const KFileItem &other) const
|
||||
|
@ -1036,11 +1034,10 @@ KMimeType::Ptr KFileItem::mimeTypePtr() const
|
|||
return KMimeType::Ptr();
|
||||
}
|
||||
if (!d->m_pMimeType) {
|
||||
// On-demand fast (but not always accurate) mimetype determination
|
||||
Q_ASSERT(!d->m_url.isEmpty());
|
||||
d->m_pMimeType = KMimeType::findByUrl(
|
||||
d->m_url, d->m_fileMode,
|
||||
// use fast mode if delayed mimetype determination can refine it later
|
||||
// use fast mode if not local (content cannot be read)
|
||||
!d->m_bIsLocalUrl
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue