X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/87eb2a2ff3c3186209bbb1cfc19c5b2f16511f11..ed0df8dc1fc9576e36c920882e7f4b00a2811113:/src/panels/information/informationpanel.cpp diff --git a/src/panels/information/informationpanel.cpp b/src/panels/information/informationpanel.cpp index c586742cf..1b8724f46 100644 --- a/src/panels/information/informationpanel.cpp +++ b/src/panels/information/informationpanel.cpp @@ -23,16 +23,16 @@ #include #include -#include -#include -#include -#include #include -#include #include +#include +#include +#include #include -#include #include +#include +#include +#include #ifdef HAVE_NEPOMUK #include @@ -57,12 +57,23 @@ #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), @@ -75,8 +86,10 @@ InformationPanel::InformationPanel(QWidget* parent) : m_selection(), m_nameLabel(0), m_preview(0), + m_previewSeparator(0), m_phononWidget(0), m_metaDataWidget(0), + m_metaDataSeparator(0), m_metaTextArea(0), m_metaTextLabel(0) { @@ -84,6 +97,7 @@ InformationPanel::InformationPanel(QWidget* parent) : InformationPanel::~InformationPanel() { + InformationPanelSettings::self()->writeConfig(); } QSize InformationPanel::sizeHint() const @@ -192,6 +206,11 @@ void InformationPanel::resizeEvent(QResizeEvent* event) m_preview->setSizeHint(QSize(maxWidth, maxWidth)); m_urlCandidate = m_shownUrl; // reset the URL candidate if a resizing is done m_infoTimer->start(); + + if (m_phononWidget->isVisible() && (m_phononWidget->mode() == PhononWidget::Video)) { + // assure that the size of the video player is the same as the preview size + m_phononWidget->setVideoSize(QSize(maxWidth, maxWidth)); + } } Panel::resizeEvent(event); } @@ -207,6 +226,132 @@ bool InformationPanel::eventFilter(QObject* obj, QEvent* event) return Panel::eventFilter(obj, event); } +void InformationPanel::contextMenuEvent(QContextMenuEvent* event) +{ + Panel::contextMenuEvent(event); + +#ifdef HAVE_NEPOMUK + if (showMultipleSelectionInfo()) { + return; + } + + KMenu popup(this); + + QAction* previewAction = popup.addAction(i18nc("@action:inmenu", "Preview")); + previewAction->setIcon(KIcon("view-preview")); + previewAction->setCheckable(true); + previewAction->setChecked(InformationPanelSettings::showPreview()); + + const bool metaDataAvailable = MetaDataWidget::metaDataAvailable(); + + QAction* ratingAction = popup.addAction(i18nc("@action:inmenu", "Rating")); + ratingAction->setIcon(KIcon("rating")); + ratingAction->setCheckable(true); + ratingAction->setChecked(InformationPanelSettings::showRating()); + ratingAction->setEnabled(metaDataAvailable); + + QAction* commentAction = popup.addAction(i18nc("@action:inmenu", "Comment")); + commentAction->setIcon(KIcon("text-plain")); + commentAction->setCheckable(true); + commentAction->setChecked(InformationPanelSettings::showComment()); + commentAction->setEnabled(metaDataAvailable); + + QAction* tagsAction = popup.addAction(i18nc("@action:inmenu", "Tags")); + tagsAction->setCheckable(true); + tagsAction->setChecked(InformationPanelSettings::showTags()); + tagsAction->setEnabled(metaDataAvailable); + + 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; + } + + const bool isChecked = action->isChecked(); + if (action == previewAction) { + m_preview->setVisible(isChecked); + m_previewSeparator->setVisible(isChecked); + InformationPanelSettings::setShowPreview(isChecked); + updatePhononWidget(); + } else if (action == ratingAction) { + m_metaDataWidget->setRatingVisible(isChecked); + InformationPanelSettings::setShowRating(isChecked); + } else if (action == commentAction) { + m_metaDataWidget->setCommentVisible(isChecked); + InformationPanelSettings::setShowComment(isChecked); + } else if (action == tagsAction) { + m_metaDataWidget->setTagsVisible(isChecked); + InformationPanelSettings::setShowTags(isChecked); + } else { + settings.writeEntry(action->data().toString(), action->isChecked()); + settings.sync(); + showMetaInfo(); + } + + const bool visible = m_metaDataWidget->isRatingVisible() || + m_metaDataWidget->isCommentVisible() || + m_metaDataWidget->areTagsVisible(); + m_metaDataSeparator->setVisible(visible); +#endif +} + void InformationPanel::showItemInfo() { if (!isVisible()) { @@ -293,11 +438,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(); } } @@ -352,6 +512,16 @@ void InformationPanel::slotLeftDirectory(const QString& directory) } } +void InformationPanel::slotPlayingStarted() +{ + m_preview->setVisible(m_phononWidget->mode() != PhononWidget::Video); +} + +void InformationPanel::slotPlayingStopped() +{ + m_preview->setVisible(true); +} + bool InformationPanel::applyPlace(const KUrl& url) { KFilePlacesModel* placesModel = DolphinSettings::instance().placesModel(); @@ -397,9 +567,6 @@ 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()) { @@ -412,15 +579,22 @@ void InformationPanel::showMetaInfo() m_metaTextLabel->add(i18nc("@label", "Modified:"), item.timeString()); #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()); - // TODO: use Nepomuk::formatValue(res, prop) if available - // instead of it.value().toString() - m_metaTextLabel->add(prop.label(), it.value().toString()); + 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 @@ -429,21 +603,9 @@ void InformationPanel::showMetaInfo() if (m_metaDataWidget != 0) { m_metaDataWidget->setFile(item.targetUrl()); } - - if (Phonon::BackendCapabilities::isMimeTypeAvailable(item.mimetype())) { - if (m_phononWidget == 0) { - m_phononWidget = new PhononWidget(this); - - QVBoxLayout* vBoxLayout = qobject_cast(layout()); - Q_ASSERT(vBoxLayout != 0); - vBoxLayout->insertWidget(3, m_phononWidget); - } - m_phononWidget->setUrl(item.url()); - } else { - delete m_phononWidget; - m_phononWidget = 0; - } } + + updatePhononWidget(); } KFileItem InformationPanel::fileItem() const @@ -511,10 +673,57 @@ void InformationPanel::reset() showItemInfo(); } -void InformationPanel::init() +void InformationPanel::initMetaInfoSettings(KConfigGroup& group) { - const int spacing = KDialog::spacingHint(); + 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::updatePhononWidget() +{ + const bool multipleSelections = showMultipleSelectionInfo(); + const bool showPreview = InformationPanelSettings::showPreview(); + + if (multipleSelections || !showPreview) { + m_phononWidget->hide(); + } else if (!multipleSelections && showPreview) { + const KFileItem item = fileItem(); + const QString mimeType = item.mimetype(); + const bool usePhonon = Phonon::BackendCapabilities::isMimeTypeAvailable(mimeType) && + (mimeType != "image/png"); // TODO: workaround, as Phonon + // thinks it supports PNG images + if (usePhonon) { + m_phononWidget->show(); + PhononWidget::Mode mode = mimeType.startsWith("video") + ? PhononWidget::Video + : PhononWidget::Audio; + m_phononWidget->setMode(mode); + m_phononWidget->setUrl(item.url()); + if ((mode == PhononWidget::Video) && m_preview->isVisible()) { + m_phononWidget->setVideoSize(m_preview->size()); + } + } else { + m_phononWidget->hide(); + m_preview->setVisible(true); + } + } +} +void InformationPanel::init() +{ m_infoTimer = new QTimer(this); m_infoTimer->setInterval(300); m_infoTimer->setSingleShot(true); @@ -531,7 +740,7 @@ void InformationPanel::init() this, SLOT(markOutdatedPreview())); QVBoxLayout* layout = new QVBoxLayout; - layout->setSpacing(spacing); + layout->setSpacing(KDialog::spacingHint()); // name m_nameLabel = new QLabel(this); @@ -540,16 +749,43 @@ void InformationPanel::init() m_nameLabel->setFont(font); m_nameLabel->setAlignment(Qt::AlignHCenter); m_nameLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + m_nameLabel->setMaximumWidth(KIconLoader::SizeEnormous); // preview + const int minPreviewWidth = KIconLoader::SizeEnormous + KIconLoader::SizeMedium; + m_preview = new PixmapViewer(this); - m_preview->setMinimumWidth(KIconLoader::SizeEnormous + KIconLoader::SizeMedium); + m_preview->setMinimumWidth(minPreviewWidth); m_preview->setMinimumHeight(KIconLoader::SizeEnormous); + m_phononWidget = new PhononWidget(this); + m_phononWidget->setMinimumWidth(minPreviewWidth); + connect(m_phononWidget, SIGNAL(playingStarted()), + this, SLOT(slotPlayingStarted())); + connect(m_phononWidget, SIGNAL(playingStopped()), + this, SLOT(slotPlayingStopped())); + + m_previewSeparator = new KSeparator(this); + + const bool showPreview = InformationPanelSettings::showPreview(); + m_preview->setVisible(showPreview); + m_previewSeparator->setVisible(showPreview); + if (MetaDataWidget::metaDataAvailable()) { // rating, comment and tags m_metaDataWidget = new MetaDataWidget(this); m_metaDataWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + + const bool showRating = InformationPanelSettings::showRating(); + const bool showComment = InformationPanelSettings::showComment(); + const bool showTags = InformationPanelSettings::showTags(); + + m_metaDataWidget->setRatingVisible(showRating); + m_metaDataWidget->setCommentVisible(showComment); + m_metaDataWidget->setTagsVisible(showTags); + + m_metaDataSeparator = new KSeparator(this); + m_metaDataSeparator->setVisible(showRating || showComment || showTags); } // general meta text information @@ -571,10 +807,11 @@ void InformationPanel::init() layout->addWidget(m_nameLabel); layout->addWidget(new KSeparator(this)); layout->addWidget(m_preview); - layout->addWidget(new KSeparator(this)); + layout->addWidget(m_phononWidget); + layout->addWidget(m_previewSeparator); if (m_metaDataWidget != 0) { layout->addWidget(m_metaDataWidget); - layout->addWidget(new KSeparator(this)); + layout->addWidget(m_metaDataSeparator); } layout->addWidget(m_metaTextArea); setLayout(layout);