diff --git a/src/libcalamares/GlobalStorage.cpp b/src/libcalamares/GlobalStorage.cpp index fd4d10c53..f24d83a1c 100644 --- a/src/libcalamares/GlobalStorage.cpp +++ b/src/libcalamares/GlobalStorage.cpp @@ -1,6 +1,6 @@ /* === This file is part of Calamares - === * - * Copyright 2014, Teo Mrnjavac + * Copyright 2014-2015, Teo Mrnjavac * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,6 +31,7 @@ namespace bp = boost::python; namespace Calamares { GlobalStorage::GlobalStorage() + : QObject( nullptr ) { } @@ -53,6 +54,7 @@ void GlobalStorage::insert( const QString& key, const QVariant& value ) { m.insert( key, value ); + emit changed(); } @@ -67,6 +69,7 @@ int GlobalStorage::remove( const QString& key ) { return m.remove( key ); + emit changed(); } @@ -76,47 +79,63 @@ GlobalStorage::value( const QString& key ) const return m.value( key ); } +} // namespace Calamares + #ifdef WITH_PYTHON -bool -GlobalStorage::python_contains( const std::string& key ) const +namespace CalamaresPython { - return contains( QString::fromStdString( key ) ); + +GlobalStoragePythonWrapper::GlobalStoragePythonWrapper( Calamares::GlobalStorage* gs ) + : m_gs( gs ) +{} + +bool +GlobalStoragePythonWrapper::contains( const std::string& key ) const +{ + return m_gs->contains( QString::fromStdString( key ) ); +} + + +int +GlobalStoragePythonWrapper::count() const +{ + return m_gs->count(); } void -GlobalStorage::python_insert( const std::string& key, +GlobalStoragePythonWrapper::insert( const std::string& key, const bp::object& value ) { - insert( QString::fromStdString( key ), - CalamaresPython::variantFromPyObject( value ) ); + m_gs->insert( QString::fromStdString( key ), + CalamaresPython::variantFromPyObject( value ) ); } bp::list -GlobalStorage::python_keys() const +GlobalStoragePythonWrapper::keys() const { bp::list pyList; - foreach( const QString& key, keys() ) + foreach( const QString& key, m_gs->keys() ) pyList.append( key.toStdString() ); return pyList; } int -GlobalStorage::python_remove( const std::string& key ) +GlobalStoragePythonWrapper::remove( const std::string& key ) { - return remove( QString::fromStdString( key ) ); + return m_gs->remove( QString::fromStdString( key ) ); } bp::object -GlobalStorage::python_value( const std::string& key ) const +GlobalStoragePythonWrapper::value( const std::string& key ) const { - return CalamaresPython::variantToPyObject( value( QString::fromStdString( key ) ) ); + return CalamaresPython::variantToPyObject( m_gs->value( QString::fromStdString( key ) ) ); } -#endif // WITH_PYTHON +} // namespace CalamaresPython -} // namespace Calamares +#endif // WITH_PYTHON diff --git a/src/libcalamares/GlobalStorage.h b/src/libcalamares/GlobalStorage.h index 9ac903183..20af3978c 100644 --- a/src/libcalamares/GlobalStorage.h +++ b/src/libcalamares/GlobalStorage.h @@ -42,8 +42,9 @@ namespace Calamares class DebugWindow; -class GlobalStorage +class GlobalStorage : public QObject { + Q_OBJECT public: explicit GlobalStorage(); @@ -56,13 +57,8 @@ public: int remove( const QString& key ); QVariant value( const QString& key ) const; -#ifdef WITH_PYTHON - bool python_contains( const std::string& key ) const; - void python_insert( const std::string& key, const boost::python::api::object& value ); - boost::python::list python_keys() const; - int python_remove( const std::string& key ); - boost::python::api::object python_value( const std::string& key ) const; -#endif +signals: + void changed(); private: QVariantMap m; @@ -72,4 +68,26 @@ private: } // namespace Calamares +#ifdef WITH_PYTHON +namespace CalamaresPython +{ + +class GlobalStoragePythonWrapper +{ +public: + explicit GlobalStoragePythonWrapper( Calamares::GlobalStorage* gs ); + + bool contains( const std::string& key ) const; + int count() const; + void insert( const std::string& key, const boost::python::api::object& value ); + boost::python::list keys() const; + int remove( const std::string& key ); + boost::python::api::object value( const std::string& key ) const; +private: + Calamares::GlobalStorage* m_gs; +}; + +} // namespace CalamaresPython +#endif + #endif // CALAMARES_GLOBALSTORAGE_H diff --git a/src/libcalamares/PythonJob.cpp b/src/libcalamares/PythonJob.cpp index 07283a469..0a2a4bd4f 100644 --- a/src/libcalamares/PythonJob.cpp +++ b/src/libcalamares/PythonJob.cpp @@ -1,6 +1,6 @@ /* === This file is part of Calamares - === * - * Copyright 2014, Teo Mrnjavac + * Copyright 2014-2015, Teo Mrnjavac * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -79,13 +79,13 @@ BOOST_PYTHON_MODULE( libcalamares ) "as a real number between 0 and 1." ); - bp::class_< Calamares::GlobalStorage >( "GlobalStorage", bp::init<>() ) - .def( "contains", &Calamares::GlobalStorage::python_contains ) - .def( "count", &Calamares::GlobalStorage::count ) - .def( "insert", &Calamares::GlobalStorage::python_insert ) - .def( "keys", &Calamares::GlobalStorage::python_keys ) - .def( "remove", &Calamares::GlobalStorage::python_remove ) - .def( "value", &Calamares::GlobalStorage::python_value ); + bp::class_< CalamaresPython::GlobalStoragePythonWrapper >( "GlobalStorage", bp::init< Calamares::GlobalStorage* >() ) + .def( "contains", &CalamaresPython::GlobalStoragePythonWrapper::contains ) + .def( "count", &CalamaresPython::GlobalStoragePythonWrapper::count ) + .def( "insert", &CalamaresPython::GlobalStoragePythonWrapper::insert ) + .def( "keys", &CalamaresPython::GlobalStoragePythonWrapper::keys ) + .def( "remove", &CalamaresPython::GlobalStoragePythonWrapper::remove ) + .def( "value", &CalamaresPython::GlobalStoragePythonWrapper::value ); // libcalamares.utils submodule starts here bp::object utilsModule( bp::handle<>( bp::borrowed( PyImport_AddModule( "libcalamares.utils" ) ) ) ); @@ -271,7 +271,8 @@ PythonJob::exec() bp::dict calamaresNamespace = bp::extract< bp::dict >( calamaresModule.attr( "__dict__" ) ); calamaresNamespace[ "job" ] = CalamaresPython::PythonJobInterface( this ); - calamaresNamespace[ "globalstorage" ] = bp::ptr( JobQueue::instance()->globalStorage() ); + calamaresNamespace[ "globalstorage" ] = CalamaresPython::GlobalStoragePythonWrapper( + JobQueue::instance()->globalStorage() ); bp::object execResult = bp::exec_file( scriptFI.absoluteFilePath().toLocal8Bit().data(), scriptNamespace,