Merge branch 'master' of https://github.com/calamares/calamares into development

This commit is contained in:
Philip Müller 2019-05-15 06:18:59 +02:00
commit 5329b77df6
45 changed files with 526 additions and 205 deletions

View File

@ -6,6 +6,7 @@ website will have to do for older versions.
# 3.2.9 (unreleased) # # 3.2.9 (unreleased) #
This release contains contributions from (alphabetically by first name): This release contains contributions from (alphabetically by first name):
- Kevin Kofler
## Core ## ## Core ##

View File

@ -193,6 +193,7 @@ if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
) )
string( APPEND CMAKE_CXX_FLAGS " ${CLANG_WARNINGS}" ) string( APPEND CMAKE_CXX_FLAGS " ${CLANG_WARNINGS}" )
endforeach() endforeach()
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOTREACHED='//'" )
# Third-party code where we don't care so much about compiler warnings # Third-party code where we don't care so much about compiler warnings
# (because it's uncomfortable to patch) get different flags; use # (because it's uncomfortable to patch) get different flags; use
@ -203,7 +204,7 @@ if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
set( CMAKE_CXX_FLAGS_DEBUG "-g ${CMAKE_CXX_FLAGS_DEBUG}" ) set( CMAKE_CXX_FLAGS_DEBUG "-g ${CMAKE_CXX_FLAGS_DEBUG}" )
set( CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG" ) set( CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG" )
set( CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG" ) set( CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" )
set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g" ) set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g" )
set( CMAKE_TOOLCHAIN_PREFIX "llvm-" ) set( CMAKE_TOOLCHAIN_PREFIX "llvm-" )
@ -211,12 +212,15 @@ if( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
set( CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined" ) set( CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined" )
set( CALAMARES_AUTOMOC_OPTIONS "-butils/moc-warnings.h" ) set( CALAMARES_AUTOMOC_OPTIONS "-butils/moc-warnings.h" )
set( CALAMARES_AUTOUIC_OPTIONS --include utils/moc-warnings.h )
else() else()
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--no-undefined" ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--no-undefined" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--fatal-warnings -Wnon-virtual-dtor -Woverloaded-virtual -Werror=return-type" ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--fatal-warnings -Wnon-virtual-dtor -Woverloaded-virtual -Werror=return-type" )
set( SUPPRESS_3RDPARTY_WARNINGS "" ) set( SUPPRESS_3RDPARTY_WARNINGS "" )
set( SUPPRESS_BOOST_WARNINGS "" ) set( SUPPRESS_BOOST_WARNINGS "" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOTREACHED='__builtin_unreachable();'" )
endif() endif()
# Use mark_thirdparty_code() to reduce warnings from the compiler # Use mark_thirdparty_code() to reduce warnings from the compiler

View File

@ -61,11 +61,6 @@ function(calamares_add_library)
include_directories(${CMAKE_CURRENT_LIST_DIR}) include_directories(${CMAKE_CURRENT_LIST_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR})
if(LIBRARY_UI)
qt5_wrap_ui(LIBRARY_UI_SOURCES ${LIBRARY_UI})
list(APPEND LIBRARY_SOURCES ${LIBRARY_UI_SOURCES})
endif()
# add resources from current dir # add resources from current dir
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${LIBRARY_RESOURCES}") if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${LIBRARY_RESOURCES}")
qt5_add_resources(LIBRARY_RC_SOURCES "${LIBRARY_RESOURCES}") qt5_add_resources(LIBRARY_RC_SOURCES "${LIBRARY_RESOURCES}")
@ -83,7 +78,10 @@ function(calamares_add_library)
endif() endif()
calamares_automoc(${target}) calamares_automoc(${target})
if(LIBRARY_UI)
calamares_autouic(${target} ${LIBRARY_UI})
endif()
if(LIBRARY_EXPORT_MACRO) if(LIBRARY_EXPORT_MACRO)
set_target_properties(${target} PROPERTIES COMPILE_DEFINITIONS ${LIBRARY_EXPORT_MACRO}) set_target_properties(${target} PROPERTIES COMPILE_DEFINITIONS ${LIBRARY_EXPORT_MACRO})
endif() endif()

View File

@ -18,7 +18,7 @@
# #
### ###
# #
# Helper function for doing automoc on a target. # Helper function for doing automoc on a target, and autoui on a .ui file.
# #
# Sets AUTOMOC TRUE for a target. # Sets AUTOMOC TRUE for a target.
# #
@ -27,6 +27,8 @@
# libcalamares/utils/moc-warnings.h file to the moc, which in turn # libcalamares/utils/moc-warnings.h file to the moc, which in turn
# reduces compiler warnings in generated MOC code. # reduces compiler warnings in generated MOC code.
# #
# If the global variable CALAMARES_AUTOUIC_OPTIONS is set, adds that
# to the options passed to uic.
function(calamares_automoc TARGET) function(calamares_automoc TARGET)
set_target_properties( ${TARGET} PROPERTIES AUTOMOC TRUE ) set_target_properties( ${TARGET} PROPERTIES AUTOMOC TRUE )
@ -34,3 +36,12 @@ function(calamares_automoc TARGET)
set_target_properties( ${TARGET} PROPERTIES AUTOMOC_MOC_OPTIONS "${CALAMARES_AUTOMOC_OPTIONS}" ) set_target_properties( ${TARGET} PROPERTIES AUTOMOC_MOC_OPTIONS "${CALAMARES_AUTOMOC_OPTIONS}" )
endif() endif()
endfunction() endfunction()
function(calamares_autouic TARGET)
set_target_properties( ${TARGET} PROPERTIES AUTOUIC TRUE )
if ( CALAMARES_AUTOUIC_OPTIONS )
foreach(S ${ARGN})
set_property(SOURCE ${S} PROPERTY AUTOUIC_OPTIONS "${CALAMARES_AUTOUIC_OPTIONS}")
endforeach()
endif()
endfunction()

View File

@ -41,8 +41,8 @@ BUILDDIR=$(mktemp -d --suffix=-build --tmpdir=.)
if test "x$BUILD_DEFAULT" = "xtrue" ; then if test "x$BUILD_DEFAULT" = "xtrue" ; then
rm -rf "$BUILDDIR" rm -rf "$BUILDDIR"
mkdir "$BUILDDIR" || { echo "Could not create build directory." ; exit 1 ; } mkdir "$BUILDDIR" || { echo "Could not create build directory." ; exit 1 ; }
( cd "$BUILDDIR" && cmake .. && make -j4 ) || { echo "Could not perform test-build." ; exit 1 ; } ( cd "$BUILDDIR" && cmake .. && make -j4 ) || { echo "Could not perform test-build in $BUILDDIR." ; exit 1 ; }
( cd "$BUILDDIR" && make test ) || { echo "Tests failed." ; exit 1 ; } ( cd "$BUILDDIR" && make test ) || { echo "Tests failed in $BUILDDIR." ; exit 1 ; }
fi fi
### Build with clang ### Build with clang
@ -53,13 +53,13 @@ if test "x$BUILD_CLANG" = "xtrue" ; then
# Do build again with clang # Do build again with clang
rm -rf "$BUILDDIR" rm -rf "$BUILDDIR"
mkdir "$BUILDDIR" || { echo "Could not create build directory." ; exit 1 ; } mkdir "$BUILDDIR" || { echo "Could not create build directory." ; exit 1 ; }
( cd "$BUILDDIR" && CC=clang CXX=clang++ cmake .. && make -j4 ) || { echo "Could not perform test-build." ; exit 1 ; } ( cd "$BUILDDIR" && CC=clang CXX=clang++ cmake .. && make -j4 ) || { echo "Could not perform test-build in $BUILDDIR." ; exit 1 ; }
( cd "$BUILDDIR" && make test ) || { echo "Tests failed." ; exit 1 ; } ( cd "$BUILDDIR" && make test ) || { echo "Tests failed in $BUILDDIR." ; exit 1 ; }
fi fi
fi fi
if test "x$BUILD_ONLY" = "xtrue" ; then if test "x$BUILD_ONLY" = "xtrue" ; then
echo "Builds completed, release stopped." echo "Builds completed, release stopped. Build remains in $BUILDDIR."
exit 1 exit 1
fi fi

View File

