2014-06-11 13:37:10 +02:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
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>
|
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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "GreetingPage.h"
|
|
|
|
|
2014-11-20 09:40:55 +01:00
|
|
|
#include "ui_GreetingPage.h"
|
2014-11-10 12:40:00 +01:00
|
|
|
#include "CalamaresVersion.h"
|
|
|
|
#include "utils/Logger.h"
|
2014-11-20 09:40:55 +01:00
|
|
|
#include "utils/CalamaresUtilsGui.h"
|
2014-11-11 15:17:46 +01:00
|
|
|
#include "utils/Retranslator.h"
|
2014-11-10 12:40:00 +01:00
|
|
|
#include "ViewManager.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
2014-06-27 18:00:27 +02:00
|
|
|
#include <QBoxLayout>
|
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-10 12:40:00 +01:00
|
|
|
#include <QListWidget>
|
2014-11-20 09:40:55 +01:00
|
|
|
#include <QMessageBox>
|
2014-06-27 18:00:27 +02:00
|
|
|
|
2014-10-16 16:58:58 +02:00
|
|
|
#include "Branding.h"
|
|
|
|
|
2014-06-11 13:37:10 +02:00
|
|
|
|
|
|
|
GreetingPage::GreetingPage( QWidget* parent )
|
2014-11-20 09:40:55 +01:00
|
|
|
: QWidget( parent )
|
|
|
|
, ui( new Ui::GreetingPage )
|
2014-06-11 13:37:10 +02:00
|
|
|
{
|
2014-11-20 09:40:55 +01:00
|
|
|
ui->setupUi( this );
|
2014-06-27 18:00:27 +02:00
|
|
|
|
2015-02-09 19:15:54 +01:00
|
|
|
QLocale defaultLocale = QLocale( QLocale::system().name() );
|
2014-11-10 12:40:00 +01:00
|
|
|
{
|
2015-01-18 14:56:46 +01:00
|
|
|
bool isTranslationAvailable = false;
|
|
|
|
|
2014-11-10 12:40:00 +01:00
|
|
|
foreach ( const QString& locale, QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') )
|
|
|
|
{
|
|
|
|
QLocale thisLocale = QLocale( locale );
|
|
|
|
QString lang = QLocale::languageToString( thisLocale.language() );
|
|
|
|
if ( QLocale::countriesForLanguage( thisLocale.language() ).count() > 2 )
|
|
|
|
lang.append( QString( " (%1)" )
|
|
|
|
.arg( QLocale::countryToString( thisLocale.country() ) ) );
|
|
|
|
|
2014-11-20 09:40:55 +01:00
|
|
|
ui->languageWidget->addItem( lang );
|
|
|
|
ui->languageWidget->item( ui->languageWidget->count() - 1 )
|
2014-11-10 12:40:00 +01:00
|
|
|
->setData( Qt::UserRole, thisLocale );
|
2015-02-09 19:15:54 +01:00
|
|
|
if ( thisLocale.language() == defaultLocale.language() &&
|
|
|
|
thisLocale.country() == defaultLocale.country() )
|
2015-01-18 14:56:46 +01:00
|
|
|
{
|
|
|
|
isTranslationAvailable = true;
|
2014-11-20 09:40:55 +01:00
|
|
|
ui->languageWidget->setCurrentRow( ui->languageWidget->count() - 1 );
|
2015-02-09 18:59:57 +01:00
|
|
|
cDebug() << "Initial locale " << thisLocale.name();
|
|
|
|
CalamaresUtils::installTranslator( thisLocale.name(), qApp );
|
2015-01-18 14:56:46 +01:00
|
|
|
}
|
2014-11-10 12:40:00 +01:00
|
|
|
}
|
2014-11-20 09:40:55 +01:00
|
|
|
ui->languageWidget->sortItems();
|
2014-11-10 12:40:00 +01:00
|
|
|
|
2015-01-18 14:56:46 +01:00
|
|
|
if ( !isTranslationAvailable )
|
|
|
|
{
|
|
|
|
for (int i = 0; i < ui->languageWidget->count(); i++)
|
|
|
|
{
|
|
|
|
QLocale thisLocale = ui->languageWidget->item(i)->data( Qt::UserRole ).toLocale();
|
2015-02-09 19:15:54 +01:00
|
|
|
if ( thisLocale.language() == defaultLocale.language() )
|
2015-01-18 14:56:46 +01:00
|
|
|
{
|
|
|
|
isTranslationAvailable = true;
|
|
|
|
ui->languageWidget->setCurrentRow( i );
|
2015-02-09 18:59:57 +01:00
|
|
|
cDebug() << "Initial locale " << thisLocale.name();
|
|
|
|
CalamaresUtils::installTranslator( thisLocale.name(), qApp );
|
2015-01-18 14:56:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !isTranslationAvailable )
|
|
|
|
{
|
|
|
|
for (int i = 0; i < ui->languageWidget->count(); i++)
|
|
|
|
{
|
|
|
|
QLocale thisLocale = ui->languageWidget->item(i)->data( Qt::UserRole ).toLocale();
|
|
|
|
if ( thisLocale == QLocale( QLocale::English, QLocale::UnitedStates ) )
|
|
|
|
{
|
|
|
|
ui->languageWidget->setCurrentRow( i );
|
2015-02-09 18:59:57 +01:00
|
|
|
cDebug() << "Translation unavailable, so initial locale set to " << thisLocale.name();
|
|
|
|
QLocale::setDefault( thisLocale );
|
|
|
|
CalamaresUtils::installTranslator( thisLocale.name(), qApp );
|
2015-01-18 14:56:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-20 09:40:55 +01:00
|
|
|
connect( ui->languageWidget, &QListWidget::currentItemChanged,
|
2014-11-10 12:40:00 +01:00
|
|
|
this, [ & ]( QListWidgetItem *current, QListWidgetItem *previous )
|
|
|
|
{
|
|
|
|
QLocale selectedLocale = current->data( Qt::UserRole ).toLocale();
|
|
|
|
cDebug() << "Selected locale" << selectedLocale.name();
|
|
|
|
|
|
|
|
QLocale::setDefault( selectedLocale );
|
|
|
|
CalamaresUtils::installTranslator( selectedLocale.name(), qApp );
|
|
|
|
} );
|
|
|
|
|
2014-11-20 09:40:55 +01:00
|
|
|
connect( ui->languageWidget, &QListWidget::itemDoubleClicked,
|
2014-11-10 12:40:00 +01:00
|
|
|
this, []
|
|
|
|
{
|
|
|
|
Calamares::ViewManager::instance()->next();
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2014-11-20 09:40:55 +01:00
|
|
|
ui->mainText->setAlignment( Qt::AlignCenter );
|
|
|
|
ui->mainText->setWordWrap( true );
|
|
|
|
ui->mainText->setOpenExternalLinks( true );
|
2014-11-10 14:36:18 +01:00
|
|
|
|
2015-04-02 12:28:40 +02:00
|
|
|
CALAMARES_RETRANSLATE(
|
|
|
|
ui->mainText->setText( tr( "<h1>Welcome to the %1 installer.</h1><br/>"
|
|
|
|
"This program will ask you some questions and "
|
|
|
|
"set up %2 on your computer." )
|
|
|
|
.arg( Calamares::Branding::instance()->
|
|
|
|
string( Calamares::Branding::VersionedName ) )
|
|
|
|
.arg( Calamares::Branding::instance()->
|
|
|
|
string( Calamares::Branding::ProductName ) ) );
|
|
|
|
)
|
2014-11-20 09:40:55 +01:00
|
|
|
|
|
|
|
ui->aboutButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Information,
|
|
|
|
CalamaresUtils::Original,
|
|
|
|
2*QSize( CalamaresUtils::defaultFontHeight(),
|
|
|
|
CalamaresUtils::defaultFontHeight() ) ) );
|
|
|
|
connect( ui->aboutButton, &QPushButton::clicked,
|
|
|
|
this, [ this ]
|
|
|
|
{
|
|
|
|
QMessageBox::about( this,
|
|
|
|
tr( "About %1 installer" )
|
|
|
|
.arg( CALAMARES_APPLICATION_NAME ),
|
|
|
|
tr(
|
|
|
|
"<h1>%1</h1><br/>"
|
|
|
|
"<b>%2<br/>"
|
|
|
|
"for %3</b><br/><br/>"
|
|
|
|
"Copyright 2014 Teo Mrnjavac <teo@kde.org><br/>"
|
|
|
|
"Thanks to: Anke Boersma, Aurélien Gâteau, Kevin Kofler, Philip Müller, "
|
|
|
|
"Pier Luigi Fiorini and Rohan Garg.<br/><br/>"
|
|
|
|
"<a href=\"https://calamares.github.io/\">Calamares</a> "
|
|
|
|
"development is sponsored by <br/>"
|
|
|
|
"<a href=\"http://www.blue-systems.com/\">Blue Systems</a> - "
|
|
|
|
"technologies for a better world."
|
|
|
|
)
|
|
|
|
.arg( CALAMARES_APPLICATION_NAME )
|
|
|
|
.arg( CALAMARES_VERSION )
|
|
|
|
.arg( Calamares::Branding::instance()->string(
|
|
|
|
Calamares::Branding::VersionedName ) ) );
|
|
|
|
} );
|
2014-11-10 12:40:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-02 12:28:40 +02:00
|
|
|
void
|
|
|
|
GreetingPage::setUpLinks( bool showSupportUrl,
|
|
|
|
bool showKnownIssuesUrl,
|
|
|
|
bool showReleaseNotesUrl )
|
|
|
|
{
|
|
|
|
using namespace Calamares;
|
|
|
|
Branding* b = Branding::instance();
|
|
|
|
if ( showSupportUrl && !b->string( Branding::SupportUrl ).isEmpty() )
|
|
|
|
{
|
|
|
|
CALAMARES_RETRANSLATE(
|
|
|
|
ui->supportButton->setText( tr( "%1 support" )
|
|
|
|
.arg( b->string( Branding::ShortProductName ) ) );
|
|
|
|
)
|
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, []
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl( Branding::instance()->string( Branding::SupportUrl ) );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->supportButton->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( showKnownIssuesUrl && !b->string( Branding::KnownIssuesUrl ).isEmpty() )
|
|
|
|
{
|
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, []
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl( Branding::instance()->string( Branding::KnownIssuesUrl ) );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->knownIssuesButton->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( showReleaseNotesUrl && !b->string( Branding::ReleaseNotesUrl ).isEmpty() )
|
|
|
|
{
|
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, []
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl( Branding::instance()->string( Branding::ReleaseNotesUrl ) );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->releaseNotesButton->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-10 12:40:00 +01:00
|
|
|
void
|
|
|
|
GreetingPage::focusInEvent( QFocusEvent* e )
|
|
|
|
{
|
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
|
|
|
|