X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/8d0fda61c8312ccaa5ee1f77fd8808e8bdedba36..8d95c06df13717fe1e8dfd0d28dc0b8357e32064:/src/infosidebarpage.cpp diff --git a/src/infosidebarpage.cpp b/src/infosidebarpage.cpp index 301920a94..d2201eb2b 100644 --- a/src/infosidebarpage.cpp +++ b/src/infosidebarpage.cpp @@ -29,12 +29,14 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -51,6 +53,7 @@ InfoSidebarPage::InfoSidebarPage(QWidget* parent) : m_shownUrl(), m_urlCandidate(), m_fileItem(), + m_selection(), m_nameLabel(0), m_preview(0), m_metaDataWidget(0), @@ -73,6 +76,7 @@ InfoSidebarPage::InfoSidebarPage(QWidget* parent) : m_nameLabel->setFont(font); m_nameLabel->setAlignment(Qt::AlignHCenter); m_nameLabel->setWordWrap(true); + m_nameLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); // preview m_preview = new PixmapViewer(this); @@ -82,16 +86,21 @@ InfoSidebarPage::InfoSidebarPage(QWidget* parent) : if (MetaDataWidget::metaDataAvailable()) { // rating, comment and tags m_metaDataWidget = new MetaDataWidget(this); + m_metaDataWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); } // general meta text information m_metaTextLabel = new MetaTextLabel(this); m_metaTextLabel->setMinimumWidth(spacing); + m_metaTextLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); layout->addWidget(m_nameLabel); + layout->addWidget(new KSeparator(this)); layout->addWidget(m_preview); + layout->addWidget(new KSeparator(this)); if (m_metaDataWidget != 0) { layout->addWidget(m_metaDataWidget); + layout->addWidget(new KSeparator(this)); } layout->addWidget(m_metaTextLabel); @@ -123,18 +132,15 @@ void InfoSidebarPage::setUrl(const KUrl& url) void InfoSidebarPage::setSelection(const KFileItemList& selection) { - SidebarPage::setSelection(selection); + m_selection = selection; const int count = selection.count(); if (count == 0) { m_shownUrl = url(); showItemInfo(); } else { - if (count == 1) { - const KUrl url = selection.first().url(); - if (!url.isEmpty()) { - m_urlCandidate = url; - } + if ((count == 1) && !selection.first().url().isEmpty()) { + m_urlCandidate = selection.first().url(); } m_timer->start(TimerDelay); } @@ -142,32 +148,29 @@ void InfoSidebarPage::setSelection(const KFileItemList& selection) void InfoSidebarPage::requestDelayedItemInfo(const KFileItem& item) { - if (!selection().isEmpty()) { - // if items are selected, no item information may get requested - return; - } - cancelRequest(); m_fileItem = KFileItem(); - - if (!item.isNull() && (selection().size() <= 1)) { - const KUrl url = item.url(); - if (!url.isEmpty()) { - m_urlCandidate = url; - m_fileItem = item; + if (item.isNull()) { + // The cursor is above the viewport. If files are selected, + // show information regarding the selection. + if (m_selection.size() > 0) { + m_pendingPreview = false; m_timer->start(TimerDelay); } + } else if (!item.url().isEmpty()) { + m_urlCandidate = item.url(); + m_fileItem = item; + m_timer->start(TimerDelay); } } void InfoSidebarPage::showEvent(QShowEvent* event) { SidebarPage::showEvent(event); - if (event->spontaneous()) { - return; + if (!event->spontaneous()) { + showItemInfo(); } - showItemInfo(); } void InfoSidebarPage::resizeEvent(QResizeEvent* event) @@ -196,27 +199,29 @@ void InfoSidebarPage::showItemInfo() cancelRequest(); - const KFileItemList& selectedItems = selection(); - const KUrl file = selectedItems.isEmpty() ? m_shownUrl : selectedItems[0].url(); + const KUrl file = (!m_fileItem.isNull() || m_selection.isEmpty()) ? m_shownUrl : m_selection[0].url(); if (!file.isValid()) { return; } - const int itemCount = selectedItems.count(); - if (itemCount > 1) { + const int selectionCount = m_selection.count(); + if (m_fileItem.isNull() && (selectionCount > 1)) { 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", selectedItems.count())); + m_nameLabel->setText(i18ncp("@info", "%1 item selected", "%1 items selected", selectionCount)); } else if (!applyPlace(file)) { // try to get a preview pixmap from the item... KUrl::List list; list.append(file); m_pendingPreview = true; - m_preview->setPixmap(QPixmap()); + + KIconEffect iconEffect; + QPixmap disabledPixmap = iconEffect.apply(m_preview->pixmap(), KIconLoader::Desktop, KIconLoader::DisabledState); + m_preview->setPixmap(disabledPixmap); KIO::PreviewJob* job = KIO::filePreview(list, m_preview->width(), @@ -289,12 +294,12 @@ void InfoSidebarPage::showMetaInfo() { m_metaTextLabel->clear(); - const KFileItemList& selectedItems = selection(); - if (selectedItems.size() <= 1) { + if ((m_selection.size() <= 1) || !m_fileItem.isNull()) { KFileItem fileItem; if (m_fileItem.isNull()) { // no pending request is ongoing - fileItem = KFileItem(KFileItem::Unknown, KFileItem::Unknown, m_shownUrl); + const KUrl url = (m_selection.size() == 1) ? m_selection.first().url() : m_shownUrl; + fileItem = KFileItem(KFileItem::Unknown, KFileItem::Unknown, url); fileItem.refresh(); } else { fileItem = m_fileItem; @@ -302,50 +307,53 @@ void InfoSidebarPage::showMetaInfo() if (fileItem.isDir()) { m_metaTextLabel->add(i18nc("@label", "Type:"), i18nc("@label", "Folder")); + m_metaTextLabel->add(i18nc("@label", "Modified:"), fileItem.timeString()); } else { m_metaTextLabel->add(i18nc("@label", "Type:"), fileItem.mimeComment()); m_metaTextLabel->add(i18nc("@label", "Size:"), KIO::convertSize(fileItem.size())); m_metaTextLabel->add(i18nc("@label", "Modified:"), fileItem.timeString()); - // TODO: See convertMetaInfo below, find a way to display only interesting information - // in a readable way - const KFileMetaInfo::WhatFlags flags = KFileMetaInfo::Fastest | - KFileMetaInfo::TechnicalInfo | - KFileMetaInfo::ContentInfo | - KFileMetaInfo::Thumbnail; - const QString path = fileItem.url().url(); - const KFileMetaInfo fileMetaInfo(path, QString(), flags); - if (fileMetaInfo.isValid()) { - const QHash& items = fileMetaInfo.items(); - QHash::const_iterator it = items.constBegin(); - const QHash::const_iterator end = items.constEnd(); - QString labelText; - while (it != end) { - const KFileMetaInfoItem& metaInfoItem = it.value(); - const QVariant& value = metaInfoItem.value(); - if (value.isValid() && convertMetaInfo(metaInfoItem.name(), labelText)) { - m_metaTextLabel->add(labelText, value.toString()); + if (fileItem.isLocalFile()) { + // TODO: See convertMetaInfo below, find a way to display only interesting information + // in a readable way + const KFileMetaInfo::WhatFlags flags = KFileMetaInfo::Fastest | + KFileMetaInfo::TechnicalInfo | + KFileMetaInfo::ContentInfo | + KFileMetaInfo::Thumbnail; + const QString path = fileItem.url().path(); + const KFileMetaInfo fileMetaInfo(path, QString(), flags); + if (fileMetaInfo.isValid()) { + const QHash& items = fileMetaInfo.items(); + QHash::const_iterator it = items.constBegin(); + const QHash::const_iterator end = items.constEnd(); + QString labelText; + while (it != end) { + const KFileMetaInfoItem& metaInfoItem = it.value(); + const QVariant& value = metaInfoItem.value(); + if (value.isValid() && convertMetaInfo(metaInfoItem.name(), labelText)) { + m_metaTextLabel->add(labelText, value.toString()); + } + ++it; } - ++it; } } } if (m_metaDataWidget != 0) { - m_metaDataWidget->setFile(fileItem.url()); + m_metaDataWidget->setFile(fileItem.targetUrl()); } } else { if (m_metaDataWidget != 0) { KUrl::List urls; - foreach (const KFileItem& item, selectedItems) { - urls.append(item.url()); + foreach (const KFileItem& item, m_selection) { + urls.append(item.targetUrl()); } m_metaDataWidget->setFiles(urls); } - unsigned long int totalSize = 0; - foreach (const KFileItem& item, selectedItems) { + 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()) {