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

Remove differenciation between project settings & preferences.

Both are now using a different instance of the Settings class, in
Core & Project, depending on the settings type
parent dc3c2856
......@@ -34,8 +34,7 @@ KeyboardShortcutHelper::KeyboardShortcutHelper( const QString& name, QWidget* pa
QString set = VLMC_GET_STRING( name );
setKey( QKeySequence( set ) );
Core::getInstance()->settings()->watchValue( name, this,
SLOT( shortcutUpdated( const QVariant& ) ),
SettingsManager::Vlmc );
SLOT( shortcutUpdated( const QVariant& ) ) );
}
KeyboardShortcutHelper::KeyboardShortcutHelper( const QString& name, QAction *action,
......@@ -47,8 +46,7 @@ KeyboardShortcutHelper::KeyboardShortcutHelper( const QString& name, QAction *ac
QString set = VLMC_GET_STRING( name );
action->setShortcut( set );
Core::getInstance()->settings()->watchValue( name, this,
SLOT( shortcutUpdated( const QVariant& ) ),
SettingsManager::Vlmc );
SLOT( shortcutUpdated( const QVariant& ) ) );
}
void
......
......@@ -26,6 +26,7 @@
#include <QSettings>
#include <QXmlStreamWriter>
#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
# include <QStandardPaths>
#else
......
......@@ -88,7 +88,7 @@ MainWindow::MainWindow( Backend::IBackend* backend, QWidget *parent ) :
//All preferences have been created: restore them:
loadVlmcPreferences();
Core::getInstance()->settings()->setValue( "private/VlmcVersion", PROJECT_VERSION_MAJOR, SettingsManager::Vlmc );
Core::getInstance()->settings()->setValue( "private/VlmcVersion", PROJECT_VERSION_MAJOR );
// GUI
DockWidgetManager::getInstance( this )->setMainWindow( this );
......@@ -275,9 +275,7 @@ MainWindow::initVlmcPreferences()
Core::getInstance()->settings()->watchValue( "vlmc/VLMCLang",
LanguageHelper::getInstance(),
SLOT( languageChanged( const QVariant& ) ),
SettingsManager::Vlmc );
SLOT( languageChanged( const QVariant& ) ) );
//Setup VLMC General Preferences...
VLMC_CREATE_PREFERENCE_BOOL( "vlmc/ConfirmDeletion", true,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Confirm clip deletion"),
......@@ -352,7 +350,7 @@ void MainWindow::loadVlmcPreferences()
QSettings s;
s.clear();
}
Core::getInstance()->settings()->setValue( "private/VlmcVersion", PROJECT_VERSION_MAJOR, SettingsManager::Vlmc );
Core::getInstance()->settings()->setValue( "private/VlmcVersion", PROJECT_VERSION_MAJOR );
}
void
......@@ -366,7 +364,7 @@ MainWindow::loadVlmcPreferencesCategory( const QString &subPart )
QVariant value = s.value( key );
QString fullKey = subPart + "/" + key;
vlmcDebug() << "Loading" << fullKey << "=>" << value;
Core::getInstance()->settings()->setValue( fullKey, value, SettingsManager::Vlmc );
Core::getInstance()->settings()->setValue( fullKey, value );
}
}
......@@ -543,15 +541,11 @@ MainWindow::initToolbar()
void
MainWindow::createGlobalPreferences()
{
m_globalPreferences = new SettingsDialog( SettingsManager::Vlmc, this );
m_globalPreferences->addCategory( "vlmc", QT_TRANSLATE_NOOP( "Settings", "General" ), SettingsManager::Vlmc,
QIcon( ":/images/vlmc" ) );
m_globalPreferences->addCategory( "keyboard", QT_TRANSLATE_NOOP( "Settings", "Keyboard" ), SettingsManager::Vlmc,
QIcon( ":/images/keyboard" ) );
m_globalPreferences->addCategory( "youtube", QT_TRANSLATE_NOOP( "Settings", "YouTube" ), SettingsManager::Vlmc,
QIcon( ":/images/youtube" ) );
m_globalPreferences->addCategory( "network", QT_TRANSLATE_NOOP( "Settings", "Network" ), SettingsManager::Vlmc,
QIcon( ":/images/network" ) );
m_globalPreferences = new SettingsDialog( Core::getInstance()->settings(), tr( "VLMC Preferences" ), this );
m_globalPreferences->addCategory( "vlmc", QT_TRANSLATE_NOOP( "Settings", "General" ), QIcon( ":/images/vlmc" ) );
m_globalPreferences->addCategory( "keyboard", QT_TRANSLATE_NOOP( "Settings", "Keyboard" ), QIcon( ":/images/keyboard" ) );
m_globalPreferences->addCategory( "youtube", QT_TRANSLATE_NOOP( "Settings", "YouTube" ), QIcon( ":/images/youtube" ) );
m_globalPreferences->addCategory( "network", QT_TRANSLATE_NOOP( "Settings", "Network" ), QIcon( ":/images/network" ) );
}
void
......@@ -576,13 +570,10 @@ MainWindow::loadGlobalProxySettings()
void
MainWindow::createProjectPreferences()
{
m_projectPreferences = new SettingsDialog( SettingsManager::Project, this );
m_projectPreferences->addCategory( "general", QT_TRANSLATE_NOOP( "Settings", "General" ), SettingsManager::Project,
QIcon( ":/images/vlmc" ) );
m_projectPreferences->addCategory( "video", QT_TRANSLATE_NOOP( "Settings", "Video" ), SettingsManager::Project,
QIcon( ":/images/video" ) );
m_projectPreferences->addCategory( "audio", QT_TRANSLATE_NOOP( "Settings", "Audio" ), SettingsManager::Project,
QIcon( ":/images/audio" ) );
m_projectPreferences = new SettingsDialog( Project::getInstance()->settings(), tr( "Project preferences" ), this );
m_projectPreferences->addCategory( "general", QT_TRANSLATE_NOOP( "Settings", "General" ), QIcon( ":/images/vlmc" ) );
m_projectPreferences->addCategory( "video", QT_TRANSLATE_NOOP( "Settings", "Video" ), QIcon( ":/images/video" ) );
m_projectPreferences->addCategory( "audio", QT_TRANSLATE_NOOP( "Settings", "Audio" ), QIcon( ":/images/audio" ) );
}
void
......@@ -795,13 +786,13 @@ MainWindow::saveSettings()
clearTemporaryFiles();
if ( pm->askForSaveIfModified() )
{
SettingsManager* sm = Core::getInstance()->settings();
Settings* settings = Core::getInstance()->settings();
// Save the current geometry
sm->setValue( "private/MainWindowGeometry", saveGeometry(), SettingsManager::Vlmc );
settings->setValue( "private/MainWindowGeometry", saveGeometry() );
// Save the current layout
sm->setValue( "private/MainWindowState", saveState(), SettingsManager::Vlmc );
sm->setValue( "private/CleanQuit", true, SettingsManager::Vlmc );
sm->save();
settings->setValue( "private/MainWindowState", saveState() );
settings->setValue( "private/CleanQuit", true );
settings->save();
return true;
}
return false;
......@@ -873,7 +864,7 @@ MainWindow::restoreSession()
QMessageBox::warning( this, tr( "Can't restore project" ), tr( "VLMC didn't manage to restore your project. We apology for the inconvenience" ) );
}
}
Core::getInstance()->settings()->setValue( "private/CleanQuit", true, SettingsManager::Vlmc );
Core::getInstance()->settings()->setValue( "private/CleanQuit", true );
return ret;
}
......
......@@ -289,8 +289,7 @@ ImportController::collapseAllButCurrentPath()
void
ImportController::saveCurrentPath()
{
Core::getInstance()->settings()->setValue( "private/ImportPreviouslySelectPath",
m_currentlyWatchedDir, SettingsManager::Vlmc );
Core::getInstance()->settings()->setValue( "private/ImportPreviouslySelectPath", m_currentlyWatchedDir );
}
void
......
......@@ -54,7 +54,6 @@ GUIProjectManager::GUIProjectManager()
"at a specified interval" ) );
Core::getInstance()->settings()->watchValue( "vlmc/AutomaticBackup", this,
SLOT( automaticSaveEnabledChanged(QVariant) ),
SettingsManager::Vlmc,
Qt::QueuedConnection );
VLMC_CREATE_PREFERENCE_INT( "vlmc/AutomaticBackupInterval", 5,
QT_TRANSLATE_NOOP( "PreferenceWidget", "Automatic save interval" ),
......@@ -62,13 +61,10 @@ GUIProjectManager::GUIProjectManager()
"between two automatic save" ) );
Core::getInstance()->settings()->watchValue( "vlmc/AutomaticBackupInterval", this,
SLOT( automaticSaveIntervalChanged(QVariant) ),
SettingsManager::Vlmc,
Qt::QueuedConnection );
automaticSaveEnabledChanged( VLMC_GET_BOOL( "vlmc/AutomaticBackup" ) );
Core::getInstance()->settings()->watchValue( "vlmc/ProjectName", this,
SLOT(projectNameChanged(QVariant) ),
SettingsManager::Project );
Project::getInstance()->settings()->watchValue( "vlmc/ProjectName", this,
SLOT(projectNameChanged(QVariant) ) );
connect( Project::getInstance()->undoStack(), SIGNAL( cleanChanged( bool ) ),
this, SLOT( cleanChanged( bool ) ) );
connect( this, SIGNAL( projectSaved() ),
......@@ -150,8 +146,7 @@ GUIProjectManager::createNewProjectFile( bool saveAs )
outputFileName += ".vlmc";
m_projectFile = new QFile( outputFileName );
QFileInfo fInfo( outputFileName );
Core::getInstance()->settings()->setValue( "vlmc/Workspace",
fInfo.absolutePath(), SettingsManager::Project);
Project::getInstance()->settings()->setValue( "vlmc/Workspace", fInfo.absolutePath() );
appendToRecentProject( projectName() );
if ( relocate == true )
......
......@@ -40,18 +40,17 @@
#include <QHashIterator>
#include <QEvent>
PreferenceWidget::PreferenceWidget( const QString &name, const char *label, SettingsManager::Type type,
PreferenceWidget::PreferenceWidget( const QString &name, const char *label, Settings* settings,
QWidget *parent ) :
QScrollArea( parent ),
m_category( label )
{
QWidget *container = new QWidget( this );
SettingsManager::SettingList settings =
Core::getInstance()->settings()->group( name, type );
Settings::SettingList settingList = settings->group( name );
QFormLayout *layout = new QFormLayout( container );
layout->setFieldGrowthPolicy( QFormLayout::AllNonFixedFieldsGrow );
foreach ( SettingValue* s, settings )
foreach ( SettingValue* s, settingList )
{
//Do not display private variables
if ( ( s->flags() & SettingValue::Private ) != 0 )
......
......@@ -40,8 +40,7 @@ class PreferenceWidget : public QScrollArea
Q_OBJECT
public:
typedef QList<ISettingsCategoryWidget*> SettingsList;
PreferenceWidget( const QString &name, const char* category, SettingsManager::Type type,
QWidget* parent = 0 );
PreferenceWidget(const QString &name, const char* category, Settings *settings, QWidget* parent = 0 );
virtual ~PreferenceWidget() {}
virtual bool save();
......
......@@ -37,9 +37,10 @@
#include <QScrollArea>
#include <QStackedLayout>
SettingsDialog::SettingsDialog( SettingsManager::Type type, QWidget *parent ) :
SettingsDialog::SettingsDialog(Settings *settings, const QString &title, QWidget *parent ) :
QDialog( parent ),
m_type( type )
m_settings( settings ),
m_windowTitle( title )
{
setMinimumHeight( 400 );
setMinimumWidth( 600 );
......@@ -62,11 +63,9 @@ SettingsDialog::SettingsDialog( SettingsManager::Type type, QWidget *parent ) :
}
void
SettingsDialog::addCategory( const QString &name, const char *label,
SettingsManager::Type type,
const QIcon &icon )
SettingsDialog::addCategory( const QString &name, const char *label, const QIcon &icon )
{
PreferenceWidget *pWidget = new PreferenceWidget( name, label, type, this );
PreferenceWidget *pWidget = new PreferenceWidget( name, label, m_settings, this );
m_stackedLayout->addWidget( pWidget );
......@@ -130,8 +129,7 @@ SettingsDialog::buttonClicked( QAbstractButton *button )
}
}
//If we're handling vlmc preferences, save the value in the QSettings
if ( m_type == SettingsManager::Vlmc )
Core::getInstance()->settings()->save();
m_settings->save();
}
case QDialogButtonBox::Cancel:
{
......@@ -178,9 +176,6 @@ SettingsDialog::retranslateUi()
if ( text.length() >= 1 )
text[0] = text[0].toUpper();
m_title->setText( text );
if ( m_type == SettingsManager::Project )
setWindowTitle( tr( "Project preferences" ) );
else
setWindowTitle( tr( "VLMC Settings" ) );
setWindowTitle( m_windowTitle );
m_panel->retranslate();
}
......@@ -42,14 +42,13 @@ class PreferenceWidget;
class SettingsDialog : public QDialog
{
Q_OBJECT
Q_DISABLE_COPY( SettingsDialog )
Q_DISABLE_COPY( SettingsDialog );
public:
SettingsDialog( SettingsManager::Type type, QWidget *parent = 0 );
SettingsDialog(Settings *settings, const QString& title, QWidget *parent = 0 );
void addCategory( const QString& categorieName,
const char *label,
SettingsManager::Type type,
const QIcon &icon );
protected:
......@@ -63,7 +62,8 @@ class SettingsDialog : public QDialog
Panel *m_panel;
QLabel *m_title;
QStackedLayout *m_stackedLayout;
SettingsManager::Type m_type;
Settings* m_settings;
QString m_windowTitle;
public slots:
void switchWidget( int index );
......
......@@ -101,8 +101,7 @@ TracksScene::askRemoveSelectedItems()
return ;
if ( clicked == always )
{
Core::getInstance()->settings()->setValue( "vlmc/ConfirmDeletion",
false, SettingsManager::Vlmc );
Core::getInstance()->settings()->setValue( "vlmc/ConfirmDeletion", false );
}
}
......
......@@ -97,19 +97,19 @@ ProjectWizard::accept()
//If he was creating a project, the current page will be the video/audio settings one.
if ( currentId() == Page_Video )
{
SettingsManager *sManager = Core::getInstance()->settings();
Settings* preferences = Core::getInstance()->settings();
Settings* projectPreferences = Project::getInstance()->settings();
GUIProjectManager::getInstance()->newProject( field( "projectName" ).toString(), field( "projectPath" ).toString() );
//Save the project workspace
sManager->setValue( "vlmc/Workspace", field( "projectPath" ), SettingsManager::Project );
//And the default vlmc workspace
sManager->setValue( "vlmc/DefaultProjectLocation", field( "workspace" ), SettingsManager::Vlmc );
sManager->setValue( "video/VLMCOutputFPS", field( "fps" ), SettingsManager::Project );
sManager->setValue( "video/VideoProjectHeight", field( "height" ), SettingsManager::Project );
sManager->setValue( "video/VideoProjectWidth", field( "width" ), SettingsManager::Project );
sManager->setValue( "video/AspectRatio", field( "aspectratio" ), SettingsManager::Project );
sManager->setValue( "audio/AudioSampleRate", field( "samplerate" ), SettingsManager::Project );
sManager->setValue( "audio/NbChannels", field( "samplerate" ), SettingsManager::Project );
preferences->setValue( "vlmc/DefaultProjectLocation", field( "workspace" ) );
projectPreferences->setValue( "vlmc/Workspace", field( "projectPath" ) );
projectPreferences->setValue( "video/VLMCOutputFPS", field( "fps" ) );
projectPreferences->setValue( "video/VideoProjectHeight", field( "height" ) );
projectPreferences->setValue( "video/VideoProjectWidth", field( "width" ) );
projectPreferences->setValue( "video/AspectRatio", field( "aspectratio" ) );
projectPreferences->setValue( "audio/AudioSampleRate", field( "samplerate" ) );
projectPreferences->setValue( "audio/NbChannels", field( "samplerate" ) );
}
QDialog::accept();
}
......
......@@ -214,5 +214,5 @@ WelcomePage::setProjectPath( const QString& path )
void
WelcomePage::hideWizardAtStartup( bool hidden )
{
Core::getInstance()->settings()->setValue( "private/ShowWizardStartup", !hidden, SettingsManager::Vlmc );
Core::getInstance()->settings()->setValue( "private/ShowWizardStartup", !hidden );
}
......@@ -22,6 +22,13 @@
#include "Core.h"
#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
# include <QStandardPaths>
#else
# include <QDesktopServices>
#endif
#include <Backend/IBackend.h>
#include <EffectsEngine/EffectsEngine.h>
#include <Settings/SettingsManager.h>
......@@ -32,7 +39,11 @@ Core::Core()
m_backend = Backend::getBackend();
m_effectsEngine = new EffectsEngine;
m_logger = new VlmcLogger;
m_settings = new SettingsManager;
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
m_settings = new Settings( QStandardPaths::writableLocation( QStandardPaths::ConfigLocation ) );
#else
m_settings = new Settings( QDesktopServices::storageLocation( QDesktopServices::ConfigLocation ) ),
#endif
}
Core::~Core()
......@@ -61,7 +72,7 @@ Core::logger()
return m_logger;
}
SettingsManager*
Settings*
Core::settings()
{
return m_settings;
......
......@@ -25,7 +25,7 @@
class EffectsEngine;
class NotificationZone;
class SettingsManager;
class Settings;
class VlmcLogger;
namespace Backend
......@@ -40,7 +40,7 @@ class Core : public Singleton<Core>
public:
Backend::IBackend* backend();
EffectsEngine* effectsEngine();
SettingsManager* settings();
Settings* settings();
VlmcLogger* logger();
private:
......@@ -48,8 +48,7 @@ class Core : public Singleton<Core>
~Core();
Backend::IBackend* m_backend;
EffectsEngine* m_effectsEngine;
//FIXME: This should only be applications settings.
SettingsManager* m_settings;
Settings* m_settings;
VlmcLogger* m_logger;
friend class Singleton<Core>;
......
......@@ -27,20 +27,23 @@
#include "Library/Library.h"
#include "Workflow/MainWorkflow.h"
#include "Project/Workspace.h"
#include "Settings/SettingsManager.h"
Project::Project()
{
m_library = new Library;
m_settings = new Settings( QString() );
m_undoStack = new QUndoStack;
m_workflow = new MainWorkflow;
m_undoStack = new QUndoStack();
m_workspace = new Workspace;
}
Project::~Project()
{
delete m_workspace;
delete m_undoStack;
delete m_workflow;
delete m_undoStack;
delete m_settings;
delete m_library;
}
......@@ -62,6 +65,12 @@ Project::undoStack()
return m_undoStack;
}
Settings*
Project::settings()
{
return m_settings;
}
Workspace*
Project::workspace()
{
......
......@@ -29,6 +29,7 @@ class QUndoStack;
class Library;
class MainWorkflow;
class Settings;
class Workspace;
class Project : public Singleton<Project>
......@@ -38,16 +39,17 @@ private:
~Project();
public:
// Insert settings here
Library* library();
MainWorkflow* workflow();
QUndoStack* undoStack();
Settings* settings();
Workspace* workspace();
private:
Library* m_library;
MainWorkflow* m_workflow;
QUndoStack* m_undoStack;
Settings* m_settings;
Workspace* m_workspace;
friend class Singleton<Project>;
......
......@@ -159,8 +159,8 @@ ProjectManager::loadProject( const QString& fileName )
QDomElement root = m_domDocument->documentElement();
//Load settings first, as it contains some informations about the workspace.
Core::getInstance()->settings()->load( root );
Core::getInstance()->settings()->setValue( "vlmc/Workspace", fInfo.absolutePath(), SettingsManager::Project );
Project::getInstance()->settings()->load( root );
Project::getInstance()->settings()->setValue( "vlmc/Workspace", fInfo.absolutePath() );
Timeline::getInstance()->renderer()->loadProject( root );
Project::getInstance()->library()->loadProject( root );
}
......@@ -171,7 +171,7 @@ ProjectManager::removeProject( const QString& project )
// Remove all occurence of fileName
m_recentsProjects.removeAll( project );
Core::getInstance()->settings()->setValue( SETTINGS_RECENTS, m_recentsProjects, SettingsManager::Vlmc );
Core::getInstance()->settings()->setValue( SETTINGS_RECENTS, m_recentsProjects );
}
void
......@@ -209,7 +209,7 @@ ProjectManager::emergencyBackup()
else
name = createAutoSaveOutputFileName( QDir::currentPath() + "/unsavedproject" );
__saveProject( name );
Core::getInstance()->settings()->setValue( SETTINGS_BACKUP, name, SettingsManager::Vlmc );
Core::getInstance()->settings()->setValue( SETTINGS_BACKUP, name );
}
bool
......@@ -234,7 +234,7 @@ ProjectManager::appendToRecentProject( const QString& projectName )
while ( m_recentsProjects.count() > 15 )
m_recentsProjects.removeLast();
Core::getInstance()->settings()->setValue( SETTINGS_RECENTS, m_recentsProjects, SettingsManager::Vlmc );
Core::getInstance()->settings()->setValue( SETTINGS_RECENTS, m_recentsProjects );
}
QString
......
......@@ -24,79 +24,35 @@
#include "SettingValue.h"
#include "Tools/VlmcDebug.h"
#include <QSettings>
#include <QByteArray>
#include <QFile>
#include <QWriteLocker>
#include <QReadLocker>
#include <QStringList>
#include <QXmlStreamWriter>
#include <QDomElement>
bool
SettingsManager::setValue( const QString &key,
const QVariant &value,
SettingsManager::Type type )
{
if ( type == Project )
{
if ( m_xmlSettings.setValue( key, value ) )
return true;
}
else// ( type == Vlmc && m_classicSettings.contains( key) == true )
{
SettingValue* v = m_classicSettings.value( key );
if ( v != NULL )
{
v->set( value );
if ( v->flags().testFlag( SettingValue::Runtime ) )
return true;
QSettings sett;
sett.setFallbacksEnabled( false );
sett.setValue( key, value );
sett.sync();
return true;
}
}
vlmcWarning() << "Setting" << key << "does not exist.";
Q_ASSERT_X( false, __FILE__, "set value without a created variable" );
return false;
}
SettingValue*
SettingsManager::value( const QString &key,
SettingsManager::Type type )
Settings::Settings(const QString &settingsFile)
: m_settingsFile( NULL )
{
SettingValue* result = NULL;
if ( type == Project )
result = m_xmlSettings.value( key );
else
result = m_classicSettings.value( key );
Q_ASSERT_X( result != NULL, __FILE__, "get value without a created variable" );
return result;
if ( settingsFile.isEmpty() == false )
m_settingsFile = new QFile( settingsFile );
}
SettingsManager::SettingList
SettingsManager::group( const QString &groupName, SettingsManager::Type type )
Settings::~Settings()
{
if ( type == Project )
return m_xmlSettings.group( groupName );
else if ( type == Vlmc )
return m_classicSettings.group( groupName );
Q_ASSERT_X( false, __FILE__, "Unknown setting type" );
return SettingList();
delete m_settingsFile;
}
bool
SettingsManager::watchValue( const QString &key,
QObject* receiver,
const char *method,
SettingsManager::Type type,
Qt::ConnectionType cType )
Settings::watchValue( const QString &key, QObject* receiver, const char *method, Qt::ConnectionType cType )
{
SettingValue* s = value( key, type );
SettingValue* s = value( key );
if ( s != NULL )
{
connect( s, SIGNAL( changed( const QVariant& ) ),
QObject::connect( s, SIGNAL( changed( const QVariant& ) ),
receiver, method , cType );
return true;
}
......@@ -105,38 +61,19 @@ SettingsManager::watchValue( const QString &key,
}
void
SettingsManager::save() const
{
m_classicSettings.lockForRead();
QSettings sett;
sett.setFallbacksEnabled( false );
SettingsContainer::SettingMap::const_iterator it = m_classicSettings.settings().begin();
SettingsContainer::SettingMap::const_iterator ed = m_classicSettings.settings().end();
for ( ; it != ed; ++it )
{
if ( ( (*it)->flags() & SettingValue::Private ) != 0 )
continue ;
sett.setValue( (*it)->key(), (*it)->get() );
}
sett.sync();
}
void
SettingsManager::save( QXmlStreamWriter& project ) const
Settings::save( QXmlStreamWriter& project ) const
{
m_xmlSettings.lockForRead();
QReadLocker lock( &m_rwLock );
SettingsContainer::SettingMap::const_iterator it = m_xmlSettings.settings().begin();
SettingsContainer::SettingMap::const_iterator end = m_xmlSettings.settings().end();
SettingMap::const_iterator it = m_settings.begin();
SettingMap::const_iterator end = m_settings.end();
project.writeStartElement( "project" );
project.writeStartElement( "settings" );
for ( ; it != end; ++it )
{
if ( ( (*it)->flags() & SettingValue::Private ) != 0 )
if ( ( (*it)->flags() & SettingValue::Runtime ) != 0 )
continue ;
project.writeStartElement( "property" );
project.writeStartElement( "setting" );
project.writeAttribute( "key", (*it)->key() );
project.writeAttribute( "value", (*it)->get().toString() );
project.writeEndElement();
......@@ -145,16 +82,15 @@ SettingsManager::save( QXmlStreamWriter& project ) const
}
bool
SettingsManager::load( const QDomElement &root )
Settings::load( const QDomElement &root )
{
//For now it only handle a project node.
QDomElement element = root.firstChildElement( "project" );
QDomElement element = root.firstChildElement( "settings" );
if ( element.isNull() == true )
{
vlmcWarning() << "Invalid settings node";
return false ;
}
QDomElement s = element.firstChildElement();
QDomElement s = element.firstChildElement( "setting" );
while ( s.isNull() == false )
{
QString key = s.attribute( "key" );
......@@ -163,31 +99,28 @@ SettingsManager::load( const QDomElement &root )
if ( key.isEmpty() == true || value.isEmpty() == true )
vlmcWarning() << "Invalid setting node.";
else
if ( setValue( key, value, SettingsManager::Project ) == false )
if ( setValue( key, value ) == false )
vlmcWarning() << "Loaded invalid project setting:" << key;
s = s.nextSiblingElement();
}
return true;
}
SettingValue*
SettingsManager::createVar( SettingValue::Type type, const QString &key,
const QVariant &defaultValue, const char *name,
const char *desc, SettingsManager::Type varType /*= Vlmc*/,
SettingValue::Flags flags /*= SettingValue::Nothing*/ )
void
Settings::save() const
{
SettingValue *val = NULL;
if ( varType == Vlmc )
val = m_classicSettings.createVar( type, key, defaultValue, name, desc, flags );
else if ( varType == Project )
val = m_xmlSettings.createVar( type, key, defaultValue, name, desc, flags );
Q_ASSERT_X( val != NULL, __FILE__, "creating an already created variable" );
return val;
if ( m_settingsFile == NULL )
return ;
QByteArray settingsContent;
QXmlStreamWriter streamWriter( &settingsContent );
save( streamWriter );
m_settingsFile->open( QFile::WriteOnly );
m_settingsFile->write( settingsContent );
m_settingsFile->close();
}
bool
SettingsManager::SettingsContainer::setValue(const QString &key, const QVariant &value)
Settings::setValue(const QString &key, const QVariant &value)
{
SettingMap::iterator it = m_settings.find( key );
if ( it != m_settings.end() )
......@@ -199,7 +132,7 @@ SettingsManager::SettingsContainer::setValue(const QString &key, const QVariant
}
SettingValue*
SettingsManager::SettingsContainer::value(const QString &key)
Settings::value(const QString &key)
{
QReadLocker lock( &m_rwLock );
......@@ -210,7 +143,7 @@ SettingsManager::SettingsContainer::value(const QString &key)
}
SettingValue*
SettingsManager::SettingsContainer::createVar(SettingValue::Type type, const QString &key, const QVariant &defaultValue, const char *name, const char *desc, SettingValue::Flags flags)
Settings::createVar(SettingValue::Type type, const QString &key,