Commit 1a039c7a authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

ProjectManager: Cleaner solution to split GUI and non GUI parts

parent 349abe15
......@@ -120,8 +120,9 @@ CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/config.h.cmake ${CMAKE_CURRENT_BINARY_D
#Add GUI stuff if required
IF (NOT WITH_GUI)
SET( WITH_CRASHHANDLER_GUI FALSE )
LIST (APPEND VLMC_SRCS Main/main.cpp )
QT4_ADD_RESOURCES(VLMC_RCC_SRCS ${VLMC_RCC})
QT4_WRAP_CPP(VLMC_MOC_SRCS ${VLMC_HDRS})
ADD_EXECUTABLE(vlmc ${GUI_TYPE} ${VLMC_SRCS} ${VLMC_MOC_SRCS} ${VLMC_RCC_SRCS})
TARGET_LINK_LIBRARIES(vlmc
${QT_QTCORE_LIBRARY}
......@@ -129,8 +130,6 @@ IF (NOT WITH_GUI)
${LIBVLC_LIBRARY}
${LIBVLCCORE_LIBRARY}
)
QT4_ADD_RESOURCES(VLMC_RCC_SRCS ${VLMC_RCC})
QT4_WRAP_CPP(VLMC_MOC_SRCS ${VLMC_HDRS})
ELSE(NOT WITH_GUI)
LIST( APPEND VLMC_SRCS
......@@ -154,8 +153,8 @@ ELSE(NOT WITH_GUI)
Gui/library/MediaListView.cpp
Gui/library/StackViewController.cpp
Gui/library/StackViewNavController.cpp
Gui/media/GUIMedia.cpp
Gui/project/GUIProjectManager.cpp
Gui/media/GuiMedia.cpp
Gui/project/GuiProjectManager.cpp
Gui/preview/PreviewRuler.cpp
Gui/preview/PreviewWidget.cpp
Gui/settings/BoolWidget.cpp
......@@ -203,11 +202,11 @@ ELSE(NOT WITH_GUI)
Gui/library/StackViewNavController.h
Gui/library/ViewController.h
Gui/MainWindow.h
Gui/media/GUIMedia.h
Gui/media/GuiMedia.h
Gui/preview/LCDTimecode.h
Gui/preview/PreviewRuler.h
Gui/preview/PreviewWidget.h
Gui/project/GUIProjectManager.h
Gui/project/GuiProjectManager.h
Gui/settings/KeyboardShortcutInput.h
Gui/settings/Panel.h
Gui/settings/PreferenceWidget.h
......@@ -278,7 +277,6 @@ ELSE(NOT WITH_GUI)
${QT_QTGUI_LIBRARY}
${QT_QTXML_LIBRARY}
${QT_QTSVG_LIBRARY}
${QT_QTNETWORK_LIBRARY}
${LIBVLC_LIBRARY}
${LIBVLCCORE_LIBRARY}
)
......
......@@ -34,7 +34,6 @@
#include "config.h"
#include "Library.h"
#include "About.h"
#include "ProjectManager.h"
#include "VlmcDebug.h"
#include "MainWorkflow.h"
......@@ -53,7 +52,7 @@
#include "UndoStack.h"
/* Settings / Preferences */
#include "ProjectManager.h"
#include "project/GuiProjectManager.h"
#include "ProjectWizard.h"
#include "Settings.h"
#include "SettingsManager.h"
......@@ -75,10 +74,10 @@ MainWindow::MainWindow( QWidget *parent ) :
// VlmcDebug::getInstance()->setup();
//VLC Instance:
LibVLCpp::Instance::getInstance( this );
LibVLCpp::Instance::getInstance();
//Creating the project manager first (so it can create all the project variables)
ProjectManager::getInstance();
GUIProjectManager::getInstance();
//Preferences
initVlmcPreferences();
......@@ -107,7 +106,7 @@ MainWindow::MainWindow( QWidget *parent ) :
connect( this, SIGNAL( toolChanged( ToolButtons ) ),
m_timeline, SLOT( setTool( ToolButtons ) ) );
connect( ProjectManager::getInstance(), SIGNAL( projectUpdated( const QString&, bool ) ),
connect( GUIProjectManager::getInstance(), SIGNAL( projectUpdated( const QString&, bool ) ),
this, SLOT( projectUpdated( const QString&, bool ) ) );
// Undo/Redo
......@@ -151,6 +150,7 @@ MainWindow::~MainWindow()
if ( m_fileRenderer )
delete m_fileRenderer;
delete m_importController;
LibVLCpp::Instance::destroyInstance();
}
void MainWindow::changeEvent( QEvent *e )
......@@ -258,17 +258,17 @@ MainWindow::setupLibrary()
void MainWindow::on_actionSave_triggered()
{
ProjectManager::getInstance()->saveProject();
GUIProjectManager::getInstance()->saveProject();
}
void MainWindow::on_actionSave_As_triggered()
{
ProjectManager::getInstance()->saveProject( true );
GUIProjectManager::getInstance()->saveProject( true );
}
void MainWindow::on_actionLoad_Project_triggered()
{
ProjectManager* pm = ProjectManager::getInstance();
GUIProjectManager* pm = GUIProjectManager::getInstance();
pm->loadProject( pm->acquireProjectFileName() );
}
......@@ -502,7 +502,8 @@ void MainWindow::on_actionProject_Preferences_triggered()
void MainWindow::closeEvent( QCloseEvent* e )
{
if ( ProjectManager::getInstance()->askForSaveIfModified() )
GUIProjectManager *pm = GUIProjectManager::getInstance();
if ( pm->askForSaveIfModified() )
e->accept();
else
e->ignore();
......@@ -520,7 +521,7 @@ void MainWindow::projectUpdated( const QString& projectName, bool savedStatus
void MainWindow::on_actionClose_Project_triggered()
{
ProjectManager::getInstance()->closeProject();
GUIProjectManager::getInstance()->closeProject();
}
void MainWindow::on_actionUndo_triggered()
......@@ -564,7 +565,7 @@ bool MainWindow::restoreSession()
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
if ( res == QMessageBox::Yes )
{
if ( ProjectManager::getInstance()->loadEmergencyBackup() == true )
if ( GUIProjectManager::getInstance()->loadEmergencyBackup() == true )
ret = true;
else
QMessageBox::warning( this, tr( "Can't restore project" ), tr( "VLMC didn't manage to restore your project. We appology for the inconvenience" ) );
......
......@@ -25,7 +25,7 @@
#include <QUndoCommand>
#include "UndoStack.h"
#include "ProjectManager.h"
#include "project/GuiProjectManager.h"
#include "SettingsManager.h"
#include "KeyboardShortcutHelper.h"
......@@ -36,14 +36,14 @@ UndoStack::UndoStack( QWidget* parent ) : QUndoView( parent )
m_undoStack = new QUndoStack( this );
setStack( m_undoStack );
connect( m_undoStack, SIGNAL( cleanChanged( bool ) ),
ProjectManager::getInstance(), SLOT( cleanChanged( bool ) ) );
connect( ProjectManager::getInstance(), SIGNAL( projectSaved() ),
GUIProjectManager::getInstance(), SLOT( cleanChanged( bool ) ) );
connect( GUIProjectManager::getInstance(), SIGNAL( projectSaved() ),
m_undoStack, SLOT( setClean() ) );
connect( m_undoStack, SIGNAL( canRedoChanged(bool) ), this, SIGNAL( canRedoChanged(bool) ) );
connect( m_undoStack, SIGNAL( canUndoChanged(bool) ), this, SIGNAL( canUndoChanged(bool) ) );
connect( ProjectManager::getInstance(), SIGNAL( projectClosed() ), this, SLOT( clear() ) );
connect( GUIProjectManager::getInstance(), SIGNAL( projectClosed() ), this, SLOT( clear() ) );
}
void UndoStack::push( QUndoCommand* command )
......
......@@ -48,9 +48,9 @@ GUIMedia::snapshot() const
{
if ( m_snapshot != NULL )
return *m_snapshot;
if ( Media::defaultSnapshot == NULL )
Media::defaultSnapshot = new QPixmap( ":/images/images/vlmc.png" );
return *Media::defaultSnapshot;
if ( GUIMedia::defaultSnapshot == NULL )
GUIMedia::defaultSnapshot = new QPixmap( ":/images/images/vlmc.png" );
return *GUIMedia::defaultSnapshot;
}
void
......
......@@ -32,7 +32,6 @@
GUIProjectManager::GUIProjectManager()
{
connect( this, SIGNAL( projectClosed() ), Library::getInstance(), SLOT( clear() ) );
connect( this, SIGNAL( projectClosed() ), MainWorkflow::getInstance(), SLOT( clear() ) );
......@@ -120,9 +119,7 @@ GUIProjectManager::saveProject( bool saveAs /*= true*/ )
//save the project with a new name
if ( createNewProjectFile( saveAs ) == false )
return ;
__saveProject( m_projectFile->fileName() );
emit projectSaved();
emit projectUpdated( projectName(), true );
ProjectManager::saveProject( saveAs );
}
bool
......@@ -130,17 +127,7 @@ GUIProjectManager::closeProject()
{
if ( askForSaveIfModified() == false )
return false;
if ( m_projectFile != NULL )
{
delete m_projectFile;
m_projectFile = NULL;
}
m_projectName = QString();
//This one is for the mainwindow, to update the title bar
emit projectUpdated( projectName(), true );
//This one is for every part that need to clean something when the project is closed.
emit projectClosed();
return true;
return ProjectManager::closeProject();
}
void
......@@ -184,3 +171,24 @@ GUIProjectManager::automaticSaveIntervalChanged( const QVariant& val )
return ;
m_timer->start( val.toInt() * 1000 * 60 );
}
bool
GUIProjectManager::needSave() const
{
return m_needSave;
}
void
GUIProjectManager::cleanChanged( bool val )
{
m_needSave = !val;
emit projectUpdated( projectName(), val );
}
void
GUIProjectManager::projectNameChanged( const QVariant& name )
{
m_projectName = name.toString();
emit projectUpdated( m_projectName, !m_needSave );
}
......@@ -23,11 +23,11 @@
#ifndef GUIPROJECTMANAGER_H
#define GUIPROJECTMANAGER_H
#include <QObject>
#include "ProjectManager.h"
class QTimer;
class GUIProjectManager : public QObject
class GUIProjectManager : public ProjectManager, public Singleton<GUIProjectManager>
{
Q_OBJECT
......@@ -51,6 +51,8 @@ public:
* \return true if the project has been closed. false otherwise.
*/
bool closeProject();
bool needSave() const;
private:
bool createNewProjectFile( bool saveAs );
......@@ -58,9 +60,13 @@ private:
QTimer* m_timer;
private slots:
void projectNameChanged( const QVariant& projectName );
void autoSaveRequired();
void cleanChanged( bool val );
void automaticSaveEnabledChanged( const QVariant& enabled );
void automaticSaveIntervalChanged( const QVariant& interval );
friend class Singleton<GUIProjectManager>;
};
#endif // GUIPROJECTMANAGER_H
......@@ -22,7 +22,7 @@
#include <QDebug>
#include "OpenPage.h"
#include "ProjectManager.h"
#include "project/GuiProjectManager.h"
#include "ProjectWizard.h"
#include "WelcomePage.h"
......@@ -51,7 +51,7 @@ void OpenPage::changeEvent( QEvent *e )
bool OpenPage::validatePage()
{
ProjectManager* pm = ProjectManager::getInstance();
ProjectManager* pm = GUIProjectManager::getInstance();
if ( !WelcomePage::projectPath().isEmpty() )
pm->loadProject( WelcomePage::projectPath() );
......
......@@ -24,7 +24,7 @@
#include <QString>
#include <QMessageBox>
#include <QWizardPage>
#include "ProjectManager.h"
#include "project/GuiProjectManager.h"
#include "ProjectWizard.h"
#include "SettingsManager.h"
#include "WelcomePage.h"
......@@ -95,7 +95,7 @@ void ProjectWizard::accept()
{
if ( currentId() == Page_Video )
{
ProjectManager::getInstance()->newProject( field( "projectName" ).toString() );
GUIProjectManager::getInstance()->newProject( field( "projectName" ).toString() );
SettingsManager::getInstance()->commit( SettingsManager::Project );
SettingsManager::getInstance()->commit( SettingsManager::Vlmc );
}
......
......@@ -20,6 +20,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "WelcomePage.h"
#include "project/GuiProjectManager.h"
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
......@@ -27,7 +31,6 @@
#include <QFileInfo>
#include <QSettings>
#include <QDebug>
#include "WelcomePage.h"
QString* WelcomePage::m_projectPath = NULL;
......@@ -112,7 +115,7 @@ void WelcomePage::cleanupPage()
void WelcomePage::loadRecentsProjects()
{
m_ui.projectsListWidget->clear();
ProjectManager* pm = ProjectManager::getInstance();
ProjectManager* pm = GUIProjectManager::getInstance();
QStringList recents = pm->recentsProjects();
for ( int i = 0; i < recents.count(); ++i )
......@@ -127,8 +130,7 @@ void WelcomePage::loadRecentsProjects()
void WelcomePage::loadProject()
{
ProjectManager* pm = ProjectManager::getInstance();
QString projectPath = pm->acquireProjectFileName();
QString projectPath = GUIProjectManager::getInstance()->acquireProjectFileName();
if ( projectPath.isEmpty() ) return;
......
......@@ -25,7 +25,6 @@
#include <QWizardPage>
#include "ProjectWizard.h"
#include "ProjectManager.h"
#include "ui_WelcomePage.h"
class QWizard;
......
......@@ -28,7 +28,7 @@
#include "config.h"
#include "MainWindow.h"
#include "ProjectManager.h"
#include "project/GuiProjectManager.h"
#include <QApplication>
#include <QColor>
......@@ -88,7 +88,7 @@ VLMCmain( int argc, char **argv )
MainWindow w;
if ( argc > 1 )
ProjectManager::getInstance()->loadProject( argv[argc - 1] );
GUIProjectManager::getInstance()->loadProject( argv[argc - 1] );
w.show();
return app.exec();
}
......@@ -38,7 +38,7 @@
#include <QHash>
#ifdef WITH_GUI
#include "Media/GUIMedia.h"
#include "media/GuiMedia.h"
#endif
namespace LibVLCpp
......
......@@ -221,6 +221,13 @@ MetaDataWorker::entrypointPlaying()
metaDataAvailable();
}
void
MetaDataWorker::failure()
{
emit failed( m_media );
deleteLater();
}
//void
//MetaDataWorker::prepareAudioSpectrumComputing()
......@@ -299,9 +306,3 @@ MetaDataWorker::entrypointPlaying()
// m_media->audioValues()->append( value );
//}
//
//void
//MetaDataWorker::failure()
//{
// emit failed( m_media );
// deleteLater();
//}
......@@ -33,6 +33,7 @@
#include "Library.h"
#include "MainWorkflow.h"
#include "project/GuiProjectManager.h"
#include "ProjectManager.h"
#include "SettingsManager.h"
......@@ -49,7 +50,11 @@ void ProjectManager::signalHandler( int sig )
{
signal( sig, SIG_DFL );
#ifdef WITH_GUI
GUIProjectManager::getInstance()->emergencyBackup();
#else
ProjectManager::getInstance()->emergencyBackup();
#endif
#ifdef WITH_CRASHHANDLER_GUI
CrashHandler* ch = new CrashHandler( sig );
......@@ -98,22 +103,12 @@ ProjectManager::~ProjectManager()
delete m_projectFile;
}
bool ProjectManager::needSave() const
{
return m_needSave;
}
QStringList ProjectManager::recentsProjects() const
{
return m_recentsProjects;
}
void ProjectManager::cleanChanged( bool val )
{
m_needSave = !val;
emit projectUpdated( projectName(), val );
}
void ProjectManager::loadTimeline()
{
QDomElement root = m_domDocument->documentElement();
......@@ -129,18 +124,17 @@ void ProjectManager::loadProject( const QString& fileName )
if ( fileName.isEmpty() == true )
return;
#ifdef WITH_GUI
if ( closeProject() == false )
return ;
#endif
m_projectFile = new QFile( fileName );
m_projectFile->open( QFile::ReadOnly );
m_projectFile->close();
m_domDocument = new QDomDocument;
m_domDocument->setContent( m_projectFile );
#ifdef WITH_GUI
m_needSave = false;
#endif
if ( ProjectManager::isBackupFile( fileName ) == false )
appendToRecentProject( QFileInfo( *m_projectFile ).absoluteFilePath() );
else
......@@ -176,12 +170,6 @@ void ProjectManager::__saveProject( const QString &fileName )
project.writeEndDocument();
}
void ProjectManager::projectNameChanged( const QVariant& name )
{
m_projectName = name.toString();
emit projectUpdated( m_projectName, !m_needSave );
}
void ProjectManager::emergencyBackup()
{
QString name;
......@@ -202,19 +190,6 @@ void ProjectManager::emergencyBackup()
s.sync();
}
bool ProjectManager::loadEmergencyBackup()
{
QSettings s;
QString lastProject = s.value( "EmergencyBackup" ).toString();
if ( QFile::exists( lastProject ) == true )
{
loadProject( lastProject );
m_needSave = true;
return true;
}
return false;
}
bool ProjectManager::isBackupFile( const QString& projectFile )
{
return projectFile.endsWith( "backup" );
......@@ -245,3 +220,41 @@ QString ProjectManager::projectName() const
}
return m_projectName;
}
bool
ProjectManager::closeProject()
{
if ( m_projectFile != NULL )
{
delete m_projectFile;
m_projectFile = NULL;
}
m_projectName = QString();
//This one is for the mainwindow, to update the title bar
emit projectUpdated( projectName(), true );
//This one is for every part that need to clean something when the project is closed.
emit projectClosed();
return true;
}
void
ProjectManager::saveProject( bool )
{
__saveProject( m_projectFile->fileName() );
emit projectSaved();
emit projectUpdated( projectName(), true );
}
bool
ProjectManager::loadEmergencyBackup()
{
QSettings s;
QString lastProject = s.value( "EmergencyBackup" ).toString();
if ( QFile::exists( lastProject ) == true )
{
loadProject( lastProject );
m_needSave = true;
return true;
}
return false;
}
......@@ -34,13 +34,10 @@ class QFile;
class QDomDocument;
#ifdef WITH_GUI
# include "Project/GUIProjectManager.h"
# define PARENTCLASS GUIProjectManager
class ProjectManager : public QObject
#else
# define PARENTCLASS QObject
class ProjectManager : public QObject , public Singleton<ProjectManager>
#endif
class ProjectManager : public PARENTCLASS, public Singleton<ProjectManager>
{
Q_OBJECT
Q_DISABLE_COPY( ProjectManager );
......@@ -49,14 +46,14 @@ public:
static const QString unSavedProject;
void loadProject( const QString& fileName );
bool needSave() const;
QStringList recentsProjects() const;
virtual bool closeProject();
virtual void saveProject( bool saveAs = false );
bool loadEmergencyBackup();
static void signalHandler( int sig );
private:
protected:
/**
* This shouldn't be call directly.
* It's only purpose it to write the project for very specific cases.
......@@ -75,22 +72,22 @@ private:
*/
QString projectName() const;
protected:
ProjectManager();
~ProjectManager();
private:
protected:
QFile* m_projectFile;
bool m_needSave;
QStringList m_recentsProjects;
QString m_projectName;
QString m_projectDescription;
QDomDocument *m_domDocument;
bool m_needSave;
friend class Singleton<ProjectManager>;
private slots:
protected slots:
void loadTimeline();
void cleanChanged( bool val );
void projectNameChanged( const QVariant& projectName );
signals:
/**
......
......@@ -23,6 +23,7 @@
#ifndef WORKFLOWFILERENDERER_H
#define WORKFLOWFILERENDERER_H
#include "config.h"
#include "Workflow/MainWorkflow.h"
#include "WorkflowRenderer.h"
#ifdef WITH_GUI
......@@ -67,7 +68,9 @@ protected:
virtual quint32 height() const;
private slots:
void stop();
#ifdef WITH_GUI
void cancelButtonClicked();
#endif
void __frameChanged( qint64 frame,
MainWorkflow::FrameChangedReason reason );
void __endReached();
......
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