From 35f4a81768685e109aa2e822f2a93c5312b50f67 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 16 Apr 2021 14:29:39 +0200 Subject: [PATCH] [libcalamares] Extend packages service API - convenience method to install a (string) list of packages (doesn't do the installation, but adds to GS the list, so that the packages module can handle it). --- src/libcalamares/packages/Globals.cpp | 34 +++++++++++++++++++++------ src/libcalamares/packages/Globals.h | 8 +++++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/libcalamares/packages/Globals.cpp b/src/libcalamares/packages/Globals.cpp index c5e882436..aedbc2119 100644 --- a/src/libcalamares/packages/Globals.cpp +++ b/src/libcalamares/packages/Globals.cpp @@ -12,11 +12,11 @@ #include "GlobalStorage.h" #include "utils/Logger.h" -bool -CalamaresUtils::Packages::setGSPackageAdditions( Calamares::GlobalStorage* gs, - const Calamares::ModuleSystem::InstanceKey& module, - const QVariantList& installPackages, - const QVariantList& tryInstallPackages ) +static bool +additions( Calamares::GlobalStorage* gs, + const QString& key, + const QVariantList& installPackages, + const QVariantList& tryInstallPackages ) { static const char PACKAGEOP[] = "packageOperations"; @@ -25,8 +25,6 @@ CalamaresUtils::Packages::setGSPackageAdditions( Calamares::GlobalStorage* gs, QVariantList packageOperations = gs->contains( PACKAGEOP ) ? gs->value( PACKAGEOP ).toList() : QVariantList(); cDebug() << "Existing package operations length" << packageOperations.length(); - const QString key = module.toString(); - // Clear out existing operations for this module, going backwards: // Sometimes we remove an item, and we don't want the index to // fall off the end of the list. @@ -66,3 +64,25 @@ CalamaresUtils::Packages::setGSPackageAdditions( Calamares::GlobalStorage* gs, } return false; } + +bool +CalamaresUtils::Packages::setGSPackageAdditions( Calamares::GlobalStorage* gs, + const Calamares::ModuleSystem::InstanceKey& module, + const QVariantList& installPackages, + const QVariantList& tryInstallPackages ) +{ + return additions( gs, module.toString(), installPackages, tryInstallPackages ); +} + +bool +CalamaresUtils::Packages::setGSPackageAdditions( Calamares::GlobalStorage* gs, + const Calamares::ModuleSystem::InstanceKey& module, + const QStringList& installPackages ) +{ + QVariantList l; + for ( const auto& s : installPackages ) + { + l << s; + } + return additions( gs, module.toString(), l, QVariantList() ); +} diff --git a/src/libcalamares/packages/Globals.h b/src/libcalamares/packages/Globals.h index a47cf5ae1..a83152ff2 100644 --- a/src/libcalamares/packages/Globals.h +++ b/src/libcalamares/packages/Globals.h @@ -28,6 +28,14 @@ bool setGSPackageAdditions( Calamares::GlobalStorage* gs, const Calamares::ModuleSystem::InstanceKey& module, const QVariantList& installPackages, const QVariantList& tryInstallPackages ); +/** @brief Sets the install-packages GS keys for the given module + * + * This replaces previously-set install-packages lists. Use this with + * plain lists of package names. It does not support try-install. + */ +bool setGSPackageAdditions( Calamares::GlobalStorage* gs, + const Calamares::ModuleSystem::InstanceKey& module, + const QStringList& installPackages ); // void setGSPackageRemovals( const Calamares::ModuleSystem::InstanceKey& key, const QVariantList& removePackages ); } // namespace Packages } // namespace CalamaresUtils