[welcome] Apply coding style

This commit is contained in:
Adriaan de Groot 2020-03-25 11:41:39 +01:00
parent ff74113675
commit 1ede7003c0
6 changed files with 224 additions and 228 deletions

View File

@ -17,10 +17,10 @@
*/ */
#include "Config.h" #include "Config.h"
#include "utils/Logger.h"
#include "utils/Retranslator.h"
#include "Branding.h" #include "Branding.h"
#include "Settings.h" #include "Settings.h"
#include "utils/Logger.h"
#include "utils/Retranslator.h"
#include <QApplication> #include <QApplication>
@ -38,7 +38,7 @@ RequirementsModel::setRequirementsList( const Calamares::RequirementsList& requi
m_satisfiedRequirements = std::none_of( m_requirements.begin(), m_requirements.end(), isUnSatisfied ); m_satisfiedRequirements = std::none_of( m_requirements.begin(), m_requirements.end(), isUnSatisfied );
m_satisfiedMandatory = std::none_of( m_requirements.begin(), m_requirements.end(), isMandatoryAndUnSatisfied ); m_satisfiedMandatory = std::none_of( m_requirements.begin(), m_requirements.end(), isMandatoryAndUnSatisfied );
emit satisfiedRequirementsChanged(m_satisfiedRequirements); emit satisfiedRequirementsChanged( m_satisfiedRequirements );
emit satisfiedMandatoryChanged(); emit satisfiedMandatoryChanged();
emit endResetModel(); emit endResetModel();
} }
@ -71,23 +71,24 @@ RequirementsModel::data( const QModelIndex& index, int role ) const
} }
} }
QHash<int, QByteArray> QHash< int, QByteArray >
RequirementsModel::roleNames() const RequirementsModel::roleNames() const
{ {
static QHash<int, QByteArray> roles; static QHash< int, QByteArray > roles;
roles[Roles::Name] = "name"; roles[ Roles::Name ] = "name";
roles[Roles::Details] = "details"; roles[ Roles::Details ] = "details";
roles[Roles::NegatedText] = "negatedText"; roles[ Roles::NegatedText ] = "negatedText";
roles[Roles::Satisfied] = "satisfied"; roles[ Roles::Satisfied ] = "satisfied";
roles[Roles::Mandatory] = "mandatory"; roles[ Roles::Mandatory ] = "mandatory";
return roles; return roles;
} }
Config::Config( QObject* parent ) : QObject( parent ) Config::Config( QObject* parent )
, m_requirementsModel( new RequirementsModel( this )) : QObject( parent )
, m_requirementsModel( new RequirementsModel( this ) )
, m_languages( CalamaresUtils::Locale::availableTranslations() ) , m_languages( CalamaresUtils::Locale::availableTranslations() )
{ {
connect(m_requirementsModel, &RequirementsModel::satisfiedRequirementsChanged, this, &Config::setIsNextEnabled); connect( m_requirementsModel, &RequirementsModel::satisfiedRequirementsChanged, this, &Config::setIsNextEnabled );
initLanguages(); initLanguages();
@ -166,22 +167,25 @@ void
Config::setCountryCode( const QString& countryCode ) Config::setCountryCode( const QString& countryCode )
{ {
m_countryCode = countryCode; m_countryCode = countryCode;
setLocaleIndex(CalamaresUtils::Locale::availableTranslations()->find( m_countryCode )); setLocaleIndex( CalamaresUtils::Locale::availableTranslations()->find( m_countryCode ) );
emit countryCodeChanged( m_countryCode ); emit countryCodeChanged( m_countryCode );
} }
void void
Config::setLanguageIcon(const QString &languageIcon ) Config::setLanguageIcon( const QString& languageIcon )
{ {
m_languageIcon = languageIcon; m_languageIcon = languageIcon;
} }
void void
Config::setLocaleIndex(const int& index) 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; return;
}
m_localeIndex = index; m_localeIndex = index;
@ -189,8 +193,7 @@ Config::setLocaleIndex(const int& index)
cDebug() << "Selected locale" << selectedLocale; cDebug() << "Selected locale" << selectedLocale;
QLocale::setDefault( selectedLocale ); QLocale::setDefault( selectedLocale );
CalamaresUtils::installTranslator( CalamaresUtils::installTranslator( selectedLocale, Calamares::Branding::instance()->translationsDirectory(), qApp );
selectedLocale, Calamares::Branding::instance()->translationsDirectory(), qApp );
emit localeIndexChanged( m_localeIndex ); emit localeIndexChanged( m_localeIndex );
} }
@ -215,7 +218,7 @@ Config::donateUrl() const
} }
void void
Config::setDonateUrl(const QString& url) Config::setDonateUrl( const QString& url )
{ {
m_donateUrl = url; m_donateUrl = url;
emit donateUrlChanged(); emit donateUrlChanged();
@ -228,14 +231,14 @@ Config::knownIssuesUrl() const
} }
void void
Config::setKnownIssuesUrl(const QString& url) Config::setKnownIssuesUrl( const QString& url )
{ {
m_knownIssuesUrl = url; m_knownIssuesUrl = url;
emit knownIssuesUrlChanged(); emit knownIssuesUrlChanged();
} }
void void
Config::setReleaseNotesUrl(const QString& url) Config::setReleaseNotesUrl( const QString& url )
{ {
m_releaseNotesUrl = url; m_releaseNotesUrl = url;
emit releaseNotesUrlChanged(); emit releaseNotesUrlChanged();
@ -254,7 +257,7 @@ Config::supportUrl() const
} }
void void
Config::setSupportUrl(const QString& url) Config::setSupportUrl( const QString& url )
{ {
m_supportUrl = url; m_supportUrl = url;
emit supportUrlChanged(); emit supportUrlChanged();
@ -278,8 +281,8 @@ RequirementsModel::retranslate()
"requirements for installing %1.<br/>" "requirements for installing %1.<br/>"
"Installation cannot continue. " "Installation cannot continue. "
"<a href=\"#details\">Details...</a>" ); "<a href=\"#details\">Details...</a>" );
}
}else else
{ {
message = setup ? tr( "This computer does not satisfy some of the " message = setup ? tr( "This computer does not satisfy some of the "
"recommended requirements for setting up %1.<br/>" "recommended requirements for setting up %1.<br/>"
@ -292,7 +295,8 @@ RequirementsModel::retranslate()
} }
m_warningMessage = message.arg( *Calamares::Branding::ShortVersionedName ); m_warningMessage = message.arg( *Calamares::Branding::ShortVersionedName );
}else }
else
{ {
m_warningMessage = tr( "This program will ask you some questions and " m_warningMessage = tr( "This program will ask you some questions and "
"set up %2 on your computer." ) "set up %2 on your computer." )
@ -322,4 +326,3 @@ Config::genericWelcomeMessage()
return message; return message;
} }

