commit
c44e221fb6
4
CHANGES
4
CHANGES
@ -20,6 +20,10 @@ This release contains contributions from (alphabetically by first name):
|
|||||||
|
|
||||||
## Modules ##
|
## Modules ##
|
||||||
|
|
||||||
|
* *Welcome* module has improved usability: a standard icon
|
||||||
|
alongside the *Language* label, for improved recognition,
|
||||||
|
and improved language-list display and sorting. #1107
|
||||||
|
|
||||||
|
|
||||||
# 3.2.5 (2019-04-15) #
|
# 3.2.5 (2019-04-15) #
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ set( utilsSources
|
|||||||
utils/CalamaresUtils.cpp
|
utils/CalamaresUtils.cpp
|
||||||
utils/CalamaresUtilsSystem.cpp
|
utils/CalamaresUtilsSystem.cpp
|
||||||
utils/CommandList.cpp
|
utils/CommandList.cpp
|
||||||
|
utils/LocaleLabel.cpp
|
||||||
utils/Logger.cpp
|
utils/Logger.cpp
|
||||||
utils/PluginFactory.cpp
|
utils/PluginFactory.cpp
|
||||||
utils/Retranslator.cpp
|
utils/Retranslator.cpp
|
||||||
|
73
src/libcalamares/utils/LocaleLabel.cpp
Normal file
73
src/libcalamares/utils/LocaleLabel.cpp
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "LocaleLabel.h"
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
|
||||||
|
LocaleLabel::LocaleLabel()
|
||||||
|
: m_locale( QLocale() )
|
||||||
|
{
|
||||||
|
m_localeId = m_locale.name();
|
||||||
|
|
||||||
|
setLabels( QString(), LabelFormat::IfNeededWithCountry );
|
||||||
|
}
|
||||||
|
|
||||||
|
LocaleLabel::LocaleLabel( const QString& locale, LabelFormat format )
|
||||||
|
: m_locale( LocaleLabel::getLocale( locale ) )
|
||||||
|
, m_localeId( locale )
|
||||||
|
{
|
||||||
|
setLabels( locale, format );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LocaleLabel::setLabels( const QString& locale, LabelFormat format )
|
||||||
|
{
|
||||||
|
//: language[name] (country[name])
|
||||||
|
QString longFormat = QObject::tr( "%1 (%2)" );
|
||||||
|
|
||||||
|
QString languageName = m_locale.nativeLanguageName();
|
||||||
|
QString englishName = m_locale.languageToString( m_locale.language() );
|
||||||
|
QString countryName;
|
||||||
|
|
||||||
|
if ( languageName.isEmpty() )
|
||||||
|
languageName = QString( "* %1 (%2)" ).arg( locale, englishName );
|
||||||
|
|
||||||
|
bool needsCountryName = ( format == LabelFormat::AlwaysWithCountry ) ||
|
||||||
|
(locale.contains( '_' ) && QLocale::countriesForLanguage( m_locale.language() ).count() > 1 );
|
||||||
|
|
||||||
|
if ( needsCountryName )
|
||||||
|
countryName = m_locale.nativeCountryName();
|
||||||
|
m_label = needsCountryName ? longFormat.arg( languageName, countryName ) : languageName;
|
||||||
|
m_englishLabel = needsCountryName ? longFormat.arg( englishName, QLocale::countryToString( m_locale.country() ) ) : englishName;
|
||||||
|
}
|
||||||
|
|
||||||
|
QLocale LocaleLabel::getLocale( const QString& localeName )
|
||||||
|
{
|
||||||
|
if ( localeName.contains( "@latin" ) )
|
||||||
|
{
|
||||||
|
QLocale loc( localeName ); // Ignores @latin
|
||||||
|
return QLocale( loc.language(), QLocale::Script::LatinScript, loc.country() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return QLocale( localeName );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
113
src/libcalamares/utils/LocaleLabel.h
Normal file
113
src/libcalamares/utils/LocaleLabel.h
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LIBCALAMARES_LOCALELABEL_H
|
||||||
|
#define LIBCALAMARES_LOCALELABEL_H
|
||||||
|
|
||||||
|
#include <QLocale>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
namespace CalamaresUtils
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Consistent locale (language + country) naming.
|
||||||
|
*
|
||||||
|
* Support class to turn locale names (as used by Calamares's
|
||||||
|
* translation system) into QLocales, and also into consistent
|
||||||
|
* human-readable text labels.
|
||||||
|
*/
|
||||||
|
class LocaleLabel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/** @brief Formatting option for label -- add (country) to label. */
|
||||||
|
enum class LabelFormat { AlwaysWithCountry, IfNeededWithCountry } ;
|
||||||
|
|
||||||
|
/** @brief Empty locale. This uses the system-default locale. */
|
||||||
|
LocaleLabel();
|
||||||
|
|
||||||
|
/** @brief Construct from a locale name.
|
||||||
|
*
|
||||||
|
* The @p localeName should be one that Qt recognizes, e.g. en_US or ar_EY.
|
||||||
|
* The @p format determines whether the country name is always present
|
||||||
|
* in the label (human-readable form) or only if needed for disambiguation.
|
||||||
|
*/
|
||||||
|
LocaleLabel( const QString& localeName, LabelFormat format = LabelFormat::IfNeededWithCountry );
|
||||||
|
|
||||||
|
/** @brief Define a sorting order.
|
||||||
|
*
|
||||||
|
* English (@see isEnglish() -- it means en_US) is sorted at the top.
|
||||||
|
*/
|
||||||
|
bool operator <( const LocaleLabel& other ) const
|
||||||
|
{
|
||||||
|
return m_localeId < other.m_localeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief Is this locale English?
|
||||||
|
*
|
||||||
|
* en_US and en (American English) is defined as English. The Queen's
|
||||||
|
* English -- proper English -- is relegated to non-English status.
|
||||||
|
*/
|
||||||
|
bool isEnglish() const
|
||||||
|
{
|
||||||
|
return m_localeId == QLatin1Literal( "en_US" ) || m_localeId == QLatin1Literal( "en" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief Get the human-readable name for this locale. */
|
||||||
|
QString label() const
|
||||||
|
{
|
||||||
|
return m_label;
|
||||||
|
}
|
||||||
|
/** @brief Get the *English* human-readable name for this locale. */
|
||||||
|
QString englishLabel() const
|
||||||
|
{
|
||||||
|
return m_englishLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief Get the Qt locale. */
|
||||||
|
QLocale locale() const
|
||||||
|
{
|
||||||
|
return m_locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString name() const
|
||||||
|
{
|
||||||
|
return m_locale.name();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief Get a Qt locale for the given @p localeName
|
||||||
|
*
|
||||||
|
* This special-cases `sr@latin`, which is used as a translation
|
||||||
|
* name in Calamares, while Qt recognizes `sr@latn`.
|
||||||
|
*/
|
||||||
|
static QLocale getLocale( const QString& localeName );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void setLabels( const QString& name, LabelFormat format );
|
||||||
|
|
||||||
|
QLocale m_locale;
|
||||||
|
QString m_localeId; // the locale identifier, e.g. "en_GB"
|
||||||
|
QString m_label; // the native name of the locale
|
||||||
|
QString m_englishLabel;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace CalamaresUtils
|
||||||
|
|
||||||
|
#endif // LIBCALAMARES_LOCALELABEL_H
|
@ -262,45 +262,4 @@ clearLayout( QLayout* layout )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LocaleLabel::LocaleLabel( const QString& locale, LabelFormat format )
|
} // namespace
|
||||||
: m_locale( LocaleLabel::getLocale( locale ) )
|
|
||||||
, m_localeId( locale )
|
|
||||||
{
|
|
||||||
//: language[name] (country[name])
|
|
||||||
QString longFormat = QObject::tr( "%1 (%2)" );
|
|
||||||
|
|
||||||
QString sortKey = QLocale::languageToString( m_locale.language() );
|
|
||||||
QString languageName = m_locale.nativeLanguageName();
|
|
||||||
QString countryName;
|
|
||||||
|
|
||||||
if ( languageName.isEmpty() )
|
|
||||||
languageName = QString( QLatin1Literal( "* %1 (%2)" ) ).arg( locale, sortKey );
|
|
||||||
|
|
||||||
bool needsCountryName = ( format == LabelFormat::AlwaysWithCountry ) ||
|
|
||||||
(locale.contains( '_' ) && QLocale::countriesForLanguage( m_locale.language() ).count() > 1 );
|
|
||||||
|
|
||||||
if ( needsCountryName )
|
|
||||||
{
|
|
||||||
sortKey.append( '+' );
|
|
||||||
sortKey.append( QLocale::countryToString( m_locale.country() ) );
|
|
||||||
|
|
||||||
countryName = m_locale.nativeCountryName();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_sortKey = sortKey;
|
|
||||||
m_label = needsCountryName ? longFormat.arg( languageName ).arg( countryName ) : languageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
QLocale LocaleLabel::getLocale( const QString& localeName )
|
|
||||||
{
|
|
||||||
if ( localeName.contains( "@latin" ) )
|
|
||||||
{
|
|
||||||
QLocale loc( localeName ); // Ignores @latin
|
|
||||||
return QLocale( loc.language(), QLocale::Script::LatinScript, loc.country() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return QLocale( localeName );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -127,76 +127,6 @@ constexpr int windowMinimumHeight = 520;
|
|||||||
constexpr int windowPreferredWidth = 1024;
|
constexpr int windowPreferredWidth = 1024;
|
||||||
constexpr int windowPreferredHeight = 520;
|
constexpr int windowPreferredHeight = 520;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Consistent locale (language + country) naming.
|
|
||||||
*
|
|
||||||
* Support class to turn locale names (as used by Calamares's
|
|
||||||
* translation system) into QLocales, and also into consistent
|
|
||||||
* human-readable text labels.
|
|
||||||
*/
|
|
||||||
class LocaleLabel
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/** @brief Formatting option for label -- add (country) to label. */
|
|
||||||
enum class LabelFormat { AlwaysWithCountry, IfNeededWithCountry } ;
|
|
||||||
|
|
||||||
/** @brief Construct from a locale name.
|
|
||||||
*
|
|
||||||
* The @p localeName should be one that Qt recognizes, e.g. en_US or ar_EY.
|
|
||||||
* The @p format determines whether the country name is always present
|
|
||||||
* in the label (human-readable form) or only if needed for disambiguation.
|
|
||||||
*/
|
|
||||||
LocaleLabel( const QString& localeName, LabelFormat format = LabelFormat::IfNeededWithCountry );
|
|
||||||
|
|
||||||
/** @brief Define a sorting order.
|
|
||||||
*
|
|
||||||
* English (@see isEnglish() -- it means en_US) is sorted at the top.
|
|
||||||
*/
|
|
||||||
bool operator <( const LocaleLabel& other ) const
|
|
||||||
{
|
|
||||||
if ( isEnglish() )
|
|
||||||
return !other.isEnglish();
|
|
||||||
if ( other.isEnglish() )
|
|
||||||
return false;
|
|
||||||
return m_sortKey < other.m_sortKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @brief Is this locale English?
|
|
||||||
*
|
|
||||||
* en_US and en (American English) is defined as English. The Queen's
|
|
||||||
* English -- proper English -- is relegated to non-English status.
|
|
||||||
*/
|
|
||||||
bool isEnglish() const
|
|
||||||
{
|
|
||||||
return m_localeId == QLatin1Literal( "en_US" ) || m_localeId == QLatin1Literal( "en" );
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @brief Get the human-readable name for this locale. */
|
|
||||||
QString label() const
|
|
||||||
{
|
|
||||||
return m_label;
|
|
||||||
}
|
|
||||||
/** @brief Get the Qt locale. */
|
|
||||||
QLocale locale() const
|
|
||||||
{
|
|
||||||
return m_locale;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @brief Get a Qt locale for the given @p localeName
|
|
||||||
*
|
|
||||||
* This special-cases `sr@latin`, which is used as a translation
|
|
||||||
* name in Calamares, while Qt recognizes `sr@latn`.
|
|
||||||
*/
|
|
||||||
static QLocale getLocale( const QString& localeName );
|
|
||||||
|
|
||||||
protected:
|
|
||||||
QLocale m_locale;
|
|
||||||
QString m_localeId; // the locale identifier, e.g. "en_GB"
|
|
||||||
QString m_sortKey; // the English name of the locale
|
|
||||||
QString m_label; // the native name of the locale
|
|
||||||
} ;
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace CalamaresUtils
|
} // namespace CalamaresUtils
|
||||||
|
|
||||||
#endif // CALAMARESUTILSGUI_H
|
#endif // CALAMARESUTILSGUI_H
|
||||||
|
@ -19,23 +19,25 @@
|
|||||||
|
|
||||||
#include "LocalePage.h"
|
#include "LocalePage.h"
|
||||||
|
|
||||||
#include "timezonewidget/timezonewidget.h"
|
|
||||||
#include "SetTimezoneJob.h"
|
#include "SetTimezoneJob.h"
|
||||||
#include "utils/CalamaresUtilsGui.h"
|
#include "timezonewidget/timezonewidget.h"
|
||||||
#include "utils/Logger.h"
|
|
||||||
#include "utils/Retranslator.h"
|
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
#include "LCLocaleDialog.h"
|
#include "LCLocaleDialog.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
|
#include "utils/CalamaresUtilsGui.h"
|
||||||
|
#include "utils/LocaleLabel.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/Retranslator.h"
|
||||||
|
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
|
|
||||||
LocalePage::LocalePage( QWidget* parent )
|
LocalePage::LocalePage( QWidget* parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
, m_blockTzWidgetSet( false )
|
, m_blockTzWidgetSet( false )
|
||||||
|
@ -16,9 +16,9 @@ include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )
|
|||||||
|
|
||||||
set( CHECKER_SOURCES
|
set( CHECKER_SOURCES
|
||||||
checker/CheckerContainer.cpp
|
checker/CheckerContainer.cpp
|
||||||
|
checker/GeneralRequirements.cpp
|
||||||
checker/ResultWidget.cpp
|
checker/ResultWidget.cpp
|
||||||
checker/ResultsListWidget.cpp
|
checker/ResultsListWidget.cpp
|
||||||
checker/GeneralRequirements.cpp
|
|
||||||
${PARTMAN_SRC}
|
${PARTMAN_SRC}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,10 +27,13 @@ calamares_add_plugin( welcome
|
|||||||
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
||||||
SOURCES
|
SOURCES
|
||||||
${CHECKER_SOURCES}
|
${CHECKER_SOURCES}
|
||||||
|
LocaleModel.cpp
|
||||||
WelcomeViewStep.cpp
|
WelcomeViewStep.cpp
|
||||||
WelcomePage.cpp
|
WelcomePage.cpp
|
||||||
UI
|
UI
|
||||||
WelcomePage.ui
|
WelcomePage.ui
|
||||||
|
RESOURCES
|
||||||
|
welcome.qrc
|
||||||
LINK_PRIVATE_LIBRARIES
|
LINK_PRIVATE_LIBRARIES
|
||||||
calamaresui
|
calamaresui
|
||||||
${CHECKER_LINK_LIBRARIES}
|
${CHECKER_LINK_LIBRARIES}
|
||||||
|
109
src/modules/welcome/LocaleModel.cpp
Normal file
109
src/modules/welcome/LocaleModel.cpp
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "LocaleModel.h"
|
||||||
|
|
||||||
|
LocaleModel::LocaleModel( const QStringList& locales, QObject* parent )
|
||||||
|
: QAbstractListModel( parent )
|
||||||
|
{
|
||||||
|
Q_ASSERT( locales.count() > 0 );
|
||||||
|
m_locales.reserve( locales.count() );
|
||||||
|
|
||||||
|
for ( const auto& l : locales )
|
||||||
|
m_locales.push_back( CalamaresUtils::LocaleLabel( l ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
LocaleModel::~LocaleModel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
LocaleModel::rowCount( const QModelIndex& ) const
|
||||||
|
{
|
||||||
|
return m_locales.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant
|
||||||
|
LocaleModel::data( const QModelIndex& index, int role ) const
|
||||||
|
{
|
||||||
|
if ( ( role != LabelRole ) && ( role != EnglishLabelRole ) )
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
if ( !index.isValid() )
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
const auto& locale = m_locales.at( index.row() );
|
||||||
|
switch ( role )
|
||||||
|
{
|
||||||
|
case LabelRole:
|
||||||
|
return locale.label();
|
||||||
|
case EnglishLabelRole:
|
||||||
|
return locale.englishLabel();
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const CalamaresUtils::LocaleLabel&
|
||||||
|
LocaleModel::locale( int row )
|
||||||
|
{
|
||||||
|
if ( ( row < 0 ) || ( row >= m_locales.count() ) )
|
||||||
|
{
|
||||||
|
for ( const auto& l : m_locales )
|
||||||
|
if ( l.isEnglish() )
|
||||||
|
return l;
|
||||||
|
return m_locales[0];
|
||||||
|
}
|
||||||
|
return m_locales[row];
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
LocaleModel::find( std::function<bool ( const LocaleLabel& )> predicate ) const
|
||||||
|
{
|
||||||
|
for ( int row = 0; row < m_locales.count() ; ++row )
|
||||||
|
{
|
||||||
|
if ( predicate( m_locales[row] ) )
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
LocaleModel::find( std::function<bool ( const QLocale& )> predicate ) const
|
||||||
|
{
|
||||||
|
return find( [&]( const LocaleLabel& l )
|
||||||
|
{
|
||||||
|
return predicate( l.locale() );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
LocaleModel::find( const QLocale& locale ) const
|
||||||
|
{
|
||||||
|
return find( [&]( const LocaleLabel& l )
|
||||||
|
{
|
||||||
|
return locale == l.locale();
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LocaleTwoColumnDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||||
|
{
|
||||||
|
QStyledItemDelegate::paint( painter, option, index );
|
||||||
|
option.widget->style()->drawItemText( painter, option.rect, Qt::AlignRight | Qt::AlignVCenter, option.palette, false, index.data( LocaleModel::EnglishLabelRole ).toString() );
|
||||||
|
}
|
73
src/modules/welcome/LocaleModel.h
Normal file
73
src/modules/welcome/LocaleModel.h
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
*
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
|
*
|
||||||
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Calamares is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WELCOME_LOCALEMODEL_H
|
||||||
|
#define WELCOME_LOCALEMODEL_H
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
|
#include "utils/LocaleLabel.h"
|
||||||
|
|
||||||
|
class LocaleModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using LocaleLabel = CalamaresUtils::LocaleLabel;
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
LabelRole = Qt::DisplayRole,
|
||||||
|
EnglishLabelRole = Qt::UserRole + 1
|
||||||
|
};
|
||||||
|
|
||||||
|
LocaleModel( const QStringList& locales, QObject* parent = nullptr );
|
||||||
|
virtual ~LocaleModel() override;
|
||||||
|
|
||||||
|
int rowCount( const QModelIndex& parent ) const override;
|
||||||
|
|
||||||
|
QVariant data( const QModelIndex& index, int role ) const override;
|
||||||
|
|
||||||
|
/** @brief Gets locale information for entry #n
|
||||||
|
*
|
||||||
|
* This is the backing data for the model; if @p row is out-of-range,
|
||||||
|
* returns a reference to en_US.
|
||||||
|
*/
|
||||||
|
const LocaleLabel& locale( int row );
|
||||||
|
|
||||||
|
/** @brief Searches for an item that matches @p predicate
|
||||||
|
*
|
||||||
|
* 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 LocaleLabel& )> predicate ) const;
|
||||||
|
int find( const QLocale& ) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVector< LocaleLabel > m_locales;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
class LocaleTwoColumnDelegate : public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using QStyledItemDelegate::QStyledItemDelegate;
|
||||||
|
|
||||||
|
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const override;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
#endif
|
@ -2,7 +2,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||||
* Copyright 2015, Anke Boersma <demm@kaosx.us>
|
* Copyright 2015, Anke Boersma <demm@kaosx.us>
|
||||||
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
|
* Copyright 2017-2019, Adriaan de Groot <groot@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -21,31 +21,32 @@
|
|||||||
#include "WelcomePage.h"
|
#include "WelcomePage.h"
|
||||||
|
|
||||||
#include "ui_WelcomePage.h"
|
#include "ui_WelcomePage.h"
|
||||||
#include "CalamaresVersion.h"
|
#include "LocaleModel.h"
|
||||||
#include "checker/CheckerContainer.h"
|
#include "checker/CheckerContainer.h"
|
||||||
#include "utils/Logger.h"
|
|
||||||
#include "utils/CalamaresUtilsGui.h"
|
|
||||||
#include "utils/Retranslator.h"
|
|
||||||
|
|
||||||
#include "modulesystem/ModuleManager.h"
|
#include "Branding.h"
|
||||||
|
#include "CalamaresVersion.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "ViewManager.h"
|
#include "ViewManager.h"
|
||||||
|
#include "modulesystem/ModuleManager.h"
|
||||||
|
#include "utils/CalamaresUtilsGui.h"
|
||||||
|
#include "utils/LocaleLabel.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
#include "utils/Retranslator.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
|
#include <QComboBox>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QFocusEvent>
|
#include <QFocusEvent>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QComboBox>
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "Branding.h"
|
|
||||||
|
|
||||||
|
|
||||||
WelcomePage::WelcomePage( QWidget* parent )
|
WelcomePage::WelcomePage( QWidget* parent )
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
, ui( new Ui::WelcomePage )
|
, ui( new Ui::WelcomePage )
|
||||||
, m_checkingWidget( new CheckerContainer( this ) )
|
, m_checkingWidget( new CheckerContainer( this ) )
|
||||||
|
, m_languages( nullptr )
|
||||||
{
|
{
|
||||||
connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsResult, m_checkingWidget, &CheckerContainer::requirementsChecked );
|
connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsResult, m_checkingWidget, &CheckerContainer::requirementsChecked );
|
||||||
connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsComplete, m_checkingWidget, &CheckerContainer::requirementsComplete );
|
connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsComplete, m_checkingWidget, &CheckerContainer::requirementsComplete );
|
||||||
@ -123,32 +124,6 @@ WelcomePage::WelcomePage( QWidget* parent )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** @brief Match the combobox of languages with a predicate
|
|
||||||
*
|
|
||||||
* Scans the entries in the @p list (actually a ComboBox) and if one
|
|
||||||
* matches the given @p predicate, returns true and sets @p matchFound
|
|
||||||
* to the locale that matched.
|
|
||||||
*
|
|
||||||
* If none match, returns false and leaves @p matchFound unchanged.
|
|
||||||
*/
|
|
||||||
static
|
|
||||||
bool matchLocale( QComboBox& list, QLocale& matchFound, std::function<bool(const QLocale&)> predicate)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < list.count(); i++)
|
|
||||||
{
|
|
||||||
QLocale thisLocale = list.itemData( i, Qt::UserRole ).toLocale();
|
|
||||||
if ( predicate(thisLocale) )
|
|
||||||
{
|
|
||||||
list.setCurrentIndex( i );
|
|
||||||
cDebug() << Logger::SubEntry << "Matched locale " << thisLocale.name();
|
|
||||||
matchFound = thisLocale;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
WelcomePage::initLanguages()
|
WelcomePage::initLanguages()
|
||||||
{
|
{
|
||||||
@ -156,58 +131,45 @@ WelcomePage::initLanguages()
|
|||||||
ui->languageWidget->clear();
|
ui->languageWidget->clear();
|
||||||
ui->languageWidget->setInsertPolicy( QComboBox::InsertAtBottom );
|
ui->languageWidget->setInsertPolicy( QComboBox::InsertAtBottom );
|
||||||
|
|
||||||
{
|
m_languages = new LocaleModel( QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') );
|
||||||
std::list< CalamaresUtils::LocaleLabel > localeList;
|
ui->languageWidget->setModel( m_languages );
|
||||||
const auto locales = QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';');
|
ui->languageWidget->setItemDelegate( new LocaleTwoColumnDelegate( ui->languageWidget ) );
|
||||||
for ( const QString& locale : locales )
|
|
||||||
{
|
|
||||||
localeList.emplace_back( locale );
|
|
||||||
}
|
|
||||||
|
|
||||||
localeList.sort(); // According to the sortkey, which is english
|
|
||||||
|
|
||||||
for ( const auto& locale : localeList )
|
|
||||||
{
|
|
||||||
ui->languageWidget->addItem( locale.label(), locale.locale() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the best initial translation
|
// Find the best initial translation
|
||||||
QLocale defaultLocale = QLocale( QLocale::system().name() );
|
QLocale defaultLocale = QLocale( QLocale::system().name() );
|
||||||
QLocale matchedLocale;
|
|
||||||
|
|
||||||
cDebug() << "Matching exact locale" << defaultLocale;
|
cDebug() << "Matching locale" << defaultLocale;
|
||||||
bool isTranslationAvailable =
|
int matchedLocaleIndex = m_languages->find(
|
||||||
matchLocale( *(ui->languageWidget), matchedLocale,
|
[&](const QLocale& x){ return x.language() == defaultLocale.language() && x.country() == defaultLocale.country(); } );
|
||||||
[&](const QLocale& x){ return x.language() == defaultLocale.language() && x.country() == defaultLocale.country(); } );
|
|
||||||
|
|
||||||
if ( !isTranslationAvailable )
|
if ( matchedLocaleIndex < 0 )
|
||||||
{
|
{
|
||||||
cDebug() << "Matching approximate locale" << defaultLocale.language();
|
cDebug() << Logger::SubEntry << "Matching approximate locale" << defaultLocale.language();
|
||||||
|
|
||||||
isTranslationAvailable =
|
matchedLocaleIndex = m_languages->find(
|
||||||
matchLocale( *(ui->languageWidget), matchedLocale,
|
[&](const QLocale& x){ return x.language() == defaultLocale.language(); } );
|
||||||
[&](const QLocale& x){ return x.language() == defaultLocale.language(); } ) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !isTranslationAvailable )
|
if ( matchedLocaleIndex < 0 )
|
||||||
{
|
{
|
||||||
QLocale en_us( QLocale::English, QLocale::UnitedStates );
|
QLocale en_us( QLocale::English, QLocale::UnitedStates );
|
||||||
|
|
||||||
cDebug() << "Matching English (US)";
|
cDebug() << Logger::SubEntry << "Matching English (US)";
|
||||||
isTranslationAvailable =
|
matchedLocaleIndex = m_languages->find( en_us );
|
||||||
matchLocale( *(ui->languageWidget), matchedLocale,
|
|
||||||
[&](const QLocale& x){ return x == en_us; } );
|
|
||||||
|
|
||||||
// Now, if it matched, because we didn't match the system locale, switch to the one found
|
// Now, if it matched, because we didn't match the system locale, switch to the one found
|
||||||
if ( isTranslationAvailable )
|
if ( matchedLocaleIndex >= 0 )
|
||||||
QLocale::setDefault( matchedLocale );
|
QLocale::setDefault( m_languages->locale( matchedLocaleIndex ).locale() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isTranslationAvailable )
|
if ( matchedLocaleIndex >= 0 )
|
||||||
CalamaresUtils::installTranslator( matchedLocale.name(),
|
{
|
||||||
Calamares::Branding::instance()->translationsPathPrefix(),
|
QString name = m_languages->locale( matchedLocaleIndex ).name();
|
||||||
qApp );
|
cDebug() << Logger::SubEntry << "Matched with index" << matchedLocaleIndex << name;
|
||||||
|
|
||||||
|
CalamaresUtils::installTranslator( name, Calamares::Branding::instance()->translationsPathPrefix(), qApp );
|
||||||
|
ui->languageWidget->setCurrentIndex( matchedLocaleIndex );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
cWarning() << "No available translation matched" << defaultLocale;
|
cWarning() << "No available translation matched" << defaultLocale;
|
||||||
|
|
||||||
@ -216,7 +178,7 @@ WelcomePage::initLanguages()
|
|||||||
this,
|
this,
|
||||||
[&]( int newIndex )
|
[&]( int newIndex )
|
||||||
{
|
{
|
||||||
QLocale selectedLocale = ui->languageWidget->itemData( newIndex, Qt::UserRole ).toLocale();
|
const auto& selectedLocale = m_languages->locale( newIndex ).locale();
|
||||||
cDebug() << "Selected locale" << selectedLocale;
|
cDebug() << "Selected locale" << selectedLocale;
|
||||||
|
|
||||||
QLocale::setDefault( selectedLocale );
|
QLocale::setDefault( selectedLocale );
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -27,6 +28,7 @@ class WelcomePage;
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CheckerContainer;
|
class CheckerContainer;
|
||||||
|
class LocaleModel;
|
||||||
|
|
||||||
class WelcomePage : public QWidget
|
class WelcomePage : public QWidget
|
||||||
{
|
{
|
||||||
@ -34,19 +36,24 @@ class WelcomePage : public QWidget
|
|||||||
public:
|
public:
|
||||||
explicit WelcomePage( QWidget* parent = nullptr );
|
explicit WelcomePage( QWidget* parent = nullptr );
|
||||||
|
|
||||||
|
/// @brief Configure the buttons for URLs from the branding configuration
|
||||||
void setUpLinks( bool showSupportUrl,
|
void setUpLinks( bool showSupportUrl,
|
||||||
bool showKnownIssuesUrl,
|
bool showKnownIssuesUrl,
|
||||||
bool showReleaseNotesUrl );
|
bool showReleaseNotesUrl );
|
||||||
|
|
||||||
|
/// @brief Results of requirements checking
|
||||||
bool verdict() const;
|
bool verdict() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus
|
void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/// @brief Fill the list of languages with the available translations
|
||||||
void initLanguages();
|
void initLanguages();
|
||||||
|
|
||||||
Ui::WelcomePage* ui;
|
Ui::WelcomePage* ui;
|
||||||
CheckerContainer* m_checkingWidget;
|
CheckerContainer* m_checkingWidget;
|
||||||
|
LocaleModel *m_languages;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WELCOMEPAGE_H
|
#endif // WELCOMEPAGE_H
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Select language</string>
|
||||||
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0">
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0">
|
||||||
@ -46,7 +49,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="0,1,2,1,0">
|
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="0,0,2,0">
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer_3">
|
<spacer name="horizontalSpacer_3">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
@ -64,21 +67,15 @@
|
|||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="sizePolicy">
|
<property name="toolTip">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<string>Select language</string>
|
||||||
<horstretch>1</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Language:</string>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="pixmap">
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
<pixmap resource="welcome.qrc">:/welcome/language-icon-48px.png</pixmap>
|
||||||
</property>
|
|
||||||
<property name="buddy">
|
|
||||||
<cstring>languageWidget</cstring>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -92,19 +89,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<spacer name="horizontalSpacer_5">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer_4">
|
<spacer name="horizontalSpacer_4">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
@ -217,6 +201,8 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources>
|
||||||
|
<include location="welcome.qrc"/>
|
||||||
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
BIN
src/modules/welcome/language-icon-128px.png
Normal file
BIN
src/modules/welcome/language-icon-128px.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.5 KiB |
BIN
src/modules/welcome/language-icon-48px.png
Normal file
BIN
src/modules/welcome/language-icon-48px.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
6
src/modules/welcome/welcome.qrc
Normal file
6
src/modules/welcome/welcome.qrc
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="welcome">
|
||||||
|
<file>language-icon-128px.png</file>
|
||||||
|
<file>language-icon-48px.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
Loading…
Reference in New Issue
Block a user