[vlmc-devel] commit: Workspace: Relocate medias when changing the project location ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Sun Jun 27 23:06:25 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Sun Jun 27 19:39:10 2010 +0200| [bce997599f3c4ed54d588519f35c75b60261ce8d] | committer: Hugo Beauzée-Luyssen 

Workspace: Relocate medias when changing the project location

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

 src/Gui/project/GuiProjectManager.cpp |    2 +
 src/Project/Workspace.cpp             |   79 +++++++++++++++++++++++++-------
 src/Project/Workspace.h               |    8 +++-
 src/Project/WorkspaceWorker.cpp       |    3 +-
 4 files changed, 72 insertions(+), 20 deletions(-)

diff --git a/src/Gui/project/GuiProjectManager.cpp b/src/Gui/project/GuiProjectManager.cpp
index 62906aa..950b260 100644
--- a/src/Gui/project/GuiProjectManager.cpp
+++ b/src/Gui/project/GuiProjectManager.cpp
@@ -33,6 +33,8 @@
 #include <QMessageBox>
 #include <QTimer>
 
+#include <QtDebug>
+
 GUIProjectManager::GUIProjectManager()
 {
     connect( this, SIGNAL( projectClosed() ), Library::getInstance(), SLOT( clear() ) );
diff --git a/src/Project/Workspace.cpp b/src/Project/Workspace.cpp
index 45e2ff8..b8e8f79 100644
--- a/src/Project/Workspace.cpp
+++ b/src/Project/Workspace.cpp
@@ -32,24 +32,44 @@
 
 const QString   Workspace::workspacePrefix = "workspace://";
 
-Workspace::Workspace()
+Workspace::Workspace() : m_copyInProgress( false )
 {
-//    connect( Library::getInstance(), SIGNAL( newClipLoaded( Clip* ) ),
-//             this, SLOT( clipLoaded( Clip* ) ) );
+    m_mediasToCopyMutex = new QMutex;
+}
+
+Workspace::~Workspace()
+{
+    delete m_mediasToCopyMutex;
 }
 
 void
 Workspace::copyToWorkspace( Media *media )
 {
-    qDebug() << "Copying media:" << media->fileInfo()->absoluteFilePath() << "to workspace.";
-    if ( media->isInWorkspace() == false )
+    QMutexLocker    lock( m_mediasToCopyMutex );
+
+    if ( m_copyInProgress == true )
     {
-        WorkspaceWorker *worker = new WorkspaceWorker( media );
-        //This one is direct connected since the thread is terminated just after emitting the signal.
-        connect( worker, SIGNAL( copied( Media*, QString ) ),
-                 this, SLOT( copyTerminated( Media*, QString ) ), Qt::DirectConnection );
-        worker->start();
+        m_mediasToCopy.enqueue( media );
     }
+    else
+    {
+        qDebug() << "Copying media:" << media->fileInfo()->absoluteFilePath() << "to workspace.";
+        m_copyInProgress = true;
+        if ( media->isInWorkspace() == false )
+        {
+            startCopyWorker( media );
+        }
+    }
+}
+
+void
+Workspace::startCopyWorker( Media *media )
+{
+    WorkspaceWorker *worker = new WorkspaceWorker( media );
+    //This one is direct connected since the thread is terminated just after emitting the signal.
+    connect( worker, SIGNAL( copied( Media*, QString ) ),
+             this, SLOT( copyTerminated( Media*, QString ) ), Qt::DirectConnection );
+    worker->start();
 }
 
 void
@@ -68,14 +88,31 @@ void
 Workspace::copyTerminated( Media *media, QString dest )
 {
     media->setFilePath( dest );
+    media->disconnect( this );
+
+    QMutexLocker    lock( m_mediasToCopyMutex );
+    if ( m_mediasToCopy.size() > 0 )
+    {
+        while ( m_mediasToCopy.size() > 0 )
+        {
+            Media   *toCopy = m_mediasToCopy.dequeue();
+            if ( toCopy->isInWorkspace() == false )
+            {
+                startCopyWorker( toCopy );
+                break ;
+            }
+        }
+    }
+    else
+        m_copyInProgress = false;
 }
 
 bool
 Workspace::isInProjectDir( const QFileInfo &fInfo )
 {
-    const QString       projectDir = VLMC_PROJECT_GET_STRING( "general/ProjectDir" );
+    const QString       projectDir = VLMC_PROJECT_GET_STRING( "general/Workspace" );
 
-    return ( fInfo.absolutePath().startsWith( projectDir ) );
+    return ( projectDir.length() > 0 && fInfo.absolutePath().startsWith( projectDir ) );
 }
 
 bool
@@ -95,7 +132,7 @@ Workspace::isInProjectDir(const Media *media)
 QString
 Workspace::pathInProjectDir( const Media *media )
 {
-    const QString      projectDir = VLMC_PROJECT_GET_STRING( "general/ProjectDir" );
+    const QString      projectDir = VLMC_PROJECT_GET_STRING( "general/Workspace" );
 
     return ( media->fileInfo()->absoluteFilePath().mid( projectDir.length() ) );
 }
@@ -103,12 +140,18 @@ Workspace::pathInProjectDir( const Media *media )
 void
 Workspace::copyAllToWorkspace()
 {
-    QHash<QString, Media*>::iterator    it = Library::getInstance()->m_medias.begin();
-    QHash<QString, Media*>::iterator    ite = Library::getInstance()->m_medias.end();
+    if ( Library::getInstance()->m_clips.size() == 0 )
+        return ;
+    QHash<QUuid, Clip*>::iterator    it = Library::getInstance()->m_clips.begin();
+    QHash<QUuid, Clip*>::iterator    ite = Library::getInstance()->m_clips.end();
 
-    while ( it != ite )
     {
-        //FIXME
-        ++it;
+        QMutexLocker    lock( m_mediasToCopyMutex );
+        while ( it != ite )
+        {
+            m_mediasToCopy.enqueue( it.value()->getMedia() );
+            ++it;
+        }
     }
+    copyToWorkspace( m_mediasToCopy.dequeue() );
 }
diff --git a/src/Project/Workspace.h b/src/Project/Workspace.h
index 5ae9966..1d7694e 100644
--- a/src/Project/Workspace.h
+++ b/src/Project/Workspace.h
@@ -25,6 +25,7 @@
 
 #include <QObject>
 
+#include <QMutex>
 #include <QQueue>
 
 #include "Singleton.hpp"
@@ -49,7 +50,12 @@ class Workspace : public QObject, public Singleton<Workspace>
         void                        copyAllToWorkspace();
     private:
         Workspace();
-        ~Workspace(){}
+        ~Workspace();
+        void                        startCopyWorker( Media *media );
+    private:
+        QQueue<Media*>              m_mediasToCopy;
+        QMutex                      *m_mediasToCopyMutex;
+        bool                        m_copyInProgress;
 
     public slots:
         void                        clipLoaded( Clip* clip );
diff --git a/src/Project/WorkspaceWorker.cpp b/src/Project/WorkspaceWorker.cpp
index b4ff57b..d1af1ba 100644
--- a/src/Project/WorkspaceWorker.cpp
+++ b/src/Project/WorkspaceWorker.cpp
@@ -40,9 +40,10 @@ void
 WorkspaceWorker::run()
 {
     QFile           file( m_media->fileInfo()->absoluteFilePath() );
-    const QString   &projectPath = VLMC_PROJECT_GET_STRING( "general/ProjectDir" );
+    const QString   &projectPath = VLMC_PROJECT_GET_STRING( "general/Workspace" );
     const QString   dest = projectPath + '/' + m_media->fileInfo()->fileName();
 
     file.copy( m_media->fileInfo()->absoluteFilePath(), dest );
+    qDebug() << "Media copied to:" << dest;
     emit copied( m_media, dest );
 }



More information about the Vlmc-devel mailing list