mirror of
https://github.com/parchlinux/calamares.git
synced 2025-02-25 03:15:44 -05:00
[packagechooser] Allow to override some of AppData
- The ID and Screenshot entries might be weird in AppData (in particular, a remove URL) so put those back under the control of Calamares even when using AppData as the source of descriptions.
This commit is contained in:
parent
d72391942f
commit
6ddae94628
3 changed files with 28 additions and 5 deletions
|
@ -234,7 +234,7 @@ PackageChooserViewStep::fillModel( const QVariantList& items )
|
|||
|
||||
if ( item_map.contains( "appdata" ) )
|
||||
{
|
||||
m_model->addPackage( PackageItem::fromAppData( CalamaresUtils::getString( item_map, "appdata" ) ) );
|
||||
m_model->addPackage( PackageItem::fromAppData( item_map ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -257,9 +257,15 @@ getNameAndSummary( const QDomNode& n )
|
|||
#endif
|
||||
|
||||
PackageItem
|
||||
PackageItem::fromAppData( const QString& fileName )
|
||||
PackageItem::fromAppData( const QVariantMap& item_map )
|
||||
{
|
||||
#ifdef HAVE_XML
|
||||
QString fileName = CalamaresUtils::getString( item_map, "appdata" );
|
||||
if ( fileName.isEmpty() )
|
||||
{
|
||||
cWarning() << "Can't load AppData without a suitable key.";
|
||||
return PackageItem();
|
||||
}
|
||||
cDebug() << "Loading AppData XML from" << fileName;
|
||||
|
||||
QDomDocument doc = loadAppData( fileName );
|
||||
|
@ -271,17 +277,28 @@ PackageItem::fromAppData( const QString& fileName )
|
|||
QDomElement componentNode = doc.documentElement();
|
||||
if ( !componentNode.isNull() && componentNode.tagName() == "component" )
|
||||
{
|
||||
QString id = getChildText( componentNode, "id" );
|
||||
// An "id" entry in the Calamares config overrides ID in the AppData
|
||||
QString id = CalamaresUtils::getString( item_map, "id" );
|
||||
if ( id.isEmpty() )
|
||||
{
|
||||
id = getChildText( componentNode, "id" );
|
||||
}
|
||||
if ( id.isEmpty() )
|
||||
{
|
||||
return PackageItem();
|
||||
}
|
||||
|
||||
QString screenshotPath = getScreenshotPath( componentNode );
|
||||
// A "screenshot" entry in the Calamares config overrides AppData
|
||||
QString screenshotPath = CalamaresUtils::getString( item_map, "screenshot" );
|
||||
if ( screenshotPath.isEmpty() )
|
||||
{
|
||||
screenshotPath = getScreenshotPath( componentNode );
|
||||
}
|
||||
|
||||
QVariantMap map = getNameAndSummary( componentNode );
|
||||
map.insert( "id", id );
|
||||
map.insert( "screenshot", screenshotPath );
|
||||
|
||||
return PackageItem( map );
|
||||
}
|
||||
|
||||
|
|
|
@ -82,11 +82,17 @@ struct PackageItem
|
|||
bool isValid() const { return !name.isEmpty(); }
|
||||
|
||||
/** @brief Loads an AppData XML file and returns a PackageItem
|
||||
*
|
||||
* The @p map must have a key *appdata*. That is used as the
|
||||
* primary source of information, but keys *id* and *screenshotPath*
|
||||
* may be used to override parts of the AppData -- so that the
|
||||
* ID is under the control of Calamares, and the screenshot can be
|
||||
* forced to a local path available on the installation medium.
|
||||
*
|
||||
* Requires XML support in libcalamares, if not present will
|
||||
* return invalid PackageItems.
|
||||
*/
|
||||
static PackageItem fromAppData( const QString& filename );
|
||||
static PackageItem fromAppData( const QVariantMap& map );
|
||||
};
|
||||
|
||||
using PackageList = QVector< PackageItem >;
|
||||
|
|
Loading…
Add table
Reference in a new issue