X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/68a7ed8bcfafe36676ddb43a5de426a6f600a05d..27a4b768714efb8a2b78f4fcb155e267cc1da05a:/src/panels/information/informationpanel.cpp diff --git a/src/panels/information/informationpanel.cpp b/src/panels/information/informationpanel.cpp index 000e7fdfb..2b3124b3c 100644 --- a/src/panels/information/informationpanel.cpp +++ b/src/panels/information/informationpanel.cpp @@ -23,16 +23,22 @@ #include #include -#include -#include -#include -#include #include -#include #include +#include +#include +#include #include -#include #include +#include +#include +#include + +#ifdef HAVE_NEPOMUK +#include +#include +#include +#endif #include #include @@ -44,17 +50,30 @@ #include #include #include +#include #include #include #include +#include #include +#include "dolphin_informationpanelsettings.h" #include "settings/dolphinsettings.h" #include "metadatawidget.h" #include "metatextlabel.h" #include "phononwidget.h" #include "pixmapviewer.h" +/** + * Helper function for sorting items with qSort() in + * InformationPanel::contextMenu(). + */ +bool lessThan(const QAction* action1, const QAction* action2) +{ + return action1->text() < action2->text(); +} + + InformationPanel::InformationPanel(QWidget* parent) : Panel(parent), m_initialized(false), @@ -69,6 +88,7 @@ InformationPanel::InformationPanel(QWidget* parent) : m_preview(0), m_phononWidget(0), m_metaDataWidget(0), + m_metaTextArea(0), m_metaTextLabel(0) { } @@ -184,10 +204,120 @@ void InformationPanel::resizeEvent(QResizeEvent* event) m_urlCandidate = m_shownUrl; // reset the URL candidate if a resizing is done m_infoTimer->start(); } - Panel::resizeEvent(event); } +bool InformationPanel::eventFilter(QObject* obj, QEvent* event) +{ + // Check whether the size of the meta text area has changed and adjust + // the fixed width in a way that no horizontal scrollbar needs to be shown. + if ((obj == m_metaTextArea->viewport()) && (event->type() == QEvent::Resize)) { + QResizeEvent* resizeEvent = static_cast(event); + m_metaTextLabel->setFixedWidth(resizeEvent->size().width()); + } + return Panel::eventFilter(obj, event); +} + +void InformationPanel::contextMenuEvent(QContextMenuEvent* event) +{ + Panel::contextMenuEvent(event); + +#ifdef HAVE_NEPOMUK + if (showMultipleSelectionInfo()) { + return; + } + + KMenu popup(this); + + QAction* ratingAction = popup.addAction(i18nc("@action:inmenu", "Rating")); + ratingAction->setCheckable(true); + ratingAction->setChecked(InformationPanelSettings::showRating()); + + QAction* commentAction = popup.addAction(i18nc("@action:inmenu", "Comment")); + commentAction->setCheckable(true); + commentAction->setChecked(InformationPanelSettings::showComment()); + + QAction* tagsAction = popup.addAction(i18nc("@action:inmenu", "Tags")); + tagsAction->setCheckable(true); + tagsAction->setChecked(InformationPanelSettings::showTags()); + + KConfig config("kmetainformationrc", KConfig::NoGlobals); + KConfigGroup settings = config.group("Show"); + initMetaInfoSettings(settings); + + QList actions; + + // Get all meta information labels that are available for + // the currently shown file item and add them to the popup. + Nepomuk::Resource res(fileItem().url()); + QHash properties = res.properties(); + QHash::const_iterator it = properties.constBegin(); + while (it != properties.constEnd()) { + Nepomuk::Types::Property prop(it.key()); + const QString key = prop.label(); + + // Meta information provided by Nepomuk that is already + // available from KFileItem should not be configurable. + bool skip = (key == "fileExtension") || + (key == "name") || + (key == "sourceModified") || + (key == "size") || + (key == "mime type"); + if (!skip) { + // Check whether there is already a meta information + // having the same label. In this case don't show it + // twice in the menu. + foreach (const QAction* action, actions) { + if (action->data().toString() == key) { + skip = true; + break; + } + } + } + + if (!skip) { + const QString label = key; // TODO + QAction* action = new QAction(label, &popup); + action->setCheckable(true); + action->setChecked(settings.readEntry(key, true)); + action->setData(key); + actions.append(action); + } + + ++it; + } + + if (actions.count() > 0) { + popup.addSeparator(); + + // add all items alphabetically sorted to the popup + qSort(actions.begin(), actions.end(), lessThan); + foreach (QAction* action, actions) { + popup.addAction(action); + } + } + + // Open the popup and adjust the settings for the + // selected action. + QAction* action = popup.exec(QCursor::pos()); + if (action == 0) { + return; + } + + if (action == ratingAction) { + // TODO + } else if (action == commentAction) { + // TODO + } else if (action == tagsAction) { + // TODO + } else { + settings.writeEntry(action->data().toString(), action->isChecked()); + settings.sync(); + showMetaInfo(); + } +#endif +} + void InformationPanel::showItemInfo() { if (!isVisible()) { @@ -274,11 +404,26 @@ void InformationPanel::showPreview(const KFileItem& item, void InformationPanel::slotFileRenamed(const QString& source, const QString& dest) { - if (m_shownUrl == KUrl(source)) { - // the currently shown file has been renamed, hence update the item information - // for the renamed file - KFileItem item(KFileItem::Unknown, KFileItem::Unknown, KUrl(dest)); - requestDelayedItemInfo(item); + const KUrl sourceUrl = KUrl(source); + + // Verify whether the renamed item is selected. If this is the case, the + // selection must be updated with the renamed item. + bool isSelected = false; + for (int i = m_selection.size() - 1; i >= 0; --i) { + if (m_selection[i].url() == sourceUrl) { + m_selection.removeAt(i); + isSelected = true; + break; + } + } + + if ((m_shownUrl == sourceUrl) || isSelected) { + m_shownUrl = KUrl(dest); + m_fileItem = KFileItem(KFileItem::Unknown, KFileItem::Unknown, m_shownUrl); + if (isSelected) { + m_selection.append(m_fileItem); + } + showItemInfo(); } } @@ -308,8 +453,7 @@ void InformationPanel::slotFilesRemoved(const QStringList& files) if (m_shownUrl == KUrl(fileName)) { // the currently shown item has been removed, show // the parent directory as fallback - m_shownUrl = url(); - showItemInfo(); + reset(); break; } } @@ -330,8 +474,7 @@ void InformationPanel::slotLeftDirectory(const QString& directory) // has been unmounted. In this case no directory change will be // done in Dolphin, but the Information Panel must be updated to // indicate an invalid directory. - m_shownUrl = url(); - showItemInfo(); + reset(); } } @@ -380,6 +523,9 @@ void InformationPanel::showMetaInfo() } } m_metaTextLabel->add(i18nc("@label", "Total size:"), KIO::convertSize(totalSize)); + + delete m_phononWidget; + m_phononWidget = 0; } else { const KFileItem item = fileItem(); if (item.isDir()) { @@ -391,29 +537,26 @@ void InformationPanel::showMetaInfo() m_metaTextLabel->add(i18nc("@label", "Size:"), KIO::convertSize(item.size())); m_metaTextLabel->add(i18nc("@label", "Modified:"), item.timeString()); - if (item.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; - const QString path = item.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; - } +#ifdef HAVE_NEPOMUK + KConfig config("kmetainformationrc", KConfig::NoGlobals); + KConfigGroup settings = config.group("Show"); + initMetaInfoSettings(settings); + + Nepomuk::Resource res(item.url()); + + QHash properties = res.properties(); + QHash::const_iterator it = properties.constBegin(); + while (it != properties.constEnd()) { + Nepomuk::Types::Property prop(it.key()); + const QString label = prop.label(); + if (settings.readEntry(label, true)) { + // TODO: use Nepomuk::formatValue(res, prop) if available + // instead of it.value().toString() + m_metaTextLabel->add(label, it.value().toString()); } + ++it; } +#endif } if (m_metaDataWidget != 0) { @@ -436,45 +579,6 @@ void InformationPanel::showMetaInfo() } } -bool InformationPanel::convertMetaInfo(const QString& key, QString& text) const -{ - struct MetaKey { - const char* key; - QString text; - }; - - // sorted list of keys, where its data should be shown - static const MetaKey keys[] = { - { "http://freedesktop.org/standards/xesam/1.0/core#album", i18nc("@label", "Album:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#artist", i18nc("@label", "Artist:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#genre", i18nc("@label", "Genre:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#height", i18nc("@label", "Height:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#lineCount", i18nc("@label", "Lines:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#title", i18nc("@label", "Title:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#type", i18nc("@label", "Type:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#trackNumber", i18nc("@label", "Track:") }, - { "http://freedesktop.org/standards/xesam/1.0/core#width", i18nc("@label", "Width:") } - }; - - // do a binary search for the key... - int top = 0; - int bottom = sizeof(keys) / sizeof(MetaKey) - 1; - while (top <= bottom) { - const int middle = (top + bottom) / 2; - const int result = key.compare(keys[middle].key); - if (result < 0) { - bottom = middle - 1; - } else if (result > 0) { - top = middle + 1; - } else { - text = keys[middle].text; - return true; - } - } - - return false; -} - KFileItem InformationPanel::fileItem() const { if (!m_fileItem.isNull()) { @@ -532,6 +636,33 @@ void InformationPanel::setNameLabelText(const QString& text) m_nameLabel->setText(wrappedText); } +void InformationPanel::reset() +{ + m_selection.clear(); + m_shownUrl = url(); + m_fileItem = KFileItem(); + showItemInfo(); +} + +void InformationPanel::initMetaInfoSettings(KConfigGroup& group) +{ + if (!group.readEntry("initialized", false)) { + // The resource file is read the first time. Assure + // that some meta information is disabled per default. + group.writeEntry("fileExtension", false); + group.writeEntry("url", false); + group.writeEntry("sourceModified", false); + group.writeEntry("parentUrl", false); + group.writeEntry("size", false); + group.writeEntry("mime type", false); + group.writeEntry("depth", false); + group.writeEntry("name", false); + + // mark the group as initialized + group.writeEntry("initialized", true); + } +} + void InformationPanel::init() { const int spacing = KDialog::spacingHint(); @@ -575,9 +706,20 @@ void InformationPanel::init() // general meta text information m_metaTextLabel = new MetaTextLabel(this); - m_metaTextLabel->setMinimumWidth(spacing); m_metaTextLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + m_metaTextArea = new QScrollArea(this); + m_metaTextArea->setWidget(m_metaTextLabel); + m_metaTextArea->setWidgetResizable(true); + m_metaTextArea->setFrameShape(QFrame::NoFrame); + + QWidget* viewport = m_metaTextArea->viewport(); + viewport->installEventFilter(this); + + QPalette palette = viewport->palette(); + palette.setColor(viewport->backgroundRole(), QColor(Qt::transparent)); + viewport->setPalette(palette); + layout->addWidget(m_nameLabel); layout->addWidget(new KSeparator(this)); layout->addWidget(m_preview); @@ -586,10 +728,7 @@ void InformationPanel::init() layout->addWidget(m_metaDataWidget); layout->addWidget(new KSeparator(this)); } - layout->addWidget(m_metaTextLabel); - - // ensure that widgets in the information side bar are aligned towards the top - layout->addStretch(1); + layout->addWidget(m_metaTextArea); setLayout(layout); org::kde::KDirNotify* dirNotify = new org::kde::KDirNotify(QString(), QString(),