tried to simplify the logic to decide whether the information panel should show the information for one file or for a multiple selection

CCMAIL: sebastian@trueg.de

svn path=/trunk/KDE/kdebase/apps/; revision=825317
This commit is contained in:
Peter Penz 2008-06-27 20:01:04 +00:00
parent 3a6ee0eee8
commit d96712f50e
2 changed files with 49 additions and 25 deletions

View file

@ -181,19 +181,18 @@ void InfoSidebarPage::showItemInfo()
cancelRequest();
const KUrl file = (!m_fileItem.isNull() || m_selection.isEmpty()) ? m_shownUrl : m_selection[0].url();
const KUrl file = fileUrl();
if (!file.isValid()) {
return;
}
const int selectionCount = m_selection.count();
if (m_fileItem.isNull() && (selectionCount > 1)) {
if (showMultipleSelectionInfo()) {
KIconLoader iconLoader;
QPixmap icon = iconLoader.loadIcon("dialog-information",
KIconLoader::NoGroup,
KIconLoader::SizeEnormous);
m_preview->setPixmap(icon);
m_nameLabel->setText(i18ncp("@info", "%1 item selected", "%1 items selected", selectionCount));
m_nameLabel->setText(i18ncp("@info", "%1 item selected", "%1 items selected", m_selection.count()));
} else if (!applyPlace(file)) {
// try to get a preview pixmap from the item...
KUrl::List list;
@ -339,10 +338,26 @@ void InfoSidebarPage::showMetaInfo()
{
m_metaTextLabel->clear();
const KUrl file = (!m_fileItem.isNull() || m_selection.isEmpty()) ? m_shownUrl : m_selection[0].url();
if (showMultipleSelectionInfo()) {
if (m_metaDataWidget != 0) {
KUrl::List urls;
foreach (const KFileItem& item, m_selection) {
urls.append(item.targetUrl());
}
m_metaDataWidget->setFiles(urls);
}
if ((m_selection.size() <= 1) || !m_fileItem.isNull()) {
KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, file);
quint64 totalSize = 0;
foreach (const KFileItem& item, m_selection) {
// Only count the size of files, not dirs to match what
// DolphinViewContainer::selectionStatusBarText() does.
if (!item.isDir() && !item.isLink()) {
totalSize += item.size();
}
}
m_metaTextLabel->add(i18nc("@label", "Total size:"), KIO::convertSize(totalSize));
} else {
KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, fileUrl());
fileItem.refresh();
if (fileItem.isDir()) {
@ -382,24 +397,6 @@ void InfoSidebarPage::showMetaInfo()
if (m_metaDataWidget != 0) {
m_metaDataWidget->setFile(fileItem.targetUrl());
}
} else {
if (m_metaDataWidget != 0) {
KUrl::List urls;
foreach (const KFileItem& item, m_selection) {
urls.append(item.targetUrl());
}
m_metaDataWidget->setFiles(urls);
}
quint64 totalSize = 0;
foreach (const KFileItem& item, m_selection) {
// Only count the size of files, not dirs to match what
// DolphinViewContainer::selectionStatusBarText() does.
if (!item.isDir() && !item.isLink()) {
totalSize += item.size();
}
}
m_metaTextLabel->add(i18nc("@label", "Total size:"), KIO::convertSize(totalSize));
}
}
@ -441,6 +438,16 @@ bool InfoSidebarPage::convertMetaInfo(const QString& key, QString& text) const
return false;
}
KUrl InfoSidebarPage::fileUrl() const
{
return (!m_fileItem.isNull() || m_selection.isEmpty()) ? m_shownUrl : m_selection[0].url();
}
bool InfoSidebarPage::showMultipleSelectionInfo() const
{
return m_fileItem.isNull() && (m_selection.count() > 1);
}
void InfoSidebarPage::init()
{
const int spacing = KDialog::spacingHint();

View file

@ -139,6 +139,23 @@ private:
*/
bool convertMetaInfo(const QString& key, QString& text) const;
/**
* Returns the URL of the file where the preview and meta information
* should be received, if InfoSidebarPage::showMultipleSelectionInfo()
* returns false.
*/
KUrl fileUrl() const;
/**
* Returns true, if the meta information should be shown for
* the items multiple selected items that are stored in
* m_selection. If true is returned, it is assured that
* m_selection.count() > 1. If false is returned, the meta
* information should be shown for the file
* InfosidebarPage::fileUrl();
*/
bool showMultipleSelectionInfo() const;
void init();
private: