2020-03-10 22:44:48 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2019-2020, 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 "Config.h"
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
#include "utils/Retranslator.h"
|
|
|
|
#include "Branding.h"
|
|
|
|
#include "Settings.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
|
|
void
|
|
|
|
RequirementsModel::setRequirementsList( const Calamares::RequirementsList& requirements )
|
|
|
|
{
|
2020-03-24 15:26:24 +01:00
|
|
|
CALAMARES_RETRANSLATE_SLOT( &RequirementsModel::retranslate )
|
|
|
|
|
2020-03-10 22:44:48 +01:00
|
|
|
emit beginResetModel();
|
2020-03-24 16:39:29 +01:00
|
|
|
m_requirements = requirements;
|
2020-03-10 22:44:48 +01:00
|
|
|
|
|
|
|
auto isUnSatisfied = []( const Calamares::RequirementEntry& e ) { return !e.satisfied; };
|
|
|
|
auto isMandatoryAndUnSatisfied = []( const Calamares::RequirementEntry& e ) { return e.mandatory && !e.satisfied; };
|
|
|
|
|
2020-03-24 16:39:29 +01:00
|
|
|
m_satisfiedRequirements = std::none_of( m_requirements.begin(), m_requirements.end(), isUnSatisfied );
|
|
|
|
m_satisfiedMandatory = std::none_of( m_requirements.begin(), m_requirements.end(), isMandatoryAndUnSatisfied );
|
2020-03-10 22:44:48 +01:00
|
|
|
|
|
|
|
emit satisfiedRequirementsChanged(m_satisfiedRequirements);
|
|
|
|
emit satisfiedMandatoryChanged();
|
|
|
|
emit endResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
RequirementsModel::rowCount( const QModelIndex& ) const
|
|
|
|
{
|
2020-03-24 16:39:29 +01:00
|
|
|
return m_requirements.count();
|
2020-03-10 22:44:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant
|
|
|
|
RequirementsModel::data( const QModelIndex& index, int role ) const
|
|
|
|
{
|
2020-03-24 16:39:29 +01:00
|
|
|
const auto requirement = m_requirements.at( index.row() );
|
2020-03-10 22:44:48 +01:00
|
|
|
|
|
|
|
switch ( role )
|
|
|
|
{
|
|
|
|
case Roles::Name:
|
|
|
|
return requirement.name;
|
|
|
|
case Roles::Details:
|
|
|
|
return requirement.enumerationText();
|
|
|
|
case Roles::NegatedText:
|
|
|
|
return requirement.negatedText();
|
|
|
|
case Roles::Satisfied:
|
|
|
|
return requirement.satisfied;
|
|
|
|
case Roles::Mandatory:
|
|
|
|
return requirement.mandatory;
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QHash<int, QByteArray>
|
|
|
|
RequirementsModel::roleNames() const
|
|
|
|
{
|
|
|
|
static QHash<int, QByteArray> roles;
|
|
|
|
roles[Roles::Name] = "name";
|
|
|
|
roles[Roles::Details] = "details";
|
|
|
|
roles[Roles::NegatedText] = "negatedText";
|
|
|
|
roles[Roles::Satisfied] = "satisfied";
|
|
|
|
roles[Roles::Mandatory] = "mandatory";
|
|
|
|
return roles;
|
|
|
|
}
|
|
|
|
|
|
|
|
Config::Config( QObject* parent ) : QObject( parent )
|
|
|
|
, m_requirementsModel( new RequirementsModel( this ))
|
|
|
|
, m_languages( CalamaresUtils::Locale::availableTranslations() )
|
|
|
|
{
|
|
|
|
connect(m_requirementsModel, &RequirementsModel::satisfiedRequirementsChanged, this, &Config::setIsNextEnabled);
|
|
|
|
|
|
|
|
initLanguages();
|
|
|
|
|
|
|
|
CALAMARES_RETRANSLATE_SLOT( &Config::retranslate )
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Config::retranslate()
|
|
|
|
{
|
2020-03-24 16:39:29 +01:00
|
|
|
m_genericWelcomeMessage = genericWelcomeMessage().arg( *Calamares::Branding::VersionedName );
|
2020-03-10 22:44:48 +01:00
|
|
|
emit genericWelcomeMessageChanged();
|
|
|
|
|
2020-03-24 15:26:24 +01:00
|
|
|
m_requirementsModel->retranslate();
|
2020-03-10 22:44:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CalamaresUtils::Locale::LabelModel*
|
|
|
|
Config::languagesModel() const
|
|
|
|
{
|
|
|
|
return m_languages;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
Config::languageIcon() const
|
|
|
|
{
|
|
|
|
return m_languageIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Config::initLanguages()
|
|
|
|
{
|
|
|
|
// Find the best initial translation
|
|
|
|
QLocale defaultLocale = QLocale( QLocale::system().name() );
|
|
|
|
|
|
|
|
cDebug() << "Matching locale" << defaultLocale;
|
|
|
|
int matchedLocaleIndex = m_languages->find( [&]( const QLocale& x ) {
|
|
|
|
return x.language() == defaultLocale.language() && x.country() == defaultLocale.country();
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( matchedLocaleIndex < 0 )
|
|
|
|
{
|
|
|
|
cDebug() << Logger::SubEntry << "Matching approximate locale" << defaultLocale.language();
|
|
|
|
|
|
|
|
matchedLocaleIndex
|
|
|
|
= m_languages->find( [&]( const QLocale& x ) { return x.language() == defaultLocale.language(); } );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( matchedLocaleIndex < 0 )
|
|
|
|
{
|
|
|
|
QLocale en_us( QLocale::English, QLocale::UnitedStates );
|
|
|
|
|
|
|
|
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 ( matchedLocaleIndex >= 0 )
|
|
|
|
{
|
|
|
|
QLocale::setDefault( m_languages->locale( matchedLocaleIndex ).locale() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( matchedLocaleIndex >= 0 )
|
|
|
|
{
|
|
|
|
QString name = m_languages->locale( matchedLocaleIndex ).name();
|
|
|
|
cDebug() << Logger::SubEntry << "Matched with index" << matchedLocaleIndex << name;
|
|
|
|
|
|
|
|
CalamaresUtils::installTranslator( name, Calamares::Branding::instance()->translationsDirectory(), qApp );
|
|
|
|
setLocaleIndex( matchedLocaleIndex );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cWarning() << "No available translation matched" << defaultLocale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Config::setCountryCode( const QString& countryCode )
|
|
|
|
{
|
|
|
|
m_countryCode = countryCode;
|
|
|
|
setLocaleIndex(CalamaresUtils::Locale::availableTranslations()->find( m_countryCode ));
|
|
|
|
|
|
|
|
emit countryCodeChanged( m_countryCode );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-03-10 23:56:09 +01:00
|
|
|
Config::setLanguageIcon(const QString &languageIcon )
|
2020-03-10 22:44:48 +01:00
|
|
|
{
|
|
|
|
m_languageIcon = languageIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Config::setLocaleIndex(const int& index)
|
|
|
|
{
|
|
|
|
if(index == m_localeIndex || index > CalamaresUtils::Locale::availableTranslations()->rowCount(QModelIndex()) || index < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_localeIndex = index;
|
|
|
|
|
|
|
|
const auto& selectedLocale = m_languages->locale( m_localeIndex ).locale();
|
|
|
|
cDebug() << "Selected locale" << selectedLocale;
|
|
|
|
|
|
|
|
QLocale::setDefault( selectedLocale );
|
|
|
|
CalamaresUtils::installTranslator(
|
|
|
|
selectedLocale, Calamares::Branding::instance()->translationsDirectory(), qApp );
|
|
|
|
|
|
|
|
emit localeIndexChanged( m_localeIndex );
|
|
|
|
}
|
|
|
|
|
|
|
|
RequirementsModel&
|
|
|
|
Config::requirementsModel() const
|
|
|
|
{
|
|
|
|
return *m_requirementsModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Config::setIsNextEnabled( const bool& isNextEnabled )
|
|
|
|
{
|
|
|
|
m_isNextEnabled = isNextEnabled;
|
|
|
|
emit isNextEnabledChanged( m_isNextEnabled );
|
|
|
|
}
|
|
|
|
|
2020-03-24 16:39:29 +01:00
|
|
|
QString
|
|
|
|
Config::donateUrl() const
|
2020-03-10 22:44:48 +01:00
|
|
|
{
|
|
|
|
return m_donateUrl;
|
|
|
|
}
|
|
|
|
|
2020-03-24 16:39:29 +01:00
|
|
|
void
|
|
|
|
Config::setDonateUrl(const QString& url)
|
2020-03-10 22:44:48 +01:00
|
|
|
{
|
|
|
|
m_donateUrl = url;
|
2020-03-24 15:26:24 +01:00
|
|
|
emit donateUrlChanged();
|
2020-03-10 22:44:48 +01:00
|
|
|
}
|
|
|
|
|
2020-03-24 16:39:29 +01:00
|
|
|
QString
|
|
|
|
Config::knownIssuesUrl() const
|
2020-03-10 22:44:48 +01:00
|
|
|
{
|
|
|
|
return m_knownIssuesUrl;
|
|
|
|
}
|
|
|
|
|
2020-03-24 16:39:29 +01:00
|
|
|
void
|
|
|
|
Config::setKnownIssuesUrl(const QString& url)
|
2020-03-10 22:44:48 +01:00
|
|
|
{
|
|
|
|
m_knownIssuesUrl = url;
|
2020-03-24 15:26:24 +01:00
|
|
|
emit knownIssuesUrlChanged();
|
2020-03-10 22:44:48 +01:00
|
|
|
}
|
|
|
|
|
2020-03-24 16:39:29 +01:00
|
|
|
void
|
|
|
|
Config::setReleaseNotesUrl(const QString& url)
|
2020-03-10 22:44:48 +01:00
|
|
|
{
|
|
|
|
m_releaseNotesUrl = url;
|
2020-03-24 15:26:24 +01:00
|
|
|
emit releaseNotesUrlChanged();
|
2020-03-10 22:44:48 +01:00
|
|
|
}
|
|
|
|
|
2020-03-24 16:39:29 +01:00
|
|
|
QString
|
|
|
|
Config::releaseNotesUrl() const
|
2020-03-10 22:44:48 +01:00
|
|
|
{
|
|
|
|
return m_releaseNotesUrl;
|
|
|
|
}
|
|
|
|
|
2020-03-24 16:39:29 +01:00
|
|
|
QString
|
|
|
|
Config::supportUrl() const
|
2020-03-10 22:44:48 +01:00
|
|
|
{
|
|
|
|
return m_supportUrl;
|
|
|
|
}
|
|
|
|
|
2020-03-24 16:39:29 +01:00
|
|
|
void
|
|
|
|
Config::setSupportUrl(const QString& url)
|
2020-03-10 22:44:48 +01:00
|
|
|
{
|
|
|
|
m_supportUrl = url;
|
2020-03-24 15:26:24 +01:00
|
|
|
emit supportUrlChanged();
|
2020-03-10 22:44:48 +01:00
|
|
|
}
|
|
|
|
|
2020-03-24 16:39:29 +01:00
|
|
|
void
|
|
|
|
RequirementsModel::retranslate()
|
2020-03-24 15:26:24 +01:00
|
|
|
{
|
|
|
|
if ( !m_satisfiedRequirements )
|
|
|
|
{
|
|
|
|
QString message;
|
|
|
|
const bool setup = Calamares::Settings::instance()->isSetupMode();
|
2020-03-10 22:44:48 +01:00
|
|
|
|
2020-03-24 15:26:24 +01:00
|
|
|
if ( !m_satisfiedMandatory )
|
|
|
|
{
|
|
|
|
message = setup ? tr( "This computer does not satisfy the minimum "
|
|
|
|
"requirements for setting up %1.<br/>"
|
|
|
|
"Setup cannot continue. "
|
|
|
|
"<a href=\"#details\">Details...</a>" )
|
|
|
|
: tr( "This computer does not satisfy the minimum "
|
|
|
|
"requirements for installing %1.<br/>"
|
|
|
|
"Installation cannot continue. "
|
|
|
|
"<a href=\"#details\">Details...</a>" );
|
|
|
|
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
message = setup ? tr( "This computer does not satisfy some of the "
|
|
|
|
"recommended requirements for setting up %1.<br/>"
|
|
|
|
"Setup can continue, but some features "
|
|
|
|
"might be disabled." )
|
|
|
|
: tr( "This computer does not satisfy some of the "
|
|
|
|
"recommended requirements for installing %1.<br/>"
|
|
|
|
"Installation can continue, but some features "
|
|
|
|
"might be disabled." );
|
|
|
|
}
|
2020-03-10 22:44:48 +01:00
|
|
|
|
2020-03-24 15:26:24 +01:00
|
|
|
m_warningMessage = message.arg( *Calamares::Branding::ShortVersionedName );
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
m_warningMessage = tr( "This program will ask you some questions and "
|
|
|
|
"set up %2 on your computer." )
|
|
|
|
.arg( *Calamares::Branding::ProductName );
|
|
|
|
}
|
2020-03-10 22:44:48 +01:00
|
|
|
|
2020-03-24 15:26:24 +01:00
|
|
|
emit warningMessageChanged();
|
|
|
|
}
|
2020-03-24 16:39:29 +01:00
|
|
|
|
|
|
|
QString
|
|
|
|
Config::genericWelcomeMessage()
|
|
|
|
{
|
|
|
|
QString message;
|
|
|
|
|
|
|
|
if ( Calamares::Settings::instance()->isSetupMode() )
|
|
|
|
{
|
|
|
|
message = Calamares::Branding::instance()->welcomeStyleCalamares()
|
|
|
|
? tr( "<h1>Welcome to the Calamares setup program for %1.</h1>" )
|
|
|
|
: tr( "<h1>Welcome to %1 setup.</h1>" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
message = Calamares::Branding::instance()->welcomeStyleCalamares()
|
|
|
|
? tr( "<h1>Welcome to the Calamares installer for %1.</h1>" )
|
|
|
|
: tr( "<h1>Welcome to the %1 installer.</h1>" );
|
|
|
|
}
|
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|