Commit 22c35342 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Libary: Handle clean state.

Now, adding a media set the project in an unclean state, which avoid
beeing able to close without saving when a media has been loaded without
saving the project afterward.
parent 3233a0bf
...@@ -39,6 +39,8 @@ GUIProjectManager::GUIProjectManager() ...@@ -39,6 +39,8 @@ GUIProjectManager::GUIProjectManager()
{ {
connect( this, SIGNAL( projectClosed() ), Library::getInstance(), SLOT( clear() ) ); connect( this, SIGNAL( projectClosed() ), Library::getInstance(), SLOT( clear() ) );
connect( this, SIGNAL( projectClosed() ), MainWorkflow::getInstance(), SLOT( clear() ) ); connect( this, SIGNAL( projectClosed() ), MainWorkflow::getInstance(), SLOT( clear() ) );
connect( Library::getInstance(), SIGNAL( cleanStateChanged( bool ) ),
this, SLOT( cleanChanged( bool ) ) );
//Automatic save part : //Automatic save part :
m_timer = new QTimer( this ); m_timer = new QTimer( this );
......
...@@ -39,6 +39,10 @@ ...@@ -39,6 +39,10 @@
#include <QHash> #include <QHash>
#include <QUuid> #include <QUuid>
Library::Library() : m_cleanState( true )
{
}
void void
Library::loadProject( const QDomElement& doc ) Library::loadProject( const QDomElement& doc )
{ {
...@@ -95,6 +99,7 @@ Library::saveProject( QXmlStreamWriter& project ) ...@@ -95,6 +99,7 @@ Library::saveProject( QXmlStreamWriter& project )
project.writeStartElement( "clips" ); project.writeStartElement( "clips" );
save( project ); save( project );
project.writeEndElement(); project.writeEndElement();
setCleanState( true );
} }
void void
...@@ -109,3 +114,44 @@ Library::mediaLoaded( const Media* media ) ...@@ -109,3 +114,44 @@ Library::mediaLoaded( const Media* media )
if ( m_nbMediaToLoad == 0 ) if ( m_nbMediaToLoad == 0 )
emit projectLoaded(); emit projectLoaded();
} }
void
Library::addMedia( Media* media )
{
setCleanState( false );
MediaContainer::addMedia( media );
}
Media*
Library::addMedia( const QFileInfo &fileInfo )
{
Media* media = MediaContainer::addMedia( fileInfo );
if ( media != NULL )
setCleanState( false );
return media;
}
bool
Library::addClip( Clip *clip )
{
bool ret = MediaContainer::addClip( clip );
if ( ret != false )
setCleanState( false );
return ret;
}
bool
Library::isInCleanState() const
{
return m_cleanState;
}
void
Library::setCleanState( bool newState )
{
if ( newState != m_cleanState )
{
m_cleanState = newState;
emit cleanStateChanged( newState );
}
}
...@@ -51,12 +51,21 @@ class Library : public MediaContainer, public Singleton<Library> ...@@ -51,12 +51,21 @@ class Library : public MediaContainer, public Singleton<Library>
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY( Library ); Q_DISABLE_COPY( Library );
public:
virtual void addMedia( Media* media );
virtual Media *addMedia( const QFileInfo &fileInfo );
virtual bool addClip( Clip *clip );
bool isInCleanState() const;
private: private:
Library() {} Library();
virtual ~Library(){} virtual ~Library(){}
void setCleanState( bool newState );
private: private:
QAtomicInt m_nbMediaToLoad; QAtomicInt m_nbMediaToLoad;
bool m_cleanState;
public slots: public slots:
/** /**
...@@ -76,6 +85,7 @@ signals: ...@@ -76,6 +85,7 @@ signals:
* \brief * \brief
*/ */
void projectLoaded(); void projectLoaded();
void cleanStateChanged( bool newState );
friend class Singleton<Library>; friend class Singleton<Library>;
friend class Workspace; friend class Workspace;
......
...@@ -63,19 +63,20 @@ public: ...@@ -63,19 +63,20 @@ public:
* *
* \param media The media to add to the library * \param media The media to add to the library
*/ */
void addMedia( Media *media ); virtual void addMedia( Media *media );
/** /**
* \brief Add a file to the media library * \brief Add a file to the media library
* *
* This method will also handle metadata parsing. * This method will also handle metadata parsing.
* \param fileInfo the file info of the media * \param fileInfo the file info of the media
* \return true if the media was successfully loaded. false otherwise. * \return The newly create media if the media was successfully loaded.
* NULL otherwise.
* \sa addClip( Clip* clip ) * \sa addClip( Clip* clip )
* \sa media( const QUuid& uuid) * \sa media( const QUuid& uuid)
* \sa clip( const QUuid& uuid ) * \sa clip( const QUuid& uuid )
*/ */
Media* addMedia( const QFileInfo& fileInfo ); virtual Media *addMedia( const QFileInfo& fileInfo );
/** /**
* \brief Check if a file has already been loaded into library. * \brief Check if a file has already been loaded into library.
* \param fileInfo The file infos * \param fileInfo The file infos
......
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