Load settings.

This commit is contained in:
Teo Mrnjavac 2014-06-12 18:47:50 +02:00
parent 4e14ec7834
commit 1f98c3efae
4 changed files with 133 additions and 6 deletions

View File

@ -20,7 +20,7 @@
#include "CalamaresWindow.h" #include "CalamaresWindow.h"
#include "CalamaresVersion.h" #include "CalamaresVersion.h"
#include "Settings.h"
#include "utils/CalamaresUtils.h" #include "utils/CalamaresUtils.h"
#include "utils/Logger.h" #include "utils/Logger.h"
@ -48,6 +48,8 @@ CalamaresApplication::init()
setQuitOnLastWindowClosed( false ); setQuitOnLastWindowClosed( false );
initSettings();
initBranding(); initBranding();
setWindowIcon( QIcon( "from branding" ) ); setWindowIcon( QIcon( "from branding" ) );
@ -63,7 +65,7 @@ CalamaresApplication::init()
CalamaresApplication::~CalamaresApplication() CalamaresApplication::~CalamaresApplication()
{ {
tDebug( LOGVERBOSE ) << "Shutting down Calamares..."; cDebug( LOGVERBOSE ) << "Shutting down Calamares...";
// if ( JobQueue::instance() ) // if ( JobQueue::instance() )
// JobQueue::instance()->stop(); // JobQueue::instance()->stop();
@ -72,7 +74,7 @@ CalamaresApplication::~CalamaresApplication()
// delete JobQueue::instance(); // 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 void
CalamaresApplication::initBranding() CalamaresApplication::initBranding()
{ {

View File

@ -35,6 +35,7 @@ public:
void init(); void init();
static CalamaresApplication* instance(); static CalamaresApplication* instance();
void initSettings();
void initBranding(); void initBranding();
void initPlugins(); void initPlugins();
void initJobQueue(); void initJobQueue();

View File

@ -17,8 +17,109 @@
*/ */
#include "Settings.h" #include "Settings.h"
#include "utils/CalamaresUtils.h"
#include "utils/Logger.h"
#include <QDir>
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
namespace Calamares
{
Settings* Settings::s_instance = 0;
Settings*
Settings::instance()
{
return s_instance;
}
Settings::Settings( QObject* parent ) Settings::Settings( QObject* parent )
: 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;
}
} }

View File

@ -20,20 +20,36 @@
#define SETTINGS_H #define SETTINGS_H
#include <QObject> #include <QObject>
#include <QStringList>
// Settings::instance() ? namespace Calamares
{
class Settings : public QObject class Settings : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit Settings( QObject *parent = 0 ); explicit Settings( QObject *parent = 0 );
static Settings* instance();
//TODO: load from JSON then emit ready //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 #endif // SETTINGS_H