[vlmc-devel] commit: Library: Ensure every media are loaded before emiting projectLoaded () signal (Hugo Beauzee-Luyssen )

git at videolan.org git at videolan.org
Sat Mar 13 14:39:49 CET 2010


vlmc | branch: master | Hugo Beauzee-Luyssen <beauze.h at gmail.com> | Sat Mar 13 14:39:28 2010 +0100| [94e97152b7e4bebd8c0e4c34539a2dc0dd7374c2] | committer: Hugo Beauzee-Luyssen 

Library: Ensure every media are loaded before emiting projectLoaded() signal

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=94e97152b7e4bebd8c0e4c34539a2dc0dd7374c2
---

 src/Library/Library.cpp |   18 +++++++++++++++++-
 src/Library/Library.h   |    8 +++++++-
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/Library/Library.cpp b/src/Library/Library.cpp
index 67bab16..ed37022 100644
--- a/src/Library/Library.cpp
+++ b/src/Library/Library.cpp
@@ -38,6 +38,10 @@
 #include <QUuid>
 #include <QXmlStreamWriter>
 
+Library::Library() : m_nbMediaToLoad( 0 )
+{
+}
+
 void
 Library::loadProject( const QDomElement& doc )
 {
@@ -53,7 +57,10 @@ Library::loadProject( const QDomElement& doc )
         {
             QString mrl = media.attribute( "mrl" );
             Media* m = addMedia( mrl );
+            connect( m, SIGNAL( metaDataComputed( const Media* ) ),
+                     this, SLOT( mediaLoaded( const Media* ) ), Qt::QueuedConnection );
             m_medias[mrl] = m;
+            ++m_nbMediaToLoad;
         }
         media = media.nextSibling().toElement();
     }
@@ -61,7 +68,6 @@ Library::loadProject( const QDomElement& doc )
     if ( clips.isNull() == true )
         return ;
     load( clips, this );
-    emit projectLoaded();
 }
 
 void
@@ -81,3 +87,13 @@ Library::saveProject( QXmlStreamWriter& project )
     save( project );
     project.writeEndElement();
 }
+
+void
+Library::mediaLoaded( const Media* media )
+{
+    disconnect( media, SIGNAL( metaDataComputed( const Media* ) ),
+             this, SLOT( mediaLoaded( const Media* ) ) );
+    --m_nbMediaToLoad;
+    if ( m_nbMediaToLoad == 0 )
+        emit projectLoaded();
+}
diff --git a/src/Library/Library.h b/src/Library/Library.h
index 517f5b1..253874e 100644
--- a/src/Library/Library.h
+++ b/src/Library/Library.h
@@ -57,9 +57,12 @@ class Library : public MediaContainer, public Singleton<Library>
     Q_DISABLE_COPY( Library );
 
 private:
-    Library(){}
+    Library();
     virtual ~Library(){}
 
+private:
+    quint32     m_nbMediaToLoad;
+
 public slots:
     /**
      *  \brief
@@ -70,6 +73,9 @@ public slots:
      */
     void    saveProject( QXmlStreamWriter& project );
 
+private slots:
+    void    mediaLoaded( const Media* m );
+
 signals:
     /**
      *  \brief



More information about the Vlmc-devel mailing list