Merge branch 'resize-control'

FIXES #1062 #1038
This commit is contained in:
Adriaan de Groot 2019-01-14 15:31:25 +01:00
commit bcce704589
12 changed files with 430 additions and 107 deletions

View File

@ -25,6 +25,9 @@ This release contains contributions from (alphabetically by first name):
Calamares configurations (in particular, distro's can **add**
configuration files and give them priority, instead of **forking**
configuration files).
* The *branding* file now contains settings that control the size
and resize behavior of Calamares. See the branding file for
more documentation.
## Modules ##

View File

@ -8,6 +8,27 @@ componentName: default
# same distribution.
welcomeStyleCalamares: false
# Should the welcome image (productWelcome, below) be scaled
# up beyond its natural size? If false, the image does not grow
# with the window but remains the same size throughout (this
# may have surprising effects on HiDPI monitors).
welcomeExpandingLogo: true
# Size and expansion policy for Calamares.
# - "normal" or unset, expand as needed, use *windowSize*
# - "fullscreen", start as large as possible, ignore *windowSize*
# - "noexpand", don't expand automatically, use *windowSize*
windowExpanding: normal
# Size of Calamares window, expressed as w,h. Both w and h
# may be either pixels (suffix px) or font-units (suffix em).
# e.g. "800px,600px"
# "60em,480px"
# This setting is ignored if "fullscreen" is selected for
# *windowExpanding*, above. If not set, use constants defined
# in CalamaresUtilsGui, 800x520.
windowSize: 800px,520px
# These are strings shown to the user in the user interface.
# There is no provision for translating them -- since they
# are names, the string is included as-is.
@ -32,12 +53,6 @@ strings:
knownIssuesUrl: https://calamares.io/about/
releaseNotesUrl: https://calamares.io/about/
# Should the welcome image (productWelcome, below) be scaled
# up beyond its natural size? If false, the image does not grow
# with the window but remains the same size throughout (this
# may have surprising effects on HiDPI monitors).
welcomeExpandingLogo: true
# These images are loaded from the branding module directory.
#
# productIcon is used as the window icon, and will (usually) be used

View File

@ -348,7 +348,13 @@ void
CalamaresApplication::initViewSteps()
{
cDebug() << "STARTUP: loadModules for all modules done";
m_mainwindow->show();
if ( Calamares::Branding::instance()->windowMaximize() )
{
m_mainwindow->setWindowFlag( Qt::FramelessWindowHint );
m_mainwindow->showMaximized();
}
else
m_mainwindow->show();
ProgressTreeModel* m = new ProgressTreeModel( nullptr );
ProgressTreeView::instance()->setModel( m );
cDebug() << "STARTUP: Window now visible and ProgressTreeView populated";

View File

@ -35,6 +35,18 @@
#include <QLabel>
#include <QTreeView>
static inline int
windowDimensionToPixels( const Calamares::Branding::WindowDimension& u )
{
if ( !u.isValid() )
return 0;
if ( u.unit() == Calamares::Branding::WindowDimensionUnit::Pixies )
return u.value();
if ( u.unit() == Calamares::Branding::WindowDimensionUnit::Fonties )
return u.value() * CalamaresUtils::defaultFontHeight();
return 0;
}
CalamaresWindow::CalamaresWindow( QWidget* parent )
: QWidget( parent )
, m_debugWindow( nullptr )
@ -45,24 +57,24 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
.arg( *Calamares::Branding::ProductName ) );
)
const Calamares::Branding* const branding = Calamares::Branding::instance();
using CalamaresUtils::windowMinimumHeight;
using CalamaresUtils::windowMinimumWidth;
using CalamaresUtils::windowPreferredHeight;
using CalamaresUtils::windowPreferredWidth;
QSize availableSize = qApp->desktop()->availableGeometry( this ).size();
cDebug() << "Available size" << availableSize;
if ( ( availableSize.width() < windowPreferredWidth ) || ( availableSize.height() < windowPreferredHeight ) )
cDebug() << " Small screen detected.";
QSize minimumSize( qBound( windowMinimumWidth, availableSize.width(), windowPreferredWidth ),
qBound( windowMinimumHeight, availableSize.height(), windowPreferredHeight ) );
setMinimumSize( minimumSize );
cDebug() << "Available desktop" << availableSize << "minimum size" << minimumSize;
int w = qBound( minimumSize.width(), CalamaresUtils::defaultFontHeight() * 60, availableSize.width() );
int h = qBound( minimumSize.height(), CalamaresUtils::defaultFontHeight() * 36, availableSize.height() );
auto brandingSizes = branding->windowSize();
int w = qBound( minimumSize.width(), windowDimensionToPixels( brandingSizes.first ), availableSize.width() );
int h = qBound( minimumSize.height(), windowDimensionToPixels( brandingSizes.second ), availableSize.height() );
cDebug() << " Proposed window size:" << w << h;
resize( w, h );
@ -85,18 +97,14 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
{
QPalette plt = sideBox->palette();
sideBox->setAutoFillBackground( true );
plt.setColor( sideBox->backgroundRole(), Calamares::Branding::instance()->
styleString( Calamares::Branding::SidebarBackground ) );
plt.setColor( sideBox->foregroundRole(), Calamares::Branding::instance()->
styleString( Calamares::Branding::SidebarText ) );
plt.setColor( sideBox->backgroundRole(),branding->styleString( Calamares::Branding::SidebarBackground ) );
plt.setColor( sideBox->foregroundRole(), branding->styleString( Calamares::Branding::SidebarText ) );
sideBox->setPalette( plt );
logoLabel->setPalette( plt );
}
logoLabel->setAlignment( Qt::AlignCenter );
logoLabel->setFixedSize( 80, 80 );
logoLabel->setPixmap( Calamares::Branding::instance()->
image( Calamares::Branding::ProductLogo,
logoLabel->size() ) );
logoLabel->setPixmap( branding->image( Calamares::Branding::ProductLogo, logoLabel->size() ) );
logoLayout->addWidget( logoLabel );
logoLayout->addStretch();
@ -139,7 +147,8 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
CalamaresUtils::unmarginLayout( mainLayout );
m_viewManager = Calamares::ViewManager::instance( this );
connect( m_viewManager, &Calamares::ViewManager::enlarge, this, &CalamaresWindow::enlarge );
if ( branding->windowExpands() )
connect( m_viewManager, &Calamares::ViewManager::enlarge, this, &CalamaresWindow::enlarge );
mainLayout->addWidget( m_viewManager->centralWidget() );
}

