[vlmc-devel] commit: Workspace: Check for file existance before copy. ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Mon Jun 28 00:57:05 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Mon Jun 28 00:33:00 2010 +0200| [3233a0bf2e7e12d742da4ab2c700e9df79bff1a2] | committer: Hugo Beauzée-Luyssen 

Workspace: Check for file existance before copy.

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

 src/Project/Workspace.cpp       |   24 +++++++++++++++++++++++-
 src/Project/WorkspaceWorker.cpp |   17 ++++++++---------
 src/Project/WorkspaceWorker.h   |    3 ++-
 3 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/src/Project/Workspace.cpp b/src/Project/Workspace.cpp
index b8e8f79..1444036 100644
--- a/src/Project/Workspace.cpp
+++ b/src/Project/Workspace.cpp
@@ -30,6 +30,10 @@
 
 #include <QtDebug>
 
+#ifdef WITH_GUI
+# include <QMessageBox>
+#endif
+
 const QString   Workspace::workspacePrefix = "workspace://";
 
 Workspace::Workspace() : m_copyInProgress( false )
@@ -65,7 +69,25 @@ Workspace::copyToWorkspace( Media *media )
 void
 Workspace::startCopyWorker( Media *media )
 {
-    WorkspaceWorker *worker = new WorkspaceWorker( media );
+    const QString   &projectPath = VLMC_PROJECT_GET_STRING( "general/Workspace" );
+    const QString   dest = projectPath + '/' + media->fileInfo()->fileName();
+
+    if ( QFile::exists( dest ) == true )
+    {
+#ifdef WITH_GUI
+        QMessageBox::StandardButton b =
+                QMessageBox::question( NULL, tr( "File already exists!" ),
+                                       tr( "A file with the same name already exists, do you want to "
+                                           "overwrite it?" ),
+                                       QMessageBox::Yes | QMessageBox::No,
+                                       QMessageBox::No );
+        if ( b == QMessageBox::No )
+            copyTerminated( media, dest );
+#else
+        copyTerminated( media, dest );
+#endif
+    }
+    WorkspaceWorker *worker = new WorkspaceWorker( media, dest );
     //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 );
diff --git a/src/Project/WorkspaceWorker.cpp b/src/Project/WorkspaceWorker.cpp
index 21e2f0d..1ae5a0b 100644
--- a/src/Project/WorkspaceWorker.cpp
+++ b/src/Project/WorkspaceWorker.cpp
@@ -31,8 +31,9 @@
 
 #include <QtDebug>
 
-WorkspaceWorker::WorkspaceWorker( Media *media ) :
-    m_media( media )
+WorkspaceWorker::WorkspaceWorker( Media *media, const QString &dest ) :
+    m_media( media ),
+    m_dest( dest )
 {
     connect( this, SIGNAL( finished() ), this, SLOT( deleteLater() ) );
 }
@@ -40,20 +41,18 @@ WorkspaceWorker::WorkspaceWorker( Media *media ) :
 void
 WorkspaceWorker::run()
 {
-    const QString   &projectPath = VLMC_PROJECT_GET_STRING( "general/Workspace" );
-    const QString   dest = projectPath + '/' + m_media->fileInfo()->fileName();
     bool            hardLinkOk = false;
 
 #ifdef Q_OS_UNIX
     if ( link( m_media->fileInfo()->absoluteFilePath().toStdString().c_str(),
-          dest.toStdString().c_str() ) < 0 )
+          m_dest.toStdString().c_str() ) < 0 )
     {
         qDebug() << "Can't create hard link:" << strerror(errno) << "falling back to"
                 " hard copy mode.";
     }
     else
     {
-        qDebug() << "Media hard linked to:" << dest;
+        qDebug() << "Media hard linked to:" << m_dest;
         hardLinkOk = true;
     }
 #endif
@@ -62,8 +61,8 @@ WorkspaceWorker::run()
     {
         QFile           file( m_media->fileInfo()->absoluteFilePath() );
 
-        file.copy( m_media->fileInfo()->absoluteFilePath(), dest );
-        qDebug() << "Media copied to:" << dest;
+        file.copy( m_media->fileInfo()->absoluteFilePath(), m_dest );
+        qDebug() << "Media copied to:" << m_dest;
     }
-    emit copied( m_media, dest );
+    emit copied( m_media, m_dest );
 }
diff --git a/src/Project/WorkspaceWorker.h b/src/Project/WorkspaceWorker.h
index f524090..588ea3c 100644
--- a/src/Project/WorkspaceWorker.h
+++ b/src/Project/WorkspaceWorker.h
@@ -31,12 +31,13 @@ class WorkspaceWorker : public QThread
 {
     Q_OBJECT
     public:
-        explicit WorkspaceWorker( Media *filePath );
+        explicit WorkspaceWorker( Media *filePath, const QString &dest );
 
     protected:
         void                run();
     private:
         Media*              m_media;
+        QString             m_dest;
     signals:
         void                copied( Media*, QString dest );
 };



More information about the Vlmc-devel mailing list