X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/b4c2bc9e062a8df4fe44dc39a8322831575ae607..093efca22dfd247f06e2a669ad968300e71ef08d:/src/infosidebarpage.cpp diff --git a/src/infosidebarpage.cpp b/src/infosidebarpage.cpp index 1a3e67e1c..319582cb4 100644 --- a/src/infosidebarpage.cpp +++ b/src/infosidebarpage.cpp @@ -19,7 +19,7 @@ #include "infosidebarpage.h" -#include +#include #include #include @@ -50,7 +50,7 @@ InfoSidebarPage::InfoSidebarPage(QWidget* parent) : m_pendingPreview(false), m_timer(0), m_preview(0), - m_name(0), + m_nameLabel(0), m_infoLabel(0), m_metadataWidget(0) { @@ -70,10 +70,10 @@ InfoSidebarPage::InfoSidebarPage(QWidget* parent) : m_preview->setFixedHeight(K3Icon::SizeEnormous); // name - m_name = new QLabel(this); - m_name->setTextFormat(Qt::RichText); - m_name->setAlignment(m_name->alignment() | Qt::AlignHCenter); - m_name->setWordWrap(true); + m_nameLabel = new QLabel(this); + m_nameLabel->setTextFormat(Qt::RichText); + m_nameLabel->setAlignment(m_nameLabel->alignment() | Qt::AlignHCenter); + m_nameLabel->setWordWrap(true); // general information m_infoLabel = new QLabel(this); @@ -86,7 +86,7 @@ InfoSidebarPage::InfoSidebarPage(QWidget* parent) : layout->addItem(new QSpacerItem(spacing, spacing, QSizePolicy::Preferred, QSizePolicy::Fixed)); layout->addWidget(m_preview); - layout->addWidget(m_name); + layout->addWidget(m_nameLabel); layout->addWidget(new KSeparator(this)); layout->addWidget(m_infoLabel); layout->addWidget(new KSeparator(this)); @@ -102,6 +102,13 @@ InfoSidebarPage::~InfoSidebarPage() { } +QSize InfoSidebarPage::sizeHint() const +{ + QSize size = SidebarPage::sizeHint(); + size.setWidth(minimumSizeHint().width()); + return size; +} + void InfoSidebarPage::setUrl(const KUrl& url) { if (url.isValid() && !m_shownUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) { @@ -111,19 +118,28 @@ void InfoSidebarPage::setUrl(const KUrl& url) } } -void InfoSidebarPage::setSelection(const KFileItemList& selection) +void InfoSidebarPage::setSelection(const QList& selection) { SidebarPage::setSelection(selection); + if (selection.size() == 1) { + const KUrl url = selection.first().url(); + if (!url.isEmpty()) { + m_urlCandidate = url; + } + } m_timer->start(TimerDelay); } -void InfoSidebarPage::requestDelayedItemInfo(const KUrl& url) +void InfoSidebarPage::requestDelayedItemInfo(const KFileItem& item) { cancelRequest(); - if (!url.isEmpty() && (selection().size() <= 1)) { - m_urlCandidate = url; - m_timer->start(TimerDelay); + if (!item.isNull() && (selection().size() <= 1)) { + const KUrl url = item.url(); + if (!url.isEmpty()) { + m_urlCandidate = url; + m_timer->start(TimerDelay); + } } } @@ -138,11 +154,14 @@ void InfoSidebarPage::showEvent(QShowEvent* event) void InfoSidebarPage::resizeEvent(QResizeEvent* event) { - // If the item name cannot get wrapped, the maximum width of - // the label is increased, so that the width of the information sidebar - // gets increased. To prevent this, the maximum width is adjusted to + // If the text inside the name label or the info label cannot + // get wrapped, then the maximum width of the label is increased + // so that the width of the information sidebar gets increased. + // To prevent this, the maximum width is adjusted to // the current width of the sidebar. - m_name->setMaximumWidth(event->size().width() - KDialog::spacingHint() * 4); + const int maxWidth = event->size().width() - KDialog::spacingHint() * 4; + m_nameLabel->setMaximumWidth(maxWidth); + m_infoLabel->setMaximumWidth(maxWidth); SidebarPage::resizeEvent(event); } @@ -154,23 +173,26 @@ void InfoSidebarPage::showItemInfo() cancelRequest(); - const KFileItemList& selectedItems = selection(); + const QList& selectedItems = selection(); KUrl file; - const int itemCount = selectedItems.count(); - if (selectedItems.count() == 0) { + if (selectedItems.isEmpty()) { file = m_shownUrl; } else { - file = selectedItems[0]->url(); + file = selectedItems[0].url(); } + if (!file.isValid()) { + return; + } + const int itemCount = selectedItems.count(); if (itemCount > 1) { KIconLoader iconLoader; QPixmap icon = iconLoader.loadIcon("exec", K3Icon::NoGroup, K3Icon::SizeEnormous); m_preview->setPixmap(icon); - m_name->setText(i18n("%1 items selected", selectedItems.count())); - } else if (!applyBookmark(file)) { + m_nameLabel->setText(i18ncp("@info", "%1 item selected", "%1 items selected", selectedItems.count())); + } else if (!applyPlace(file)) { // try to get a preview pixmap from the item... KUrl::List list; list.append(file); @@ -195,7 +217,7 @@ void InfoSidebarPage::showItemInfo() QString text(""); text.append(file.fileName()); text.append(""); - m_name->setText(text); + m_nameLabel->setText(text); } showMetaInfo(); @@ -210,7 +232,7 @@ void InfoSidebarPage::slotTimeout() void InfoSidebarPage::showIcon(const KFileItem& item) { m_pendingPreview = false; - if (!applyBookmark(item.url())) { + if (!applyPlace(item.url())) { m_preview->setPixmap(item.pixmap(K3Icon::SizeEnormous)); } } @@ -225,7 +247,7 @@ void InfoSidebarPage::showPreview(const KFileItem& item, } } -bool InfoSidebarPage::applyBookmark(const KUrl& url) +bool InfoSidebarPage::applyPlace(const KUrl& url) { KFilePlacesModel* placesModel = DolphinSettings::instance().placesModel(); int count = placesModel->rowCount(); @@ -237,7 +259,7 @@ bool InfoSidebarPage::applyBookmark(const KUrl& url) QString text(""); text.append(placesModel->text(index)); text.append(""); - m_name->setText(text); + m_nameLabel->setText(text); m_preview->setPixmap(placesModel->icon(index).pixmap(128, 128)); return true; @@ -257,23 +279,23 @@ void InfoSidebarPage::showMetaInfo() { QString text; - const KFileItemList& selectedItems = selection(); + const QList& selectedItems = selection(); if (selectedItems.size() <= 1) { KFileItem fileItem(S_IFDIR, KFileItem::Unknown, m_shownUrl); fileItem.refresh(); if (fileItem.isDir()) { - addInfoLine(text, i18n("Type:"), i18n("Folder")); + addInfoLine(text, i18nc("@label", "Type:"), i18nc("@label", "Folder")); } else { - addInfoLine(text, i18n("Type:"), fileItem.mimeComment()); + addInfoLine(text, i18nc("@label", "Type:"), fileItem.mimeComment()); QString sizeText(KIO::convertSize(fileItem.size())); - addInfoLine(text, i18n("Size:"), sizeText); - addInfoLine(text, i18n("Modified:"), fileItem.timeString()); + addInfoLine(text, i18nc("@label", "Size:"), sizeText); + addInfoLine(text, i18nc("@label", "Modified:"), fileItem.timeString()); - // TODO: deactivate showing additional meta information, as the system - // hangs when retrieving the meta information of a zipped file - /*const KFileMetaInfo metaInfo(fileItem.url()); + // TODO: See convertMetaInfo below, find a way to display only interesting information + // in a readable way + const KFileMetaInfo metaInfo(fileItem.url()); if (metaInfo.isValid()) { const QHash& items = metaInfo.items(); QHash::const_iterator it = items.constBegin(); @@ -287,7 +309,7 @@ void InfoSidebarPage::showMetaInfo() } ++it; } - }*/ + } } if (MetaDataWidget::metaDataAvailable()) { @@ -295,16 +317,20 @@ void InfoSidebarPage::showMetaInfo() } } else { if (MetaDataWidget::metaDataAvailable()) { - m_metadataWidget->setFiles(selectedItems.urlList()); + KUrl::List urls; + foreach (const KFileItem& item, selectedItems) { + urls.append(item.url()); + } + m_metadataWidget->setFiles(urls); } unsigned long int totalSize = 0; - foreach (KFileItem* item, selectedItems) { + foreach (const KFileItem& item, selectedItems) { // TODO: what to do with directories (same with the one-item-selected-code)?, - // item->size() does not return the size of the content : not very instinctive for users - totalSize += item->size(); + // item.size() does not return the size of the content : not very instinctive for users + totalSize += item.size(); } - addInfoLine(text, i18n("Total size:"), KIO::convertSize(totalSize)); + addInfoLine(text, i18nc("@label", "Total size:"), KIO::convertSize(totalSize)); } m_infoLabel->setText(text); } @@ -313,7 +339,7 @@ void InfoSidebarPage::addInfoLine(QString& text, const QString& labelText, const QString& infoText) { - if (!infoText.isEmpty()) { + if (!text.isEmpty()) { text += "
"; } text += QString("%1 %2").arg(labelText).arg(infoText);