Commit 3233a0bf authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Workspace: Check for file existance before copy.

parent fd173bff
......@@ -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 );
......
......@@ -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 );
}
......@@ -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 );
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment