commit
c44e221fb6
4
CHANGES
4
CHANGES
@ -20,6 +20,10 @@ This release contains contributions from (alphabetically by first name):
|
||||
|
||||
## 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) #
|
||||
|
||||
|
@ -23,6 +23,7 @@ set( utilsSources
|
||||
utils/CalamaresUtils.cpp
|
||||
utils/CalamaresUtilsSystem.cpp
|
||||
utils/CommandList.cpp
|
||||
utils/LocaleLabel.cpp
|
||||
utils/Logger.cpp
|
||||
utils/PluginFactory.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 )
|
||||
: 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 );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
@ -127,76 +127,6 @@ constexpr int windowMinimumHeight = 520;
|
||||
constexpr int windowPreferredWidth = 1024;
|
||||
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
|
||||
|
||||
#endif // CALAMARESUTILSGUI_H
|
||||
|
@ -19,23 +19,25 @@
|
||||
|
||||
#include "LocalePage.h"
|
||||
|
||||
#include "timezonewidget/timezonewidget.h"
|
||||
#include "SetTimezoneJob.h"
|
||||
#include "utils/CalamaresUtilsGui.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Retranslator.h"
|
||||
#include "timezonewidget/timezonewidget.h"
|
||||
|
||||
#include "GlobalStorage.h"
|
||||
#include "JobQueue.h"
|
||||
#include "LCLocaleDialog.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#include "utils/CalamaresUtilsGui.h"
|
||||
#include "utils/LocaleLabel.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Retranslator.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QProcess>
|
||||
|
||||
|
||||
LocalePage::LocalePage( QWidget* parent )
|
||||
: QWidget( parent )
|
||||
, m_blockTzWidgetSet( false )
|
||||
|
@ -16,9 +16,9 @@ include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )
|
||||
|
||||
set( CHECKER_SOURCES
|
||||
checker/CheckerContainer.cpp
|
||||
checker/GeneralRequirements.cpp
|
||||
checker/ResultWidget.cpp
|
||||
checker/ResultsListWidget.cpp
|
||||
checker/GeneralRequirements.cpp
|
||||
${PARTMAN_SRC}
|
||||
)
|
||||
|
||||
@ -27,10 +27,13 @@ calamares_add_plugin( welcome
|
||||
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
||||
SOURCES
|
||||
${CHECKER_SOURCES}
|
||||
LocaleModel.cpp
|
||||
WelcomeViewStep.cpp
|
||||
WelcomePage.cpp
|
||||
UI
|
||||
WelcomePage.ui
|
||||
RESOURCES
|
||||
welcome.qrc
|
||||
LINK_PRIVATE_LIBRARIES
|
||||
calamaresui
|
||||
${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 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -21,31 +21,32 @@
|
||||
#include "WelcomePage.h"
|
||||
|
||||
#include "ui_WelcomePage.h"
|
||||
#include "CalamaresVersion.h"
|
||||
#include "LocaleModel.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 "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 <QBoxLayout>
|
||||
#include <QComboBox>
|
||||
#include <QDesktopServices>
|
||||
#include <QFocusEvent>
|
||||
#include <QLabel>
|
||||
#include <QComboBox>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "Branding.h"
|
||||
|
||||
|
||||
WelcomePage::WelcomePage( QWidget* parent )
|
||||
: QWidget( parent )
|
||||
, ui( new Ui::WelcomePage )
|
||||
, 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::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
|
||||
WelcomePage::initLanguages()
|
||||
{
|
||||
@ -156,58 +131,45 @@ WelcomePage::initLanguages()
|
||||
ui->languageWidget->clear();
|
||||
ui->languageWidget->setInsertPolicy( QComboBox::InsertAtBottom );
|
||||
|
||||
{
|
||||
std::list< CalamaresUtils::LocaleLabel > localeList;
|
||||
const auto locales = QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';');
|
||||
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() );
|
||||
}
|
||||
}
|
||||
m_languages = new LocaleModel( QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') );
|
||||
ui->languageWidget->setModel( m_languages );
|
||||
ui->languageWidget->setItemDelegate( new LocaleTwoColumnDelegate( ui->languageWidget ) );
|
||||
|
||||
// Find the best initial translation
|
||||
QLocale defaultLocale = QLocale( QLocale::system().name() );
|
||||
QLocale matchedLocale;
|
||||
|
||||
cDebug() << "Matching exact locale" << defaultLocale;
|
||||
bool isTranslationAvailable =
|
||||
matchLocale( *(ui->languageWidget), matchedLocale,
|
||||
[&](const QLocale& x){ return x.language() == defaultLocale.language() && x.country() == defaultLocale.country(); } );
|
||||
cDebug() << "Matching locale" << defaultLocale;
|
||||
int matchedLocaleIndex = m_languages->find(
|
||||
[&](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 =
|
||||
matchLocale( *(ui->languageWidget), matchedLocale,
|
||||
[&](const QLocale& x){ return x.language() == defaultLocale.language(); } ) ;
|
||||
matchedLocaleIndex = m_languages->find(
|
||||
[&](const QLocale& x){ return x.language() == defaultLocale.language(); } );
|
||||
}
|
||||
|
||||
if ( !isTranslationAvailable )
|
||||
if ( matchedLocaleIndex < 0 )
|
||||
{
|
||||
QLocale en_us( QLocale::English, QLocale::UnitedStates );
|
||||
|
||||
cDebug() << "Matching English (US)";
|
||||
isTranslationAvailable =
|
||||
matchLocale( *(ui->languageWidget), matchedLocale,
|
||||
[&](const QLocale& x){ return x == en_us; } );
|
||||
cDebug() << Logger::SubEntry << "Matching English (US)";
|
||||
matchedLocaleIndex = m_languages->find( en_us );
|
||||
|
||||
// Now, if it matched, because we didn't match the system locale, switch to the one found
|
||||
if ( isTranslationAvailable )
|
||||
QLocale::setDefault( matchedLocale );
|
||||
if ( matchedLocaleIndex >= 0 )
|
||||
QLocale::setDefault( m_languages->locale( matchedLocaleIndex ).locale() );
|
||||
}
|
||||
|
||||
if ( isTranslationAvailable )
|
||||
CalamaresUtils::installTranslator( matchedLocale.name(),
|
||||
Calamares::Branding::instance()->translationsPathPrefix(),
|
||||
qApp );
|
||||
if ( matchedLocaleIndex >= 0 )
|
||||
{
|
||||
QString name = m_languages->locale( matchedLocaleIndex ).name();
|
||||
cDebug() << Logger::SubEntry << "Matched with index" << matchedLocaleIndex << name;
|
||||
|
||||
CalamaresUtils::installTranslator( name, Calamares::Branding::instance()->translationsPathPrefix(), qApp );
|
||||
ui->languageWidget->setCurrentIndex( matchedLocaleIndex );
|
||||
}
|
||||
else
|
||||
cWarning() << "No available translation matched" << defaultLocale;
|
||||
|
||||
@ -216,7 +178,7 @@ WelcomePage::initLanguages()
|
||||
this,
|
||||
[&]( int newIndex )
|
||||
{
|
||||
QLocale selectedLocale = ui->languageWidget->itemData( newIndex, Qt::UserRole ).toLocale();
|
||||
const auto& selectedLocale = m_languages->locale( newIndex ).locale();
|
||||
cDebug() << "Selected locale" << selectedLocale;
|
||||
|
||||
QLocale::setDefault( selectedLocale );
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* 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
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -27,6 +28,7 @@ class WelcomePage;
|
||||
}
|
||||
|
||||
class CheckerContainer;
|
||||
class LocaleModel;
|
||||
|
||||
class WelcomePage : public QWidget
|
||||
{
|
||||
@ -34,19 +36,24 @@ class WelcomePage : public QWidget
|
||||
public:
|
||||
explicit WelcomePage( QWidget* parent = nullptr );
|
||||
|
||||
/// @brief Configure the buttons for URLs from the branding configuration
|
||||
void setUpLinks( bool showSupportUrl,
|
||||
bool showKnownIssuesUrl,
|
||||
bool showReleaseNotesUrl );
|
||||
|
||||
/// @brief Results of requirements checking
|
||||
bool verdict() const;
|
||||
|
||||
protected:
|
||||
void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus
|
||||
|
||||
private:
|
||||
/// @brief Fill the list of languages with the available translations
|
||||
void initLanguages();
|
||||
|
||||
Ui::WelcomePage* ui;
|
||||
CheckerContainer* m_checkingWidget;
|
||||
LocaleModel *m_languages;
|
||||
};
|
||||
|
||||
#endif // WELCOMEPAGE_H
|
||||
|
@ -13,6 +13,9 @@
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Select language</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0">
|
||||
@ -46,7 +49,7 @@
|
||||
</widget>
|
||||
</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>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
@ -64,21 +67,15 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="toolTip">
|
||||
<string>Select language</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Language:</string>
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>languageWidget</cstring>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="welcome.qrc">:/welcome/language-icon-48px.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -92,19 +89,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
@ -217,6 +201,8 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="welcome.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</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