Merge branch 'milohr-qml-bits'

FIXES #1352
This commit is contained in:
Adriaan de Groot 2020-03-25 13:48:26 +01:00
commit de5c97af11
8 changed files with 361 additions and 263 deletions

View File

@ -12,8 +12,6 @@ else()
add_definitions( -DWITHOUT_LIBPARTED )
endif()
include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )
set( CHECKER_SOURCES
checker/CheckerContainer.cpp
checker/GeneralRequirements.cpp

View File

@ -17,25 +17,25 @@
*/
#include "Config.h"
#include "utils/Logger.h"
#include "utils/Retranslator.h"
#include "Branding.h"
#include "Settings.h"
#include <QApplication>
#include "utils/Logger.h"
#include "utils/Retranslator.h"
void
RequirementsModel::setRequirementsList( const Calamares::RequirementsList& requirements )
{
CALAMARES_RETRANSLATE_SLOT( &RequirementsModel::retranslate )
emit beginResetModel();
m_requierements = requirements;
m_satisfiedRequirements = true;
m_requirements = requirements;
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 );
m_satisfiedRequirements = std::none_of( m_requirements.begin(), m_requirements.end(), isUnSatisfied );
m_satisfiedMandatory = std::none_of( m_requirements.begin(), m_requirements.end(), isMandatoryAndUnSatisfied );
emit satisfiedRequirementsChanged( m_satisfiedRequirements );
emit satisfiedMandatoryChanged();
@ -45,13 +45,13 @@ RequirementsModel::setRequirementsList( const Calamares::RequirementsList& requi
int
RequirementsModel::rowCount( const QModelIndex& ) const
{
return m_requierements.count();
return m_requirements.count();
}
QVariant
RequirementsModel::data( const QModelIndex& index, int role ) const
{
const auto requirement = m_requierements.at( index.row() );
const auto requirement = m_requirements.at( index.row() );
switch ( role )
{
@ -82,7 +82,8 @@ RequirementsModel::roleNames() const
return roles;
}
Config::Config( QObject* parent ) : QObject( parent )
Config::Config( QObject* parent )
: QObject( parent )
, m_requirementsModel( new RequirementsModel( this ) )
, m_languages( CalamaresUtils::Locale::availableTranslations() )
{
@ -91,31 +92,15 @@ Config::Config( QObject* parent ) : QObject( parent )
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 );
m_genericWelcomeMessage = genericWelcomeMessage().arg( *Calamares::Branding::VersionedName );
emit genericWelcomeMessageChanged();
// ui->supportButton->setText( tr( "%1 support" ).arg( *Calamares::Branding::ShortProductName ) );
m_requirementsModel->retranslate();
}
CalamaresUtils::Locale::LabelModel*
@ -168,7 +153,7 @@ Config::initLanguages()
QString name = m_languages->locale( matchedLocaleIndex ).name();
cDebug() << Logger::SubEntry << "Matched with index" << matchedLocaleIndex << name;
CalamaresUtils::installTranslator( name, Calamares::Branding::instance()->translationsDirectory(), qApp );
CalamaresUtils::installTranslator( name, Calamares::Branding::instance()->translationsDirectory() );
setLocaleIndex( matchedLocaleIndex );
}
else
@ -195,8 +180,11 @@ Config::setLanguageIcon(const QString &languageIcon )
void
Config::setLocaleIndex( const int& index )
{
if(index == m_localeIndex || index > CalamaresUtils::Locale::availableTranslations()->rowCount(QModelIndex()) || index < 0)
if ( index == m_localeIndex || index > CalamaresUtils::Locale::availableTranslations()->rowCount( QModelIndex() )
|| index < 0 )
{
return;
}
m_localeIndex = index;
@ -204,8 +192,7 @@ Config::setLocaleIndex(const int& index)
cDebug() << "Selected locale" << selectedLocale;
QLocale::setDefault( selectedLocale );
CalamaresUtils::installTranslator(
selectedLocale, Calamares::Branding::instance()->translationsDirectory(), qApp );
CalamaresUtils::installTranslator( selectedLocale, Calamares::Branding::instance()->translationsDirectory() );
emit localeIndexChanged( m_localeIndex );
}
@ -223,51 +210,118 @@ Config::setIsNextEnabled( const bool& isNextEnabled )
emit isNextEnabledChanged( m_isNextEnabled );
}
QString Config::donateUrl() const
QString
Config::donateUrl() const
{
return m_donateUrl;
}
void Config::setDonateUrl(const QString& url)
void
Config::setDonateUrl( const QString& url )
{
m_donateUrl = url;
emit donateUrlChanged();
}
QString Config::knownIssuesUrl() const
QString
Config::knownIssuesUrl() const
{
return m_knownIssuesUrl;
}
void Config::setKnownIssuesUrl(const QString& url)
void
Config::setKnownIssuesUrl( const QString& url )
{
m_knownIssuesUrl = url;
emit knownIssuesUrlChanged();
}
void Config::setReleaseNotesUrl(const QString& url)
void
Config::setReleaseNotesUrl( const QString& url )
{
m_releaseNotesUrl = url;
emit releaseNotesUrlChanged();
}
QString Config::releaseNotesUrl() const
QString
Config::releaseNotesUrl() const
{
return m_releaseNotesUrl;
}
QString Config::supportUrl() const
QString
Config::supportUrl() const
{
return m_supportUrl;
}
void Config::setSupportUrl(const QString& url)
void
Config::setSupportUrl( const QString& url )
{
m_supportUrl = url;
emit supportUrlChanged();
}
void
RequirementsModel::retranslate()
{
if ( !m_satisfiedRequirements )
{
QString message;
const bool setup = Calamares::Settings::instance()->isSetupMode();
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." );
}
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 );
}
emit warningMessageChanged();
}
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;
}

