2014-06-11 13:37:10 +02:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2014, Teo Mrnjavac <teo@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 "ViewManager.h"
|
|
|
|
|
2014-07-01 11:49:09 +02:00
|
|
|
#include "viewpages/ViewStep.h"
|
2014-07-08 15:23:30 +02:00
|
|
|
#include "InstallationViewStep.h"
|
2014-07-08 17:04:39 +02:00
|
|
|
#include "JobQueue.h"
|
2014-07-01 11:49:09 +02:00
|
|
|
|
2014-06-24 15:31:11 +02:00
|
|
|
#include <QApplication>
|
2014-06-27 13:58:53 +02:00
|
|
|
#include <QLabel>
|
2014-06-11 13:37:10 +02:00
|
|
|
#include <QBoxLayout>
|
|
|
|
|
|
|
|
namespace Calamares
|
|
|
|
{
|
|
|
|
|
2014-06-27 15:21:16 +02:00
|
|
|
ViewManager* ViewManager::s_instance = nullptr;
|
2014-06-11 13:37:10 +02:00
|
|
|
|
|
|
|
ViewManager*
|
|
|
|
ViewManager::instance()
|
|
|
|
{
|
|
|
|
return s_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewManager::ViewManager( QObject* parent )
|
|
|
|
: QObject( parent )
|
|
|
|
, m_widget( new QWidget() )
|
2014-06-27 18:00:27 +02:00
|
|
|
, m_currentStep( 0 )
|
2014-06-11 13:37:10 +02:00
|
|
|
{
|
|
|
|
s_instance = this;
|
|
|
|
QBoxLayout* mainLayout = new QVBoxLayout;
|
|
|
|
m_widget->setLayout( mainLayout );
|
|
|
|
|
|
|
|
m_stack = new QStackedWidget( m_widget );
|
2014-06-12 10:56:13 +02:00
|
|
|
m_stack->setContentsMargins( 0, 0, 0, 0 );
|
2014-06-11 13:37:10 +02:00
|
|
|
mainLayout->addWidget( m_stack );
|
|
|
|
|
|
|
|
m_back = new QPushButton( tr( "&Back" ), m_widget );
|
|
|
|
m_next = new QPushButton( tr( "&Next" ), m_widget );
|
2014-06-24 15:31:11 +02:00
|
|
|
m_quit = new QPushButton( tr( "&Quit" ), m_widget );
|
2014-06-11 13:37:10 +02:00
|
|
|
|
|
|
|
QBoxLayout* bottomLayout = new QHBoxLayout;
|
|
|
|
mainLayout->addLayout( bottomLayout );
|
|
|
|
bottomLayout->addStretch();
|
|
|
|
bottomLayout->addWidget( m_back );
|
|
|
|
bottomLayout->addWidget( m_next );
|
2014-06-24 15:31:11 +02:00
|
|
|
bottomLayout->addSpacing( 12 );
|
|
|
|
bottomLayout->addWidget( m_quit );
|
2014-06-27 18:00:27 +02:00
|
|
|
|
2014-06-24 15:31:11 +02:00
|
|
|
connect( m_quit, &QPushButton::clicked, qApp, &QApplication::quit );
|
2014-06-27 18:00:27 +02:00
|
|
|
connect( m_next, &QPushButton::clicked, this, &ViewManager::next );
|
|
|
|
connect( m_back, &QPushButton::clicked, this, &ViewManager::back );
|
|
|
|
m_back->setEnabled( false );
|
2014-07-08 15:23:30 +02:00
|
|
|
|
|
|
|
m_installationViewStep = new InstallationViewStep( this );
|
|
|
|
insertViewStep( 0, m_installationViewStep );
|
2014-06-11 13:37:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ViewManager::~ViewManager()
|
|
|
|
{
|
|
|
|
m_widget->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget*
|
2014-06-27 18:00:27 +02:00
|
|
|
ViewManager::centralWidget()
|
2014-06-11 13:37:10 +02:00
|
|
|
{
|
|
|
|
return m_widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-12 10:56:13 +02:00
|
|
|
void
|
2014-06-27 18:00:27 +02:00
|
|
|
ViewManager::addViewStep( ViewStep* step )
|
2014-06-12 10:56:13 +02:00
|
|
|
{
|
2014-07-08 15:23:30 +02:00
|
|
|
m_prepareSteps.append( step );
|
|
|
|
|
|
|
|
insertViewStep( m_steps.size() - 1, step );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ViewManager::insertViewStep( int before, ViewStep* step)
|
|
|
|
{
|
|
|
|
m_steps.insert( before, step );
|
2014-07-02 16:38:57 +02:00
|
|
|
QLayout* layout = step->widget()->layout();
|
|
|
|
if ( layout )
|
|
|
|
{
|
|
|
|
layout->setContentsMargins( 0, 0, 0, 0 );
|
|
|
|
}
|
2014-07-08 15:23:30 +02:00
|
|
|
m_stack->insertWidget( before, step->widget() );
|
2014-06-12 10:56:13 +02:00
|
|
|
|
2014-06-27 18:00:27 +02:00
|
|
|
connect( step, &ViewStep::nextStatusChanged,
|
|
|
|
m_next, &QPushButton::setEnabled );
|
2014-07-01 17:45:28 +02:00
|
|
|
|
2014-07-08 15:23:30 +02:00
|
|
|
m_stack->setCurrentIndex( 0 );
|
2014-07-01 17:45:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QList< ViewStep* >
|
2014-07-08 15:23:30 +02:00
|
|
|
ViewManager::prepareSteps() const
|
2014-07-01 17:45:28 +02:00
|
|
|
{
|
2014-07-08 15:23:30 +02:00
|
|
|
return m_prepareSteps;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ViewStep*
|
|
|
|
ViewManager::installationStep() const
|
|
|
|
{
|
|
|
|
return m_installationViewStep;
|
2014-07-01 17:45:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ViewStep*
|
|
|
|
ViewManager::currentStep() const
|
|
|
|
{
|
|
|
|
return m_steps.value( m_currentStep );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
ViewManager::currentStepIndex() const
|
|
|
|
{
|
|
|
|
return m_currentStep;
|
2014-06-12 10:56:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-11 13:37:10 +02:00
|
|
|
void
|
|
|
|
ViewManager::next()
|
|
|
|
{
|
2014-06-27 18:00:27 +02:00
|
|
|
ViewStep* step = m_steps.at( m_currentStep );
|
2014-07-08 15:23:30 +02:00
|
|
|
bool installing = false;
|
|
|
|
if ( step->isAtEnd() )
|
2014-06-27 18:00:27 +02:00
|
|
|
{
|
|
|
|
m_currentStep++;
|
|
|
|
m_stack->setCurrentIndex( m_currentStep );
|
2014-07-08 18:24:39 +02:00
|
|
|
step->onLeave();
|
|
|
|
m_steps.at( m_currentStep )->onActivate();
|
2014-07-08 15:23:30 +02:00
|
|
|
installing = m_steps.at( m_currentStep ) == m_installationViewStep;
|
2014-07-01 17:45:28 +02:00
|
|
|
emit currentStepChanged();
|
2014-07-08 17:04:39 +02:00
|
|
|
if ( installing )
|
|
|
|
{
|
|
|
|
startInstallation();
|
|
|
|
}
|
2014-06-27 18:00:27 +02:00
|
|
|
}
|
2014-07-08 15:23:30 +02:00
|
|
|
else
|
2014-06-27 18:00:27 +02:00
|
|
|
{
|
|
|
|
step->next();
|
|
|
|
}
|
|
|
|
|
2014-07-08 15:23:30 +02:00
|
|
|
m_next->setEnabled( !installing && m_steps.at( m_currentStep )->isNextEnabled() );
|
|
|
|
m_back->setEnabled( !installing );
|
2014-06-11 13:37:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ViewManager::back()
|
|
|
|
{
|
2014-06-27 18:00:27 +02:00
|
|
|
ViewStep* step = m_steps.at( m_currentStep );
|
|
|
|
if ( step->isAtBeginning() && m_currentStep > 0 )
|
|
|
|
{
|
|
|
|
m_currentStep--;
|
|
|
|
m_stack->setCurrentIndex( m_currentStep );
|
2014-07-08 18:24:39 +02:00
|
|
|
step->onLeave();
|
|
|
|
m_steps.at( m_currentStep )->onActivate();
|
2014-07-01 17:45:28 +02:00
|
|
|
emit currentStepChanged();
|
2014-06-27 18:00:27 +02:00
|
|
|
}
|
|
|
|
else if ( !step->isAtBeginning() )
|
|
|
|
{
|
|
|
|
step->back();
|
|
|
|
}
|
|
|
|
else return;
|
|
|
|
|
2014-06-27 18:18:36 +02:00
|
|
|
m_next->setEnabled( m_steps.at( m_currentStep )->isNextEnabled() );
|
2014-06-27 18:00:27 +02:00
|
|
|
if ( m_currentStep == 0 && m_steps.first()->isAtBeginning() )
|
|
|
|
m_back->setEnabled( false );
|
2014-06-11 13:37:10 +02:00
|
|
|
}
|
|
|
|
|
2014-07-08 17:04:39 +02:00
|
|
|
void
|
|
|
|
ViewManager::startInstallation()
|
|
|
|
{
|
|
|
|
for( ViewStep* step : m_prepareSteps )
|
|
|
|
{
|
|
|
|
JobQueue::instance()->enqueue( step->jobs() );
|
|
|
|
}
|
|
|
|
JobQueue::instance()->start();
|
|
|
|
}
|
|
|
|
|
2014-06-11 13:37:10 +02:00
|
|
|
}
|