[vlmc-devel] [PATCH 1/3] Remove AutomaticBackup class

Yikai Lu luyikei.qmltu at gmail.com
Mon Mar 7 12:43:42 CET 2016


It is not needed as a class therefore being merged into Project.
---
 src/CMakeLists.txt              |  5 +--
 src/Main/Core.cpp               | 13 +------
 src/Main/Core.h                 |  2 -
 src/Project/AutomaticBackup.cpp | 84 -----------------------------------------
 src/Project/AutomaticBackup.h   | 52 -------------------------
 src/Project/Project.cpp         | 54 ++++++++++++++++++++++++--
 src/Project/Project.h           |  7 +++-
 7 files changed, 59 insertions(+), 158 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..472f458 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"
@@ -53,20 +52,17 @@ Core::Core()
 
     createSettings();
     m_recentProjects = new RecentProjects( m_settings );
-    m_automaticBackup = new AutomaticBackup( m_settings );
     m_workspace = new Workspace( m_settings );
     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_currentProject = new Project( m_settings );
 
     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 ) ) );
 
-    //FIXME: Pass the project through the constructor since it doesn't change anymore
-    m_automaticBackup->setProject( m_currentProject );
     m_recentProjects->setProject( m_currentProject );
 }
 
@@ -79,7 +75,6 @@ Core::~Core()
     delete m_workflow;
     delete m_currentProject;
     delete m_workspace;
-    delete m_automaticBackup;
     delete m_settings;
     delete m_logger;
     delete m_effectsEngine;
@@ -128,12 +123,6 @@ Core::recentProjects()
     return m_recentProjects;
 }
 
-AutomaticBackup*
-Core::automaticBackup()
-{
-    return m_automaticBackup;
-}
-
 bool
 Core::loadProject(const QString& fileName)
 {
diff --git a/src/Main/Core.h b/src/Main/Core.h
index b4e26e0..52463a6 100644
--- a/src/Main/Core.h
+++ b/src/Main/Core.h
@@ -54,7 +54,6 @@ class Core : public QObject
         Settings*               settings();
         VlmcLogger*             logger();
         RecentProjects*         recentProjects();
-        AutomaticBackup*        automaticBackup();
         Workspace*              workspace();
         Project*                project();
         WorkflowRenderer*       workflowRenderer();
@@ -80,7 +79,6 @@ class Core : public QObject
         Settings*               m_settings;
         VlmcLogger*             m_logger;
         RecentProjects*         m_recentProjects;
-        AutomaticBackup*        m_automaticBackup;
         Workspace*              m_workspace;
         Project*                m_currentProject;
         MainWorkflow*           m_workflow;
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..3800e51 100644
--- a/src/Project/Project.cpp
+++ b/src/Project/Project.cpp
@@ -25,8 +25,9 @@
 #include <QFile>
 #include <QFileInfo>
 #include <QDomDocument>
+#include <QTimer>
+
 
-#include "AutomaticBackup.h"
 #include "Backend/IBackend.h"
 #include "Project.h"
 #include "RecentProjects.h"
@@ -42,19 +43,41 @@
 const QString   Project::unNamedProject = Project::tr( "Untitled Project" );
 const QString   Project::backupSuffix = "~";
 
-Project::Project()
+Project::Project( Settings* settings )
     : 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();
+
+    SettingValue    *automaticBackup = 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 );
+    SettingValue    *automaticBackupInterval = 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 );
+
+    connect( m_timer, SIGNAL( timeout() ), this, SLOT(autoSaveRequired() ) );
+    connect( this, SIGNAL( destroyed() ), m_timer, SLOT( stop() ) );
+
+    connect( automaticBackup, SIGNAL( changed( QVariant ) ),
+             this, SLOT( autoSaveEnabledChanged( QVariant ) ) );
+    connect( automaticBackupInterval, SIGNAL( changed( QVariant ) ), this,
+             SLOT( autoSaveIntervalChanged( QVariant ) ) );
+
+    m_timer->start();
 }
 
 Project::~Project()
 {
     delete m_projectFile;
     delete m_settings;
+    delete m_timer;
 }
 
 Settings*
@@ -193,7 +216,7 @@ Project::initSettings()
 	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::NotEmpty );
     connect( pName, SIGNAL( changed( QVariant ) ), this, SIGNAL( projectUpdated( QVariant ) ) );
 }
 
@@ -299,3 +322,26 @@ 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( 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( interval.toInt() * 1000 * 60 );
+}
diff --git a/src/Project/Project.h b/src/Project/Project.h
index 0c8b53a..3d53d05 100644
--- a/src/Project/Project.h
+++ b/src/Project/Project.h
@@ -33,6 +33,7 @@ class QDomDocument;
 class QFile;
 class QString;
 class QXmlStreamWriter;
+class QTimer;
 
 class AutomaticBackup;
 class Library;
@@ -49,7 +50,7 @@ class Project : public QObject
 
     public:
         Q_DISABLE_COPY( Project );
-        Project();
+        Project( Settings* settings );
 
         virtual ~Project();
 
@@ -84,6 +85,9 @@ 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:
         /**
@@ -120,6 +124,7 @@ private:
         QFile*              m_projectFile;
         bool                m_isClean;
         bool                m_libraryCleanState;
+        QTimer*             m_timer;
 
     ///////////////////////////////////
     // Dependent components part below:
-- 
1.9.1



More information about the Vlmc-devel mailing list