From d8af11adeee88b41ff210ed9e06ffcfd890cd219 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 20 Aug 2019 04:38:24 -0400 Subject: [PATCH] [packagechooser] Build AppStream Pool first - Don't build a Pool for each PackageItem loaded - Do make it load all languages instead of only the current one --- src/modules/packagechooser/ItemAppStream.cpp | 9 +-------- src/modules/packagechooser/ItemAppStream.h | 7 ++++++- .../packagechooser/PackageChooserViewStep.cpp | 18 +++++++++++++++++- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/modules/packagechooser/ItemAppStream.cpp b/src/modules/packagechooser/ItemAppStream.cpp index 3ee49f7d0..fe4af95b4 100644 --- a/src/modules/packagechooser/ItemAppStream.cpp +++ b/src/modules/packagechooser/ItemAppStream.cpp @@ -96,7 +96,7 @@ fromComponent( AppStream::Component& component ) } PackageItem -fromAppStream( const QVariantMap& item_map ) +fromAppStream( AppStream::Pool& pool, const QVariantMap& item_map ) { QString appstreamId = CalamaresUtils::getString( item_map, "appstream" ); if ( appstreamId.isEmpty() ) @@ -106,13 +106,6 @@ fromAppStream( const QVariantMap& item_map ) } cDebug() << "Loading AppStream data for" << appstreamId; - AppStream::Pool pool; - if ( !pool.load() ) - { - cWarning() << "AppStream load failed" << pool.lastError(); - return PackageItem(); - } - auto itemList = pool.componentsById( appstreamId ); if ( itemList.count() < 1 ) { diff --git a/src/modules/packagechooser/ItemAppStream.h b/src/modules/packagechooser/ItemAppStream.h index 7d820400f..c44b84b06 100644 --- a/src/modules/packagechooser/ItemAppStream.h +++ b/src/modules/packagechooser/ItemAppStream.h @@ -21,6 +21,11 @@ #include "PackageModel.h" +namespace AppStream +{ +class Pool; +} + /** @brief Loads an item from AppStream data. * * The @p map must have a key *appstream*. That is used as the @@ -33,6 +38,6 @@ * Requires AppStreamQt, if not present will return invalid * PackageItems. */ -PackageItem fromAppStream( const QVariantMap& map ); +PackageItem fromAppStream( AppStream::Pool& pool, const QVariantMap& map ); #endif diff --git a/src/modules/packagechooser/PackageChooserViewStep.cpp b/src/modules/packagechooser/PackageChooserViewStep.cpp index bf45c6726..7758986ba 100644 --- a/src/modules/packagechooser/PackageChooserViewStep.cpp +++ b/src/modules/packagechooser/PackageChooserViewStep.cpp @@ -23,6 +23,8 @@ #endif #ifdef HAVE_APPSTREAM #include "ItemAppStream.h" +#include +#include #endif #include "PackageChooserPage.h" #include "PackageModel.h" @@ -209,6 +211,11 @@ PackageChooserViewStep::fillModel( const QVariantList& items ) return; } +#ifdef HAVE_APPSTREAM + std::unique_ptr< AppStream::Pool > pool; + bool poolOk = false; +#endif + cDebug() << "Loading PackageChooser model items from config"; int item_index = 0; for ( const auto& item_it : items ) @@ -232,7 +239,16 @@ PackageChooserViewStep::fillModel( const QVariantList& items ) else if ( item_map.contains( "appstream" ) ) { #ifdef HAVE_APPSTREAM - m_model->addPackage( fromAppStream( item_map ) ); + if ( !pool ) + { + pool = std::make_unique< AppStream::Pool >(); + pool->setLocale( QStringLiteral( "ALL" ) ); + poolOk = pool->load(); + } + if ( pool && poolOk ) + { + m_model->addPackage( fromAppStream( *pool, item_map ) ); + } #else cWarning() << "Loading AppStream data is not supported."; #endif