@ -56,6 +56,10 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
, m_debugWindow( nullptr ) , m_debugWindow( nullptr )
, m_viewManager( nullptr ) , m_viewManager( nullptr )
{ {
// If we can never cancel, don't show the window-close button
if ( Calamares::Settings::instance()->disableCancel() )
setWindowFlag( Qt::WindowCloseButtonHint, false );
CALAMARES_RETRANSLATE( CALAMARES_RETRANSLATE(
setWindowTitle( Calamares::Settings::instance()->isSetupMode() setWindowTitle( Calamares::Settings::instance()->isSetupMode()
? tr( "%1 Setup Program" ).arg( *Calamares::Branding::ProductName ) ? tr( "%1 Setup Program" ).arg( *Calamares::Branding::ProductName )
@ -161,7 +165,15 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
m_viewManager = Calamares::ViewManager::instance( this ); m_viewManager = Calamares::ViewManager::instance( this );
if ( branding->windowExpands() ) if ( branding->windowExpands() )
connect( m_viewManager, &Calamares::ViewManager::enlarge, this, &CalamaresWindow::enlarge ); connect( m_viewManager, &Calamares::ViewManager::enlarge, this, &CalamaresWindow::enlarge );
// NOTE: Although the ViewManager has a signal cancelEnabled() that
// signals when the state of the cancel button changes (in
// particular, to disable cancel during the exec phase),
// we don't connect to it here. Changing the window flag
// for the close button causes uncomfortable window flashing
// and requires an extra show() (at least with KWin/X11) which
// is too annoying. Instead, leave it up to ignoring-the-quit-
// event, which is also the ViewManager's responsibility.
mainLayout->addWidget( m_viewManager->centralWidget() ); mainLayout->addWidget( m_viewManager->centralWidget() );
setStyleSheet( Calamares::Branding::instance()->stylesheet() ); setStyleSheet( Calamares::Branding::instance()->stylesheet() );
} }

View File

@ -167,6 +167,16 @@ if ( ECM_FOUND AND BUILD_TESTING )
${YAMLCPP_LIBRARY} ${YAMLCPP_LIBRARY}
) )
calamares_automoc( geoiptest ) calamares_automoc( geoiptest )
ecm_add_test(
partition/Tests.cpp
TEST_NAME
libcalamarespartitiontest
LINK_LIBRARIES
calamares
Qt5::Test
)
calamares_automoc( libcalamarespartitiontest )
endif() endif()
if( BUILD_TESTING ) if( BUILD_TESTING )

View File

@ -185,7 +185,7 @@ Settings::Settings( const QString& settingsFilePath,
, m_doChroot( true ) , m_doChroot( true )
, m_promptInstall( false ) , m_promptInstall( false )
, m_disableCancel( false ) , m_disableCancel( false )
, m_dontCancel( false ) , m_disableCancelDuringExec( false )
{ {
cDebug() << "Using Calamares settings file at" << settingsFilePath; cDebug() << "Using Calamares settings file at" << settingsFilePath;
QFile file( settingsFilePath ); QFile file( settingsFilePath );
@ -207,7 +207,7 @@ Settings::Settings( const QString& settingsFilePath,
m_doChroot = !requireBool( config, "dont-chroot", false ); m_doChroot = !requireBool( config, "dont-chroot", false );
m_isSetupMode = requireBool( config, "oem-setup", !m_doChroot ); m_isSetupMode = requireBool( config, "oem-setup", !m_doChroot );
m_disableCancel = requireBool( config, "disable-cancel", false ); m_disableCancel = requireBool( config, "disable-cancel", false );
m_dontCancel = requireBool( config, "disable-cancel-during-exec", false ); m_disableCancelDuringExec = requireBool( config, "disable-cancel-during-exec", false );
} }
catch ( YAML::Exception& e ) catch ( YAML::Exception& e )
{ {
@ -277,9 +277,9 @@ Settings::disableCancel() const
} }
bool bool
Settings::dontCancel() const Settings::disableCancelDuringExec() const
{ {
return m_dontCancel; return m_disableCancelDuringExec;
} }

View File

@ -68,7 +68,7 @@ public:
/** @brief Global setting of disable-cancel: can't cancel ever. */ /** @brief Global setting of disable-cancel: can't cancel ever. */
bool disableCancel() const; bool disableCancel() const;
/** @brief Temporary setting of disable-cancel: can't cancel during exec. */ /** @brief Temporary setting of disable-cancel: can't cancel during exec. */
bool dontCancel() const; bool disableCancelDuringExec() const;
private: private:
static Settings* s_instance; static Settings* s_instance;
@ -85,7 +85,7 @@ private:
bool m_isSetupMode; bool m_isSetupMode;
bool m_promptInstall; bool m_promptInstall;
bool m_disableCancel; bool m_disableCancel;
bool m_dontCancel; bool m_disableCancelDuringExec;
}; };
} }

View File

@ -25,7 +25,9 @@
#include <QByteArray> #include <QByteArray>
namespace CalamaresUtils::GeoIP namespace CalamaresUtils
{
namespace GeoIP
{ {
GeoIPJSON::GeoIPJSON(const QString& attribute) GeoIPJSON::GeoIPJSON(const QString& attribute)
@ -88,6 +90,5 @@ GeoIPJSON::processReply( const QByteArray& data )
return splitTZString( rawReply( data ) ); return splitTZString( rawReply( data ) );
} }
}
} // namespace } // namespace

View File

