[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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString id = CalamaresUtils::getString( item_map, "id" );
|
m_model->addPackage( PackageItem( item_map ) );
|
||||||
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 } );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "PackageModel.h"
|
#include "PackageModel.h"
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/Variant.h"
|
||||||
|
|
||||||
const NamedEnumTable< PackageChooserMode >&
|
const NamedEnumTable< PackageChooserMode >&
|
||||||
roleNames()
|
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 )
|
PackageListModel::PackageListModel( QObject* parent )
|
||||||
: QAbstractListModel( parent )
|
: QAbstractListModel( parent )
|
||||||
@ -90,10 +116,14 @@ PackageListModel::~PackageListModel() {}
|
|||||||
void
|
void
|
||||||
PackageListModel::addPackage( PackageItem&& p )
|
PackageListModel::addPackage( PackageItem&& p )
|
||||||
{
|
{
|
||||||
|
// Only add valid packages
|
||||||
|
if ( !p.name.isEmpty() )
|
||||||
|
{
|
||||||
int c = m_packages.count();
|
int c = m_packages.count();
|
||||||
beginInsertRows( QModelIndex(), c, c );
|
beginInsertRows( QModelIndex(), c, c );
|
||||||
m_packages.append( p );
|
m_packages.append( p );
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -56,12 +56,26 @@ struct PackageItem
|
|||||||
*/
|
*/
|
||||||
PackageItem( const QString& id, const QString& package, const QString& name, const QString& description );
|
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,
|
PackageItem( const QString& id,
|
||||||
const QString& package,
|
const QString& package,
|
||||||
const QString& name,
|
const QString& name,
|
||||||
const QString& description,
|
const QString& description,
|
||||||
const QString& screenshotPath );
|
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
|
// TODO: implement this
|
||||||
PackageItem fromAppStream( const QString& filename );
|
PackageItem fromAppStream( const QString& filename );
|
||||||
};
|
};
|
||||||
@ -75,6 +89,10 @@ public:
|
|||||||
PackageListModel( QObject* parent );
|
PackageListModel( QObject* parent );
|
||||||
virtual ~PackageListModel() override;
|
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 );
|
void addPackage( PackageItem&& p );
|
||||||
|
|
||||||
int rowCount( const QModelIndex& index ) const override;
|
int rowCount( const QModelIndex& index ) const override;
|
||||||
|
Loading…
Reference in New Issue
Block a user