Merge branch 'resize-control' of https://github.com/calamares/calamares into development

This commit is contained in:
Philip Müller 2019-01-13 14:10:52 +01:00
commit 42f8bc50f8
6 changed files with 179 additions and 28 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", never expand, 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

@ -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::initializer_list< 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( type 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

@ -21,9 +21,10 @@
#include "GlobalStorage.h"
#include "utils/CalamaresUtils.h"
#include "utils/Logger.h"
#include "utils/YamlUtils.h"
#include "utils/ImageRegistry.h"
#include "utils/Logger.h"
#include "utils/NamedEnum.h"
#include "utils/YamlUtils.h"
#include <QDir>
#include <QFile>
@ -107,12 +108,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();
@ -288,6 +288,25 @@ Branding::setGlobals( GlobalStorage* globalStorage ) const
}
void
Branding::initSimpleSettings( const YAML::Node& doc )
{
static const NamedEnumTable< WindowExpansion > weNames{
{ QStringLiteral( "normal" ), WindowExpansion::Normal },
{ QStringLiteral( "fullscreen" ), WindowExpansion::Fullscreen },
{ QStringLiteral( "noexpand" ), WindowExpansion::Fixed }
};
bool ok = false;
m_welcomeStyleCalamares = doc[ "welcomeStyleCalamares" ].as< bool >( false );
m_welcomeExpandingLogo = doc[ "welcomeExpandingLogo" ].as< bool >( true );
m_windowExpansion = weNames.find( QString::fromStdString( doc[ "windowExpanding" ].as< std::string >() ), ok );
if ( !ok )
cWarning() << "Branding module-setting *windowExpanding* interpreted as" << weNames.find( m_windowExpansion, ok );
}
void
Branding::bail( const QString& message )
{

View File

@ -27,6 +27,10 @@
#include <QStringList>
#include <QMap>
namespace YAML
{
class Node;
}
namespace Calamares
{
@ -72,6 +76,9 @@ public:
SidebarTextHighlight
};
/** @brief Setting for how much the main window may expand. */
enum class WindowExpansion { Normal, Fullscreen, Fixed } ;
static Branding* instance();
explicit Branding( const QString& brandingFilePath,
@ -115,8 +122,12 @@ 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;
};
template<typename U> inline QString operator*(U e) { return Branding::instance()->string( e ); }

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