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 ) 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 calamares_add_plugin( welcome
TYPE viewmodule TYPE viewmodule
EXPORT_MACRO PLUGINDLLEXPORT_PRO EXPORT_MACRO PLUGINDLLEXPORT_PRO
SOURCES SOURCES
${CHECKER_SOURCES}
WelcomeViewStep.cpp WelcomeViewStep.cpp
WelcomePage.cpp WelcomePage.cpp
UI UI
WelcomePage.ui WelcomePage.ui
LINK_LIBRARIES LINK_LIBRARIES
calamaresui calamaresui
${CHECKER_LINK_LIBRARIES}
SHARED_LIB SHARED_LIB
) )

View File

@ -1,6 +1,6 @@
/* === This file is part of Calamares - <http://github.com/calamares> === /* === 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 * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * 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/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "PrepareCheckWidget.h" #include "CheckItemWidget.h"
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include <QBoxLayout> #include <QBoxLayout>
PrepareCheckWidget::PrepareCheckWidget( bool checked, CheckItemWidget::CheckItemWidget( bool checked,
QWidget* parent ) QWidget* parent )
: QWidget( parent ) : QWidget( parent )
{ {
@ -51,7 +51,7 @@ PrepareCheckWidget::PrepareCheckWidget( bool checked,
void void
PrepareCheckWidget::setText( const QString& text ) CheckItemWidget::setText( const QString& text )
{ {
m_textLabel->setText( text ); m_textLabel->setText( text );
} }

View File

@ -1,6 +1,6 @@
/* === This file is part of Calamares - <http://github.com/calamares> === /* === 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 * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * 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/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef PREPARECHECKWIDGET_H #ifndef CHECKITEMWIDGET_H
#define PREPARECHECKWIDGET_H #define CHECKITEMWIDGET_H
#include <QLabel> #include <QLabel>
class PrepareCheckWidget : public QWidget class CheckItemWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit PrepareCheckWidget( bool checked, explicit CheckItemWidget( bool checked,
QWidget* parent = nullptr ); QWidget* parent = nullptr );
void setText( const QString& text ); void setText( const QString& text );
@ -34,4 +34,4 @@ private:
QLabel* m_iconLabel; 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> === /* === 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 * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * 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/>. * 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/CalamaresUtilsGui.h"
#include "utils/Retranslator.h" #include "utils/Retranslator.h"
@ -28,7 +28,7 @@
#include <QLabel> #include <QLabel>
PreparePage::PreparePage( QWidget* parent ) CheckerWidget::CheckerWidget( QWidget* parent )
: QWidget() : QWidget()
{ {
QBoxLayout* mainLayout = new QVBoxLayout; QBoxLayout* mainLayout = new QVBoxLayout;
@ -52,17 +52,17 @@ PreparePage::PreparePage( QWidget* parent )
void void
PreparePage::init( const QList< PrepareEntry >& checkEntries ) CheckerWidget::init( const QList< PrepareEntry >& checkEntries )
{ {
bool allChecked = true; bool allChecked = true;
bool requirementsSatisfied = true; bool requirementsSatisfied = true;
for ( const PrepareEntry& entry : checkEntries ) for ( const PrepareEntry& entry : checkEntries )
{ {
PrepareCheckWidget* pcw = new PrepareCheckWidget( entry.checked ); CheckItemWidget* ciw = new CheckItemWidget( entry.checked );
CALAMARES_RETRANSLATE( pcw->setText( entry.text() ); ) CALAMARES_RETRANSLATE( ciw->setText( entry.text() ); )
m_entriesLayout->addWidget( pcw ); m_entriesLayout->addWidget( ciw );
pcw->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ); ciw->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
if ( !entry.checked ) if ( !entry.checked )
{ {

View File

@ -1,6 +1,6 @@
/* === This file is part of Calamares - <http://github.com/calamares> === /* === 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 * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * 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/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef PREPAREPAGE_H #ifndef CHECKERWIDGET_H
#define PREPAREPAGE_H #define CHECKERWIDGET_H
#include "PrepareViewStep.h" #include "RequirementsChecker.h"
#include <QBoxLayout> #include <QBoxLayout>
#include <QWidget> #include <QWidget>
class PreparePage : public QWidget class CheckerWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit PreparePage( QWidget* parent = nullptr ); explicit CheckerWidget( QWidget* parent = nullptr );
void init( const QList< PrepareEntry >& checkEntries ); void init( const QList< PrepareEntry >& checkEntries );
@ -36,4 +36,4 @@ private:
QBoxLayout* m_entriesLayout; 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/>. * 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 "partman_devices.h"
#include "widgets/WaitingWidget.h" #include "widgets/WaitingWidget.h"
@ -38,11 +38,11 @@
#include <QProcess> #include <QProcess>
#include <QTimer> #include <QTimer>
PrepareViewStep::PrepareViewStep( QObject* parent ) RequirementsChecker::RequirementsChecker( QObject* parent )
: Calamares::ViewStep( parent ) : QObject( parent )
, m_widget( new QWidget() ) , m_widget( new QWidget() )
, m_actualWidget( new PreparePage() ) , m_actualWidget( new CheckerWidget() )
, m_nextEnabled( false ) , m_verdict( false )
, m_requiredStorageGB( -1 ) , m_requiredStorageGB( -1 )
{ {
QBoxLayout* mainLayout = new QHBoxLayout; QBoxLayout* mainLayout = new QHBoxLayout;
@ -131,8 +131,8 @@ PrepareViewStep::PrepareViewStep( QObject* parent )
break; break;
} }
} }
m_nextEnabled = canGoNext; m_verdict = canGoNext;
emit nextStatusChanged( m_nextEnabled ); emit verdictChanged( m_verdict );
if ( canGoNext ) if ( canGoNext )
detectFirmwareType(); detectFirmwareType();
@ -141,86 +141,26 @@ PrepareViewStep::PrepareViewStep( QObject* parent )
} ); } );
timer->start( 0 ); timer->start( 0 );
emit nextStatusChanged( true ); emit verdictChanged( true );
} }
PrepareViewStep::~PrepareViewStep() RequirementsChecker::~RequirementsChecker()
{ {
if ( m_widget && m_widget->parent() == nullptr ) if ( m_widget && m_widget->parent() == nullptr )
m_widget->deleteLater(); m_widget->deleteLater();
} }
QString
PrepareViewStep::prettyName() const
{
return tr( "Prepare" );
}
QWidget* QWidget*
PrepareViewStep::widget() RequirementsChecker::widget() const
{ {
return m_widget; return m_widget;
} }
void void
PrepareViewStep::next() RequirementsChecker::setConfigurationMap( const QVariantMap& configurationMap )
{
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 )
{ {
if ( configurationMap.contains( "requiredStorage" ) && if ( configurationMap.contains( "requiredStorage" ) &&
configurationMap.value( "requiredStorage" ).type() == QVariant::Double ) configurationMap.value( "requiredStorage" ).type() == QVariant::Double )
@ -267,14 +207,21 @@ PrepareViewStep::setConfigurationMap( const QVariantMap& configurationMap )
bool bool
PrepareViewStep::checkEnoughStorage( qint64 requiredSpace ) RequirementsChecker::verdict() const
{
return m_verdict;
}
bool
RequirementsChecker::checkEnoughStorage( qint64 requiredSpace )
{ {
return check_big_enough( requiredSpace ); return check_big_enough( requiredSpace );
} }
bool bool
PrepareViewStep::checkEnoughRam( qint64 requiredRam ) RequirementsChecker::checkEnoughRam( qint64 requiredRam )
{ {
// A line in meminfo looks like this, with {print $2} we grab the second column. // A line in meminfo looks like this, with {print $2} we grab the second column.
// MemTotal: 8133432 kB // MemTotal: 8133432 kB
@ -290,7 +237,7 @@ PrepareViewStep::checkEnoughRam( qint64 requiredRam )
bool bool
PrepareViewStep::checkBatteryExists() RequirementsChecker::checkBatteryExists()
{ {
const QFileInfo basePath( "/sys/class/power_supply" ); const QFileInfo basePath( "/sys/class/power_supply" );
@ -317,7 +264,7 @@ PrepareViewStep::checkBatteryExists()
bool bool
PrepareViewStep::checkHasPower() RequirementsChecker::checkHasPower()
{ {
const QString UPOWER_SVC_NAME( "org.freedesktop.UPower" ); const QString UPOWER_SVC_NAME( "org.freedesktop.UPower" );
const QString UPOWER_INTF_NAME( "org.freedesktop.UPower" ); const QString UPOWER_INTF_NAME( "org.freedesktop.UPower" );
@ -348,7 +295,7 @@ PrepareViewStep::checkHasPower()
bool bool
PrepareViewStep::checkHasInternet() RequirementsChecker::checkHasInternet()
{ {
const QString NM_SVC_NAME( "org.freedesktop.NetworkManager" ); const QString NM_SVC_NAME( "org.freedesktop.NetworkManager" );
const QString NM_INTF_NAME( "org.freedesktop.NetworkManager" ); const QString NM_INTF_NAME( "org.freedesktop.NetworkManager" );
@ -376,7 +323,7 @@ PrepareViewStep::checkHasInternet()
void void
PrepareViewStep::detectFirmwareType() RequirementsChecker::detectFirmwareType()
{ {
QString fwType = QFile::exists( "/sys/firmware/efi/efivars" ) ? "efi" : "bios"; QString fwType = QFile::exists( "/sys/firmware/efi/efivars" ) ? "efi" : "bios";
Calamares::JobQueue::instance()->globalStorage()->insert( "firmwareType", fwType ); Calamares::JobQueue::instance()->globalStorage()->insert( "firmwareType", fwType );

View File

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