diff --git a/src/panels/information/phononwidget.h b/src/panels/information/phononwidget.h --- a/src/panels/information/phononwidget.h +++ b/src/panels/information/phononwidget.h @@ -26,6 +26,7 @@ #include #include #include +#include namespace Phonon { @@ -87,6 +88,7 @@ Phonon::SeekSlider *m_seekSlider; Phonon::AudioOutput *m_audioOutput; EmbeddedVideoPlayer *m_videoPlayer; + QTimer *m_autoPlayTimer; }; #endif // PHONONWIDGET_H diff --git a/src/panels/information/phononwidget.cpp b/src/panels/information/phononwidget.cpp --- a/src/panels/information/phononwidget.cpp +++ b/src/panels/information/phononwidget.cpp @@ -19,6 +19,7 @@ */ #include "phononwidget.h" +#include "dolphin_generalsettings.h" #include #include @@ -30,6 +31,7 @@ #include #include #include +#include class EmbeddedVideoPlayer : public Phonon::VideoWidget { @@ -67,13 +69,22 @@ m_audioOutput(nullptr), m_videoPlayer(nullptr) { + // timer to start/stop the auto play + m_autoPlayTimer = new QTimer(this); + m_autoPlayTimer->setSingleShot(true); + connect(m_autoPlayTimer, &QTimer::timeout, this, &PhononWidget::play); } void PhononWidget::setUrl(const QUrl &url) { if (m_url != url) { stop(); // emits playingStopped() signal m_url = url; + + if (GeneralSettings::autoPlayMediaFiles()) { + // TODO move the 1000 ms to a constant or a setting + m_autoPlayTimer->start(1000); + } } } @@ -211,6 +222,9 @@ if (m_media) { m_media->stop(); } + if (m_autoPlayTimer->isActive()) { + m_autoPlayTimer->stop(); + } } void PhononWidget::slotHasVideoChanged(bool hasVideo) diff --git a/src/settings/dolphin_generalsettings.kcfg b/src/settings/dolphin_generalsettings.kcfg --- a/src/settings/dolphin_generalsettings.kcfg +++ b/src/settings/dolphin_generalsettings.kcfg @@ -109,6 +109,10 @@ true + + + false + diff --git a/src/settings/general/previewssettingspage.h b/src/settings/general/previewssettingspage.h --- a/src/settings/general/previewssettingspage.h +++ b/src/settings/general/previewssettingspage.h @@ -25,6 +25,7 @@ class QSpinBox; class QListView; class QModelIndex; +class QCheckBox; /** * @brief Allows the configuration of file previews. @@ -61,7 +62,8 @@ bool m_initialized; QListView *m_listView; QStringList m_enabledPreviewPlugins; - QSpinBox* m_remoteFileSizeBox; + QSpinBox *m_remoteFileSizeBox; + QCheckBox *m_autoPlayMediaFiles; }; #endif diff --git a/src/settings/general/previewssettingspage.cpp b/src/settings/general/previewssettingspage.cpp --- a/src/settings/general/previewssettingspage.cpp +++ b/src/settings/general/previewssettingspage.cpp @@ -34,6 +34,7 @@ #include #include #include +#include // default settings namespace { @@ -45,7 +46,8 @@ m_initialized(false), m_listView(nullptr), m_enabledPreviewPlugins(), - m_remoteFileSizeBox(nullptr) + m_remoteFileSizeBox(nullptr), + m_autoPlayMediaFiles(nullptr) { QVBoxLayout* topLayout = new QVBoxLayout(this); @@ -78,14 +80,18 @@ fileSizeBoxLayout->addWidget(remoteFileSizeLabel, 0, Qt::AlignRight); fileSizeBoxLayout->addWidget(m_remoteFileSizeBox); + m_autoPlayMediaFiles = new QCheckBox(i18nc("@option:check", "Play media files automatically while hovering"), this); + topLayout->addWidget(showPreviewsLabel); topLayout->addWidget(m_listView); topLayout->addLayout(fileSizeBoxLayout); + topLayout->addWidget(m_autoPlayMediaFiles); loadSettings(); connect(m_listView, &QListView::clicked, this, &PreviewsSettingsPage::changed); connect(m_remoteFileSizeBox, static_cast(&QSpinBox::valueChanged), this, &PreviewsSettingsPage::changed); + connect(m_autoPlayMediaFiles, &QCheckBox::toggled, this, &PreviewsSettingsPage::changed); } PreviewsSettingsPage::~PreviewsSettingsPage() @@ -116,11 +122,16 @@ maximumRemoteSize, KConfigBase::Normal | KConfigBase::Global); globalConfig.sync(); + + GeneralSettings* settings = GeneralSettings::self(); + settings->setAutoPlayMediaFiles(m_autoPlayMediaFiles->isChecked()); + settings->save(); } void PreviewsSettingsPage::restoreDefaults() { m_remoteFileSizeBox->setValue(MaxRemotePreviewSize); + m_autoPlayMediaFiles->setChecked(false); } void PreviewsSettingsPage::showEvent(QShowEvent* event) @@ -172,5 +183,7 @@ const qulonglong maxRemoteByteSize = globalConfig.readEntry("MaximumRemoteSize", defaultRemotePreview); const int maxRemoteMByteSize = maxRemoteByteSize / (1024 * 1024); m_remoteFileSizeBox->setValue(maxRemoteMByteSize); + + m_autoPlayMediaFiles->setChecked(GeneralSettings::autoPlayMediaFiles()); }