@ -21,7 +21,9 @@
#include "Interface.h" #include "Interface.h"
namespace CalamaresUtils::GeoIP namespace CalamaresUtils
{
namespace GeoIP
{ {
/** @brief GeoIP lookup for services that return JSON. /** @brief GeoIP lookup for services that return JSON.
* *
@ -46,5 +48,6 @@ public:
virtual QString rawReply(const QByteArray & ) override; virtual QString rawReply(const QByteArray & ) override;
} ; } ;
}
} // namespace } // namespace
#endif #endif

View File

@ -23,7 +23,9 @@
#include <QNetworkReply> #include <QNetworkReply>
#include <QtXml/QDomDocument> #include <QtXml/QDomDocument>
namespace CalamaresUtils::GeoIP namespace CalamaresUtils
{
namespace GeoIP
{ {
GeoIPXML::GeoIPXML( const QString& element ) GeoIPXML::GeoIPXML( const QString& element )
@ -87,4 +89,5 @@ GeoIPXML::processReply( const QByteArray& data )
return RegionZonePair(); return RegionZonePair();
} }
}
} // namespace } // namespace

View File

@ -21,7 +21,9 @@
#include "Interface.h" #include "Interface.h"
namespace CalamaresUtils::GeoIP namespace CalamaresUtils
{
namespace GeoIP
{ {
/** @brief GeoIP lookup with XML data /** @brief GeoIP lookup with XML data
* *
@ -46,5 +48,6 @@ public:
virtual QString rawReply(const QByteArray & ) override; virtual QString rawReply(const QByteArray & ) override;
} ; } ;
}
} // namespace } // namespace
#endif #endif

View File

@ -47,7 +47,9 @@ handlerTypes()
return names; return names;
} }
namespace CalamaresUtils::GeoIP namespace CalamaresUtils
{
namespace GeoIP
{ {
Handler::Handler() Handler::Handler()
@ -110,9 +112,8 @@ create_interface( Handler::Type t, const QString& selector )
#else #else
return nullptr; return nullptr;
#endif #endif
default: // there are no others
return nullptr;
} }
NOTREACHED return nullptr;
} }
static RegionZonePair static RegionZonePair
@ -179,5 +180,5 @@ Handler::queryRaw() const
} ); } );
} }
}
} // namespace } // namespace

View File

@ -25,8 +25,9 @@
#include <QString> #include <QString>
#include <QVariantMap> #include <QVariantMap>
namespace CalamaresUtils {} namespace CalamaresUtils
namespace CalamaresUtils::GeoIP {
namespace GeoIP
{ {
/** @brief Handle one complete GeoIP lookup. /** @brief Handle one complete GeoIP lookup.
@ -86,6 +87,7 @@ private:
const QString m_selector; const QString m_selector;
}; };
}
} // namespace } // namespace
#endif #endif

View File

@ -20,7 +20,9 @@
#include "utils/Logger.h" #include "utils/Logger.h"
namespace CalamaresUtils::GeoIP namespace CalamaresUtils
{
namespace GeoIP
{ {
Interface::Interface(const QString& e) Interface::Interface(const QString& e)
@ -51,4 +53,5 @@ splitTZString( const QString& tz )
return RegionZonePair( QString(), QString() ); return RegionZonePair( QString(), QString() );
} }
}
} // namespace } // namespace

View File

@ -27,8 +27,9 @@
class QByteArray; class QByteArray;
namespace CalamaresUtils {} namespace CalamaresUtils
namespace CalamaresUtils::GeoIP {
namespace GeoIP
{ {
/** @brief A Region, Zone pair of strings /** @brief A Region, Zone pair of strings
* *
@ -94,5 +95,6 @@ protected:
QString m_element; // string for selecting from data QString m_element; // string for selecting from data
} ; } ;
}
} // namespace } // namespace
#endif #endif

View File

@ -19,7 +19,9 @@
#include "Label.h" #include "Label.h"
namespace CalamaresUtils::Locale namespace CalamaresUtils
{
namespace Locale
{ {
Label::Label() Label::Label()
@ -70,4 +72,5 @@ QLocale Label::getLocale( const QString& localeName )
return QLocale( localeName ); return QLocale( localeName );
} }
}
} // namespace } // namespace

View File

@ -23,8 +23,9 @@
#include <QLocale> #include <QLocale>
#include <QString> #include <QString>
namespace CalamaresUtils {} namespace CalamaresUtils
namespace CalamaresUtils::Locale {
namespace Locale
{ {
/** /**
@ -120,7 +121,7 @@ protected:
QString m_englishLabel; QString m_englishLabel;
} ; } ;
}
} // namespace } // namespace
#endif #endif

View File

@ -22,7 +22,9 @@
#include "CalamaresVersion.h" // For the list of translations #include "CalamaresVersion.h" // For the list of translations
namespace CalamaresUtils::Locale namespace CalamaresUtils
{
namespace Locale
{ {
LabelModel::LabelModel( const QStringList& locales, QObject* parent ) LabelModel::LabelModel( const QStringList& locales, QObject* parent )
@ -121,10 +123,11 @@ LabelModel::find( const QString& countryCode ) const
return find( [&]( const Label& l ){ return l.language() == c_l.second; } ); return find( [&]( const Label& l ){ return l.language() == c_l.second; } );
} }
LabelModel* const availableTranslations() LabelModel* availableTranslations()
{ {
static LabelModel model( QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') ); static LabelModel model( QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';') );
return &model; return &model;
} }
}
} // namespace } // namespace

View File

@ -26,8 +26,9 @@
#include <QVector> #include <QVector>
namespace CalamaresUtils {} namespace CalamaresUtils
namespace CalamaresUtils::Locale {
namespace Locale
{ {
class DLLEXPORT LabelModel : public QAbstractListModel class DLLEXPORT LabelModel : public QAbstractListModel
@ -78,7 +79,7 @@ private:
* *
* NOTE: While the model is not typed const, it should be. Do not modify. * NOTE: While the model is not typed const, it should be. Do not modify.
*/ */
DLLEXPORT LabelModel* const availableTranslations(); DLLEXPORT LabelModel* availableTranslations();
}
} // namespace } // namespace
#endif #endif

View File

@ -20,7 +20,9 @@
#include "CountryData_p.cpp" #include "CountryData_p.cpp"
namespace CalamaresUtils::Locale namespace CalamaresUtils
{
namespace Locale
{ {
struct TwoChar struct TwoChar
@ -87,4 +89,5 @@ QLocale::Language languageForCountry(QLocale::Country country)
return p->l; return p->l;
} }
}
} // namespace } // namespace

View File

