[packagechooser] Load translated strings as well
- This makes it possible to put the translations into the config file, and have them displayed when the Calamares language changes.
This commit is contained in:
parent
4febe477cf
commit
6e05a1ef05
@ -232,31 +232,7 @@ PackageChooserViewStep::fillModel( const QVariantList& items )
|
||||
continue;
|
||||
}
|
||||
|
||||
QString id = CalamaresUtils::getString( item_map, "id" );
|
||||
QString package = CalamaresUtils::getString( item_map, "package" );
|
||||
QString name = CalamaresUtils::getString( item_map, "name" );
|
||||
QString description = CalamaresUtils::getString( item_map, "description" );
|
||||
QString screenshot = CalamaresUtils::getString( item_map, "screenshot" );
|
||||
|
||||
if ( name.isEmpty() && id.isEmpty() )
|
||||
{
|
||||
name = tr( "No product" );
|
||||
}
|
||||
else if ( name.isEmpty() )
|
||||
{
|
||||
cWarning() << "PackageChooser item" << id << "has an empty name.";
|
||||
continue;
|
||||
}
|
||||
if ( description.isEmpty() )
|
||||
{
|
||||
description = tr( "No description provided." );
|
||||
}
|
||||
if ( screenshot.isEmpty() )
|
||||
{
|
||||
screenshot = QStringLiteral( ":/images/no-selection.png" );
|
||||
}
|
||||
|
||||
m_model->addPackage( PackageItem { id, package, name, description, screenshot } );
|
||||
m_model->addPackage( PackageItem( item_map ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "PackageModel.h"
|
||||
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Variant.h"
|
||||
|
||||
const NamedEnumTable< PackageChooserMode >&
|
||||
roleNames()
|
||||
@ -73,6 +74,31 @@ PackageItem::PackageItem( const QString& a_id,
|
||||
{
|
||||
}
|
||||
|
||||
PackageItem::PackageItem::PackageItem( const QVariantMap& item_map )
|
||||
: id( CalamaresUtils::getString( item_map, "id" ) )
|
||||
, package( CalamaresUtils::getString( item_map, "package" ) )
|
||||
, name( CalamaresUtils::Locale::TranslatedString( item_map, "name" ) )
|
||||
, description( CalamaresUtils::Locale::TranslatedString( item_map, "description" ) )
|
||||
, screenshot( CalamaresUtils::getString( item_map, "screenshot" ) )
|
||||
{
|
||||
if ( name.isEmpty() && id.isEmpty() )
|
||||
{
|
||||
name = QObject::tr( "No product" );
|
||||
}
|
||||
else if ( name.isEmpty() )
|
||||
{
|
||||
cWarning() << "PackageChooser item" << id << "has an empty name.";
|
||||
}
|
||||
if ( description.isEmpty() )
|
||||
{
|
||||
description = QObject::tr( "No description provided." );
|
||||
}
|
||||
if ( screenshot.isNull() )
|
||||
{
|
||||
screenshot = QPixmap( QStringLiteral( ":/images/no-selection.png" ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PackageListModel::PackageListModel( QObject* parent )
|
||||
: QAbstractListModel( parent )
|
||||
@ -90,10 +116,14 @@ PackageListModel::~PackageListModel() {}
|
||||
void
|
||||
PackageListModel::addPackage( PackageItem&& p )
|
||||
{
|
||||
int c = m_packages.count();
|
||||
beginInsertRows( QModelIndex(), c, c );
|
||||
m_packages.append( p );
|
||||
endInsertRows();
|
||||
// Only add valid packages
|
||||
if ( !p.name.isEmpty() )
|
||||
{
|
||||
int c = m_packages.count();
|
||||
beginInsertRows( QModelIndex(), c, c );
|
||||
m_packages.append( p );
|
||||
endInsertRows();
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -56,12 +56,26 @@ struct PackageItem
|
||||
*/
|
||||
PackageItem( const QString& id, const QString& package, const QString& name, const QString& description );
|
||||
|
||||
/** @brief Creates a PackageItem from given strings.
|
||||
*
|
||||
* Set all the text members and load the screenshot from the given
|
||||
* @p screenshotPath, which may be a QRC path (:/path/in/qrc) or
|
||||
* a filesystem path, whatever QPixmap understands.
|
||||
*/
|
||||
PackageItem( const QString& id,
|
||||
const QString& package,
|
||||
const QString& name,
|
||||
const QString& description,
|
||||
const QString& screenshotPath );
|
||||
|
||||
/** @brief Creates a PackageItem from a QVariantMap
|
||||
*
|
||||
* This is intended for use when loading PackageItems from a
|
||||
* configuration map. It will look up the various keys in the map
|
||||
* and handle translation strings as well.
|
||||
*/
|
||||
PackageItem( const QVariantMap& map );
|
||||
|
||||
// TODO: implement this
|
||||
PackageItem fromAppStream( const QString& filename );
|
||||
};
|
||||
@ -75,6 +89,10 @@ public:
|
||||
PackageListModel( QObject* parent );
|
||||
virtual ~PackageListModel() override;
|
||||
|
||||
/** @brief Add a package @p to the model
|
||||
*
|
||||
* Only valid packages are added -- that is, they must have a name.
|
||||
*/
|
||||
void addPackage( PackageItem&& p );
|
||||
|
||||
int rowCount( const QModelIndex& index ) const override;
|
||||
|
Loading…
Reference in New Issue
Block a user