Merge branch 'require-kcoreaddons'
Require KCoreAddons. This is one of the KDE Frameworks, small and lightweight libraries adding functionality on top of Qt. Since lots of **other** parts of Calamares require KDE Frameworks, including the partitioning module, requiring a tier-1 for basic functionality seems reasonable. This brings: - using KPluginLoader instead of an ancient fork - availability of KMacroExpander everywhere - kaboutdata (needed for KCrash anyway) - kjobs (need to look into using those as a base for Calamares jobs)
This commit is contained in:
commit
c53b59c504
5
CHANGES
5
CHANGES
@ -13,6 +13,11 @@ This release contains contributions from (alphabetically by first name):
|
|||||||
has had a few updates and has now been consistently applied across
|
has had a few updates and has now been consistently applied across
|
||||||
the core codebase (e.g. libcalamares, libcalamaresui, calamares, but
|
the core codebase (e.g. libcalamares, libcalamaresui, calamares, but
|
||||||
not the modules).
|
not the modules).
|
||||||
|
- *KCoreAddons* is now a required dependency. This lets us drop a chunk
|
||||||
|
of code that was copied from KCoreAddons years ago, and use the
|
||||||
|
(maintained!) upstream version instead. It also gives us KMacroExpander
|
||||||
|
everywhere, which will simplify code for handling substitutions
|
||||||
|
in configuration files.
|
||||||
|
|
||||||
## Modules ##
|
## Modules ##
|
||||||
|
|
||||||
|
@ -261,6 +261,8 @@ if( Qt5_VERSION VERSION_GREATER 5.12.1 )
|
|||||||
list( APPEND _tx_ok "eo" )
|
list( APPEND _tx_ok "eo" )
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
# Optional Qt parts
|
||||||
|
find_package( Qt5DBus CONFIG )
|
||||||
|
|
||||||
find_package( YAMLCPP ${YAMLCPP_VERSION} REQUIRED )
|
find_package( YAMLCPP ${YAMLCPP_VERSION} REQUIRED )
|
||||||
if( INSTALL_POLKIT )
|
if( INSTALL_POLKIT )
|
||||||
@ -291,7 +293,14 @@ if( ECM_FOUND )
|
|||||||
include(KDEInstallDirs)
|
include(KDEInstallDirs)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package( KF5 COMPONENTS CoreAddons Crash )
|
find_package( KF5 QUIET COMPONENTS CoreAddons Crash )
|
||||||
|
set_package_properties(
|
||||||
|
KF5::CoreAddons PROPERTIES
|
||||||
|
TYPE REQUIRED
|
||||||
|
DESCRIPTION "Classes built on QtCore for About Data"
|
||||||
|
URL "https://api.kde.org/frameworks/kcoreaddons/"
|
||||||
|
PURPOSE "About Calamares"
|
||||||
|
)
|
||||||
if( NOT KF5Crash_FOUND )
|
if( NOT KF5Crash_FOUND )
|
||||||
set( WITH_KF5Crash OFF )
|
set( WITH_KF5Crash OFF )
|
||||||
endif()
|
endif()
|
||||||
@ -590,10 +599,25 @@ add_custom_target( uninstall
|
|||||||
|
|
||||||
### CMAKE SUMMARY REPORT
|
### CMAKE SUMMARY REPORT
|
||||||
#
|
#
|
||||||
feature_summary(WHAT ALL)
|
|
||||||
|
|
||||||
get_directory_property( SKIPPED_MODULES
|
get_directory_property( SKIPPED_MODULES
|
||||||
DIRECTORY src/modules
|
DIRECTORY src/modules
|
||||||
DEFINITION LIST_SKIPPED_MODULES
|
DEFINITION LIST_SKIPPED_MODULES
|
||||||
)
|
)
|
||||||
calamares_explain_skipped_modules( ${SKIPPED_MODULES} )
|
calamares_explain_skipped_modules( ${SKIPPED_MODULES} )
|
||||||
|
|
||||||
|
feature_summary(
|
||||||
|
WHAT DISABLED_FEATURES
|
||||||
|
DESCRIPTION "The following features have been disabled:"
|
||||||
|
QUIET_ON_EMPTY
|
||||||
|
)
|
||||||
|
feature_summary(
|
||||||
|
WHAT OPTIONAL_PACKAGES_NOT_FOUND
|
||||||
|
DESCRIPTION "The following OPTIONAL packages were not found:"
|
||||||
|
QUIET_ON_EMPTY
|
||||||
|
)
|
||||||
|
feature_summary(
|
||||||
|
WHAT REQUIRED_PACKAGES_NOT_FOUND
|
||||||
|
FATAL_ON_MISSING_REQUIRED_PACKAGES
|
||||||
|
DESCRIPTION "The following REQUIRED packages were not found:"
|
||||||
|
QUIET_ON_EMPTY
|
||||||
|
)
|
||||||
|
@ -21,6 +21,7 @@ Main:
|
|||||||
* Boost.Python >= 1.55.0 (required for some modules)
|
* Boost.Python >= 1.55.0 (required for some modules)
|
||||||
* KDE extra-cmake-modules >= 5.18 (recommended; required for some modules;
|
* KDE extra-cmake-modules >= 5.18 (recommended; required for some modules;
|
||||||
required for some tests)
|
required for some tests)
|
||||||
|
* KDE Frameworks KCoreAddons (>= 5.58 recommended)
|
||||||
* PythonQt (optional, deprecated)
|
* PythonQt (optional, deprecated)
|
||||||
|
|
||||||
Modules:
|
Modules:
|
||||||
|
@ -46,11 +46,11 @@ target_link_libraries( calamares_bin
|
|||||||
calamaresui
|
calamaresui
|
||||||
Qt5::Core
|
Qt5::Core
|
||||||
Qt5::Widgets
|
Qt5::Widgets
|
||||||
|
KF5::CoreAddons
|
||||||
)
|
)
|
||||||
if( WITH_KF5Crash )
|
if( WITH_KF5Crash )
|
||||||
target_link_libraries( calamares_bin
|
target_link_libraries( calamares_bin
|
||||||
PRIVATE
|
PRIVATE
|
||||||
KF5::CoreAddons
|
|
||||||
KF5::Crash
|
KF5::Crash
|
||||||
)
|
)
|
||||||
target_compile_definitions( calamares_bin PRIVATE WITH_KF5Crash )
|
target_compile_definitions( calamares_bin PRIVATE WITH_KF5Crash )
|
||||||
|
@ -26,8 +26,8 @@
|
|||||||
|
|
||||||
#include "3rdparty/kdsingleapplicationguard/kdsingleapplicationguard.h"
|
#include "3rdparty/kdsingleapplicationguard/kdsingleapplicationguard.h"
|
||||||
|
|
||||||
#ifdef WITH_KF5Crash
|
|
||||||
#include <KF5/KCoreAddons/KAboutData>
|
#include <KF5/KCoreAddons/KAboutData>
|
||||||
|
#ifdef WITH_KF5Crash
|
||||||
#include <KF5/KCrash/KCrash>
|
#include <KF5/KCrash/KCrash>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -93,7 +93,6 @@ main( int argc, char* argv[] )
|
|||||||
{
|
{
|
||||||
CalamaresApplication a( argc, argv );
|
CalamaresApplication a( argc, argv );
|
||||||
|
|
||||||
#ifdef WITH_KF5Crash
|
|
||||||
KAboutData aboutData( "calamares",
|
KAboutData aboutData( "calamares",
|
||||||
"Calamares",
|
"Calamares",
|
||||||
a.applicationVersion(),
|
a.applicationVersion(),
|
||||||
@ -104,12 +103,14 @@ main( int argc, char* argv[] )
|
|||||||
"https://calamares.io",
|
"https://calamares.io",
|
||||||
"https://github.com/calamares/calamares/issues" );
|
"https://github.com/calamares/calamares/issues" );
|
||||||
KAboutData::setApplicationData( aboutData );
|
KAboutData::setApplicationData( aboutData );
|
||||||
|
a.setApplicationDisplayName( QString() ); // To avoid putting an extra "Calamares/" into the log-file
|
||||||
|
|
||||||
|
#ifdef WITH_KF5Crash
|
||||||
KCrash::initialize();
|
KCrash::initialize();
|
||||||
// KCrash::setCrashHandler();
|
// KCrash::setCrashHandler();
|
||||||
KCrash::setDrKonqiEnabled( true );
|
KCrash::setDrKonqiEnabled( true );
|
||||||
KCrash::setFlags( KCrash::SaferDialog | KCrash::AlwaysDirectly );
|
KCrash::setFlags( KCrash::SaferDialog | KCrash::AlwaysDirectly );
|
||||||
// TODO: umount anything in /tmp/calamares-... as an emergency save function
|
// TODO: umount anything in /tmp/calamares-... as an emergency save function
|
||||||
a.setApplicationDisplayName( QString() );
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
handle_args( a );
|
handle_args( a );
|
||||||
|
@ -120,6 +120,7 @@ target_link_libraries( calamares
|
|||||||
LINK_PUBLIC
|
LINK_PUBLIC
|
||||||
${YAMLCPP_LIBRARY}
|
${YAMLCPP_LIBRARY}
|
||||||
Qt5::Core
|
Qt5::Core
|
||||||
|
KF5::CoreAddons
|
||||||
${OPTIONAL_PUBLIC_LIBRARIES}
|
${OPTIONAL_PUBLIC_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,127 +1,11 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
|
|
||||||
*
|
*
|
||||||
* Based on KPluginFactory from KCoreAddons, KDE project
|
|
||||||
* Copyright 2007, Matthias Kretz <kretz@kde.org>
|
|
||||||
* Copyright 2007, Bernhard Loos <nhuh.put@web.de>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "PluginFactory.h"
|
#include "PluginFactory.h"
|
||||||
#include "PluginFactory_p.h"
|
|
||||||
|
|
||||||
#include <QDebug>
|
CalamaresPluginFactory::~CalamaresPluginFactory()
|
||||||
#include <QObjectCleanupHandler>
|
|
||||||
|
|
||||||
// *INDENT-OFF*
|
|
||||||
// clang-format off
|
|
||||||
|
|
||||||
Q_GLOBAL_STATIC( QObjectCleanupHandler, factorycleanup )
|
|
||||||
|
|
||||||
namespace Calamares
|
|
||||||
{
|
{
|
||||||
|
|
||||||
PluginFactory::PluginFactory()
|
|
||||||
: pd_ptr( new PluginFactoryPrivate )
|
|
||||||
{
|
|
||||||
pd_ptr->q_ptr = this;
|
|
||||||
|
|
||||||
factorycleanup()->add( this );
|
|
||||||
}
|
|
||||||
|
|
||||||
PluginFactory::PluginFactory( PluginFactoryPrivate& d )
|
|
||||||
: pd_ptr( &d )
|
|
||||||
{
|
|
||||||
factorycleanup()->add( this );
|
|
||||||
}
|
|
||||||
|
|
||||||
PluginFactory::~PluginFactory()
|
|
||||||
{
|
|
||||||
delete pd_ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PluginFactory::doRegisterPlugin( const QString& keyword, const QMetaObject* metaObject, CreateInstanceFunction instanceFunction )
|
|
||||||
{
|
|
||||||
Q_ASSERT( metaObject );
|
|
||||||
|
|
||||||
// we allow different interfaces to be registered without keyword
|
|
||||||
if ( !keyword.isEmpty() )
|
|
||||||
{
|
|
||||||
if ( pd_ptr->createInstanceHash.contains( keyword ) )
|
|
||||||
qWarning() << "A plugin with the keyword" << keyword << "was already registered. A keyword must be unique!";
|
|
||||||
pd_ptr->createInstanceHash.insert( keyword, PluginFactoryPrivate::Plugin( metaObject, instanceFunction ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const QList<PluginFactoryPrivate::Plugin> clashes( pd_ptr->createInstanceHash.values( keyword ) );
|
|
||||||
const QMetaObject* superClass = metaObject->superClass();
|
|
||||||
if ( superClass )
|
|
||||||
{
|
|
||||||
for ( const PluginFactoryPrivate::Plugin& plugin : clashes )
|
|
||||||
{
|
|
||||||
for ( const QMetaObject* otherSuper = plugin.first->superClass(); otherSuper;
|
|
||||||
otherSuper = otherSuper->superClass() )
|
|
||||||
{
|
|
||||||
if ( superClass == otherSuper )
|
|
||||||
qWarning() << "Two plugins with the same interface(" << superClass->className() << ") were registered. Use keywords to identify the plugins.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for ( const PluginFactoryPrivate::Plugin& plugin : clashes )
|
|
||||||
{
|
|
||||||
superClass = plugin.first->superClass();
|
|
||||||
if ( superClass )
|
|
||||||
{
|
|
||||||
for ( const QMetaObject* otherSuper = metaObject->superClass(); otherSuper;
|
|
||||||
otherSuper = otherSuper->superClass() )
|
|
||||||
{
|
|
||||||
if ( superClass == otherSuper )
|
|
||||||
qWarning() << "Two plugins with the same interface(" << superClass->className() << ") were registered. Use keywords to identify the plugins.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pd_ptr->createInstanceHash.insertMulti( keyword, PluginFactoryPrivate::Plugin( metaObject, instanceFunction ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QObject* PluginFactory::create( const char* iface, QWidget* parentWidget, QObject* parent, const QString& keyword )
|
|
||||||
{
|
|
||||||
QObject* obj = nullptr;
|
|
||||||
|
|
||||||
const QList<PluginFactoryPrivate::Plugin> candidates( pd_ptr->createInstanceHash.values( keyword ) );
|
|
||||||
// for !keyword.isEmpty() candidates.count() is 0 or 1
|
|
||||||
|
|
||||||
for ( const PluginFactoryPrivate::Plugin& plugin : candidates )
|
|
||||||
{
|
|
||||||
for ( const QMetaObject* current = plugin.first; current; current = current->superClass() )
|
|
||||||
{
|
|
||||||
if ( 0 == qstrcmp( iface, current->className() ) )
|
|
||||||
{
|
|
||||||
if ( obj )
|
|
||||||
qWarning() << "ambiguous interface requested from a DSO containing more than one plugin";
|
|
||||||
obj = plugin.second( parentWidget, parent );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( obj )
|
|
||||||
emit objectCreated( obj );
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,298 +24,80 @@
|
|||||||
#ifndef UTILS_PLUGINFACTORY_H
|
#ifndef UTILS_PLUGINFACTORY_H
|
||||||
#define UTILS_PLUGINFACTORY_H
|
#define UTILS_PLUGINFACTORY_H
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include <KF5/KCoreAddons/KPluginFactory>
|
||||||
|
|
||||||
#include <QtCore/QObject>
|
|
||||||
#include <QtCore/QStringList>
|
|
||||||
#include <QtCore/QVariant>
|
|
||||||
|
|
||||||
// *INDENT-OFF*
|
|
||||||
// clang-format off
|
|
||||||
|
|
||||||
namespace Calamares
|
|
||||||
{
|
|
||||||
class PluginFactoryPrivate;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define CalamaresPluginFactory_iid "io.calamares.PluginFactory"
|
#define CalamaresPluginFactory_iid "io.calamares.PluginFactory"
|
||||||
|
|
||||||
/**
|
/** @brief Plugin factory for Calamares
|
||||||
* \relates PluginFactory
|
|
||||||
*
|
*
|
||||||
* CALAMARES_PLUGIN_FACTORY_DECLARATION declares the PluginFactory subclass. This macro
|
* Try to re-use KPluginFactory as much as possible (since the
|
||||||
* can be used in a header file.
|
* old code for PluginFactory was a fork of an old version of
|
||||||
|
* exactly that).
|
||||||
*
|
*
|
||||||
* \param name The name of the PluginFactory derived class.
|
* The current createInstance() method passes more arguments
|
||||||
*
|
* to the job and viewstep constructors than we want; chasing
|
||||||
* \see CALAMARES_PLUGIN_FACTORY
|
* that change means modifying each Calamares module. This class
|
||||||
* \see CALAMARES_PLUGIN_FACTORY_DEFINITION
|
* implements a version of createInstance() with fewer arguments
|
||||||
|
* and overloads registerPlugin() to use that.
|
||||||
*/
|
*/
|
||||||
#define CALAMARES_PLUGIN_FACTORY_DECLARATION(name) \
|
class CalamaresPluginFactory : public KPluginFactory
|
||||||
class name : public Calamares::PluginFactory \
|
|
||||||
{ \
|
|
||||||
Q_OBJECT \
|
|
||||||
Q_INTERFACES(Calamares::PluginFactory) \
|
|
||||||
Q_PLUGIN_METADATA(IID CalamaresPluginFactory_iid) \
|
|
||||||
public: \
|
|
||||||
explicit name(); \
|
|
||||||
~name(); \
|
|
||||||
private: \
|
|
||||||
void init(); \
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \relates PluginFactory
|
|
||||||
* CALAMARES_PLUGIN_FACTORY_DEFINITION defines the PluginFactory subclass. This macro
|
|
||||||
* can <b>not</b> be used in a header file.
|
|
||||||
*
|
|
||||||
* \param name The name of the PluginFactory derived class.
|
|
||||||
*
|
|
||||||
* \param pluginRegistrations Code to be inserted into the constructor of the
|
|
||||||
* class. Usually a series of registerPlugin() calls.
|
|
||||||
*
|
|
||||||
* \see CALAMARES_PLUGIN_FACTORY
|
|
||||||
* \see CALAMARES_PLUGIN_FACTORY_DECLARATION
|
|
||||||
*/
|
|
||||||
#define CALAMARES_PLUGIN_FACTORY_DEFINITION(name, pluginRegistrations) \
|
|
||||||
name::name() \
|
|
||||||
{ \
|
|
||||||
pluginRegistrations \
|
|
||||||
} \
|
|
||||||
name::~name() {}
|
|
||||||
|
|
||||||
namespace Calamares
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \class PluginFactory PluginFactory.h <PluginFactory.h>
|
|
||||||
*
|
|
||||||
* PluginFactory provides a convenient way to provide factory-style plugins.
|
|
||||||
* Qt plugins provide a singleton object, but a common pattern is for plugins
|
|
||||||
* to generate as many objects of a particular type as the application requires.
|
|
||||||
* By using PluginFactory, you can avoid implementing the factory pattern
|
|
||||||
* yourself.
|
|
||||||
*
|
|
||||||
* PluginFactory also allows plugins to provide multiple different object
|
|
||||||
* types, indexed by keywords.
|
|
||||||
*
|
|
||||||
* The objects created by PluginFactory must inherit QObject, and must have a
|
|
||||||
* standard constructor pattern:
|
|
||||||
* \li if the object is a KPart::Part, it must be of the form
|
|
||||||
* \code
|
|
||||||
* T(QWidget *parentWidget, QObject *parent, const QVariantList &args)
|
|
||||||
* \endcode
|
|
||||||
* \li if it is a QWidget, it must be of the form
|
|
||||||
* \code
|
|
||||||
* T(QWidget *parent, const QVariantList &args)
|
|
||||||
* \endcode
|
|
||||||
* \li otherwise it must be of the form
|
|
||||||
* \code
|
|
||||||
* T(QObject *parent, const QVariantList &args)
|
|
||||||
* \endcode
|
|
||||||
*
|
|
||||||
* You should typically use CALAMARES_PLUGIN_FACTORY_DEFINITION() in your plugin code to
|
|
||||||
* create the factory. The pattern is
|
|
||||||
*
|
|
||||||
* \code
|
|
||||||
* #include "utils/PluginFactory.h"
|
|
||||||
*
|
|
||||||
* class MyPlugin : public PluginInterface
|
|
||||||
* {
|
|
||||||
* public:
|
|
||||||
* MyPlugin(QObject *parent, const QVariantList &args)
|
|
||||||
* : PluginInterface(parent)
|
|
||||||
* {}
|
|
||||||
* };
|
|
||||||
*
|
|
||||||
* CALAMARES_PLUGIN_FACTORY_DEFINITION(MyPluginFactory,
|
|
||||||
* registerPlugin<MyPlugin>();
|
|
||||||
* )
|
|
||||||
* \endcode
|
|
||||||
*
|
|
||||||
* If you want to load a library use KPluginLoader.
|
|
||||||
* The application that wants to instantiate plugin classes can do the following:
|
|
||||||
* \code
|
|
||||||
* PluginFactory *factory = KPluginLoader("libraryname").factory();
|
|
||||||
* if (factory) {
|
|
||||||
* PluginInterface *p1 = factory->create<PluginInterface>(parent);
|
|
||||||
* OtherInterface *p2 = factory->create<OtherInterface>(parent);
|
|
||||||
* NextInterface *p3 = factory->create<NextInterface>("keyword1", parent);
|
|
||||||
* NextInterface *p3 = factory->create<NextInterface>("keyword2", parent);
|
|
||||||
* }
|
|
||||||
* \endcode
|
|
||||||
*
|
|
||||||
* \author Matthias Kretz <kretz\@kde.org>
|
|
||||||
* \author Bernhard Loos <nhuh.put\@web.de>
|
|
||||||
*/
|
|
||||||
class DLLEXPORT PluginFactory : public QObject
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
friend class PluginFactoryPrivate;
|
|
||||||
public:
|
public:
|
||||||
/**
|
explicit CalamaresPluginFactory() : KPluginFactory() {}
|
||||||
* This constructor creates a factory for a plugin.
|
~CalamaresPluginFactory() override;
|
||||||
*/
|
|
||||||
explicit PluginFactory();
|
|
||||||
|
|
||||||
/**
|
/** @brief Create an object from the factory.
|
||||||
* This destroys the PluginFactory.
|
|
||||||
*/
|
|
||||||
virtual ~PluginFactory();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this method to create an object. It will try to create an object which inherits
|
|
||||||
* \p T. If it has multiple choices, you will get a fatal error (kFatal()), so be careful
|
|
||||||
* to request a unique interface or use keywords.
|
|
||||||
*
|
*
|
||||||
* \tparam T The interface for which an object should be created. The object will inherit \p T.
|
* Ignores all the @p args since they are not used. Calls
|
||||||
* \param parent The parent of the object. If \p parent is a widget type, it will also passed
|
* Calamares constructors for the Jobs and ViewSteps.
|
||||||
* to the parentWidget argument of the CreateInstanceFunction for the object.
|
|
||||||
* \returns A pointer to the created object is returned, or 0 if an error occurred.
|
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
|
||||||
T* create( QObject* parent = nullptr );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this method to create an object. It will try to create an object which inherits
|
|
||||||
* \p T and was registered with \p keyword.
|
|
||||||
*
|
|
||||||
* \tparam T The interface for which an object should be created. The object will inherit \p T.
|
|
||||||
* \param keyword The keyword of the object.
|
|
||||||
* \param parent The parent of the object. If \p parent is a widget type, it will also passed
|
|
||||||
* to the parentWidget argument of the CreateInstanceFunction for the object.
|
|
||||||
* \returns A pointer to the created object is returned, or 0 if an error occurred.
|
|
||||||
*/
|
|
||||||
template<typename T>
|
|
||||||
T* create( const QString& keyword, QObject* parent = nullptr );
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void objectCreated( QObject* object );
|
|
||||||
|
|
||||||
protected:
|
|
||||||
/**
|
|
||||||
* Function pointer type to a function that instantiates a plugin.
|
|
||||||
*/
|
|
||||||
typedef QObject* ( *CreateInstanceFunction )( QWidget*, QObject* );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is used to detect the arguments need for the constructor of plugin classes.
|
|
||||||
* You can inherit it, if you want to add new classes and still keep support for the old ones.
|
|
||||||
*/
|
|
||||||
template<class impl>
|
|
||||||
struct InheritanceChecker
|
|
||||||
{
|
|
||||||
CreateInstanceFunction createInstanceFunction( QWidget* )
|
|
||||||
{
|
|
||||||
return &createInstance<impl, QWidget>;
|
|
||||||
}
|
|
||||||
CreateInstanceFunction createInstanceFunction( ... )
|
|
||||||
{
|
|
||||||
return &createInstance<impl, QObject>;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit PluginFactory( PluginFactoryPrivate& dd );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a plugin with the factory. Call this function from the constructor of the
|
|
||||||
* PluginFactory subclass to make the create function able to instantiate the plugin when asked
|
|
||||||
* for an interface the plugin implements.
|
|
||||||
*
|
|
||||||
* \tparam T the name of the plugin class
|
|
||||||
*
|
|
||||||
* \param keyword An optional keyword as unique identifier for the plugin. This allows you to
|
|
||||||
* put more than one plugin with the same interface into the same library using the same
|
|
||||||
* factory. X-KDE-PluginKeyword is a convenient way to specify the keyword in a desktop file.
|
|
||||||
*
|
|
||||||
* \param instanceFunction A function pointer to a function that creates an instance of the
|
|
||||||
* plugin. The default function that will be used depends on the type of interface. If the
|
|
||||||
* interface inherits from
|
|
||||||
* \li \c KParts::Part the function will call
|
|
||||||
* \code
|
|
||||||
* new T(QWidget *parentWidget, QObject *parent)
|
|
||||||
* \endcode
|
|
||||||
* \li \c QWidget the function will call
|
|
||||||
* \code
|
|
||||||
* new T(QWidget *parent)
|
|
||||||
* \endcode
|
|
||||||
* \li else the function will call
|
|
||||||
* \code
|
|
||||||
* new T(QObject *parent)
|
|
||||||
* \endcode
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
void registerPlugin( const QString& keyword = QString(),
|
|
||||||
CreateInstanceFunction instanceFunction
|
|
||||||
= InheritanceChecker<T>().createInstanceFunction( reinterpret_cast<T*>( 0 ) ) )
|
|
||||||
{
|
|
||||||
doRegisterPlugin( keyword, &T::staticMetaObject, instanceFunction );
|
|
||||||
}
|
|
||||||
|
|
||||||
PluginFactoryPrivate* const pd_ptr;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function is called when the factory asked to create an Object.
|
|
||||||
*
|
|
||||||
* You may reimplement it to provide a very flexible factory. This is especially useful to
|
|
||||||
* provide generic factories for plugins implemeted using a scripting language.
|
|
||||||
*
|
|
||||||
* \param iface The staticMetaObject::className() string identifying the plugin interface that
|
|
||||||
* was requested. E.g. for KCModule plugins this string will be "KCModule".
|
|
||||||
* \param parentWidget Only used if the requested plugin is a KPart.
|
|
||||||
* \param parent The parent object for the plugin object.
|
|
||||||
* \param keyword A string that uniquely identifies the plugin. If a KService is used this
|
|
||||||
* keyword is read from the X-KDE-PluginKeyword entry in the .desktop file.
|
|
||||||
*/
|
|
||||||
virtual QObject* create( const char* iface, QWidget* parentWidget, QObject* parent, const QString& keyword );
|
|
||||||
|
|
||||||
template<class impl, class ParentType>
|
template<class impl, class ParentType>
|
||||||
static QObject* createInstance( QWidget* parentWidget, QObject* parent )
|
static QObject *createInstance(QWidget *parentWidget, QObject *parent, const QVariantList &args)
|
||||||
{
|
{
|
||||||
Q_UNUSED( parentWidget )
|
Q_UNUSED(parentWidget);
|
||||||
|
Q_UNUSED(args);
|
||||||
ParentType *p = nullptr;
|
ParentType *p = nullptr;
|
||||||
if ( parent )
|
if (parent) {
|
||||||
{
|
|
||||||
p = qobject_cast<ParentType *>(parent);
|
p = qobject_cast<ParentType *>(parent);
|
||||||
Q_ASSERT(p);
|
Q_ASSERT(p);
|
||||||
}
|
}
|
||||||
return new impl(p);
|
return new impl(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
/** @brief register a plugin
|
||||||
void doRegisterPlugin( const QString& keyword, const QMetaObject* metaObject, CreateInstanceFunction instanceFunction );
|
*
|
||||||
|
* The Calamares version doesn't accept keywords, and uses
|
||||||
|
* the Calamares createInstance() version which ignores
|
||||||
|
* the QVariantList of arguments.
|
||||||
|
*/
|
||||||
|
template<class T>
|
||||||
|
void registerPlugin()
|
||||||
|
{
|
||||||
|
KPluginFactory::registerPlugin<T>(QString(), &createInstance<T, QObject>);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
/** @brief declare a Calamares Plugin Factory
|
||||||
inline T* PluginFactory::create( QObject* parent )
|
*
|
||||||
{
|
* This would be defined as K_PLUGIN_FACTORY_DECLARATION_WITH_BASEFACTORY,
|
||||||
QObject* o = create( T::staticMetaObject.className(),
|
* except that does not actually use the base factory class that is
|
||||||
parent && parent->isWidgetType() ? reinterpret_cast<QWidget*>( parent ) : nullptr,
|
* passed in.
|
||||||
parent,
|
*/
|
||||||
QString() );
|
#define CALAMARES_PLUGIN_FACTORY_DECLARATION(name) \
|
||||||
|
class name : public CalamaresPluginFactory \
|
||||||
|
{ \
|
||||||
|
Q_OBJECT \
|
||||||
|
Q_INTERFACES(KPluginFactory) \
|
||||||
|
Q_PLUGIN_METADATA(IID CalamaresPluginFactory_iid) \
|
||||||
|
public: \
|
||||||
|
explicit name(); \
|
||||||
|
~name(); \
|
||||||
|
};
|
||||||
|
#define CALAMARES_PLUGIN_FACTORY_DEFINITION(name, pluginRegistrations) \
|
||||||
|
K_PLUGIN_FACTORY_DEFINITION_WITH_BASEFACTORY(name,CalamaresPluginFactory,pluginRegistrations)
|
||||||
|
|
||||||
T* t = qobject_cast<T*>( o );
|
|
||||||
if ( !t )
|
|
||||||
delete o;
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
// Q_DECLARE_INTERFACE( Calamares::PluginFactory, CalamaresPluginFactory_iid )
|
||||||
inline T* PluginFactory::create( const QString& keyword, QObject* parent )
|
|
||||||
{
|
|
||||||
QObject* o = create( T::staticMetaObject.className(),
|
|
||||||
parent && parent->isWidgetType() ? reinterpret_cast<QWidget*>( parent ) : nullptr,
|
|
||||||
parent,
|
|
||||||
keyword );
|
|
||||||
|
|
||||||
T* t = qobject_cast<T*>( o );
|
|
||||||
if ( !t )
|
|
||||||
delete o;
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
Q_DECLARE_INTERFACE( Calamares::PluginFactory, CalamaresPluginFactory_iid )
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,55 +0,0 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
|
||||||
*
|
|
||||||
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
|
|
||||||
*
|
|
||||||
* Based on KPluginFactory from KCoreAddons, KDE project
|
|
||||||
* Copyright 2007, Matthias Kretz <kretz@kde.org>
|
|
||||||
* Copyright 2007, Bernhard Loos <nhuh.put@web.de>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef UTILS_PLUGINFACTORY_P_H
|
|
||||||
#define UTILS_PLUGINFACTORY_P_H
|
|
||||||
|
|
||||||
#include "PluginFactory.h"
|
|
||||||
|
|
||||||
#include <QtCore/QHash>
|
|
||||||
|
|
||||||
namespace Calamares
|
|
||||||
{
|
|
||||||
|
|
||||||
class PluginFactoryPrivate
|
|
||||||
{
|
|
||||||
Q_DECLARE_PUBLIC( PluginFactory )
|
|
||||||
protected:
|
|
||||||
typedef QPair< const QMetaObject*, PluginFactory::CreateInstanceFunction > Plugin;
|
|
||||||
|
|
||||||
PluginFactoryPrivate()
|
|
||||||
: catalogInitialized( false )
|
|
||||||
, q_ptr( nullptr )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
~PluginFactoryPrivate() {}
|
|
||||||
|
|
||||||
QHash< QString, Plugin > createInstanceHash;
|
|
||||||
QString catalogName;
|
|
||||||
bool catalogInitialized;
|
|
||||||
|
|
||||||
PluginFactory* q_ptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Calamares
|
|
||||||
|
|
||||||
#endif
|
|
@ -75,8 +75,6 @@ calamares_add_library( calamaresui
|
|||||||
VERSION ${CALAMARES_VERSION_SHORT}
|
VERSION ${CALAMARES_VERSION_SHORT}
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package( KF5CoreAddons 5.58 QUIET ) # If it's really new
|
if ( KF5CoreAddons_FOUND AND KF5CoreAddons_VERSION VERSION_GREATER_EQUAL 5.58 )
|
||||||
if ( KF5CoreAddons_FOUND )
|
|
||||||
target_compile_definitions( calamaresui PRIVATE WITH_KOSRelease )
|
target_compile_definitions( calamaresui PRIVATE WITH_KOSRelease )
|
||||||
target_link_libraries( calamaresui PRIVATE KF5::CoreAddons )
|
|
||||||
endif()
|
endif()
|
||||||
|
@ -49,7 +49,7 @@ CppJobModule::loadSelf()
|
|||||||
{
|
{
|
||||||
if ( m_loader )
|
if ( m_loader )
|
||||||
{
|
{
|
||||||
PluginFactory* pf = qobject_cast< PluginFactory* >( m_loader->instance() );
|
CalamaresPluginFactory* pf = qobject_cast< CalamaresPluginFactory* >( m_loader->instance() );
|
||||||
if ( !pf )
|
if ( !pf )
|
||||||
{
|
{
|
||||||
cDebug() << Q_FUNC_INFO << m_loader->errorString();
|
cDebug() << Q_FUNC_INFO << m_loader->errorString();
|
||||||
|
@ -50,7 +50,7 @@ ViewModule::loadSelf()
|
|||||||
{
|
{
|
||||||
if ( m_loader )
|
if ( m_loader )
|
||||||
{
|
{
|
||||||
PluginFactory* pf = qobject_cast< PluginFactory* >( m_loader->instance() );
|
CalamaresPluginFactory* pf = qobject_cast< CalamaresPluginFactory* >( m_loader->instance() );
|
||||||
if ( !pf )
|
if ( !pf )
|
||||||
{
|
{
|
||||||
cWarning() << Q_FUNC_INFO << "No factory:" << m_loader->errorString();
|
cWarning() << Q_FUNC_INFO << "No factory:" << m_loader->errorString();
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
find_package( KPMcore 3.3 )
|
find_package( KPMcore 3.3 )
|
||||||
|
find_package( KF5Config CONFIG )
|
||||||
|
find_package( KF5I18n CONFIG )
|
||||||
|
find_package( KF5WidgetsAddons CONFIG )
|
||||||
|
|
||||||
set( _partition_defs "" )
|
set( _partition_defs "" )
|
||||||
|
|
||||||
if ( KPMcore_FOUND )
|
if ( KPMcore_FOUND AND Qt5DBus_FOUND AND KF5CoreAddons_FOUND AND KF5Config_FOUND )
|
||||||
find_package( Qt5 REQUIRED DBus ) # Needed for KPMCore
|
|
||||||
find_package( KF5 REQUIRED I18n WidgetsAddons ) # Needed for KPMCore
|
|
||||||
|
|
||||||
include_directories( ${KPMCORE_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src/modules/partition )
|
include_directories( ${KPMCORE_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src/modules/partition )
|
||||||
|
|
||||||
if ( KPMcore_VERSION VERSION_GREATER "3.3.0")
|
if ( KPMcore_VERSION VERSION_GREATER "3.3.0")
|
||||||
@ -48,5 +48,9 @@ if ( KPMcore_FOUND )
|
|||||||
target_compile_definitions( fsresizertest PRIVATE ${_partition_defs} )
|
target_compile_definitions( fsresizertest PRIVATE ${_partition_defs} )
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
|
if ( NOT KPMcore_FOUND )
|
||||||
calamares_skip_module( "fsresizer (missing suitable KPMcore)" )
|
calamares_skip_module( "fsresizer (missing suitable KPMcore)" )
|
||||||
|
else()
|
||||||
|
calamares_skip_module( "fsresizer (missing dependencies for KPMcore)" )
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
@ -22,11 +22,11 @@ set_package_properties(
|
|||||||
KPMcore PROPERTIES
|
KPMcore PROPERTIES
|
||||||
PURPOSE "For partitioning module"
|
PURPOSE "For partitioning module"
|
||||||
)
|
)
|
||||||
|
find_package( KF5Config CONFIG )
|
||||||
|
find_package( KF5I18n CONFIG )
|
||||||
|
find_package( KF5WidgetsAddons CONFIG )
|
||||||
|
|
||||||
if ( KPMcore_FOUND )
|
if ( KPMcore_FOUND AND Qt5DBus_FOUND AND KF5CoreAddons_FOUND AND KF5Config_FOUND )
|
||||||
find_package( Qt5 REQUIRED DBus )
|
|
||||||
find_package( KF5 REQUIRED Config CoreAddons I18n WidgetsAddons )
|
|
||||||
|
|
||||||
if ( KPMcore_VERSION VERSION_GREATER "3.3.0")
|
if ( KPMcore_VERSION VERSION_GREATER "3.3.0")
|
||||||
list( APPEND _partition_defs WITH_KPMCORE331API) # kpmcore > 3.3.0 with deprecations
|
list( APPEND _partition_defs WITH_KPMCORE331API) # kpmcore > 3.3.0 with deprecations
|
||||||
endif()
|
endif()
|
||||||
@ -106,5 +106,9 @@ if ( KPMcore_FOUND )
|
|||||||
SHARED_LIB
|
SHARED_LIB
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
|
if ( NOT KPMcore_FOUND )
|
||||||
calamares_skip_module( "partition (missing suitable KPMcore)" )
|
calamares_skip_module( "partition (missing suitable KPMcore)" )
|
||||||
|
else()
|
||||||
|
calamares_skip_module( "partition (missing dependencies for KPMcore)" )
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
Loading…
Reference in New Issue
Block a user