Merge prepare module into welcome, and repurpose it as a req checker.

This commit is contained in:
Teo Mrnjavac 2015-05-14 18:00:26 +02:00
parent 3dd1d7932f
commit ceedc1166b
13 changed files with 87 additions and 175 deletions

View File

@ -1,22 +0,0 @@
include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules )
find_package( LIBPARTED REQUIRED )
find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED DBus )
set_source_files_properties( partman_devices.c PROPERTIES LANGUAGE CXX )
calamares_add_plugin( prepare
TYPE viewmodule
EXPORT_MACRO PLUGINDLLEXPORT_PRO
SOURCES
PrepareCheckWidget.cpp
PreparePage.cpp
PrepareViewStep.cpp
partman_devices.c
UI
LINK_LIBRARIES
calamaresui
${LIBPARTED_LIBS}
Qt5::DBus
SHARED_LIB
)

View File

@ -1,5 +0,0 @@
---
type: "view" #core or view
name: "prepare" #the module name. must be unique and same as the parent directory
interface: "qtplugin" #can be: qtplugin, python, process, ...
load: "libcalamares_viewmodule_prepare.so"

View File

@ -1,11 +0,0 @@
---
requiredStorage: 5.5
requiredRam: 1.0
check:
- storage
- ram
- power
- internet
required:
- storage
- ram

View File

@ -1,13 +1,32 @@
include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )
set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules )
find_package( LIBPARTED REQUIRED )
find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED DBus )
set_source_files_properties( checker/partman_devices.c PROPERTIES LANGUAGE CXX )
set( CHECKER_SOURCES
checker/CheckItemWidget.cpp
checker/CheckerWidget.cpp
checker/RequirementsChecker.cpp
checker/partman_devices.c
)
set( CHECKER_LINK_LIBRARIES
${LIBPARTED_LIBS}
Qt5::DBus
)
calamares_add_plugin( welcome
TYPE viewmodule
EXPORT_MACRO PLUGINDLLEXPORT_PRO
SOURCES
${CHECKER_SOURCES}
WelcomeViewStep.cpp
WelcomePage.cpp
UI
WelcomePage.ui
LINK_LIBRARIES
calamaresui
${CHECKER_LINK_LIBRARIES}
SHARED_LIB
)

View File

@ -1,6 +1,6 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
* Copyright 2014-2015, 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
@ -16,14 +16,14 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "PrepareCheckWidget.h"
#include "CheckItemWidget.h"
#include "utils/CalamaresUtilsGui.h"
#include "utils/Logger.h"
#include <QBoxLayout>
PrepareCheckWidget::PrepareCheckWidget( bool checked,
CheckItemWidget::CheckItemWidget( bool checked,
QWidget* parent )
: QWidget( parent )
{
@ -51,7 +51,7 @@ PrepareCheckWidget::PrepareCheckWidget( bool checked,
void
PrepareCheckWidget::setText( const QString& text )
CheckItemWidget::setText( const QString& text )
{
m_textLabel->setText( text );
}

View File

@ -1,6 +1,6 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
* Copyright 2014-2015, 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
@ -16,16 +16,16 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PREPARECHECKWIDGET_H
#define PREPARECHECKWIDGET_H
#ifndef CHECKITEMWIDGET_H
#define CHECKITEMWIDGET_H
#include <QLabel>
class PrepareCheckWidget : public QWidget
class CheckItemWidget : public QWidget
{
Q_OBJECT
public:
explicit PrepareCheckWidget( bool checked,
explicit CheckItemWidget( bool checked,
QWidget* parent = nullptr );
void setText( const QString& text );
@ -34,4 +34,4 @@ private:
QLabel* m_iconLabel;
};
#endif // PREPARECHECKWIDGET_H
#endif // CHECKITEMWIDGET_H

View File

@ -1,6 +1,6 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
* Copyright 2014-2015, 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
@ -16,9 +16,9 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "PreparePage.h"
#include "CheckerWidget.h"
#include "PrepareCheckWidget.h"
#include "CheckItemWidget.h"
#include "utils/CalamaresUtilsGui.h"
#include "utils/Retranslator.h"
@ -28,7 +28,7 @@
#include <QLabel>
PreparePage::PreparePage( QWidget* parent )
CheckerWidget::CheckerWidget( QWidget* parent )
: QWidget()
{
QBoxLayout* mainLayout = new QVBoxLayout;
@ -52,17 +52,17 @@ PreparePage::PreparePage( QWidget* parent )
void
PreparePage::init( const QList< PrepareEntry >& checkEntries )
CheckerWidget::init( const QList< PrepareEntry >& checkEntries )
{
bool allChecked = true;
bool requirementsSatisfied = true;
for ( const PrepareEntry& entry : checkEntries )
{
PrepareCheckWidget* pcw = new PrepareCheckWidget( entry.checked );
CALAMARES_RETRANSLATE( pcw->setText( entry.text() ); )
m_entriesLayout->addWidget( pcw );
pcw->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
CheckItemWidget* ciw = new CheckItemWidget( entry.checked );
CALAMARES_RETRANSLATE( ciw->setText( entry.text() ); )
m_entriesLayout->addWidget( ciw );
ciw->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
if ( !entry.checked )
{

View File

@ -1,6 +1,6 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
* Copyright 2014-2015, 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
@ -16,19 +16,19 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PREPAREPAGE_H
#define PREPAREPAGE_H
#ifndef CHECKERWIDGET_H
#define CHECKERWIDGET_H
#include "PrepareViewStep.h"
#include "RequirementsChecker.h"
#include <QBoxLayout>
#include <QWidget>
class PreparePage : public QWidget
class CheckerWidget : public QWidget
{
Q_OBJECT
public:
explicit PreparePage( QWidget* parent = nullptr );
explicit CheckerWidget( QWidget* parent = nullptr );
void init( const QList< PrepareEntry >& checkEntries );
@ -36,4 +36,4 @@ private:
QBoxLayout* m_entriesLayout;
};
#endif // PREPAREPAGE_H
#endif // CHECKERWIDGET_H

View File

@ -16,9 +16,9 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "PrepareViewStep.h"
#include "RequirementsChecker.h"
#include "PreparePage.h"
#include "CheckerWidget.h"
#include "partman_devices.h"
#include "widgets/WaitingWidget.h"
@ -38,11 +38,11 @@
#include <QProcess>
#include <QTimer>
PrepareViewStep::PrepareViewStep( QObject* parent )
: Calamares::ViewStep( parent )
RequirementsChecker::RequirementsChecker( QObject* parent )
: QObject( parent )
, m_widget( new QWidget() )
, m_actualWidget( new PreparePage() )
, m_nextEnabled( false )
, m_actualWidget( new CheckerWidget() )
, m_verdict( false )
, m_requiredStorageGB( -1 )
{
QBoxLayout* mainLayout = new QHBoxLayout;
@ -131,8 +131,8 @@ PrepareViewStep::PrepareViewStep( QObject* parent )
break;
}
}
m_nextEnabled = canGoNext;
emit nextStatusChanged( m_nextEnabled );
m_verdict = canGoNext;
emit verdictChanged( m_verdict );
if ( canGoNext )
detectFirmwareType();
@ -141,86 +141,26 @@ PrepareViewStep::PrepareViewStep( QObject* parent )
} );
timer->start( 0 );
emit nextStatusChanged( true );
emit verdictChanged( true );
}
PrepareViewStep::~PrepareViewStep()
RequirementsChecker::~RequirementsChecker()
{
if ( m_widget && m_widget->parent() == nullptr )
m_widget->deleteLater();
}
QString
PrepareViewStep::prettyName() const
{
return tr( "Prepare" );
}
QWidget*
PrepareViewStep::widget()
RequirementsChecker::widget() const
{
return m_widget;
}
void
PrepareViewStep::next()
{
emit done();
}
void
PrepareViewStep::back()
{}
bool
PrepareViewStep::isNextEnabled() const
{
return m_nextEnabled;
}
bool
PrepareViewStep::isBackEnabled() const
{
return true;
}
bool
PrepareViewStep::isAtBeginning() const
{
return true;
}
bool
PrepareViewStep::isAtEnd() const
{
return true;
}
QList< Calamares::job_ptr >
PrepareViewStep::jobs() const
{
return QList< Calamares::job_ptr >();
}
void
PrepareViewStep::onLeave()
{
}
void
PrepareViewStep::setConfigurationMap( const QVariantMap& configurationMap )
RequirementsChecker::setConfigurationMap( const QVariantMap& configurationMap )
{
if ( configurationMap.contains( "requiredStorage" ) &&
configurationMap.value( "requiredStorage" ).type() == QVariant::Double )
@ -267,14 +207,21 @@ PrepareViewStep::setConfigurationMap( const QVariantMap& configurationMap )
bool
PrepareViewStep::checkEnoughStorage( qint64 requiredSpace )
RequirementsChecker::verdict() const
{
return m_verdict;
}
bool
RequirementsChecker::checkEnoughStorage( qint64 requiredSpace )
{
return check_big_enough( requiredSpace );
}
bool
PrepareViewStep::checkEnoughRam( qint64 requiredRam )
RequirementsChecker::checkEnoughRam( qint64 requiredRam )
{
// A line in meminfo looks like this, with {print $2} we grab the second column.
// MemTotal: 8133432 kB
@ -290,7 +237,7 @@ PrepareViewStep::checkEnoughRam( qint64 requiredRam )
bool
PrepareViewStep::checkBatteryExists()
RequirementsChecker::checkBatteryExists()
{
const QFileInfo basePath( "/sys/class/power_supply" );
@ -317,7 +264,7 @@ PrepareViewStep::checkBatteryExists()
bool
PrepareViewStep::checkHasPower()
RequirementsChecker::checkHasPower()
{
const QString UPOWER_SVC_NAME( "org.freedesktop.UPower" );
const QString UPOWER_INTF_NAME( "org.freedesktop.UPower" );
@ -348,7 +295,7 @@ PrepareViewStep::checkHasPower()
bool
PrepareViewStep::checkHasInternet()
RequirementsChecker::checkHasInternet()
{
const QString NM_SVC_NAME( "org.freedesktop.NetworkManager" );
const QString NM_INTF_NAME( "org.freedesktop.NetworkManager" );
@ -376,7 +323,7 @@ PrepareViewStep::checkHasInternet()
void
PrepareViewStep::detectFirmwareType()
RequirementsChecker::detectFirmwareType()
{
QString fwType = QFile::exists( "/sys/firmware/efi/efivars" ) ? "efi" : "bios";
Calamares::JobQueue::instance()->globalStorage()->insert( "firmwareType", fwType );

View File

@ -16,18 +16,16 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PREPAREPAGEPLUGIN_H
#define PREPAREPAGEPLUGIN_H
#include "viewpages/ViewStep.h"
#include "PluginDllMacro.h"
#ifndef REQUIREMENTSCHECKER_H
#define REQUIREMENTSCHECKER_H
#include <QObject>
#include <QStringList>
#include <functional>
class PreparePage;
class CheckerWidget;
class QWidget;
struct PrepareEntry
{
@ -37,35 +35,21 @@ struct PrepareEntry
bool required;
};
class PLUGINDLLEXPORT PrepareViewStep : public Calamares::ViewStep
class RequirementsChecker : public QObject
{
Q_OBJECT
Q_PLUGIN_METADATA( IID "calamares.ViewModule/1.0" )
Q_INTERFACES( Calamares::ViewStep )
public:
explicit PrepareViewStep( QObject* parent = nullptr );
virtual ~PrepareViewStep();
explicit RequirementsChecker( QObject* parent = nullptr );
virtual ~RequirementsChecker();
QString prettyName() const override;
QWidget* widget() const;
QWidget* widget() override;
void setConfigurationMap( const QVariantMap& configurationMap );
void next() override;
void back() override;
bool verdict() const;
bool isNextEnabled() const override;
bool isBackEnabled() const override;
bool isAtBeginning() const override;
bool isAtEnd() const override;
QList< Calamares::job_ptr > jobs() const override;
void onLeave() override;
void setConfigurationMap( const QVariantMap& configurationMap ) override;
signals:
void verdictChanged( bool );
private:
QStringList m_entriesToCheck;
@ -82,8 +66,8 @@ private:
qreal m_requiredStorageGB;
qreal m_requiredRamGB;
PreparePage* m_actualWidget;
bool m_nextEnabled;
CheckerWidget* m_actualWidget;
bool m_verdict;
};
#endif // PREPAREPAGEPLUGIN_H
#endif // REQUIREMENTSCHECKER_H