[welcome] using config for both qcc2 or qwidgets

This commit is contained in:
Camilo Higuita 2020-03-10 16:44:48 -05:00 committed by Adriaan de Groot
parent 7ec6dff352
commit d7f7c16958
13 changed files with 666 additions and 271 deletions

View File

@ -28,6 +28,8 @@ calamares_add_plugin( welcome
SOURCES
${CHECKER_SOURCES}
WelcomeViewStep.cpp
Config.cpp
Config.h
WelcomePage.cpp
UI
WelcomePage.ui

View File

@ -0,0 +1,273 @@
/* === 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 )
{
emit beginResetModel();
m_requierements = requirements;
m_satisfiedRequirements = true;
auto isUnSatisfied = []( const Calamares::RequirementEntry& e ) { return !e.satisfied; };
auto isMandatoryAndUnSatisfied = []( const Calamares::RequirementEntry& e ) { return e.mandatory && !e.satisfied; };
m_satisfiedRequirements = std::none_of( m_requierements.begin(), m_requierements.end(), isUnSatisfied );
m_satisfiedMandatory = std::none_of( m_requierements.begin(), m_requierements.end(), isMandatoryAndUnSatisfied );
emit satisfiedRequirementsChanged(m_satisfiedRequirements);
emit satisfiedMandatoryChanged();
emit endResetModel();
}
int
RequirementsModel::rowCount( const QModelIndex& ) const
{
return m_requierements.count();
}
QVariant
RequirementsModel::data( const QModelIndex& index, int role ) const
{
const auto requirement = m_requierements.at( index.row() );
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()
{
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>" );
}
m_genericWelcomeMessage = message.arg( *Calamares::Branding::VersionedName );
emit genericWelcomeMessageChanged();
// ui->supportButton->setText( tr( "%1 support" ).arg( *Calamares::Branding::ShortProductName ) );
}
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
Config::setLanguageIcon( const QString languageIcon )
{
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 );
}
QString Config::donateUrl() const
{
return m_donateUrl;
}
void Config::setDonateUrl(const QString& url)
{
m_donateUrl = url;
}
QString Config::knownIssuesUrl() const
{
return m_knownIssuesUrl;
}
void Config::setKnownIssuesUrl(const QString& url)
{
m_knownIssuesUrl = url;
}
void Config::setReleaseNotesUrl(const QString& url)
{
m_releaseNotesUrl = url;
}
QString Config::releaseNotesUrl() const
{
return m_releaseNotesUrl;
}
QString Config::supportUrl() const
{
return m_supportUrl;
}
void Config::setSupportUrl(const QString& url)
{
m_supportUrl = url;
}

View File

@ -0,0 +1,162 @@
/* === 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/>.
*/
#ifndef WELCOME_CONFIG_H
#define WELCOME_CONFIG_H
#include <QObject>
#include <QUrl>
#include "modulesystem/Requirement.h"
#include "locale/LabelModel.h"
class RequirementsModel : public QAbstractListModel
{
Q_OBJECT
using QAbstractListModel::QAbstractListModel;
Q_PROPERTY(bool satisfiedRequirements READ satisfiedRequirements NOTIFY satisfiedRequirementsChanged FINAL)
Q_PROPERTY(bool satisfiedMandatory READ satisfiedMandatory NOTIFY satisfiedMandatoryChanged FINAL)
public:
enum Roles : short
{
Name,
Satisfied,
Mandatory,
Details,
NegatedText,
HasDetails
};
bool satisfiedRequirements() const
{
return m_satisfiedRequirements;
}
bool satisfiedMandatory() const
{
return m_satisfiedMandatory;
}
const Calamares::RequirementEntry& getEntry(const int& index) const
{
if(index > count() || index < 0)
return *(new Calamares::RequirementEntry());
return m_requierements.at(index);
}
void setRequirementsList( const Calamares::RequirementsList& requirements );
int rowCount(const QModelIndex&) const override;
int count() const
{
return m_requierements.count();
}
QVariant data(const QModelIndex& index, int role) const override;
protected:
QHash<int, QByteArray> roleNames() const override;
private:
Calamares::RequirementsList m_requierements;
bool m_satisfiedRequirements = false;
bool m_satisfiedMandatory = false;
signals:
void satisfiedRequirementsChanged(bool value);
void satisfiedMandatoryChanged();
};
class Config : public QObject
{
Q_OBJECT
Q_PROPERTY( CalamaresUtils::Locale::LabelModel* languagesModel READ languagesModel CONSTANT FINAL)
Q_PROPERTY( RequirementsModel* requirementsModel MEMBER m_requirementsModel CONSTANT FINAL )
Q_PROPERTY( QString languageIcon READ languageIcon CONSTANT FINAL )
Q_PROPERTY( QString countryCode MEMBER m_countryCode NOTIFY countryCodeChanged FINAL )
Q_PROPERTY (int localeIndex READ localeIndex WRITE setLocaleIndex NOTIFY localeIndexChanged)
Q_PROPERTY( QString genericWelcomeMessage MEMBER m_genericWelcomeMessage NOTIFY genericWelcomeMessageChanged FINAL )
Q_PROPERTY( QString warningMessage MEMBER m_warningMessage CONSTANT FINAL )
Q_PROPERTY( bool isNextEnabled MEMBER m_isNextEnabled NOTIFY isNextEnabledChanged FINAL )
public:
Config( QObject* parent = nullptr );
void setCountryCode( const QString &countryCode );
void setLanguageIcon( const QString languageIcon );
RequirementsModel& requirementsModel () const;
void setIsNextEnabled( const bool& isNextEnabled );
void setLocaleIndex(const int &index);
int localeIndex() const { return m_localeIndex; }
QString supportUrl() const;
void setSupportUrl(const QString &url);
QString knownIssuesUrl() const;
void setKnownIssuesUrl(const QString &url);
QString releaseNotesUrl() const;
void setReleaseNotesUrl(const QString &url);
QString donateUrl() const;
void setDonateUrl(const QString &url);
public slots:
CalamaresUtils::Locale::LabelModel* languagesModel() const;
void retranslate();
QString languageIcon() const;
private:
void initLanguages();
QVariantMap m_configurationMap;
RequirementsModel* m_requirementsModel;
QString m_languageIcon;
QString m_countryCode;
int m_localeIndex = 0;
bool m_isNextEnabled = false;
CalamaresUtils::Locale::LabelModel* m_languages;
QString m_genericWelcomeMessage = tr("This program will ask you some questions and set up your installation");
QString m_warningMessage = tr("This program does not satisfy the minimum requirements for installing.\nInstallation can not continue");
QString m_supportUrl;
QString m_knownIssuesUrl;
QString m_releaseNotesUrl;
QString m_donateUrl;
signals:
void countryCodeChanged( QString countryCode );
void localeIndexChanged( int localeIndex );
void isNextEnabledChanged( bool isNextEnabled );
void genericWelcomeMessageChanged();
};
#endif

View File

@ -27,6 +27,7 @@
#include "CalamaresVersion.h"
#include "Settings.h"
#include "ViewManager.h"
#include "Config.h"
#include "locale/LabelModel.h"
#include "modulesystem/ModuleManager.h"
@ -43,16 +44,14 @@
#include <QLabel>
#include <QMessageBox>
WelcomePage::WelcomePage( QWidget* parent )
WelcomePage::WelcomePage( Config *conf, QWidget* parent )
: QWidget( parent )
, ui( new Ui::WelcomePage )
, m_checkingWidget( new CheckerContainer( this ) )
, m_checkingWidget( new CheckerContainer( conf->requirementsModel(), this ) )
, m_languages( nullptr )
, m_conf( conf )
{
connect( Calamares::ModuleManager::instance(),
&Calamares::ModuleManager::requirementsResult,
m_checkingWidget,
&CheckerContainer::requirementsChecked );
connect( Calamares::ModuleManager::instance(),
&Calamares::ModuleManager::requirementsComplete,
m_checkingWidget,
@ -85,6 +84,21 @@ WelcomePage::WelcomePage( QWidget* parent )
ui->verticalLayout->insertWidget( welcome_text_idx + 1, m_checkingWidget );
}
void WelcomePage::init()
{
//setup the url buttons
setupButton( WelcomePage::Button::Support, m_conf->supportUrl());
setupButton( WelcomePage::Button::KnownIssues, m_conf->knownIssuesUrl() );
setupButton( WelcomePage::Button::ReleaseNotes, m_conf->releaseNotesUrl() );
setupButton( WelcomePage::Button::Donate, m_conf->donateUrl());
//language icon
auto icon = Calamares::Branding::instance()->image( m_conf->languageIcon(), QSize( 48, 48 ) );
if ( !icon.isNull() )
{
setLanguageIcon( icon );
}
}
void
WelcomePage::initLanguages()
@ -93,67 +107,15 @@ WelcomePage::initLanguages()
ui->languageWidget->clear();
ui->languageWidget->setInsertPolicy( QComboBox::InsertAtBottom );
m_languages = CalamaresUtils::Locale::availableTranslations();
ui->languageWidget->setModel( m_languages );
ui->languageWidget->setModel( m_conf->languagesModel() );
ui->languageWidget->setItemDelegate( new LocaleTwoColumnDelegate( ui->languageWidget ) );
// 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 );
ui->languageWidget->setCurrentIndex( matchedLocaleIndex );
}
else
{
cWarning() << "No available translation matched" << defaultLocale;
}
ui->languageWidget->setCurrentIndex( m_conf->localeIndex() );
connect( ui->languageWidget,
static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ),
this,
[&]( int newIndex ) {
const auto& selectedLocale = m_languages->locale( newIndex ).locale();
cDebug() << "Selected locale" << selectedLocale;
QLocale::setDefault( selectedLocale );
CalamaresUtils::installTranslator(
selectedLocale, Calamares::Branding::instance()->translationsDirectory(), qApp );
} );
static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ), m_conf, &Config::setLocaleIndex );
}
void
WelcomePage::setupButton( Button role, const QString& url )
{

View File

@ -31,12 +31,12 @@ class WelcomePage;
}
class CheckerContainer;
class Config;
class WelcomePage : public QWidget
{
Q_OBJECT
public:
explicit WelcomePage( QWidget* parent = nullptr );
explicit WelcomePage( Config *conf, QWidget* parent = nullptr );
enum class Button
{
@ -58,6 +58,8 @@ public:
/// @brief Change the language from an external source.
void externallySelectedLanguage( int row );
void init();
public slots:
void retranslate();
void showAboutBox();
@ -72,6 +74,8 @@ private:
Ui::WelcomePage* ui;
CheckerContainer* m_checkingWidget;
CalamaresUtils::Locale::LabelModel* m_languages;
Config *m_conf;
};
/** @brief Delegate to display language information in two columns.

View File

@ -18,6 +18,7 @@
*/
#include "WelcomeViewStep.h"
#include "Config.h"
#include "WelcomePage.h"
#include "checker/GeneralRequirements.h"
@ -36,72 +37,73 @@
CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeViewStepFactory, registerPlugin< WelcomeViewStep >(); )
WelcomeViewStep::WelcomeViewStep( QObject* parent )
: Calamares::ViewStep( parent )
, m_requirementsChecker( new GeneralRequirements( this ) )
: Calamares::ViewStep( parent )
, m_requirementsChecker( new GeneralRequirements( this ) )
, m_conf( new Config(this) )
{
connect( Calamares::ModuleManager::instance(),
&Calamares::ModuleManager::requirementsComplete,
this,
&WelcomeViewStep::nextStatusChanged );
m_widget = new WelcomePage();
}
connect( Calamares::ModuleManager::instance(),
&Calamares::ModuleManager::requirementsComplete,
this,
&WelcomeViewStep::nextStatusChanged );
// the instance of the qqc2 or qwidgets page
m_widget = new WelcomePage(m_conf);
}
WelcomeViewStep::~WelcomeViewStep()
{
if ( m_widget && m_widget->parent() == nullptr )
{
m_widget->deleteLater();
}
if ( m_widget && m_widget->parent() == nullptr )
{
m_widget->deleteLater();
}
}
QString
WelcomeViewStep::prettyName() const
{
return tr( "Welcome" );
return tr( "Welcome" );
}
QWidget*
WelcomeViewStep::widget()
{
return m_widget;
return m_widget;
}
bool
WelcomeViewStep::isNextEnabled() const
{
return m_widget->verdict();
return m_widget->verdict();
}
bool
WelcomeViewStep::isBackEnabled() const
{
return false;
return false;
}
bool
WelcomeViewStep::isAtBeginning() const
{
return true;
return true;
}
bool
WelcomeViewStep::isAtEnd() const
{
return true;
return true;
}
Calamares::JobList
WelcomeViewStep::jobs() const
{
return Calamares::JobList();
return Calamares::JobList();
}
@ -120,129 +122,125 @@ WelcomeViewStep::jobs() const
static QString
jobOrBrandingSetting( Calamares::Branding::StringEntry e, const QVariantMap& map, const QString& key )
{
if ( !map.contains( key ) )
{
return QString();
}
auto v = map.value( key );
if ( v.type() == QVariant::Bool )
{
return v.toBool() ? ( *e ) : QString();
}
if ( v.type() == QVariant::String )
{
return v.toString();
}
if ( !map.contains( key ) )
{
return QString();
}
auto v = map.value( key );
if ( v.type() == QVariant::Bool )
{
return v.toBool() ? ( *e ) : QString();
}
if ( v.type() == QVariant::String )
{
return v.toString();
}
return QString();
return QString();
}
void
WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{
using Calamares::Branding;
using Calamares::Branding;
m_widget->setupButton( WelcomePage::Button::Support,
jobOrBrandingSetting( Branding::SupportUrl, configurationMap, "showSupportUrl" ) );
m_widget->setupButton( WelcomePage::Button::KnownIssues,
jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) );
m_widget->setupButton( WelcomePage::Button::ReleaseNotes,
jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) );
m_widget->setupButton( WelcomePage::Button::Donate,
CalamaresUtils::getString( configurationMap, "showDonateUrl" ) );
m_conf->setSupportUrl( jobOrBrandingSetting( Branding::SupportUrl, configurationMap, "showSupportUrl" ) );
m_conf->setKnownIssuesUrl( jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) );
m_conf->setReleaseNotesUrl( jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) );
m_conf->setDonateUrl( CalamaresUtils::getString( configurationMap, "showDonateUrl" ) );
if ( configurationMap.contains( "requirements" )
&& configurationMap.value( "requirements" ).type() == QVariant::Map )
{
m_requirementsChecker->setConfigurationMap( configurationMap.value( "requirements" ).toMap() );
}
else
cWarning() << "no valid requirements map found in welcome "
"module configuration.";
if ( configurationMap.contains( "requirements" )
&& configurationMap.value( "requirements" ).type() == QVariant::Map )
{
m_requirementsChecker->setConfigurationMap( configurationMap.value( "requirements" ).toMap() );
bool ok = false;
QVariantMap geoip = CalamaresUtils::getSubMap( configurationMap, "geoip", ok );
if ( ok )
{
using FWString = QFutureWatcher< QString >;
m_conf->requirementsModel().setRequirementsList( checkRequirements() );
}
else
cWarning() << "no valid requirements map found in welcome "
"module configuration.";
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();
connect( future, &FWString::finished, [view = this, f = future, h = handler]() {
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;
}
}
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();
connect( future, &FWString::finished, [view = this, f = future, h = handler]() {
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() )
{
auto icon = Calamares::Branding::instance()->image( language, QSize( 48, 48 ) );
if ( !icon.isNull() )
{
m_widget->setLanguageIcon( icon );
}
}
QString language = CalamaresUtils::getString( configurationMap, "languageIcon" );
if ( !language.isEmpty() )
{
m_conf->setLanguageIcon( language );
}
//here init the qml or qwidgets needed bits
m_widget->init();
}
Calamares::RequirementsList
WelcomeViewStep::checkRequirements()
{
return m_requirementsChecker->checkRequirements();
return m_requirementsChecker->checkRequirements();
}
static inline void
logGeoIPHandler( CalamaresUtils::GeoIP::Handler* handler )
{
if ( handler )
{
cDebug() << Logger::SubEntry << "Obtained from" << handler->url() << " ("
<< static_cast< int >( handler->type() ) << handler->selector() << ')';
}
if ( handler )
{
cDebug() << Logger::SubEntry << "Obtained from" << handler->url() << " ("
<< static_cast< int >( handler->type() ) << handler->selector() << ')';
}
}
void
WelcomeViewStep::setCountry( const QString& countryCode, CalamaresUtils::GeoIP::Handler* handler )
{
if ( countryCode.length() != 2 )
{
cDebug() << "Unusable country code" << countryCode;
logGeoIPHandler( handler );
return;
}
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)";
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 )
{
m_conf->setCountryCode( countryCode );
}
if ( ( r >= 0 ) && m_widget )
{
m_widget->externallySelectedLanguage( r );
}
}
}
}

