2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2014-06-11 13:37:10 +02:00
|
|
|
*
|
2015-01-29 20:24:09 +01:00
|
|
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
2018-06-15 11:59:11 +02:00
|
|
|
* Copyright 2018, Adriaan de Groot <groot@kde.org>
|
2014-06-11 13:37:10 +02:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2015-05-13 12:44:11 +02:00
|
|
|
#include "WelcomeViewStep.h"
|
2014-06-11 13:37:10 +02:00
|
|
|
|
2020-03-25 13:46:27 +01:00
|
|
|
#include "Config.h"
|
2015-05-13 12:44:11 +02:00
|
|
|
#include "WelcomePage.h"
|
2019-02-23 18:29:59 +01:00
|
|
|
#include "checker/GeneralRequirements.h"
|
2015-05-14 18:02:26 +02:00
|
|
|
|
2020-03-25 13:46:27 +01:00
|
|
|
#include "Branding.h"
|
2019-05-09 21:15:03 +02:00
|
|
|
#include "geoip/Handler.h"
|
2019-05-10 17:03:01 +02:00
|
|
|
#include "locale/Lookup.h"
|
2020-03-25 13:46:27 +01:00
|
|
|
#include "modulesystem/ModuleManager.h"
|
2019-02-25 12:11:14 +01:00
|
|
|
#include "utils/Logger.h"
|
2019-05-02 20:00:32 +02:00
|
|
|
#include "utils/Variant.h"
|
2014-06-27 13:58:53 +02:00
|
|
|
|
2019-05-09 21:15:03 +02:00
|
|
|
#include <QFutureWatcher>
|
2015-04-02 12:27:54 +02:00
|
|
|
#include <QVariant>
|
|
|
|
|
2019-08-13 22:29:01 +02:00
|
|
|
CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeViewStepFactory, registerPlugin< WelcomeViewStep >(); )
|
2015-09-09 18:46:13 +02:00
|
|
|
|
2015-05-13 12:44:11 +02:00
|
|
|
WelcomeViewStep::WelcomeViewStep( QObject* parent )
|
2020-03-25 11:41:39 +01:00
|
|
|
: Calamares::ViewStep( parent )
|
|
|
|
, m_requirementsChecker( new GeneralRequirements( this ) )
|
|
|
|
, m_conf( new Config( this ) )
|
2014-06-11 13:37:10 +02:00
|
|
|
{
|
2020-03-25 11:41:39 +01:00
|
|
|
connect( Calamares::ModuleManager::instance(),
|
|
|
|
&Calamares::ModuleManager::requirementsComplete,
|
|
|
|
this,
|
|
|
|
&WelcomeViewStep::nextStatusChanged );
|
2014-06-27 18:00:27 +02:00
|
|
|
|
2020-03-10 22:44:48 +01:00
|
|
|
// the instance of the qqc2 or qwidgets page
|
2020-03-25 11:41:39 +01:00
|
|
|
m_widget = new WelcomePage( m_conf );
|
2020-04-02 23:04:23 +02:00
|
|
|
connect( m_conf, &Config::localeIndexChanged, m_widget, &WelcomePage::externallySelectedLanguage );
|
2020-03-10 22:44:48 +01:00
|
|
|
}
|
2014-06-27 18:00:27 +02:00
|
|
|
|
2015-05-13 12:44:11 +02:00
|
|
|
WelcomeViewStep::~WelcomeViewStep()
|
2014-06-27 18:00:27 +02:00
|
|
|
{
|
2020-03-25 11:41:39 +01:00
|
|
|
if ( m_widget && m_widget->parent() == nullptr )
|
|
|
|
{
|
|
|
|
m_widget->deleteLater();
|
|
|
|
}
|
2014-06-11 13:37:10 +02:00
|
|
|
}
|
2014-06-27 13:58:53 +02:00
|
|
|
|
|
|
|
QString
|
2015-05-13 12:44:11 +02:00
|
|
|
WelcomeViewStep::prettyName() const
|
2014-06-27 13:58:53 +02:00
|
|
|
{
|
2020-03-25 11:41:39 +01:00
|
|
|
return tr( "Welcome" );
|
2014-06-27 13:58:53 +02:00
|
|
|
}
|
2014-06-27 18:00:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
QWidget*
|
2015-05-13 12:44:11 +02:00
|
|
|
WelcomeViewStep::widget()
|
2014-06-27 18:00:27 +02:00
|
|
|
{
|
2020-03-25 11:41:39 +01:00
|
|
|
return m_widget;
|
2014-06-27 18:00:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2015-05-13 12:44:11 +02:00
|
|
|
WelcomeViewStep::isNextEnabled() const
|
2014-06-27 18:00:27 +02:00
|
|
|
{
|
2020-03-25 11:41:39 +01:00
|
|
|
return m_widget->verdict();
|
2014-06-27 18:00:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-29 20:24:09 +01:00
|
|
|
bool
|
2015-05-13 12:44:11 +02:00
|
|
|
WelcomeViewStep::isBackEnabled() const
|
2015-01-29 20:24:09 +01:00
|
|
|
{
|
2020-03-25 11:41:39 +01:00
|
|
|
return false;
|
2015-01-29 20:24:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-27 18:00:27 +02:00
|
|
|
bool
|
2015-05-13 12:44:11 +02:00
|
|
|
WelcomeViewStep::isAtBeginning() const
|
2014-06-27 18:00:27 +02:00
|
|
|
{
|
2020-03-25 11:41:39 +01:00
|
|
|
return true;
|
2014-06-27 18:00:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2015-05-13 12:44:11 +02:00
|
|
|
WelcomeViewStep::isAtEnd() const
|
2014-06-27 18:00:27 +02:00
|
|
|
{
|
2020-03-25 11:41:39 +01:00
|
|
|
return true;
|
2014-06-27 18:00:27 +02:00
|
|
|
}
|
|
|
|
|
2014-07-08 14:02:21 +02:00
|
|
|
|
2019-02-25 13:05:12 +01:00
|
|
|
Calamares::JobList
|
2015-05-13 12:44:11 +02:00
|
|
|
WelcomeViewStep::jobs() const
|
2014-07-08 14:02:21 +02:00
|
|
|
{
|
2020-03-25 11:41:39 +01:00
|
|
|
return Calamares::JobList();
|
2014-07-08 14:02:21 +02:00
|
|
|
}
|
|
|
|
|
2015-04-02 12:27:54 +02:00
|
|
|
|
|
|
|
void
|
2015-05-13 12:44:11 +02:00
|
|
|
WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
2015-04-02 12:27:54 +02:00
|
|
|
{
|
2020-05-06 15:08:31 +02:00
|
|
|
m_conf->setConfigurationMap( configurationMap );
|
2020-03-10 22:44:48 +01:00
|
|
|
|
2020-03-25 11:41:39 +01:00
|
|
|
if ( configurationMap.contains( "requirements" )
|
|
|
|
&& configurationMap.value( "requirements" ).type() == QVariant::Map )
|
|
|
|
{
|
|
|
|
m_requirementsChecker->setConfigurationMap( configurationMap.value( "requirements" ).toMap() );
|
2020-03-10 22:44:48 +01:00
|
|
|
|
|
|
|
m_conf->requirementsModel().setRequirementsList( checkRequirements() );
|
2020-03-25 11:41:39 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
cWarning() << "no valid requirements map found in welcome "
|
|
|
|
"module configuration.";
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
QVariantMap geoip = CalamaresUtils::getSubMap( configurationMap, "geoip", ok );
|
|
|
|
if ( ok )
|
|
|
|
{
|
|
|
|
using FWString = QFutureWatcher< QString >;
|
|
|
|
|
|
|
|
auto* handler = new CalamaresUtils::GeoIP::Handler( CalamaresUtils::getString( geoip, "style" ),
|
|
|
|
CalamaresUtils::getString( geoip, "url" ),
|
|
|
|
CalamaresUtils::getString( geoip, "selector" ) );
|
|
|
|
if ( handler->type() != CalamaresUtils::GeoIP::Handler::Type::None )
|
|
|
|
{
|
|
|
|
auto* future = new FWString();
|
2020-05-04 12:51:28 +02:00
|
|
|
connect( future, &FWString::finished, [ view = this, f = future, h = handler ]() {
|
2020-03-25 11:41:39 +01:00
|
|
|
QString countryResult = f->future().result();
|
|
|
|
cDebug() << "GeoIP result for welcome=" << countryResult;
|
|
|
|
view->setCountry( countryResult, h );
|
|
|
|
f->deleteLater();
|
|
|
|
delete h;
|
|
|
|
} );
|
|
|
|
future->setFuture( handler->queryRaw() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Would not produce useful country code anyway.
|
|
|
|
delete handler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString language = CalamaresUtils::getString( configurationMap, "languageIcon" );
|
|
|
|
if ( !language.isEmpty() )
|
|
|
|
{
|
2020-03-10 22:44:48 +01:00
|
|
|
m_conf->setLanguageIcon( language );
|
2020-03-25 11:41:39 +01:00
|
|
|
}
|
2020-03-10 22:44:48 +01:00
|
|
|
|
2020-03-25 11:41:39 +01:00
|
|
|
//here init the qml or qwidgets needed bits
|
|
|
|
m_widget->init();
|
2015-04-02 12:27:54 +02:00
|
|
|
}
|
|
|
|
|
2019-05-10 13:53:44 +02:00
|
|
|
Calamares::RequirementsList
|
|
|
|
WelcomeViewStep::checkRequirements()
|
2017-12-02 17:25:26 +01:00
|
|
|
{
|
2020-03-25 11:41:39 +01:00
|
|
|
return m_requirementsChecker->checkRequirements();
|
2017-12-02 17:25:26 +01:00
|
|
|
}
|
2019-05-10 13:53:44 +02:00
|
|
|
|
2019-06-18 12:24:30 +02:00
|
|
|
static inline void
|
|
|
|
logGeoIPHandler( CalamaresUtils::GeoIP::Handler* handler )
|
|
|
|
{
|
2020-03-25 11:41:39 +01:00
|
|
|
if ( handler )
|
|
|
|
{
|
|
|
|
cDebug() << Logger::SubEntry << "Obtained from" << handler->url() << " ("
|
|
|
|
<< static_cast< int >( handler->type() ) << handler->selector() << ')';
|
|
|
|
}
|
2019-06-18 12:24:30 +02:00
|
|
|
}
|
|
|
|
|
2019-05-10 13:53:44 +02:00
|
|
|
void
|
2019-06-18 12:24:30 +02:00
|
|
|
WelcomeViewStep::setCountry( const QString& countryCode, CalamaresUtils::GeoIP::Handler* handler )
|
2019-05-10 13:53:44 +02:00
|
|
|
{
|
2020-03-25 11:41:39 +01:00
|
|
|
if ( countryCode.length() != 2 )
|
|
|
|
{
|
|
|
|
cDebug() << "Unusable country code" << countryCode;
|
|
|
|
logGeoIPHandler( handler );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto c_l = CalamaresUtils::Locale::countryData( countryCode );
|
|
|
|
if ( c_l.first == QLocale::Country::AnyCountry )
|
|
|
|
{
|
|
|
|
cDebug() << "Unusable country code" << countryCode;
|
|
|
|
logGeoIPHandler( handler );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int r = CalamaresUtils::Locale::availableTranslations()->find( countryCode );
|
|
|
|
if ( r < 0 )
|
|
|
|
{
|
|
|
|
cDebug() << "Unusable country code" << countryCode << "(no suitable translation)";
|
|
|
|
}
|
|
|
|
if ( ( r >= 0 ) && m_conf )
|
|
|
|
{
|
2020-03-10 22:44:48 +01:00
|
|
|
m_conf->setCountryCode( countryCode );
|
2019-08-13 22:29:01 +02:00
|
|
|
}
|
2020-03-25 11:41:39 +01:00
|
|
|
}
|
2019-05-10 13:53:44 +02:00
|
|
|
}
|