View File

@ -0,0 +1,110 @@
/* === 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/>.
*/
/** @brief Support for "named" enumerations
*
* For tables which map string names to enum values, provide a NamedEnumTable
* which hangs on to an initializer_list of pairs of names and values.
* This table can be used with find() to map names to values, or
* values to names. A convenience function smash() is provided to help
* in printing integer (underlying) values of an enum.
*/
#ifndef LIBCALAMARES_NAMEDENUM_H
#define LIBCALAMARES_NAMEDENUM_H
#include <QString>
#include <type_traits>
#include <initializer_list>
/** @brief Type for collecting parts of a named enum. */
template<typename T>
struct NamedEnumTable
{
using string_t = QString;
using enum_t = T;
using pair_t = std::pair< string_t, enum_t >;
using type = std::vector< pair_t >;
type table;
/** @brief Create a table of named enum values.
*
* Use braced-initialisation for NamedEnum, and remember that the
* elements of the list are **pairs**, e.g.
*
* static const NamedEnumTable<Colors> c{ {"red", Colors::Red } };
*/
NamedEnumTable( const std::initializer_list< pair_t >& v ) : table( v ) { /* static_assert( v.size() > 0 ); */ };
/** @brief Find a name @p s in the table.
*
* Searches case-insensitively.
*
* If the name @p s is not found, @p ok is set to false and
* the first enum value in the table is returned. Otherwise,
* @p ok is set to true and the corresponding value is returned.
*
*/
enum_t find( const string_t& s, bool& ok ) const
{
ok = false;
for ( const auto p : table )
if ( 0 == QString::compare( s, p.first, Qt::CaseInsensitive ) )
{
ok = true;
return p.second;
}
// ok is still false
return table.begin()->second;
}
/** @brief Find a value @p s in the table.
*
* If the value @p s is not found, @p ok is set to false and
* an empty string is returned. Otherwise, @p is set to true
* and the corresponding name is returned.
*/
string_t find( enum_t s, bool& ok ) const
{
ok = false;
for ( const auto p : table )
if ( s == p.second)
{
ok = true;
return p.first;
}
// ok is still false
return string_t();
}
} ;
/** @brief Smashes an enum value to its underlying type. */
template<typename E>
constexpr typename std::underlying_type<E>::type smash( const E e )
{
return static_cast<typename std::underlying_type<E>::type>( e );
}
#endif

