[vlmc-devel] MetaDataWorker: Delegate the snapshot handling to the GuiMedia.
Hugo Beauzée-Luyssen
git at videolan.org
Sun Sep 23 16:31:36 CEST 2012
vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Sun Sep 23 16:07:03 2012 +0300| [967bfbd51ead6b18cf5cffd2298692061a48abe9] | committer: Hugo Beauzée-Luyssen
MetaDataWorker: Delegate the snapshot handling to the GuiMedia.
This allows to remove dirty haks such as "emitSnapshotComputed"
Also, it breaks image snapshot computing for now.
> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=967bfbd51ead6b18cf5cffd2298692061a48abe9
---
src/Gui/media/GuiMedia.cpp | 22 ++++++++++++++++------
src/Gui/media/GuiMedia.h | 4 +++-
src/Metadata/MetaDataWorker.cpp | 29 ++++++++---------------------
src/Metadata/MetaDataWorker.h | 1 -
4 files changed, 27 insertions(+), 29 deletions(-)
diff --git a/src/Gui/media/GuiMedia.cpp b/src/Gui/media/GuiMedia.cpp
index 50ea829..26ab7e3 100644
--- a/src/Gui/media/GuiMedia.cpp
+++ b/src/Gui/media/GuiMedia.cpp
@@ -30,6 +30,22 @@ GUIMedia::GUIMedia() :
{
}
+void GUIMedia::snapshotReady(const char *fileName)
+{
+ QFile tmp( fileName );
+
+ QPixmap* pixmap = new QPixmap( fileName );
+ if ( pixmap->isNull() )
+ delete pixmap;
+ else
+ {
+ setSnapshot( pixmap );
+ emit snapshotComputed( qobject_cast<const Media*>( this ) );
+ }
+ tmp.remove();
+
+}
+
GUIMedia::~GUIMedia()
{
if ( m_snapshot )
@@ -59,9 +75,3 @@ GUIMedia::hasSnapshot() const
{
return ( m_snapshot != NULL );
}
-
-void
-GUIMedia::emitSnapshotComputed()
-{
- emit snapshotComputed( qobject_cast<const Media*>( this ) );
-}
diff --git a/src/Gui/media/GuiMedia.h b/src/Gui/media/GuiMedia.h
index 19ac9c7..35459ec 100644
--- a/src/Gui/media/GuiMedia.h
+++ b/src/Gui/media/GuiMedia.h
@@ -38,7 +38,6 @@ public:
void setSnapshot( QPixmap* snapshot );
const QPixmap &snapshot() const;
bool hasSnapshot() const;
- void emitSnapshotComputed();
protected:
//A GUIMedia shouldn't be constructed by something else than a media
@@ -48,6 +47,9 @@ protected:
QPixmap* m_snapshot;
+public slots:
+ void snapshotReady( const char *fileName );
+
signals:
void snapshotComputed( const Media* );
};
diff --git a/src/Metadata/MetaDataWorker.cpp b/src/Metadata/MetaDataWorker.cpp
index b44b926..233603d 100644
--- a/src/Metadata/MetaDataWorker.cpp
+++ b/src/Metadata/MetaDataWorker.cpp
@@ -43,6 +43,7 @@ MetaDataWorker::MetaDataWorker( LibVLCpp::MediaPlayer* mediaPlayer, Media* media
m_media( media ),
m_audioBuffer( NULL )
{
+ connect( this, SIGNAL( finished() ), this, SLOT( deleteLater() ) );
}
MetaDataWorker::~MetaDataWorker()
@@ -138,9 +139,9 @@ MetaDataWorker::metaDataAvailable()
}
else if ( m_media->fileType() == Media::Image && m_media->hasSnapshot() == false )
{
- QPixmap *pixmap = new QPixmap( m_media->fileInfo()->absoluteFilePath() );
- m_media->setSnapshot( pixmap );
- m_media->emitSnapshotComputed();
+// QPixmap *pixmap = new QPixmap( m_media->fileInfo()->absoluteFilePath() );
+// m_media->setSnapshot( pixmap );
+// m_media->emitSnapshotComputed();
}
#endif
finalize();
@@ -175,10 +176,12 @@ MetaDataWorker::computeSnapshot()
tmp.setAutoRemove( false );
// Although this function is synchrone, we have to be in the main thread to
- // handle a QPixmap
+ // handle a QPixmap, hence the QueuedConnection
connect( m_mediaPlayer, SIGNAL( snapshotTaken( const char* ) ),
- this, SLOT( renderSnapshot( const char* ) ) );
+ m_media, SLOT( snapshotReady( const char* ) ),
+ Qt::QueuedConnection );
m_mediaPlayer->takeSnapshot( tmp.fileName().toUtf8().constData(), 0, 0 );
+ finalize();
}
#endif
@@ -186,7 +189,6 @@ void
MetaDataWorker::finalize()
{
emit computed();
- deleteLater();
}
void
@@ -196,21 +198,6 @@ MetaDataWorker::failure()
deleteLater();
}
-void MetaDataWorker::renderSnapshot(const char* filename)
-{
- QFile tmp( filename );
-
- QPixmap* pixmap = new QPixmap( filename );
- if ( pixmap->isNull() )
- delete pixmap;
- else
- m_media->setSnapshot( pixmap );
-
- m_media->emitSnapshotComputed();
- tmp.remove();
- finalize();
-}
-
//void
//MetaDataWorker::prepareAudioSpectrumComputing()
//{
diff --git a/src/Metadata/MetaDataWorker.h b/src/Metadata/MetaDataWorker.h
index e900e0a..a7506f6 100644
--- a/src/Metadata/MetaDataWorker.h
+++ b/src/Metadata/MetaDataWorker.h
@@ -74,7 +74,6 @@ class MetaDataWorker : public QThread
private slots:
// void generateAudioSpectrum();
void failure();
- void renderSnapshot(const char *filename);
signals:
void computed();
More information about the Vlmc-devel
mailing list