diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index ed5f9dd56..e9401ae34 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -20,7 +20,7 @@ #include "CalamaresWindow.h" #include "CalamaresVersion.h" - +#include "Settings.h" #include "utils/CalamaresUtils.h" #include "utils/Logger.h" @@ -48,6 +48,8 @@ CalamaresApplication::init() setQuitOnLastWindowClosed( false ); + initSettings(); + initBranding(); setWindowIcon( QIcon( "from branding" ) ); @@ -63,7 +65,7 @@ CalamaresApplication::init() CalamaresApplication::~CalamaresApplication() { - tDebug( LOGVERBOSE ) << "Shutting down Calamares..."; + cDebug( LOGVERBOSE ) << "Shutting down Calamares..."; // if ( JobQueue::instance() ) // JobQueue::instance()->stop(); @@ -72,7 +74,7 @@ CalamaresApplication::~CalamaresApplication() // delete JobQueue::instance(); - tDebug( LOGVERBOSE ) << "Finished shutdown."; + cDebug( LOGVERBOSE ) << "Finished shutdown."; } @@ -83,6 +85,13 @@ CalamaresApplication::instance() } +void +CalamaresApplication::initSettings() +{ + new Calamares::Settings( this ); +} + + void CalamaresApplication::initBranding() { diff --git a/src/calamares/CalamaresApplication.h b/src/calamares/CalamaresApplication.h index 72616d8d0..7a599e194 100644 --- a/src/calamares/CalamaresApplication.h +++ b/src/calamares/CalamaresApplication.h @@ -35,6 +35,7 @@ public: void init(); static CalamaresApplication* instance(); + void initSettings(); void initBranding(); void initPlugins(); void initJobQueue(); diff --git a/src/calamares/Settings.cpp b/src/calamares/Settings.cpp index 6a8d1a97a..e0fa03cf4 100644 --- a/src/calamares/Settings.cpp +++ b/src/calamares/Settings.cpp @@ -17,8 +17,109 @@ */ #include "Settings.h" +#include "utils/CalamaresUtils.h" +#include "utils/Logger.h" + +#include +#include +#include +#include +#include + +namespace Calamares +{ + +Settings* Settings::s_instance = 0; + +Settings* +Settings::instance() +{ + return s_instance; +} + Settings::Settings( QObject* parent ) : QObject( parent ) { + QFile file( CalamaresUtils::appDataDir().absoluteFilePath( "settings.json" ) ); + if ( file.exists() && file.canReadLine() ) + { + QByteArray ba = file.readAll(); + QJsonParseError* err = 0; + QJsonDocument document = QJsonDocument::fromJson( ba, err ); + if ( !err && !document.isNull() && !document.isEmpty() ) + { + QJsonObject json = document.object(); + + foreach ( const QJsonValue& val, json[ "modules-search" ].toArray() ) + { + if ( !val.isString() || val.toString().isEmpty() ) + continue; + + QString entry = val.toString(); + + if ( entry == "local" ) + { + m_modulesSearchPaths.append( CalamaresUtils::appDataDir().absolutePath() + QDir::separator() + "modules" ); + } + else + { + QDir path( entry ); + if ( path.exists() && path.isReadable() ) + m_modulesSearchPaths.append( path.absolutePath() ); + } + } + + foreach ( const QJsonValue& val, json[ "modules-prepare" ].toArray() ) + { + if ( !val.isString() || val.toString().isEmpty() ) + continue; + + m_viewModulesPrepareList.append( val.toString() ); + } + + foreach ( const QJsonValue& val, json[ "modules-postinstall" ].toArray() ) + { + if ( !val.isString() || val.toString().isEmpty() ) + continue; + + m_viewModulesPostInstallList.append( val.toString() ); + } + } + else + { + cDebug() << "WARNING: Invalid document " << file.fileName() + << " error: " << err->errorString(); + } + } + else + { + cDebug() << "WARNING: Cannot read " << file.fileName(); + } + + s_instance = this; +} + + +QStringList +Settings::modulesSearchPaths() +{ + return m_modulesSearchPaths; +} + + +QStringList +Settings::viewModulesPrepare() +{ + return m_viewModulesPrepareList; +} + + +QStringList +Settings::viewModulesPostInstall() +{ + return m_viewModulesPostInstallList; +} + + } diff --git a/src/calamares/Settings.h b/src/calamares/Settings.h index 5943b34c9..2cbd17104 100644 --- a/src/calamares/Settings.h +++ b/src/calamares/Settings.h @@ -20,20 +20,36 @@ #define SETTINGS_H #include +#include -// Settings::instance() ? +namespace Calamares +{ class Settings : public QObject { Q_OBJECT public: explicit Settings( QObject *parent = 0 ); + + static Settings* instance(); //TODO: load from JSON then emit ready -signals: -public slots: + QStringList modulesSearchPaths(); + + QStringList viewModulesPrepare(); + + QStringList viewModulesPostInstall(); + +private: + static Settings* s_instance; + + QStringList m_modulesSearchPaths; + QStringList m_viewModulesPrepareList; + QStringList m_viewModulesPostInstallList; }; +} + #endif // SETTINGS_H