From 8af17fafe1883240a03889c64858a8549976b6f2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 1 May 2020 09:58:38 +0200 Subject: [PATCH] [libcalamaresui] Register Global Storage (as 'Global') for QML --- src/libcalamares/GlobalStorage.h | 10 ++++++---- src/libcalamaresui/utils/Qml.cpp | 6 ++++++ src/libcalamaresui/utils/Qml.h | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/libcalamares/GlobalStorage.h b/src/libcalamares/GlobalStorage.h index bef9ec1cc..2a59009f7 100644 --- a/src/libcalamares/GlobalStorage.h +++ b/src/libcalamares/GlobalStorage.h @@ -39,12 +39,8 @@ public: //NOTE: thread safety is guaranteed by JobQueue, which executes jobs one by one. // If at any time jobs become concurrent, this class must be made thread-safe. - bool contains( const QString& key ) const; - int count() const; void insert( const QString& key, const QVariant& value ); - QStringList keys() const; int remove( const QString& key ); - QVariant value( const QString& key ) const; /// @brief dump keys and values to the debug log void debugDump() const; @@ -83,6 +79,12 @@ public: */ const QVariantMap& data() const { return m; } +public Q_SLOTS: + bool contains( const QString& key ) const; + int count() const; + QStringList keys() const; + QVariant value( const QString& key ) const; + signals: void changed(); diff --git a/src/libcalamaresui/utils/Qml.cpp b/src/libcalamaresui/utils/Qml.cpp index 246bf9c78..2c1cc0c49 100644 --- a/src/libcalamaresui/utils/Qml.cpp +++ b/src/libcalamaresui/utils/Qml.cpp @@ -19,6 +19,8 @@ #include "Qml.h" #include "Branding.h" +#include "GlobalStorage.h" +#include "JobQueue.h" #include "ViewManager.h" #include "utils/Logger.h" @@ -164,6 +166,10 @@ registerCalamaresModels() "io.calamares.core", 1, 0, "ViewManager", []( QQmlEngine*, QJSEngine* ) -> QObject* { return Calamares::ViewManager::instance(); } ); + qmlRegisterSingletonType< Calamares::GlobalStorage >( + "io.calamares.core", 1, 0, "Global", []( QQmlEngine*, QJSEngine* ) -> QObject* { + return Calamares::JobQueue::instance()->globalStorage(); + } ); } } diff --git a/src/libcalamaresui/utils/Qml.h b/src/libcalamaresui/utils/Qml.h index b109d8381..33b44b9ea 100644 --- a/src/libcalamaresui/utils/Qml.h +++ b/src/libcalamaresui/utils/Qml.h @@ -36,6 +36,7 @@ namespace CalamaresUtils * The following objects are made available globally: * - `io.calamares.ui.Branding` (an object, see Branding.h) * - `io.calamares.core.ViewManager` (a model, see ViewManager.h) + * - `io.calamares.core.Global` (an object, see GlobalStorage.h) * Additionally, modules based on QmlViewStep have a context * property `config` referring to that module's configuration (if any). */