diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 966ca9c7d..b1f6c48cf 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -11,6 +11,7 @@ configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/../calamares/CalamaresVersion.h.in ${CMAKE_CURRENT_BINARY_DIR}/CalamaresVersion.h ) set( libSources + CppJob.cpp GlobalStorage.cpp Job.cpp JobQueue.cpp @@ -24,6 +25,7 @@ set( libSources utils/CalamaresUtils.cpp utils/CalamaresUtilsSystem.cpp utils/Logger.cpp + utils/PluginFactory.cpp utils/Retranslator.cpp ) diff --git a/src/libcalamares/CppJob.cpp b/src/libcalamares/CppJob.cpp new file mode 100644 index 000000000..1925e398b --- /dev/null +++ b/src/libcalamares/CppJob.cpp @@ -0,0 +1,45 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * Copyright 2016, Kevin Kofler + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "CppJob.h" + +namespace Calamares +{ + +CppJob::CppJob( QObject* parent ) + : Job( parent ) +{} + + +CppJob::~CppJob() +{} + + +void +CppJob::setModuleInstanceKey( const QString& instanceKey ) +{ + m_instanceKey = instanceKey; +} + + +void +CppJob::setConfigurationMap( const QVariantMap& configurationMap ) +{} + +} diff --git a/src/libcalamares/CppJob.h b/src/libcalamares/CppJob.h new file mode 100644 index 000000000..a6e67355f --- /dev/null +++ b/src/libcalamares/CppJob.h @@ -0,0 +1,51 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014-2015, Teo Mrnjavac + * Copyright 2016, Kevin Kofler + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef CALAMARES_CPPJOB_H +#define CALAMARES_CPPJOB_H + +#include +#include + +#include "DllMacro.h" +#include "Typedefs.h" +#include "Job.h" + +namespace Calamares +{ + +class DLLEXPORT CppJob : public Job +{ + Q_OBJECT +public: + explicit CppJob( QObject* parent = nullptr ); + virtual ~CppJob(); + + void setModuleInstanceKey( const QString& instanceKey ); + QString moduleInstanceKey() const { return m_instanceKey; } + + virtual void setConfigurationMap( const QVariantMap& configurationMap ); + +protected: + QString m_instanceKey; +}; + +} + +#endif // CALAMARES_CPPJOB_H diff --git a/src/libcalamaresui/utils/PluginFactory.cpp b/src/libcalamares/utils/PluginFactory.cpp similarity index 100% rename from src/libcalamaresui/utils/PluginFactory.cpp rename to src/libcalamares/utils/PluginFactory.cpp diff --git a/src/libcalamaresui/utils/PluginFactory.h b/src/libcalamares/utils/PluginFactory.h similarity index 99% rename from src/libcalamaresui/utils/PluginFactory.h rename to src/libcalamares/utils/PluginFactory.h index a77d9594f..c0053ba38 100644 --- a/src/libcalamaresui/utils/PluginFactory.h +++ b/src/libcalamares/utils/PluginFactory.h @@ -23,7 +23,7 @@ #ifndef CALAMARESPLUGINFACTORY_H #define CALAMARESPLUGINFACTORY_H -#include "UiDllMacro.h" +#include "DllMacro.h" #include #include @@ -196,7 +196,7 @@ namespace Calamares * \author Matthias Kretz * \author Bernhard Loos */ -class UIDLLEXPORT PluginFactory : public QObject +class DLLEXPORT PluginFactory : public QObject { Q_OBJECT Q_DECLARE_PRIVATE(PluginFactory) diff --git a/src/libcalamaresui/utils/PluginFactory_p.h b/src/libcalamares/utils/PluginFactory_p.h similarity index 100% rename from src/libcalamaresui/utils/PluginFactory_p.h rename to src/libcalamares/utils/PluginFactory_p.h diff --git a/src/libcalamaresui/CMakeLists.txt b/src/libcalamaresui/CMakeLists.txt index 939d05ad7..478034b3e 100644 --- a/src/libcalamaresui/CMakeLists.txt +++ b/src/libcalamaresui/CMakeLists.txt @@ -1,6 +1,7 @@ set( CALAMARESUI_LIBRARY_TARGET calamaresui ) list( APPEND ${CALAMARESUI_LIBRARY_TARGET}_SOURCES + modulesystem/CppJobModule.cpp modulesystem/Module.cpp modulesystem/ModuleManager.cpp modulesystem/ProcessJobModule.cpp @@ -14,8 +15,6 @@ list( APPEND ${CALAMARESUI_LIBRARY_TARGET}_SOURCES utils/qjsonmodel.cpp utils/qjsonitem.cpp - utils/PluginFactory.cpp - viewpages/AbstractPage.cpp viewpages/ViewStep.cpp diff --git a/src/libcalamaresui/modulesystem/CppJobModule.cpp b/src/libcalamaresui/modulesystem/CppJobModule.cpp new file mode 100644 index 000000000..15e41c2e5 --- /dev/null +++ b/src/libcalamaresui/modulesystem/CppJobModule.cpp @@ -0,0 +1,128 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * Copyright 2016, Kevin Kofler + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "CppJobModule.h" + +#include "utils/PluginFactory.h" +#include "utils/Logger.h" +#include "CppJob.h" + +#include +#include + +namespace Calamares { + + +Module::Type +CppJobModule::type() const +{ + return Job; +} + + +Module::Interface +CppJobModule::interface() const +{ + return QtPlugin; +} + + +void +CppJobModule::loadSelf() +{ + if ( m_loader ) + { + PluginFactory* pf = qobject_cast< PluginFactory* >( m_loader->instance() ); + if ( !pf ) + { + cDebug() << Q_FUNC_INFO << m_loader->errorString(); + return; + } + + CppJob *cppJob = pf->create< Calamares::CppJob >(); + if ( !cppJob ) + { + cDebug() << Q_FUNC_INFO << m_loader->errorString(); + return; + } +// cDebug() << "CppJobModule loading self for instance" << instanceKey() +// << "\nCppJobModule at address" << this +// << "\nCalamares::PluginFactory at address" << pf +// << "\nCppJob at address" << cppJob; + + cppJob->setModuleInstanceKey( instanceKey() ); + cppJob->setConfigurationMap( m_configurationMap ); + m_job = Calamares::job_ptr( static_cast< Calamares::Job * >( cppJob ) ); + m_loaded = true; + cDebug() << "CppJobModule" << instanceKey() << "loading complete."; + } +} + + +QList< job_ptr > +CppJobModule::jobs() const +{ + return QList< job_ptr >() << m_job; +} + + +void +CppJobModule::initFrom( const QVariantMap& moduleDescriptor ) +{ + Module::initFrom( moduleDescriptor ); + QDir directory( location() ); + QString load; + if ( !moduleDescriptor.value( "load" ).toString().isEmpty() ) + { + load = moduleDescriptor.value( "load" ).toString(); + load = directory.absoluteFilePath( load ); + } + // If a load path is not specified, we look for a plugin to load in the directory. + if ( load.isEmpty() || !QLibrary::isLibrary( load ) ) + { + const QStringList ls = directory.entryList( QStringList{ "*.so" } ); + if ( !ls.isEmpty() ) + { + for ( QString entry : ls ) + { + entry = directory.absoluteFilePath( entry ); + if ( QLibrary::isLibrary( entry ) ) + { + load = entry; + break; + } + } + } + } + + m_loader = new QPluginLoader( load ); +} + +CppJobModule::CppJobModule() + : Module() + , m_loader( nullptr ) +{ +} + +CppJobModule::~CppJobModule() +{ + delete m_loader; +} + +} // namespace Calamares diff --git a/src/libcalamaresui/modulesystem/CppJobModule.h b/src/libcalamaresui/modulesystem/CppJobModule.h new file mode 100644 index 000000000..127614ec5 --- /dev/null +++ b/src/libcalamaresui/modulesystem/CppJobModule.h @@ -0,0 +1,53 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, Teo Mrnjavac + * Copyright 2016, Kevin Kofler + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef CALAMARES_CPPJOBMODULE_H +#define CALAMARES_CPPJOBMODULE_H + +#include "UiDllMacro.h" +#include "Module.h" + +class QPluginLoader; + +namespace Calamares { + +class UIDLLEXPORT CppJobModule : public Module +{ +public: + Type type() const override; + Interface interface() const override; + + void loadSelf() override; + QList< job_ptr > jobs() const override; + +protected: + void initFrom( const QVariantMap& moduleDescriptor ) override; + +private: + friend class Module; //so only the superclass can instantiate + explicit CppJobModule(); + virtual ~CppJobModule(); + + QPluginLoader* m_loader; + job_ptr m_job; +}; + +} // namespace Calamares + +#endif // CALAMARES_CPPJOBMODULE_H diff --git a/src/libcalamaresui/modulesystem/Module.cpp b/src/libcalamaresui/modulesystem/Module.cpp index 780975418..2a2fe779b 100644 --- a/src/libcalamaresui/modulesystem/Module.cpp +++ b/src/libcalamaresui/modulesystem/Module.cpp @@ -19,6 +19,7 @@ #include "Module.h" #include "ProcessJobModule.h" +#include "CppJobModule.h" #include "ViewModule.h" #include "utils/CalamaresUtils.h" #include "utils/YamlUtils.h" @@ -76,7 +77,11 @@ Module::fromDescriptor( const QVariantMap& moduleDescriptor, } else if ( typeString == "job" ) { - if ( intfString == "process" ) + if ( intfString == "qtplugin" ) + { + m = new CppJobModule(); + } + else if ( intfString == "process" ) { m = new ProcessJobModule(); }