[vlmc-devel] commit: Library: When a clip is removed, emit a signal with its uuid, as the clip may have been deleted. (Hugo Beauzee-Luyssen )

git at videolan.org git at videolan.org
Tue Mar 16 02:09:40 CET 2010


vlmc | branch: master | Hugo Beauzee-Luyssen <beauze.h at gmail.com> | Tue Mar 16 02:08:35 2010 +0100| [5bcf50918bab6c9f62fbd902b4130680ed23316f] | committer: Hugo Beauzee-Luyssen 

Library: When a clip is removed, emit a signal with its uuid, as the clip may have been deleted.

A media that fail to load is automatically removed from the view (as
it's removed from the media container.)
Fixes #4

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

 src/Gui/MainWindow.cpp              |    4 ++--
 src/Gui/import/ImportController.cpp |    4 ++--
 src/Gui/library/MediaCellView.cpp   |   15 +++++----------
 src/Gui/library/MediaCellView.h     |    4 +---
 src/Gui/library/MediaListView.cpp   |   22 ++++++++++++++--------
 src/Gui/library/MediaListView.h     |   10 ++++++++--
 src/Gui/timeline/TracksView.cpp     |    8 ++++----
 src/Gui/timeline/TracksView.h       |    2 +-
 src/Library/MediaContainer.cpp      |    6 +++---
 src/Library/MediaContainer.h        |    4 +++-
 10 files changed, 43 insertions(+), 36 deletions(-)

diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp
index 74e115e..38cb3d0 100644
--- a/src/Gui/MainWindow.cpp
+++ b/src/Gui/MainWindow.cpp
@@ -251,8 +251,8 @@ MainWindow::setupLibrary()
     connect( mediaView, SIGNAL( clipSelected( Clip* ) ),
              clipRenderer, SLOT( setClip( Clip* ) ) );
 
-    connect( Library::getInstance(), SIGNAL( clipRemoved( const Clip* ) ),
-             clipRenderer, SLOT( clipUnloaded( const Clip* ) ) );
+    connect( Library::getInstance(), SIGNAL( clipRemoved( const QUuid& ) ),
+             clipRenderer, SLOT( clipUnloaded( const QUuid& ) ) );
 }
 
 void    MainWindow::on_actionSave_triggered()
diff --git a/src/Gui/import/ImportController.cpp b/src/Gui/import/ImportController.cpp
index 22eeb01..fd44918 100644
--- a/src/Gui/import/ImportController.cpp
+++ b/src/Gui/import/ImportController.cpp
@@ -92,8 +92,8 @@ ImportController::ImportController(QWidget *parent) :
              m_clipRenderer, SLOT( setClip( Clip* ) ) );
     connect( m_mediaListView, SIGNAL( clipSelected( Clip* ) ),
              this, SLOT( clipSelection( Clip* ) ) );
-    connect( m_mediaListView, SIGNAL( clipDeleted( const QUuid& ) ),
-             m_clipRenderer, SLOT( clipUnloaded( const QUuid& ) ) );
+    connect( m_mediaListView, SIGNAL( clipRemoved( const Clip* ) ),
+             m_clipRenderer, SLOT( clipUnloaded( const Clip* ) ) );
 
     connect( MetaDataManager::getInstance(), SIGNAL( failedToCompute( Media* ) ),
              this, SLOT( failedToLoad( Media* ) ) );
diff --git a/src/Gui/library/MediaCellView.cpp b/src/Gui/library/MediaCellView.cpp
index 57ba250..a2ade57 100644
--- a/src/Gui/library/MediaCellView.cpp
+++ b/src/Gui/library/MediaCellView.cpp
@@ -45,9 +45,9 @@ MediaCellView::MediaCellView( Clip* clip, QWidget *parent ) :
              SLOT( arrowButtonClicked( QWidget*, QMouseEvent* ) ) );
     m_ui->clipCount->setText( QString::number( clip->getChilds()->count() ) );
     connect( clip->getChilds(), SIGNAL( newClipLoaded( Clip* ) ),
-             this, SLOT( nbClipUpdated( Clip* ) ) );
-    connect( clip->getChilds(), SIGNAL( clipRemoved( const Clip* ) ),
-             this, SLOT( nbClipUpdated( const Clip* ) ) );
+             this, SLOT( nbClipUpdated() ) );
+    connect( clip->getChilds(), SIGNAL( clipRemoved( const QUuid& ) ),
+             this, SLOT( nbClipUpdated() ) );
     if ( clip->getChilds()->count() == 0 )
     {
         m_ui->clipCount->hide();
@@ -103,14 +103,9 @@ void            MediaCellView::setTitle( const QString& title )
 }
 
 void
