Internal cleanup: Make it easier getting the correct file item that should be used for showing the meta information (it depends on the current selection and whether the file item is already available).

CCMAIL: sebastian@trueg.de

svn path=/trunk/KDE/kdebase/apps/; revision=825996
This commit is contained in:
Peter Penz 2008-06-29 17:08:49 +00:00
parent 85b0ed6a63
commit 4af0c48f05
2 changed files with 26 additions and 23 deletions

View file

@ -183,10 +183,11 @@ void InfoSidebarPage::showItemInfo()
cancelRequest(); cancelRequest();
const KUrl file = fileUrl(); const KFileItem item = fileItem();
if (!file.isValid()) { if (item.isNull()) {
return; return;
} }
const KUrl itemUrl = item.url();
if (showMultipleSelectionInfo()) { if (showMultipleSelectionInfo()) {
KIconLoader iconLoader; KIconLoader iconLoader;
@ -195,11 +196,8 @@ void InfoSidebarPage::showItemInfo()
KIconLoader::SizeEnormous); KIconLoader::SizeEnormous);
m_preview->setPixmap(icon); m_preview->setPixmap(icon);
m_nameLabel->setText(i18ncp("@info", "%1 item selected", "%1 items selected", m_selection.count())); m_nameLabel->setText(i18ncp("@info", "%1 item selected", "%1 items selected", m_selection.count()));
} else if (!applyPlace(file)) { } else if (!applyPlace(itemUrl)) {
// try to get a preview pixmap from the item... // try to get a preview pixmap from the item...
KUrl::List list;
list.append(file);
m_pendingPreview = true; m_pendingPreview = true;
// Mark the currently shown preview as outdated. This is done // Mark the currently shown preview as outdated. This is done
@ -207,7 +205,7 @@ void InfoSidebarPage::showItemInfo()
// can be shown within a short timeframe. // can be shown within a short timeframe.
m_outdatedPreviewTimer->start(); m_outdatedPreviewTimer->start();
KIO::PreviewJob* job = KIO::filePreview(list, KIO::PreviewJob* job = KIO::filePreview(KUrl::List() << itemUrl,
m_preview->width(), m_preview->width(),
m_preview->height(), m_preview->height(),
0, 0,
@ -221,7 +219,7 @@ void InfoSidebarPage::showItemInfo()
connect(job, SIGNAL(failed(const KFileItem&)), connect(job, SIGNAL(failed(const KFileItem&)),
this, SLOT(showIcon(const KFileItem&))); this, SLOT(showIcon(const KFileItem&)));
m_nameLabel->setText(file.fileName()); m_nameLabel->setText(itemUrl.fileName());
} }
showMetaInfo(); showMetaInfo();
@ -372,25 +370,23 @@ void InfoSidebarPage::showMetaInfo()
} }
m_metaTextLabel->add(i18nc("@label", "Total size:"), KIO::convertSize(totalSize)); m_metaTextLabel->add(i18nc("@label", "Total size:"), KIO::convertSize(totalSize));
} else { } else {
KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, fileUrl()); const KFileItem item = fileItem();
fileItem.refresh(); if (item.isDir()) {
if (fileItem.isDir()) {
m_metaTextLabel->add(i18nc("@label", "Type:"), i18nc("@label", "Folder")); m_metaTextLabel->add(i18nc("@label", "Type:"), i18nc("@label", "Folder"));
m_metaTextLabel->add(i18nc("@label", "Modified:"), fileItem.timeString()); m_metaTextLabel->add(i18nc("@label", "Modified:"), item.timeString());
} else { } else {
m_metaTextLabel->add(i18nc("@label", "Type:"), fileItem.mimeComment()); m_metaTextLabel->add(i18nc("@label", "Type:"), item.mimeComment());
m_metaTextLabel->add(i18nc("@label", "Size:"), KIO::convertSize(fileItem.size())); m_metaTextLabel->add(i18nc("@label", "Size:"), KIO::convertSize(item.size()));
m_metaTextLabel->add(i18nc("@label", "Modified:"), fileItem.timeString()); m_metaTextLabel->add(i18nc("@label", "Modified:"), item.timeString());
if (fileItem.isLocalFile()) { if (item.isLocalFile()) {
// TODO: See convertMetaInfo below, find a way to display only interesting information // TODO: See convertMetaInfo below, find a way to display only interesting information
// in a readable way // in a readable way
const KFileMetaInfo::WhatFlags flags = KFileMetaInfo::Fastest | const KFileMetaInfo::WhatFlags flags = KFileMetaInfo::Fastest |
KFileMetaInfo::TechnicalInfo | KFileMetaInfo::TechnicalInfo |
KFileMetaInfo::ContentInfo; KFileMetaInfo::ContentInfo;
const QString path = fileItem.url().path(); const QString path = item.url().path();
const KFileMetaInfo fileMetaInfo(path, QString(), flags); const KFileMetaInfo fileMetaInfo(path, QString(), flags);
if (fileMetaInfo.isValid()) { if (fileMetaInfo.isValid()) {
const QHash<QString, KFileMetaInfoItem>& items = fileMetaInfo.items(); const QHash<QString, KFileMetaInfoItem>& items = fileMetaInfo.items();
@ -410,7 +406,7 @@ void InfoSidebarPage::showMetaInfo()
} }
if (m_metaDataWidget != 0) { if (m_metaDataWidget != 0) {
m_metaDataWidget->setFile(fileItem.targetUrl()); m_metaDataWidget->setFile(item.targetUrl());
} }
} }
} }
@ -453,9 +449,16 @@ bool InfoSidebarPage::convertMetaInfo(const QString& key, QString& text) const
return false; return false;
} }
KUrl InfoSidebarPage::fileUrl() const KFileItem InfoSidebarPage::fileItem() const
{ {
return (!m_fileItem.isNull() || m_selection.isEmpty()) ? m_shownUrl : m_selection[0].url(); if (!m_fileItem.isNull()) {
return m_fileItem;
}
const KUrl url = m_selection.isEmpty() ? m_shownUrl : m_selection[0].url();
KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
item.refresh();
return item;
} }
bool InfoSidebarPage::showMultipleSelectionInfo() const bool InfoSidebarPage::showMultipleSelectionInfo() const

View file

@ -144,11 +144,11 @@ private:
bool convertMetaInfo(const QString& key, QString& text) const; bool convertMetaInfo(const QString& key, QString& text) const;
/** /**
* Returns the URL of the file where the preview and meta information * Returns the item for file where the preview and meta information
* should be received, if InfoSidebarPage::showMultipleSelectionInfo() * should be received, if InfoSidebarPage::showMultipleSelectionInfo()
* returns false. * returns false.
*/ */
KUrl fileUrl() const; KFileItem fileItem() const;
/** /**
* Returns true, if the meta information should be shown for * Returns true, if the meta information should be shown for