View File

@ -19,9 +19,9 @@
#ifndef WELCOME_CONFIG_H #ifndef WELCOME_CONFIG_H
#define WELCOME_CONFIG_H #define WELCOME_CONFIG_H
#include "modulesystem/Requirement.h"
#include <QObject> #include <QObject>
#include <QUrl> #include <QUrl>
#include "modulesystem/Requirement.h"
#include "locale/LabelModel.h" #include "locale/LabelModel.h"
@ -29,9 +29,9 @@ class RequirementsModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
using QAbstractListModel::QAbstractListModel; using QAbstractListModel::QAbstractListModel;
Q_PROPERTY(bool satisfiedRequirements READ satisfiedRequirements NOTIFY satisfiedRequirementsChanged FINAL) Q_PROPERTY( bool satisfiedRequirements READ satisfiedRequirements NOTIFY satisfiedRequirementsChanged FINAL )
Q_PROPERTY(bool satisfiedMandatory READ satisfiedMandatory NOTIFY satisfiedMandatoryChanged FINAL) Q_PROPERTY( bool satisfiedMandatory READ satisfiedMandatory NOTIFY satisfiedMandatoryChanged FINAL )
Q_PROPERTY( QString warningMessage READ warningMessage NOTIFY warningMessageChanged FINAL ) Q_PROPERTY( QString warningMessage READ warningMessage NOTIFY warningMessageChanged FINAL )
public: public:
@ -45,44 +45,33 @@ public:
HasDetails HasDetails
}; };
bool satisfiedRequirements() const bool satisfiedRequirements() const { return m_satisfiedRequirements; }
bool satisfiedMandatory() const { return m_satisfiedMandatory; }
const Calamares::RequirementEntry& getEntry( const int& index ) const
{ {
return m_satisfiedRequirements;
if ( index > count() || index < 0 )
{
return *( new Calamares::RequirementEntry() );
} }
bool satisfiedMandatory() const return m_requirements.at( index );
{
return m_satisfiedMandatory;
}
const Calamares::RequirementEntry& getEntry(const int& index) const
{
if(index > count() || index < 0)
return *(new Calamares::RequirementEntry());
return m_requirements.at(index);
} }
void setRequirementsList( const Calamares::RequirementsList& requirements ); void setRequirementsList( const Calamares::RequirementsList& requirements );
int rowCount(const QModelIndex&) const override; int rowCount( const QModelIndex& ) const override;
int count() const int count() const { return m_requirements.count(); }
{
return m_requirements.count();
}
QString warningMessage() const QString warningMessage() const { return m_warningMessage; }
{
return m_warningMessage;
}
void retranslate(); void retranslate();
QVariant data(const QModelIndex& index, int role) const override; QVariant data( const QModelIndex& index, int role ) const override;
protected: protected:
QHash<int, QByteArray> roleNames() const override; QHash< int, QByteArray > roleNames() const override;
private: private:
Calamares::RequirementsList m_requirements; Calamares::RequirementsList m_requirements;
@ -92,7 +81,7 @@ private:
QString m_warningMessage; QString m_warningMessage;
signals: signals:
void satisfiedRequirementsChanged(bool value); void satisfiedRequirementsChanged( bool value );
void satisfiedMandatoryChanged(); void satisfiedMandatoryChanged();
void warningMessageChanged(); void warningMessageChanged();
}; };
@ -101,45 +90,45 @@ signals:
class Config : public QObject class Config : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY( CalamaresUtils::Locale::LabelModel* languagesModel READ languagesModel CONSTANT FINAL) Q_PROPERTY( CalamaresUtils::Locale::LabelModel* languagesModel READ languagesModel CONSTANT FINAL )
Q_PROPERTY( RequirementsModel* requirementsModel MEMBER m_requirementsModel CONSTANT FINAL ) Q_PROPERTY( RequirementsModel* requirementsModel MEMBER m_requirementsModel CONSTANT FINAL )
Q_PROPERTY( QString languageIcon READ languageIcon CONSTANT FINAL ) Q_PROPERTY( QString languageIcon READ languageIcon CONSTANT FINAL )
Q_PROPERTY( QString countryCode MEMBER m_countryCode NOTIFY countryCodeChanged FINAL ) Q_PROPERTY( QString countryCode MEMBER m_countryCode NOTIFY countryCodeChanged FINAL )
Q_PROPERTY (int localeIndex READ localeIndex WRITE setLocaleIndex NOTIFY localeIndexChanged) Q_PROPERTY( int localeIndex READ localeIndex WRITE setLocaleIndex NOTIFY localeIndexChanged )
Q_PROPERTY( QString genericWelcomeMessage MEMBER m_genericWelcomeMessage NOTIFY genericWelcomeMessageChanged FINAL ) Q_PROPERTY( QString genericWelcomeMessage MEMBER m_genericWelcomeMessage NOTIFY genericWelcomeMessageChanged FINAL )
Q_PROPERTY( QString supportUrl MEMBER m_supportUrl NOTIFY supportUrlChanged FINAL ) Q_PROPERTY( QString supportUrl MEMBER m_supportUrl NOTIFY supportUrlChanged FINAL )
Q_PROPERTY( QString knownIssuesUrl MEMBER m_knownIssuesUrl NOTIFY knownIssuesUrlChanged FINAL ) Q_PROPERTY( QString knownIssuesUrl MEMBER m_knownIssuesUrl NOTIFY knownIssuesUrlChanged FINAL )
Q_PROPERTY( QString releaseNotesUrl MEMBER m_releaseNotesUrl NOTIFY releaseNotesUrlChanged FINAL ) Q_PROPERTY( QString releaseNotesUrl MEMBER m_releaseNotesUrl NOTIFY releaseNotesUrlChanged FINAL )
Q_PROPERTY (QString donateUrl MEMBER m_donateUrl NOTIFY donateUrlChanged FINAL ) Q_PROPERTY( QString donateUrl MEMBER m_donateUrl NOTIFY donateUrlChanged FINAL )
Q_PROPERTY( bool isNextEnabled MEMBER m_isNextEnabled NOTIFY isNextEnabledChanged FINAL ) Q_PROPERTY( bool isNextEnabled MEMBER m_isNextEnabled NOTIFY isNextEnabledChanged FINAL )
public: public:
Config( QObject* parent = nullptr ); Config( QObject* parent = nullptr );
void setCountryCode( const QString &countryCode ); void setCountryCode( const QString& countryCode );
void setLanguageIcon( const QString &languageIcon ); void setLanguageIcon( const QString& languageIcon );
RequirementsModel& requirementsModel () const; RequirementsModel& requirementsModel() const;
void setIsNextEnabled( const bool& isNextEnabled ); void setIsNextEnabled( const bool& isNextEnabled );
void setLocaleIndex(const int &index); void setLocaleIndex( const int& index );
int localeIndex() const { return m_localeIndex; } int localeIndex() const { return m_localeIndex; }
QString supportUrl() const; QString supportUrl() const;
void setSupportUrl(const QString &url); void setSupportUrl( const QString& url );
QString knownIssuesUrl() const; QString knownIssuesUrl() const;
void setKnownIssuesUrl(const QString &url); void setKnownIssuesUrl( const QString& url );
QString releaseNotesUrl() const; QString releaseNotesUrl() const;
void setReleaseNotesUrl(const QString &url); void setReleaseNotesUrl( const QString& url );
QString donateUrl() const; QString donateUrl() const;
void setDonateUrl(const QString &url); void setDonateUrl( const QString& url );
QString genericWelcomeMessage(); QString genericWelcomeMessage();
@ -175,7 +164,6 @@ signals:
void knownIssuesUrlChanged(); void knownIssuesUrlChanged();
void releaseNotesUrlChanged(); void releaseNotesUrlChanged();
void donateUrlChanged(); void donateUrlChanged();
}; };
#endif #endif