-MediaCellView::nbClipUpdated( Clip *clip )
+MediaCellView::nbClipUpdated()
 {
-    nbClipUpdated( const_cast<const Clip*>( clip ) );
-}
-
-void            MediaCellView::nbClipUpdated( const Clip *clip )
-{
-    quint32     nbClips = clip->getParent()->getChilds()->count();
+    quint32     nbClips = m_clip->getParent()->getChilds()->count();
 
     if ( nbClips == 0 )
     {
diff --git a/src/Gui/library/MediaCellView.h b/src/Gui/library/MediaCellView.h
index 7c969db..331da9f 100644
--- a/src/Gui/library/MediaCellView.h
+++ b/src/Gui/library/MediaCellView.h
@@ -81,9 +81,7 @@ public slots:
 private slots:
     void        snapshotUpdated( const Media *media );
     void        metadataUpdated( const Media *media );
-    void        nbClipUpdated( const Clip *clip );
-    void        nbClipUpdated( Clip *clip );
-
+    void        nbClipUpdated();
 };
 
 #endif // MEDIACELLVIEW_H
diff --git a/src/Gui/library/MediaListView.cpp b/src/Gui/library/MediaListView.cpp
index 0ecc42b..a4c80c5 100644
--- a/src/Gui/library/MediaListView.cpp
+++ b/src/Gui/library/MediaListView.cpp
@@ -32,8 +32,10 @@ MediaListView::MediaListView( StackViewController* nav, MediaContainer* mc ) :
 {
     connect( mc, SIGNAL( newClipLoaded(Clip*) ),
              this, SLOT( newClipLoaded( Clip* ) ) );
-    connect( this, SIGNAL( clipDeleted( const QUuid& ) ),
-             mc, SLOT(removeClip( const QUuid& ) ) );
+    connect( this, SIGNAL( clipRemoved( const Clip* ) ),
+             mc, SLOT( removeClip( const Clip* ) ) );
+    connect( mc, SIGNAL( clipRemoved( const QUuid& ) ),
+             this, SLOT( __clipRemoved( const QUuid& ) ) );
     foreach ( Clip* clip, mc->clips() )
         newClipLoaded( clip );
 }
@@ -52,7 +54,7 @@ void        MediaListView::newClipLoaded( Clip *clip )
     connect( cell, SIGNAL ( cellSelected( QUuid ) ),
              this, SLOT ( cellSelection( QUuid ) ) );
     connect( cell, SIGNAL ( cellDeleted( const Clip* ) ),
-             this, SLOT( clipRemoved( const Clip* ) ) );
+             this, SLOT( removeClip( const Clip* ) ) );
     connect( cell, SIGNAL( arrowClicked( const QUuid& ) ),
              this, SLOT( showSubClips( const QUuid& ) ) );
     addCell( cell );
@@ -80,14 +82,18 @@ void    MediaListView::cellSelection( const QUuid& uuid )
     }
 }
 
-void    MediaListView::clipRemoved( const Clip* clip )
+void    MediaListView::removeClip( const Clip* clip )
 {
-    QWidget* cell = m_cells.value( clip->uuid() );
+    __clipRemoved( clip->uuid() );
+    emit clipRemoved( clip );
+}
+
+void
+MediaListView::__clipRemoved( const QUuid &uuid )
+{
+    QWidget* cell = m_cells.take( uuid );
     removeCell( cell );
-    m_cells.remove( clip->uuid() );
     m_currentUuid = QUuid();
-    emit clipDeleted( clip->uuid() );
-    delete clip;
 }
 
 void
diff --git a/src/Gui/library/MediaListView.h b/src/Gui/library/MediaListView.h
index b5c6374..58e7c52 100644
--- a/src/Gui/library/MediaListView.h
+++ b/src/Gui/library/MediaListView.h
@@ -53,11 +53,17 @@ public slots:
     void        clear();
 
 private slots:
