From c318a3da6c79c35b4d3ba3043d71228cbeda64f8 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Sat, 19 May 2012 22:27:53 +0200 Subject: [PATCH] Show video previews according to file content instead of the mimetype-string Show a video widget depending on the video content instead of the mimetype string: There are container formats which can be either audios or videos. Besides, the rmvb video files have a mimetype of "application/vnd.rn-realmedia", and these files can be recognized as videos correctly now. The patch has been provided by Hui Ni. REVIEW: 104988 FIXED-IN: 4.9 --- .../information/informationpanelcontent.cpp | 23 ++--- .../information/informationpanelcontent.h | 3 +- src/panels/information/phononwidget.cpp | 93 +++++++++---------- src/panels/information/phononwidget.h | 25 +++-- 4 files changed, 61 insertions(+), 83 deletions(-) diff --git a/src/panels/information/informationpanelcontent.cpp b/src/panels/information/informationpanelcontent.cpp index 4a96bd1b6..1cbe0cd31 100644 --- a/src/panels/information/informationpanelcontent.cpp +++ b/src/panels/information/informationpanelcontent.cpp @@ -90,10 +90,8 @@ InformationPanelContent::InformationPanelContent(QWidget* parent) : m_phononWidget = new PhononWidget(parent); m_phononWidget->hide(); m_phononWidget->setMinimumWidth(minPreviewWidth); - connect(m_phononWidget, SIGNAL(playingStarted()), - this, SLOT(slotPlayingStarted())); - connect(m_phononWidget, SIGNAL(playingStopped()), - this, SLOT(slotPlayingStopped())); + connect(m_phononWidget, SIGNAL(hasVideoChanged(bool)), + this, SLOT(slotHasVideoChanged(bool))); // name m_nameLabel = new QLabel(parent); @@ -200,12 +198,8 @@ void InformationPanelContent::showItem(const KFileItem& item) // thinks it supports PNG images if (usePhonon) { m_phononWidget->show(); - PhononWidget::Mode mode = mimeType.startsWith(QLatin1String("video")) - ? PhononWidget::Video - : PhononWidget::Audio; - m_phononWidget->setMode(mode); m_phononWidget->setUrl(item.targetUrl()); - if ((mode == PhononWidget::Video) && m_preview->isVisible()) { + if (m_preview->isVisible()) { m_phononWidget->setVideoSize(m_preview->size()); } } else { @@ -338,14 +332,9 @@ void InformationPanelContent::markOutdatedPreview() m_preview->setPixmap(disabledPixmap); } -void InformationPanelContent::slotPlayingStarted() +void InformationPanelContent::slotHasVideoChanged(bool hasVideo) { - m_preview->setVisible(m_phononWidget->mode() != PhononWidget::Video); -} - -void InformationPanelContent::slotPlayingStopped() -{ - m_preview->setVisible(true); + m_preview->setVisible(!hasVideo); } void InformationPanelContent::refreshMetaData() @@ -423,7 +412,7 @@ void InformationPanelContent::adjustWidgetSizes(int width) // try to increase the preview as large as possible m_preview->setSizeHint(QSize(maxWidth, maxWidth)); - if (m_phononWidget->isVisible() && (m_phononWidget->mode() == PhononWidget::Video)) { + if (m_phononWidget->isVisible()) { // assure that the size of the video player is the same as the preview size m_phononWidget->setVideoSize(QSize(maxWidth, maxWidth)); } diff --git a/src/panels/information/informationpanelcontent.h b/src/panels/information/informationpanelcontent.h index 1d964f515..0f90c5ea1 100644 --- a/src/panels/information/informationpanelcontent.h +++ b/src/panels/information/informationpanelcontent.h @@ -92,8 +92,7 @@ private slots: */ void markOutdatedPreview(); - void slotPlayingStarted(); - void slotPlayingStopped(); + void slotHasVideoChanged(bool hasVideo); /** * Is invoked after the file meta data configuration dialog has been diff --git a/src/panels/information/phononwidget.cpp b/src/panels/information/phononwidget.cpp index 5f0c11158..1419f68be 100644 --- a/src/panels/information/phononwidget.cpp +++ b/src/panels/information/phononwidget.cpp @@ -20,10 +20,11 @@ #include "phononwidget.h" +#include #include #include #include -#include +#include #include #include @@ -35,11 +36,11 @@ #include #include -class EmbeddedVideoPlayer : public Phonon::VideoPlayer +class EmbeddedVideoPlayer : public Phonon::VideoWidget { public: - EmbeddedVideoPlayer(Phonon::Category category, QWidget *parent = 0) : - Phonon::VideoPlayer(category, parent) + EmbeddedVideoPlayer(QWidget *parent = 0) : + Phonon::VideoWidget(parent) { } @@ -51,7 +52,7 @@ class EmbeddedVideoPlayer : public Phonon::VideoPlayer virtual QSize sizeHint() const { - return m_sizeHint.isValid() ? m_sizeHint : Phonon::VideoPlayer::sizeHint(); + return m_sizeHint.isValid() ? m_sizeHint : Phonon::VideoWidget::sizeHint(); } private: @@ -60,14 +61,13 @@ class EmbeddedVideoPlayer : public Phonon::VideoPlayer PhononWidget::PhononWidget(QWidget *parent) : QWidget(parent), - m_mode(Audio), m_url(), m_playButton(0), m_stopButton(0), m_topLayout(0), - m_audioMedia(0), m_media(0), m_seekSlider(0), + m_audioOutput(0), m_videoPlayer(0) { } @@ -85,19 +85,6 @@ KUrl PhononWidget::url() const return m_url; } -void PhononWidget::setMode(Mode mode) -{ - if (m_mode != mode) { - stop(); // emits playingStopped() signal - m_mode = mode; - } -} - -PhononWidget::Mode PhononWidget::mode() const -{ - return m_mode; -} - void PhononWidget::setVideoSize(const QSize& size) { if (m_videoSize != size) { @@ -183,47 +170,31 @@ void PhononWidget::stateChanged(Phonon::State newstate) void PhononWidget::play() { - switch (m_mode) { - case Audio: - if (!m_audioMedia) { - m_audioMedia = Phonon::createPlayer(Phonon::MusicCategory, m_url); - m_audioMedia->setParent(this); - } - m_media = m_audioMedia; - m_media->setCurrentSource(m_url); - m_media->play(); - break; - - case Video: - if (!m_videoPlayer) { - m_videoPlayer = new EmbeddedVideoPlayer(Phonon::VideoCategory, this); - m_topLayout->insertWidget(0, m_videoPlayer); - } - applyVideoSize(); - m_videoPlayer->show(); - m_videoPlayer->play(m_url); - m_media = m_videoPlayer->mediaObject(); - break; + if (!m_media) { + m_media = new Phonon::MediaObject(this); + connect(m_media, SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this, SLOT(stateChanged(Phonon::State))); + connect(m_media, SIGNAL(hasVideoChanged(bool)), + this, SLOT(slotHasVideoChanged(bool))); + m_seekSlider->setMediaObject(m_media); + } - default: - break; + if (!m_audioOutput) { + m_audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); + Phonon::createPath(m_media, m_audioOutput); } - Q_ASSERT(m_media); - connect(m_media, SIGNAL(stateChanged(Phonon::State,Phonon::State)), - this, SLOT(stateChanged(Phonon::State))); - m_seekSlider->setMediaObject(m_media); + emit hasVideoChanged(false); - emit playingStarted(); + m_media->setCurrentSource(m_url); + m_media->hasVideo(); + m_media->play(); } void PhononWidget::stop() { if (m_media) { m_media->stop(); - disconnect(m_media, SIGNAL(stateChanged(Phonon::State,Phonon::State)), - this, SLOT(stateChanged(Phonon::State))); - emit playingStopped(); m_stopButton->hide(); m_playButton->show(); @@ -232,6 +203,26 @@ void PhononWidget::stop() if (m_videoPlayer) { m_videoPlayer->hide(); } + + emit hasVideoChanged(false); +} + +void PhononWidget::slotHasVideoChanged(bool hasVideo) +{ + emit hasVideoChanged(hasVideo); + + if (hasVideo) { + if (!m_videoPlayer) { + // Replay the media to apply path changes + m_media->stop(); + m_videoPlayer = new EmbeddedVideoPlayer(this); + m_topLayout->insertWidget(0, m_videoPlayer); + Phonon::createPath(m_media, m_videoPlayer); + m_media->play(); + } + applyVideoSize(); + m_videoPlayer->show(); + } } void PhononWidget::applyVideoSize() diff --git a/src/panels/information/phononwidget.h b/src/panels/information/phononwidget.h index 1e1ea37e9..b5aedfe4f 100644 --- a/src/panels/information/phononwidget.h +++ b/src/panels/information/phononwidget.h @@ -30,6 +30,7 @@ namespace Phonon { + class AudioOutput; class MediaObject; class SeekSlider; class VideoPlayer; @@ -43,26 +44,24 @@ class PhononWidget : public QWidget { Q_OBJECT public: - enum Mode - { - Audio, - Video - }; - PhononWidget(QWidget *parent = 0); void setUrl(const KUrl &url); KUrl url() const; - void setMode(Mode mode); - Mode mode() const; - void setVideoSize(const QSize& size); QSize videoSize() const; signals: - void playingStarted(); - void playingStopped(); + /** + * Is emitted whenever the video-state + * has changed: If true is returned, a video + * including control-buttons will be shown. + * If false is returned, no video is shown + * and the control-buttons are available for + * audio only. + */ + void hasVideoChanged(bool hasVideo); protected: virtual void showEvent(QShowEvent *event); @@ -72,12 +71,12 @@ class PhononWidget : public QWidget void stateChanged(Phonon::State); void play(); void stop(); + void slotHasVideoChanged(bool); private: void applyVideoSize(); private: - Mode m_mode; KUrl m_url; QSize m_videoSize; @@ -85,9 +84,9 @@ class PhononWidget : public QWidget QToolButton *m_stopButton; QVBoxLayout *m_topLayout; - Phonon::MediaObject *m_audioMedia; Phonon::MediaObject *m_media; Phonon::SeekSlider *m_seekSlider; + Phonon::AudioOutput *m_audioOutput; EmbeddedVideoPlayer *m_videoPlayer; }; -- 2.47.3