View File

@ -19,21 +19,23 @@
#ifndef WELCOME_CONFIG_H
#define WELCOME_CONFIG_H
#include <QObject>
#include <QUrl>
#include "modulesystem/Requirement.h"
#include "locale/LabelModel.h"
#include <QObject>
#include <QUrl>
// TODO: move this (and modulesystem/Requirement) to libcalamares
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 )
Q_PROPERTY( QString warningMessage READ warningMessage NOTIFY warningMessageChanged FINAL )
public:
using QAbstractListModel::QAbstractListModel;
enum Roles : short
{
Name,
@ -44,32 +46,27 @@ public:
HasDetails
};
bool satisfiedRequirements() const
{
return m_satisfiedRequirements;
}
bool satisfiedRequirements() const { return m_satisfiedRequirements; }
bool satisfiedMandatory() const
{
return m_satisfiedMandatory;
}
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);
return m_requirements.at( index );
}
void setRequirementsList( const Calamares::RequirementsList& requirements );
int rowCount( const QModelIndex& ) const override;
int count() const
{
return m_requierements.count();
}
int count() const { return m_requirements.count(); }
QString warningMessage() const { return m_warningMessage; }
void retranslate();
QVariant data( const QModelIndex& index, int role ) const override;
@ -77,13 +74,16 @@ protected:
QHash< int, QByteArray > roleNames() const override;
private:
Calamares::RequirementsList m_requierements;
Calamares::RequirementsList m_requirements;
bool m_satisfiedRequirements = false;
bool m_satisfiedMandatory = false;
QString m_warningMessage;
signals:
void satisfiedRequirementsChanged( bool value );
void satisfiedMandatoryChanged();
void warningMessageChanged();
};
@ -99,12 +99,13 @@ class Config : public QObject
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(QString supportUrl MEMBER m_supportUrl CONSTANT FINAL)
Q_PROPERTY(QString knownIssuesUrl MEMBER m_knownIssuesUrl CONSTANT FINAL)
Q_PROPERTY(QString releaseNotesUrl MEMBER m_releaseNotesUrl CONSTANT FINAL)
Q_PROPERTY(QString donateUrl MEMBER m_donateUrl CONSTANT FINAL)
Q_PROPERTY( QString supportUrl MEMBER m_supportUrl NOTIFY supportUrlChanged FINAL )
Q_PROPERTY( QString knownIssuesUrl MEMBER m_knownIssuesUrl NOTIFY knownIssuesUrlChanged FINAL )
Q_PROPERTY( QString releaseNotesUrl MEMBER m_releaseNotesUrl NOTIFY releaseNotesUrlChanged FINAL )
Q_PROPERTY( QString donateUrl MEMBER m_donateUrl NOTIFY donateUrlChanged FINAL )
Q_PROPERTY( bool isNextEnabled MEMBER m_isNextEnabled NOTIFY isNextEnabledChanged FINAL )
public:
Config( QObject* parent = nullptr );
@ -129,6 +130,9 @@ public:
QString donateUrl() const;
void setDonateUrl( const QString& url );
QString genericWelcomeMessage();
public slots:
CalamaresUtils::Locale::LabelModel* languagesModel() const;
void retranslate();
@ -144,9 +148,7 @@ private:
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_genericWelcomeMessage;
QString m_supportUrl;
QString m_knownIssuesUrl;
@ -158,6 +160,10 @@ signals:
void localeIndexChanged( int localeIndex );
void isNextEnabledChanged( bool isNextEnabled );
void genericWelcomeMessageChanged();
void supportUrlChanged();
void knownIssuesUrlChanged();
void releaseNotesUrlChanged();
void donateUrlChanged();
};
#endif

