From 00deeec8c88d1c28722d2d22ecffe98951d31674 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 24 Jan 2020 17:47:06 +0100 Subject: [PATCH] [libcalamaresui] Use InstanceKey instead of strings - Replace return type of Module::instanceKey() by the structured ModuleSystem::InstanceKey type - Chase API breakage --- src/calamares/progresstree/ViewStepItem.cpp | 2 +- src/libcalamares/CppJob.cpp | 2 +- src/libcalamares/CppJob.h | 15 +++++++----- src/libcalamaresui/modulesystem/Module.h | 2 +- src/libcalamaresui/viewpages/ViewStep.cpp | 2 +- src/libcalamaresui/viewpages/ViewStep.h | 23 ++++++++++--------- .../packagechooser/PackageChooserViewStep.cpp | 3 +-- 7 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/calamares/progresstree/ViewStepItem.cpp b/src/calamares/progresstree/ViewStepItem.cpp index 27e56ef55..885b81dfc 100644 --- a/src/calamares/progresstree/ViewStepItem.cpp +++ b/src/calamares/progresstree/ViewStepItem.cpp @@ -67,7 +67,7 @@ ViewStepItem::data( int role ) const toolTip.append( QString( "
Status:\t%1" ).arg( m_step->prettyStatus() ) ); toolTip.append( QString( "
Source:\t%1" ) - .arg( m_step->moduleInstanceKey().isEmpty() ? "built-in" : m_step->moduleInstanceKey() ) ); + .arg( m_step->moduleInstanceKey().isValid() ? m_step->moduleInstanceKey().toString() : QStringLiteral("built-in") ) ); } else { diff --git a/src/libcalamares/CppJob.cpp b/src/libcalamares/CppJob.cpp index 82af344dd..b6b18b1b7 100644 --- a/src/libcalamares/CppJob.cpp +++ b/src/libcalamares/CppJob.cpp @@ -32,7 +32,7 @@ CppJob::~CppJob() {} void -CppJob::setModuleInstanceKey( const QString& instanceKey ) +CppJob::setModuleInstanceKey( const Calamares::ModuleSystem::InstanceKey& instanceKey ) { m_instanceKey = instanceKey; } diff --git a/src/libcalamares/CppJob.h b/src/libcalamares/CppJob.h index 10ab71649..e4997733e 100644 --- a/src/libcalamares/CppJob.h +++ b/src/libcalamares/CppJob.h @@ -2,6 +2,7 @@ * * Copyright 2014-2015, Teo Mrnjavac * Copyright 2016, Kevin Kofler + * Copyright 2020, Adriaan de Groor * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,12 +21,14 @@ #ifndef CALAMARES_CPPJOB_H #define CALAMARES_CPPJOB_H -#include -#include - #include "DllMacro.h" #include "Job.h" +#include "modulesystem/InstanceKey.h" + +#include +#include + namespace Calamares { @@ -36,13 +39,13 @@ public: explicit CppJob( QObject* parent = nullptr ); virtual ~CppJob(); - void setModuleInstanceKey( const QString& instanceKey ); - QString moduleInstanceKey() const { return m_instanceKey; } + void setModuleInstanceKey( const Calamares::ModuleSystem::InstanceKey& instanceKey ); + Calamares::ModuleSystem::InstanceKey moduleInstanceKey() const { return m_instanceKey; } virtual void setConfigurationMap( const QVariantMap& configurationMap ); protected: - QString m_instanceKey; + Calamares::ModuleSystem::InstanceKey m_instanceKey; }; } // namespace Calamares diff --git a/src/libcalamaresui/modulesystem/Module.h b/src/libcalamaresui/modulesystem/Module.h index ec316bece..bf2f1cb5d 100644 --- a/src/libcalamaresui/modulesystem/Module.h +++ b/src/libcalamaresui/modulesystem/Module.h @@ -101,7 +101,7 @@ public: * For instance, "partition\@partition" (default configuration) or * "locale\@someconfig" (custom configuration) */ - QString instanceKey() const { return m_key.toString(); } + ModuleSystem::InstanceKey instanceKey() const { return m_key; } /** * @brief location returns the full path of this module's directory. diff --git a/src/libcalamaresui/viewpages/ViewStep.cpp b/src/libcalamaresui/viewpages/ViewStep.cpp index 7fe7ff88d..11cfa2beb 100644 --- a/src/libcalamaresui/viewpages/ViewStep.cpp +++ b/src/libcalamaresui/viewpages/ViewStep.cpp @@ -66,7 +66,7 @@ ViewStep::back() void -ViewStep::setModuleInstanceKey( const QString& instanceKey ) +ViewStep::setModuleInstanceKey( const Calamares::ModuleSystem::InstanceKey& instanceKey ) { m_instanceKey = instanceKey; } diff --git a/src/libcalamaresui/viewpages/ViewStep.h b/src/libcalamaresui/viewpages/ViewStep.h index 8c5020f83..c5903d6f5 100644 --- a/src/libcalamaresui/viewpages/ViewStep.h +++ b/src/libcalamaresui/viewpages/ViewStep.h @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2015, Teo Mrnjavac - * Copyright 2017, Adriaan de Groot + * Copyright 2017, 2020, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,15 +20,16 @@ #ifndef VIEWSTEP_H #define VIEWSTEP_H -#include -#include -#include - #include "Job.h" #include "UiDllMacro.h" +#include "modulesystem/InstanceKey.h" #include "modulesystem/Requirement.h" +#include +#include +#include + namespace Calamares { @@ -36,9 +37,9 @@ namespace Calamares * @brief The ViewStep class is the base class for all view modules. * A view module is a Calamares module which has at least one UI page (exposed as * ViewStep::widget), and can optionally create Calamares jobs at runtime. - * As of early 2017, a view module can be implemented by deriving from ViewStep - * in C++ (as a Qt Plugin) or in Python with the PythonQt interface (which also - * mimics the ViewStep class). + * As of early 2020, a view module can be implemented by deriving from ViewStep + * in C++ (as a Qt Plugin or a Qml ViewStep) or in Python with the PythonQt interface + * (which also mimics the ViewStep class). * * A ViewStep can describe itself in human-readable format for the SummaryPage * (which shows all of the things which have been collected to be done in the @@ -129,8 +130,8 @@ public: */ virtual JobList jobs() const = 0; - void setModuleInstanceKey( const QString& instanceKey ); - QString moduleInstanceKey() const { return m_instanceKey; } + void setModuleInstanceKey( const Calamares::ModuleSystem::InstanceKey& instanceKey ); + Calamares::ModuleSystem::InstanceKey moduleInstanceKey() const { return m_instanceKey; } virtual void setConfigurationMap( const QVariantMap& configurationMap ); @@ -154,7 +155,7 @@ signals: void enlarge( QSize enlarge ) const; protected: - QString m_instanceKey; + Calamares::ModuleSystem::InstanceKey m_instanceKey; }; using ViewStepList = QList< ViewStep* >; diff --git a/src/modules/packagechooser/PackageChooserViewStep.cpp b/src/modules/packagechooser/PackageChooserViewStep.cpp index c933147ee..759c6eeab 100644 --- a/src/modules/packagechooser/PackageChooserViewStep.cpp +++ b/src/modules/packagechooser/PackageChooserViewStep.cpp @@ -192,8 +192,7 @@ PackageChooserViewStep::setConfigurationMap( const QVariantMap& configurationMap if ( m_id.isEmpty() ) { // Not set, so use the instance id - // TODO: use a stronger type than QString for structured IDs - m_id = moduleInstanceKey().split( '@' ).last(); + m_id = moduleInstanceKey().id(); } bool labels_ok = false;