Commit 33e051ec authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Workspace: Simplify & refactor.

Workspace & Projects are now based on the assumption that there cannot
be a project without workspace, and editing is not possible without an
opened project.
This is not yet ensured by the GUI.
parent 7c1225c9
......@@ -58,8 +58,6 @@ ClipMetadataDisplayer::metadataUpdated()
m_ui->nbAudioTracksValueLabel->setText( QString::number( source->nbAudioTracks() ) );
//Path:
m_ui->pathValueLabel->setText( m_watchedMedia->fileInfo()->absoluteFilePath() );
//Workspace:
workspaceStateChanged( m_watchedMedia->isInWorkspace() );
}
void
......@@ -104,17 +102,6 @@ ClipMetadataDisplayer::setWatchedClip( const Clip *clip )
connect( m_watchedMedia, SIGNAL( metaDataComputed() ),
this, SLOT( metadataUpdated() ) );
}
connect( m_watchedMedia, SIGNAL( workspaceStateChanged( bool ) ),
this, SLOT( workspaceStateChanged( bool ) ) );
}
void
ClipMetadataDisplayer::workspaceStateChanged( bool state )
{
if ( state == true )
m_ui->inProjectWorkspaceValueLabel->setPixmap( QPixmap( ":/images/ok" ).scaled( 16, 16 ) );
else
m_ui->inProjectWorkspaceValueLabel->setPixmap( QPixmap( ":/images/ko" ).scaled( 16, 16 ) );
}
void
......
......@@ -54,7 +54,6 @@ class ClipMetadataDisplayer : public QWidget
private slots:
void metadataUpdated();
void workspaceStateChanged( bool state );
void clipDestroyed( Clip* clip );
};
......
......@@ -14,12 +14,6 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
......@@ -32,15 +26,15 @@
<string>Media Properties</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::FieldsStayAtSizeHint</enum>
</property>
<property name="horizontalSpacing">
<number>4</number>
</property>
<property name="verticalSpacing">
<number>4</number>
</property>
<property name="margin">
<number>9</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="sizePolicy">
......@@ -257,20 +251,6 @@
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="inProjectWorkspaceLabel">
<property name="text">
<string>In project workspace</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLabel" name="inProjectWorkspaceValueLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="8" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......
......@@ -98,34 +98,11 @@ GUIProjectManager::askForSaveIfModified()
return true;
}
bool
GUIProjectManager::confirmRelocate() const
{
QMessageBox msgBox;
msgBox.setText( tr( "You are about to relocate the project. Every video will be copied to your new workspace." ) );
msgBox.setInformativeText( tr( "Do you want to proceed?" ) );
msgBox.setStandardButtons( QMessageBox::Ok | QMessageBox::No );
msgBox.setDefaultButton( QMessageBox::Ok );
int ret = msgBox.exec();
switch ( ret )
{
case QMessageBox::Ok:
return true;
case QMessageBox::No:
return false ;
default:
return false;
}
}
bool
GUIProjectManager::createNewProjectFile( bool saveAs )
{
if ( m_projectFile == NULL || saveAs == true )
{
bool relocate = false;
QString defaultPath = VLMC_PROJECT_GET_STRING( "vlmc/Workspace" );
if ( defaultPath.length() == 0 )
defaultPath = VLMC_GET_STRING( "vlmc/DefaultProjectLocation" );
......@@ -134,12 +111,6 @@ GUIProjectManager::createNewProjectFile( bool saveAs )
defaultPath, tr( "VLMC project file(*.vlmc)" ) );
if ( outputFileName.length() == 0 )
return false;
if ( Workspace::isInProjectDir( outputFileName ) == false )
{
if ( confirmRelocate() == false )
return false;
relocate = true;
}
if ( m_projectFile != NULL )
delete m_projectFile;
if ( outputFileName.endsWith( ".vlmc" ) == false )
......@@ -149,8 +120,6 @@ GUIProjectManager::createNewProjectFile( bool saveAs )
Project::getInstance()->settings()->setValue( "vlmc/Workspace", fInfo.absolutePath() );
appendToRecentProject( projectName() );
if ( relocate == true )
Project::getInstance()->workspace()->copyAllToWorkspace();
emit projectUpdated( projectName(), true );
}
return true;
......
......@@ -72,7 +72,6 @@ protected:
private:
bool createNewProjectFile( bool saveAs );
bool confirmRelocate() const;
private:
QTimer* m_timer;
......
......@@ -39,7 +39,9 @@
#include <QHash>
#include <QUuid>
Library::Library() : m_cleanState( true )
Library::Library( Workspace *workspace )
: m_cleanState( true )
, m_workspace( workspace )
{
}
......@@ -61,13 +63,7 @@ Library::loadProject( const QDomElement& doc )
{
QString mrl = media.attribute( "mrl" );
//If in workspace: compute the path in workspace
if ( mrl.startsWith( Workspace::workspacePrefix ) == true )
{
//Transforming the workspace://[path] into [project-path]/[path]
QString projectPath = VLMC_PROJECT_GET_STRING( "vlmc/Workspace" );
mrl = projectPath + mrl.mid( Workspace::workspacePrefix.length() );
}
mrl = m_workspace->toAbsolutePath( mrl );
Media* m = addMedia( mrl );
if ( m == NULL )
vlmcWarning() << "Failed to load media" << mrl << "when loading project.";
......
......@@ -39,6 +39,7 @@ class QDomElement;
class Clip;
class Media;
class Workspace;
/**
* \class Library
......@@ -50,7 +51,7 @@ class Library : public MediaContainer
Q_DISABLE_COPY( Library );
public:
Library();
Library( Workspace* workspace );
virtual ~Library(){}
virtual void addMedia( Media* media );
virtual Media *addMedia( const QFileInfo &fileInfo );
......@@ -63,6 +64,7 @@ private:
private:
QAtomicInt m_nbMediaToLoad;
bool m_cleanState;
Workspace* m_workspace;
public slots:
/**
......@@ -83,8 +85,6 @@ signals:
*/
void projectLoaded();
void cleanStateChanged( bool newState );
friend class Workspace;
};
#endif // LIBRARY_H
......@@ -31,20 +31,20 @@
Project::Project()
{
m_library = new Library;
m_settings = new Settings( QString() );
m_undoStack = new QUndoStack;
m_workflow = new MainWorkflow;
m_workspace = new Workspace( m_settings );
m_library = new Library( m_workspace );
}
Project::~Project()
{
delete m_library;
delete m_workspace;
delete m_workflow;
delete m_undoStack;
delete m_settings;
delete m_library;
}
Library*
......
......@@ -222,10 +222,12 @@ Clip::save( QXmlStreamWriter &project )
project.writeStartElement( "clip" );
if ( isRootClip() == true )
{
if ( m_media->isInWorkspace() == true )
project.writeAttribute( "media", Workspace::workspacePrefix + Workspace::pathInProjectDir( m_media ) );
else
project.writeAttribute( "media", m_media->fileInfo()->absoluteFilePath() );
// This need to go away. That's not the Clip's job, and we don't want to refer the workspace from all clips
Q_ASSERT(false);
// if ( m_media->isInWorkspace() == true )
// project.writeAttribute( "media", Workspace::toWorkspaceDir( m_media ) );
// else
// project.writeAttribute( "media", m_media->fileInfo()->absoluteFilePath() );
}
else
{
......
......@@ -59,7 +59,6 @@ Media::Media(const QString &path )
: m_source( NULL )
, m_fileInfo( NULL )
, m_baseClip( NULL )
, m_inWorkspace( false )
, m_snapshotImage( NULL )
{
setFilePath( path );
......@@ -116,10 +115,7 @@ void
Media::save( QXmlStreamWriter& project )
{
project.writeStartElement( "media" );
if ( m_inWorkspace == true )
project.writeAttribute( "mrl", Workspace::workspacePrefix + m_workspacePath );
else
project.writeAttribute( "mrl", m_fileInfo->absoluteFilePath() );
project.writeAttribute( "mrl", m_fileInfo->absoluteFilePath() );
project.writeEndElement();
}
......@@ -130,12 +126,6 @@ Media::setBaseClip( Clip *clip )
m_baseClip = clip;
}
bool
Media::isInWorkspace() const
{
return m_inWorkspace;
}
void
Media::onMetaDataComputed()
{
......@@ -177,19 +167,6 @@ Media::setFilePath( const QString &filePath )
delete m_source;
m_source = backend->createSource( qPrintable( filePath ) );
MetaDataManager::getInstance()->computeMediaMetadata( this );
//Don't call this before setting all the internals, as it relies on Media::fileInfo.
if ( Workspace::isInProjectDir( this ) == true )
{
m_inWorkspace = true;
m_workspacePath = Workspace::pathInProjectDir( this );
}
else
{
m_inWorkspace = false;
m_workspacePath = "";
}
emit workspaceStateChanged( m_inWorkspace );
}
QPixmap&
......
......@@ -97,8 +97,6 @@ public:
void save( QXmlStreamWriter& project );
bool isInWorkspace() const;
void onMetaDataComputed();
// This has to be called from the GUI thread.
......@@ -111,8 +109,6 @@ protected:
FileType m_fileType;
QString m_fileName;
Clip* m_baseClip;
bool m_inWorkspace;
QString m_workspacePath;
static QPixmap* defaultSnapshot;
QPixmap m_snapshot;
......@@ -120,7 +116,6 @@ protected:
signals:
void metaDataComputed();
void workspaceStateChanged( bool );
void snapshotAvailable();
};
......
......@@ -43,6 +43,10 @@ const QString Workspace::workspacePrefix = "workspace://";
Workspace::Workspace(Settings *settings)
: m_copyInProgress( false )
{
SettingValue* workspaceDir = settings->value( "vlmc/Workspace" );
connect(workspaceDir, SIGNAL( changed( QVariant ) ),
this, SLOT( workspaceChanged( QVariant ) ) );
m_workspaceDir = workspaceDir->get().toString();
m_mediasToCopyMutex = new QMutex;
#ifdef WITH_GUI
connect( this, SIGNAL( notify( QString ) ),
......@@ -58,7 +62,7 @@ Workspace::~Workspace()
bool
Workspace::copyToWorkspace( Media *media )
{
if ( VLMC_PROJECT_GET_STRING("vlmc/Workspace").length() == 0 )
if ( m_workspaceDir.isEmpty() )
{
setError( "There is no current workspace. Please create a project first.");
return false;
......@@ -73,10 +77,8 @@ Workspace::copyToWorkspace( Media *media )
{
vlmcDebug() << "Copying media:" << media->fileInfo()->absoluteFilePath() << "to workspace.";
m_copyInProgress = true;
if ( media->isInWorkspace() == false )
{
startCopyWorker( media );
}
Q_ASSERT( this->isInWorkspace( media ) == false );
startCopyWorker( media );
}
return true;
}
......@@ -84,8 +86,7 @@ Workspace::copyToWorkspace( Media *media )
void
Workspace::startCopyWorker( Media *media )
{
const QString &projectPath = VLMC_PROJECT_GET_STRING( "vlmc/Workspace" );
const QString dest = projectPath + '/' + media->fileInfo()->fileName();
const QString dest = m_workspaceDir + '/' + media->fileInfo()->fileName();
if ( QFile::exists( dest ) == true )
{
......@@ -116,7 +117,7 @@ Workspace::clipLoaded( Clip *clip )
if ( clip->isRootClip() == false )
return ;
//If already in workspace : well...
if ( clip->getMedia()->isInWorkspace() == true )
if ( isInWorkspace( clip->getMedia() ) == true )
return ;
copyToWorkspace( clip->getMedia() );
}
......@@ -135,7 +136,7 @@ Workspace::copyTerminated( Media *media, QString dest )
while ( m_mediasToCopy.size() > 0 )
{
Media *toCopy = m_mediasToCopy.dequeue();
if ( toCopy->isInWorkspace() == false )
if ( isInWorkspace( media ) == true )
{
startCopyWorker( toCopy );
break ;
......@@ -146,51 +147,41 @@ Workspace::copyTerminated( Media *media, QString dest )
m_copyInProgress = false;
}
bool
Workspace::isInProjectDir( const QFileInfo &fInfo )
void
Workspace::workspaceChanged(const QVariant &newWorkspace)
{
const QString projectDir = VLMC_PROJECT_GET_STRING( "vlmc/Workspace" );
m_workspaceDir = newWorkspace.toString();
}
return ( projectDir.length() > 0 && fInfo.absolutePath().startsWith( projectDir ) );
bool
Workspace::isInWorkspace( const QFileInfo &fInfo )
{
return ( m_workspaceDir.length() > 0 && fInfo.absolutePath().startsWith( m_workspaceDir ) );
}
bool
Workspace::isInProjectDir( const QString &path )
Workspace::isInWorkspace( const QString &path )
{
QFileInfo fInfo( path );
return isInProjectDir( fInfo );
return isInWorkspace( fInfo );
}
bool
Workspace::isInProjectDir(const Media *media)
Workspace::isInWorkspace(const Media *media)
{
return isInProjectDir( *(media->fileInfo() ) );
return isInWorkspace( *(media->fileInfo() ) );
}
QString
Workspace::pathInProjectDir( const Media *media )
Workspace::toAbsolutePath( const QString& path )
{
const QString projectDir = VLMC_PROJECT_GET_STRING( "vlmc/Workspace" );
return ( media->fileInfo()->absoluteFilePath().mid( projectDir.length() ) );
QString res = path;
return res.replace( Workspace::workspacePrefix, m_workspaceDir );
}
void
Workspace::copyAllToWorkspace()
QString
Workspace::toWorkspacePath(const Media *media)
{
if ( Project::getInstance()->library()->m_clips.size() == 0 )
return ;
QHash<QUuid, Clip*>::iterator it = Project::getInstance()->library()->m_clips.begin();
QHash<QUuid, Clip*>::iterator ite = Project::getInstance()->library()->m_clips.end();
{
QMutexLocker lock( m_mediasToCopyMutex );
while ( it != ite )
{
m_mediasToCopy.enqueue( it.value()->getMedia() );
++it;
}
}
copyToWorkspace( m_mediasToCopy.dequeue() );
return media->fileInfo()->absoluteFilePath().replace( m_workspaceDir, Workspace::workspacePrefix );
}
......@@ -44,24 +44,26 @@ class Workspace : public QObject, public ErrorHandler
Workspace( Settings* settings );
~Workspace();
static bool isInProjectDir( const QString &path );
static bool isInProjectDir( const QFileInfo &fInfo );
static bool isInProjectDir( const Media *media );
static QString pathInProjectDir( const Media* media );
bool isInWorkspace( const QString &path );
bool isInWorkspace( const Media *media );
QString toAbsolutePath( const QString &path );
QString toWorkspacePath( const Media* media );
bool copyToWorkspace( Media* media );
void copyAllToWorkspace();
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:
void notify( QString );
......
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