View File

@ -0,0 +1,108 @@
/* === 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/>.
*/
/** @brief Support for unit-suffixed values.
*
* This combines a value with an (enum) unit indicating what kind
* of value it is, e.g. 10 meters, or 64 pixels. Includes simple
* parsing support for the values written as strings like <value><unit>,
* e.g. "10m" or "64px".
*
* When a suffixed unit value needs validation, define an isValid()
* method; similarly for simple construction from a string (with a fixed
* table of suffixes). Typical use then looks like:
*
* class MyUnit : public NamedSuffix<MyUnitEnum, MyUnitEnum::None>
* {
* public:
* using NamedSuffix::NamedSuffix; // Keep existing constructors
* MyUnit( const QString& s );
* bool isValid() const;
* } ;
*/
#ifndef LIBCALAMARES_NAMEDSUFFIX_H
#define LIBCALAMARES_NAMEDSUFFIX_H
#include "NamedEnum.h"
/** @brief Template that takes the enum type to work with and a special none-enum. */
template<typename T, T _none>
class NamedSuffix
{
public:
using unit_t = T;
static constexpr unit_t none = _none;
/** @brief Empty value. */
NamedSuffix()
: m_value(0)
, m_unit( none )
{
}
/** @brief Specific value and unit. */
NamedSuffix( int value, unit_t unit )
: m_value( value )
, m_unit( unit )
{
}
/** @brief Construct value and unit from string.
*
* This parses the given string @p s by comparing with the suffixes
* in @p table and uses the first matching suffix as the unit.
*/
NamedSuffix( const NamedEnumTable<T>& table, const QString& s )
: NamedSuffix()
{
for( const auto suffix : table.table )
if ( s.endsWith( suffix.first ) )
{
m_value = s.left( s.length() - suffix.first.length() ).toInt();
m_unit = suffix.second;
break;
}
}
/** @brief Construct value from string.
*
* This is not defined in the template, because it should probably
* delegate to the constructor above with a fixed table.
*/
NamedSuffix( const QString& s );
int value() const { return m_value; }
unit_t unit() const { return m_unit; }
/** @brief Check that a value-unit combination is valid.
*
* This is not defined in the template, because validity (e.g.
* range of acceptable values) depends on the kind of unit.
*/
bool isValid() const;
protected:
int m_value;
unit_t m_unit;
};
#endif

View File

@ -21,9 +21,11 @@
#include "GlobalStorage.h"
#include "utils/CalamaresUtils.h"
#include "utils/Logger.h"
#include "utils/YamlUtils.h"
#include "utils/CalamaresUtilsGui.h"
#include "utils/ImageRegistry.h"
#include "utils/Logger.h"
#include "utils/NamedEnum.h"
#include "utils/YamlUtils.h"
#include <QDir>
#include <QFile>
@ -76,6 +78,17 @@ const QStringList Branding::s_styleEntryStrings =
"sidebarTextHighlight"
};
static const NamedEnumTable<Branding::WindowDimensionUnit>&
windowDimensions()
{
using Unit = Branding::WindowDimensionUnit;
static const NamedEnumTable<Unit> names{
{"px", Unit::Pixies},
{"em", Unit::Fonties}
};
return names;
}
Branding::Branding( const QString& brandingFilePath,
QObject* parent )
@ -107,12 +120,11 @@ Branding::Branding( const QString& brandingFilePath,
bail( "The branding component name should match the name of the "
"component directory." );
initSimpleSettings( doc );
if ( !doc[ "strings" ].IsMap() )
bail( "Syntax error in strings map." );
m_welcomeStyleCalamares = doc[ "welcomeStyleCalamares" ].as< bool >( false );
m_welcomeExpandingLogo = doc[ "welcomeExpandingLogo" ].as< bool >( true );
QVariantMap strings =
CalamaresUtils::yamlMapToVariant( doc[ "strings" ] ).toMap();
m_strings.clear();
@ -287,6 +299,59 @@ Branding::setGlobals( GlobalStorage* globalStorage ) const
globalStorage->insert( "branding", brandingMap );
}
bool
Branding::WindowDimension::isValid() const
{
return ( unit() != none ) && ( value() > 0 );
}
/// @brief Guard against cases where the @p key doesn't exist in @p doc
static inline QString
getString( const YAML::Node& doc, const char* key )
{
if ( doc[key] )
return QString::fromStdString( doc[key].as< std::string >() );
return QString();
}
void
Branding::initSimpleSettings( const YAML::Node& doc )
{
static const NamedEnumTable< WindowExpansion > expansionNames{
{ QStringLiteral( "normal" ), WindowExpansion::Normal },
{ QStringLiteral( "fullscreen" ), WindowExpansion::Fullscreen },
{ QStringLiteral( "noexpand" ), WindowExpansion::Fixed }
};
static const NamedEnumTable< WindowDimensionUnit > dimensionNames{
{ QStringLiteral( "px" ), WindowDimensionUnit::Pixies },
{ QStringLiteral( "em" ), WindowDimensionUnit::Fonties }
};
bool ok = false;
m_welcomeStyleCalamares = doc[ "welcomeStyleCalamares" ].as< bool >( false );
m_welcomeExpandingLogo = doc[ "welcomeExpandingLogo" ].as< bool >( true );
m_windowExpansion = expansionNames.find( getString( doc, "windowExpanding" ), ok );
if ( !ok )
cWarning() << "Branding module-setting *windowExpanding* interpreted as" << expansionNames.find( m_windowExpansion, ok );
QString windowSize = getString( doc, "windowSize" );
if ( !windowSize.isEmpty() )
{
auto l = windowSize.split( ',' );
if ( l.count() == 2 )
{
m_windowWidth = WindowDimension( dimensionNames, l[0] );
m_windowHeight = WindowDimension( dimensionNames, l[1] );
}
}
if ( !m_windowWidth.isValid() )
m_windowWidth = WindowDimension( CalamaresUtils::windowPreferredWidth, WindowDimensionUnit::Pixies );
if ( !m_windowHeight.isValid() )
m_windowHeight = WindowDimension( CalamaresUtils::windowPreferredHeight, WindowDimensionUnit::Pixies );
}
void
Branding::bail( const QString& message )

