Commit 4eeb736a authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Splitting project manager and gui project manager parts in two classes.

parent af0149b9
......@@ -120,6 +120,7 @@ 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 )
ADD_EXECUTABLE(vlmc ${GUI_TYPE} ${VLMC_SRCS} ${VLMC_MOC_SRCS} ${VLMC_RCC_SRCS})
TARGET_LINK_LIBRARIES(vlmc
......@@ -143,8 +144,6 @@ ELSE(NOT WITH_GUI)
Gui/LanguageHelper.cpp
Gui/preview/LCDTimecode.cpp
Gui/MainWindow.cpp
Gui/preview/PreviewRuler.cpp
Gui/preview/PreviewWidget.cpp
Gui/import/TagWidget.cpp
Gui/UndoStack.cpp
Gui/WorkflowFileRendererDialog.cpp
......@@ -155,6 +154,10 @@ 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/preview/PreviewRuler.cpp
Gui/preview/PreviewWidget.cpp
Gui/settings/BoolWidget.cpp
Gui/settings/DoubleWidget.cpp
Gui/settings/IntWidget.cpp
......@@ -192,7 +195,7 @@ ELSE(NOT WITH_GUI)
Gui/export/RendererSettings.h
Gui/import/ImportController.h
Gui/LanguageHelper.h
Gui/preview/LCDTimecode.h
Gui/import/TagWidget.h
Gui/library/ListViewController.h
Gui/library/MediaCellView.h
Gui/library/MediaListView.h
......@@ -200,13 +203,15 @@ ELSE(NOT WITH_GUI)
Gui/library/StackViewNavController.h
Gui/library/ViewController.h
Gui/MainWindow.h
Gui/media/GUIMedia.h
Gui/preview/LCDTimecode.h
Gui/preview/PreviewRuler.h
Gui/preview/PreviewWidget.h
Gui/project/GUIProjectManager.h
Gui/settings/KeyboardShortcutInput.h
Gui/settings/Panel.h
Gui/settings/PreferenceWidget.h
Gui/settings/Settings.h
Gui/import/TagWidget.h
Gui/timeline/AbstractGraphicsMediaItem.h
Gui/timeline/GraphicsAudioItem.h
Gui/timeline/GraphicsCursorItem.h
......@@ -257,7 +262,6 @@ ELSE(NOT WITH_GUI)
ENDIF( CMAKE_SYSTEM_NAME STREQUAL "Linux" )
LIST( APPEND VLMC_HDRS Gui/widgets/CrashHandler.h )
LIST( APPEND VLMC_UIS Gui/widgets/CrashHandler.ui )
ENDIF(WITH_CRASHHANDLER_GUI)
QT4_WRAP_UI(VLMC_UIS_H ${VLMC_UIS})
......
/*****************************************************************************
* GUIProjectManager.cpp: Handle the GUI part of the project managing
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "GuiProjectManager.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QTimer>
#include "Library.h"
#include "MainWorkflow.h"
#include "SettingsManager.h"
GUIProjectManager::GUIProjectManager()
{
connect( this, SIGNAL( projectClosed() ), Library::getInstance(), SLOT( clear() ) );
connect( this, SIGNAL( projectClosed() ), MainWorkflow::getInstance(), SLOT( clear() ) );
//Automatic save part :
m_timer = new QTimer( this );
connect( m_timer, SIGNAL( timeout() ), this, SLOT( autoSaveRequired() ) );
VLMC_CREATE_PREFERENCE_BOOL( "general/AutomaticBackup", false, "Automatic save",
"When this option is activated,"
"VLMC will automatically save your project at a specified interval" );
SettingsManager::getInstance()->watchValue( "general/AutomaticBackup", this,
SLOT( automaticSaveEnabledChanged(QVariant) ),
SettingsManager::Vlmc,
Qt::QueuedConnection );
VLMC_CREATE_PREFERENCE_INT( "general/AutomaticBackupInterval", 5, "Automatic save interval",
"This is the interval that VLMC will wait between two automatic save" );
SettingsManager::getInstance()->watchValue( "general/AutomaticBackupInterval", this,
SLOT( automaticSaveIntervalChanged(QVariant) ),
SettingsManager::Vlmc,
Qt::QueuedConnection );
automaticSaveEnabledChanged( VLMC_GET_BOOL( "general/AutomaticBackup" ) );
}
bool
GUIProjectManager::askForSaveIfModified()
{
if ( m_needSave == true )
{
QMessageBox msgBox;
msgBox.setText( tr( "The project has been modified." ) );
msgBox.setInformativeText( tr( "Do you want to save it ?" ) );
msgBox.setStandardButtons( QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel );
msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec();
switch ( ret )
{
case QMessageBox::Save:
saveProject();
break ;
case QMessageBox::Discard:
break ;
case QMessageBox::Cancel:
default:
return false ;
}
}
return true;
}
QString
GUIProjectManager::acquireProjectFileName()
{
QString fileName =
QFileDialog::getOpenFileName( NULL, "Enter the output file name",
QString(), "VLMC project file(*.vlmc)" );
return fileName;
}
bool
GUIProjectManager::createNewProjectFile( bool saveAs )
{
if ( m_projectFile == NULL || saveAs == true )
{
QString outputFileName =
QFileDialog::getSaveFileName( NULL, "Enter the output file name",
QString(), "VLMC project file(*.vlmc)" );
if ( outputFileName.length() == 0 )
return false;
if ( m_projectFile != NULL )
delete m_projectFile;
if ( outputFileName.endsWith( ".vlmc" ) == false )
outputFileName += ".vlmc";
m_projectFile = new QFile( outputFileName );
appendToRecentProject( outputFileName );
emit projectUpdated( projectName(), true );
}
return true;
}
void
GUIProjectManager::saveProject( bool saveAs /*= true*/ )
{
//If the project is still unsaved, or if we want to
//save the project with a new name
if ( createNewProjectFile( saveAs ) == false )
return ;
__saveProject( m_projectFile->fileName() );
emit projectSaved();
emit projectUpdated( projectName(), true );
}
bool
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;
}
void
GUIProjectManager::newProject( const QString &projectName )
{
if ( closeProject() == false )
return ;
m_projectName = projectName;
emit projectUpdated( this->projectName(), false );
}
void
GUIProjectManager::autoSaveRequired()
{
if ( m_projectFile == NULL )
return ;
saveProject( false );
}
void
GUIProjectManager::automaticSaveEnabledChanged( const QVariant& val )
{
bool enabled = val.toBool();
if ( enabled == true )
{
int interval = VLMC_GET_INT( "general/AutomaticBackupInterval" );
m_timer->start( interval * 1000 * 60 );
}
else
m_timer->stop();
}
void
GUIProjectManager::automaticSaveIntervalChanged( const QVariant& val )
{
bool enabled = VLMC_GET_BOOL( "general/AutomaticBackup" );
if ( enabled == false )
return ;
m_timer->start( val.toInt() * 1000 * 60 );
}
/*****************************************************************************
* GUIProjectManager.h: Handle the GUI part of the project managing
*****************************************************************************
* Copyright (C) 2008-2010 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef GUIPROJECTMANAGER_H
#define GUIPROJECTMANAGER_H
#include <QObject>
class QTimer;
class GUIProjectManager : public QObject
{
Q_OBJECT
public:
GUIProjectManager();
bool askForSaveIfModified();
void newProject( const QString& projectName );
/**
* \brief Ask the user for the project file she wants to load.
*
* \return The project to load.
*/
QString acquireProjectFileName();
void saveProject( bool saveAs = false );
/**
* \brief Ask the project manager to close current project.
*
* This can fail, as the user will be asked if he wants to save the current project.
* If she selects discard, the project closing procedure is aborted.
* \return true if the project has been closed. false otherwise.
*/
bool closeProject();
private:
bool createNewProjectFile( bool saveAs );
private:
QTimer* m_timer;
private slots:
void autoSaveRequired();
void automaticSaveEnabledChanged( const QVariant& enabled );
void automaticSaveIntervalChanged( const QVariant& interval );
};
#endif // GUIPROJECTMANAGER_H
......@@ -22,8 +22,13 @@
#include "config.h"
#ifdef WITH_CRASHHANDLER_GUI
#include "CrashHandler.h"
#ifdef WITH_GUI
# ifdef WITH_CRASHHANDLER_GUI
# include "CrashHandler.h"
# endif
#else
//We shouldn't have to do this.
#undef WITH_CRASHHANDLER_GUI
#endif
#include "Library.h"
......@@ -31,11 +36,9 @@
#include "ProjectManager.h"
#include "SettingsManager.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QDir>
#include <QSettings>
#include <QtDebug>
#include <QTimer>
#include <QXmlStreamWriter>
#include <errno.h>
......@@ -72,9 +75,6 @@ ProjectManager::ProjectManager() : m_projectFile( NULL ), m_needSave( false )
signal( SIGILL, ProjectManager::signalHandler );
#endif
connect( this, SIGNAL( projectClosed() ), Library::getInstance(), SLOT( clear() ) );
connect( this, SIGNAL( projectClosed() ), MainWorkflow::getInstance(), SLOT( clear() ) );
VLMC_CREATE_PROJECT_DOUBLE( "video/VLMCOutputFPS", 29.97, "Output video FPS", "Frame Per Second used when previewing and rendering the project" );
VLMC_CREATE_PROJECT_INT( "video/VideoProjectWidth", 480, "Video width", "Width resolution of the output video" );
VLMC_CREATE_PROJECT_INT( "video/VideoProjectHeight", 300, "Video height", "Height resolution of the output video" );
......@@ -86,23 +86,6 @@ ProjectManager::ProjectManager() : m_projectFile( NULL ), m_needSave( false )
SLOT(projectNameChanged(QVariant) ),
SettingsManager::Project );
//Automatic save part :
m_timer = new QTimer( this );
connect( m_timer, SIGNAL( timeout() ), this, SLOT( autoSaveRequired() ) );
VLMC_CREATE_PREFERENCE_BOOL( "general/AutomaticBackup", false, "Automatic save",
"When this option is activated,"
"VLMC will automatically save your project at a specified interval" );
SettingsManager::getInstance()->watchValue( "general/AutomaticBackup", this,
SLOT( automaticSaveEnabledChanged(QVariant) ),
SettingsManager::Vlmc,
Qt::QueuedConnection );
VLMC_CREATE_PREFERENCE_INT( "general/AutomaticBackupInterval", 5, "Automatic save interval",
"This is the interval that VLMC will wait between two automatic save" );
SettingsManager::getInstance()->watchValue( "general/AutomaticBackupInterval", this,
SLOT( automaticSaveIntervalChanged(QVariant) ),
SettingsManager::Vlmc,
Qt::QueuedConnection );
automaticSaveEnabledChanged( VLMC_GET_BOOL( "general/AutomaticBackup" ) );
}
ProjectManager::~ProjectManager()
......@@ -146,9 +129,10 @@ 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();
......@@ -173,45 +157,6 @@ void ProjectManager::loadProject( const QString& fileName )
Library::getInstance()->loadProject( root );
}
QString ProjectManager::acquireProjectFileName()
{
QString fileName =
QFileDialog::getOpenFileName( NULL, "Enter the output file name",
QString(), "VLMC project file(*.vlmc)" );
return fileName;
}
bool ProjectManager::createNewProjectFile( bool saveAs )
{
if ( m_projectFile == NULL || saveAs == true )
{
QString outputFileName =
QFileDialog::getSaveFileName( NULL, "Enter the output file name",
QString(), "VLMC project file(*.vlmc)" );
if ( outputFileName.length() == 0 )
return false;
if ( m_projectFile != NULL )
delete m_projectFile;
if ( outputFileName.endsWith( ".vlmc" ) == false )
outputFileName += ".vlmc";
m_projectFile = new QFile( outputFileName );
appendToRecentProject( outputFileName );
emit projectUpdated( projectName(), true );
}
return true;
}
void ProjectManager::saveProject( bool saveAs /*= true*/ )
{
//If the project is still unsaved, or if we want to
//save the project with a new name
if ( createNewProjectFile( saveAs ) == false )
return ;
__saveProject( m_projectFile->fileName() );
emit projectSaved();
emit projectUpdated( projectName(), true );
}
void ProjectManager::__saveProject( const QString &fileName )
{
QFile file( fileName );
......@@ -231,57 +176,6 @@ void ProjectManager::__saveProject( const QString &fileName )
project.writeEndDocument();
}
void ProjectManager::newProject( const QString &projectName )
{
if ( closeProject() == false )
return ;
m_projectName = projectName;
emit projectUpdated( this->projectName(), false );
}
bool ProjectManager::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;
}
bool ProjectManager::askForSaveIfModified()
{
if ( m_needSave == true )
{
QMessageBox msgBox;
msgBox.setText( tr( "The project has been modified." ) );
msgBox.setInformativeText( tr( "Do you want to save it ?" ) );
msgBox.setStandardButtons( QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel );
msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec();
switch ( ret )
{
case QMessageBox::Save:
saveProject();
break ;
case QMessageBox::Discard:
break ;
case QMessageBox::Cancel:
default:
return false ;
}
}
return true;
}
void ProjectManager::projectNameChanged( const QVariant& name )
{
m_projectName = name.toString();
......@@ -338,35 +232,6 @@ void ProjectManager::appendToRecentProject( const QString& projectFile )
s.setValue( "RecentsProjects", m_recentsProjects );
}
void ProjectManager::automaticSaveEnabledChanged( const QVariant& val )
{
bool enabled = val.toBool();
if ( enabled == true )
{
int interval = VLMC_GET_INT( "general/AutomaticBackupInterval" );
m_timer->start( interval * 1000 * 60 );
}
else
m_timer->stop();
}
void ProjectManager::automaticSaveIntervalChanged( const QVariant& val )
{
bool enabled = VLMC_GET_BOOL( "general/AutomaticBackup" );
if ( enabled == false )
return ;
m_timer->start( val.toInt() * 1000 * 60 );
}
void ProjectManager::autoSaveRequired()
{
if ( m_projectFile == NULL )
return ;
saveProject( false );
}
QString ProjectManager::projectName() const
{
if ( m_projectName.isEmpty() == true )
......
......@@ -23,17 +23,24 @@
#ifndef PROJECTMANAGER_H
#define PROJECTMANAGER_H
#include "config.h"
#include <QObject>
#include <QDomDocument>
#include <QStringList>
#include <QTimer>
#include "Singleton.hpp"
class QFile;
class QDomDocument;
class ProjectManager : public QObject, public Singleton<ProjectManager>
#ifdef WITH_GUI
# include "Project/GUIProjectManager.h"
# define PARENTCLASS GUIProjectManager
#else
# define PARENTCLASS QObject
#endif
class ProjectManager : public PARENTCLASS, public Singleton<ProjectManager>
{
Q_OBJECT
Q_DISABLE_COPY( ProjectManager );
......@@ -42,25 +49,9 @@ public:
static const QString unSavedProject;
void loadProject( const QString& fileName );
void newProject( const QString& projectName );
/**
* \brief Ask the user for the project file she wants to load.
*
* \return The project to load.
*/
QString acquireProjectFileName();
void saveProject( bool saveAs = false );
bool needSave() const;
QStringList recentsProjects() const;
/**
* \brief Ask the project manager to close current project.
*
* This can fail, as the user will be asked if he wants to save the current project.
* If she selects discard, the project closing procedure is aborted.
* \return true if the project has been closed. false otherwise.
*/
bool closeProject();
bool askForSaveIfModified();
bool loadEmergencyBackup();
static void signalHandler( int sig );
......@@ -86,16 +77,12 @@ private:
ProjectManager();
~ProjectManager();
bool createNewProjectFile( bool saveAs );
private:
QFile* m_projectFile;
bool m_needSave;
QStringList m_recentsProjects;
QString m_projectName;
QString m_projectDescription;
QTimer* m_timer;
QDomDocument *m_domDocument;
friend class Singleton<ProjectManager>;
......@@ -103,9 +90,6 @@ private:
private slots:
void loadTimeline();
void cleanChanged( bool val );
void automaticSaveEnabledChanged( const QVariant& enabled );
void automaticSaveIntervalChanged( const QVariant& interval );
void autoSaveRequired();
void projectNameChanged( const QVariant& projectName );
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