-    void        clipRemoved( const Clip* );
+    void        removeClip( const Clip* );
+    /**
+     *  \brief  Called when the media container unload a clip
+     *
+     *  This slot will be triggered when a Clip is removed from the media container.
+     */
+    void        __clipRemoved( const QUuid& );
     void        newClipLoaded( Clip* clip );
 
 signals:
     void        clipSelected( Clip* );
-    void        clipDeleted( const QUuid& );
+    void        clipRemoved( const Clip* );
 };
 #endif // MEDIALISTVIEW_H
diff --git a/src/Gui/timeline/TracksView.cpp b/src/Gui/timeline/TracksView.cpp
index f17f74c..dc24ac0 100644
--- a/src/Gui/timeline/TracksView.cpp
+++ b/src/Gui/timeline/TracksView.cpp
@@ -72,8 +72,8 @@ TracksView::TracksView( QGraphicsScene *scene, MainWorkflow *mainWorkflow,
 
     connect( m_cursorLine, SIGNAL( cursorPositionChanged(qint64) ),
              this, SLOT( ensureCursorVisible() ) );
-    connect( Library::getInstance(), SIGNAL( clipRemoved( const Clip* ) ),
-             this, SLOT( deleteMedia( const Clip* ) ) );
+    connect( Library::getInstance(), SIGNAL( clipRemoved( const QUuid& ) ),
+             this, SLOT( deleteMedia( const QUuid& ) ) );
 }
 
 void
@@ -184,7 +184,7 @@ TracksView::clear()
 }
 
 void
-TracksView::deleteMedia( const Clip* clip  )
+TracksView::deleteMedia( const QUuid& uuid  )
 {
     AbstractGraphicsMediaItem *item;
 
@@ -196,7 +196,7 @@ TracksView::deleteMedia( const Clip* clip  )
     foreach( item, items )
     {
         if ( item->clip()->getMedia()->baseClip()->uuid() ==
-             clip->uuid() )
+             uuid )
         {
             // This item needs to be removed.
             // Saving its values
diff --git a/src/Gui/timeline/TracksView.h b/src/Gui/timeline/TracksView.h
index e6310af..12fdda6 100644
--- a/src/Gui/timeline/TracksView.h
+++ b/src/Gui/timeline/TracksView.h
@@ -185,7 +185,7 @@ public slots:
      * \brief Remove a Media from the timeline (and from the backend).
      * \param uuid The unique identifier of the Media.
      */
-    void                    deleteMedia( const Clip* clip  );
+    void                    deleteMedia( const QUuid& uuid );
     /**
      * \brief Insert an item into the timeline.
      * \param clip Clip to insert.
diff --git a/src/Library/MediaContainer.cpp b/src/Library/MediaContainer.cpp
index b97c5b2..004fae7 100644
--- a/src/Library/MediaContainer.cpp
+++ b/src/Library/MediaContainer.cpp
@@ -120,7 +120,7 @@ MediaContainer::clear()
 
     while ( it != end )
     {
-        emit clipRemoved( it.value() );
+        emit clipRemoved( it.key() );
         it.value()->clear();
         it.value()->deleteLater();
         ++it;
@@ -136,7 +136,7 @@ MediaContainer::removeAll()
 
     while ( it != end )
     {
-        emit clipRemoved( it.value() );
+        emit clipRemoved( it.key() );
         ++it;
     }
     m_clips.clear();
@@ -150,7 +150,7 @@ MediaContainer::removeClip( const QUuid &uuid )
     {
         Clip* clip = it.value();
         m_clips.remove( uuid );
-        emit clipRemoved( clip );
+        emit clipRemoved( uuid );
         return clip;
     }
     return NULL;
diff --git a/src/Library/MediaContainer.h b/src/Library/MediaContainer.h
index 40fa640..0186f94 100644
--- a/src/Library/MediaContainer.h
+++ b/src/Library/MediaContainer.h
@@ -154,9 +154,11 @@ signals:
     void    newClipLoaded( Clip* );
     /**
      *  \brief This signal should be emiteted when a Clip has been removed
+     *  This signal pass a QUuid as the clip may be deleted when the signal reaches its
+     *  slot.
      *  \param uuid The removed clip uuid
      */
-    void    clipRemoved( const Clip* );
+    void    clipRemoved( const QUuid& );
 };
 
 #endif // MEDIACONTAINER_H



More information about the Vlmc-devel mailing list