View File

@ -23,10 +23,16 @@
#include "UiDllMacro.h"
#include "Typedefs.h"
#include "utils/NamedSuffix.h"
#include <QObject>
#include <QStringList>
#include <QMap>
namespace YAML
{
class Node;
}
namespace Calamares
{
@ -63,7 +69,7 @@ public:
ProductIcon,
ProductWelcome
};
enum StyleEntry : short
{
SidebarBackground,
@ -72,6 +78,21 @@ public:
SidebarTextHighlight
};
/** @brief Setting for how much the main window may expand. */
enum class WindowExpansion { Normal, Fullscreen, Fixed } ;
/** @brief Setting for the main window size.
*
* The units are pixels (Pixies) or something-based-on-fontsize (Fonties), which
* we suffix as "em", e.g. "600px" or "32em".
*/
enum class WindowDimensionUnit { None, Pixies, Fonties };
class WindowDimension : public NamedSuffix<WindowDimensionUnit, WindowDimensionUnit::None>
{
public:
using NamedSuffix::NamedSuffix;
bool isValid() const;
} ;
static Branding* instance();
explicit Branding( const QString& brandingFilePath,
@ -90,6 +111,12 @@ public:
bool welcomeStyleCalamares() const { return m_welcomeStyleCalamares; }
bool welcomeExpandingLogo() const { return m_welcomeExpandingLogo; }
bool windowMaximize() const { return m_windowExpansion == WindowExpansion::Fullscreen; }
bool windowExpands() const { return m_windowExpansion != WindowExpansion::Fixed; }
QPair< WindowDimension, WindowDimension > windowSize() const
{
return QPair< WindowDimension, WindowDimension >( m_windowWidth, m_windowHeight );
}
/**
* Creates a map called "branding" in the global storage, and inserts an
@ -115,8 +142,15 @@ private:
QString m_slideshowPath;
QString m_translationsPathPrefix;
/** @brief Initialize the simple settings below */
void initSimpleSettings( const YAML::Node& doc );
bool m_welcomeStyleCalamares;
bool m_welcomeExpandingLogo;
WindowExpansion m_windowExpansion;
WindowDimension m_windowHeight, m_windowWidth;
};
template<typename U> inline QString operator*(U e) { return Branding::instance()->string( e ); }

View File

