Load settings.

main
Teo Mrnjavac 11 years ago
parent 4e14ec7834
commit 1f98c3efae

@ -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()
{

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

@ -17,8 +17,109 @@
*/
#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 )
: 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;
}
}

@ -20,20 +20,36 @@
#define SETTINGS_H
#include <QObject>
#include <QStringList>
// 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

Loading…
Cancel
Save