@ -24,8 +24,9 @@
#include <QLocale> #include <QLocale>
#include <QPair> #include <QPair>
namespace CalamaresUtils {} namespace CalamaresUtils
namespace CalamaresUtils::Locale {
namespace Locale
{ {
/* All the functions in this file do lookups of locale data /* All the functions in this file do lookups of locale data
* based on CLDR tables; these are lookups that you can't (easily) * based on CLDR tables; these are lookups that you can't (easily)
@ -48,6 +49,7 @@ namespace CalamaresUtils::Locale
DLLEXPORT QPair< QLocale::Country, QLocale::Language > countryData( const QString& code ); DLLEXPORT QPair< QLocale::Country, QLocale::Language > countryData( const QString& code );
/// @brief Get a likely locale for a 2-letter country code /// @brief Get a likely locale for a 2-letter country code
DLLEXPORT QLocale countryLocale( const QString& code ); DLLEXPORT QLocale countryLocale( const QString& code );
}
} // namespace } // namespace
#endif #endif

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> === /* === This file is part of Calamares - <https://github.com/calamares> ===
* *
* Copyright 2019, Collabora Ltd <arnaud.ferraris@collabora.com> * Copyright 2019, Collabora Ltd <arnaud.ferraris@collabora.com>
* Copyright 2019, Adriaan de Groot <groot@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
@ -20,7 +21,9 @@
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Units.h" #include "utils/Units.h"
namespace Calamares namespace CalamaresUtils
{
namespace Partition
{ {
static const NamedEnumTable<SizeUnit>& static const NamedEnumTable<SizeUnit>&
@ -42,23 +45,23 @@ unitSuffixes()
PartitionSize::PartitionSize( const QString& s ) PartitionSize::PartitionSize( const QString& s )
: NamedSuffix( unitSuffixes(), s ) : NamedSuffix( unitSuffixes(), s )
{ {
if ( ( unit() == unit_t::Percent ) && ( value() > 100 || value() < 0 ) ) if ( ( unit() == SizeUnit::Percent ) && ( value() > 100 || value() < 0 ) )
{ {
cDebug() << "Percent value" << value() << "is not valid."; cDebug() << "Percent value" << value() << "is not valid.";
m_value = 0; m_value = 0;
} }
if ( m_unit == unit_t::None ) if ( m_unit == SizeUnit::None )
{ {
m_value = s.toInt(); m_value = s.toInt();
if ( m_value > 0 ) if ( m_value > 0 )
m_unit = unit_t::Byte; m_unit = SizeUnit::Byte;
} }
if ( m_value <= 0 ) if ( m_value <= 0 )
{ {
m_value = 0; m_value = 0;
m_unit = unit_t::None; m_unit = SizeUnit::None;
} }
} }
@ -72,17 +75,17 @@ PartitionSize::toSectors( qint64 totalSectors, qint64 sectorSize ) const
switch ( m_unit ) switch ( m_unit )
{ {
case unit_t::None: case SizeUnit::None:
return -1; return -1;
case unit_t::Percent: case SizeUnit::Percent:
if ( value() == 100 ) if ( value() == 100 )
return totalSectors; // Common-case, avoid futzing around return totalSectors; // Common-case, avoid futzing around
else else
return totalSectors * value() / 100; return totalSectors * value() / 100;
case unit_t::Byte: case SizeUnit::Byte:
case unit_t::KiB: case SizeUnit::KiB:
case unit_t::MiB: case SizeUnit::MiB:
case unit_t::GiB: case SizeUnit::GiB:
return CalamaresUtils::bytesToSectors ( toBytes(), sectorSize ); return CalamaresUtils::bytesToSectors ( toBytes(), sectorSize );
} }
@ -97,19 +100,19 @@ PartitionSize::toBytes( qint64 totalSectors, qint64 sectorSize ) const
switch ( m_unit ) switch ( m_unit )
{ {
case unit_t::None: case SizeUnit::None:
return -1; return -1;
case unit_t::Percent: case SizeUnit::Percent:
if ( totalSectors < 1 || sectorSize < 1 ) if ( totalSectors < 1 || sectorSize < 1 )
return -1; return -1;
if ( value() == 100 ) if ( value() == 100 )
return totalSectors * sectorSize; // Common-case, avoid futzing around return totalSectors * sectorSize; // Common-case, avoid futzing around
else else
return totalSectors * value() / 100; return totalSectors * value() / 100;
case unit_t::Byte: case SizeUnit::Byte:
case unit_t::KiB: case SizeUnit::KiB:
case unit_t::MiB: case SizeUnit::MiB:
case unit_t::GiB: case SizeUnit::GiB:
return toBytes(); return toBytes();
} }
@ -125,19 +128,19 @@ PartitionSize::toBytes( qint64 totalBytes ) const
switch ( m_unit ) switch ( m_unit )
{ {
case unit_t::None: case SizeUnit::None:
return -1; return -1;
case unit_t::Percent: case SizeUnit::Percent:
if ( totalBytes < 1 ) if ( totalBytes < 1 )
return -1; return -1;
if ( value() == 100 ) if ( value() == 100 )
return totalBytes; // Common-case, avoid futzing around return totalBytes; // Common-case, avoid futzing around
else else
return totalBytes * value() / 100; return totalBytes * value() / 100;
case unit_t::Byte: case SizeUnit::Byte:
case unit_t::KiB: case SizeUnit::KiB:
case unit_t::MiB: case SizeUnit::MiB:
case unit_t::GiB: case SizeUnit::GiB:
return toBytes(); return toBytes();
} }
@ -153,86 +156,83 @@ PartitionSize::toBytes() const
switch ( m_unit ) switch ( m_unit )
{ {
case unit_t::Byte: case SizeUnit::None:
case SizeUnit::Percent:
return -1;
case SizeUnit::Byte:
return value(); return value();
case unit_t::KiB: case SizeUnit::KiB:
return CalamaresUtils::KiBtoBytes( static_cast<unsigned long long>( value() ) ); return CalamaresUtils::KiBtoBytes( static_cast<unsigned long long>( value() ) );
case unit_t::MiB: case SizeUnit::MiB:
return CalamaresUtils::MiBtoBytes( static_cast<unsigned long long>( value() ) ); return CalamaresUtils::MiBtoBytes( static_cast<unsigned long long>( value() ) );
case unit_t::GiB: case SizeUnit::GiB:
return CalamaresUtils::GiBtoBytes( static_cast<unsigned long long>( value() ) ); return CalamaresUtils::GiBtoBytes( static_cast<unsigned long long>( value() ) );
default:
break;
} }
NOTREACHED return -1;
// Reached only when unit is Percent or None
return -1;
} }
bool bool
PartitionSize::operator< ( const PartitionSize& other ) const PartitionSize::operator< ( const PartitionSize& other ) const
{ {
if ( ( m_unit == unit_t::None || other.m_unit == unit_t::None ) || if ( !unitsComparable( m_unit, other.m_unit ) )
( m_unit == unit_t::Percent && other.m_unit != unit_t::Percent ) ||
( m_unit != unit_t::Percent && other.m_unit == unit_t::Percent ) )
return false; return false;
switch ( m_unit ) switch ( m_unit )
{ {
case unit_t::Percent: case SizeUnit::None:
return false;
case SizeUnit::Percent:
return ( m_value < other.m_value ); return ( m_value < other.m_value );
case unit_t::Byte: case SizeUnit::Byte:
case unit_t::KiB: case SizeUnit::KiB:
case unit_t::MiB: case SizeUnit::MiB:
case unit_t::GiB: case SizeUnit::GiB:
return ( toBytes() < other.toBytes () ); return ( toBytes() < other.toBytes () );
} }
NOTREACHED return false;
return false;
} }
bool bool
PartitionSize::operator> ( const PartitionSize& other ) const PartitionSize::operator> ( const PartitionSize& other ) const
{ {
if ( ( m_unit == unit_t::None || other.m_unit == unit_t::None ) || if ( !unitsComparable( m_unit, other.m_unit ) )
( m_unit == unit_t::Percent && other.m_unit != unit_t::Percent ) ||
( m_unit != unit_t::Percent && other.m_unit == unit_t::Percent ) )
return false; return false;
switch ( m_unit ) switch ( m_unit )
{ {
case unit_t::Percent: case SizeUnit::None:
return false;
case SizeUnit::Percent:
return ( m_value > other.m_value ); return ( m_value > other.m_value );
case unit_t::Byte: case SizeUnit::Byte:
case unit_t::KiB: case SizeUnit::KiB:
case unit_t::MiB: case SizeUnit::MiB:
case unit_t::GiB: case SizeUnit::GiB:
return ( toBytes() > other.toBytes () ); return ( toBytes() > other.toBytes () );
} }
NOTREACHED return false;
return false;
} }
bool bool
PartitionSize::operator== ( const PartitionSize& other ) const PartitionSize::operator== ( const PartitionSize& other ) const
{ {
if ( ( m_unit == unit_t::None || other.m_unit == unit_t::None ) || if ( !unitsComparable( m_unit, other.m_unit ) )
( m_unit == unit_t::Percent && other.m_unit != unit_t::Percent ) ||
( m_unit != unit_t::Percent && other.m_unit == unit_t::Percent ) )
return false; return false;
switch ( m_unit ) switch ( m_unit )
{ {
case unit_t::Percent: case SizeUnit::None:
return false;
case SizeUnit::Percent:
return ( m_value == other.m_value ); return ( m_value == other.m_value );
case unit_t::Byte: case SizeUnit::Byte:
case unit_t::KiB: case SizeUnit::KiB:
case unit_t::MiB: case SizeUnit::MiB:
case unit_t::GiB: case SizeUnit::GiB:
return ( toBytes() == other.toBytes () ); return ( toBytes() == other.toBytes () );
} }
NOTREACHED return false;
return false;
} }
} // namespace Calamares }
} // namespace

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> === /* === This file is part of Calamares - <https://github.com/calamares> ===
* *
* Copyright 2019, Collabora Ltd <arnaud.ferraris@collabora.com> * Copyright 2019, Collabora Ltd <arnaud.ferraris@collabora.com>
* Copyright 2019, Adriaan de Groot <groot@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
@ -25,7 +26,9 @@
// Qt // Qt
#include <QString> #include <QString>
namespace Calamares namespace CalamaresUtils
{
namespace Partition
{ {
enum class SizeUnit enum class SizeUnit
@ -48,7 +51,7 @@ class PartitionSize : public NamedSuffix<SizeUnit, SizeUnit::None>
{ {
public: public:
PartitionSize() : NamedSuffix() { } PartitionSize() : NamedSuffix() { }
PartitionSize( int v, unit_t u ) : NamedSuffix( v, u ) { } PartitionSize( int v, SizeUnit u ) : NamedSuffix( v, u ) { }
PartitionSize( const QString& ); PartitionSize( const QString& );
bool isValid() const bool isValid() const
@ -91,13 +94,29 @@ public:
/** @brief Convert the size to bytes. /** @brief Convert the size to bytes.
* *
* This method is only valid for sizes in Bytes, KiB, MiB or GiB. * This method is only valid for sizes in Bytes, KiB, MiB or GiB.
* It will return -1 in any other case. * It will return -1 in any other case. Note that 0KiB and 0MiB and
* 0GiB are considered **invalid** sizes and return -1.
* *
* @return the size in bytes, or -1 if it cannot be calculated. * @return the size in bytes, or -1 if it cannot be calculated.
*/ */
qint64 toBytes() const; qint64 toBytes() const;
/** @brief Are the units comparable?
*
* None units cannot be compared with anything. Percentages can
* be compared with each other, and all the explicit sizes (KiB, ...)
* can be compared with each other.
*/
static constexpr bool unitsComparable( const SizeUnit u1, const SizeUnit u2 )
{
return !( ( u1 == SizeUnit::None || u2 == SizeUnit::None ) ||
( u1 == SizeUnit::Percent && u2 != SizeUnit::Percent ) ||
( u1 != SizeUnit::Percent && u2 == SizeUnit::Percent ) );
}
}; };
} // namespace Calamares }
} // namespace
#endif // PARTITION_PARTITIONSIZE_H #endif // PARTITION_PARTITIONSIZE_H

View File

