Commit 5b091082 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Starting a settings refactor

parent 1711cd64
......@@ -9,9 +9,11 @@ KeyboardShortcutHelper::KeyboardShortcutHelper( const QString& name, QWidget* pa
m_name( name ),
m_menu( menu )
{
QVariant set = SettingsManager::getInstance()->value( name );
if ( m_menu == false )
setKey( QKeySequence( set.toString() ) );
{
QString set = VLMC_GET_STRING( name );
setKey( QKeySequence( set ) );
}
SettingsManager::getInstance()->watchValue( "keyboard/" + name, this,
SLOT( shortcutUpdated( const QVariant& ) ),
SettingsManager::Vlmc );
......
......@@ -23,11 +23,15 @@
#include "SettingValue.h"
#include <QtDebug>
SettingValue::SettingValue( const QVariant& val ) : m_val ( val )
SettingValue::SettingValue( const QVariant& defaultValue, const QString& desc ) :
m_val( defaultValue ),
m_defaultVal( defaultValue ),
m_desc( desc )
{
}
void SettingValue::set( const QVariant& val )
void
SettingValue::set( const QVariant& val )
{
if ( val != m_val )
{
......@@ -36,7 +40,20 @@ void SettingValue::set( const QVariant& val )
}
}
const QVariant& SettingValue::get() const
const QVariant&
SettingValue::get() const
{
return m_val;
}
const QString&
SettingValue::description() const
{
return m_desc;
}
void
SettingValue::restoreDefault()
{
set( m_defaultVal );
}
......@@ -32,13 +32,18 @@
* \brief represent a setting value
*
*/
class SettingValue : public QObject
{
Q_OBJECT
Q_DISABLE_COPY( SettingValue );
public:
SettingValue( const QVariant& val );
/**
* \brief Constructs a setting value with its default value and description
*
* \param defaultValue The setting default value.
* \param desc The setting description
*/
SettingValue( const QVariant& defaultValue, const QString& desc );
/**
* \brief setter for the m_val member
......@@ -50,13 +55,22 @@ class SettingValue : public QObject
/**
* \brief getter for the m_val member
*/
const QVariant& get() const;
/**
* \return The setting's description
*/
const QString &description() const;
/**
* \brief Set the setting to its default value.
*/
void restoreDefault();
private:
/**
* \brief the QVariant containingthe value of the settings
*/
QVariant m_val;
QVariant m_defaultVal;
QString m_desc;
signals:
/**
* \brief This signal is emmited while the m_val
......
......@@ -39,10 +39,11 @@ SettingsManager::setValue( const QString &key,
const QVariant &value,
SettingsManager::Type type )
{
if ( type == Project )
m_tmpXmlSettings.insert( key, new SettingValue( value ) );
else if ( type == Vlmc )
m_tmpClassicSettings.insert( key, new SettingValue( value ) );
if ( type == Project && m_xmlSettings.contains( key ) == true )
m_xmlSettings[key]->set( value );
else if ( type == Vlmc && m_classicSettings.contains( key) == true )
m_classicSettings[key]->set( value );
qWarning() << "Setting" << key << "does not exist.";
return ;
}
......@@ -66,15 +67,11 @@ SettingsManager::setImmediateValue( const QString &key,
{
settMap->value( key )->set( value );
}
else
{
settMap->insert( key, new SettingValue( value ) );
}
qWarning() << "Setting" << key << "does not exist.";
return ;
}
QVariant
SettingValue*
SettingsManager::value( const QString &key,
const QVariant &defaultValue,
SettingsManager::Type type )
......@@ -84,27 +81,15 @@ SettingsManager::value( const QString &key,
if ( type == Project )
{
if ( m_xmlSettings.contains( key ) )
return m_xmlSettings.value( key )->get();
else
{
m_xmlSettings.insert( key, new SettingValue( defaultValue ) );
return defaultValue;
}
return m_xmlSettings.value( key );
}
else
{
if ( m_classicSettings.contains( key ) )
return m_classicSettings.value( key )->get();
else
{
QSettings sett;
QVariant val = sett.value( key, defaultValue );
if ( val != defaultValue )
m_classicSettings.insert( key, new SettingValue( val ) );
return val;
}
return m_classicSettings.value( key );
}
qWarning() << "Setting" << key << "does not exist.";
return NULL;
}
QHash<QString, QVariant>
......@@ -150,8 +135,9 @@ SettingsManager::group( const QString &groupName, SettingsManager::Type type )
{
ret.insert( key.right( key.size()
- key.indexOf( "/" ) - 1 ), sett.value( key ) );
if ( !m_classicSettings.contains( key ) )
m_classicSettings.insert( key, new SettingValue( sett.value( key ) ) );
//FIXME !
// if ( !m_classicSettings.contains( key ) )
// m_classicSettings.insert( key, new SettingValue( sett.value( key ) ) );
}
}
}
......@@ -260,9 +246,6 @@ SettingsManager::load( const QDomElement &element )
QString key = "project/" + list.at( idx ).toElement().tagName();
if ( m_xmlSettings.contains( key ) )
m_xmlSettings[key]->set( QVariant( attrMap.item( 0 ).nodeValue() ) );
else
m_xmlSettings.insert( key,
new SettingValue( QVariant( attrMap.item( 0 ).nodeValue() ) ) );
}
return true;
}
......@@ -302,6 +285,18 @@ SettingsManager::commit( SettingsManager::Type type )
flush();
}
void
SettingsManager::createVar( const QString &key, const QVariant &defaultValue,
const QString &desc, SettingsManager::Type type /*= Vlmc*/ )
{
QWriteLocker wlock( &m_rwLock );
if ( type == Vlmc && m_classicSettings.contains( key ) == false )
m_classicSettings.insert( key, new SettingValue( defaultValue, desc ) );
else if ( type == Project && m_xmlSettings.contains( key ) == false )
m_classicSettings.insert( key, new SettingValue( defaultValue, desc ) );
}
void
SettingsManager::flush()
{
......
......@@ -23,7 +23,8 @@
#ifndef SETTINGSMANAGER_H
#define SETTINGSMANAGER_H
#include <Singleton.hpp>
#include "SettingValue.h"
#include "Singleton.hpp"
#include <QString>
#include <QHash>
......@@ -35,7 +36,21 @@ class SettingValue;
class QXmlStreamWriter;
class QDomElement;
class QDomDocument;
class SettingValue;
//Var helpers :
#define VLMC_GET_STRING( key ) SettingsManager::getInstance()->value( key )->get().toString()
#define VLMC_GET_INT( key ) SettingsManager::getInstance()->value( key )->get().toInt()
#define VLMC_GET_UINT( key ) SettingsManager::getInstance()->value( key )->get().toUInt()
#define VLMC_GET_DOUBLE( key ) SettingsManager::getInstance()->value( key )->get().toDouble()
#define VLMC_GET_BOOL( key ) SettingsManager::getInstance()->value( key )->get().toBool()
#define VLMC_CREATE_PROJECT_VAR( key, defaultValue, desc ) \
SettingsManager::getInstance()->createVar( key, defaultValue, QObject::tr(desc), \
SettingsManager::Project );
#define VLMC_CREATE_PREFERENCE( key, defaultValue, desc ) \
SettingsManager::getInstance()->createVar( key, defaultValue, QObject::tr(desc), \
SettingsManager::Vlmc );
class SettingsManager : public QObject, public Singleton<SettingsManager>
{
......@@ -55,12 +70,15 @@ class SettingsManager : public QObject, public Singleton<SettingsManager>
void setImmediateValue( const QString &key,
const QVariant &value,
SettingsManager::Type = Vlmc);
QVariant value( const QString &key,
SettingValue *value( const QString &key,
const QVariant &defaultValue = QVariant(),
SettingsManager::Type type = Vlmc );
QHash<QString, QVariant> group( const QString &groupName,
SettingsManager::Type type = Vlmc );
void createVar( const QString &key,
const QVariant &defaultValue,
const QString &desc, Type type = Vlmc );
bool watchValue( const QString &key,
QObject* receiver,
const char *method,
......
......@@ -26,6 +26,7 @@
#include "SettingsManager.h"
#include "LanguagePreferences.h"
#include "ui_LanguagePreferences.h"
#include "SettingValue.h"
#include <QVariant>
#include <QDir>
......@@ -72,6 +73,7 @@ LanguagePreferences::LanguagePreferences( QWidget *parent )
// Sort the combobox
m_ui.comboBoxLanguage->model()->sort( 0 );
VLMC_CREATE_PREFERENCE( "global/VLMCLang", "en_US", "The VLMC's UI language" );
}
LanguagePreferences::~LanguagePreferences() {}
......@@ -80,7 +82,7 @@ void LanguagePreferences::load()
{
SettingsManager *setMan = SettingsManager::getInstance();
QVariant lang = setMan->value( "global/VLMCLang", "en_US", m_type );
QVariant lang = setMan->value( "global/VLMCLang", "en_US", m_type )->get();
int idx = m_ui.comboBoxLanguage->findData( lang );
if ( idx != -1 )
......
......@@ -479,10 +479,10 @@ void MainWindow::on_actionRedo_triggered()
}
#define INIT_SHORTCUT( instName, shortcutName, actionInstance ) \
QVariant instName = SettingsManager::getInstance()->value( "keyboard/" shortcutName );\
QString instName = VLMC_GET_STRING( "keyboard/"shortcutName ); \
KeyboardShortcutHelper* helper##instName = new KeyboardShortcutHelper( shortcutName, this, true ); \
connect( helper##instName, SIGNAL( changed( const QString&, const QString&) ), this, SLOT( keyboardShortcutChanged(const QString&, const QString&)) ); \
m_ui.actionInstance->setShortcut( instName.toString() );
m_ui.actionInstance->setShortcut( instName );
void MainWindow::initializeMenuKeyboardShortcut()
{
......
......@@ -34,12 +34,9 @@ RendererSettings::RendererSettings()
m_ui.setupUi( this );
connect( m_ui.outputFileNameButton, SIGNAL(clicked() ),
this, SLOT(selectOutputFileName() ) );
QVariant width = SettingsManager::getInstance()->value( "project/VideoProjectWidth", 480 ,xml );
QVariant height = SettingsManager::getInstance()->value( "project/VideoProjectHeight", 300, xml );
QVariant outputFps = SettingsManager::getInstance()->value( "global/VLMCOutPutFPS", 30, SettingsManager::Vlmc );
m_ui.width->setValue( width.toInt() );
m_ui.height->setValue( height.toInt() );
m_ui.fps->setValue( outputFps.toDouble() );
m_ui.width->setValue( VLMC_GET_INT( "project/VideoProjectWidth" ) );
m_ui.height->setValue( VLMC_GET_INT( "project/VideoProjectHeight" ) );
m_ui.fps->setValue( VLMC_GET_DOUBLE( "global/VLMCOutputFPS" ) );
}
void
......
......@@ -29,16 +29,15 @@ AudioProjectPreferences::AudioProjectPreferences( QWidget *parent )
m_type( SettingsManager::Project )
{
m_ui.setupUi( this );
VLMC_CREATE_PROJECT_VAR( "project/AudioSampleRate", 0, "The project audio samplerate" );
}
AudioProjectPreferences::~AudioProjectPreferences() { }
void AudioProjectPreferences::load()
{
SettingsManager* setMan = SettingsManager::getInstance();
int sampleRate = setMan->value( "project/AudioSampleRate", 0, m_type ).toInt();
int sampleRate = VLMC_GET_INT( "project/AudioSampleRate" );
m_ui.SampleRate->setValue( sampleRate );
return ;
}
......
......@@ -27,16 +27,14 @@
#include "ProjectManager.h"
#include <QWidget>
//DEBUG
#include <QtDebug>
//!DEBUG
ProjectPreferences::ProjectPreferences( QWidget* parent )
: PreferenceWidget( parent ),
m_type( SettingsManager::Project )
{
m_ui.setupUi( this );
VLMC_CREATE_PROJECT_VAR( "project/ProjectName", ProjectManager::unSavedProject,
"The project name" );
}
ProjectPreferences::~ProjectPreferences() { }
......@@ -44,9 +42,7 @@ ProjectPreferences::~ProjectPreferences() { }
void ProjectPreferences::load()
{
SettingsManager* settMan = SettingsManager::getInstance();
QString Name = settMan->value( "project/ProjectName",
ProjectManager::unNamedProject,
m_type ).toString();
QString Name = VLMC_GET_STRING( "project/ProjectName" );
m_ui.ProjectNameLineEdit->setText( Name );
}
......
......@@ -55,10 +55,10 @@ void VLMCPreferences::load()
{
SettingsManager* settMan = SettingsManager::getInstance();
QString outputFPS = settMan->value( "global/VLMCOutPutFPS", "30", m_type ).toString();
QString tracksNb = settMan->value( "global/VLMCTracksNb", "64", m_type ).toString();
bool autoSave = settMan->value( "global/AutomaticBackup", false, m_type ).toBool();
QString autoSaveInterval = settMan->value( "global/AutomaticBackupInterval", "5", m_type ).toString();
QString outputFPS = VLMC_GET_STRING( "global/VLMCOutputFPS" );
QString tracksNb = VLMC_GET_STRING( "global/VLMCTracksNb" );
bool autoSave = VLMC_GET_BOOL( "global/AutomaticBackup" );
QString autoSaveInterval = VLMC_GET_STRING( "global/AutomaticBackupInterval" );
m_ui.outputFPS->setText( outputFPS );
m_ui.tracksNb->setText( tracksNb );
......
......@@ -30,6 +30,9 @@ VideoProjectPreferences::VideoProjectPreferences( QWidget *parent )
m_type( SettingsManager::Project )
{
m_ui.setupUi( this );
VLMC_CREATE_PROJECT_VAR( "project/VideoProjectWidth", 480, "The project video width" );
VLMC_CREATE_PROJECT_VAR( "project/VideoProjectHeight", 300, "The project video height" );
VLMC_CREATE_PROJECT_VAR( "global/VLMCOutputFPS", 30, "The project output FPS" );
}
VideoProjectPreferences::~VideoProjectPreferences() { }
......@@ -38,9 +41,10 @@ void VideoProjectPreferences::load()
{
SettingsManager* setMan = SettingsManager::getInstance();
int projectFps = setMan->value( "project/VideoProjectFPS", 30, m_type ).toInt();
int projectHeight = setMan->value( "project/VideoProjectHeight", 300, m_type ).toInt();
int projectWidth = setMan->value( "project/VideoProjectWidth", 480, m_type ).toInt();
int projectWidth = VLMC_GET_INT( "project/VideoProjectWidth" );
int projectHeight = VLMC_GET_INT( "project/VideoProjectHeight" );
//FIXME: fps is a double value
int projectFps = VLMC_GET_INT( "global/VLMCOutputFPS" );
m_ui.FPSSpinBox->setValue( projectFps );
m_ui.HeightSpinBox->setValue( projectHeight );
......
......@@ -37,8 +37,7 @@ TracksRuler::TracksRuler( TracksView* tracksView, QWidget* parent )
//TODO We should really get that from the
// workflow and not directly from the settings.
SettingsManager* settings = SettingsManager::getInstance();
m_fps = qRound( settings->value( "global/VLMCOutPutFPS", 30, SettingsManager::Vlmc ).toDouble() );
m_fps = qRound( VLMC_GET_DOUBLE( "global/VLMCOutputFPS" ) );
m_factor = 1;
m_scale = 3;
......
......@@ -49,16 +49,12 @@ int GeneralPage::nextId() const
void GeneralPage::initializePage()
{
SettingsManager* sManager = SettingsManager::getInstance();
//Since this is a new project, it will be unnamed
QString projectName = ProjectManager::unNamedProject;
ui.lineEditName->setText( projectName );
//fetching the global workspace path
QString workspacePath = sManager->value( "global/VLMCWorkspace",
QDir::homePath(),
SettingsManager::Vlmc ).toString();
QString workspacePath = VLMC_GET_STRING( "global/VLMCWorkspace" );
ui.lineEditWorkspace->setText( workspacePath );
updateProjectLocation();
......
......@@ -139,9 +139,8 @@ MetaDataWorker::metaDataAvailable()
}
else
{
QVariant val = SettingsManager::getInstance()->value( "project/VideoProjectFPS", 30, SettingsManager::Project );
Q_ASSERT_X( val.isNull() == false , "MetaDataWorker", "Can't operate without a project FPS value ");
m_media->setFps( val.toDouble() );
double fps = VLMC_GET_DOUBLE( "project/VideoProjectFPS" );
m_media->setFps( fps );
}
m_media->setLength( m_mediaPlayer->getLength() );
......
......@@ -74,8 +74,7 @@ ProjectManager::ProjectManager() : m_projectFile( NULL ), m_needSave( false )
connect( this, SIGNAL( projectClosed() ), Library::getInstance(), SLOT( clear() ) );
connect( this, SIGNAL( projectClosed() ), MainWorkflow::getInstance(), SLOT( clear() ) );
QVariant val =
SettingsManager::getInstance()->value( "project/ProjectName", unNamedProject, SettingsManager::Project );
VLMC_CREATE_PROJECT_VAR( "project/ProjectName", unNamedProject, "The project name" );
SettingsManager::getInstance()->watchValue( "project/ProjectName", this,
SLOT(projectNameChanged(QVariant) ),
SettingsManager::Project );
......@@ -83,19 +82,19 @@ ProjectManager::ProjectManager() : m_projectFile( NULL ), m_needSave( false )
//Automatic save part :
m_timer = new QTimer( this );
connect( m_timer, SIGNAL( timeout() ), this, SLOT( autoSaveRequired() ) );
QVariant autoSaveEnabled =
SettingsManager::getInstance()->value( "global/AutomaticBackup", false, SettingsManager::Vlmc );
VLMC_CREATE_PREFERENCE( "global/AutomaticBackup", false, "When this option is activated,"
"vlmc will automatically save your project at a specified interval" );
SettingsManager::getInstance()->watchValue( "global/AutomaticBackup", this,
SLOT( automaticSaveEnabledChanged(QVariant) ),
SettingsManager::Vlmc,
Qt::QueuedConnection );
QVariant autoSaveInterval =
SettingsManager::getInstance()->value( "global/AutomaticBackupInterval", 5, SettingsManager::Vlmc );
VLMC_CREATE_PREFERENCE( "global/AutomaticBackupInterval", 5, "This is the interval that"
"vlmc will wait between two automatic save" );
SettingsManager::getInstance()->watchValue( "global/AutomaticBackupInterval", this,
SLOT( automaticSaveIntervalChanged(QVariant) ),
SettingsManager::Vlmc,
Qt::QueuedConnection );
automaticSaveEnabledChanged( autoSaveEnabled );
automaticSaveEnabledChanged( VLMC_GET_BOOL( "global/AutomaticBackup" ) );
}
ProjectManager::~ProjectManager()
......@@ -348,8 +347,8 @@ void ProjectManager::automaticSaveEnabledChanged( const QVariant& val )
if ( enabled == true )
{
QVariant interval = SettingsManager::getInstance()->value( "global/AutomaticBackupInterval", 5, SettingsManager::Vlmc );
m_timer->start( interval.toInt() * 1000 * 60 );
int interval = VLMC_GET_INT( "global/AutomaticBackupInterval" );
m_timer->start( interval * 1000 * 60 );
}
else
m_timer->stop();
......@@ -357,9 +356,9 @@ void ProjectManager::automaticSaveEnabledChanged( const QVariant& val )
void ProjectManager::automaticSaveIntervalChanged( const QVariant& val )
{
QVariant enabled = SettingsManager::getInstance()->value( "global/AutomaticBackup", false, SettingsManager::Vlmc );
bool enabled = VLMC_GET_BOOL( "global/AutomaticBackup" );
if ( enabled.toBool() == false )
if ( enabled == false )
return ;
m_timer->start( val.toInt() * 1000 * 60 );
}
......
......@@ -160,15 +160,13 @@ WorkflowFileRenderer::getUnlockCallback()
quint32
WorkflowFileRenderer::width() const
{
QVariant width = SettingsManager::getInstance()->value( "project/VideoProjectWidth", 480, SettingsManager::Project );
return width.toUInt();
return VLMC_GET_UINT( "project/VideoProjectWidth" );
}
quint32
WorkflowFileRenderer::height() const
{
QVariant height = SettingsManager::getInstance()->value( "project/VideoProjectHeight", 300, SettingsManager::Project );
return height.toUInt();
return VLMC_GET_UINT( "project/VideoProjectHeight" );
}
void
......
......@@ -348,22 +348,19 @@ void* WorkflowRenderer::getUnlockCallback()
quint32
WorkflowRenderer::width() const
{
QVariant width = SettingsManager::getInstance()->value( "project/VideoProjectWidth", 480, SettingsManager::Project );
return width.toUInt();
return VLMC_GET_UINT( "project/VideoProjectWidth" );
}
quint32
WorkflowRenderer::height() const
{
QVariant height = SettingsManager::getInstance()->value( "project/VideoProjectHeight", 300, SettingsManager::Project );
return height.toUInt();
return VLMC_GET_UINT( "project/VideoProjectHeight" );
}
float
WorkflowRenderer::outputFps() const
{
QVariant outputFps = SettingsManager::getInstance()->value( "global/VLMCOutPutFPS", 30, SettingsManager::Vlmc );
return outputFps.toDouble();
return VLMC_GET_DOUBLE( "global/VLMCOutPutFPS" );
}
bool
......
......@@ -49,20 +49,20 @@ VlmcDebug::VlmcDebug() : m_logFile( NULL )
}
QVariant setVal = SettingsManager::getInstance()->value( "private/LogFile", "log.vlmc", SettingsManager::Vlmc );
SettingsManager::getInstance()->watchValue( "private/LogFile", this,
SLOT( logFileChanged( const QVariant& ) ),
SettingsManager::Vlmc );
QObject::connect( qApp,
SIGNAL( aboutToQuit() ),
this,
SLOT( deleteLater() ) );
QString logFile = setVal.toString();
if ( logFile.isEmpty() == false )
{
m_logFile = new QFile( logFile );
m_logFile->open( QFile::WriteOnly | QFile::Truncate );
}
// QVariant setVal = SettingsManager::getInstance()->value( "private/LogFile", "log.vlmc", SettingsManager::Vlmc );
// SettingsManager::getInstance()->watchValue( "private/LogFile", this,
// SLOT( logFileChanged( const QVariant& ) ),
// SettingsManager::Vlmc );
// QObject::connect( qApp,
// SIGNAL( aboutToQuit() ),
// this,
// SLOT( deleteLater() ) );
// QString logFile = setVal.toString();
// if ( logFile.isEmpty() == false )
// {
// m_logFile = new QFile( logFile );
// m_logFile->open( QFile::WriteOnly | QFile::Truncate );
// }
}
VlmcDebug::~VlmcDebug()
......@@ -100,9 +100,9 @@ void VlmcDebug::vlmcMessageHandler( QtMsgType type, const char* msg )
VlmcDebug::getInstance()->m_logFile->write( msg );
VlmcDebug::getInstance()->m_logFile->write( "\n" );
}
if ( type != QtFatalMsg
&& type < SettingsManager::getInstance()->value( "private/LogLevel", QtDebugMsg, SettingsManager::Vlmc ).toInt() )
return ;
// if ( type != QtFatalMsg
// && type < SettingsManager::getInstance()->value( "private/LogLevel", QtDebugMsg, SettingsManager::Vlmc ).toInt() )
// return ;
switch ( type )
{
case QtDebugMsg:
......
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