@ -39,46 +39,32 @@
#include "modules/partition/core/PartitionIterator.h"
ResizeFSJob::RelativeSize::RelativeSize()
: m_value( 0 )
, m_unit( None )
static const NamedEnumTable<ResizeFSJob::RelativeUnit>&
unitSuffixes()
{
using Unit = ResizeFSJob::RelativeUnit;
static const NamedEnumTable<Unit> names{
{ QStringLiteral( "%" ), Unit::Percent },
{ QStringLiteral( "MiB" ), Unit::Absolute }
};
return names;
}
template<int N>
void matchUnitSuffix(
const QString& s,
const char ( &suffix )[N],
ResizeFSJob::RelativeSize::Unit matchedUnit,
int& value,
ResizeFSJob::RelativeSize::Unit& unit
)
{
if ( s.endsWith( suffix ) )
{
value = s.left( s.length() - N + 1 ).toInt();
unit = matchedUnit;
}
}
ResizeFSJob::RelativeSize::RelativeSize( const QString& s )
: m_value( 0 )
, m_unit( None )
: NamedSuffix( unitSuffixes(), s )
{
matchUnitSuffix( s, "%", Percent, m_value, m_unit );
matchUnitSuffix( s, "MiB", Absolute, m_value, m_unit );
if ( ( unit() == Percent ) && ( value() > 100 ) )
if ( ( unit() == RelativeUnit::Percent ) && ( value() > 100 ) )
{
cDebug() << "Percent value" << value() << "is not valid.";
m_value = 0;
m_unit = None;
m_unit = RelativeUnit::None;
}
if ( !m_value )
m_unit = None;
m_unit = RelativeUnit::None;
}
qint64
@ -91,11 +77,11 @@ ResizeFSJob::RelativeSize::apply( qint64 totalSectors, qint64 sectorSize )
switch ( m_unit )
{
case None:
case unit_t::None:
return -1;
case Absolute:
case unit_t::Absolute:
return CalamaresUtils::MiBtoBytes( value() ) / sectorSize;
case Percent:
case unit_t::Percent:
if ( value() == 100 )
return totalSectors; // Common-case, avoid futzing around
else

View File

@ -24,7 +24,8 @@
#include <CppJob.h>
#include <utils/PluginFactory.h>
#include "utils/NamedSuffix.h"
#include "utils/PluginFactory.h"
#include <PluginDllMacro.h>
@ -37,31 +38,28 @@ class PLUGINDLLEXPORT ResizeFSJob : public Calamares::CppJob
Q_OBJECT
public:
enum class RelativeUnit
{
None,
Percent,
Absolute
};
/** @brief Size expressions
*
* Sizes can be specified in MiB or percent (of the device they
* are on). This class handles parsing of such strings from the
* config file.
*/
class RelativeSize
class RelativeSize : public NamedSuffix<RelativeUnit, RelativeUnit::None>
{
public:
RelativeSize();
RelativeSize() : NamedSuffix() { };
RelativeSize( const QString& );
enum Unit
{
None,
Percent,
Absolute
};
int value() const { return m_value; }
Unit unit() const { return m_unit; }
bool isValid() const
{
return ( unit() != None ) && ( value() > 0 );
return ( unit() != RelativeUnit::None ) && ( value() > 0 );
}
/** @brief Apply this size to the number of sectors @p totalSectors .
@ -80,10 +78,6 @@ public:
* Equivalent to apply( d->totalLogical(), d->logicalSize() )
*/
qint64 apply( Device* d );
private:
int m_value;
Unit m_unit;
} ;
explicit ResizeFSJob( QObject* parent = nullptr );

View File

@ -54,13 +54,13 @@ FSResizerTests::initTestCase()
void FSResizerTests::testConfigurationRobust()
{
ResizeFSJob j;
// Empty config
j.setConfigurationMap( QVariantMap() );
QVERIFY( j.m_fsname.isEmpty() );
QVERIFY( j.m_devicename.isEmpty() );
QCOMPARE( j.m_size.unit(), ResizeFSJob::RelativeSize::None );
QCOMPARE( j.m_atleast.unit(), ResizeFSJob::RelativeSize::None );
QCOMPARE( j.m_size.unit(), ResizeFSJob::RelativeUnit::None );
QCOMPARE( j.m_atleast.unit(), ResizeFSJob::RelativeUnit::None );
// Config is missing fs and dev, so it isn't valid
YAML::Node doc0 = YAML::Load( R"(---
@ -70,17 +70,17 @@ atleast: 600MiB
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
QVERIFY( j.m_fsname.isEmpty() );
QVERIFY( j.m_devicename.isEmpty() );
QCOMPARE( j.m_size.unit(), ResizeFSJob::RelativeSize::None );
QCOMPARE( j.m_atleast.unit(), ResizeFSJob::RelativeSize::None );
QCOMPARE( j.m_size.unit(), ResizeFSJob::RelativeUnit::None );
QCOMPARE( j.m_atleast.unit(), ResizeFSJob::RelativeUnit::None );
QCOMPARE( j.m_size.value(), 0 );
QCOMPARE( j.m_atleast.value(), 0 );
}
}
void FSResizerTests::testConfigurationValues()
{
ResizeFSJob j;
// Check both
// Check both
YAML::Node doc0 = YAML::Load( R"(---
fs: /
size: 100%
@ -89,8 +89,8 @@ atleast: 600MiB
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
QVERIFY( !j.m_fsname.isEmpty() );
QVERIFY( j.m_devicename.isEmpty() );
QCOMPARE( j.m_size.unit(), ResizeFSJob::RelativeSize::Percent );
QCOMPARE( j.m_atleast.unit(), ResizeFSJob::RelativeSize::Absolute );
QCOMPARE( j.m_size.unit(), ResizeFSJob::RelativeUnit::Percent );
QCOMPARE( j.m_atleast.unit(), ResizeFSJob::RelativeUnit::Absolute );
QCOMPARE( j.m_size.value(), 100 );
QCOMPARE( j.m_atleast.value(), 600 );
@ -104,8 +104,8 @@ atleast: 127 %
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
QVERIFY( !j.m_fsname.isEmpty() );
QVERIFY( !j.m_devicename.isEmpty() );
QCOMPARE( j.m_size.unit(), ResizeFSJob::RelativeSize::Absolute );
QCOMPARE( j.m_atleast.unit(), ResizeFSJob::RelativeSize::Percent );
QCOMPARE( j.m_size.unit(), ResizeFSJob::RelativeUnit::Absolute );
QCOMPARE( j.m_atleast.unit(), ResizeFSJob::RelativeUnit::Percent );
QCOMPARE( j.m_size.value(), 72 );
QCOMPARE( j.m_atleast.value(), 127 );
@ -119,8 +119,8 @@ size: 71MiB
j.setConfigurationMap( CalamaresUtils::yamlMapToVariant( doc0 ).toMap() );
QVERIFY( !j.m_fsname.isEmpty() );
QVERIFY( j.m_devicename.isEmpty() );
QCOMPARE( j.m_size.unit(), ResizeFSJob::RelativeSize::Absolute );
QCOMPARE( j.m_atleast.unit(), ResizeFSJob::RelativeSize::None );
QCOMPARE( j.m_size.unit(), ResizeFSJob::RelativeUnit::Absolute );
QCOMPARE( j.m_atleast.unit(), ResizeFSJob::RelativeUnit::None );
QCOMPARE( j.m_size.value(), 71 );
QCOMPARE( j.m_atleast.value(), 0 );
}

View File

@ -36,6 +36,7 @@
#include "CalamaresVersion.h"
#include "utils/CalamaresUtilsGui.h"
#include "utils/Logger.h"
#include "utils/NamedEnum.h"
#include "utils/Retranslator.h"
#include "widgets/WaitingWidget.h"
#include "GlobalStorage.h"
@ -479,25 +480,17 @@ PartitionViewStep::onLeave()
static PartitionActions::Choices::SwapChoice
nameToChoice( QString name, bool& ok )
{
ok = false;
name = name.toLower();
using namespace PartitionActions::Choices;
// Each return here first sets ok to true, returns enum value
if ( name == QStringLiteral( "none" ) )
return( ok=true, SwapChoice::NoSwap );
else if ( name == QStringLiteral( "small" ) )
return( ok=true, SwapChoice::SmallSwap);
else if ( name == QStringLiteral( "suspend" ) )
return( ok=true, SwapChoice::FullSwap );
else if ( name == QStringLiteral( "reuse" ) )
return( ok=true, SwapChoice::ReuseSwap );
else if ( name == QStringLiteral( "file" ) )
return( ok=true, SwapChoice::SwapFile );
static const NamedEnumTable<SwapChoice> names {
{ QStringLiteral( "none" ), SwapChoice::NoSwap },
{ QStringLiteral( "small" ), SwapChoice::SmallSwap },
{ QStringLiteral( "suspend" ), SwapChoice::FullSwap },
{ QStringLiteral( "reuse" ), SwapChoice::ReuseSwap },
{ QStringLiteral( "file" ), SwapChoice::SwapFile }
};
ok = false;
return SwapChoice::NoSwap;
return names.find( name, ok );
}
/** @brief translate @p defaultFS into a recognized name