View File

@ -25,9 +25,9 @@
#include "Branding.h"
#include "CalamaresVersion.h"
#include "Config.h"
#include "Settings.h"
#include "ViewManager.h"
#include "Config.h"
#include "locale/LabelModel.h"
#include "modulesystem/ModuleManager.h"
@ -84,7 +84,8 @@ WelcomePage::WelcomePage( Config *conf, QWidget* parent )
ui->verticalLayout->insertWidget( welcome_text_idx + 1, m_checkingWidget );
}
void WelcomePage::init()
void
WelcomePage::init()
{
//setup the url buttons
setupButton( WelcomePage::Button::Support, m_conf->supportUrl() );
@ -113,7 +114,9 @@ WelcomePage::initLanguages()
ui->languageWidget->setCurrentIndex( m_conf->localeIndex() );
connect( ui->languageWidget,
static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ), m_conf, &Config::setLocaleIndex );
static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ),
m_conf,
&Config::setLocaleIndex );
}
void

View File

@ -18,19 +18,18 @@
*/
#include "WelcomeViewStep.h"
#include "Config.h"
#include "Config.h"
#include "WelcomePage.h"
#include "checker/GeneralRequirements.h"
#include "Branding.h"
#include "geoip/Handler.h"
#include "locale/Lookup.h"
#include "modulesystem/ModuleManager.h"
#include "utils/Logger.h"
#include "utils/Variant.h"
#include "Branding.h"
#include "modulesystem/ModuleManager.h"
#include <QFutureWatcher>
#include <QVariant>
@ -145,8 +144,10 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap )
using Calamares::Branding;
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->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" )

View File

@ -16,22 +16,22 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WELCOMEPAGEPLUGIN_H
#define WELCOMEPAGEPLUGIN_H
#ifndef WELCOMEVIEWSTEP_H
#define WELCOMEVIEWSTEP_H
#include "DllMacro.h"
#include "modulesystem/Requirement.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
@ -80,4 +80,4 @@ private:
CALAMARES_PLUGIN_FACTORY_DECLARATION( WelcomeViewStepFactory )
#endif // WELCOMEPAGEPLUGIN_H
#endif // WELCOMEVIEWSTEP_H

View File

@ -41,7 +41,7 @@ CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeQmlViewStepFactory, registerPlugin<
WelcomeQmlViewStep::WelcomeQmlViewStep( QObject* parent )
: Calamares::QmlViewStep(parent )
, m_config( new Config( ) ) // the qml singleton takes ownership and deletes it
, m_config( new Config( this ) ) // the qml singleton takes ownership and deletes it
// , m_nextEnabled( false )
, m_requirementsChecker( new GeneralRequirements( this ) )
@ -98,10 +98,46 @@ WelcomeQmlViewStep::jobs() const
return Calamares::JobList();
}
/** @brief Look up a URL for a button
*
* Looks up @p key in @p map; if it is a *boolean* value, then
* assume an old-style configuration, and fetch the string from
* the branding settings @p e. If it is a string, not a boolean,
* use it as-is. If not found, or a weird type, returns empty.
*
* This allows switching the showKnownIssuesUrl and similar settings
* in welcome.conf from a boolean (deferring to branding) to an
* actual string for immediate use. Empty strings, as well as
* "false" as a setting, will hide the buttons as before.
*/
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();
}
return QString();
}
void
WelcomeQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap )
{
using Calamares::Branding;
m_config->setSupportUrl( jobOrBrandingSetting( Branding::SupportUrl, configurationMap, "showSupportUrl" ) );
m_config->setKnownIssuesUrl( jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) );
m_config->setReleaseNotesUrl( jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) );
m_config->setDonateUrl( CalamaresUtils::getString( configurationMap, "showDonateUrl" ) );
// TODO: expand Config class and set the remaining fields // with the configurationMap all those properties can be accesed withouth having to declare a property, get and setter for each