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-03-31 19:13:55 +02:00
|
|
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
2015-04-01 18:11:38 +02:00
|
|
|
* Copyright 2015, Anke Boersma <demm@kaosx.us>
|
2019-04-18 23:17:49 +02:00
|
|
|
* Copyright 2017-2019, 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 "WelcomePage.h"
|
2014-06-11 13:37:10 +02:00
|
|
|
|
2015-05-13 12:44:11 +02:00
|
|
|
#include "ui_WelcomePage.h"
|
2017-12-02 15:56:03 +01:00
|
|
|
#include "checker/CheckerContainer.h"
|
|
|
|
|
2019-04-18 23:17:49 +02:00
|
|
|
#include "Branding.h"
|
|
|
|
#include "CalamaresVersion.h"
|
2019-04-01 11:54:35 +02:00
|
|
|
#include "Settings.h"
|
2014-11-10 12:40:00 +01:00
|
|
|
#include "ViewManager.h"
|
2019-05-10 17:46:20 +02:00
|
|
|
|
|
|
|
#include "locale/LabelModel.h"
|
2019-04-18 23:17:49 +02:00
|
|
|
#include "modulesystem/ModuleManager.h"
|
|
|
|
#include "utils/CalamaresUtilsGui.h"
|
2019-04-19 10:10:36 +02:00
|
|
|
#include "utils/Logger.h"
|
2019-04-18 23:17:49 +02:00
|
|
|
#include "utils/Retranslator.h"
|
2014-11-10 12:40:00 +01:00
|
|
|
|
|
|
|
#include <QApplication>
|
2014-06-27 18:00:27 +02:00
|
|
|
#include <QBoxLayout>
|
2019-04-19 13:34:25 +02:00
|
|
|
#include <QComboBox>
|
2015-04-02 12:28:40 +02:00
|
|
|
#include <QDesktopServices>
|
2014-11-10 12:40:00 +01:00
|
|
|
#include <QFocusEvent>
|
2014-06-27 18:00:27 +02:00
|
|
|
#include <QLabel>
|
2014-11-20 09:40:55 +01:00
|
|
|
#include <QMessageBox>
|
2014-06-27 18:00:27 +02:00
|
|
|
|
2017-12-02 15:56:03 +01:00
|
|
|
WelcomePage::WelcomePage( QWidget* parent )
|
2014-11-20 09:40:55 +01:00
|
|
|
: QWidget( parent )
|
2015-05-13 12:44:11 +02:00
|
|
|
, ui( new Ui::WelcomePage )
|
2017-12-02 15:56:03 +01:00
|
|
|
, m_checkingWidget( new CheckerContainer( this ) )
|
2019-04-18 23:17:49 +02:00
|
|
|
, m_languages( nullptr )
|
2014-06-11 13:37:10 +02:00
|
|
|
{
|
2017-12-02 15:56:03 +01:00
|
|
|
connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsResult, m_checkingWidget, &CheckerContainer::requirementsChecked );
|
|
|
|
connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsComplete, m_checkingWidget, &CheckerContainer::requirementsComplete );
|
2019-02-24 15:07:44 +01:00
|
|
|
connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsProgress, m_checkingWidget, &CheckerContainer::requirementsProgress );
|
2014-11-20 09:40:55 +01:00
|
|
|
ui->setupUi( this );
|
2015-05-14 18:02:26 +02:00
|
|
|
|
2017-06-28 08:46:24 +02:00
|
|
|
ui->verticalLayout->insertSpacing( 1, CalamaresUtils::defaultFontHeight() * 2 );
|
2015-05-14 18:02:26 +02:00
|
|
|
initLanguages();
|
|
|
|
|
|
|
|
ui->mainText->setAlignment( Qt::AlignCenter );
|
|
|
|
ui->mainText->setWordWrap( true );
|
|
|
|
ui->mainText->setOpenExternalLinks( true );
|
|
|
|
|
2017-06-12 21:25:05 +02:00
|
|
|
cDebug() << "Welcome string" << Calamares::Branding::instance()->welcomeStyleCalamares()
|
2017-07-04 00:07:18 +02:00
|
|
|
<< *Calamares::Branding::VersionedName;
|
2017-06-12 21:25:05 +02:00
|
|
|
|
2015-05-14 18:02:26 +02:00
|
|
|
CALAMARES_RETRANSLATE(
|
2019-04-01 11:54:35 +02:00
|
|
|
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>" );
|
|
|
|
|
|
|
|
ui->mainText->setText( message.arg( *Calamares::Branding::VersionedName ) );
|
2015-05-14 18:02:26 +02:00
|
|
|
ui->retranslateUi( this );
|
|
|
|
)
|
|
|
|
|
|
|
|
ui->aboutButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Information,
|
|
|
|
CalamaresUtils::Original,
|
|
|
|
2*QSize( CalamaresUtils::defaultFontHeight(),
|
|
|
|
CalamaresUtils::defaultFontHeight() ) ) );
|
|
|
|
connect( ui->aboutButton, &QPushButton::clicked,
|
|
|
|
this, [ this ]
|
|
|
|
{
|
2019-04-01 11:54:35 +02:00
|
|
|
QString title = Calamares::Settings::instance()->isSetupMode()
|
|
|
|
? tr( "About %1 setup" )
|
|
|
|
: tr( "About %1 installer" );
|
2015-06-16 02:38:07 +02:00
|
|
|
QMessageBox mb( QMessageBox::Information,
|
2019-04-01 11:54:35 +02:00
|
|
|
title.arg( CALAMARES_APPLICATION_NAME ),
|
2015-06-16 02:38:07 +02:00
|
|
|
tr(
|
|
|
|
"<h1>%1</h1><br/>"
|
|
|
|
"<strong>%2<br/>"
|
|
|
|
"for %3</strong><br/><br/>"
|
2017-01-20 16:17:55 +01:00
|
|
|
"Copyright 2014-2017 Teo Mrnjavac <teo@kde.org><br/>"
|
2019-03-17 09:43:42 +01:00
|
|
|
"Copyright 2017-2019 Adriaan de Groot <groot@kde.org><br/>"
|
|
|
|
"Thanks to <a href=\"https://calamares.io/team/\">the Calamares team</a> "
|
|
|
|
"and the <a href=\"https://www.transifex.com/calamares/calamares/\">Calamares "
|
2016-03-29 13:40:23 +02:00
|
|
|
"translators team</a>.<br/><br/>"
|
2018-01-03 10:20:21 +01:00
|
|
|
"<a href=\"https://calamares.io/\">Calamares</a> "
|
2015-06-16 02:38:07 +02:00
|
|
|
"development is sponsored by <br/>"
|
|
|
|
"<a href=\"http://www.blue-systems.com/\">Blue Systems</a> - "
|
|
|
|
"Liberating Software."
|
|
|
|
)
|
|
|
|
.arg( CALAMARES_APPLICATION_NAME )
|
|
|
|
.arg( CALAMARES_VERSION )
|
2017-07-04 00:07:18 +02:00
|
|
|
.arg( *Calamares::Branding::VersionedName ),
|
2015-06-16 02:38:07 +02:00
|
|
|
QMessageBox::Ok,
|
|
|
|
this );
|
|
|
|
mb.setIconPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::Squid,
|
|
|
|
CalamaresUtils::Original,
|
|
|
|
QSize( CalamaresUtils::defaultFontHeight() * 6,
|
|
|
|
CalamaresUtils::defaultFontHeight() * 6 ) ) );
|
2017-07-12 13:43:47 +02:00
|
|
|
QGridLayout* layout = reinterpret_cast<QGridLayout *>( mb.layout() );
|
|
|
|
if ( layout )
|
|
|
|
layout->setColumnMinimumWidth( 2, CalamaresUtils::defaultFontHeight() * 24 );
|
2015-06-16 02:38:07 +02:00
|
|
|
mb.exec();
|
2015-05-14 18:02:26 +02:00
|
|
|
} );
|
|
|
|
|
2017-12-02 15:56:03 +01:00
|
|
|
ui->verticalLayout->insertWidget( 3, m_checkingWidget);
|
2015-05-14 18:02:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-19 00:18:00 +02:00
|
|
|
void
|
|
|
|
WelcomePage::initLanguages()
|
|
|
|
{
|
2018-04-18 16:42:58 +02:00
|
|
|
// Fill the list of translations
|
2018-04-19 00:18:00 +02:00
|
|
|
ui->languageWidget->clear();
|
|
|
|
ui->languageWidget->setInsertPolicy( QComboBox::InsertAtBottom );
|
|
|
|
|
2019-05-10 18:06:10 +02:00
|
|
|
m_languages = CalamaresUtils::Locale::availableTranslations();
|
2019-04-18 23:17:49 +02:00
|
|
|
ui->languageWidget->setModel( m_languages );
|
2019-04-19 13:34:25 +02:00
|
|
|
ui->languageWidget->setItemDelegate( new LocaleTwoColumnDelegate( ui->languageWidget ) );
|
2014-11-10 12:40:00 +01:00
|
|
|
|
2018-04-18 16:42:58 +02:00
|
|
|
// Find the best initial translation
|
2018-04-19 00:18:00 +02:00
|
|
|
QLocale defaultLocale = QLocale( QLocale::system().name() );
|
2015-01-18 14:56:46 +01:00
|
|
|
|
2019-04-19 10:15:57 +02:00
|
|
|
cDebug() << "Matching locale" << defaultLocale;
|
2019-04-19 10:10:36 +02:00
|
|
|
int matchedLocaleIndex = m_languages->find(
|
|
|
|
[&](const QLocale& x){ return x.language() == defaultLocale.language() && x.country() == defaultLocale.country(); } );
|
2015-01-18 14:56:46 +01:00
|
|
|
|
2019-04-19 10:10:36 +02:00
|
|
|
if ( matchedLocaleIndex < 0 )
|
2018-04-18 16:42:58 +02:00
|
|
|
{
|
2019-04-19 10:15:57 +02:00
|
|
|
cDebug() << Logger::SubEntry << "Matching approximate locale" << defaultLocale.language();
|
2018-03-28 13:47:13 +02:00
|
|
|
|
2019-04-19 10:10:36 +02:00
|
|
|
matchedLocaleIndex = m_languages->find(
|
|
|
|
[&](const QLocale& x){ return x.language() == defaultLocale.language(); } );
|
2014-11-10 12:40:00 +01:00
|
|
|
}
|
2018-04-18 16:42:58 +02:00
|
|
|
|
2019-04-19 10:10:36 +02:00
|
|
|
if ( matchedLocaleIndex < 0 )
|
2018-04-18 16:42:58 +02:00
|
|
|
{
|
|
|
|
QLocale en_us( QLocale::English, QLocale::UnitedStates );
|
|
|
|
|
2019-04-19 10:15:57 +02:00
|
|
|
cDebug() << Logger::SubEntry << "Matching English (US)";
|
2019-04-19 10:10:36 +02:00
|
|
|
matchedLocaleIndex = m_languages->find( en_us );
|
2014-11-10 12:40:00 +01:00
|
|
|
|
2018-04-18 16:42:58 +02:00
|
|
|
// Now, if it matched, because we didn't match the system locale, switch to the one found
|
2019-04-19 10:10:36 +02:00
|
|
|
if ( matchedLocaleIndex >= 0 )
|
|
|
|
QLocale::setDefault( m_languages->locale( matchedLocaleIndex ).locale() );
|
2014-11-10 12:40:00 +01:00
|
|
|
}
|
2018-04-18 16:42:58 +02:00
|
|
|
|
2019-04-19 10:10:36 +02:00
|
|
|
if ( matchedLocaleIndex >= 0 )
|
2019-04-19 10:15:57 +02:00
|
|
|
{
|
|
|
|
QString name = m_languages->locale( matchedLocaleIndex ).name();
|
|
|
|
cDebug() << Logger::SubEntry << "Matched with index" << matchedLocaleIndex << name;
|
2019-04-19 13:34:25 +02:00
|
|
|
|
2019-04-23 22:41:22 +02:00
|
|
|
CalamaresUtils::installTranslator( name, Calamares::Branding::instance()->translationsDirectory(), qApp );
|
2019-04-19 10:15:57 +02:00
|
|
|
ui->languageWidget->setCurrentIndex( matchedLocaleIndex );
|
|
|
|
}
|
2018-04-18 16:42:58 +02:00
|
|
|
else
|
|
|
|
cWarning() << "No available translation matched" << defaultLocale;
|
|
|
|
|
|
|
|
connect( ui->languageWidget,
|
|
|
|
static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ),
|
|
|
|
this,
|
|
|
|
[&]( int newIndex )
|
|
|
|
{
|
2019-04-19 10:24:10 +02:00
|
|
|
const auto& selectedLocale = m_languages->locale( newIndex ).locale();
|
2018-04-19 14:40:04 +02:00
|
|
|
cDebug() << "Selected locale" << selectedLocale;
|
2018-04-18 16:42:58 +02:00
|
|
|
|
|
|
|
QLocale::setDefault( selectedLocale );
|
|
|
|
CalamaresUtils::installTranslator( selectedLocale,
|
2018-05-22 11:21:20 +02:00
|
|
|
Calamares::Branding::instance()->translationsDirectory(),
|
2018-04-18 16:42:58 +02:00
|
|
|
qApp );
|
|
|
|
} );
|
2014-11-10 12:40:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-02 12:28:40 +02:00
|
|
|
void
|
2015-05-13 12:44:11 +02:00
|
|
|
WelcomePage::setUpLinks( bool showSupportUrl,
|
2015-04-02 12:28:40 +02:00
|
|
|
bool showKnownIssuesUrl,
|
|
|
|
bool showReleaseNotesUrl )
|
|
|
|
{
|
|
|
|
using namespace Calamares;
|
2017-07-04 00:07:18 +02:00
|
|
|
if ( showSupportUrl && !( *Branding::SupportUrl ).isEmpty() )
|
2015-04-02 12:28:40 +02:00
|
|
|
{
|
|
|
|
CALAMARES_RETRANSLATE(
|
|
|
|
ui->supportButton->setText( tr( "%1 support" )
|
2017-07-04 00:07:18 +02:00
|
|
|
.arg( *Branding::ShortProductName ) );
|
2015-04-02 12:28:40 +02:00
|
|
|
)
|
2015-04-02 12:50:17 +02:00
|
|
|
ui->supportButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Help,
|
|
|
|
CalamaresUtils::Original,
|
|
|
|
2*QSize( CalamaresUtils::defaultFontHeight(),
|
|
|
|
CalamaresUtils::defaultFontHeight() ) ) );
|
2015-04-02 12:28:40 +02:00
|
|
|
connect( ui->supportButton, &QPushButton::clicked, []
|
|
|
|
{
|
2017-07-04 00:07:18 +02:00
|
|
|
QDesktopServices::openUrl( *Branding::SupportUrl );
|
2015-04-02 12:28:40 +02:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->supportButton->hide();
|
|
|
|
}
|
|
|
|
|
2017-07-04 00:07:18 +02:00
|
|
|
if ( showKnownIssuesUrl && !( *Branding::KnownIssuesUrl ).isEmpty() )
|
2015-04-02 12:28:40 +02:00
|
|
|
{
|
2015-04-02 12:50:17 +02:00
|
|
|
ui->knownIssuesButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Bugs,
|
|
|
|
CalamaresUtils::Original,
|
|
|
|
2*QSize( CalamaresUtils::defaultFontHeight(),
|
|
|
|
CalamaresUtils::defaultFontHeight() ) ) );
|
2015-04-02 12:28:40 +02:00
|
|
|
connect( ui->knownIssuesButton, &QPushButton::clicked, []
|
|
|
|
{
|
2017-07-04 00:07:18 +02:00
|
|
|
QDesktopServices::openUrl( *Branding::KnownIssuesUrl );
|
2015-04-02 12:28:40 +02:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->knownIssuesButton->hide();
|
|
|
|
}
|
|
|
|
|
2017-07-04 00:07:18 +02:00
|
|
|
if ( showReleaseNotesUrl && !( *Branding::ReleaseNotesUrl ).isEmpty() )
|
2015-04-02 12:28:40 +02:00
|
|
|
{
|
2015-04-02 12:50:17 +02:00
|
|
|
ui->releaseNotesButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Release,
|
|
|
|
CalamaresUtils::Original,
|
|
|
|
2*QSize( CalamaresUtils::defaultFontHeight(),
|
|
|
|
CalamaresUtils::defaultFontHeight() ) ) );
|
2015-04-02 12:28:40 +02:00
|
|
|
connect( ui->releaseNotesButton, &QPushButton::clicked, []
|
|
|
|
{
|
2017-07-04 00:07:18 +02:00
|
|
|
QDesktopServices::openUrl( *Branding::ReleaseNotesUrl );
|
2015-04-02 12:28:40 +02:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->releaseNotesButton->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-10 12:40:00 +01:00
|
|
|
void
|
2015-05-13 12:44:11 +02:00
|
|
|
WelcomePage::focusInEvent( QFocusEvent* e )
|
2014-11-10 12:40:00 +01:00
|
|
|
{
|
2014-11-20 09:40:55 +01:00
|
|
|
if ( ui->languageWidget )
|
|
|
|
ui->languageWidget->setFocus();
|
2014-11-10 12:40:00 +01:00
|
|
|
e->accept();
|
|
|
|
}
|
2014-11-10 14:36:18 +01:00
|
|
|
|
2017-12-02 15:56:03 +01:00
|
|
|
bool WelcomePage::verdict() const
|
|
|
|
{
|
|
|
|
return m_checkingWidget->verdict();
|
|
|
|
}
|
2019-05-10 17:46:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
LocaleTwoColumnDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
|
|
|
{
|
|
|
|
QStyledItemDelegate::paint( painter, option, index );
|
|
|
|
option.widget->style()->drawItemText( painter, option.rect, Qt::AlignRight | Qt::AlignVCenter, option.palette, false, index.data( CalamaresUtils::Locale::LabelModel::EnglishLabelRole ).toString() );
|
|
|
|
}
|