mirror of https://github.com/cutefishos/calamares
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
213 lines
5.1 KiB
C++
213 lines
5.1 KiB
C++
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
|
*
|
|
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
|
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
|
* Copyright 2018, 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 "ExecutionViewStep.h"
|
|
|
|
#include "Slideshow.h"
|
|
|
|
#include "Branding.h"
|
|
#include "CalamaresConfig.h"
|
|
#include "Job.h"
|
|
#include "JobQueue.h"
|
|
#include "Settings.h"
|
|
#include "ViewManager.h"
|
|
#include "modulesystem/Module.h"
|
|
#include "modulesystem/ModuleManager.h"
|
|
#include "utils/CalamaresUtilsGui.h"
|
|
#include "utils/Dirs.h"
|
|
#include "utils/Logger.h"
|
|
#include "utils/Qml.h"
|
|
#include "utils/Retranslator.h"
|
|
|
|
#include <QDir>
|
|
#include <QLabel>
|
|
#include <QProgressBar>
|
|
#include <QVBoxLayout>
|
|
|
|
static Calamares::Slideshow*
|
|
makeSlideshow( QWidget* parent )
|
|
{
|
|
const int api = Calamares::Branding::instance()->slideshowAPI();
|
|
switch ( api )
|
|
{
|
|
case -1:
|
|
return new Calamares::SlideshowPictures( parent );
|
|
#ifdef WITH_QML
|
|
case 1:
|
|
FALLTHRU;
|
|
case 2:
|
|
return new Calamares::SlideshowQML( parent );
|
|
#endif
|
|
default:
|
|
cWarning() << "Unknown Branding slideshow API" << api;
|
|
return new Calamares::SlideshowPictures( parent );
|
|
}
|
|
}
|
|
|
|
namespace Calamares
|
|
{
|
|
|
|
ExecutionViewStep::ExecutionViewStep( QObject* parent )
|
|
: ViewStep( parent )
|
|
, m_widget( new QWidget )
|
|
, m_progressBar( new QProgressBar )
|
|
, m_label( new QLabel )
|
|
, m_slideshow( makeSlideshow( m_widget ) )
|
|
{
|
|
QVBoxLayout* layout = new QVBoxLayout( m_widget );
|
|
QVBoxLayout* innerLayout = new QVBoxLayout;
|
|
|
|
m_progressBar->setMaximum( 10000 );
|
|
|
|
layout->addWidget( m_slideshow->widget() );
|
|
CalamaresUtils::unmarginLayout( layout );
|
|
layout->addLayout( innerLayout );
|
|
|
|
innerLayout->addSpacing( CalamaresUtils::defaultFontHeight() / 2 );
|
|
innerLayout->addWidget( m_progressBar );
|
|
innerLayout->addWidget( m_label );
|
|
|
|
connect( JobQueue::instance(), &JobQueue::progress, this, &ExecutionViewStep::updateFromJobQueue );
|
|
}
|
|
|
|
|
|
QString
|
|
ExecutionViewStep::prettyName() const
|
|
{
|
|
return Calamares::Settings::instance()->isSetupMode() ? tr( "Set up" ) : tr( "Install" );
|
|
}
|
|
|
|
|
|
QWidget*
|
|
ExecutionViewStep::widget()
|
|
{
|
|
return m_widget;
|
|
}
|
|
|
|
|
|
void
|
|
ExecutionViewStep::next()
|
|
{
|
|
}
|
|
|
|
|
|
void
|
|
ExecutionViewStep::back()
|
|
{
|
|
}
|
|
|
|
|
|
bool
|
|
ExecutionViewStep::isNextEnabled() const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
|
|
bool
|
|
ExecutionViewStep::isBackEnabled() const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
|
|
bool
|
|
ExecutionViewStep::isAtBeginning() const
|
|
{
|
|
return true;
|
|
}
|
|
|
|
|
|
bool
|
|
ExecutionViewStep::isAtEnd() const
|
|
{
|
|
return !JobQueue::instance()->isRunning();
|
|
}
|
|
|
|
void
|
|
ExecutionViewStep::onActivate()
|
|
{
|
|
m_slideshow->changeSlideShowState( Slideshow::Start );
|
|
|
|
const auto instanceDescriptors = Calamares::Settings::instance()->moduleInstances();
|
|
|
|
JobQueue* queue = JobQueue::instance();
|
|
for ( const auto& instanceKey : m_jobInstanceKeys )
|
|
{
|
|
const auto& moduleDescriptor = Calamares::ModuleManager::instance()->moduleDescriptor( instanceKey );
|
|
Calamares::Module* module = Calamares::ModuleManager::instance()->moduleInstance( instanceKey );
|
|
|
|
const auto instanceDescriptor
|
|
= std::find_if( instanceDescriptors.constBegin(),
|
|
instanceDescriptors.constEnd(),
|
|
[=]( const Calamares::InstanceDescription& d ) { return d.key() == instanceKey; } );
|
|
int weight = moduleDescriptor.weight();
|
|
if ( instanceDescriptor != instanceDescriptors.constEnd() && instanceDescriptor->explicitWeight() )
|
|
{
|
|
weight = instanceDescriptor->weight();
|
|
}
|
|
weight = qBound( 1, weight, 100 );
|
|
if ( module )
|
|
{
|
|
auto jl = module->jobs();
|
|
if ( module->isEmergency() )
|
|
{
|
|
for ( auto& j : jl )
|
|
{
|
|
j->setEmergency( true );
|
|
}
|
|
}
|
|
queue->enqueue( weight, jl );
|
|
}
|
|
}
|
|
|
|
queue->start();
|
|
}
|
|
|
|
|
|
JobList
|
|
ExecutionViewStep::jobs() const
|
|
{
|
|
return JobList();
|
|
}
|
|
|
|
|
|
void
|
|
ExecutionViewStep::appendJobModuleInstanceKey( const ModuleSystem::InstanceKey& instanceKey )
|
|
{
|
|
m_jobInstanceKeys.append( instanceKey );
|
|
}
|
|
|
|
|
|
void
|
|
ExecutionViewStep::updateFromJobQueue( qreal percent, const QString& message )
|
|
{
|
|
m_progressBar->setValue( int( percent * m_progressBar->maximum() ) );
|
|
m_label->setText( message );
|
|
}
|
|
|
|
void
|
|
ExecutionViewStep::onLeave()
|
|
{
|
|
m_slideshow->changeSlideShowState( Slideshow::Stop );
|
|
}
|
|
|
|
} // namespace Calamares
|