Skip to content

Commit 8d8defc

Browse files
committed
Added startup configuration.
1 parent 23104a6 commit 8d8defc

File tree

6 files changed

+79
-43
lines changed

6 files changed

+79
-43
lines changed

application/src/livekeys.cpp

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -349,44 +349,30 @@ void Livekeys::loadInternalPackages(){
349349

350350
m_engine->setPackageGraph(m_packageGraph);
351351

352-
std::vector<std::string> internalPackages = {
353-
"editor",
354-
"editqml",
355-
"fs",
356-
"live",
357-
"lcvcore",
358-
"lcvfeatures2d",
359-
"lcvimgproc",
360-
"lcvphoto",
361-
"lcvvideo"
362-
};
352+
const MLNode& defaults = ApplicationContext::instance().startupConfiguration();
353+
if ( defaults.hasKey("internalPackages") ){
354+
const MLNode& internalPackages = defaults["internalPackages"];
363355

364-
for ( auto it = internalPackages.begin(); it != internalPackages.end(); ++it ){
356+
for ( auto it = internalPackages.asArray().begin(); it != internalPackages.asArray().end(); ++it ){
365357

366-
std::string packagePath = ApplicationContext::instance().pluginPath() + "/" + *it;
358+
std::string packagePath = ApplicationContext::instance().pluginPath() + "/" + it->asString();
367359

368-
if ( Package::existsIn(packagePath) ){
369-
PackageGraph::addInternalPackage(Package::createFromPath(packagePath));
360+
if ( Package::existsIn(packagePath) ){
361+
PackageGraph::addInternalPackage(Package::createFromPath(packagePath));
362+
}
370363
}
371364
}
372365

373-
std::vector<std::string> qtPackages = {
374-
"Qt",
375-
"QtQml",
376-
"QtQuick",
377-
"QtCanvas3D",
378-
"QtGraphicalEffects",
379-
"QtMultimedia",
380-
"QtWebSockets"
381-
};
382-
383-
for ( auto it = qtPackages.begin(); it != qtPackages.end(); ++it ){
384-
Package::Ptr package = Package::createFromNode(*it, "", {
385-
{"name", *it},
386-
{"version", QT_VERSION_STR},
387-
{"documentation", "editor/loadqtdocs.qml"}
388-
});
389-
PackageGraph::addInternalPackage(package);
366+
if ( defaults.hasKey("internalQtPackages") ){
367+
const MLNode& qtPackages = defaults["internalQtPackages"];
368+
for ( auto it = qtPackages.asArray().begin(); it != qtPackages.asArray().end(); ++it ){
369+
Package::Ptr package = Package::createFromNode(it->asString(), "", {
370+
{"name", *it},
371+
{"version", QT_VERSION_STR},
372+
{"documentation", "editor/loadqtdocs.qml"}
373+
});
374+
PackageGraph::addInternalPackage(package);
375+
}
390376
}
391377
}
392378

@@ -416,9 +402,13 @@ void Livekeys::initializeProject(){
416402
}
417403

418404
void Livekeys::addDefaultLayers(){
419-
addLayer("window", ":/windowlayer.qml");
420-
addLayer("workspace", ":/workspacelayer.qml");
421-
addLayer("editor", ":/editorlayer.qml");
405+
const MLNode& defaults = ApplicationContext::instance().startupConfiguration();
406+
if ( defaults.hasKey("layers") ){
407+
const MLNode& layers = defaults["layers"];
408+
for ( auto it = layers.begin(); it != layers.end(); ++it ){
409+
addLayer(QString::fromStdString(it.key()), QString::fromStdString(it.value().asString()));
410+
}
411+
}
422412
}
423413

424414
std::vector<std::string> Livekeys::packageImportPaths() const{
@@ -451,6 +441,37 @@ QQmlPropertyMap *Livekeys::layers(){
451441
return m_layers;
452442
}
453443

444+
const MLNode &Livekeys::startupConfiguration(){
445+
static MLNode config = {
446+
{"layers", {
447+
{"window", ":/windowlayer.qml"},
448+
{"workspace", ":/workspacelayer.qml"},
449+
{"editor", ":/editorlayer.qml"}
450+
}},
451+
{"internalPackages",{
452+
"editor",
453+
"editqml",
454+
"fs",
455+
"live",
456+
"lcvcore",
457+
"lcvfeatures2d",
458+
"lcvimgproc",
459+
"lcvphoto",
460+
"lcvvideo"
461+
}},
462+
{"internalQtPackages",{
463+
"Qt",
464+
"QtQml",
465+
"QtQuick",
466+
"QtCanvas3D",
467+
"QtGraphicalEffects",
468+
"QtMultimedia",
469+
"QtWebSockets"
470+
}}
471+
};
472+
return config;
473+
}
474+
454475
QObject *Livekeys::layerPlaceholder() const{
455476
if ( !m_layerPlaceholder ){
456477
QList<QObject*> rootObjects = static_cast<QQmlApplicationEngine*>(m_engine->engine())->rootObjects();

application/src/livekeys.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ class Livekeys : public QObject{
115115
VisualLogModel* log();
116116
QQmlPropertyMap* layers();
117117

118+
static const MLNode& startupConfiguration();
119+
118120
public slots:
119121
QObject* layerPlaceholder() const;
120122
void engineError(QJSValue error);

application/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ using namespace lv;
3232

3333
int main(int argc, char *argv[]){
3434

35-
ApplicationContext::initialize();
35+
ApplicationContext::initialize(Livekeys::startupConfiguration());
3636

3737
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
3838
QGuiApplication::addLibraryPath(QString::fromStdString(lv::ApplicationContext::instance().librariesPath()));

lib/lvbase/src/applicationcontext.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "live/applicationcontext.h"
1818
#include "live/exception.h"
19+
#include "live/mlnode.h"
1920

2021
#include <QCoreApplication>
2122
#include <QStandardPaths>
@@ -49,6 +50,8 @@ class ApplicationContextPrivate{
4950
std::string developmentPath;
5051
std::string configPath;
5152
std::string appDataPath;
53+
54+
MLNode defaults;
5255
};
5356

5457
std::unique_ptr<ApplicationContext> ApplicationContextPrivate::ApplicationContextPrivate::instance;
@@ -63,13 +66,14 @@ ApplicationContext::~ApplicationContext(){
6366
/**
6467
* Initalizes the singleton instance of the context
6568
*/
66-
void ApplicationContext::initialize(){
67-
ApplicationContextPrivate::instance.reset(new ApplicationContext);
69+
void ApplicationContext::initialize(const lv::MLNode &defaults){
70+
ApplicationContextPrivate::instance.reset(new ApplicationContext(defaults));
6871
}
6972

70-
ApplicationContext::ApplicationContext()
73+
ApplicationContext::ApplicationContext(const lv::MLNode &defaults)
7174
: m_d(new ApplicationContextPrivate)
7275
{
76+
m_d->defaults = defaults;
7377
initializePaths();
7478
}
7579

@@ -182,6 +186,13 @@ const std::string &ApplicationContext::appDataPath(){
182186
return m_d->appDataPath;
183187
}
184188

189+
/**
190+
* \brief Returns the startup configuration for Livekeys
191+
*/
192+
const MLNode &ApplicationContext::startupConfiguration(){
193+
return m_d->defaults;
194+
}
195+
185196
/** Executable path getter */
186197
const std::string &ApplicationContext::executablePath(){
187198
return m_d->executablePath;

lib/lvbase/src/applicationcontext.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class QString;
2424

2525
namespace lv{
2626

27-
class ViewEngine;
27+
class MLNode;
2828
class Settings;
2929

3030
class ApplicationContextPrivate;
@@ -34,7 +34,7 @@ class LV_BASE_EXPORT ApplicationContext{
3434
public:
3535
~ApplicationContext();
3636

37-
static void initialize();
37+
static void initialize(const MLNode& defaults);
3838
static ApplicationContext& instance();
3939

4040
const std::string& applicationPath();
@@ -50,8 +50,10 @@ class LV_BASE_EXPORT ApplicationContext{
5050
const std::string& configPath();
5151
const std::string& appDataPath();
5252

53+
const MLNode& startupConfiguration();
54+
5355
private:
54-
ApplicationContext();
56+
ApplicationContext(const MLNode& defaults);
5557
void initializePaths();
5658

5759
static std::string applicationFilePathImpl();

tests/unit/lvelementstest/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141

4242
int main(int argc, char *argv[]){
43-
lv::ApplicationContext::initialize();
43+
lv::ApplicationContext::initialize({});
4444

4545
QCoreApplication app(argc, argv);
4646
app.setAttribute(Qt::AA_Use96Dpi, true);

0 commit comments

Comments
 (0)