X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/993c47f30923e39b33dbd47a2a62e3dde5ccdbe4..200bc71130f4e60c28cdc7d32249eeb321e71d13:/src/panels/information/informationpanelcontent.cpp diff --git a/src/panels/information/informationpanelcontent.cpp b/src/panels/information/informationpanelcontent.cpp index 5dcf8612e..363ad818d 100644 --- a/src/panels/information/informationpanelcontent.cpp +++ b/src/panels/information/informationpanelcontent.cpp @@ -29,14 +29,9 @@ #include #include -#include #include -#ifndef HAVE_BALOO -#include -#else #include -#endif #include #include @@ -45,6 +40,7 @@ #include #include +#include #include #include #include @@ -52,7 +48,6 @@ #include #include "dolphin_informationpanelsettings.h" -#include "filemetadataconfigurationdialog.h" #include "phononwidget.h" #include "pixmapviewer.h" @@ -91,6 +86,7 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) : m_phononWidget = new PhononWidget(parent); m_phononWidget->hide(); m_phononWidget->setMinimumWidth(minPreviewWidth); + m_phononWidget->setAutoPlay(InformationPanelSettings::previewsAutoPlay()); connect(m_phononWidget, &PhononWidget::hasVideoChanged, this, &InformationPanelContent::slotHasVideoChanged); @@ -106,30 +102,38 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) : const bool previewsShown = InformationPanelSettings::previewsShown(); m_preview->setVisible(previewsShown); -#ifndef HAVE_BALOO - m_metaDataWidget = new KFileMetaDataWidget(parent); - connect(m_metaDataWidget, &KFileMetaDataWidget::urlActivated, - this, &InformationPanelContent::urlActivated); -#else m_metaDataWidget = new Baloo::FileMetaDataWidget(parent); + m_metaDataWidget->setDateFormat(static_cast(InformationPanelSettings::dateFormat())); connect(m_metaDataWidget, &Baloo::FileMetaDataWidget::urlActivated, this, &InformationPanelContent::urlActivated); -#endif m_metaDataWidget->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)); m_metaDataWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); - // Encapsulate the MetaDataWidget inside a container that has a dummy widget - // at the bottom. This prevents that the meta data widget gets vertically stretched - // in the case where the height of m_metaDataArea > m_metaDataWidget. - QWidget* metaDataWidgetContainer = new QWidget(parent); - QVBoxLayout* containerLayout = new QVBoxLayout(metaDataWidgetContainer); - containerLayout->setContentsMargins(0, 0, 0, 0); - containerLayout->setSpacing(0); - containerLayout->addWidget(m_metaDataWidget); - containerLayout->addStretch(); + // Configuration + m_configureLabel = new QLabel(i18nc("@label::textbox", + "Select which data should be shown:"), this); + m_configureLabel->setWordWrap(true); + m_configureLabel->setVisible(false); + + m_configureButtons = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel); + m_configureButtons->setVisible(false); + connect(m_configureButtons, &QDialogButtonBox::accepted, this, [this]() { + m_metaDataWidget->setConfigurationMode(Baloo::ConfigurationMode::Accept); + m_configureButtons->setVisible(false); + m_configureLabel->setVisible(false); + emit configurationFinished(); + } + ); + connect(m_configureButtons, &QDialogButtonBox::rejected, this, [this]() { + m_metaDataWidget->setConfigurationMode(Baloo::ConfigurationMode::Cancel); + m_configureButtons->setVisible(false); + m_configureLabel->setVisible(false); + emit configurationFinished(); + } + ); m_metaDataArea = new QScrollArea(parent); - m_metaDataArea->setWidget(metaDataWidgetContainer); + m_metaDataArea->setWidget(m_metaDataWidget); m_metaDataArea->setWidgetResizable(true); m_metaDataArea->setFrameShape(QFrame::NoFrame); @@ -140,7 +144,9 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) : layout->addWidget(m_phononWidget); layout->addWidget(m_nameLabel); layout->addWidget(new KSeparator()); + layout->addWidget(m_configureLabel); layout->addWidget(m_metaDataArea); + layout->addWidget(m_configureButtons); m_placesItemModel = new PlacesItemModel(this); } @@ -151,6 +157,16 @@ InformationPanelContent::~InformationPanelContent() } void InformationPanelContent::showItem(const KFileItem& item) +{ + if (item != m_item) { + m_item = item; + + refreshMetaData(); + } + refreshPreview(); +} + +void InformationPanelContent::refreshPreview() { // If there is a preview job, kill it to prevent that we have jobs for // multiple items running, and thus a race condition (bug 250787). @@ -158,63 +174,87 @@ void InformationPanelContent::showItem(const KFileItem& item) m_previewJob->kill(); } - const QUrl itemUrl = item.url(); - const bool isSearchUrl = itemUrl.scheme().contains(QStringLiteral("search")) && item.localPath().isEmpty(); - setNameLabelText(item.text()); - if (isSearchUrl) { - // in the case of a search-URL the URL is not readable for humans - // (at least not useful to show in the Information Panel) - m_preview->setPixmap( - QIcon::fromTheme(QStringLiteral("nepomuk")).pixmap(KIconLoader::SizeEnormous, KIconLoader::SizeEnormous) - ); - } else { - // try to get a preview pixmap from the item... - - // Mark the currently shown preview as outdated. This is done - // with a small delay to prevent a flickering when the next preview - // can be shown within a short timeframe. This timer is not started - // for directories, as directory previews might fail and return the - // same icon. - if (!item.isDir()) { - m_outdatedPreviewTimer->start(); - } + setNameLabelText(m_item.text()); + if (InformationPanelSettings::previewsShown()) { - m_previewJob = new KIO::PreviewJob(KFileItemList() << item, QSize(m_preview->width(), m_preview->height())); - m_previewJob->setScaleType(KIO::PreviewJob::Unscaled); - m_previewJob->setIgnoreMaximumSize(item.isLocalFile()); - if (m_previewJob->uiDelegate()) { - KJobWidgets::setWindow(m_previewJob, this); - } + const QUrl itemUrl = m_item.url(); + const bool isSearchUrl = itemUrl.scheme().contains(QStringLiteral("search")) && m_item.localPath().isEmpty(); + if (isSearchUrl) { + m_preview->show(); - connect(m_previewJob.data(), &KIO::PreviewJob::gotPreview, - this, &InformationPanelContent::showPreview); - connect(m_previewJob.data(), &KIO::PreviewJob::failed, - this, &InformationPanelContent::showIcon); - } + // in the case of a search-URL the URL is not readable for humans + // (at least not useful to show in the Information Panel) + m_preview->setPixmap( + QIcon::fromTheme(QStringLiteral("nepomuk")).pixmap(KIconLoader::SizeEnormous, KIconLoader::SizeEnormous) + ); + } else { + // try to get a preview pixmap from the item... + + // Mark the currently shown preview as outdated. This is done + // with a small delay to prevent a flickering when the next preview + // can be shown within a short timeframe. This timer is not started + // for directories, as directory previews might fail and return the + // same icon. + if (!m_item.isDir()) { + m_outdatedPreviewTimer->start(); + } - if (m_metaDataWidget) { - m_metaDataWidget->show(); - m_metaDataWidget->setItems(KFileItemList() << item); - } + QStringList plugins = KIO::PreviewJob::availablePlugins(); + m_previewJob = new KIO::PreviewJob(KFileItemList() << m_item, + QSize(m_preview->width(), m_preview->height()), + &plugins); + m_previewJob->setScaleType(KIO::PreviewJob::Unscaled); + m_previewJob->setIgnoreMaximumSize(m_item.isLocalFile()); + if (m_previewJob->uiDelegate()) { + KJobWidgets::setWindow(m_previewJob, this); + } - if (InformationPanelSettings::previewsShown()) { - const QString mimeType = item.mimetype(); - const bool usePhonon = mimeType.startsWith(QLatin1String("audio/")) || mimeType.startsWith(QLatin1String("video/")); - if (usePhonon) { - m_phononWidget->show(); - m_phononWidget->setUrl(item.targetUrl()); - if (m_preview->isVisible()) { + connect(m_previewJob.data(), &KIO::PreviewJob::gotPreview, + this, &InformationPanelContent::showPreview); + connect(m_previewJob.data(), &KIO::PreviewJob::failed, + this, &InformationPanelContent::showIcon); + + const QString mimeType = m_item.mimetype(); + const bool isVideo = mimeType.startsWith(QLatin1String("video/")); + const bool usePhonon = mimeType.startsWith(QLatin1String("audio/")) || isVideo; + + if (usePhonon) { + + if (InformationPanelSettings::previewsAutoPlay() && isVideo) { + // hides the preview now to avoid flickering when the autoplay video starts + m_preview->hide(); + } else { + // the video won't play before the preview is displayed + m_preview->show(); + } + + m_phononWidget->show(); + m_phononWidget->setUrl(m_item.targetUrl(), isVideo ? PhononWidget::MediaKind::Video : PhononWidget::MediaKind::Audio); m_phononWidget->setVideoSize(m_preview->size()); + } else { + // When we don't need it, hide the phonon widget first to avoid flickering + m_phononWidget->hide(); + m_preview->show(); } - } else { - m_phononWidget->hide(); - m_preview->setVisible(true); } } else { + m_preview->hide(); m_phononWidget->hide(); } +} - m_item = item; +void InformationPanelContent::configureShownProperties() +{ + m_configureLabel->setVisible(true); + m_configureButtons->setVisible(true); + m_metaDataWidget->setConfigurationMode(Baloo::ConfigurationMode::ReStart); +} + +void InformationPanelContent::refreshMetaData() +{ + m_metaDataWidget->setDateFormat(static_cast(InformationPanelSettings::dateFormat())); + m_metaDataWidget->show(); + m_metaDataWidget->setItems(KFileItemList() << m_item); } void InformationPanelContent::showItems(const KFileItemList& items) @@ -230,9 +270,7 @@ void InformationPanelContent::showItems(const KFileItemList& items) ); setNameLabelText(i18ncp("@label", "%1 item selected", "%1 items selected", items.count())); - if (m_metaDataWidget) { - m_metaDataWidget->setItems(items); - } + m_metaDataWidget->setItems(items); m_phononWidget->hide(); @@ -269,45 +307,6 @@ bool InformationPanelContent::eventFilter(QObject* obj, QEvent* event) return QWidget::eventFilter(obj, event); } -void InformationPanelContent::configureSettings(const QList& customContextMenuActions) -{ - QMenu popup(this); - - QAction* previewAction = popup.addAction(i18nc("@action:inmenu", "Preview")); - previewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-preview"))); - previewAction->setCheckable(true); - previewAction->setChecked(InformationPanelSettings::previewsShown()); - - QAction* configureAction = popup.addAction(i18nc("@action:inmenu", "Configure...")); - configureAction->setIcon(QIcon::fromTheme(QStringLiteral("configure"))); - - popup.addSeparator(); - foreach (QAction* action, customContextMenuActions) { - popup.addAction(action); - } - - // Open the popup and adjust the settings for the - // selected action. - QAction* action = popup.exec(QCursor::pos()); - if (!action) { - return; - } - - const bool isChecked = action->isChecked(); - if (action == previewAction) { - m_preview->setVisible(isChecked); - InformationPanelSettings::setPreviewsShown(isChecked); - } else if (action == configureAction) { - FileMetaDataConfigurationDialog* dialog = new FileMetaDataConfigurationDialog(this); - dialog->setDescription(i18nc("@label::textbox", - "Select which data should be shown in the information panel:")); - dialog->setItems(m_metaDataWidget->items()); - dialog->setAttribute(Qt::WA_DeleteOnClose); - dialog->show(); - connect(dialog, &FileMetaDataConfigurationDialog::destroyed, this, &InformationPanelContent::refreshMetaData); - } -} - void InformationPanelContent::showIcon(const KFileItem& item) { m_outdatedPreviewTimer->stop(); @@ -336,16 +335,18 @@ void InformationPanelContent::markOutdatedPreview() m_preview->setPixmap(disabledPixmap); } -void InformationPanelContent::slotHasVideoChanged(bool hasVideo) +KFileItemList InformationPanelContent::items() { - m_preview->setVisible(!hasVideo); + return m_metaDataWidget->items(); } -void InformationPanelContent::refreshMetaData() +void InformationPanelContent::slotHasVideoChanged(bool hasVideo) { - if (!m_item.isNull()) { - showItem(m_item); - } + m_preview->setVisible(InformationPanelSettings::previewsShown() && !hasVideo); +} + +void InformationPanelContent::setPreviewAutoPlay(bool autoPlay) { + m_phononWidget->setAutoPlay(autoPlay); } void InformationPanelContent::setNameLabelText(const QString& text) @@ -391,9 +392,7 @@ void InformationPanelContent::adjustWidgetSizes(int width) // The metadata widget also contains a text widget which may return // a large preferred width. - if (m_metaDataWidget) { - m_metaDataWidget->setMaximumWidth(maxWidth); - } + m_metaDataWidget->setMaximumWidth(maxWidth); // try to increase the preview as large as possible m_preview->setSizeHint(QSize(maxWidth, maxWidth));