Commit df1e2a1d authored by Clement CHAVANCE's avatar Clement CHAVANCE
Browse files

Merge branch 'kinder_settings_refactor'

Conflicts:
	src/Configuration/SettingsManager.h
	src/GUI/MainWindow.cpp
	src/GUI/Settings.cpp
	vlmc.pro
parents 15621fbd 2c556d60
#include "SettingsManager.h"
#include "ProjectSettingsDefault.h"
void ProjectSettingsDefault::load( const QString& part )
{
SettingsManager::getInstance()->addNewSettingsPart( part );
ProjectSettingsDefault::loadAudioDefaults( part );
ProjectSettingsDefault::loadVideoDefaults( part );
ProjectSettingsDefault::loadProjectDefaults( part );
return ;
}
void ProjectSettingsDefault::loadAudioDefaults( const QString& part )
{
SettingsManager* setMan = SettingsManager::getInstance();
QVariant defaultSampleRate = 0;
setMan->setValue( part, "AudioSampleRate", defaultSampleRate );
return ;
}
void ProjectSettingsDefault::loadVideoDefaults( const QString& part )
{
SettingsManager* settingsMan = SettingsManager::getInstance();
QVariant defaultProjectFPS = 25;
QVariant defaultProjectHeight = 800;
QVariant defaultProjectWidth = 600;
settingsMan->setValue( part,
"VideoProjectFPS",
defaultProjectFPS );
settingsMan->setValue( part,
"VideoProjectHeight",
defaultProjectHeight );
settingsMan->setValue( part,
"VideoProjectWidth",
defaultProjectWidth );
return ;
}
void ProjectSettingsDefault::loadProjectDefaults( const QString& part )
{
SettingsManager* setMan = SettingsManager::getInstance();
QVariant defaultName = "project";
QVariant defaultPath = "./";
setMan->setValue( part, "ProjectName", defaultName );
setMan->setValue( part, "ProjectDirectory", defaultPath );
return ;
}
#ifndef PROJECTSETTINGSDEFAULT_H
#define PROJECTSETTINGSDEFAULT_H
class ProjectSettingsDefault
{
public:
static void load( const QString& part );
private:
static void loadAudioDefaults( const QString& part );
static void loadVideoDefaults( const QString& part );
static void loadProjectDefaults( const QString& part );
private:
ProjectSettingsDefault();
~ProjectSettingsDefault();
ProjectSettingsDefault( const ProjectSettingsDefault & );
ProjectSettingsDefault& operator = ( const ProjectSettingsDefault& );
};
#endif
......@@ -25,9 +25,14 @@
#include <QDomNamedNodeMap>
#include <QDomNodeList>
#include <QtDebug>
#include <QWriteLocker>
#include <QReadLocker>
#include <QTextStream>
#include "SettingsManager.h"
#include "VLMCSettingsDefault.h"
#include "ProjectSettingsDefault.h"
SettingsManager::SettingsManager( QObject* parent )
: QObject( parent )
......@@ -38,70 +43,91 @@ SettingsManager::~SettingsManager()
{
}
void SettingsManager::setValues( QHash<QString, QVariant> values )
void SettingsManager::setValues( const QString& part, QHash<QString, QVariant> values )
{
if ( !m_data.contains( part ) )
addNewSettingsPart( part );
m_globalLock.lockForRead();
SettingsPart* sett = m_data[part];
m_globalLock.unlock();
QHash<QString, QVariant>::iterator it = values.begin();
QHash<QString, QVariant>::iterator end = values.end();
m_lock.lockForWrite();
QWriteLocker lock( &sett->m_lock );
for ( ; it != end; ++it )
m_data.insert( it.key(), it.value() );
m_lock.unlock();
sett->m_data.insert( it.key(), it.value() );
return ;
}
void SettingsManager::setValue( const QString& key, QVariant& value )
void SettingsManager::setValue( const QString& part , const QString& key, QVariant& value )
{
m_lock.lockForWrite();
m_data.insert( key, value );
m_lock.unlock();
m_globalLock.lockForRead();
if ( !m_data.contains( part ) )
{
addNewSettingsPart( part );
}
m_globalLock.unlock();
QWriteLocker lock( &m_globalLock );
SettingsPart* tmp = m_data[part];
tmp->m_data.insert( key, value );
return ;
}
const QVariant SettingsManager::getValue( const QString& key ) const
const QVariant& SettingsManager::getValue( const QString& part, const QString& key ) const
{
m_lock.lockForRead();
QVariant value = m_data[key];
m_lock.unlock();
if ( !m_data.contains( part ) )
return getValue( "default", key );
QReadLocker readLock( &m_globalLock );
QReadLocker rdLock( &m_data[part]->m_lock );
QVariant& value = m_data[part]->m_data[key];
qDebug() << "value" << value;
return value;
}
void SettingsManager::saveSettings( QDomDocument& xmlfile, QDomElement& root )
void SettingsManager::saveSettings( const QString& part, QDomDocument& xmlfile, QDomElement& root )
{
m_lock.lockForRead();
m_globalLock.lockForRead();
if ( !m_data.contains( part ) )
{
m_globalLock.unlock();
return ;
}
SettingsPart* sett = m_data[part];
m_globalLock.unlock();
//SAVE SETTINGS TO DomDocument
QHash<QString, QVariant>::iterator it = m_data.begin();
QHash<QString, QVariant>::iterator end = m_data.end();
QDomElement settingsNode = xmlfile.createElement( "settings" );
QReadLocker lock( &sett->m_lock );
QHash<QString, QVariant>::iterator it = sett->m_data.begin();
QHash<QString, QVariant>::iterator end = sett->m_data.end();
QDomElement settingsNode = xmlfile.createElement( part );
for ( ; it != end; ++it )
{
QDomElement elem = xmlfile.createElement( it.key() );
elem.setAttribute( "value", it.value().toString() );
settingsNode.appendChild( elem );
}
m_lock.unlock();
//DEBUG
{
QTextStream stream( stdout );
stream << settingsNode;
}
root.appendChild( settingsNode );
}
void SettingsManager::loadSettings( const QDomElement& settings )
void SettingsManager::loadSettings( const QString& part, const QDomElement& settings )
{
qDebug() << "Loading settings";
if ( settings.isNull() == true || settings.tagName() != "settings" )
if ( settings.isNull() == true || settings.tagName() != "project" )
{
qWarning() << "Invalid settings node";
return ;
}
m_globalLock.lockForRead();
if ( !m_data.contains( part ) )
{
qWarning() << "These settings Does not exists";
return ;
}
SettingsPart* sett = m_data[part];
qDebug() << sett->m_data;
m_globalLock.unlock();
//Loading all the settings
m_lock.lockForWrite();
m_globalLock.lockForWrite();
sett->m_lock.lockForWrite();
QDomNodeList list = settings.childNodes();
int nbChild = list.size();
......@@ -113,10 +139,28 @@ void SettingsManager::loadSettings( const QDomElement& settings )
qWarning() << "Invalid number of attributes for" << list.at( idx ).nodeName();
return ;
}
m_data.insert( list.at( idx ).toElement().tagName(),
sett->m_data.insert( list.at( idx ).toElement().tagName(),
QVariant( attrMap.item( 0 ).nodeValue() ));
}
m_lock.unlock();
sett->m_lock.unlock();
m_globalLock.unlock();
emit settingsLoaded();
}
void SettingsManager::addNewSettingsPart( const QString& name )
{
QReadLocker rLock( &m_globalLock );
if ( !m_data.contains( name ) )
{
rLock.unlock();
QWriteLocker lock( &m_globalLock );
m_data.insert( name, new SettingsPart );
}
}
void SettingsManager::loadDefaultsSettings()
{
VLMCSettingsDefault::load( "default" );
ProjectSettingsDefault::load( "default" );
}
......@@ -33,6 +33,18 @@
#include "QSingleton.hpp"
struct SettingsPart
{
SettingsPart() {}
QHash<QString, QVariant> m_data;
mutable QReadWriteLock m_lock;
bool m_rdOnly;
private:
SettingsPart( const SettingsPart& );
SettingsPart& operator =( const SettingsPart& );
};
class SettingsManager : public QObject, public QSingleton<SettingsManager>
{
......@@ -41,18 +53,20 @@ class SettingsManager : public QObject, public QSingleton<SettingsManager>
friend class QSingleton<SettingsManager>;
public:
void setValues( const QString& part, QHash<QString, QVariant> );
void setValue( const QString& part, const QString& key, QVariant& value );
const QVariant& getValue( const QString& part, const QString& key ) const;
void saveSettings( const QString& part, QDomDocument& xmlfile, QDomElement& root );
void loadSettings( const QString& part, const QDomElement& settings );
void addNewSettingsPart( const QString& name );
static void loadDefaultsSettings();
void setValues( QHash<QString, QVariant> );
void setValue( const QString& key, QVariant& value );
const QVariant getValue( const QString& key ) const;
void saveSettings( QDomDocument& xmlfile, QDomElement& root );
void loadSettings( const QDomElement& settings );
private:
SettingsManager( QObject* parent = 0 );
~SettingsManager();
QHash<QString, QVariant> m_data;
mutable QReadWriteLock m_lock;
QHash<QString, SettingsPart*> m_data;
mutable QReadWriteLock m_globalLock;
signals:
void settingsLoaded();
......
#include <QVariant>
#include "VLMCSettingsDefault.h"
#include "SettingsManager.h"
void VLMCSettingsDefault::load( const QString& part )
{
SettingsManager::getInstance()->addNewSettingsPart( part );
VLMCSettingsDefault::loadVLMCDefaults( part );
VLMCSettingsDefault::loadlanguageDefaults( part );
return ;
}
void VLMCSettingsDefault::loadVLMCDefaults( const QString& part )
{
SettingsManager* settingsMan = SettingsManager::getInstance();
QVariant defaultOutputPFS = "25";
QVariant defaultPreviewFPS = "25";
QVariant defaultTrackNb = "64";
settingsMan->setValue( part,
"VLMCOutPutFPS", defaultOutputPFS );
settingsMan->setValue( part,
"VLMCPreviewFPS",
defaultPreviewFPS );
settingsMan->setValue( part,
"VLMCTracksNb",
defaultTrackNb );
return ;
}
void VLMCSettingsDefault::loadlanguageDefaults( const QString& part )
{
}
#ifndef VLMCSETTINGSDEFAULT_H
#define VLMCSETTINGSDEFAULT_H
class VLMCSettingsDefault
{
public:
static void load( const QString& part );
private:
static void loadVLMCDefaults( const QString& part );
static void loadlanguageDefaults( const QString& part );
private:
VLMCSettingsDefault();
~VLMCSettingsDefault();
VLMCSettingsDefault( const VLMCSettingsDefault& );
VLMCSettingsDefault& operator = ( const VLMCSettingsDefault& );
};
#endif
......@@ -25,25 +25,28 @@
#include "QDebug"
AudioProjectPreferences::AudioProjectPreferences( QWidget *parent )
: PreferenceWidget( parent )
AudioProjectPreferences::AudioProjectPreferences( QWidget *parent )
: PreferenceWidget( parent )
{
m_ui.setupUi( this );
m_ui.setupUi( this );
}
AudioProjectPreferences::~AudioProjectPreferences() { }
void AudioProjectPreferences::load()
{
qDebug() << "Loading preferences : Audio";
int sampleRate = SettingsManager::getInstance()->getValue( "AudioSampleRate" ).toInt();
SettingsManager* setMan = SettingsManager::getInstance();
const QString& part = m_defaults ? "default" : m_settName;
int sampleRate = setMan->getValue( part, "AudioSampleRate" ).toInt();
m_ui.SampleRate->setValue( sampleRate );
return ;
}
void AudioProjectPreferences::save( QHash<QString, QVariant>& settings )
void AudioProjectPreferences::save()
{
settings.insert( "AudioSampleRate", m_ui.SampleRate->value() );
SettingsManager* setMan = SettingsManager::getInstance();
QVariant sampleRate( m_ui.SampleRate->value() );
setMan->setValue( m_settName, "AudioSampleRate", sampleRate );
return ;
}
......@@ -35,7 +35,7 @@ class AudioProjectPreferences : public PreferenceWidget
AudioProjectPreferences( QWidget *parent = 0 );
~AudioProjectPreferences();
void load();
void save( QHash<QString, QVariant>& settings );
void save();
private:
Ui::AudioProjectPreferences m_ui;
};
......
......@@ -50,6 +50,8 @@
#include "ProjectManager.h"
#include "AudioProjectPreferences.h"
#include "VideoProjectPreferences.h"
#include "VLMCSettingsDefault.h"
#include "ProjectSettingsDefault.h"
#include "VLMCPreferences.h"
#include "Import.h"
#include "MediaLibraryWidget.h"
......@@ -61,6 +63,9 @@ MainWindow::MainWindow( QWidget *parent ) :
DockWidgetManager::instance( this )->setMainWindow( this );
initializeDockWidgets();
createStatusBar();
loadDefaults();
VLMCSettingsDefault::load( "default" );
VLMCSettingsDefault::load( "VLMC" );
createGlobalPreferences();
createProjectPreferences();
......@@ -303,7 +308,7 @@ void MainWindow::initializeDockWidgets( void )
void MainWindow::createGlobalPreferences()
{
m_globalPreferences = new Settings( this );
m_globalPreferences = new Settings( false, "VLMC", this );
m_globalPreferences->addWidget("VLMC",
new VLMCPreferences( m_globalPreferences ),
"../images/vlmc.png",
......@@ -313,9 +318,8 @@ void MainWindow::createGlobalPreferences()
void MainWindow::createProjectPreferences()
{
m_projectPreferences = new Settings( );
m_projectPreferences->addWidget( "Project",
m_projectPreferences = new Settings( false, "project", this );
m_projectPreferences->addWidget("Project",
new ProjectPreferences,
":/images/images/vlmc",
"Project settings" );
......@@ -330,6 +334,14 @@ void MainWindow::createProjectPreferences()
m_projectPreferences->build();
}
void MainWindow::loadDefaults()
{
VLMCSettingsDefault::load( "default" );
VLMCSettingsDefault::load( "VLMC" );
ProjectSettingsDefault::load( "default" );
ProjectSettingsDefault::load( "project" );
}
//Private slots definition
void MainWindow::on_actionQuit_triggered()
......@@ -339,7 +351,7 @@ void MainWindow::on_actionQuit_triggered()
void MainWindow::on_actionPreferences_triggered()
{
m_globalPreferences->show();
m_projectPreferences->show();
}
void MainWindow::on_actionAbout_triggered()
......@@ -443,5 +455,5 @@ void MainWindow::on_actionBypass_effects_engine_toggled(bool toggled)
void MainWindow::on_actionProject_Preferences_triggered()
{
m_projectPreferences->show();
m_projectPreferences->show( "project" );
}
......@@ -66,6 +66,7 @@ private:
void createStatusBar();
void createGlobalPreferences();
void createProjectPreferences();
void loadDefaults();
Ui::MainWindow m_ui;
MetaDataManager* m_metaDataManager;
......@@ -75,6 +76,7 @@ private:
PreviewWidget* m_projectPreview;
WorkflowFileRenderer* m_renderer;
Settings* m_globalPreferences;
Settings* m_DefaultProjectPreferences;
Settings* m_projectPreferences;
private slots:
......
......@@ -21,11 +21,32 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <QtDebug>
#include <QWidget>
#include "PreferenceWidget.h"
PreferenceWidget::PreferenceWidget( QWidget* parent )
: QWidget( parent )
: QWidget( parent ),
m_defaults( false ),
m_settName( "" )
{
}
void PreferenceWidget::setDefaults( bool defaults )
{
m_defaults = defaults;
}
void PreferenceWidget::setName( const QString& name )
{
m_settName = name;
}
void PreferenceWidget::loadThemAll( const QString& part,
bool defaults)
{
m_defaults = defaults;
m_settName = part;
load();
}
......@@ -32,12 +32,24 @@
class PreferenceWidget : public QWidget
{
Q_OBJECT
public:
PreferenceWidget( QWidget* parent = 0 );
virtual ~PreferenceWidget() {}
void setDefaults( bool defaults );
void setName( const QString& name );
virtual void load() = 0;
virtual void save( QHash<QString, QVariant>& settings ) = 0;
virtual void save() = 0;
protected:
bool m_defaults;
QString m_settName;
protected slots:
void loadThemAll( const QString& part = "default",
bool defaults = false );
};
#endif
......@@ -40,16 +40,21 @@ ProjectPreferences::~ProjectPreferences() { }
void ProjectPreferences::load()
{
qDebug() << "Loading preferences : Project";
QString Name = SettingsManager::getInstance()->getValue( "ProjectName" ).toString();
QString Dir = SettingsManager::getInstance()->getValue( "ProjectDirectory" ).toString();
SettingsManager* settMan = SettingsManager::getInstance();
const QString& part = m_defaults ? "default" : m_settName;
QString Name = settMan->getValue( part, "ProjectName" ).toString();
QString Dir = settMan->getValue( part, "ProjectDirectory" ).toString();
m_ui.ProjectNameLineEdit->setText( Name );
m_ui.ProjectDirectoryLineEdit->setText( Dir );
}
void ProjectPreferences::save( QHash<QString, QVariant>& settings )
void ProjectPreferences::save()
{
settings.insert( "ProjectName", QVariant( m_ui.ProjectNameLineEdit->text() ) );
settings.insert( "ProjectDirectory", QVariant( m_ui.ProjectDirectoryLineEdit->text() ) );
SettingsManager* settMan = SettingsManager::getInstance();
QVariant name( m_ui.ProjectNameLineEdit->text() );
QVariant dir( m_ui.ProjectDirectoryLineEdit->text() );
settMan->setValue( m_settName, "ProjectName", name );
settMan->setValue( m_settName, "ProjectDirectory", dir );
}
......@@ -36,7 +36,7 @@ class ProjectPreferences : public PreferenceWidget
ProjectPreferences( QWidget* parent = 0 );
virtual ~ProjectPreferences();
void load();
void save( QHash<QString, QVariant>& settings );
void save();
private:
Ui::ProjectPreferences m_ui;
};
......
......@@ -38,23 +38,19 @@
#include "Panel.h"
Settings::Settings( QWidget* parent, Qt::WindowFlags f )
Settings::Settings( bool loadDefaults,
const QString& name,
QWidget* parent,
Qt::WindowFlags f )
: QDialog( parent, f ),
m_currentWidget( NULL )
m_currentWidget( NULL ),
m_defaults( loadDefaults ),
m_name( name )
{
m_panel = new Panel( this );
m_stackedWidgets = new QStackedWidget( this );
QObject::connect( m_panel,
SIGNAL( changePanel( int ) ),
SLOT( switchWidget( int ) ) );
QObject::connect( this,
SIGNAL( widgetSwitched( int ) ),
m_stackedWidgets,