[vlmc-devel] Fix preferences loading
Hugo Beauzée-Luyssen
git at videolan.org
Sat Mar 29 16:19:43 CET 2014
vlmc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Sat Mar 29 17:10:17 2014 +0200| [f523c2e7df6bffe5d8d0a62f2ecc6e9d09921528] | committer: Hugo Beauzée-Luyssen
Fix preferences loading
> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=f523c2e7df6bffe5d8d0a62f2ecc6e9d09921528
---
src/Gui/MainWindow.cpp | 33 +++------------------------------
src/Gui/MainWindow.h | 2 --
src/Main/Core.cpp | 10 ++++++++--
src/Project/ProjectManager.cpp | 4 +++-
src/Settings/Settings.cpp | 37 +++++++++++++++++++++++++++++++++----
src/Settings/Settings.h | 3 ++-
6 files changed, 49 insertions(+), 40 deletions(-)
diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp
index fa5344f..735e6fb 100644
--- a/src/Gui/MainWindow.cpp
+++ b/src/Gui/MainWindow.cpp
@@ -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
diff --git a/src/Gui/MainWindow.h b/src/Gui/MainWindow.h
index cb5239d..b3f4e4b 100644
--- a/src/Gui/MainWindow.h
+++ b/src/Gui/MainWindow.h
@@ -77,8 +77,6 @@ private:
void createProjectPreferences();
void clearTemporaryFiles();
void initVlmcPreferences();
- void loadVlmcPreferences();
- void loadVlmcPreferencesCategory( const QString& category );
void loadGlobalProxySettings();
void initToolbar();
bool saveSettings();
diff --git a/src/Main/Core.cpp b/src/Main/Core.cpp
index d73f28c..da4f37c 100644
--- a/src/Main/Core.cpp
+++ b/src/Main/Core.cpp
@@ -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()
diff --git a/src/Project/ProjectManager.cpp b/src/Project/ProjectManager.cpp
index 3f29808..0cc1fc5 100644
--- a/src/Project/ProjectManager.cpp
+++ b/src/Project/ProjectManager.cpp
@@ -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 );
diff --git a/src/Settings/Settings.cpp b/src/Settings/Settings.cpp
index 69c5a63..448cab0 100644
--- a/src/Settings/Settings.cpp
+++ b/src/Settings/Settings.cpp
@@ -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()
@@ -61,6 +62,25 @@ Settings::watchValue( const QString &key, QObject* receiver, const char *method,
}
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
{
QReadLocker lock( &m_rwLock );
@@ -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;
diff --git a/src/Settings/Settings.h b/src/Settings/Settings.h
index 10a97e6..025681f 100644
--- a/src/Settings/Settings.h
+++ b/src/Settings/Settings.h
@@ -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;
More information about the Vlmc-devel
mailing list