mirror of https://github.com/cutefishos/calamares
commit
fa9006c677
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,163 @@
|
||||
/* === 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(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)
|
||||
|
||||
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
|
@ -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>
|
||||
|
@ -1,23 +0,0 @@
|
||||
/* === 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"
|
||||
|
||||
Config::Config() {}
|
||||
|
||||
Config::~Config() {}
|
@ -1,51 +0,0 @@
|
||||
/* === 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 WELCOMEQ_CONFIG_H
|
||||
#define WELCOMEQ_CONFIG_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
|
||||
class Config : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY( QUrl helpUrl READ helpUrl CONSTANT FINAL )
|
||||
Q_PROPERTY( QUrl issuesUrl READ issuesUrl CONSTANT FINAL )
|
||||
Q_PROPERTY( QUrl notesUrl READ notesUrl CONSTANT FINAL )
|
||||
Q_PROPERTY( QUrl donateUrl READ donateUrl CONSTANT FINAL )
|
||||
public:
|
||||
Config();
|
||||
virtual ~Config();
|
||||
|
||||
void setHelpUrl( const QUrl& url ) { m_helpUrl = url; }
|
||||
void setIssuesUrl( const QUrl& url ) { m_issuesUrl = url; }
|
||||
void setNotesUrl( const QUrl& url ) { m_notesUrl = url; }
|
||||
void setDonateUrl( const QUrl& url ) { m_donateUrl = url; }
|
||||
|
||||
public slots:
|
||||
QUrl helpUrl() const { return m_helpUrl; }
|
||||
QUrl issuesUrl() const { return m_issuesUrl; }
|
||||
QUrl notesUrl() const { return m_notesUrl; }
|
||||
QUrl donateUrl() const { return m_donateUrl; }
|
||||
|
||||
private:
|
||||
QUrl m_helpUrl, m_issuesUrl, m_notesUrl, m_donateUrl;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue