calamares/src/modules/summary/Config.cpp

129 lines
3.2 KiB
C++
Raw Normal View History

/* === This file is part of Calamares - <https://calamares.io> ===
*
* SPDX-FileCopyrightText: 2020, Camilo Higuita <milo.h@aol.com>
* SPDX-FileCopyrightText: 2021 Anke Boersma <demm@kaosx.us>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Calamares is Free Software: see the License-Identifier above.
*
*/
#include "Config.h"
#include "Branding.h"
#include "Settings.h"
#include "ViewManager.h"
#include "utils/CalamaresUtilsGui.h"
#include "utils/Logger.h"
#include "utils/Retranslator.h"
#include "viewpages/ExecutionViewStep.h"
2021-07-13 10:36:05 +02:00
SummaryModel::SummaryModel( QObject* parent )
: QAbstractListModel( parent )
{
}
2021-07-13 10:36:05 +02:00
QHash< int, QByteArray >
SummaryModel::roleNames() const
{
return { { Qt::DisplayRole, "title" }, { Qt::UserRole, "message" } };
}
2021-07-13 10:36:05 +02:00
QVariant
SummaryModel::data( const QModelIndex& index, int role ) const
{
if ( !index.isValid() )
{
return QVariant();
}
const auto item = m_summary.at( index.row() );
return role == Qt::DisplayRole ? item.title : item.message;
}
2021-07-13 10:36:05 +02:00
int
SummaryModel::rowCount( const QModelIndex& ) const
{
return m_summary.count();
}
2021-07-13 10:36:05 +02:00
void
SummaryModel::setSummaryList( const Calamares::ViewStepList& steps, bool withWidgets )
{
Q_EMIT beginResetModel();
m_summary.clear();
for ( Calamares::ViewStep* step : steps )
{
QString text = step->prettyStatus();
QWidget* widget = withWidgets ? step->createSummaryWidget() : nullptr;
if ( text.isEmpty() && !widget )
2021-07-13 10:36:05 +02:00
{
continue;
2021-07-13 10:36:05 +02:00
}
m_summary << StepSummary { step->prettyName(), text, widget };
}
Q_EMIT endResetModel();
}
Config::Config( Calamares::ViewStep* parent )
2021-07-13 10:36:05 +02:00
: QObject( parent )
, m_thisViewStep( parent )
2021-07-13 10:36:05 +02:00
, m_summary( new SummaryModel( this ) )
{
CALAMARES_RETRANSLATE_SLOT( &Config::retranslate );
retranslate();
}
void
Config::retranslate()
{
m_title = m_thisViewStep->prettyName();
if ( Calamares::Settings::instance()->isSetupMode() )
{
2021-07-13 10:36:05 +02:00
m_message = ( tr( "This is an overview of what will happen once you start "
"the setup procedure." ) );
}
else
{
m_message = ( tr( "This is an overview of what will happen once you start "
2021-07-13 10:36:05 +02:00
"the install procedure." ) );
}
Q_EMIT titleChanged( m_title );
Q_EMIT messageChanged( m_message );
}
2021-07-13 10:36:05 +02:00
void
Config::init()
{
Calamares::ViewStepList steps;
for ( Calamares::ViewStep* step : Calamares::ViewManager::instance()->viewSteps() )
{
// *Assume* that if there's an exec step in the sequence,
// we don't need a summary for steps before it. This works in
// practice if there's a summary step before each exec --
// and in practice, there's only one of each.
if ( qobject_cast< Calamares::ExecutionViewStep* >( step ) )
{
steps.clear();
continue;
}
// Having reached the parent view-step of the Config object,
// we know we're providing a summary of steps up until this
// view step, so we now have steps since the previous exec, up
// to this summary.
if ( m_thisViewStep == step )
2021-07-13 10:36:05 +02:00
{
break;
2021-07-13 10:36:05 +02:00
}
steps.append( step );
}
m_summary->setSummaryList( steps );
}