[welcome] Coding style

- apply coding style, add {}
 - remove unneeded includes (moved to the widgets)
 - update copyright
This commit is contained in:
Adriaan de Groot 2020-01-29 11:10:30 +01:00
parent 6b77d5db4a
commit 8f581ca861

View File

@ -1,7 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> === /* === This file is part of Calamares - <https://github.com/calamares> ===
* *
* Copyright 2014-2017, Teo Mrnjavac <teo@kde.org> * Copyright 2014-2017, Teo Mrnjavac <teo@kde.org>
* Copyright 2017-2018, Adriaan de Groot <groot@kde.org> * Copyright 2017-2018, 2020, Adriaan de Groot <groot@kde.org>
* Copyright 2017, Gabriel Craciunescu <crazy@frugalware.org> * Copyright 2017, Gabriel Craciunescu <crazy@frugalware.org>
* Copyright 2019, Collabora Ltd <arnaud.ferraris@collabora.com> * Copyright 2019, Collabora Ltd <arnaud.ferraris@collabora.com>
* *
@ -24,32 +24,27 @@
#include "CheckerContainer.h" #include "CheckerContainer.h"
#include "partman_devices.h" #include "partman_devices.h"
#include "Settings.h"
#include "modulesystem/Requirement.h" #include "modulesystem/Requirement.h"
#include "network/Manager.h" #include "network/Manager.h"
#include "widgets/WaitingWidget.h"
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
#include "utils/CalamaresUtilsSystem.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Retranslator.h" #include "utils/Retranslator.h"
#include "utils/CalamaresUtilsSystem.h"
#include "utils/Units.h" #include "utils/Units.h"
#include "utils/Variant.h" #include "utils/Variant.h"
#include "Settings.h" #include "widgets/WaitingWidget.h"
#include "JobQueue.h"
#include "GlobalStorage.h" #include "GlobalStorage.h"
#include "JobQueue.h"
#include <QApplication> #include <QGuiApplication>
#include <QBoxLayout>
#include <QDBusConnection> #include <QDBusConnection>
#include <QDBusInterface> #include <QDBusInterface>
#include <QDesktopWidget>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QLabel>
#include <QProcess>
#include <QScreen> #include <QScreen>
#include <QTimer>
#include <unistd.h> //geteuid #include <unistd.h> //geteuid
@ -75,7 +70,8 @@ biggestSingleScreen()
return s; return s;
} }
Calamares::RequirementsList GeneralRequirements::checkRequirements() Calamares::RequirementsList
GeneralRequirements::checkRequirements()
{ {
QSize availableSize = biggestSingleScreen(); QSize availableSize = biggestSingleScreen();
@ -84,90 +80,108 @@ Calamares::RequirementsList GeneralRequirements::checkRequirements()
bool hasPower = false; bool hasPower = false;
bool hasInternet = false; bool hasInternet = false;
bool isRoot = false; bool isRoot = false;
bool enoughScreen = availableSize.isValid() && (availableSize.width() >= CalamaresUtils::windowMinimumWidth) && (availableSize.height() >= CalamaresUtils::windowMinimumHeight); bool enoughScreen = availableSize.isValid() && ( availableSize.width() >= CalamaresUtils::windowMinimumWidth )
&& ( availableSize.height() >= CalamaresUtils::windowMinimumHeight );
qint64 requiredStorageB = CalamaresUtils::GiBtoBytes(m_requiredStorageGiB); qint64 requiredStorageB = CalamaresUtils::GiBtoBytes( m_requiredStorageGiB );
cDebug() << "Need at least storage bytes:" << requiredStorageB; cDebug() << "Need at least storage bytes:" << requiredStorageB;
if ( m_entriesToCheck.contains( "storage" ) ) if ( m_entriesToCheck.contains( "storage" ) )
{
enoughStorage = checkEnoughStorage( requiredStorageB ); enoughStorage = checkEnoughStorage( requiredStorageB );
}
qint64 requiredRamB = CalamaresUtils::GiBtoBytes(m_requiredRamGiB); qint64 requiredRamB = CalamaresUtils::GiBtoBytes( m_requiredRamGiB );
cDebug() << "Need at least ram bytes:" << requiredRamB; cDebug() << "Need at least ram bytes:" << requiredRamB;
if ( m_entriesToCheck.contains( "ram" ) ) if ( m_entriesToCheck.contains( "ram" ) )
{
enoughRam = checkEnoughRam( requiredRamB ); enoughRam = checkEnoughRam( requiredRamB );
}
if ( m_entriesToCheck.contains( "power" ) ) if ( m_entriesToCheck.contains( "power" ) )
{
hasPower = checkHasPower(); hasPower = checkHasPower();
}
if ( m_entriesToCheck.contains( "internet" ) ) if ( m_entriesToCheck.contains( "internet" ) )
{
hasInternet = checkHasInternet(); hasInternet = checkHasInternet();
}
if ( m_entriesToCheck.contains( "root" ) ) if ( m_entriesToCheck.contains( "root" ) )
{
isRoot = checkIsRoot(); isRoot = checkIsRoot();
}
using TR = Logger::DebugRow<const char *, bool>; using TR = Logger::DebugRow< const char*, bool >;
cDebug() << "GeneralRequirements output:" cDebug() << "GeneralRequirements output:" << TR( "enoughStorage", enoughStorage ) << TR( "enoughRam", enoughRam )
<< TR("enoughStorage", enoughStorage) << TR( "hasPower", hasPower ) << TR( "hasInternet", hasInternet ) << TR( "isRoot", isRoot );
<< TR("enoughRam", enoughRam)
<< TR("hasPower", hasPower)
<< TR("hasInternet", hasInternet)
<< TR("isRoot", isRoot);
Calamares::RequirementsList checkEntries; Calamares::RequirementsList checkEntries;
foreach ( const QString& entry, m_entriesToCheck ) foreach ( const QString& entry, m_entriesToCheck )
{ {
if ( entry == "storage" ) if ( entry == "storage" )
checkEntries.append( { {
entry, checkEntries.append(
[req=m_requiredStorageGiB]{ return tr( "has at least %1 GiB available drive space" ).arg( req ); }, { entry,
[req=m_requiredStorageGiB]{ return tr( "There is not enough drive space. At least %1 GiB is required." ).arg( req ); }, [req = m_requiredStorageGiB] { return tr( "has at least %1 GiB available drive space" ).arg( req ); },
[req = m_requiredStorageGiB] {
return tr( "There is not enough drive space. At least %1 GiB is required." ).arg( req );
},
enoughStorage, enoughStorage,
m_entriesToRequire.contains( entry ) m_entriesToRequire.contains( entry ) } );
} ); }
else if ( entry == "ram" ) else if ( entry == "ram" )
checkEntries.append( { {
entry, checkEntries.append(
[req=m_requiredRamGiB]{ return tr( "has at least %1 GiB working memory" ).arg( req ); }, { entry,
[req=m_requiredRamGiB]{ return tr( "The system does not have enough working memory. At least %1 GiB is required." ).arg( req ); }, [req = m_requiredRamGiB] { return tr( "has at least %1 GiB working memory" ).arg( req ); },
[req = m_requiredRamGiB] {
return tr( "The system does not have enough working memory. At least %1 GiB is required." )
.arg( req );
},
enoughRam, enoughRam,
m_entriesToRequire.contains( entry ) m_entriesToRequire.contains( entry ) } );
} ); }
else if ( entry == "power" ) else if ( entry == "power" )
checkEntries.append( { {
entry, checkEntries.append( { entry,
[]{ return tr( "is plugged in to a power source" ); }, [] { return tr( "is plugged in to a power source" ); },
[]{ return tr( "The system is not plugged in to a power source." ); }, [] { return tr( "The system is not plugged in to a power source." ); },
hasPower, hasPower,
m_entriesToRequire.contains( entry ) m_entriesToRequire.contains( entry ) } );
} ); }
else if ( entry == "internet" ) else if ( entry == "internet" )
checkEntries.append( { {
entry, checkEntries.append( { entry,
[]{ return tr( "is connected to the Internet" ); }, [] { return tr( "is connected to the Internet" ); },
[]{ return tr( "The system is not connected to the Internet." ); }, [] { return tr( "The system is not connected to the Internet." ); },
hasInternet, hasInternet,
m_entriesToRequire.contains( entry ) m_entriesToRequire.contains( entry ) } );
} ); }
else if ( entry == "root" ) else if ( entry == "root" )
checkEntries.append( { {
entry, checkEntries.append( { entry,
[]{ return tr( "is running the installer as an administrator (root)" ); }, [] { return tr( "is running the installer as an administrator (root)" ); },
[]{ return Calamares::Settings::instance()->isSetupMode() [] {
return Calamares::Settings::instance()->isSetupMode()
? tr( "The setup program is not running with administrator rights." ) ? tr( "The setup program is not running with administrator rights." )
: tr( "The installer is not running with administrator rights." ); }, : tr( "The installer is not running with administrator rights." );
},
isRoot, isRoot,
m_entriesToRequire.contains( entry ) m_entriesToRequire.contains( entry ) } );
} ); }
else if ( entry == "screen" ) else if ( entry == "screen" )
checkEntries.append( { {
entry, checkEntries.append( { entry,
[]{ return tr( "has a screen large enough to show the whole installer" ); }, [] { return tr( "has a screen large enough to show the whole installer" ); },
[]{ return Calamares::Settings::instance()->isSetupMode() [] {
return Calamares::Settings::instance()->isSetupMode()
? tr( "The screen is too small to display the setup program." ) ? tr( "The screen is too small to display the setup program." )
: tr( "The screen is too small to display the installer." ); }, : tr( "The screen is too small to display the installer." );
},
enoughScreen, enoughScreen,
false false } );
} ); }
} }
return checkEntries; return checkEntries;
} }
@ -178,8 +192,7 @@ GeneralRequirements::setConfigurationMap( const QVariantMap& configurationMap )
{ {
bool incompleteConfiguration = false; bool incompleteConfiguration = false;
if ( configurationMap.contains( "check" ) && if ( configurationMap.contains( "check" ) && configurationMap.value( "check" ).type() == QVariant::List )
configurationMap.value( "check" ).type() == QVariant::List )
{ {
m_entriesToCheck.clear(); m_entriesToCheck.clear();
m_entriesToCheck.append( configurationMap.value( "check" ).toStringList() ); m_entriesToCheck.append( configurationMap.value( "check" ).toStringList() );
@ -190,8 +203,7 @@ GeneralRequirements::setConfigurationMap( const QVariantMap& configurationMap )
incompleteConfiguration = true; incompleteConfiguration = true;
} }
if ( configurationMap.contains( "required" ) && if ( configurationMap.contains( "required" ) && configurationMap.value( "required" ).type() == QVariant::List )
configurationMap.value( "required" ).type() == QVariant::List )
{ {
m_entriesToRequire.clear(); m_entriesToRequire.clear();
m_entriesToRequire.append( configurationMap.value( "required" ).toStringList() ); m_entriesToRequire.append( configurationMap.value( "required" ).toStringList() );
@ -216,11 +228,13 @@ GeneralRequirements::setConfigurationMap( const QVariantMap& configurationMap )
// Help out with consistency, but don't fix // Help out with consistency, but don't fix
for ( const auto& r : m_entriesToRequire ) for ( const auto& r : m_entriesToRequire )
if ( !m_entriesToCheck.contains( r ) ) if ( !m_entriesToCheck.contains( r ) )
{
cWarning() << "GeneralRequirements requires" << r << "but does not check it."; cWarning() << "GeneralRequirements requires" << r << "but does not check it.";
}
if ( configurationMap.contains( "requiredStorage" ) && if ( configurationMap.contains( "requiredStorage" )
( configurationMap.value( "requiredStorage" ).type() == QVariant::Double || && ( configurationMap.value( "requiredStorage" ).type() == QVariant::Double
configurationMap.value( "requiredStorage" ).type() == QVariant::LongLong ) ) || configurationMap.value( "requiredStorage" ).type() == QVariant::LongLong ) )
{ {
bool ok = false; bool ok = false;
m_requiredStorageGiB = configurationMap.value( "requiredStorage" ).toDouble( &ok ); m_requiredStorageGiB = configurationMap.value( "requiredStorage" ).toDouble( &ok );
@ -239,9 +253,9 @@ GeneralRequirements::setConfigurationMap( const QVariantMap& configurationMap )
incompleteConfiguration = true; incompleteConfiguration = true;
} }
if ( configurationMap.contains( "requiredRam" ) && if ( configurationMap.contains( "requiredRam" )
( configurationMap.value( "requiredRam" ).type() == QVariant::Double || && ( configurationMap.value( "requiredRam" ).type() == QVariant::Double
configurationMap.value( "requiredRam" ).type() == QVariant::LongLong ) ) || configurationMap.value( "requiredRam" ).type() == QVariant::LongLong ) )
{ {
bool ok = false; bool ok = false;
m_requiredRamGiB = configurationMap.value( "requiredRam" ).toDouble( &ok ); m_requiredRamGiB = configurationMap.value( "requiredRam" ).toDouble( &ok );
@ -266,8 +280,8 @@ GeneralRequirements::setConfigurationMap( const QVariantMap& configurationMap )
checkInternetUrl = QUrl( checkInternetSetting.trimmed() ); checkInternetUrl = QUrl( checkInternetSetting.trimmed() );
if ( !checkInternetUrl.isValid() ) if ( !checkInternetUrl.isValid() )
{ {
cWarning() << "GeneralRequirements entry 'internetCheckUrl' is invalid in welcome.conf" << checkInternetSetting cWarning() << "GeneralRequirements entry 'internetCheckUrl' is invalid in welcome.conf"
<< "reverting to default (http://example.com)."; << checkInternetSetting << "reverting to default (http://example.com).";
checkInternetUrl = QUrl( "http://example.com" ); checkInternetUrl = QUrl( "http://example.com" );
incompleteConfiguration = true; incompleteConfiguration = true;
} }
@ -320,21 +334,24 @@ GeneralRequirements::checkBatteryExists()
const QFileInfo basePath( "/sys/class/power_supply" ); const QFileInfo basePath( "/sys/class/power_supply" );
if ( !( basePath.exists() && basePath.isDir() ) ) if ( !( basePath.exists() && basePath.isDir() ) )
{
return false; return false;
}
QDir baseDir( basePath.absoluteFilePath() ); QDir baseDir( basePath.absoluteFilePath() );
const auto entries = baseDir.entryList( QDir::AllDirs | QDir::Readable | QDir::NoDotAndDotDot ); const auto entries = baseDir.entryList( QDir::AllDirs | QDir::Readable | QDir::NoDotAndDotDot );
for ( const auto &item : entries ) for ( const auto& item : entries )
{ {
QFileInfo typePath( baseDir.absoluteFilePath( QString( "%1/type" ) QFileInfo typePath( baseDir.absoluteFilePath( QString( "%1/type" ).arg( item ) ) );
.arg( item ) ) );
QFile typeFile( typePath.absoluteFilePath() ); QFile typeFile( typePath.absoluteFilePath() );
if ( typeFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) if ( typeFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
{ {
if ( typeFile.readAll().startsWith( "Battery" ) ) if ( typeFile.readAll().startsWith( "Battery" ) )
{
return true; return true;
} }
} }
}
return false; return false;
} }
@ -348,13 +365,12 @@ GeneralRequirements::checkHasPower()
const QString UPOWER_PATH( "/org/freedesktop/UPower" ); const QString UPOWER_PATH( "/org/freedesktop/UPower" );
if ( !checkBatteryExists() ) if ( !checkBatteryExists() )
{
return true; return true;
}
cDebug() << "A battery exists, checking for mains power."; cDebug() << "A battery exists, checking for mains power.";
QDBusInterface upowerIntf( UPOWER_SVC_NAME, QDBusInterface upowerIntf( UPOWER_SVC_NAME, UPOWER_PATH, UPOWER_INTF_NAME, QDBusConnection::systemBus() );
UPOWER_PATH,
UPOWER_INTF_NAME,
QDBusConnection::systemBus() );
bool onBattery = upowerIntf.property( "OnBattery" ).toBool(); bool onBattery = upowerIntf.property( "OnBattery" ).toBool();