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

Move automatic backup code in its own class.

This is not plugged in for now
parent 76bcfc6e
......@@ -33,6 +33,7 @@ SET(VLMC_SRCS
Media/Clip.cpp
Media/Media.cpp
Metadata/MetaDataManager.cpp
Project/AutomaticBackup.cpp
Project/ProjectManager.cpp
Project/Workspace.cpp
Project/WorkspaceWorker.cpp
......
......@@ -323,16 +323,6 @@ MainWindow::initVlmcPreferences()
VLMC_CREATE_PRIVATE_PREFERENCE_STRING( "private/ImportPreviouslySelectPath", QDir::homePath() );
VLMC_CREATE_PRIVATE_PREFERENCE_BYTEARRAY( "private/MainWindowGeometry", "" );
VLMC_CREATE_PRIVATE_PREFERENCE_BYTEARRAY( "private/MainWindowState", "" );
Core::getInstance()->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 );
Core::getInstance()->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 );
}
#undef CREATE_MENU_SHORTCUT
......
/*****************************************************************************
* AutomaticBackup.cpp: Handles the project automatic backup & associated settings
*****************************************************************************
* Copyright (C) 2008-2014 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <hugo@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 "ProjectManager.h"
#include "Settings/Settings.h"
AutomaticBackup::AutomaticBackup( Settings* vlmcSettings, QObject *parent )
: QObject(parent)
, m_vlmcSettings( vlmcSettings )
{
m_timer = new QTimer( this );
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 );
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 );
vlmcSettings->watchValue( "vlmc/AutomaticBackup", this, SLOT( automaticSaveEnabledChanged( QVariant ) ) );
vlmcSettings->watchValue( "vlmc/AutomaticBackupInterval", this, SLOT( automaticSaveIntervalChanged( QVariant ) ) );
}
AutomaticBackup::~AutomaticBackup()
{
delete m_timer;
}
void
AutomaticBackup::setProject(ProjectManager* projectManager)
{
m_timer->disconnect();
connect( m_timer, SIGNAL( timeout() ), projectManager, SLOT(autoSaveRequired() ) );
}
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 );
}
/*****************************************************************************
* AutomaticBackup.h: Handles the project automatic backup & associated settings
*****************************************************************************
* Copyright (C) 2008-2014 VideoLAN
*
* Authors: Hugo Beauzée-Luyssen <hugo@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 ProjectManager;
class Settings;
#include <QObject>
class AutomaticBackup : public QObject
{
Q_OBJECT
public:
explicit AutomaticBackup(Settings* vlmcSettings, QObject *parent = 0);
virtual ~AutomaticBackup();
void setProject( ProjectManager* projectManager );
private:
Settings* m_vlmcSettings;
QTimer* m_timer;
private slots:
void automaticSaveEnabledChanged( const QVariant& enabled );
void automaticSaveIntervalChanged( const QVariant& interval );
};
#endif // AUTOMATICBACKUP_H
......@@ -26,7 +26,6 @@
#include <QDir>
#include <QDomDocument>
#include <QUndoStack>
#include <QTimer>
#include <errno.h>
#include <signal.h>
......@@ -90,17 +89,6 @@ ProjectManager::ProjectManager( Settings* projectSettings, Settings* vlmcSetting
projectSettings->createVar( SettingValue::String, "vlmc/Workspace", "", "", "", SettingValue::Private );
m_timer = new QTimer( this );
connect( m_timer, SIGNAL( timeout() ), this, SLOT( autoSaveRequired() ) );
vlmcSettings->watchValue( "vlmc/AutomaticBackup", this,
SLOT( automaticSaveEnabledChanged(QVariant) ),
Qt::QueuedConnection );
vlmcSettings->watchValue( "vlmc/AutomaticBackupInterval", this,
SLOT( automaticSaveIntervalChanged(QVariant) ),
Qt::QueuedConnection );
projectSettings->watchValue( "vlmc/ProjectName", this, SLOT(projectNameChanged(QVariant) ) );
//We have to wait for the library to be loaded before loading the workflow
//FIXME
......@@ -247,30 +235,6 @@ ProjectManager::failedToLoad( const QString &reason ) const
abort();
}
void
ProjectManager::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
ProjectManager::automaticSaveIntervalChanged( const QVariant& val )
{
bool enabled = m_vlmcSettings->value( "vlmc/AutomaticBackup" )->get().toBool();
if ( enabled == false )
return ;
m_timer->start( val.toInt() * 1000 * 60 );
}
void
ProjectManager::cleanChanged( bool val )
{
......@@ -390,7 +354,7 @@ ProjectManager::autoSaveRequired()
{
if ( m_projectFile == NULL )
return ;
ProjectManager::saveProject( createAutoSaveOutputFileName( m_projectFile->fileName() ) );
saveProject( createAutoSaveOutputFileName( m_projectFile->fileName() ) );
}
bool
......
......@@ -25,7 +25,6 @@
#include "config.h"
class QTimer;
class QFile;
class QDomDocument;
class QXmlStreamWriter;
......@@ -141,9 +140,8 @@ protected:
QString m_projectName;
QString m_projectDescription;
QDomDocument* m_domDocument;
bool m_needSave;
bool m_isClean;
bool m_libraryCleanState;
QTimer* m_timer;
IProjectManagerUiCb* m_projectManagerUi;
Settings* m_projectSettings;
Settings* m_vlmcSettings;
......@@ -155,8 +153,6 @@ public slots:
private slots:
void loadWorkflow();
void automaticSaveEnabledChanged( const QVariant& enabled );
void automaticSaveIntervalChanged( const QVariant& interval );
void projectNameChanged( const QVariant& projectName );
void autoSaveRequired();
......
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