[vlmc-devel] commit: MediaContainer: Don' t add the same clip twice in the same container (Hugo Beauzee-Luyssen )

git at videolan.org git at videolan.org
Wed Mar 10 23:43:45 CET 2010


vlmc | branch: master | Hugo Beauzee-Luyssen <beauze.h at gmail.com> | Wed Mar 10 23:29:33 2010 +0100| [5912bd9f398ba56200cb6763766427d6f0b00ce5] | committer: Hugo Beauzee-Luyssen 

MediaContainer: Don't add the same clip twice in the same container

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

 src/Gui/PreviewWidget.cpp      |    3 ++-
 src/Library/MediaContainer.cpp |   10 +++++++++-
 src/Library/MediaContainer.h   |    8 +++++---
 src/Media/Clip.cpp             |    4 ++--
 src/Media/Clip.h               |    2 +-
 5 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/Gui/PreviewWidget.cpp b/src/Gui/PreviewWidget.cpp
index 82a185a..a5301e5 100644
--- a/src/Gui/PreviewWidget.cpp
+++ b/src/Gui/PreviewWidget.cpp
@@ -209,5 +209,6 @@ void        PreviewWidget::createNewClipFromMarkers()
     Clip*   part = new Clip( clip, beg, end );
 
     //Adding the newly created clip to the media
-    clip->addSubclip( part );
+    if ( clip->addSubclip( part ) == false )
+        delete part;
 }
diff --git a/src/Library/MediaContainer.cpp b/src/Library/MediaContainer.cpp
index 43eef54..febd859 100644
--- a/src/Library/MediaContainer.cpp
+++ b/src/Library/MediaContainer.cpp
@@ -79,11 +79,19 @@ MediaContainer::mediaAlreadyLoaded( const QFileInfo& fileInfo )
     return false;
 }
 
-void
+bool
 MediaContainer::addClip( Clip* clip )
 {
+    foreach ( Clip* c, m_clips.values() )
+    {
+        if ( clip->uuid() == c->uuid() ||
+             ( clip->getMedia()->fileInfo() == clip->getMedia()->fileInfo() &&
+                    ( clip->begin() == c->begin() && clip->end() == c->end() ) ) )
+            return false;
+    }
     m_clips[clip->uuid()] = clip;
     emit newClipLoaded( clip );
+    return true;
 }
 
 void
diff --git a/src/Library/MediaContainer.h b/src/Library/MediaContainer.h
index 2d9a9cf..f672fca 100644
--- a/src/Library/MediaContainer.h
+++ b/src/Library/MediaContainer.h
@@ -70,15 +70,17 @@ public:
      *  \param  fileInfo    The file infos
      *  \return true if the file is already loaded, false otherwhise
      */
-    bool    mediaAlreadyLoaded( const QFileInfo& fileInfo );
+    bool        mediaAlreadyLoaded( const QFileInfo& fileInfo );
     /**
      *  \brief  Add a clip.
      *
-     *  This will emit the newClipLoaded signal.
+     *  The method will first check for an identic clip existence.
+     *  This will emit the newClipLoaded signal if the Clip is added.
      *
      *  \param  clip    The clip to be added.
+     *  \return true if the Clip has been added.
      */
-    void    addClip( Clip* clip );
+    bool        addClip( Clip* clip );
 
     /**
      *  \return All the loaded Clip
diff --git a/src/Media/Clip.cpp b/src/Media/Clip.cpp
index 445d31a..84a8198 100644
--- a/src/Media/Clip.cpp
+++ b/src/Media/Clip.cpp
@@ -280,10 +280,10 @@ Clip::getChilds() const
     return m_childs;
 }
 
-void
+bool
 Clip::addSubclip( Clip *clip )
 {
-    m_childs->addClip( clip );
+    return m_childs->addClip( clip );
 }
 
 void
diff --git a/src/Media/Clip.h b/src/Media/Clip.h
index 58f39fe..e609865 100644
--- a/src/Media/Clip.h
+++ b/src/Media/Clip.h
@@ -122,7 +122,7 @@ class   Clip : public QObject
          */
         void                clear();
 
-        void                addSubclip( Clip* clip );
+        bool                addSubclip( Clip* clip );
 
     private:
         Media               *m_media;



More information about the Vlmc-devel mailing list