[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.
This commit is contained in:
Adriaan de Groot 2019-05-10 12:06:10 -04:00
parent 76b45a2740
commit 1857952431
3 changed files with 22 additions and 2 deletions

View file

@ -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

View file

@ -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

View file

@ -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 ) );