[vlmc-devel] [PATCH] Refined the flow of the construction of Core.
Yikai Lu
luyikei.qmltu at gmail.com
Sun Mar 6 06:50:01 CET 2016
1, remove AutomaticBackup
2, make Workspace, RecentProjects, and Project independent of Settings.
(if you want to pass Settings to them, just *add* constructor.)
3, fix signal/slots problem.
4, make SettingsValue emit a slgnal, change(), when it is created.
5, add
QString projectName() const;
QString projectPath() const;
to Project.
6, Keep QTimer from running with an interval of 0 by using qMax.
Sorry, I forgot adding src/CmakeLists.txt in my previous email
---
src/CMakeLists.txt | 5 +--
src/Main/Core.cpp | 38 ++++++++++++-------
src/Project/AutomaticBackup.cpp | 84 -----------------------------------------
src/Project/AutomaticBackup.h | 52 -------------------------
src/Project/Project.cpp | 57 +++++++++++++++++++++++-----
src/Project/Project.h | 18 ++++++---
src/Project/RecentProjects.cpp | 18 +--------
src/Project/RecentProjects.h | 3 +-
src/Project/Workspace.cpp | 6 +--
src/Project/Workspace.h | 2 +-
src/Settings/SettingValue.cpp | 1 +
11 files changed, 92 insertions(+), 192 deletions(-)
delete mode 100644 src/Project/AutomaticBackup.cpp
delete mode 100644 src/Project/AutomaticBackup.h
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3ec6c87..ea4867e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -32,11 +32,10 @@ SET(VLMC_SRCS
Media/Clip.cpp
Media/Media.cpp
Metadata/MetaDataManager.cpp
- Project/AutomaticBackup.cpp
- Project/Project.cpp
+ Project/Project.cpp
Project/Workspace.cpp
Project/WorkspaceWorker.cpp
- Project/RecentProjects.cpp
+ Project/RecentProjects.cpp
Renderer/ClipRenderer.cpp
Renderer/GenericRenderer.cpp
Renderer/WorkflowFileRenderer.cpp
diff --git a/src/Main/Core.cpp b/src/Main/Core.cpp
index d1fac98..bcd576d 100644
--- a/src/Main/Core.cpp
+++ b/src/Main/Core.cpp
@@ -36,7 +36,6 @@
#include <Backend/IBackend.h>
#include <EffectsEngine/EffectsEngine.h>
#include "Library/Library.h"
-#include "Project/AutomaticBackup.h"
#include "Project/RecentProjects.h"
#include "Project/Workspace.h"
#include "Renderer/WorkflowRenderer.h"
@@ -52,22 +51,28 @@ Core::Core()
m_logger = new VlmcLogger;
createSettings();
- m_recentProjects = new RecentProjects( m_settings );
- m_automaticBackup = new AutomaticBackup( m_settings );
- m_workspace = new Workspace( m_settings );
+ m_workspace = new Workspace;
m_workflow = new MainWorkflow;
m_workflowRenderer = new WorkflowRenderer( Backend::getBackend(), m_workflow );
m_undoStack = new QUndoStack;
m_library = new Library( m_workspace );
m_currentProject = new Project;
+ m_recentProjects = new RecentProjects;
connect( m_undoStack, SIGNAL( cleanChanged( bool ) ), m_currentProject, SLOT( cleanChanged( bool ) ) );
connect( m_currentProject, SIGNAL( projectSaved() ), m_undoStack, SLOT( setClean() ) );
connect( m_library, SIGNAL( cleanStateChanged( bool ) ), m_currentProject, SLOT( libraryCleanChanged( bool ) ) );
+ connect( m_currentProject, SIGNAL( projectLoaded( QString, QString ) ),
+ m_recentProjects, SLOT( projectLoaded( QString, QString ) ) );
- //FIXME: Pass the project through the constructor since it doesn't change anymore
- m_automaticBackup->setProject( m_currentProject );
- m_recentProjects->setProject( m_currentProject );
+ connect( m_settings->value( "vlmc/AutomaticBackup" ), SIGNAL( changed( QVariant ) ),
+ m_currentProject, SLOT( autoSaveEnabledChanged( QVariant ) ) );
+ connect( m_settings->value( "vlmc/AutomaticBackupInterval" ), SIGNAL( changed( QVariant ) ), m_currentProject,
+ SLOT( autoSaveIntervalChanged( QVariant ) ) );
+ connect( m_settings->value( "private/RecentsProjects" ), SIGNAL( changed( QVariant ) ),
+ m_recentProjects, SLOT( loadRecentProjects( QVariant ) ) );
+ connect( m_settings->value( "vlmc/Workspace" ), SIGNAL( changed( QVariant ) ),
+ m_workspace, SLOT( workspaceChanged( QVariant ) ) );
}
Core::~Core()
@@ -79,7 +84,6 @@ Core::~Core()
delete m_workflow;
delete m_currentProject;
delete m_workspace;
- delete m_automaticBackup;
delete m_settings;
delete m_logger;
delete m_effectsEngine;
@@ -102,6 +106,18 @@ Core::createSettings()
QT_TRANSLATE_NOOP( "Settings", "VLMC's workspace location" ),
SettingValue::Nothing );
m_settings->createVar( SettingValue::Bool, "private/FirstLaunchDone", false, "", "", SettingValue::Private );
+ m_settings->createVar( SettingValue::Bool, "vlmc/AutomaticBackup", false,
+ QT_TRANSLATE_NOOP( "PreferenceWidget", "Automatic save" ),
+ QT_TRANSLATE_NOOP( "PreferenceWidget", "When this option is activated,"
+ "VLMC will automatically save your project "
+ "at a specified interval" ), SettingValue::Nothing );
+ m_settings->createVar( SettingValue::Int, "vlmc/AutomaticBackupInterval", 5,
+ QT_TRANSLATE_NOOP( "PreferenceWidget", "Automatic save interval" ),
+ QT_TRANSLATE_NOOP( "PreferenceWidget", "This is the interval that VLMC will wait "
+ "between two automatic save" ), SettingValue::Nothing );
+ m_settings->createVar( SettingValue::String, "private/RecentsProjects", "",
+ "", "", SettingValue::Private );
+ m_settings->createVar( SettingValue::String, "vlmc/Workspace", "", "", "", SettingValue::Private );
}
Backend::IBackend*
@@ -128,12 +144,6 @@ Core::recentProjects()
return m_recentProjects;
}
-AutomaticBackup*
-Core::automaticBackup()
-{
- return m_automaticBackup;
-}
-
bool
Core::loadProject(const QString& fileName)
{
diff --git a/src/Project/AutomaticBackup.cpp b/src/Project/AutomaticBackup.cpp
deleted file mode 100644
index 5018a91..0000000
--- a/src/Project/AutomaticBackup.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-/*****************************************************************************
- * AutomaticBackup.cpp: Handles the project automatic backup & associated settings
- *****************************************************************************
- * Copyright (C) 2008-2014 VideoLAN
- *
- * Authors: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
- *
- * 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 <QTimer>
-
-#include "AutomaticBackup.h"
-#include "Project.h"
-#include "Settings/Settings.h"
-
-AutomaticBackup::AutomaticBackup( Settings* vlmcSettings, QObject *parent )
- : QObject(parent)
- , m_vlmcSettings( vlmcSettings )
-{
- m_timer = new QTimer( this );
- SettingValue* autoBackup = m_vlmcSettings->createVar( SettingValue::Bool, "vlmc/AutomaticBackup", false,
- QT_TRANSLATE_NOOP( "PreferenceWidget", "Automatic save" ),
- QT_TRANSLATE_NOOP( "PreferenceWidget", "When this option is activated,"
- "VLMC will automatically save your project "
- "at a specified interval" ), SettingValue::Nothing );
- SettingValue* interval = m_vlmcSettings->createVar( SettingValue::Int, "vlmc/AutomaticBackupInterval", 5,
- QT_TRANSLATE_NOOP( "PreferenceWidget", "Automatic save interval" ),
- QT_TRANSLATE_NOOP( "PreferenceWidget", "This is the interval that VLMC will wait "
- "between two automatic save" ), SettingValue::Nothing );
-
- connect( autoBackup, SIGNAL( changed( QVariant ) ), this, SLOT( automaticSaveEnabledChanged( QVariant ) ) );
- connect( interval, SIGNAL( changed( QVariant ) ), this, SLOT( automaticSaveIntervalChanged( QVariant ) ) );
-}
-
-AutomaticBackup::~AutomaticBackup()
-{
- delete m_timer;
-}
-
-void
-AutomaticBackup::setProject( Project* projectManager )
-{
- m_timer->disconnect();
- connect( m_timer, SIGNAL( timeout() ), projectManager, SLOT(autoSaveRequired() ) );
- connect( projectManager, SIGNAL( destroyed() ), m_timer, SLOT( stop() ) );
- m_timer->start();
-}
-
-void
-AutomaticBackup::automaticSaveEnabledChanged( const QVariant& val )
-{
- bool enabled = val.toBool();
-
- if ( enabled == true )
- {
- int interval = m_vlmcSettings->value( "vlmc/AutomaticBackupInterval" )->get().toInt();
- m_timer->start( interval * 1000 * 60 );
- }
- else
- m_timer->stop();
-}
-
-void
-AutomaticBackup::automaticSaveIntervalChanged( const QVariant& val )
-{
- bool enabled = m_vlmcSettings->value( "vlmc/AutomaticBackup" )->get().toBool();
-
- if ( enabled == false )
- return ;
- m_timer->start( val.toInt() * 1000 * 60 );
-}
diff --git a/src/Project/AutomaticBackup.h b/src/Project/AutomaticBackup.h
deleted file mode 100644
index bbfdc5b..0000000
--- a/src/Project/AutomaticBackup.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*****************************************************************************
- * AutomaticBackup.h: Handles the project automatic backup & associated settings
- *****************************************************************************
- * Copyright (C) 2008-2014 VideoLAN
- *
- * Authors: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
- *
- * 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 AUTOMATICBACKUP_H
-#define AUTOMATICBACKUP_H
-
-class QTimer;
-
-class Project;
-class Settings;
-
-#include <QObject>
-
-class AutomaticBackup : public QObject
-{
- Q_OBJECT
-
- public:
- explicit AutomaticBackup( Settings* vlmcSettings, QObject *parent = 0 );
- virtual ~AutomaticBackup();
- void setProject( Project* projectManager );
-
- private:
- Settings* m_vlmcSettings;
- QTimer* m_timer;
-
- private slots:
- void automaticSaveEnabledChanged( const QVariant& enabled );
- void automaticSaveIntervalChanged( const QVariant& interval );
-
-};
-
-#endif // AUTOMATICBACKUP_H
diff --git a/src/Project/Project.cpp b/src/Project/Project.cpp
index af3eeaf..e2202d9 100644
--- a/src/Project/Project.cpp
+++ b/src/Project/Project.cpp
@@ -25,8 +25,8 @@
#include <QFile>
#include <QFileInfo>
#include <QDomDocument>
+#include <QTimer>
-#include "AutomaticBackup.h"
#include "Backend/IBackend.h"
#include "Project.h"
#include "RecentProjects.h"
@@ -41,13 +41,15 @@
const QString Project::unNamedProject = Project::tr( "Untitled Project" );
const QString Project::backupSuffix = "~";
+const int Project::minInterval = 5 * 1000 * 60;
Project::Project()
: m_projectFile( nullptr )
, m_isClean( true )
, m_libraryCleanState( true )
+ , m_timer( new QTimer( this ) )
+ , m_settings( new Settings( QString() ) )
{
- m_settings = new Settings( QString() );
initSettings();
}
@@ -55,6 +57,7 @@ Project::~Project()
{
delete m_projectFile;
delete m_settings;
+ delete m_timer;
}
Settings*
@@ -116,8 +119,7 @@ Project::load( const QString& path )
}
m_settings->load( doc );
- auto projectName = m_settings->value( "vlmc/ProjectName" )->get().toString();
- emit projectLoading( projectName );
+ emit projectLoading( projectName() );
Core::getInstance()->library()->load( doc );
Core::getInstance()->workflow()->load( doc );
Core::getInstance()->workflowRenderer()->load( doc );
@@ -125,7 +127,7 @@ Project::load( const QString& path )
emit cleanStateChanged( m_isClean );
if ( autoBackupFound == false )
m_projectFile->close();
- emit projectLoaded( projectName );
+ emit projectLoaded( projectName(), projectPath() );
if ( outdatedBackupFound == true )
emit outdatedBackupFileFound();
if ( autoBackupFound == true )
@@ -158,6 +160,18 @@ Project::newProject( const QString& projectName, const QString& projectPath )
save();
}
+QString
+Project::projectName() const
+{
+ return m_settings->value( "vlmc/ProjectName" )->get().toString();
+}
+
+QString
+Project::projectPath() const
+{
+ return m_projectFile->fileName();
+}
+
void
Project::initSettings()
{
@@ -190,11 +204,14 @@ Project::initSettings()
QT_TRANSLATE_NOOP("PreferenceWidget", "Number of audio channels" ),
SettingValue::Clamped );
audioChannel->setLimits( 2, 2 );
- SettingValue* pName = m_settings->createVar( SettingValue::String, "vlmc/ProjectName", unNamedProject,
- QT_TRANSLATE_NOOP( "PreferenceWidget", "Project name" ),
- QT_TRANSLATE_NOOP( "PreferenceWidget", "The project name" ),
- SettingValue::NotEmpty );
+ SettingValue* pName = m_settings->createVar( SettingValue::String, "vlmc/ProjectName", unNamedProject,
+ QT_TRANSLATE_NOOP( "PreferenceWidget", "Project name" ),
+ QT_TRANSLATE_NOOP( "PreferenceWidget", "The project name" ),
+ SettingValue::NotEmpty );
connect( pName, SIGNAL( changed( QVariant ) ), this, SIGNAL( projectUpdated( QVariant ) ) );
+
+ connect( m_timer, SIGNAL( timeout() ), this, SLOT(autoSaveRequired() ) );
+ connect( this, SIGNAL( destroyed() ), m_timer, SLOT( stop() ) );
}
void
@@ -299,3 +316,25 @@ Project::autoSaveRequired()
return ;
saveProject( m_projectFile->fileName() + Project::backupSuffix );
}
+
+void
+Project::autoSaveEnabledChanged(const QVariant &enabled)
+{
+ if ( enabled.toBool() == true )
+ {
+ int interval = Core::getInstance()->settings()->value( "vlmc/AutomaticBackupInterval" )->get().toInt();
+ m_timer->start( qMax( minInterval, interval * 1000 * 60 ) );
+ }
+ else
+ m_timer->stop();
+}
+
+void
+Project::autoSaveIntervalChanged(const QVariant &interval)
+{
+ bool enabled = Core::getInstance()->settings()->value( "vlmc/AutomaticBackup" )->get().toBool();
+
+ if ( enabled == false )
+ return ;
+ m_timer->start( qMax( minInterval, interval.toInt() * 1000 * 60 ) );
+}
diff --git a/src/Project/Project.h b/src/Project/Project.h
index 0c8b53a..9301681 100644
--- a/src/Project/Project.h
+++ b/src/Project/Project.h
@@ -33,12 +33,13 @@ class QDomDocument;
class QFile;
class QString;
class QXmlStreamWriter;
+class QTimer;
-class AutomaticBackup;
class Library;
class MainWorkflow;
class ProjectManager;
class Settings;
+class SettingValue;
class Project : public QObject
{
@@ -46,9 +47,11 @@ class Project : public QObject
public:
static const QString unNamedProject;
static const QString backupSuffix;
+ static const int minInterval;
public:
Q_DISABLE_COPY( Project );
+
Project();
virtual ~Project();
@@ -56,6 +59,8 @@ class Project : public QObject
void save();
void saveAs(const QString& fileName);
void newProject( const QString& projectName, const QString& projectPath );
+ QString projectName() const;
+ QString projectPath() const;
/**
* @brief Check for a project backup file, and load the appropriate file,
* according to the user input.
@@ -84,6 +89,8 @@ class Project : public QObject
void cleanChanged( bool val );
void libraryCleanChanged( bool val );
void autoSaveRequired();
+ void autoSaveEnabledChanged( const QVariant& enabled );
+ void autoSaveIntervalChanged( const QVariant& interval );
signals:
/**
@@ -91,7 +98,7 @@ class Project : public QObject
* - The project name has changed
* - The revision (if activated) has changed
*/
- void projectUpdated( const QString& projectName );
+ void projectUpdated( const QVariant& projectName );
/**
* \brief Used to signal that the project has been saved.
@@ -108,25 +115,26 @@ class Project : public QObject
void cleanStateChanged( bool value );
void projectLoading( const QString& projectName );
- void projectLoaded( const QString& projectName );
+ void projectLoaded(const QString& projectName, const QString& projectPath );
void projectClosed();
void backupProjectLoaded();
void outdatedBackupFileFound();
-private:
+ private:
bool loadWorkflow( const QDomDocument& root );
private:
QFile* m_projectFile;
bool m_isClean;
bool m_libraryCleanState;
+ QTimer* m_timer;
///////////////////////////////////
// Dependent components part below:
public:
Settings* settings();
- private:
+private:
Settings* m_settings;
};
diff --git a/src/Project/RecentProjects.cpp b/src/Project/RecentProjects.cpp
index 080950d..5efd97f 100644
--- a/src/Project/RecentProjects.cpp
+++ b/src/Project/RecentProjects.cpp
@@ -28,25 +28,9 @@
#include "Settings/Settings.h"
#include "Tools/VlmcDebug.h"
-RecentProjects::RecentProjects( Settings* vlmcSettings, QObject *parent )
+RecentProjects::RecentProjects( QObject *parent )
: QObject(parent)
- , m_settings( vlmcSettings )
- , m_project( NULL )
{
- SettingValue* recentProjects = vlmcSettings->createVar( SettingValue::String, "private/RecentsProjects", "",
- "", "", SettingValue::Private );
-
- connect( recentProjects, SIGNAL( changed( QVariant ) ), this, SLOT( loadRecentProjects( QVariant ) ) );
-}
-
-void
-RecentProjects::setProject( Project* project )
-{
- if ( m_project != NULL )
- disconnect( m_project, SIGNAL( projectLoaded( QString, QString ) ) );
- m_project = project;
- connect( project, SIGNAL( projectLoaded( QString, QString ) ),
- this, SLOT( projectLoaded( QString, QString ) ) );
}
void
diff --git a/src/Project/RecentProjects.h b/src/Project/RecentProjects.h
index 4bdf3e2..3be23a1 100644
--- a/src/Project/RecentProjects.h
+++ b/src/Project/RecentProjects.h
@@ -40,9 +40,8 @@ class RecentProjects : public QObject
};
typedef QList<RecentProject> List;
- explicit RecentProjects(Settings* vlmcSettings, QObject *parent = 0 );
+ explicit RecentProjects( QObject *parent = 0 );
- void setProject(Project* projectManager );
void remove( const QString& projectFile );
const List& list() const;
diff --git a/src/Project/Workspace.cpp b/src/Project/Workspace.cpp
index 0de8e67..b75e7c7 100644
--- a/src/Project/Workspace.cpp
+++ b/src/Project/Workspace.cpp
@@ -40,13 +40,9 @@
const QString Workspace::workspacePrefix = "workspace://";
-Workspace::Workspace(Settings *settings)
+Workspace::Workspace()
: m_copyInProgress( false )
{
- settings->createVar( SettingValue::String, "vlmc/Workspace", "", "", "", SettingValue::Private );
- SettingValue* workspaceDir = settings->value( "vlmc/Workspace" );
- connect(workspaceDir, SIGNAL( changed( QVariant ) ),
- this, SLOT( workspaceChanged( QVariant ) ) );
// Wait for the SettingValue to be loaded.
m_mediasToCopyMutex = new QMutex;
#ifdef WITH_GUI
diff --git a/src/Project/Workspace.h b/src/Project/Workspace.h
index 5a8d695..2dde36a 100644
--- a/src/Project/Workspace.h
+++ b/src/Project/Workspace.h
@@ -42,7 +42,7 @@ class Workspace : public QObject, public ErrorHandler
public:
static const QString workspacePrefix;
- Workspace( Settings* settings );
+ Workspace();
~Workspace();
bool isInWorkspace( const QString &path );
bool isInWorkspace( const Media *media );
diff --git a/src/Settings/SettingValue.cpp b/src/Settings/SettingValue.cpp
index 7f35926..948c30c 100644
--- a/src/Settings/SettingValue.cpp
+++ b/src/Settings/SettingValue.cpp
@@ -32,6 +32,7 @@ SettingValue::SettingValue( const QString& key, SettingValue::Type type, const Q
m_type( type ),
m_flags( flags )
{
+ emit changed( m_val );
}
void
--
1.9.1
More information about the Vlmc-devel
mailing list