Commit 7ed6d983 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

Workspace: Kill old media media copying code

It hasn't been tested for ages, and isn't aligned with our current goal
of using the medialibrary.
parent bf86b5f0
......@@ -33,118 +33,14 @@
#include "Settings/Settings.h"
#include "Tools/VlmcDebug.h"
#include "Project/WorkspaceWorker.h"
#include <QMutex>
#ifdef HAVE_GUI
# include <QMessageBox>
#endif
const QString Workspace::workspacePrefix = "workspace://";
Workspace::Workspace(Settings *settings)
: m_copyInProgress( false )
{
SettingValue* workspaceDir = settings->createVar( SettingValue::String, "vlmc/Workspace", "",
"", "", SettingValue::Private );
connect(workspaceDir, SIGNAL( changed( QVariant ) ),
this, SLOT( workspaceChanged( QVariant ) ) );
// Wait for the SettingValue to be loaded.
m_mediasToCopyMutex = new QMutex;
}
Workspace::~Workspace()
{
delete m_mediasToCopyMutex;
}
bool
Workspace::copyToWorkspace( Media *media )
{
if ( m_workspaceDir.isEmpty() )
{
setError( "There is no current workspace. Please create a project first.");
return false;
}
QMutexLocker lock( m_mediasToCopyMutex );
if ( m_copyInProgress == true )
{
m_mediasToCopy.enqueue( media );
}
else
{
vlmcDebug() << "Copying media:" << media->fileInfo()->absoluteFilePath() << "to workspace.";
m_copyInProgress = true;
Q_ASSERT( this->isInWorkspace( media ) == false );
startCopyWorker( media );
}
return true;
}
void
Workspace::startCopyWorker( Media *media )
{
const QString dest = m_workspaceDir + '/' + media->fileInfo()->fileName();
if ( QFile::exists( dest ) == true )
{
#ifdef HAVE_GUI
QMessageBox::StandardButton b =
QMessageBox::question( nullptr, 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 );
worker->start();
}
void
Workspace::clipLoaded( Clip *clip )
{
//Don't bother if the clip is a subclip.
if ( clip->isRootClip() == false )
return ;
//If already in workspace : well...
if ( isInWorkspace( clip->media() ) == true )
return ;
copyToWorkspace( clip->media() );
}
void
Workspace::copyTerminated( Media *media, QString dest )
{
emit notify( tr( "Workspace: " ) + media->fileInfo()->fileName() + tr( " copied to " ) + 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 ( isInWorkspace( media ) == true )
{
startCopyWorker( toCopy );
break ;
}
}
}
else
m_copyInProgress = false;
}
void
......
......@@ -24,11 +24,9 @@
#define WORKSPACE_H
#include <QObject>
#include <QQueue>
#include "Tools/ErrorHandler.h"
class QMutex;
class QFileInfo;
class Clip;
......@@ -43,24 +41,15 @@ class Workspace : public QObject, public ErrorHandler
static const QString workspacePrefix;
Workspace( Settings* settings );
~Workspace();
bool isInWorkspace( const QString &path );
bool isInWorkspace( const Media *media );
bool copyToWorkspace( Media* media );
private:
void startCopyWorker( Media *media );
bool isInWorkspace( const QFileInfo &fInfo );
private:
QQueue<Media*> m_mediasToCopy;
QMutex *m_mediasToCopyMutex;
bool m_copyInProgress;
QString m_workspaceDir;
public slots:
void clipLoaded( Clip* clip );
private slots:
void copyTerminated( Media* media, QString dest );
void workspaceChanged( const QVariant& newWorkspace );
signals:
......
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