[libcalamares] Rename classes describing Translations
- the name 'Label' was a relic of the class being UI-centered
This commit is contained in:
parent
d6825c4986
commit
bf9f1c95bc
@ -46,14 +46,14 @@ namespace CalamaresUtils
|
||||
namespace Locale
|
||||
{
|
||||
|
||||
Label::Label( QObject* parent )
|
||||
: Label( QString(), LabelFormat::IfNeededWithCountry, parent )
|
||||
Translation::Translation( QObject* parent )
|
||||
: Translation( QString(), LabelFormat::IfNeededWithCountry, parent )
|
||||
{
|
||||
}
|
||||
|
||||
Label::Label( const QString& locale, LabelFormat format, QObject* parent )
|
||||
Translation::Translation( const QString& locale, LabelFormat format, QObject* parent )
|
||||
: QObject( parent )
|
||||
, m_locale( Label::getLocale( locale ) )
|
||||
, m_locale( getLocale( locale ) )
|
||||
, m_localeId( locale.isEmpty() ? m_locale.name() : locale )
|
||||
{
|
||||
auto special = specialCase( locale );
|
||||
@ -80,7 +80,7 @@ Label::Label( const QString& locale, LabelFormat format, QObject* parent )
|
||||
}
|
||||
|
||||
QLocale
|
||||
Label::getLocale( const QString& localeName )
|
||||
Translation::getLocale( const QString& localeName )
|
||||
{
|
||||
if ( localeName.isEmpty() )
|
||||
{
|
||||
|
@ -34,7 +34,7 @@ namespace Locale
|
||||
* - `ca@valencia` is the Catalan dialect spoken in Valencia.
|
||||
* There is no Qt code for it.
|
||||
*/
|
||||
class Label : public QObject
|
||||
class Translation : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -47,7 +47,7 @@ public:
|
||||
};
|
||||
|
||||
/** @brief Empty locale. This uses the system-default locale. */
|
||||
Label( QObject* parent = nullptr );
|
||||
Translation( QObject* parent = nullptr );
|
||||
|
||||
/** @brief Construct from a locale name.
|
||||
*
|
||||
@ -55,7 +55,7 @@ public:
|
||||
* The @p format determines whether the country name is always present
|
||||
* in the label (human-readable form) or only if needed for disambiguation.
|
||||
*/
|
||||
Label( const QString& localeName,
|
||||
Translation( const QString& localeName,
|
||||
LabelFormat format = LabelFormat::IfNeededWithCountry,
|
||||
QObject* parent = nullptr );
|
||||
|
||||
@ -64,7 +64,7 @@ public:
|
||||
*
|
||||
* Locales are sorted by their id, which means the ISO 2-letter code + country.
|
||||
*/
|
||||
bool operator<( const Label& other ) const { return m_localeId < other.m_localeId; }
|
||||
bool operator<( const Translation& other ) const { return m_localeId < other.m_localeId; }
|
||||
|
||||
/** @brief Is this locale English?
|
||||
*
|
||||
@ -96,7 +96,7 @@ public:
|
||||
*/
|
||||
static QLocale getLocale( const QString& localeName );
|
||||
|
||||
protected:
|
||||
private:
|
||||
QLocale m_locale;
|
||||
QString m_localeId; // the locale identifier, e.g. "en_GB"
|
||||
QString m_label; // the native name of the locale
|
||||
|
@ -20,7 +20,7 @@ namespace CalamaresUtils
|
||||
namespace Locale
|
||||
{
|
||||
|
||||
LabelModel::LabelModel( const QStringList& locales, QObject* parent )
|
||||
TranslationsModel::TranslationsModel( const QStringList& locales, QObject* parent )
|
||||
: QAbstractListModel( parent )
|
||||
, m_localeIds( locales )
|
||||
{
|
||||
@ -29,20 +29,20 @@ LabelModel::LabelModel( const QStringList& locales, QObject* parent )
|
||||
|
||||
for ( const auto& l : locales )
|
||||
{
|
||||
m_locales.push_back( new Label( l, Label::LabelFormat::IfNeededWithCountry, this ) );
|
||||
m_locales.push_back( new Translation( l, Translation::LabelFormat::IfNeededWithCountry, this ) );
|
||||
}
|
||||
}
|
||||
|
||||
LabelModel::~LabelModel() {}
|
||||
TranslationsModel::~TranslationsModel() {}
|
||||
|
||||
int
|
||||
LabelModel::rowCount( const QModelIndex& ) const
|
||||
TranslationsModel::rowCount( const QModelIndex& ) const
|
||||
{
|
||||
return m_locales.count();
|
||||
}
|
||||
|
||||
QVariant
|
||||
LabelModel::data( const QModelIndex& index, int role ) const
|
||||
TranslationsModel::data( const QModelIndex& index, int role ) const
|
||||
{
|
||||
if ( ( role != LabelRole ) && ( role != EnglishLabelRole ) )
|
||||
{
|
||||
@ -67,13 +67,13 @@ LabelModel::data( const QModelIndex& index, int role ) const
|
||||
}
|
||||
|
||||
QHash< int, QByteArray >
|
||||
LabelModel::roleNames() const
|
||||
TranslationsModel::roleNames() const
|
||||
{
|
||||
return { { LabelRole, "label" }, { EnglishLabelRole, "englishLabel" } };
|
||||
}
|
||||
|
||||
const Label&
|
||||
LabelModel::locale( int row ) const
|
||||
const Translation&
|
||||
TranslationsModel::locale( int row ) const
|
||||
{
|
||||
if ( ( row < 0 ) || ( row >= m_locales.count() ) )
|
||||
{
|
||||
@ -88,7 +88,7 @@ LabelModel::locale( int row ) const
|
||||
}
|
||||
|
||||
int
|
||||
LabelModel::find( std::function< bool( const Label& ) > predicate ) const
|
||||
TranslationsModel::find( std::function< bool( const Translation& ) > predicate ) const
|
||||
{
|
||||
for ( int row = 0; row < m_locales.count(); ++row )
|
||||
{
|
||||
@ -101,19 +101,19 @@ LabelModel::find( std::function< bool( const Label& ) > predicate ) const
|
||||
}
|
||||
|
||||
int
|
||||
LabelModel::find( std::function< bool( const QLocale& ) > predicate ) const
|
||||
TranslationsModel::find( std::function< bool( const QLocale& ) > predicate ) const
|
||||
{
|
||||
return find( [&]( const Label& l ) { return predicate( l.locale() ); } );
|
||||
return find( [&]( const Translation& l ) { return predicate( l.locale() ); } );
|
||||
}
|
||||
|
||||
int
|
||||
LabelModel::find( const QLocale& locale ) const
|
||||
TranslationsModel::find( const QLocale& locale ) const
|
||||
{
|
||||
return find( [&]( const Label& l ) { return locale == l.locale(); } );
|
||||
return find( [&]( const Translation& l ) { return locale == l.locale(); } );
|
||||
}
|
||||
|
||||
int
|
||||
LabelModel::find( const QString& countryCode ) const
|
||||
TranslationsModel::find( const QString& countryCode ) const
|
||||
{
|
||||
if ( countryCode.length() != 2 )
|
||||
{
|
||||
@ -121,18 +121,18 @@ LabelModel::find( const QString& countryCode ) const
|
||||
}
|
||||
|
||||
auto c_l = countryData( countryCode );
|
||||
int r = find( [&]( const Label& l ) { return ( l.language() == c_l.second ) && ( l.country() == c_l.first ); } );
|
||||
int r = find( [&]( const Translation& l ) { return ( l.language() == c_l.second ) && ( l.country() == c_l.first ); } );
|
||||
if ( r >= 0 )
|
||||
{
|
||||
return r;
|
||||
}
|
||||
return find( [&]( const Label& l ) { return l.language() == c_l.second; } );
|
||||
return find( [&]( const Translation& l ) { return l.language() == c_l.second; } );
|
||||
}
|
||||
|
||||
LabelModel*
|
||||
TranslationsModel*
|
||||
availableTranslations()
|
||||
{
|
||||
static LabelModel* model = new LabelModel( QStringLiteral( CALAMARES_TRANSLATION_LANGUAGES ).split( ';' ) );
|
||||
static TranslationsModel* model = new TranslationsModel( QStringLiteral( CALAMARES_TRANSLATION_LANGUAGES ).split( ';' ) );
|
||||
return model;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ namespace CalamaresUtils
|
||||
namespace Locale
|
||||
{
|
||||
|
||||
class DLLEXPORT LabelModel : public QAbstractListModel
|
||||
class DLLEXPORT TranslationsModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -35,8 +35,8 @@ public:
|
||||
EnglishLabelRole = Qt::UserRole + 1
|
||||
};
|
||||
|
||||
LabelModel( const QStringList& locales, QObject* parent = nullptr );
|
||||
~LabelModel() override;
|
||||
TranslationsModel( const QStringList& locales, QObject* parent = nullptr );
|
||||
~TranslationsModel() override;
|
||||
|
||||
int rowCount( const QModelIndex& parent ) const override;
|
||||
|
||||
@ -48,7 +48,7 @@ public:
|
||||
* This is the backing data for the model; if @p row is out-of-range,
|
||||
* returns a reference to en_US.
|
||||
*/
|
||||
const Label& locale( int row ) const;
|
||||
const Translation& locale( int row ) const;
|
||||
|
||||
/// @brief Returns all of the locale Ids (e.g. en_US) put into this model.
|
||||
const QStringList& localeIds() const { return m_localeIds; }
|
||||
@ -58,14 +58,14 @@ public:
|
||||
* Returns the row number of the first match, or -1 if there isn't one.
|
||||
*/
|
||||
int find( std::function< bool( const QLocale& ) > predicate ) const;
|
||||
int find( std::function< bool( const Label& ) > predicate ) const;
|
||||
int find( std::function< bool( const Translation& ) > predicate ) const;
|
||||
/// @brief Looks for an item using the same locale, -1 if there isn't one
|
||||
int find( const QLocale& ) const;
|
||||
/// @brief Looks for an item that best matches the 2-letter country code
|
||||
int find( const QString& countryCode ) const;
|
||||
|
||||
private:
|
||||
QVector< Label* > m_locales;
|
||||
QVector< Translation* > m_locales;
|
||||
QStringList m_localeIds;
|
||||
};
|
||||
|
||||
@ -79,7 +79,7 @@ private:
|
||||
*
|
||||
* NOTE: While the model is not typed const, it should be. Do not modify.
|
||||
*/
|
||||
DLLEXPORT LabelModel* availableTranslations();
|
||||
DLLEXPORT TranslationsModel* availableTranslations();
|
||||
} // namespace Locale
|
||||
} // namespace CalamaresUtils
|
||||
#endif
|
||||
|
@ -368,9 +368,9 @@ Config::currentTimezoneName() const
|
||||
static inline QString
|
||||
localeLabel( const QString& s )
|
||||
{
|
||||
using CalamaresUtils::Locale::Label;
|
||||
using CalamaresUtils::Locale::Translation;
|
||||
|
||||
Label lang( s, Label::LabelFormat::AlwaysWithCountry );
|
||||
Translation lang( s, Translation::LabelFormat::AlwaysWithCountry );
|
||||
return lang.label();
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ Config::retranslate()
|
||||
emit warningMessageChanged( m_warningMessage );
|
||||
}
|
||||
|
||||
CalamaresUtils::Locale::LabelModel*
|
||||
CalamaresUtils::Locale::TranslationsModel*
|
||||
Config::languagesModel() const
|
||||
{
|
||||
return m_languages;
|
||||
|
@ -27,7 +27,7 @@ class Config : public QObject
|
||||
* This is a list-model, with names and descriptions for the translations
|
||||
* available to Calamares.
|
||||
*/
|
||||
Q_PROPERTY( CalamaresUtils::Locale::LabelModel* languagesModel READ languagesModel CONSTANT FINAL )
|
||||
Q_PROPERTY( CalamaresUtils::Locale::TranslationsModel* languagesModel READ languagesModel CONSTANT FINAL )
|
||||
/** @brief The requirements (from modules) and their checked-status
|
||||
*
|
||||
* The model grows rows over time as each module is checked and its
|
||||
@ -92,7 +92,7 @@ public:
|
||||
QString warningMessage() const;
|
||||
|
||||
public slots:
|
||||
CalamaresUtils::Locale::LabelModel* languagesModel() const;
|
||||
CalamaresUtils::Locale::TranslationsModel* languagesModel() const;
|
||||
void retranslate();
|
||||
|
||||
///@brief The **global** requirements model, from ModuleManager
|
||||
@ -116,7 +116,7 @@ signals:
|
||||
private:
|
||||
void initLanguages();
|
||||
|
||||
CalamaresUtils::Locale::LabelModel* m_languages = nullptr;
|
||||
CalamaresUtils::Locale::TranslationsModel* m_languages = nullptr;
|
||||
std::unique_ptr< QSortFilterProxyModel > m_filtermodel;
|
||||
|
||||
QString m_languageIcon;
|
||||
|
@ -275,5 +275,5 @@ LocaleTwoColumnDelegate::paint( QPainter* painter, const QStyleOptionViewItem& o
|
||||
Qt::AlignRight | Qt::AlignVCenter,
|
||||
option.palette,
|
||||
false,
|
||||
index.data( CalamaresUtils::Locale::LabelModel::EnglishLabelRole ).toString() );
|
||||
index.data( CalamaresUtils::Locale::TranslationsModel::EnglishLabelRole ).toString() );
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ private:
|
||||
|
||||
Ui::WelcomePage* ui;
|
||||
CheckerContainer* m_checkingWidget;
|
||||
CalamaresUtils::Locale::LabelModel* m_languages;
|
||||
CalamaresUtils::Locale::TranslationsModel* m_languages;
|
||||
|
||||
Config* m_conf;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user