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

Fix preferences loading

parent b7f0c9fc
......@@ -33,8 +33,6 @@
#include <QUndoStack>
#include <QUrl>
#include <QNetworkProxy>
#include <QSettings>
#include "Main/Core.h"
#include "Main/Project.h"
#include "Library/Library.h"
......@@ -85,10 +83,10 @@ MainWindow::MainWindow( Backend::IBackend* backend, QWidget *parent )
//Preferences
initVlmcPreferences();
//All preferences have been created: restore them:
Core::getInstance()->settings()->load();
Project::getInstance()->projectManager()->setProjectManagerUi( new GUIProjectManager );
//All preferences have been created: restore them:
loadVlmcPreferences();
// GUI
DockWidgetManager::getInstance( this )->setMainWindow( this );
......@@ -288,7 +286,7 @@ MainWindow::initVlmcPreferences()
QT_TRANSLATE_NOOP( "PreferenceWidget", "The temporary folder used by VLMC to process videos." ) );
//Setup VLMC Youtube Preference...
VLMC_CREATE_PREFERENCE_STRING( "youtube/DeveloperKey", "AI39si7FOtp165Vq644xVkuka84TVQNbztQmQ1dC9stheBfh3-33RZaTu7eJkYJzvxp6XNbvlr4M6-ULjXDERFl62WIo6AQIEQ",
VLMC_CREATE_PREFERENCE_STRING( "youtube/DeveloperKey", "",
QT_TRANSLATE_NOOP( "PreferenceWidget", "Youtube Developer Key" ),
QT_TRANSLATE_NOOP( "PreferenceWidget", "VLMC's Youtube Developer Key" ) );
......@@ -329,31 +327,6 @@ MainWindow::initVlmcPreferences()
VLMC_CREATE_PRIVATE_PREFERENCE_BYTEARRAY( "private/MainWindowState", "" );
}
void MainWindow::loadVlmcPreferences()
{
//Load saved preferences :
loadVlmcPreferencesCategory( "private" );
loadVlmcPreferencesCategory( "keyboard" );
loadVlmcPreferencesCategory( "vlmc" );
loadVlmcPreferencesCategory( "youtube" );
loadVlmcPreferencesCategory( "network" );
}
void
MainWindow::loadVlmcPreferencesCategory( const QString &subPart )
{
QSettings s;
s.setFallbacksEnabled( false );
s.beginGroup( subPart );
foreach ( QString key, s.allKeys() )
{
QVariant value = s.value( key );
QString fullKey = subPart + "/" + key;
vlmcDebug() << "Loading" << fullKey << "=>" << value;
Core::getInstance()->settings()->setValue( fullKey, value );
}
}
#undef CREATE_MENU_SHORTCUT
void
......
......@@ -77,8 +77,6 @@ private:
void createProjectPreferences();
void clearTemporaryFiles();
void initVlmcPreferences();
void loadVlmcPreferences();
void loadVlmcPreferencesCategory( const QString& category );
void loadGlobalProxySettings();
void initToolbar();
bool saveSettings();
......
......@@ -22,6 +22,8 @@
#include "Core.h"
#include <QCoreApplication>
#include <QDir>
#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
# include <QStandardPaths>
......@@ -39,11 +41,15 @@ Core::Core()
m_backend = Backend::getBackend();
m_effectsEngine = new EffectsEngine;
m_logger = new VlmcLogger;
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
m_settings = new Settings( QStandardPaths::writableLocation( QStandardPaths::ConfigLocation ) );
QString configDir = QStandardPaths::writableLocation( QStandardPaths::ConfigLocation );
#else
m_settings = new Settings( QDesktopServices::storageLocation( QDesktopServices::DataLocation ) );
QString configDir = QDesktopServices::storageLocation( QDesktopServices::DataLocation );
#endif
QString configPath = configDir + QDir::separator() + qApp->organizationName()
+ QDir::separator() + qApp->applicationName() + ".conf";
m_settings = new Settings( configPath );
}
Core::~Core()
......
......@@ -420,7 +420,9 @@ ProjectManager::loadProject( const QString &fileName )
QDomElement root = m_domDocument->documentElement();
//Load settings first, as it contains some informations about the workspace.
Project::getInstance()->settings()->load( root );
Project::getInstance()->settings()->setSettingsFile( fInfo.absoluteFilePath() );
Project::getInstance()->settings()->load();
//FIXME: This line looks fishy
Project::getInstance()->settings()->setValue( "vlmc/Workspace", fInfo.absolutePath() );
Timeline::getInstance()->renderer()->loadProject( root );
Project::getInstance()->library()->loadProject( root );
......
......@@ -30,6 +30,8 @@
#include <QReadLocker>
#include <QStringList>
#include <QXmlStreamWriter>
#include <QFileInfo>
#include <QDir>
#include <QDomElement>
......@@ -37,8 +39,7 @@
Settings::Settings(const QString &settingsFile)
: m_settingsFile( NULL )
{
if ( settingsFile.isEmpty() == false )
m_settingsFile = new QFile( settingsFile );
setSettingsFile( settingsFile );
}
Settings::~Settings()
......@@ -60,6 +61,25 @@ Settings::watchValue( const QString &key, QObject* receiver, const char *method,
return false;
}
void
Settings::setSettingsFile(const QString &settingsFile)
{
delete m_settingsFile;
if ( settingsFile.isEmpty() == false )
{
QFileInfo fInfo( settingsFile );
if ( fInfo.exists() == false )
{
QDir dir = fInfo.dir();
if ( dir.exists() == false )
dir.mkpath( fInfo.absolutePath() );
}
m_settingsFile = new QFile( settingsFile );
}
else
m_settingsFile = NULL;
}
void
Settings::save( QXmlStreamWriter& project ) const
{
......@@ -82,9 +102,15 @@ Settings::save( QXmlStreamWriter& project ) const
}
bool
Settings::load( const QDomElement &root )
Settings::load()
{
QDomElement element = root.firstChildElement( "settings" );
QDomDocument doc("root");
if ( doc.setContent( m_settingsFile ) == false )
{
vlmcWarning() << "Failed to load settings file" << m_settingsFile->fileName();
return false;
}
QDomElement element = doc.firstChildElement( "settings" );
if ( element.isNull() == true )
{
vlmcWarning() << "Invalid settings node";
......@@ -99,8 +125,11 @@ Settings::load( const QDomElement &root )
if ( key.isEmpty() == true || value.isEmpty() == true )
vlmcWarning() << "Invalid setting node.";
else
{
vlmcDebug() << "Loading" << key << "=>" << value;
if ( setValue( key, value ) == false )
vlmcWarning() << "Loaded invalid project setting:" << key;
}
s = s.nextSiblingElement();
}
return true;
......
......@@ -120,10 +120,11 @@ class Settings
SettingValue* value( const QString &key );
SettingValue* createVar( SettingValue::Type type, const QString &key, const QVariant &defaultValue, const char *name, const char *desc, SettingValue::Flags flags );
SettingList group( const QString &groupName ) const;
bool load( const QDomElement &element );
bool load();
void save() const;
void save( QXmlStreamWriter& project ) const;
bool watchValue( const QString &key, QObject* receiver, const char *method, Qt::ConnectionType cType = Qt::AutoConnection );
void setSettingsFile( const QString& settingsFile );
private:
SettingMap m_settings;
mutable QReadWriteLock m_rwLock;
......
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