@ -0,0 +1,144 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2019, 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 "Tests.h"
#include "PartitionSize.h"
using SizeUnit = CalamaresUtils::Partition::SizeUnit;
using PartitionSize = CalamaresUtils::Partition::PartitionSize;
Q_DECLARE_METATYPE( SizeUnit )
#include "utils/Logger.h"
#include <QtTest/QtTest>
QTEST_GUILESS_MAIN( PartitionSizeTests )
PartitionSizeTests::PartitionSizeTests()
{
}
PartitionSizeTests::~PartitionSizeTests()
{
}
void
PartitionSizeTests::initTestCase()
{
}
void
PartitionSizeTests::testUnitComparison_data()
{
QTest::addColumn<SizeUnit>("u1");
QTest::addColumn<SizeUnit>("u2");
QTest::addColumn<bool>("comparable");
QTest::newRow("nones") << SizeUnit::None << SizeUnit::None << false;
QTest::newRow("none+%") << SizeUnit::None << SizeUnit::Percent<< false;
QTest::newRow("%+none") << SizeUnit::Percent << SizeUnit::None << false;
QTest::newRow("KiB+none") << SizeUnit::KiB << SizeUnit::None << false;
QTest::newRow("none+MiB") << SizeUnit::None << SizeUnit::MiB << false;
QTest::newRow("KiB+KiB") << SizeUnit::KiB << SizeUnit::KiB << true;
QTest::newRow("KiB+MiB") << SizeUnit::KiB << SizeUnit::MiB << true;
QTest::newRow("KiB+GiB") << SizeUnit::KiB << SizeUnit::GiB << true;
QTest::newRow("MiB+MiB") << SizeUnit::MiB << SizeUnit::MiB << true;
QTest::newRow("MiB+GiB") << SizeUnit::MiB << SizeUnit::GiB << true;
QTest::newRow("GiB+GiB") << SizeUnit::GiB << SizeUnit::GiB << true;
QTest::newRow("%+None") << SizeUnit::Percent << SizeUnit::None << false;
QTest::newRow("%+%") << SizeUnit::Percent << SizeUnit::Percent << true;
QTest::newRow("%+KiB") << SizeUnit::Percent << SizeUnit::KiB << false;
}
static bool
original_compare( SizeUnit m_unit, SizeUnit other_m_unit )
{
if ( ( m_unit == SizeUnit::None || other_m_unit == SizeUnit::None ) ||
( m_unit == SizeUnit::Percent && other_m_unit != SizeUnit::Percent ) ||
( m_unit != SizeUnit::Percent && other_m_unit == SizeUnit::Percent ) )
return false;
return true;
}
void
PartitionSizeTests::testUnitComparison()
{
QFETCH( SizeUnit, u1 );
QFETCH( SizeUnit, u2 );
QFETCH( bool, comparable );
if ( comparable )
{
QVERIFY( PartitionSize::unitsComparable( u1, u2 ) );
QVERIFY( PartitionSize::unitsComparable( u2, u1 ) );
}
else
{
QVERIFY( !PartitionSize::unitsComparable( u1, u2 ) );
QVERIFY( !PartitionSize::unitsComparable( u2, u1 ) );
}
QCOMPARE( original_compare( u1, u2 ), PartitionSize::unitsComparable( u1, u2 ) );
}
void
PartitionSizeTests::testUnitNormalisation_data()
{
QTest::addColumn<SizeUnit>("u1");
QTest::addColumn<int>("v");
QTest::addColumn<long>("bytes");
QTest::newRow("none") << SizeUnit::None << 16 << -1L;
QTest::newRow("none") << SizeUnit::None << 0 << -1L;
QTest::newRow("none") << SizeUnit::None << -2 << -1L;
QTest::newRow("percent") << SizeUnit::Percent << 0 << -1L;
QTest::newRow("percent") << SizeUnit::Percent << 16 << -1L;
QTest::newRow("percent") << SizeUnit::Percent << -2 << -1L;
QTest::newRow("KiB") << SizeUnit::KiB << 0 << -1L;
QTest::newRow("KiB") << SizeUnit::KiB << 1 << 1024L;
QTest::newRow("KiB") << SizeUnit::KiB << 1000 << 1024000L;
QTest::newRow("KiB") << SizeUnit::KiB << 1024 << 1024 * 1024L;
QTest::newRow("KiB") << SizeUnit::KiB << -2 << -1L;
QTest::newRow("MiB") << SizeUnit::MiB << 0 << -1L;
QTest::newRow("MiB") << SizeUnit::MiB << 1 << 1024 * 1024L;
QTest::newRow("MiB") << SizeUnit::MiB << 1000 << 1024 * 1024000L;
QTest::newRow("MiB") << SizeUnit::MiB << 1024 << 1024 * 1024 * 1024L;
QTest::newRow("MiB") << SizeUnit::MiB << -2 << -1L;
QTest::newRow("GiB") << SizeUnit::GiB << 0 << -1L;
QTest::newRow("GiB") << SizeUnit::GiB << 1 << 1024 * 1024 * 1024L;
QTest::newRow("GiB") << SizeUnit::GiB << 2 << 2048 * 1024 * 1024L;
}
void
PartitionSizeTests::testUnitNormalisation()
{
QFETCH( SizeUnit, u1 );
QFETCH( int, v );
QFETCH( long, bytes );
QCOMPARE( PartitionSize( v, u1 ).toBytes(), static_cast<qint64>( bytes ) );
}

View File

@ -0,0 +1,41 @@
/* === This file is part of Calamares - <https://github.com/calamares> ===
*
* Copyright 2019, 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/>.
*/
#ifndef LIBCALAMARES_PARTITION_TESTS_H
#define LIBCALAMARES_PARTITION_TESTS_H
#include <QObject>
class PartitionSizeTests : public QObject
{
Q_OBJECT
public:
PartitionSizeTests();
~PartitionSizeTests() override;
private Q_SLOTS:
void initTestCase();
void testUnitComparison_data();
void testUnitComparison();
void testUnitNormalisation_data();
void testUnitNormalisation();
};
#endif

View File

