]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Show video previews according to file content instead of the mimetype-string
authorPeter Penz <peter.penz19@gmail.com>
Sat, 19 May 2012 20:27:53 +0000 (22:27 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 19 May 2012 20:30:31 +0000 (22:30 +0200)
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

src/panels/information/informationpanelcontent.cpp
src/panels/information/informationpanelcontent.h
src/panels/information/phononwidget.cpp
src/panels/information/phononwidget.h

index 4a96bd1b6f266f3f0e4e7153f061f43aac554ffc..1cbe0cd31737943ed0d514bcca2f655de1dc58f3 100644 (file)
@@ -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));
     }
index 1d964f515933f819e4a7b4199038c31d916c8ec1..0f90c5ea1b7189872f42078d038d8b537da53eb4 100644 (file)
@@ -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
index 5f0c1115827f37de817d3cf32a3c5d35b21e4e2b..1419f68be9b80e425b08b59285458db22817a93a 100644 (file)
 
 #include "phononwidget.h"
 
+#include <Phonon/AudioOutput>
 #include <Phonon/Global>
 #include <Phonon/MediaObject>
 #include <Phonon/SeekSlider>
-#include <Phonon/VideoPlayer>
+#include <Phonon/VideoWidget>
 
 #include <QVBoxLayout>
 #include <QHBoxLayout>
 #include <KUrl>
 #include <KLocale>
 
-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()
index 1e1ea37e9b4c892879756e41b40a1a1ea6e7be37..b5aedfe4f209fe461cae53dd833124cf67f90888 100644 (file)
@@ -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;
 };