Merge branch 'issue-2202' into calamares

FIXES #2202
This commit is contained in:
Adriaan de Groot 2023-10-30 20:08:52 +01:00
commit f55161c06a
5 changed files with 30 additions and 10 deletions

View File

@ -35,7 +35,7 @@ if(BUILD_APPSTREAM)
TYPE OPTIONAL TYPE OPTIONAL
) )
if(AppStreamQt_FOUND) if(AppStreamQt_FOUND)
add_definitions(-DHAVE_APPSTREAM) add_definitions(-DHAVE_APPSTREAM_VERSION=${AppStreamQt_VERSION_MAJOR})
list(APPEND _extra_libraries AppStreamQt) list(APPEND _extra_libraries AppStreamQt)
list(APPEND _extra_src ItemAppStream.cpp) list(APPEND _extra_src ItemAppStream.cpp)
endif() endif()

View File

@ -14,7 +14,7 @@
#include "ItemAppData.h" #include "ItemAppData.h"
#endif #endif
#ifdef HAVE_APPSTREAM #ifdef HAVE_APPSTREAM_VERSION
#include "ItemAppStream.h" #include "ItemAppStream.h"
#include <AppStreamQt/pool.h> #include <AppStreamQt/pool.h>
#include <memory> #include <memory>
@ -257,7 +257,7 @@ fillModel( PackageListModel* model, const QVariantList& items )
return; return;
} }
#ifdef HAVE_APPSTREAM #ifdef HAVE_APPSTREAM_VERSION
std::unique_ptr< AppStream::Pool > pool; std::unique_ptr< AppStream::Pool > pool;
bool poolOk = false; bool poolOk = false;
#endif #endif
@ -284,7 +284,7 @@ fillModel( PackageListModel* model, const QVariantList& items )
} }
else if ( item_map.contains( "appstream" ) ) else if ( item_map.contains( "appstream" ) )
{ {
#ifdef HAVE_APPSTREAM #ifdef HAVE_APPSTREAM_VERSION
if ( !pool ) if ( !pool )
{ {
pool = std::make_unique< AppStream::Pool >(); pool = std::make_unique< AppStream::Pool >();

View File

@ -56,8 +56,20 @@ setScreenshot( QVariantMap& map, const AppStream::Screenshot& screenshot )
/// @brief Interpret an AppStream Component /// @brief Interpret an AppStream Component
static PackageItem static PackageItem
fromComponent( AppStream::Component& component ) fromComponent( AppStream::Pool& pool, AppStream::Component& component )
{ {
#if HAVE_APPSTREAM_VERSION == 0
auto setActiveLocale = [&component](const QString & locale)
{
component.setActiveLocale( locale );
};
#else
auto setActiveLocale = [&pool](const QString & locale)
{
pool.setLocale( locale );
};
#endif
QVariantMap map; QVariantMap map;
map.insert( "id", component.id() ); map.insert( "id", component.id() );
map.insert( "package", component.packageNames().join( "," ) ); map.insert( "package", component.packageNames().join( "," ) );
@ -66,7 +78,7 @@ fromComponent( AppStream::Component& component )
// to any of them; get the en_US locale as "untranslated" and then // to any of them; get the en_US locale as "untranslated" and then
// loop over Calamares locales (since there is no way to query for // loop over Calamares locales (since there is no way to query for
// available locales in the Component) to see if there's anything else. // available locales in the Component) to see if there's anything else.
component.setActiveLocale( QStringLiteral( "en_US" ) ); setActiveLocale( QStringLiteral( "en_US" ) );
QString en_name = component.name(); QString en_name = component.name();
QString en_description = component.description(); QString en_description = component.description();
map.insert( "name", en_name ); map.insert( "name", en_name );
@ -74,7 +86,7 @@ fromComponent( AppStream::Component& component )
for ( const QString& locale : Calamares::Locale::availableTranslations()->localeIds() ) for ( const QString& locale : Calamares::Locale::availableTranslations()->localeIds() )
{ {
component.setActiveLocale( locale ); setActiveLocale( locale );
QString name = component.name(); QString name = component.name();
if ( name != en_name ) if ( name != en_name )
{ {
@ -87,7 +99,11 @@ fromComponent( AppStream::Component& component )
} }
} }
#if HAVE_APPSTREAM_VERSION == 0
auto screenshots = component.screenshots(); auto screenshots = component.screenshots();
#else
auto screenshots = component.screenshotsAll();
#endif
if ( screenshots.count() > 0 ) if ( screenshots.count() > 0 )
{ {
bool done = false; bool done = false;
@ -120,7 +136,11 @@ fromAppStream( AppStream::Pool& pool, const QVariantMap& item_map )
} }
cDebug() << "Loading AppStream data for" << appstreamId; cDebug() << "Loading AppStream data for" << appstreamId;
#if HAVE_APPSTREAM_VERSION == 0
auto itemList = pool.componentsById( appstreamId ); auto itemList = pool.componentsById( appstreamId );
#else
auto itemList = pool.componentsById( appstreamId ).toList();
#endif
if ( itemList.count() < 1 ) if ( itemList.count() < 1 )
{ {
cWarning() << "No AppStream data for" << appstreamId; cWarning() << "No AppStream data for" << appstreamId;
@ -131,7 +151,7 @@ fromAppStream( AppStream::Pool& pool, const QVariantMap& item_map )
cDebug() << "Multiple AppStream data for" << appstreamId << "using first."; cDebug() << "Multiple AppStream data for" << appstreamId << "using first.";
} }
auto r = fromComponent( itemList.first() ); auto r = fromComponent( pool, itemList.first() );
if ( r.isValid() ) if ( r.isValid() )
{ {
QString id = Calamares::getString( item_map, "id" ); QString id = Calamares::getString( item_map, "id" );

View File

@ -12,7 +12,7 @@
#ifdef HAVE_APPDATA #ifdef HAVE_APPDATA
#include "ItemAppData.h" #include "ItemAppData.h"
#endif #endif
#ifdef HAVE_APPSTREAM #ifdef HAVE_APPSTREAM_VERSION
#include "ItemAppStream.h" #include "ItemAppStream.h"
#endif #endif
#include "PackageModel.h" #include "PackageModel.h"

View File

@ -46,7 +46,7 @@ if(BUILD_APPSTREAM)
TYPE OPTIONAL TYPE OPTIONAL
) )
if(AppStreamQt_FOUND) if(AppStreamQt_FOUND)
add_definitions(-DHAVE_APPSTREAM) add_definitions(-DHAVE_APPSTREAM_VERSION=${AppStreamQt_VERSION_MAJOR})
list(APPEND _extra_libraries AppStreamQt) list(APPEND _extra_libraries AppStreamQt)
list(APPEND _extra_src ${_packagechooser}/ItemAppStream.cpp) list(APPEND _extra_src ${_packagechooser}/ItemAppStream.cpp)
endif() endif()