@ -227,10 +227,18 @@ ViewManager::currentStepIndex() const
return m_currentStep; return m_currentStep;
} }
/** @brief Is the given step at @p index an execution step?
*
* Returns true if the step is an execution step, false otherwise.
* Also returns false if the @p index is out of range.
*/
static inline bool static inline bool
stepNextWillExecute(const ViewStepList& steps, int index) stepIsExecute( const ViewStepList& steps, int index )
{ {
return ( index + 1 < steps.count() ) && qobject_cast< ExecutionViewStep* >( steps.at( index + 1 ) ); return
( 0 <= index ) &&
( index < steps.count() ) &&
( qobject_cast< ExecutionViewStep* >( steps.at( index ) ) != nullptr );
} }
void void
@ -245,7 +253,7 @@ ViewManager::next()
// Special case when the user clicks next on the very last page in a view phase // Special case when the user clicks next on the very last page in a view phase
// and right before switching to an execution phase. // and right before switching to an execution phase.
// Depending on Calamares::Settings, we show an "are you sure" prompt or not. // Depending on Calamares::Settings, we show an "are you sure" prompt or not.
if ( settings->showPromptBeforeExecution() && stepNextWillExecute( m_steps, m_currentStep ) ) if ( settings->showPromptBeforeExecution() && stepIsExecute( m_steps, m_currentStep+1 ) )
{ {
QString title = settings->isSetupMode() QString title = settings->isSetupMode()
? tr( "Continue with setup?" ) ? tr( "Continue with setup?" )
@ -280,16 +288,7 @@ ViewManager::next()
m_steps.at( m_currentStep )->onActivate(); m_steps.at( m_currentStep )->onActivate();
executing = qobject_cast< ExecutionViewStep* >( m_steps.at( m_currentStep ) ) != nullptr; executing = qobject_cast< ExecutionViewStep* >( m_steps.at( m_currentStep ) ) != nullptr;
emit currentStepChanged(); emit currentStepChanged();
if ( executing ) updateCancelEnabled( !settings->disableCancel() && !(executing && settings->disableCancelDuringExec() ) );
{
m_back->setEnabled( false );
m_next->setEnabled( false );
// Enabled if there's nothing blocking it during exec
m_quit->setEnabled( !( settings->dontCancel() || settings->disableCancel() ) );
}
else
// Enabled unless it's also hidden
m_quit->setEnabled( !settings->disableCancel() );
} }
else else
step->next(); step->next();
@ -303,17 +302,20 @@ ViewManager::next()
void void
ViewManager::updateButtonLabels() ViewManager::updateButtonLabels()
{ {
QString next = Calamares::Settings::instance()->isSetupMode() const auto* const settings = Calamares::Settings::instance();
QString next = settings->isSetupMode()
? tr( "&Set up" ) ? tr( "&Set up" )
: tr( "&Install" ); : tr( "&Install" );
QString complete = Calamares::Settings::instance()->isSetupMode() QString complete = settings->isSetupMode()
? tr( "Setup is complete. Close the setup program." ) ? tr( "Setup is complete. Close the setup program." )
: tr( "The installation is complete. Close the installer." ); : tr( "The installation is complete. Close the installer." );
QString quit = Calamares::Settings::instance()->isSetupMode() QString quit = settings->isSetupMode()
? tr( "Cancel setup without changing the system." ) ? tr( "Cancel setup without changing the system." )
: tr( "Cancel installation without changing the system." ); : tr( "Cancel installation without changing the system." );
if ( stepNextWillExecute( m_steps, m_currentStep ) ) // If we're going into the execution step / install phase, other message
if ( stepIsExecute( m_steps, m_currentStep+1 ) )
m_next->setText( next ); m_next->setText( next );
else else
m_next->setText( tr( "&Next" ) ); m_next->setText( tr( "&Next" ) );
@ -323,15 +325,14 @@ ViewManager::updateButtonLabels()
m_quit->setText( tr( "&Done" ) ); m_quit->setText( tr( "&Done" ) );
m_quit->setToolTip( complete ); m_quit->setToolTip( complete );
m_quit->setVisible( true ); // At end, always visible and enabled. m_quit->setVisible( true ); // At end, always visible and enabled.
m_quit->setEnabled( true ); updateCancelEnabled( true );
} }
else else
{ {
if ( Calamares::Settings::instance()->disableCancel() ) if ( settings->disableCancel() )
{ m_quit->setVisible( false ); // In case we went back from final
m_quit->setVisible( false ); updateCancelEnabled( !settings->disableCancel() && !( stepIsExecute( m_steps, m_currentStep ) && settings->disableCancelDuringExec() ) );
m_quit->setEnabled( false ); // Can't be triggered through DBUS
}
m_quit->setText( tr( "&Cancel" ) ); m_quit->setText( tr( "&Cancel" ) );
m_quit->setToolTip( quit ); m_quit->setToolTip( quit );
} }
@ -364,14 +365,21 @@ ViewManager::back()
bool ViewManager::confirmCancelInstallation() bool ViewManager::confirmCancelInstallation()
{ {
const auto* const settings = Calamares::Settings::instance();
if ( settings->disableCancel() )
return false;
if ( settings->disableCancelDuringExec() && stepIsExecute( m_steps, m_currentStep ) )
return false;
// If it's NOT the last page of the last step, we ask for confirmation // If it's NOT the last page of the last step, we ask for confirmation
if ( !( m_currentStep == m_steps.count() -1 && if ( !( m_currentStep == m_steps.count() -1 &&
m_steps.last()->isAtEnd() ) ) m_steps.last()->isAtEnd() ) )
{ {
QString title = Calamares::Settings::instance()->isSetupMode() QString title = settings->isSetupMode()
? tr( "Cancel setup?" ) ? tr( "Cancel setup?" )
: tr( "Cancel installation?" ); : tr( "Cancel installation?" );
QString question = Calamares::Settings::instance()->isSetupMode() QString question = settings->isSetupMode()
? tr( "Do you really want to cancel the current setup process?\n" ? tr( "Do you really want to cancel the current setup process?\n"
"The setup program will quit and all changes will be lost." ) "The setup program will quit and all changes will be lost." )
: tr( "Do you really want to cancel the current install process?\n" : tr( "Do you really want to cancel the current install process?\n"
@ -391,4 +399,11 @@ bool ViewManager::confirmCancelInstallation()
return true; return true;
} }
void
ViewManager::updateCancelEnabled( bool enabled )
{
m_quit->setEnabled( enabled );
emit cancelEnabled( enabled );
}
} // namespace } // namespace

View File

@ -121,6 +121,7 @@ public slots:
signals: signals:
void currentStepChanged(); void currentStepChanged();
void enlarge( QSize enlarge ) const; // See ViewStep::enlarge() void enlarge( QSize enlarge ) const; // See ViewStep::enlarge()
void cancelEnabled( bool enabled ) const;
private: private:
explicit ViewManager( QObject* parent = nullptr ); explicit ViewManager( QObject* parent = nullptr );
@ -128,7 +129,8 @@ private:
void insertViewStep( int before, ViewStep* step ); void insertViewStep( int before, ViewStep* step );
void updateButtonLabels(); void updateButtonLabels();
void updateCancelEnabled( bool enabled );
static ViewManager* s_instance; static ViewManager* s_instance;
ViewStepList m_steps; ViewStepList m_steps;

View File

@ -358,7 +358,8 @@ ModuleManager::checkDependencies()
somethingWasRemovedBecauseOfUnmetDependencies = true; somethingWasRemovedBecauseOfUnmetDependencies = true;
m_availableDescriptorsByModuleName.erase( it ); m_availableDescriptorsByModuleName.erase( it );
failed << moduleName; failed << moduleName;
cWarning() << "Module" << moduleName << "has unknown requirements" << Logger::DebugList( unmet ); cWarning() << "Module" << moduleName << "requires modules" << Logger::DebugList( unmet );
cWarning() << Logger::SubEntry << "but these are not available (listed in settings, or installed).";
break; break;
} }
} }

View File

@ -7,7 +7,7 @@
# Copyright 2014, Anke Boersma <demm@kaosx.us> # Copyright 2014, Anke Boersma <demm@kaosx.us>
# Copyright 2014, Daniel Hillenbrand <codeworkx@bbqlinux.org> # Copyright 2014, Daniel Hillenbrand <codeworkx@bbqlinux.org>
# Copyright 2014, Benjamin Vaudour <benjamin.vaudour@yahoo.fr> # Copyright 2014, Benjamin Vaudour <benjamin.vaudour@yahoo.fr>
# Copyright 2014, Kevin Kofler <kevin.kofler@chello.at> # Copyright 2014-2019, Kevin Kofler <kevin.kofler@chello.at>
# Copyright 2015-2018, Philip Mueller <philm@manjaro.org> # Copyright 2015-2018, Philip Mueller <philm@manjaro.org>
# Copyright 2016-2017, Teo Mrnjavac <teo@kde.org> # Copyright 2016-2017, Teo Mrnjavac <teo@kde.org>
# Copyright 2017, Alf Gaida <agaida@siduction.org> # Copyright 2017, Alf Gaida <agaida@siduction.org>
@ -339,8 +339,8 @@ def install_grub(efi_directory, fw_type):
"--force", "--force",
boot_loader["installPath"]]) boot_loader["installPath"]])
# The file specified in grubCfg should already be filled out # The input file /etc/default/grub should already be filled out by the
# by the grubcfg job module. # grubcfg job module.
check_target_env_call([libcalamares.job.configuration["grubMkconfig"], check_target_env_call([libcalamares.job.configuration["grubMkconfig"],
"-o", libcalamares.job.configuration["grubCfg"]]) "-o", libcalamares.job.configuration["grubCfg"]])
@ -395,6 +395,12 @@ def install_secureboot(efi_directory):
"-p", efi_partition_number, "-p", efi_partition_number,
"-l", install_efi_directory + "/" + install_efi_bin]) "-l", install_efi_directory + "/" + install_efi_bin])
# The input file /etc/default/grub should already be filled out by the
# grubcfg job module.
check_target_env_call([libcalamares.job.configuration["grubMkconfig"],
"-o", os.path.join(efi_directory, "EFI",
efi_bootloader_id, "grub.cfg")])
def vfat_correct_case(parent, name): def vfat_correct_case(parent, name):
for candidate in os.listdir(parent): for candidate in os.listdir(parent):

View File

@ -272,8 +272,8 @@ ResizeFSJob::setConfigurationMap( const QVariantMap& configurationMap )
return; return;
} }
m_size = Calamares::PartitionSize( configurationMap["size"].toString() ); m_size = PartitionSize( configurationMap["size"].toString() );
m_atleast = Calamares::PartitionSize( configurationMap["atleast"].toString() ); m_atleast = PartitionSize( configurationMap["atleast"].toString() );
m_required = CalamaresUtils::getBool( configurationMap, "required", false ); m_required = CalamaresUtils::getBool( configurationMap, "required", false );
} }

View File

