From 18579524312687e0c013b8bb5cf6bebb18b082b1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 10 May 2019 12:06:10 -0400 Subject: [libcalamares] Add convenience accessor for translations - Which translations are available is a global property of Calamares itself, not of the plugins, so getting the model of available translations should live there. Move the relevant code (which is simple) from the Welcome module. --- src/libcalamares/locale/LabelModel.cpp | 8 ++++++++ src/libcalamares/locale/LabelModel.h | 14 +++++++++++++- src/modules/welcome/WelcomePage.cpp | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/locale/LabelModel.cpp b/src/libcalamares/locale/LabelModel.cpp index 90475cb0e..ac931620d 100644 --- a/src/libcalamares/locale/LabelModel.cpp +++ b/src/libcalamares/locale/LabelModel.cpp @@ -18,6 +18,8 @@ #include "LabelModel.h" +#include "CalamaresVersion.h" // For the list of translations + namespace CalamaresUtils::Locale { @@ -104,4 +106,10 @@ LabelModel::find( const QLocale& locale ) const } ); } +LabelModel* const availableTranslations() +{ + static LabelModel model( QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') ); + return &model; +} + } // namespace diff --git a/src/libcalamares/locale/LabelModel.h b/src/libcalamares/locale/LabelModel.h index c807e6016..6b4f41343 100644 --- a/src/libcalamares/locale/LabelModel.h +++ b/src/libcalamares/locale/LabelModel.h @@ -30,7 +30,7 @@ namespace CalamaresUtils {} namespace CalamaresUtils::Locale { -DLLEXPORT class LabelModel : public QAbstractListModel +class DLLEXPORT LabelModel : public QAbstractListModel { public: enum @@ -65,5 +65,17 @@ private: QVector< Label > m_locales; } ; +/** @brief Returns a model with all available translations. + * + * The translations are set when Calamares is compiled; the list + * is provided by CMake via the CALAMARES_TRANSLATION_LANGUAGES + * #define. + * + * This model is a singleton and can be shared. + * + * NOTE: While the model is not typed const, it should be. Do not modify. + */ +DLLEXPORT LabelModel* const availableTranslations(); + } // namespace #endif diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index 11a17c2f0..c7d169c92 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -131,7 +131,7 @@ WelcomePage::initLanguages() ui->languageWidget->clear(); ui->languageWidget->setInsertPolicy( QComboBox::InsertAtBottom ); - m_languages = new CalamaresUtils::Locale::LabelModel( QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') ); + m_languages = CalamaresUtils::Locale::availableTranslations(); ui->languageWidget->setModel( m_languages ); ui->languageWidget->setItemDelegate( new LocaleTwoColumnDelegate( ui->languageWidget ) ); -- cgit v1.2.2