View File

@ -25,9 +25,9 @@
#include "Branding.h" #include "Branding.h"
#include "CalamaresVersion.h" #include "CalamaresVersion.h"
#include "Config.h"
#include "Settings.h" #include "Settings.h"
#include "ViewManager.h" #include "ViewManager.h"
#include "Config.h"
#include "locale/LabelModel.h" #include "locale/LabelModel.h"
#include "modulesystem/ModuleManager.h" #include "modulesystem/ModuleManager.h"
@ -44,7 +44,7 @@
#include <QLabel> #include <QLabel>
#include <QMessageBox> #include <QMessageBox>
WelcomePage::WelcomePage( Config *conf, QWidget* parent ) WelcomePage::WelcomePage( Config* conf, QWidget* parent )
: QWidget( parent ) : QWidget( parent )
, ui( new Ui::WelcomePage ) , ui( new Ui::WelcomePage )
, m_checkingWidget( new CheckerContainer( conf->requirementsModel(), this ) ) , m_checkingWidget( new CheckerContainer( conf->requirementsModel(), this ) )
@ -84,13 +84,14 @@ WelcomePage::WelcomePage( Config *conf, QWidget* parent )
ui->verticalLayout->insertWidget( welcome_text_idx + 1, m_checkingWidget ); ui->verticalLayout->insertWidget( welcome_text_idx + 1, m_checkingWidget );
} }
void WelcomePage::init() void
WelcomePage::init()
{ {
//setup the url buttons //setup the url buttons
setupButton( WelcomePage::Button::Support, m_conf->supportUrl()); setupButton( WelcomePage::Button::Support, m_conf->supportUrl() );
setupButton( WelcomePage::Button::KnownIssues, m_conf->knownIssuesUrl() ); setupButton( WelcomePage::Button::KnownIssues, m_conf->knownIssuesUrl() );
setupButton( WelcomePage::Button::ReleaseNotes, m_conf->releaseNotesUrl() ); setupButton( WelcomePage::Button::ReleaseNotes, m_conf->releaseNotesUrl() );
setupButton( WelcomePage::Button::Donate, m_conf->donateUrl()); setupButton( WelcomePage::Button::Donate, m_conf->donateUrl() );
//language icon //language icon
auto icon = Calamares::Branding::instance()->image( m_conf->languageIcon(), QSize( 48, 48 ) ); auto icon = Calamares::Branding::instance()->image( m_conf->languageIcon(), QSize( 48, 48 ) );
@ -113,7 +114,9 @@ WelcomePage::initLanguages()
ui->languageWidget->setCurrentIndex( m_conf->localeIndex() ); ui->languageWidget->setCurrentIndex( m_conf->localeIndex() );
connect( ui->languageWidget, 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 void

View File

@ -36,7 +36,7 @@ class WelcomePage : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit WelcomePage( Config *conf, QWidget* parent = nullptr ); explicit WelcomePage( Config* conf, QWidget* parent = nullptr );
enum class Button enum class Button
{ {
@ -75,7 +75,7 @@ private:
CheckerContainer* m_checkingWidget; CheckerContainer* m_checkingWidget;
CalamaresUtils::Locale::LabelModel* m_languages; CalamaresUtils::Locale::LabelModel* m_languages;
Config *m_conf; Config* m_conf;
}; };
/** @brief Delegate to display language information in two columns. /** @brief Delegate to display language information in two columns.

View File

@ -39,7 +39,7 @@ CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeViewStepFactory, registerPlugin< Wel
WelcomeViewStep::WelcomeViewStep( QObject* parent ) WelcomeViewStep::WelcomeViewStep( QObject* parent )
: Calamares::ViewStep( parent ) : Calamares::ViewStep( parent )
, m_requirementsChecker( new GeneralRequirements( this ) ) , m_requirementsChecker( new GeneralRequirements( this ) )
, m_conf( new Config(this) ) , m_conf( new Config( this ) )
{ {
connect( Calamares::ModuleManager::instance(), connect( Calamares::ModuleManager::instance(),
&Calamares::ModuleManager::requirementsComplete, &Calamares::ModuleManager::requirementsComplete,
@ -47,7 +47,7 @@ WelcomeViewStep::WelcomeViewStep( QObject* parent )
&WelcomeViewStep::nextStatusChanged ); &WelcomeViewStep::nextStatusChanged );
// the instance of the qqc2 or qwidgets page // the instance of the qqc2 or qwidgets page
m_widget = new WelcomePage(m_conf); m_widget = new WelcomePage( m_conf );
} }
WelcomeViewStep::~WelcomeViewStep() WelcomeViewStep::~WelcomeViewStep()
@ -145,8 +145,10 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap )
using Calamares::Branding; using Calamares::Branding;
m_conf->setSupportUrl( jobOrBrandingSetting( Branding::SupportUrl, configurationMap, "showSupportUrl" ) ); m_conf->setSupportUrl( jobOrBrandingSetting( Branding::SupportUrl, configurationMap, "showSupportUrl" ) );
m_conf->setKnownIssuesUrl( jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) ); m_conf->setKnownIssuesUrl(
m_conf->setReleaseNotesUrl( jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) ); jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) );
m_conf->setReleaseNotesUrl(
jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) );
m_conf->setDonateUrl( CalamaresUtils::getString( configurationMap, "showDonateUrl" ) ); m_conf->setDonateUrl( CalamaresUtils::getString( configurationMap, "showDonateUrl" ) );
if ( configurationMap.contains( "requirements" ) if ( configurationMap.contains( "requirements" )

View File

@ -75,7 +75,7 @@ public:
private: private:
WelcomePage* m_widget; WelcomePage* m_widget;
GeneralRequirements* m_requirementsChecker; GeneralRequirements* m_requirementsChecker;
Config *m_conf; Config* m_conf;
}; };
CALAMARES_PLUGIN_FACTORY_DECLARATION( WelcomeViewStepFactory ) CALAMARES_PLUGIN_FACTORY_DECLARATION( WelcomeViewStepFactory )