diff --git a/CMakeLists.txt b/CMakeLists.txt index c1791b217..aad5f60d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ project( calamares ) cmake_minimum_required( VERSION 2.8.12 ) set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules" ) +set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wl,--no-undefined" ) +#set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" ) cmake_policy( SET CMP0023 OLD ) diff --git a/src/calamares/CMakeLists.txt b/src/calamares/CMakeLists.txt index 2dcb28875..d8da1be35 100644 --- a/src/calamares/CMakeLists.txt +++ b/src/calamares/CMakeLists.txt @@ -8,8 +8,11 @@ set( calamaresSources main.cpp CalamaresApplication.cpp CalamaresWindow.cpp + Module.cpp + ModuleLoader.cpp ViewManager.cpp Settings.cpp + YamlUtils.cpp viewpages/PagePlugin.cpp viewpages/AbstractPage.cpp @@ -43,6 +46,7 @@ add_executable( calamares_bin ${final_src} ) SET_TARGET_PROPERTIES(calamares_bin PROPERTIES AUTOMOC TRUE + ENABLE_EXPORTS TRUE RUNTIME_OUTPUT_NAME calamares ) diff --git a/src/calamares/Module.cpp b/src/calamares/Module.cpp new file mode 100644 index 000000000..f4071c9eb --- /dev/null +++ b/src/calamares/Module.cpp @@ -0,0 +1,120 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, 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 + * 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 "Module.h" + +#include "YamlUtils.h" + +#include "utils/Logger.h" + +#include + +#include +#include + + +// Example module.conf +/* +--- +type: "core" #core or view +name: "foo" #the module name. must be unique and same as the parent directory +interface: "qtplugin" #can be: qtplugin, python, process, ... +requires: [] #list of module names that must also be loaded. only applies to + #binary plugins! these are actual link-time dependencies, not + #conceptual dependencies for the setup procedure +*/ + +void +operator>>( const YAML::Node& node, Calamares::Module& m ) +{ + m.m_name = QString::fromStdString( node[ "name" ].as< std::string >() ); + + QString typeString = QString::fromStdString( node[ "type" ].as< std::string >() ); + if ( typeString == "core" ) + { + m.m_type = Calamares::Module::Core; + } + else if ( typeString == "view" ) + { + m.m_type = Calamares::Module::View; + m.m_interface = Calamares::Module::QtPlugin; + } + + if ( m.m_type != Calamares::Module::View ) + { + QString interfaceString = QString::fromStdString( node[ "interface" ].as< std::string >() ); + if ( interfaceString == "qtplugin" ) + { + m.m_interface = Calamares::Module::QtPlugin; + } + else if ( interfaceString == "python" ) + { + m.m_interface = Calamares::Module::Python; + } + else if ( interfaceString == "process" ) + { + m.m_interface = Calamares::Module::Process; + } + } + + if ( node[ "requires" ] && node[ "requires" ].IsSequence() ) + { + node[ "requires" ] >> m.m_requiredModules; + } + +} + + +Calamares::Module* +Calamares::Module::loadFromFile( const QString& path ) +{ + QFile metadataFile( path ); + if ( metadataFile.exists() && metadataFile.open( QFile::ReadOnly | QFile::Text ) ) + { + QByteArray ba = metadataFile.readAll(); + cDebug() << Q_FUNC_INFO << "module metadata file: " << ba; + + try + { + YAML::Node moduleDocument = YAML::Load( ba.constData() ); + if ( !moduleDocument.IsMap() ) + { + cDebug() << Q_FUNC_INFO << "bad module metadata format" + << path; + return nullptr; + } + + Module* m = new Module(); + moduleDocument >> *m; + return m; + } + catch ( YAML::Exception& e ) + { + cDebug() << "WARNING: YAML parser error " << e.what(); + return nullptr; + } + } + + return nullptr; +} + +QString +Calamares::Module::name() +{ + return m_name; +} diff --git a/src/calamares/Module.h b/src/calamares/Module.h new file mode 100644 index 000000000..c938a6cda --- /dev/null +++ b/src/calamares/Module.h @@ -0,0 +1,72 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, 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 + * 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 CALAMARESMODULE_H +#define CALAMARESMODULE_H + +#include "DllMacro.h" + +#include + + +namespace YAML +{ +class Node; +} + +namespace Calamares +{ +class Module; +} + +void operator>>( const YAML::Node& node, Calamares::Module& m ); + +namespace Calamares +{ + +class UIDLLEXPORT Module +{ +public: + static Module* loadFromFile( const QString& path ); + + QString name(); + + enum Type + { + Core, + View + }; + + enum Interface + { + QtPlugin, + Python, + Process + }; +private: + QString m_name; + Type m_type; + Interface m_interface; + QStringList m_requiredModules; + + friend void ::operator>>( const YAML::Node& node, Calamares::Module& m ); +}; + +} + +#endif // CALAMARESMODULE_H diff --git a/src/calamares/ModuleLoader.cpp b/src/calamares/ModuleLoader.cpp new file mode 100644 index 000000000..ee21e9a23 --- /dev/null +++ b/src/calamares/ModuleLoader.cpp @@ -0,0 +1,103 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, 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 + * 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 "ModuleLoader.h" + +#include "utils/Logger.h" + +#include + +#include + +#define MODULE_CONFIG_FILENAME "module.conf" + +namespace Calamares +{ + +ModuleLoader::ModuleLoader( const QStringList& paths, QObject* parent ) + : QObject( parent ) + , m_paths( paths ) +{ +} + +ModuleLoader::~ModuleLoader() +{ + foreach ( Module* m, m_availableModules ) + { + delete m; + } +} + + +void +ModuleLoader::exec() +{ + // We start from a list of paths in m_paths. Each of those is a directory that + // might (should) contain Calamares modules of any type/interface. + // For each modules search path (directory), it is expected that each module + // lives in its own subdirectory. This subdirectory must have the same name as + // the module name, and must contain a settings file named module.conf. + // If at any time the module loading procedure finds something unexpected, it + // silently skips to the next module or search path. --Teo 6/2014 + foreach ( const QString& path, m_paths ) + { + QDir currentDir( path ); + if ( currentDir.exists() && currentDir.isReadable() ) + { + QStringList subdirs = currentDir.entryList( QDir::AllDirs | QDir::NoDotAndDotDot ); + foreach ( const QString& subdir, subdirs ) + { + bool success = currentDir.cd( subdir ); + if ( success && currentDir.isReadable() ) + { + QFileInfo metadataFileInfo( currentDir.absoluteFilePath( MODULE_CONFIG_FILENAME ) ); + if ( ! ( metadataFileInfo.exists() && metadataFileInfo.isReadable() ) ) + { + cDebug() << Q_FUNC_INFO << "unreadable file: " + << metadataFileInfo.absoluteFilePath(); + continue; + } + + Module* moduleInfo = Module::loadFromFile( metadataFileInfo.absoluteFilePath() ); + + if ( moduleInfo && + ( moduleInfo->name() == currentDir.dirName() ) && + ( !m_availableModules.contains( moduleInfo->name() ) ) ) + { + m_availableModules.insert( moduleInfo->name(), moduleInfo ); + } + + currentDir.cdUp(); + } + else + { + cDebug() << Q_FUNC_INFO << "cannot cd into module directory " + << path << "/" << subdir; + } + } + } + else + { + cDebug() << Q_FUNC_INFO << "bad search path " << path; + } + } + // At this point m_availableModules is filled with whatever was found in the + // search paths. +} + +} diff --git a/src/calamares/ModuleLoader.h b/src/calamares/ModuleLoader.h new file mode 100644 index 000000000..c5920b068 --- /dev/null +++ b/src/calamares/ModuleLoader.h @@ -0,0 +1,54 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, 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 + * 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 MODULELOADER_H +#define MODULELOADER_H + +#include "Module.h" + +#include +#include +#include + +namespace Calamares +{ + +class Module; + +class ModuleLoader : public QObject +{ + Q_OBJECT +public: + explicit ModuleLoader( const QStringList& paths, QObject* parent = 0 ); + virtual ~ModuleLoader(); + + void exec(); + +signals: + void done(); + +private: + QMap< QString, Module* > m_availableModules; + + QStringList m_paths; + +}; + +} + +#endif // MODULELOADER_H diff --git a/src/calamares/Settings.cpp b/src/calamares/Settings.cpp index ccef36f14..0df7620df 100644 --- a/src/calamares/Settings.cpp +++ b/src/calamares/Settings.cpp @@ -21,6 +21,7 @@ #include "CalamaresApplication.h" #include "utils/CalamaresUtils.h" #include "utils/Logger.h" +#include "YamlUtils.h" #include #include @@ -28,16 +29,6 @@ #include -void -operator>>( const YAML::Node& node, QStringList& v ) -{ - for ( int i = 0; i < node.size(); ++i ) - { - v.append( QString::fromStdString( node[ i ].as< std::string >() ) ); - } -} - - namespace Calamares { @@ -89,7 +80,7 @@ Settings::Settings( QObject* parent ) config[ "modules-prepare" ] >> m_viewModulesPrepareList; config[ "modules-postinstall" ] >> m_viewModulesPostInstallList; } - catch( YAML::Exception& e ) + catch ( YAML::Exception& e ) { cDebug() << "WARNING: YAML parser error " << e.what(); } diff --git a/src/calamares/YamlUtils.cpp b/src/calamares/YamlUtils.cpp new file mode 100644 index 000000000..2bd89a082 --- /dev/null +++ b/src/calamares/YamlUtils.cpp @@ -0,0 +1,30 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, 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 + * 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 "YamlUtils.h" + +#include + +void +operator>>( const YAML::Node& node, QStringList& v ) +{ + for ( int i = 0; i < node.size(); ++i ) + { + v.append( QString::fromStdString( node[ i ].as< std::string >() ) ); + } +} + diff --git a/src/calamares/YamlUtils.h b/src/calamares/YamlUtils.h new file mode 100644 index 000000000..173d76f76 --- /dev/null +++ b/src/calamares/YamlUtils.h @@ -0,0 +1,31 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014, 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 + * 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 YAMLUTILS_H +#define YAMLUTILS_H + +#include + +namespace YAML +{ +class Node; +} + +void operator>>( const YAML::Node& node, QStringList& v ); + +#endif // YAMLUTILS_H diff --git a/src/calamares/viewpages/AbstractPage.h b/src/calamares/viewpages/AbstractPage.h index 6dd04af7c..d40932499 100644 --- a/src/calamares/viewpages/AbstractPage.h +++ b/src/calamares/viewpages/AbstractPage.h @@ -31,10 +31,8 @@ class UIDLLEXPORT AbstractPage : public QWidget Q_OBJECT public: explicit AbstractPage(QWidget *parent = 0); + virtual ~AbstractPage() {} -signals: - -public slots: }; diff --git a/src/calamares/viewpages/PagePlugin.h b/src/calamares/viewpages/PagePlugin.h index 58ba31cd8..35155512e 100644 --- a/src/calamares/viewpages/PagePlugin.h +++ b/src/calamares/viewpages/PagePlugin.h @@ -33,6 +33,7 @@ class UIDLLEXPORT PagePlugin : public QObject Q_OBJECT public: explicit PagePlugin( QObject *parent = 0 ); + virtual ~PagePlugin() {} signals: void done(); diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 1358089d2..d99654229 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -17,8 +17,8 @@ set( libSources kdsingleapplicationguard/kdtoolsglobal.cpp kdsingleapplicationguard/kdlockedsharedmemorypointer.cpp - utils/Logger.cpp utils/CalamaresUtils.cpp + utils/Logger.cpp ) include_directories( diff --git a/src/modules/greeting/CMakeLists.txt b/src/modules/greeting/CMakeLists.txt index c4eb762da..e03a3dc8d 100644 --- a/src/modules/greeting/CMakeLists.txt +++ b/src/modules/greeting/CMakeLists.txt @@ -8,5 +8,6 @@ calamares_add_plugin( greeting UI LINK_LIBRARIES ${CALAMARES_LIBRARIES} + calamares_bin SHARED_LIB ) diff --git a/src/modules/greeting/GreetingPage.cpp b/src/modules/greeting/GreetingPage.cpp index a215895c0..db4558535 100644 --- a/src/modules/greeting/GreetingPage.cpp +++ b/src/modules/greeting/GreetingPage.cpp @@ -20,6 +20,6 @@ GreetingPage::GreetingPage( QWidget* parent ) - : AbstractPage( parent ) + : Calamares::AbstractPage( parent ) { } diff --git a/src/modules/greeting/GreetingPagePlugin.cpp b/src/modules/greeting/GreetingPagePlugin.cpp index 2aa33f018..5028c84bf 100644 --- a/src/modules/greeting/GreetingPagePlugin.cpp +++ b/src/modules/greeting/GreetingPagePlugin.cpp @@ -19,6 +19,6 @@ #include "GreetingPagePlugin.h" GreetingPagePlugin::GreetingPagePlugin( QObject *parent ) - : PagePlugin( parent ) + : Calamares::PagePlugin( parent ) { }