@ -33,6 +33,8 @@ class CoreBackend; // From KPMCore
class Device; // From KPMCore class Device; // From KPMCore
class Partition; class Partition;
using PartitionSize = CalamaresUtils::Partition::PartitionSize;
class PLUGINDLLEXPORT ResizeFSJob : public Calamares::CppJob class PLUGINDLLEXPORT ResizeFSJob : public Calamares::CppJob
{ {
Q_OBJECT Q_OBJECT
@ -54,9 +56,24 @@ public:
m_size.isValid(); m_size.isValid();
} }
QString name() const
{
return m_fsname.isEmpty() ? m_devicename : m_fsname;
}
PartitionSize size() const
{
return m_size;
}
PartitionSize minimumSize() const
{
return m_atleast;
}
private: private:
Calamares::PartitionSize m_size; PartitionSize m_size;
Calamares::PartitionSize m_atleast; PartitionSize m_atleast;
QString m_fsname; // Either this, or devicename, is set, not both QString m_fsname; // Either this, or devicename, is set, not both
QString m_devicename; QString m_devicename;
bool m_required; bool m_required;

View File

@ -18,6 +18,8 @@
#include "Tests.h" #include "Tests.h"
#include "ResizeFSJob.h"
#include "GlobalStorage.h" #include "GlobalStorage.h"
#include "JobQueue.h" #include "JobQueue.h"
#include "Settings.h" #include "Settings.h"
@ -30,9 +32,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <QStringList> #include <QStringList>
#define private public using SizeUnit = CalamaresUtils::Partition::SizeUnit;
#include "ResizeFSJob.h"
#undef private
QTEST_GUILESS_MAIN( FSResizerTests ) QTEST_GUILESS_MAIN( FSResizerTests )
@ -55,10 +55,9 @@ void FSResizerTests::testConfigurationRobust()
// Empty config // Empty config
j.setConfigurationMap( QVariantMap() ); j.setConfigurationMap( QVariantMap() );
QVERIFY( j.m_fsname.isEmpty() ); QVERIFY( j.name().isEmpty() );
QVERIFY( j.m_devicename.isEmpty() ); QCOMPARE( j.size().unit(), SizeUnit::None );
QCOMPARE( j.m_size.unit(), Calamares::SizeUnit::None ); QCOMPARE( j.minimumSize().unit(), SizeUnit::None );
QCOMPARE( j.m_atleast.unit(), Calamares::SizeUnit::None );
// Config is missing fs and dev, so it isn't valid // Config is missing fs and dev, so it isn't valid
YAML::Node doc0 = YAML::Load( R"(--- YAML::Node doc0 = YAML::Load( R"(---
@ -66,12 +65,11 @@ size: 100%
atleast: 600MiB atleast: 600MiB
)" ); )" );
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() ); j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
QVERIFY( j.m_fsname.isEmpty() ); QVERIFY( j.name().isEmpty() );
QVERIFY( j.m_devicename.isEmpty() ); QCOMPARE( j.size().unit(), SizeUnit::None );
QCOMPARE( j.m_size.unit(), Calamares::SizeUnit::None ); QCOMPARE( j.minimumSize().unit(), SizeUnit::None );
QCOMPARE( j.m_atleast.unit(), Calamares::SizeUnit::None ); QCOMPARE( j.size().value(), 0 );
QCOMPARE( j.m_size.value(), 0 ); QCOMPARE( j.minimumSize().value(), 0 );
QCOMPARE( j.m_atleast.value(), 0 );
} }
void FSResizerTests::testConfigurationValues() void FSResizerTests::testConfigurationValues()
@ -85,12 +83,11 @@ size: 100%
atleast: 600MiB atleast: 600MiB
)" ); )" );
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() ); j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
QVERIFY( !j.m_fsname.isEmpty() ); QVERIFY( j.name().isEmpty() );
QVERIFY( j.m_devicename.isEmpty() ); QCOMPARE( j.size().unit(), SizeUnit::Percent );
QCOMPARE( j.m_size.unit(), Calamares::SizeUnit::Percent ); QCOMPARE( j.minimumSize().unit(), SizeUnit::MiB );
QCOMPARE( j.m_atleast.unit(), Calamares::SizeUnit::MiB ); QCOMPARE( j.size().value(), 100 );
QCOMPARE( j.m_size.value(), 100 ); QCOMPARE( j.minimumSize().value(), 600 );
QCOMPARE( j.m_atleast.value(), 600 );
// Silly config // Silly config
doc0 = YAML::Load( R"(--- doc0 = YAML::Load( R"(---
@ -100,12 +97,11 @@ size: 72 MiB
atleast: 127 % atleast: 127 %
)" ); )" );
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() ); j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
QVERIFY( !j.m_fsname.isEmpty() ); QVERIFY( !j.name().isEmpty() );
QVERIFY( !j.m_devicename.isEmpty() ); QCOMPARE( j.size().unit(), SizeUnit::MiB );
QCOMPARE( j.m_size.unit(), Calamares::SizeUnit::MiB ); QCOMPARE( j.minimumSize().unit(), SizeUnit::None );
QCOMPARE( j.m_atleast.unit(), Calamares::SizeUnit::None ); QCOMPARE( j.size().value(), 72 );
QCOMPARE( j.m_size.value(), 72 ); QCOMPARE( j.minimumSize().value(), 0 );
QCOMPARE( j.m_atleast.value(), 0 );
// Silly config // Silly config
doc0 = YAML::Load( R"(--- doc0 = YAML::Load( R"(---
@ -115,10 +111,9 @@ size: 71MiB
# atleast: 127% # atleast: 127%
)" ); )" );
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() ); j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
QVERIFY( !j.m_fsname.isEmpty() ); QVERIFY( j.name().isEmpty() );
QVERIFY( j.m_devicename.isEmpty() ); QCOMPARE( j.size().unit(), SizeUnit::MiB );
QCOMPARE( j.m_size.unit(), Calamares::SizeUnit::MiB ); QCOMPARE( j.minimumSize().unit(), SizeUnit::None );
QCOMPARE( j.m_atleast.unit(), Calamares::SizeUnit::None ); QCOMPARE( j.size().value(), 71 );
QCOMPARE( j.m_size.value(), 71 ); QCOMPARE( j.minimumSize().value(), 0 );
QCOMPARE( j.m_atleast.value(), 0 );
} }

View File

@ -43,9 +43,15 @@ public:
) )
} }
virtual ~OEMPage() override;
Ui_OEMPage* m_ui; Ui_OEMPage* m_ui;
} ; } ;
OEMPage::~OEMPage()
{
}
OEMViewStep::OEMViewStep(QObject* parent) OEMViewStep::OEMViewStep(QObject* parent)
: Calamares::ViewStep( parent ) : Calamares::ViewStep( parent )

View File