View File

@ -19,16 +19,19 @@
#ifndef WELCOMEPAGEPLUGIN_H
#define WELCOMEPAGEPLUGIN_H
#include "DllMacro.h"
#include "utils/PluginFactory.h"
#include "viewpages/ViewStep.h"
#include <QObject>
#include <modulesystem/Requirement.h>
#include <utils/PluginFactory.h>
#include <viewpages/ViewStep.h>
#include <DllMacro.h>
#include <QVariantMap>
class WelcomePage;
class GeneralRequirements;
class Config;
namespace CalamaresUtils
{
namespace GeoIP
@ -72,6 +75,7 @@ public:
private:
WelcomePage* m_widget;
GeneralRequirements* m_requirementsChecker;
Config *m_conf;
};
CALAMARES_PLUGIN_FACTORY_DECLARATION( WelcomeViewStepFactory )

View File

@ -31,11 +31,12 @@
#include <QHBoxLayout>
CheckerContainer::CheckerContainer( QWidget* parent )
CheckerContainer::CheckerContainer( const RequirementsModel &model, QWidget* parent )
: QWidget( parent )
, m_waitingWidget( new WaitingWidget( QString(), this ) )
, m_checkerWidget( nullptr )
, m_verdict( false )
, m_model( model )
{
QBoxLayout* mainLayout = new QHBoxLayout;
setLayout( mainLayout );
@ -59,18 +60,12 @@ CheckerContainer::requirementsComplete( bool ok )
m_waitingWidget->deleteLater();
m_waitingWidget = nullptr; // Don't delete in destructor
m_checkerWidget = new ResultsListWidget( this, m_requirements );
m_checkerWidget = new ResultsListWidget( m_model, this);
layout()->addWidget( m_checkerWidget );
m_verdict = ok;
}
void
CheckerContainer::requirementsChecked( const Calamares::RequirementsList& l )
{
m_requirements.append( l );
}
void
CheckerContainer::requirementsProgress( const QString& message )
{

View File

@ -24,8 +24,7 @@
#define CHECKERCONTAINER_H
#include <QWidget>
#include "modulesystem/Requirement.h"
#include "Config.h"
class ResultsListWidget;
class WaitingWidget;
@ -36,18 +35,17 @@ class WaitingWidget;
* a (list) diplay of the results, plus some explanation of the
* overall state of the entire list of results.
*/
class CheckerContainer : public QWidget
{
Q_OBJECT
public:
explicit CheckerContainer( QWidget* parent = nullptr );
explicit CheckerContainer(const RequirementsModel &model, QWidget* parent = nullptr );
virtual ~CheckerContainer();
bool verdict() const;
public slots:
void requirementsChecked( const Calamares::RequirementsList& );
/** @brief All the requirements are complete, switch to list view */
void requirementsComplete( bool );
@ -57,8 +55,10 @@ protected:
WaitingWidget *m_waitingWidget;
ResultsListWidget *m_checkerWidget;
Calamares::RequirementsList m_requirements;
bool m_verdict;
private:
const RequirementsModel &m_model;
} ;
#endif

View File

@ -47,14 +47,16 @@
static void
createResultWidgets( QLayout* layout,
QList< ResultWidget* >& resultWidgets,
const Calamares::RequirementsList& checkEntries,
std::function< bool( const Calamares::RequirementEntry& ) > predicate )
const RequirementsModel &model,
std::function< bool( const Calamares::RequirementEntry& ) > predicate
)
{
resultWidgets.clear();
resultWidgets.reserve( checkEntries.count() );
for ( const auto& entry : checkEntries )
resultWidgets.reserve( model.count() );
for ( auto i = 0; i < model.count(); i++ )
{
if ( !predicate( entry ) )
const auto &entry = model.getEntry(i);
if ( !predicate(entry))
{
resultWidgets.append( nullptr );
continue;
@ -91,27 +93,27 @@ public:
* The list must continue to exist for the lifetime of the dialog,
* or UB happens.
*/
ResultsListDialog( QWidget* parent, const Calamares::RequirementsList& checkEntries );
ResultsListDialog( const RequirementsModel& model, QWidget* parent );
virtual ~ResultsListDialog();
private:
QLabel* m_title;
QList< ResultWidget* > m_resultWidgets; ///< One widget for each entry with details available
const Calamares::RequirementsList& m_entries;
const RequirementsModel& m_model;
void retranslate();
};
ResultsListDialog::ResultsListDialog( QWidget* parent, const Calamares::RequirementsList& checkEntries )
ResultsListDialog::ResultsListDialog( const RequirementsModel& model, QWidget* parent)
: QDialog( parent )
, m_entries( checkEntries )
, m_model( model )
{
auto* mainLayout = new QVBoxLayout;
auto* entriesLayout = new QVBoxLayout;
m_title = new QLabel( this );
createResultWidgets( entriesLayout, m_resultWidgets, checkEntries, []( const Calamares::RequirementEntry& e ) {
createResultWidgets( entriesLayout, m_resultWidgets, model, []( const Calamares::RequirementEntry& e ) {
return e.hasDetails();
} );
@ -137,21 +139,20 @@ ResultsListDialog::retranslate()
m_title->setText( tr( "For best results, please ensure that this computer:" ) );
setWindowTitle( tr( "System requirements" ) );
int i = 0;
for ( const auto& entry : m_entries )
for ( auto i = 0; i < m_model.count(); i++ )
{
const auto &entry = m_model.getEntry(i);
if ( m_resultWidgets[ i ] )
{
m_resultWidgets[ i ]->setText( entry.enumerationText() );
}
i++;
}
}
ResultsListWidget::ResultsListWidget( QWidget* parent, const Calamares::RequirementsList& checkEntries )
ResultsListWidget::ResultsListWidget( const RequirementsModel &model, QWidget* parent )
: QWidget( parent )
, m_entries( checkEntries )
, m_model( model )
{
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
@ -178,10 +179,11 @@ ResultsListWidget::ResultsListWidget( QWidget* parent, const Calamares::Requirem
// Check that all are satisfied (gives warnings if not) and
// all *mandatory* entries are satisfied (gives errors if not).
auto isUnSatisfied = []( const Calamares::RequirementEntry& e ) { return !e.satisfied; };
const bool requirementsSatisfied = std::none_of( checkEntries.begin(), checkEntries.end(), isUnSatisfied );
createResultWidgets( entriesLayout, m_resultWidgets, checkEntries, isUnSatisfied );
const bool requirementsSatisfied = m_model.satisfiedRequirements();
auto isUnSatisfied = []( const Calamares::RequirementEntry& e ) { return !e.satisfied; };
createResultWidgets( entriesLayout, m_resultWidgets, model, isUnSatisfied );
if ( !requirementsSatisfied )
{
@ -228,7 +230,7 @@ ResultsListWidget::linkClicked( const QString& link )
{
if ( link == "#details" )
{
auto* dialog = new ResultsListDialog( this, m_entries );
auto* dialog = new ResultsListDialog( m_model, this );
dialog->exec();
dialog->deleteLater();
}
@ -237,28 +239,23 @@ ResultsListWidget::linkClicked( const QString& link )
void
ResultsListWidget::retranslate()
{
int i = 0;
for ( const auto& entry : m_entries )
for ( auto i = 0; i < m_model.count(); i++ )
{
const auto &entry = m_model.getEntry(i);
if ( m_resultWidgets[ i ] )
{
m_resultWidgets[ i ]->setText( entry.negatedText() );
}
i++;
}
// Check that all are satisfied (gives warnings if not) and
// all *mandatory* entries are satisfied (gives errors if not).
auto isUnSatisfied = []( const Calamares::RequirementEntry& e ) { return !e.satisfied; };
auto isMandatoryAndUnSatisfied = []( const Calamares::RequirementEntry& e ) { return e.mandatory && !e.satisfied; };
const bool requirementsSatisfied = std::none_of( m_entries.begin(), m_entries.end(), isUnSatisfied );
const bool mandatorySatisfied = std::none_of( m_entries.begin(), m_entries.end(), isMandatoryAndUnSatisfied );
if ( !requirementsSatisfied )
if ( !m_model.satisfiedRequirements() )
{
QString message;
const bool setup = Calamares::Settings::instance()->isSetupMode();
if ( !mandatorySatisfied )
if ( !m_model.satisfiedMandatory() )
{
message = setup ? tr( "This computer does not satisfy the minimum "
"requirements for setting up %1.<br/>"

View File

@ -22,17 +22,15 @@
#include "ResultWidget.h"
#include "modulesystem/Requirement.h"
#include "Config.h"
#include <QWidget>
class QLabel;
class ResultsListWidget : public QWidget
{
Q_OBJECT
public:
explicit ResultsListWidget( QWidget* parent, const Calamares::RequirementsList& checkEntries );
explicit ResultsListWidget(const RequirementsModel &model, QWidget* parent);
private:
/// @brief A link in the explanatory text has been clicked
@ -40,7 +38,7 @@ private:
void retranslate();
QLabel* m_explanation = nullptr; ///< Explanatory text above the list, with link
const Calamares::RequirementsList& m_entries;
const RequirementsModel &m_model;
QList< ResultWidget* > m_resultWidgets; ///< One widget for each unsatisfied entry
};

View File

@ -1,6 +1,6 @@
<RCC>
<qresource prefix="welcome">
<file>language-icon-128px.png</file>
<file>language-icon-48px.png</file>
</qresource>
<qresource prefix="welcome">
<file>language-icon-128px.png</file>
<file>language-icon-48px.png</file>
</qresource>
</RCC>

View File

@ -1,44 +1,44 @@
# This is a re-write of the welcome module using QML view steps
# instead of widgets.
set( _welcome ${CMAKE_CURRENT_SOURCE_DIR}/../welcome )
#set( _welcome ${CMAKE_CURRENT_SOURCE_DIR}/../welcome )
include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ${_welcome} )
#include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ${_welcome} )
# DUPLICATED WITH WELCOME MODULE
find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED DBus Network )
## DUPLICATED WITH WELCOME MODULE
#find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED DBus Network )
find_package( LIBPARTED )
if ( LIBPARTED_FOUND )
set( PARTMAN_SRC ${_welcome}/checker/partman_devices.c )
set( CHECKER_LINK_LIBRARIES ${LIBPARTED_LIBRARY} )
else()
set( PARTMAN_SRC )
set( CHECKER_LINK_LIBRARIES )
add_definitions( -DWITHOUT_LIBPARTED )
endif()
#find_package( LIBPARTED )
#if ( LIBPARTED_FOUND )
# set( PARTMAN_SRC ${_welcome}/checker/partman_devices.c )
# set( CHECKER_LINK_LIBRARIES ${LIBPARTED_LIBRARY} )
#else()
# set( PARTMAN_SRC )
# set( CHECKER_LINK_LIBRARIES )
# add_definitions( -DWITHOUT_LIBPARTED )
#endif()
set( CHECKER_SOURCES
${_welcome}/checker/CheckerContainer.cpp
${_welcome}/checker/GeneralRequirements.cpp
${_welcome}/checker/ResultWidget.cpp
${_welcome}/checker/ResultsListWidget.cpp
${PARTMAN_SRC}
)
#set( CHECKER_SOURCES
# ${_welcome}/checker/CheckerContainer.cpp
# ${_welcome}/checker/GeneralRequirements.cpp
# ${_welcome}/checker/ResultWidget.cpp
# ${_welcome}/checker/ResultsListWidget.cpp
# ${PARTMAN_SRC}
#)
calamares_add_plugin( welcomeq
TYPE viewmodule
EXPORT_MACRO PLUGINDLLEXPORT_PRO
SOURCES
${CHECKER_SOURCES}
WelcomeQmlViewStep.cpp
Config.cpp
RESOURCES
welcomeq.qrc
LINK_PRIVATE_LIBRARIES
calamaresui
${CHECKER_LINK_LIBRARIES}
Qt5::DBus
Qt5::Network
SHARED_LIB
)
#calamares_add_plugin( welcomeq
# TYPE viewmodule
# EXPORT_MACRO PLUGINDLLEXPORT_PRO
# SOURCES
# ${CHECKER_SOURCES}
# WelcomeQmlViewStep.cpp
# Config.cpp
# RESOURCES
# welcomeq.qrc
# LINK_PRIVATE_LIBRARIES
# calamaresui
# ${CHECKER_LINK_LIBRARIES}
# Qt5::DBus
# Qt5::Network
# SHARED_LIB
#)