@ -103,7 +103,7 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO
{ {
if ( gs->contains( "efiSystemPartitionSize" ) ) if ( gs->contains( "efiSystemPartitionSize" ) )
{ {
Calamares::PartitionSize part_size = Calamares::PartitionSize( CalamaresUtils::Partition::PartitionSize part_size = CalamaresUtils::Partition::PartitionSize(
gs->value( "efiSystemPartitionSize" ).toString() ); gs->value( "efiSystemPartitionSize" ).toString() );
uefisys_part_sizeB = part_size.toBytes( dev->capacity() ); uefisys_part_sizeB = part_size.toBytes( dev->capacity() );
} }

View File

@ -86,10 +86,10 @@ PartitionLayout::addEntry( PartitionLayout::PartitionEntry entry )
} }
PartitionLayout::PartitionEntry::PartitionEntry( const QString& size, const QString& min, const QString& max ) PartitionLayout::PartitionEntry::PartitionEntry( const QString& size, const QString& min, const QString& max )
: partSize( size )
, partMinSize( min )
, partMaxSize( max )
{ {
partSize = Calamares::PartitionSize( size );
partMinSize = Calamares::PartitionSize( min );
partMaxSize = Calamares::PartitionSize( max );
} }
bool bool
@ -150,7 +150,7 @@ PartitionLayout::execute( Device *dev, qint64 firstSector,
const PartitionRole& role ) const PartitionRole& role )
{ {
QList< Partition* > partList; QList< Partition* > partList;
qint64 size, minSize, maxSize, end; qint64 minSize, maxSize, end;
qint64 totalSize = lastSector - firstSector + 1; qint64 totalSize = lastSector - firstSector + 1;
qint64 availableSize = totalSize; qint64 availableSize = totalSize;
@ -161,6 +161,7 @@ PartitionLayout::execute( Device *dev, qint64 firstSector,
{ {
Partition *currentPartition = nullptr; Partition *currentPartition = nullptr;
qint64 size = -1;
// Calculate partition size // Calculate partition size
if ( part.partSize.isValid() ) if ( part.partSize.isValid() )
{ {

View File

@ -43,9 +43,9 @@ public:
QString partLabel; QString partLabel;
QString partMountPoint; QString partMountPoint;
FileSystem::Type partFileSystem = FileSystem::Unknown; FileSystem::Type partFileSystem = FileSystem::Unknown;
Calamares::PartitionSize partSize; CalamaresUtils::Partition::PartitionSize partSize;
Calamares::PartitionSize partMinSize; CalamaresUtils::Partition::PartitionSize partMinSize;
Calamares::PartitionSize partMaxSize; CalamaresUtils::Partition::PartitionSize partMaxSize;
/// @brief All-zeroes PartitionEntry /// @brief All-zeroes PartitionEntry
PartitionEntry() {} PartitionEntry() {}

View File

@ -564,7 +564,7 @@ PartitionPage::updateFromCurrentDevice()
QAbstractItemModel* oldModel = m_ui->partitionTreeView->model(); QAbstractItemModel* oldModel = m_ui->partitionTreeView->model();
if ( oldModel ) if ( oldModel )
disconnect( oldModel, 0, this, 0 ); disconnect( oldModel, nullptr, this, nullptr );
PartitionModel* model = m_core->partitionModelForDevice( device ); PartitionModel* model = m_core->partitionModelForDevice( device );
m_ui->partitionBarsView->setModel( model ); m_ui->partitionBarsView->setModel( model );

View File

@ -44,7 +44,7 @@ ResizeVolumeGroupDialog::ResizeVolumeGroupDialog( LvmDevice *device,
for ( const Partition* p : availablePVs ) for ( const Partition* p : availablePVs )
pvList()->addItem( new ListPhysicalVolumeWidgetItem( p, false ) ); pvList()->addItem( new ListPhysicalVolumeWidgetItem( p, false ) );
peSize()->setValue( device->peSize() / Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::MiB) ); peSize()->setValue( static_cast<int>( device->peSize() / Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::MiB) ) );
vgName()->setEnabled( false ); vgName()->setEnabled( false );
peSize()->setEnabled( false ); peSize()->setEnabled( false );

View File

@ -137,9 +137,9 @@ VolumeGroupBaseDialog::updateTotalSize()
void void
VolumeGroupBaseDialog::updateTotalSectors() VolumeGroupBaseDialog::updateTotalSectors()
{ {
qint32 totalSectors = 0; qint64 totalSectors = 0;
qint32 extentSize = ui->peSize->value() * Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::MiB); qint64 extentSize = ui->peSize->value() * Capacity::unitFactor(Capacity::Unit::Byte, Capacity::Unit::MiB);
if ( extentSize > 0 ) if ( extentSize > 0 )
totalSectors = m_totalSizeValue / extentSize; totalSectors = m_totalSizeValue / extentSize;

View File

@ -68,7 +68,7 @@ CreatePartitionTableJob::prettyStatusMessage() const
static inline QDebug& static inline QDebug&
operator <<( QDebug& s, PartitionIterator& it ) operator <<( QDebug&& s, PartitionIterator& it )
{ {
s << ( ( *it ) ? ( *it )->deviceNode() : QString( "<null device>" ) ); s << ( ( *it ) ? ( *it )->deviceNode() : QString( "<null device>" ) );
return s; return s;
@ -89,7 +89,7 @@ CreatePartitionTableJob::exec()
{ {
for ( auto it = PartitionIterator::begin( table ); for ( auto it = PartitionIterator::begin( table );
it != PartitionIterator::end( table ); ++it ) it != PartitionIterator::end( table ); ++it )
cDebug() << *it; cDebug() << it;
QProcess lsblk; QProcess lsblk;
lsblk.setProgram( "lsblk" ); lsblk.setProgram( "lsblk" );

View File

@ -30,7 +30,7 @@ efiSystemPartition: "/boot/efi"
# 8.8GiB on disk in the end). # 8.8GiB on disk in the end).
userSwapChoices: userSwapChoices:
- none # Create no swap, use no swap - none # Create no swap, use no swap
- reuse # Re-use existing swap, but don't create any - reuse # Re-use existing swap, but don't create any (unsupported right now)
- small # Up to 4GB - small # Up to 4GB
- suspend # At least main memory size - suspend # At least main memory size
- file # To swap file instead of partition (unsupported right now) - file # To swap file instead of partition (unsupported right now)

View File

@ -78,7 +78,7 @@ static QByteArray
generateTestData( qint64 size ) generateTestData( qint64 size )
{ {
QByteArray ba; QByteArray ba;
ba.resize( size ); ba.resize( static_cast<int>( size ) );
// Fill the array explicitly to keep Valgrind happy // Fill the array explicitly to keep Valgrind happy
for ( auto it = ba.data() ; it < ba.data() + size ; ++it ) for ( auto it = ba.data() ; it < ba.data() + size ; ++it )
{ {
@ -131,6 +131,11 @@ QueueRunner::QueueRunner( JobQueue* queue )
connect( m_queue, &JobQueue::failed, this, &QueueRunner::onFailed ); connect( m_queue, &JobQueue::failed, this, &QueueRunner::onFailed );
} }
QueueRunner::~QueueRunner()
{
// Nothing to do. We don't own the queue, and disconnect happens automatically
}
bool bool
QueueRunner::run() QueueRunner::run()
{ {
@ -168,7 +173,8 @@ PartitionJobTests::initTestCase()
QString devicePath = qgetenv( "CALAMARES_TEST_DISK" ); QString devicePath = qgetenv( "CALAMARES_TEST_DISK" );
if ( devicePath.isEmpty() ) if ( devicePath.isEmpty() )
{ {
QSKIP( "Skipping test, CALAMARES_TEST_DISK is not set. It should point to a disk which can be safely formatted" ); // The 0 is to keep the macro parameters happy
QSKIP( "Skipping test, CALAMARES_TEST_DISK is not set. It should point to a disk which can be safely formatted", 0 );
} }
QVERIFY( KPMHelpers::initKPMcore() ); QVERIFY( KPMHelpers::initKPMcore() );
@ -323,10 +329,10 @@ PartitionJobTests::testCreatePartitionExtended()
void void
PartitionJobTests::testResizePartition_data() PartitionJobTests::testResizePartition_data()
{ {
QTest::addColumn< int >( "oldStartMiB" ); QTest::addColumn< unsigned int >( "oldStartMiB" );
QTest::addColumn< int >( "oldSizeMiB" ); QTest::addColumn< unsigned int >( "oldSizeMiB" );
QTest::addColumn< int >( "newStartMiB" ); QTest::addColumn< unsigned int >( "newStartMiB" );
QTest::addColumn< int >( "newSizeMiB" ); QTest::addColumn< unsigned int >( "newSizeMiB" );
QTest::newRow("grow") << 10 << 50 << 10 << 70; QTest::newRow("grow") << 10 << 50 << 10 << 70;
QTest::newRow("shrink") << 10 << 70 << 10 << 50; QTest::newRow("shrink") << 10 << 70 << 10 << 50;
@ -337,10 +343,10 @@ PartitionJobTests::testResizePartition_data()
void void
PartitionJobTests::testResizePartition() PartitionJobTests::testResizePartition()
{ {
QFETCH( int, oldStartMiB ); QFETCH( unsigned int, oldStartMiB );
QFETCH( int, oldSizeMiB ); QFETCH( unsigned int, oldSizeMiB );
QFETCH( int, newStartMiB ); QFETCH( unsigned int, newStartMiB );
QFETCH( int, newSizeMiB ); QFETCH( unsigned int, newSizeMiB );
const qint64 sectorsPerMiB = 1_MiB / m_device->logicalSize(); const qint64 sectorsPerMiB = 1_MiB / m_device->logicalSize();

View File

@ -36,6 +36,7 @@ class QueueRunner : public QObject
{ {
public: public:
QueueRunner( Calamares::JobQueue* queue ); QueueRunner( Calamares::JobQueue* queue );
virtual ~QueueRunner() override;
/** /**
* Synchronously runs the queue. Returns true on success * Synchronously runs the queue. Returns true on success