From 8c78a6cdfa6bc0943b7e2ac4776636f811e6d222 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 12 Aug 2019 12:05:50 +0200 Subject: [PATCH 01/32] Documentation: match stated requirements with CMakeLists.txt --- README.md | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index f35b012c8..df4c02b66 100644 --- a/README.md +++ b/README.md @@ -13,28 +13,22 @@ ### Dependencies Main: -* Compiler with C++11 support: GCC >= 4.9.0 or Clang >= 3.5.1 -* CMake >= 3.2 -* Qt >= 5.7 +* Compiler with C++14 support: GCC >= 5 or Clang >= 3.5.1 +* CMake >= 3.3 +* Qt >= 5.9 * yaml-cpp >= 0.5.1 * Python >= 3.3 (required for some modules) -* Boost.Python >= 1.55.0 (recommended, or PythonQt; one is required for some modules) -* PythonQt (recommended, or Boost.Python; one is required for some modules) -* extra-cmake-modules >= 5.18 (recommended; required for some modules) +* Boost.Python >= 1.55.0 (required for some modules) +* KDE extra-cmake-modules >= 5.18 (recommended; required for some modules; + required for some tests) +* PythonQt (optional, deprecated) Modules: -* welcome: - * NetworkManager - * UPower (optional, runtime) -* partition: - * extra-cmake-modules - * KF5: KCoreAddons, KConfig, KI18n, KService, KWidgetsAddons - * KPMcore >= 3.3 -* bootloader: - * systemd-boot or GRUB -* unpackfs: - * squashfs-tools - * rsync +* Individual modules may have their own requirements; + these are listed in CMake output. Particular requirements (not complete): +* *fsresizer* KPMCore >= 3.3 +* *partition* KPMCore >= 3.3 +* *users* LibPWQuality (optional) ### Building From a6db224fcb98d90309aea2795ad444e4c16231f0 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 8 Aug 2019 13:32:20 +0200 Subject: [PATCH 02/32] [fsresizer] [partition] Gracefully fail on missing dependencies - If KPMcore is found -- it requires some other KDE Frameworks but at least in pre-4.0 versions doesn't check very well for them -- then missing its dependencies is no cause for CMake failure. Instead, log it nicely and suppress the module. --- src/modules/fsresizer/CMakeLists.txt | 14 +++++++++----- src/modules/partition/CMakeLists.txt | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/modules/fsresizer/CMakeLists.txt b/src/modules/fsresizer/CMakeLists.txt index ba9c81f4c..3d82489b7 100644 --- a/src/modules/fsresizer/CMakeLists.txt +++ b/src/modules/fsresizer/CMakeLists.txt @@ -1,11 +1,11 @@ find_package( KPMcore 3.3 ) +find_package( KF5Config CONFIG ) +find_package( KF5I18n CONFIG ) +find_package( KF5WidgetsAddons CONFIG ) set( _partition_defs "" ) -if ( KPMcore_FOUND ) - find_package( Qt5 REQUIRED DBus ) # Needed for KPMCore - find_package( KF5 REQUIRED I18n WidgetsAddons ) # Needed for KPMCore - +if ( KPMcore_FOUND AND Qt5DBus_FOUND AND KF5CoreAddons_FOUND AND KF5Config_FOUND ) include_directories( ${KPMCORE_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src/modules/partition ) if ( KPMcore_VERSION VERSION_GREATER "3.3.0") @@ -48,5 +48,9 @@ if ( KPMcore_FOUND ) target_compile_definitions( fsresizertest PRIVATE ${_partition_defs} ) endif() else() - calamares_skip_module( "fsresizer (missing suitable KPMcore)" ) + if ( NOT KPMcore_FOUND ) + calamares_skip_module( "fsresizer (missing suitable KPMcore)" ) + else() + calamares_skip_module( "fsresizer (missing dependencies for KPMcore)" ) + endif() endif() diff --git a/src/modules/partition/CMakeLists.txt b/src/modules/partition/CMakeLists.txt index df1588cb2..f9c32b39e 100644 --- a/src/modules/partition/CMakeLists.txt +++ b/src/modules/partition/CMakeLists.txt @@ -22,11 +22,11 @@ set_package_properties( KPMcore PROPERTIES PURPOSE "For partitioning module" ) +find_package( KF5Config CONFIG ) +find_package( KF5I18n CONFIG ) +find_package( KF5WidgetsAddons CONFIG ) -if ( KPMcore_FOUND ) - find_package( Qt5 REQUIRED DBus ) - find_package( KF5 REQUIRED Config CoreAddons I18n WidgetsAddons ) - +if ( KPMcore_FOUND AND Qt5DBus_FOUND AND KF5CoreAddons_FOUND AND KF5Config_FOUND ) if ( KPMcore_VERSION VERSION_GREATER "3.3.0") list( APPEND _partition_defs WITH_KPMCORE331API) # kpmcore > 3.3.0 with deprecations endif() @@ -106,5 +106,9 @@ if ( KPMcore_FOUND ) SHARED_LIB ) else() - calamares_skip_module( "partition (missing suitable KPMcore)" ) + if ( NOT KPMcore_FOUND ) + calamares_skip_module( "partition (missing suitable KPMcore)" ) + else() + calamares_skip_module( "partition (missing dependencies for KPMcore)" ) + endif() endif() From bcb7f17584161fe0805605ca8eae2db8c2f3d1a2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 8 Aug 2019 14:06:33 +0200 Subject: [PATCH 03/32] [calamares] Make KCoreAddons a requirement - Require KCoreAddons for KAboutData (also, optionally, for KOSRelease) --- CMakeLists.txt | 30 +++++++++++++++++++++++++++--- src/calamares/CMakeLists.txt | 2 +- src/calamares/main.cpp | 7 ++++--- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 36c09abf0..5461aa3c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -261,6 +261,8 @@ if( Qt5_VERSION VERSION_GREATER 5.12.1 ) list( APPEND _tx_ok "eo" ) endif() endif() +# Optional Qt parts +find_package( Qt5DBus CONFIG ) find_package( YAMLCPP ${YAMLCPP_VERSION} REQUIRED ) if( INSTALL_POLKIT ) @@ -291,7 +293,14 @@ if( ECM_FOUND ) include(KDEInstallDirs) endif() -find_package( KF5 COMPONENTS CoreAddons Crash ) +find_package( KF5 QUIET COMPONENTS CoreAddons Crash ) +set_package_properties( + KF5::CoreAddons PROPERTIES + TYPE REQUIRED + DESCRIPTION "Classes built on QtCore for About Data" + URL "https://api.kde.org/frameworks/kcoreaddons/" + PURPOSE "About Calamares" +) if( NOT KF5Crash_FOUND ) set( WITH_KF5Crash OFF ) endif() @@ -590,10 +599,25 @@ add_custom_target( uninstall ### CMAKE SUMMARY REPORT # -feature_summary(WHAT ALL) - get_directory_property( SKIPPED_MODULES DIRECTORY src/modules DEFINITION LIST_SKIPPED_MODULES ) calamares_explain_skipped_modules( ${SKIPPED_MODULES} ) + +feature_summary( + WHAT DISABLED_FEATURES + DESCRIPTION "The following features have been disabled:" + QUIET_ON_EMPTY +) +feature_summary( + WHAT OPTIONAL_PACKAGES_NOT_FOUND + DESCRIPTION "The following OPTIONAL packages were not found:" + QUIET_ON_EMPTY +) +feature_summary( + WHAT REQUIRED_PACKAGES_NOT_FOUND + FATAL_ON_MISSING_REQUIRED_PACKAGES + DESCRIPTION "The following REQUIRED packages were not found:" + QUIET_ON_EMPTY +) diff --git a/src/calamares/CMakeLists.txt b/src/calamares/CMakeLists.txt index 259e3bf56..a55e26b6d 100644 --- a/src/calamares/CMakeLists.txt +++ b/src/calamares/CMakeLists.txt @@ -46,11 +46,11 @@ target_link_libraries( calamares_bin calamaresui Qt5::Core Qt5::Widgets + KF5::CoreAddons ) if( WITH_KF5Crash ) target_link_libraries( calamares_bin PRIVATE - KF5::CoreAddons KF5::Crash ) target_compile_definitions( calamares_bin PRIVATE WITH_KF5Crash ) diff --git a/src/calamares/main.cpp b/src/calamares/main.cpp index 704c2bf59..caf1f6cfd 100644 --- a/src/calamares/main.cpp +++ b/src/calamares/main.cpp @@ -26,8 +26,8 @@ #include "3rdparty/kdsingleapplicationguard/kdsingleapplicationguard.h" -#ifdef WITH_KF5Crash #include +#ifdef WITH_KF5Crash #include #endif @@ -93,7 +93,6 @@ main( int argc, char* argv[] ) { CalamaresApplication a( argc, argv ); -#ifdef WITH_KF5Crash KAboutData aboutData( "calamares", "Calamares", a.applicationVersion(), @@ -104,12 +103,14 @@ main( int argc, char* argv[] ) "https://calamares.io", "https://github.com/calamares/calamares/issues" ); KAboutData::setApplicationData( aboutData ); + a.setApplicationDisplayName( QString() ); // To avoid putting an extra "Calamares/" into the log-file + +#ifdef WITH_KF5Crash KCrash::initialize(); // KCrash::setCrashHandler(); KCrash::setDrKonqiEnabled( true ); KCrash::setFlags( KCrash::SaferDialog | KCrash::AlwaysDirectly ); // TODO: umount anything in /tmp/calamares-... as an emergency save function - a.setApplicationDisplayName( QString() ); #endif handle_args( a ); From 44991e700b943003fe58030ce7dbdcaa43bbf0dd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 8 Aug 2019 14:30:50 +0200 Subject: [PATCH 04/32] [libcalamaresui] Check KCoreAddons version directly --- src/libcalamaresui/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libcalamaresui/CMakeLists.txt b/src/libcalamaresui/CMakeLists.txt index 111113a47..a9d31c2c3 100644 --- a/src/libcalamaresui/CMakeLists.txt +++ b/src/libcalamaresui/CMakeLists.txt @@ -75,8 +75,6 @@ calamares_add_library( calamaresui VERSION ${CALAMARES_VERSION_SHORT} ) -find_package( KF5CoreAddons 5.58 QUIET ) # If it's really new -if ( KF5CoreAddons_FOUND ) +if ( KF5CoreAddons_FOUND AND KF5CoreAddons_VERSION VERSION_GREATER_EQUAL 5.58 ) target_compile_definitions( calamaresui PRIVATE WITH_KOSRelease ) - target_link_libraries( calamaresui PRIVATE KF5::CoreAddons ) endif() From 1711071c588b6fdd779ca06dcbcea1f99dbb62f5 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 8 Aug 2019 14:31:25 +0200 Subject: [PATCH 05/32] [libcalamares] Swap out own PluginLoader for KCoreAddons --- src/libcalamares/CMakeLists.txt | 2 +- src/libcalamares/utils/PluginFactory.cpp | 127 ---------- src/libcalamares/utils/PluginFactory.h | 291 +---------------------- src/libcalamares/utils/PluginFactory_p.h | 55 ----- 4 files changed, 5 insertions(+), 470 deletions(-) delete mode 100644 src/libcalamares/utils/PluginFactory.cpp delete mode 100644 src/libcalamares/utils/PluginFactory_p.h diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 790d4b6ac..c6f8cd0d2 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -44,7 +44,6 @@ set( libSources utils/CommandList.cpp utils/Dirs.cpp utils/Logger.cpp - utils/PluginFactory.cpp utils/Retranslator.cpp utils/String.cpp utils/UMask.cpp @@ -120,6 +119,7 @@ target_link_libraries( calamares LINK_PUBLIC ${YAMLCPP_LIBRARY} Qt5::Core + KF5::CoreAddons ${OPTIONAL_PUBLIC_LIBRARIES} ) diff --git a/src/libcalamares/utils/PluginFactory.cpp b/src/libcalamares/utils/PluginFactory.cpp deleted file mode 100644 index 878182ea4..000000000 --- a/src/libcalamares/utils/PluginFactory.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* === This file is part of Calamares - === - * - * Copyright 2015, Teo Mrnjavac - * Copyright 2017-2018, Adriaan de Groot - * - * Based on KPluginFactory from KCoreAddons, KDE project - * Copyright 2007, Matthias Kretz - * Copyright 2007, Bernhard Loos - * - * 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 . - */ - -#include "PluginFactory.h" -#include "PluginFactory_p.h" - -#include -#include - -// *INDENT-OFF* -// clang-format off - -Q_GLOBAL_STATIC( QObjectCleanupHandler, factorycleanup ) - -namespace Calamares -{ - -PluginFactory::PluginFactory() - : pd_ptr( new PluginFactoryPrivate ) -{ - pd_ptr->q_ptr = this; - - factorycleanup()->add( this ); -} - -PluginFactory::PluginFactory( PluginFactoryPrivate& d ) - : pd_ptr( &d ) -{ - factorycleanup()->add( this ); -} - -PluginFactory::~PluginFactory() -{ - delete pd_ptr; -} - -void PluginFactory::doRegisterPlugin( const QString& keyword, const QMetaObject* metaObject, CreateInstanceFunction instanceFunction ) -{ - Q_ASSERT( metaObject ); - - // we allow different interfaces to be registered without keyword - if ( !keyword.isEmpty() ) - { - if ( pd_ptr->createInstanceHash.contains( keyword ) ) - qWarning() << "A plugin with the keyword" << keyword << "was already registered. A keyword must be unique!"; - pd_ptr->createInstanceHash.insert( keyword, PluginFactoryPrivate::Plugin( metaObject, instanceFunction ) ); - } - else - { - const QList clashes( pd_ptr->createInstanceHash.values( keyword ) ); - const QMetaObject* superClass = metaObject->superClass(); - if ( superClass ) - { - for ( const PluginFactoryPrivate::Plugin& plugin : clashes ) - { - for ( const QMetaObject* otherSuper = plugin.first->superClass(); otherSuper; - otherSuper = otherSuper->superClass() ) - { - if ( superClass == otherSuper ) - qWarning() << "Two plugins with the same interface(" << superClass->className() << ") were registered. Use keywords to identify the plugins."; - } - } - } - for ( const PluginFactoryPrivate::Plugin& plugin : clashes ) - { - superClass = plugin.first->superClass(); - if ( superClass ) - { - for ( const QMetaObject* otherSuper = metaObject->superClass(); otherSuper; - otherSuper = otherSuper->superClass() ) - { - if ( superClass == otherSuper ) - qWarning() << "Two plugins with the same interface(" << superClass->className() << ") were registered. Use keywords to identify the plugins."; - } - } - } - pd_ptr->createInstanceHash.insertMulti( keyword, PluginFactoryPrivate::Plugin( metaObject, instanceFunction ) ); - } -} - -QObject* PluginFactory::create( const char* iface, QWidget* parentWidget, QObject* parent, const QString& keyword ) -{ - QObject* obj = nullptr; - - const QList candidates( pd_ptr->createInstanceHash.values( keyword ) ); - // for !keyword.isEmpty() candidates.count() is 0 or 1 - - for ( const PluginFactoryPrivate::Plugin& plugin : candidates ) - { - for ( const QMetaObject* current = plugin.first; current; current = current->superClass() ) - { - if ( 0 == qstrcmp( iface, current->className() ) ) - { - if ( obj ) - qWarning() << "ambiguous interface requested from a DSO containing more than one plugin"; - obj = plugin.second( parentWidget, parent ); - break; - } - } - } - - if ( obj ) - emit objectCreated( obj ); - return obj; -} - -} diff --git a/src/libcalamares/utils/PluginFactory.h b/src/libcalamares/utils/PluginFactory.h index f2481f10d..2ba9fd3cd 100644 --- a/src/libcalamares/utils/PluginFactory.h +++ b/src/libcalamares/utils/PluginFactory.h @@ -24,298 +24,15 @@ #ifndef UTILS_PLUGINFACTORY_H #define UTILS_PLUGINFACTORY_H -#include "DllMacro.h" - -#include -#include -#include - -// *INDENT-OFF* -// clang-format off - -namespace Calamares -{ -class PluginFactoryPrivate; -} +#include #define CalamaresPluginFactory_iid "io.calamares.PluginFactory" -/** - * \relates PluginFactory - * - * CALAMARES_PLUGIN_FACTORY_DECLARATION declares the PluginFactory subclass. This macro - * can be used in a header file. - * - * \param name The name of the PluginFactory derived class. - * - * \see CALAMARES_PLUGIN_FACTORY - * \see CALAMARES_PLUGIN_FACTORY_DEFINITION - */ #define CALAMARES_PLUGIN_FACTORY_DECLARATION(name) \ - class name : public Calamares::PluginFactory \ - { \ - Q_OBJECT \ - Q_INTERFACES(Calamares::PluginFactory) \ - Q_PLUGIN_METADATA(IID CalamaresPluginFactory_iid) \ - public: \ - explicit name(); \ - ~name(); \ - private: \ - void init(); \ - }; - -/** - * \relates PluginFactory - * CALAMARES_PLUGIN_FACTORY_DEFINITION defines the PluginFactory subclass. This macro - * can not be used in a header file. - * - * \param name The name of the PluginFactory derived class. - * - * \param pluginRegistrations Code to be inserted into the constructor of the - * class. Usually a series of registerPlugin() calls. - * - * \see CALAMARES_PLUGIN_FACTORY - * \see CALAMARES_PLUGIN_FACTORY_DECLARATION - */ + K_PLUGIN_FACTORY_DECLARATION_WITH_BASEFACTORY_SKEL(name,KPluginFactory,Q_PLUGIN_METADATA(IID CalamaresPluginFactory_iid)) #define CALAMARES_PLUGIN_FACTORY_DEFINITION(name, pluginRegistrations) \ - name::name() \ - { \ - pluginRegistrations \ - } \ - name::~name() {} + K_PLUGIN_FACTORY_DEFINITION(name, pluginRegistrations ) -namespace Calamares -{ - -/** - * \class PluginFactory PluginFactory.h - * - * PluginFactory provides a convenient way to provide factory-style plugins. - * Qt plugins provide a singleton object, but a common pattern is for plugins - * to generate as many objects of a particular type as the application requires. - * By using PluginFactory, you can avoid implementing the factory pattern - * yourself. - * - * PluginFactory also allows plugins to provide multiple different object - * types, indexed by keywords. - * - * The objects created by PluginFactory must inherit QObject, and must have a - * standard constructor pattern: - * \li if the object is a KPart::Part, it must be of the form - * \code - * T(QWidget *parentWidget, QObject *parent, const QVariantList &args) - * \endcode - * \li if it is a QWidget, it must be of the form - * \code - * T(QWidget *parent, const QVariantList &args) - * \endcode - * \li otherwise it must be of the form - * \code - * T(QObject *parent, const QVariantList &args) - * \endcode - * - * You should typically use CALAMARES_PLUGIN_FACTORY_DEFINITION() in your plugin code to - * create the factory. The pattern is - * - * \code - * #include "utils/PluginFactory.h" - * - * class MyPlugin : public PluginInterface - * { - * public: - * MyPlugin(QObject *parent, const QVariantList &args) - * : PluginInterface(parent) - * {} - * }; - * - * CALAMARES_PLUGIN_FACTORY_DEFINITION(MyPluginFactory, - * registerPlugin(); - * ) - * \endcode - * - * If you want to load a library use KPluginLoader. - * The application that wants to instantiate plugin classes can do the following: - * \code - * PluginFactory *factory = KPluginLoader("libraryname").factory(); - * if (factory) { - * PluginInterface *p1 = factory->create(parent); - * OtherInterface *p2 = factory->create(parent); - * NextInterface *p3 = factory->create("keyword1", parent); - * NextInterface *p3 = factory->create("keyword2", parent); - * } - * \endcode - * - * \author Matthias Kretz - * \author Bernhard Loos - */ -class DLLEXPORT PluginFactory : public QObject -{ - Q_OBJECT - friend class PluginFactoryPrivate; -public: - /** - * This constructor creates a factory for a plugin. - */ - explicit PluginFactory(); - - /** - * This destroys the PluginFactory. - */ - virtual ~PluginFactory(); - - /** - * Use this method to create an object. It will try to create an object which inherits - * \p T. If it has multiple choices, you will get a fatal error (kFatal()), so be careful - * to request a unique interface or use keywords. - * - * \tparam T The interface for which an object should be created. The object will inherit \p T. - * \param parent The parent of the object. If \p parent is a widget type, it will also passed - * to the parentWidget argument of the CreateInstanceFunction for the object. - * \returns A pointer to the created object is returned, or 0 if an error occurred. - */ - template - T* create( QObject* parent = nullptr ); - - /** - * Use this method to create an object. It will try to create an object which inherits - * \p T and was registered with \p keyword. - * - * \tparam T The interface for which an object should be created. The object will inherit \p T. - * \param keyword The keyword of the object. - * \param parent The parent of the object. If \p parent is a widget type, it will also passed - * to the parentWidget argument of the CreateInstanceFunction for the object. - * \returns A pointer to the created object is returned, or 0 if an error occurred. - */ - template - T* create( const QString& keyword, QObject* parent = nullptr ); - -Q_SIGNALS: - void objectCreated( QObject* object ); - -protected: - /** - * Function pointer type to a function that instantiates a plugin. - */ - typedef QObject* ( *CreateInstanceFunction )( QWidget*, QObject* ); - - /** - * This is used to detect the arguments need for the constructor of plugin classes. - * You can inherit it, if you want to add new classes and still keep support for the old ones. - */ - template - struct InheritanceChecker - { - CreateInstanceFunction createInstanceFunction( QWidget* ) - { - return &createInstance; - } - CreateInstanceFunction createInstanceFunction( ... ) - { - return &createInstance; - } - }; - - explicit PluginFactory( PluginFactoryPrivate& dd ); - - /** - * Registers a plugin with the factory. Call this function from the constructor of the - * PluginFactory subclass to make the create function able to instantiate the plugin when asked - * for an interface the plugin implements. - * - * \tparam T the name of the plugin class - * - * \param keyword An optional keyword as unique identifier for the plugin. This allows you to - * put more than one plugin with the same interface into the same library using the same - * factory. X-KDE-PluginKeyword is a convenient way to specify the keyword in a desktop file. - * - * \param instanceFunction A function pointer to a function that creates an instance of the - * plugin. The default function that will be used depends on the type of interface. If the - * interface inherits from - * \li \c KParts::Part the function will call - * \code - * new T(QWidget *parentWidget, QObject *parent) - * \endcode - * \li \c QWidget the function will call - * \code - * new T(QWidget *parent) - * \endcode - * \li else the function will call - * \code - * new T(QObject *parent) - * \endcode - */ - template - void registerPlugin( const QString& keyword = QString(), - CreateInstanceFunction instanceFunction - = InheritanceChecker().createInstanceFunction( reinterpret_cast( 0 ) ) ) - { - doRegisterPlugin( keyword, &T::staticMetaObject, instanceFunction ); - } - - PluginFactoryPrivate* const pd_ptr; - - /** - * This function is called when the factory asked to create an Object. - * - * You may reimplement it to provide a very flexible factory. This is especially useful to - * provide generic factories for plugins implemeted using a scripting language. - * - * \param iface The staticMetaObject::className() string identifying the plugin interface that - * was requested. E.g. for KCModule plugins this string will be "KCModule". - * \param parentWidget Only used if the requested plugin is a KPart. - * \param parent The parent object for the plugin object. - * \param keyword A string that uniquely identifies the plugin. If a KService is used this - * keyword is read from the X-KDE-PluginKeyword entry in the .desktop file. - */ - virtual QObject* create( const char* iface, QWidget* parentWidget, QObject* parent, const QString& keyword ); - - template - static QObject* createInstance( QWidget* parentWidget, QObject* parent ) - { - Q_UNUSED( parentWidget ) - ParentType* p = nullptr; - if ( parent ) - { - p = qobject_cast( parent ); - Q_ASSERT( p ); - } - return new impl( p ); - } - -private: - void doRegisterPlugin( const QString& keyword, const QMetaObject* metaObject, CreateInstanceFunction instanceFunction ); -}; - -template -inline T* PluginFactory::create( QObject* parent ) -{ - QObject* o = create( T::staticMetaObject.className(), - parent && parent->isWidgetType() ? reinterpret_cast( parent ) : nullptr, - parent, - QString() ); - - T* t = qobject_cast( o ); - if ( !t ) - delete o; - return t; -} - -template -inline T* PluginFactory::create( const QString& keyword, QObject* parent ) -{ - QObject* o = create( T::staticMetaObject.className(), - parent && parent->isWidgetType() ? reinterpret_cast( parent ) : nullptr, - parent, - keyword ); - - T* t = qobject_cast( o ); - if ( !t ) - delete o; - return t; -} - -} // namespace - -Q_DECLARE_INTERFACE( Calamares::PluginFactory, CalamaresPluginFactory_iid ) +// Q_DECLARE_INTERFACE( Calamares::PluginFactory, CalamaresPluginFactory_iid ) #endif diff --git a/src/libcalamares/utils/PluginFactory_p.h b/src/libcalamares/utils/PluginFactory_p.h deleted file mode 100644 index dc272f077..000000000 --- a/src/libcalamares/utils/PluginFactory_p.h +++ /dev/null @@ -1,55 +0,0 @@ -/* === This file is part of Calamares - === - * - * Copyright 2015, Teo Mrnjavac - * - * Based on KPluginFactory from KCoreAddons, KDE project - * Copyright 2007, Matthias Kretz - * Copyright 2007, Bernhard Loos - * - * 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 . - */ - -#ifndef UTILS_PLUGINFACTORY_P_H -#define UTILS_PLUGINFACTORY_P_H - -#include "PluginFactory.h" - -#include - -namespace Calamares -{ - -class PluginFactoryPrivate -{ - Q_DECLARE_PUBLIC( PluginFactory ) -protected: - typedef QPair< const QMetaObject*, PluginFactory::CreateInstanceFunction > Plugin; - - PluginFactoryPrivate() - : catalogInitialized( false ) - , q_ptr( nullptr ) - { - } - ~PluginFactoryPrivate() {} - - QHash< QString, Plugin > createInstanceHash; - QString catalogName; - bool catalogInitialized; - - PluginFactory* q_ptr; -}; - -} // namespace Calamares - -#endif From 9098f8d7410661e286787200c19c079a2522ec28 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 12 Aug 2019 13:29:53 +0200 Subject: [PATCH 06/32] Changes: document KCoreAddons dependency --- CHANGES | 5 +++++ README.md | 1 + 2 files changed, 6 insertions(+) diff --git a/CHANGES b/CHANGES index dbdcb3523..00ea25223 100644 --- a/CHANGES +++ b/CHANGES @@ -13,6 +13,11 @@ This release contains contributions from (alphabetically by first name): has had a few updates and has now been consistently applied across the core codebase (e.g. libcalamares, libcalamaresui, calamares, but not the modules). +- *KCoreAddons* is now a required dependency. This lets us drop a chunk + of code that was copied from KCoreAddons years ago, and use the + (maintained!) upstream version instead. It also gives us KMacroExpander + everywhere, which will simplify code for handling substitutions + in configuration files. ## Modules ## diff --git a/README.md b/README.md index df4c02b66..e2e87fddf 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Main: * Boost.Python >= 1.55.0 (required for some modules) * KDE extra-cmake-modules >= 5.18 (recommended; required for some modules; required for some tests) +* KDE Frameworks KCoreAddons (>= 5.58 recommended) * PythonQt (optional, deprecated) Modules: From 2ab45cf4f0d7181ca3b393feb213288e16a8f77b Mon Sep 17 00:00:00 2001 From: Arnaud Rebillout Date: Tue, 16 Jul 2019 20:20:19 +0700 Subject: [PATCH 07/32] Make sure that variable num_files_total_local is declared This variable is declared in `if m:`. Of course if this codepath doesn't run, the variable is not declared an Python doesn't like this kind of surprise... Signed-off-by: Arnaud Rebillout --- src/modules/unpackfs/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/unpackfs/main.py b/src/modules/unpackfs/main.py index ac90a994e..e956dc070 100644 --- a/src/modules/unpackfs/main.py +++ b/src/modules/unpackfs/main.py @@ -103,6 +103,7 @@ def file_copy(source, dest, progress_cb): if not source.endswith("/"): source += "/" + num_files_total_local = 0 num_files_copied = 0 # Gets updated through rsync output args = ['rsync', '-aHAXr'] From 0d06e047ae32f5a0c9afddb8a0df1986f3b006d4 Mon Sep 17 00:00:00 2001 From: Arnaud Ferraris Date: Mon, 22 Jul 2019 15:56:20 +0200 Subject: [PATCH 08/32] libcalamares: Prevent integer overflows when parsing configuration Currently, a number of configuration parsing-related functions and classes use only `int` type for dealing with integers. Should the user need a bigger integer value, this would result in an erroneous value being used (`0`), as the correct value would overflow the 32-bits type. In order to prevent these overflow, this patch replaces `int` with `qint64` in the following functions & classes : * CalamaresUtils::yamlScalarToVariant() * CalamaresUtils::getInteger * NamedSuffix * PartitionSize This way, sizes or other integer values greater than 2^31 (for signed types) can be used. Signed-off-by: Arnaud Ferraris --- src/libcalamares/partition/PartitionSize.cpp | 2 +- src/libcalamares/utils/NamedSuffix.h | 8 ++++---- src/libcalamares/utils/Variant.cpp | 10 +++++++--- src/libcalamares/utils/Variant.h | 2 +- src/libcalamares/utils/Yaml.cpp | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/libcalamares/partition/PartitionSize.cpp b/src/libcalamares/partition/PartitionSize.cpp index 3f4463f3c..3397dcbec 100644 --- a/src/libcalamares/partition/PartitionSize.cpp +++ b/src/libcalamares/partition/PartitionSize.cpp @@ -50,7 +50,7 @@ PartitionSize::PartitionSize( const QString& s ) if ( m_unit == SizeUnit::None ) { - m_value = s.toInt(); + m_value = s.toLongLong(); if ( m_value > 0 ) { m_unit = SizeUnit::Byte; diff --git a/src/libcalamares/utils/NamedSuffix.h b/src/libcalamares/utils/NamedSuffix.h index e697c0640..8ad52edea 100644 --- a/src/libcalamares/utils/NamedSuffix.h +++ b/src/libcalamares/utils/NamedSuffix.h @@ -58,7 +58,7 @@ public: } /** @brief Specific value and unit. */ - NamedSuffix( int value, unit_t unit ) + NamedSuffix( qint64 value, unit_t unit ) : m_value( value ) , m_unit( unit ) { @@ -75,7 +75,7 @@ public: for ( const auto& suffix : table.table ) if ( s.endsWith( suffix.first ) ) { - m_value = s.left( s.length() - suffix.first.length() ).toInt(); + m_value = s.left( s.length() - suffix.first.length() ).toLongLong(); m_unit = suffix.second; break; } @@ -89,7 +89,7 @@ public: */ NamedSuffix( const QString& s ); - int value() const { return m_value; } + qint64 value() const { return m_value; } unit_t unit() const { return m_unit; } /** @brief Check that a value-unit combination is valid. @@ -100,7 +100,7 @@ public: bool isValid() const; protected: - int m_value; + qint64 m_value; unit_t m_unit; }; diff --git a/src/libcalamares/utils/Variant.cpp b/src/libcalamares/utils/Variant.cpp index 2e7a13eed..c56f9301a 100644 --- a/src/libcalamares/utils/Variant.cpp +++ b/src/libcalamares/utils/Variant.cpp @@ -61,10 +61,10 @@ getString( const QVariantMap& map, const QString& key ) return QString(); } -int -getInteger( const QVariantMap& map, const QString& key, int d ) +qint64 +getInteger( const QVariantMap& map, const QString& key, qint64 d ) { - int result = d; + qint64 result = d; if ( map.contains( key ) ) { auto v = map.value( key ); @@ -72,6 +72,10 @@ getInteger( const QVariantMap& map, const QString& key, int d ) { result = v.toInt(); } + else if ( v.type() == QVariant::LongLong ) + { + result = v.toLongLong(); + } } return result; diff --git a/src/libcalamares/utils/Variant.h b/src/libcalamares/utils/Variant.h index c68c2a801..15f791b74 100644 --- a/src/libcalamares/utils/Variant.h +++ b/src/libcalamares/utils/Variant.h @@ -41,7 +41,7 @@ DLLEXPORT QString getString( const QVariantMap& map, const QString& key ); /** * Get an integer value from a mapping; returns @p d if no value. */ -DLLEXPORT int getInteger( const QVariantMap& map, const QString& key, int d ); +DLLEXPORT qint64 getInteger( const QVariantMap& map, const QString& key, qint64 d ); /** * Get a double value from a mapping (integers are converted); returns @p d if no value. diff --git a/src/libcalamares/utils/Yaml.cpp b/src/libcalamares/utils/Yaml.cpp index cad6ac1fe..164c17a21 100644 --- a/src/libcalamares/utils/Yaml.cpp +++ b/src/libcalamares/utils/Yaml.cpp @@ -79,7 +79,7 @@ yamlScalarToVariant( const YAML::Node& scalarNode ) } if ( QRegExp( "[-+]?\\d+" ).exactMatch( scalarString ) ) { - return QVariant( scalarString.toInt() ); + return QVariant( scalarString.toLongLong() ); } if ( QRegExp( "[-+]?\\d*\\.?\\d+" ).exactMatch( scalarString ) ) { From 3929557a5ac5ad69af6f6ada1a9a3c04941d9c9d Mon Sep 17 00:00:00 2001 From: Arnaud Ferraris Date: Thu, 25 Jul 2019 09:53:02 +0200 Subject: [PATCH 09/32] welcome: Fix requirements parsing As the config files integer are now of type `QVariant::LongLong` instead of `QVariant::Int`, requirements relying on this type were not parsed correctly. This patch fixes this, and adds an option to the python conversion to take into account `QVariant::LongLong` types. Signed-off-by: Arnaud Ferraris --- src/libcalamares/PythonHelper.cpp | 3 +++ src/modules/welcome/checker/GeneralRequirements.cpp | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/PythonHelper.cpp b/src/libcalamares/PythonHelper.cpp index 40210856b..670390d6c 100644 --- a/src/libcalamares/PythonHelper.cpp +++ b/src/libcalamares/PythonHelper.cpp @@ -52,6 +52,9 @@ variantToPyObject( const QVariant& variant ) case QVariant::Int: return bp::object( variant.toInt() ); + case QVariant::LongLong: + return bp::object( variant.toLongLong() ); + case QVariant::Double: return bp::object( variant.toDouble() ); diff --git a/src/modules/welcome/checker/GeneralRequirements.cpp b/src/modules/welcome/checker/GeneralRequirements.cpp index 812605091..0e6133d3f 100644 --- a/src/modules/welcome/checker/GeneralRequirements.cpp +++ b/src/modules/welcome/checker/GeneralRequirements.cpp @@ -206,7 +206,7 @@ GeneralRequirements::setConfigurationMap( const QVariantMap& configurationMap ) if ( configurationMap.contains( "requiredStorage" ) && ( configurationMap.value( "requiredStorage" ).type() == QVariant::Double || - configurationMap.value( "requiredStorage" ).type() == QVariant::Int ) ) + configurationMap.value( "requiredStorage" ).type() == QVariant::LongLong ) ) { bool ok = false; m_requiredStorageGiB = configurationMap.value( "requiredStorage" ).toDouble( &ok ); @@ -227,7 +227,7 @@ GeneralRequirements::setConfigurationMap( const QVariantMap& configurationMap ) if ( configurationMap.contains( "requiredRam" ) && ( configurationMap.value( "requiredRam" ).type() == QVariant::Double || - configurationMap.value( "requiredRam" ).type() == QVariant::Int ) ) + configurationMap.value( "requiredRam" ).type() == QVariant::LongLong ) ) { bool ok = false; m_requiredRamGiB = configurationMap.value( "requiredRam" ).toDouble( &ok ); From 0716a46eb2a79668c727bfc5b24f539306cd65e2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 12 Aug 2019 15:52:59 +0200 Subject: [PATCH 10/32] [libcalamares] Switch to using KPluginFactory - this is not entirely straightfoward, since we need different constructor arguments for the objects Calamares creates (no QVariantList& args, in particular). Implement our own registerPlugin() and createInstance() for that. - work around a bug in K_PLUGIN_FACTORY_DECLARATION_WITH_BASEFACTORY --- src/libcalamares/CMakeLists.txt | 1 + src/libcalamares/utils/PluginFactory.cpp | 11 +++ src/libcalamares/utils/PluginFactory.h | 69 ++++++++++++++++++- .../modulesystem/CppJobModule.cpp | 2 +- .../modulesystem/ViewModule.cpp | 2 +- 5 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 src/libcalamares/utils/PluginFactory.cpp diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index c6f8cd0d2..f2063813c 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -44,6 +44,7 @@ set( libSources utils/CommandList.cpp utils/Dirs.cpp utils/Logger.cpp + utils/PluginFactory.cpp utils/Retranslator.cpp utils/String.cpp utils/UMask.cpp diff --git a/src/libcalamares/utils/PluginFactory.cpp b/src/libcalamares/utils/PluginFactory.cpp new file mode 100644 index 000000000..7e1b29921 --- /dev/null +++ b/src/libcalamares/utils/PluginFactory.cpp @@ -0,0 +1,11 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019, Adriaan de Groot + * + */ + +#include "PluginFactory.h" + +CalamaresPluginFactory::~CalamaresPluginFactory() +{ +} diff --git a/src/libcalamares/utils/PluginFactory.h b/src/libcalamares/utils/PluginFactory.h index 2ba9fd3cd..20c82c464 100644 --- a/src/libcalamares/utils/PluginFactory.h +++ b/src/libcalamares/utils/PluginFactory.h @@ -28,10 +28,75 @@ #define CalamaresPluginFactory_iid "io.calamares.PluginFactory" +/** @brief Plugin factory for Calamares + * + * Try to re-use KPluginFactory as much as possible (since the + * old code for PluginFactory was a fork of an old version of + * exactly that). + * + * The current createInstance() method passes more arguments + * to the job and viewstep constructors than we want; chasing + * that change means modifying each Calamares module. This class + * implements a version of createInstance() with fewer arguments + * and overloads registerPlugin() to use that. + */ +class CalamaresPluginFactory : public KPluginFactory +{ + Q_OBJECT +public: + explicit CalamaresPluginFactory() : KPluginFactory() {} + ~CalamaresPluginFactory() override; + + /** @brief Create an object from the factory. + * + * Ignores all the @p args since they are not used. Calls + * Calamares constructors for the Jobs and ViewSteps. + */ + template + static QObject *createInstance(QWidget *parentWidget, QObject *parent, const QVariantList &args) + { + Q_UNUSED(parentWidget); + Q_UNUSED(args); + ParentType *p = nullptr; + if (parent) { + p = qobject_cast(parent); + Q_ASSERT(p); + } + return new impl(p); + } + + /** @brief register a plugin + * + * The Calamares version doesn't accept keywords, and uses + * the Calamares createInstance() version which ignores + * the QVariantList of arguments. + */ + template + void registerPlugin() + { + KPluginFactory::registerPlugin(QString(), &createInstance); + } +}; + +/** @brief declare a Calamares Plugin Factory + * + * This would be defined as K_PLUGIN_FACTORY_DECLARATION_WITH_BASEFACTORY, + * except that does not actually use the base factory class that is + * passed in. + */ #define CALAMARES_PLUGIN_FACTORY_DECLARATION(name) \ - K_PLUGIN_FACTORY_DECLARATION_WITH_BASEFACTORY_SKEL(name,KPluginFactory,Q_PLUGIN_METADATA(IID CalamaresPluginFactory_iid)) + class name : public CalamaresPluginFactory \ + { \ + Q_OBJECT \ + Q_INTERFACES(KPluginFactory) \ + Q_PLUGIN_METADATA(IID CalamaresPluginFactory_iid) \ + public: \ + explicit name(); \ + ~name(); \ + }; #define CALAMARES_PLUGIN_FACTORY_DEFINITION(name, pluginRegistrations) \ - K_PLUGIN_FACTORY_DEFINITION(name, pluginRegistrations ) + K_PLUGIN_FACTORY_DEFINITION_WITH_BASEFACTORY(name,CalamaresPluginFactory,pluginRegistrations) + // Q_DECLARE_INTERFACE( Calamares::PluginFactory, CalamaresPluginFactory_iid ) diff --git a/src/libcalamaresui/modulesystem/CppJobModule.cpp b/src/libcalamaresui/modulesystem/CppJobModule.cpp index 17c191024..c6571dbf6 100644 --- a/src/libcalamaresui/modulesystem/CppJobModule.cpp +++ b/src/libcalamaresui/modulesystem/CppJobModule.cpp @@ -49,7 +49,7 @@ CppJobModule::loadSelf() { if ( m_loader ) { - PluginFactory* pf = qobject_cast< PluginFactory* >( m_loader->instance() ); + CalamaresPluginFactory* pf = qobject_cast< CalamaresPluginFactory* >( m_loader->instance() ); if ( !pf ) { cDebug() << Q_FUNC_INFO << m_loader->errorString(); diff --git a/src/libcalamaresui/modulesystem/ViewModule.cpp b/src/libcalamaresui/modulesystem/ViewModule.cpp index 5cd2fe7d9..7506e5348 100644 --- a/src/libcalamaresui/modulesystem/ViewModule.cpp +++ b/src/libcalamaresui/modulesystem/ViewModule.cpp @@ -50,7 +50,7 @@ ViewModule::loadSelf() { if ( m_loader ) { - PluginFactory* pf = qobject_cast< PluginFactory* >( m_loader->instance() ); + CalamaresPluginFactory* pf = qobject_cast< CalamaresPluginFactory* >( m_loader->instance() ); if ( !pf ) { cWarning() << Q_FUNC_INFO << "No factory:" << m_loader->errorString(); From 209e8331b7843e1dbc2ead5931a8354074865b43 Mon Sep 17 00:00:00 2001 From: Arnaud Ferraris Date: Mon, 22 Jul 2019 16:29:39 +0200 Subject: [PATCH 11/32] libcalamares: Add support for KB/MB/GB size units Currently, all size units are expressed as KiB, MiB or GiB (resp. 2^10, 2^20 or 2^30). In order to maximize compatibility and consistent results with other partitioning tools, this commit adds support for sizes expressed as KB, MB or GB (resp. 10^3, 10^6 or 10^9). This change won't affect existing users, it simply adds a new option that wasn't previously handled. Signed-off-by: Arnaud Ferraris --- src/libcalamares/partition/PartitionSize.cpp | 27 +++++++++- src/libcalamares/partition/PartitionSize.h | 3 ++ src/libcalamares/utils/Units.h | 54 ++++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/src/libcalamares/partition/PartitionSize.cpp b/src/libcalamares/partition/PartitionSize.cpp index 3f4463f3c..bdb9eaad8 100644 --- a/src/libcalamares/partition/PartitionSize.cpp +++ b/src/libcalamares/partition/PartitionSize.cpp @@ -33,7 +33,8 @@ unitSuffixes() { QStringLiteral( "%" ), SizeUnit::Percent }, { QStringLiteral( "K" ), SizeUnit::KiB }, { QStringLiteral( "KiB" ), SizeUnit::KiB }, { QStringLiteral( "M" ), SizeUnit::MiB }, { QStringLiteral( "MiB" ), SizeUnit::MiB }, { QStringLiteral( "G" ), SizeUnit::GiB }, - { QStringLiteral( "GiB" ), SizeUnit::GiB } + { QStringLiteral( "GiB" ), SizeUnit::GiB }, { QStringLiteral( "KB" ), SizeUnit::KB }, + { QStringLiteral( "MB" ), SizeUnit::MB }, { QStringLiteral( "GB" ), SizeUnit::GB } }; return names; @@ -90,8 +91,11 @@ PartitionSize::toSectors( qint64 totalSectors, qint64 sectorSize ) const return totalSectors * value() / 100; } case SizeUnit::Byte: + case SizeUnit::KB: case SizeUnit::KiB: + case SizeUnit::MB: case SizeUnit::MiB: + case SizeUnit::GB: case SizeUnit::GiB: return CalamaresUtils::bytesToSectors( toBytes(), sectorSize ); } @@ -125,8 +129,11 @@ PartitionSize::toBytes( qint64 totalSectors, qint64 sectorSize ) const return totalSectors * value() / 100; } case SizeUnit::Byte: + case SizeUnit::KB: case SizeUnit::KiB: + case SizeUnit::MB: case SizeUnit::MiB: + case SizeUnit::GB: case SizeUnit::GiB: return toBytes(); } @@ -161,8 +168,11 @@ PartitionSize::toBytes( qint64 totalBytes ) const return totalBytes * value() / 100; } case SizeUnit::Byte: + case SizeUnit::KB: case SizeUnit::KiB: + case SizeUnit::MB: case SizeUnit::MiB: + case SizeUnit::GB: case SizeUnit::GiB: return toBytes(); } @@ -186,10 +196,16 @@ PartitionSize::toBytes() const return -1; case SizeUnit::Byte: return value(); + case SizeUnit::KB: + return CalamaresUtils::KBtoBytes( static_cast< unsigned long long >( value() ) ); case SizeUnit::KiB: return CalamaresUtils::KiBtoBytes( static_cast< unsigned long long >( value() ) ); + case SizeUnit::MB: + return CalamaresUtils::MBtoBytes( static_cast< unsigned long long >( value() ) ); case SizeUnit::MiB: return CalamaresUtils::MiBtoBytes( static_cast< unsigned long long >( value() ) ); + case SizeUnit::GB: + return CalamaresUtils::GBtoBytes( static_cast< unsigned long long >( value() ) ); case SizeUnit::GiB: return CalamaresUtils::GiBtoBytes( static_cast< unsigned long long >( value() ) ); } @@ -211,8 +227,11 @@ PartitionSize::operator<( const PartitionSize& other ) const case SizeUnit::Percent: return ( m_value < other.m_value ); case SizeUnit::Byte: + case SizeUnit::KB: case SizeUnit::KiB: + case SizeUnit::MB: case SizeUnit::MiB: + case SizeUnit::GB: case SizeUnit::GiB: return ( toBytes() < other.toBytes() ); } @@ -234,8 +253,11 @@ PartitionSize::operator>( const PartitionSize& other ) const case SizeUnit::Percent: return ( m_value > other.m_value ); case SizeUnit::Byte: + case SizeUnit::KB: case SizeUnit::KiB: + case SizeUnit::MB: case SizeUnit::MiB: + case SizeUnit::GB: case SizeUnit::GiB: return ( toBytes() > other.toBytes() ); } @@ -257,8 +279,11 @@ PartitionSize::operator==( const PartitionSize& other ) const case SizeUnit::Percent: return ( m_value == other.m_value ); case SizeUnit::Byte: + case SizeUnit::KB: case SizeUnit::KiB: + case SizeUnit::MB: case SizeUnit::MiB: + case SizeUnit::GB: case SizeUnit::GiB: return ( toBytes() == other.toBytes() ); } diff --git a/src/libcalamares/partition/PartitionSize.h b/src/libcalamares/partition/PartitionSize.h index 44cedbffe..b22698e55 100644 --- a/src/libcalamares/partition/PartitionSize.h +++ b/src/libcalamares/partition/PartitionSize.h @@ -36,8 +36,11 @@ enum class SizeUnit None, Percent, Byte, + KB, KiB, + MB, MiB, + GB, GiB }; diff --git a/src/libcalamares/utils/Units.h b/src/libcalamares/utils/Units.h index e1f30460a..b869d7dde 100644 --- a/src/libcalamares/utils/Units.h +++ b/src/libcalamares/utils/Units.h @@ -25,54 +25,108 @@ namespace CalamaresUtils { +/** User defined literals, 1_KB is 1 KiloByte (= 10^3 bytes) */ +constexpr qint64 operator""_KB( unsigned long long m ) +{ + return qint64( m ) * 1000; +} + /** User defined literals, 1_KiB is 1 KibiByte (= 2^10 bytes) */ constexpr qint64 operator""_KiB( unsigned long long m ) { return qint64( m ) * 1024; } +/** User defined literals, 1_MB is 1 MegaByte (= 10^6 bytes) */ +constexpr qint64 operator""_MB( unsigned long long m ) +{ + return operator""_KB(m)*1000; +} + /** User defined literals, 1_MiB is 1 MibiByte (= 2^20 bytes) */ constexpr qint64 operator""_MiB( unsigned long long m ) { return operator""_KiB(m)*1024; } +/** User defined literals, 1_GB is 1 GigaByte (= 10^9 bytes) */ +constexpr qint64 operator""_GB( unsigned long long m ) +{ + return operator""_MB(m)*1000; +} + /** User defined literals, 1_GiB is 1 GibiByte (= 2^30 bytes) */ constexpr qint64 operator""_GiB( unsigned long long m ) { return operator""_MiB(m)*1024; } +constexpr qint64 +KBtoBytes( unsigned long long m ) +{ + return operator""_KB( m ); +} + constexpr qint64 KiBtoBytes( unsigned long long m ) { return operator""_KiB( m ); } +constexpr qint64 +MBtoBytes( unsigned long long m ) +{ + return operator""_MB( m ); +} + constexpr qint64 MiBtoBytes( unsigned long long m ) { return operator""_MiB( m ); } +constexpr qint64 +GBtoBytes( unsigned long long m ) +{ + return operator""_GB( m ); +} + constexpr qint64 GiBtoBytes( unsigned long long m ) { return operator""_GiB( m ); } +constexpr qint64 +KBtoBytes( double m ) +{ + return qint64( m * 1000 ); +} + constexpr qint64 KiBtoBytes( double m ) { return qint64( m * 1024 ); } +constexpr qint64 +MBtoBytes( double m ) +{ + return qint64( m * 1000 * 1000 ); +} + constexpr qint64 MiBtoBytes( double m ) { return qint64( m * 1024 * 1024 ); } +constexpr qint64 +GBtoBytes( double m ) +{ + return qint64( m * 1000 * 1000 * 1000 ); +} + constexpr qint64 GiBtoBytes( double m ) { From 40202705ffd397757d74f9c0ab1ac82ce990a2c9 Mon Sep 17 00:00:00 2001 From: Arnaud Ferraris Date: Mon, 22 Jul 2019 16:33:00 +0200 Subject: [PATCH 12/32] libcalamares: Align partition sizes on actual sectors Currently, the `bytesToSectors()` function rounds a partition size to the nearest MiB unit, which may lead to inconsistencies when a partition is expected to only be a few KiB's. This patch changes the behaviour of `bytesToSectors()` so that it aligns on sector size, without rounding the partition size to a multiple of 1MiB. Signed-off-by: Arnaud Ferraris --- src/libcalamares/utils/Units.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcalamares/utils/Units.h b/src/libcalamares/utils/Units.h index b869d7dde..7b8b8c172 100644 --- a/src/libcalamares/utils/Units.h +++ b/src/libcalamares/utils/Units.h @@ -160,7 +160,7 @@ alignBytesToBlockSize( qint64 bytes, qint64 blocksize ) constexpr qint64 bytesToSectors( qint64 bytes, qint64 blocksize ) { - return alignBytesToBlockSize( alignBytesToBlockSize( bytes, blocksize ), MiBtoBytes( 1ULL ) ) / blocksize; + return alignBytesToBlockSize( bytes, blocksize ) / blocksize; } } // namespace CalamaresUtils From a51d612afa456191b5c88be2ac32f89c06f09fba Mon Sep 17 00:00:00 2001 From: Arnaud Ferraris Date: Tue, 13 Aug 2019 16:57:47 +0200 Subject: [PATCH 13/32] Revert "libcalamares: Align partition sizes on actual sectors" This reverts commit 40202705ffd397757d74f9c0ab1ac82ce990a2c9. --- src/libcalamares/utils/Units.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcalamares/utils/Units.h b/src/libcalamares/utils/Units.h index 7b8b8c172..b869d7dde 100644 --- a/src/libcalamares/utils/Units.h +++ b/src/libcalamares/utils/Units.h @@ -160,7 +160,7 @@ alignBytesToBlockSize( qint64 bytes, qint64 blocksize ) constexpr qint64 bytesToSectors( qint64 bytes, qint64 blocksize ) { - return alignBytesToBlockSize( bytes, blocksize ) / blocksize; + return alignBytesToBlockSize( alignBytesToBlockSize( bytes, blocksize ), MiBtoBytes( 1ULL ) ) / blocksize; } } // namespace CalamaresUtils From c57a30c73fb28718bfa0ad1bb7ababa49d26cf76 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 17:06:27 +0200 Subject: [PATCH 14/32] Changes: credit where due for recent PRs --- CHANGES | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES b/CHANGES index 00ea25223..3f4aad749 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,8 @@ website will have to do for older versions. # 3.2.13 (unreleased) # This release contains contributions from (alphabetically by first name): + - Arnaud Ferraris + - Arnaud Rebillout ## Core ## From ccd707b23a82d1f426ec93af315f893c72cbde06 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 20:49:58 +0200 Subject: [PATCH 15/32] [libcalamares] Apply coding style - .. or, rather, avoid re-formatting tables in future. --- src/libcalamares/partition/PartitionSize.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/libcalamares/partition/PartitionSize.cpp b/src/libcalamares/partition/PartitionSize.cpp index 90431fb70..fc8d72582 100644 --- a/src/libcalamares/partition/PartitionSize.cpp +++ b/src/libcalamares/partition/PartitionSize.cpp @@ -29,13 +29,22 @@ namespace Partition static const NamedEnumTable< SizeUnit >& unitSuffixes() { + // *INDENT-OFF* + // clang-format off static const NamedEnumTable< SizeUnit > names { - { QStringLiteral( "%" ), SizeUnit::Percent }, { QStringLiteral( "K" ), SizeUnit::KiB }, - { QStringLiteral( "KiB" ), SizeUnit::KiB }, { QStringLiteral( "M" ), SizeUnit::MiB }, - { QStringLiteral( "MiB" ), SizeUnit::MiB }, { QStringLiteral( "G" ), SizeUnit::GiB }, - { QStringLiteral( "GiB" ), SizeUnit::GiB }, { QStringLiteral( "KB" ), SizeUnit::KB }, - { QStringLiteral( "MB" ), SizeUnit::MB }, { QStringLiteral( "GB" ), SizeUnit::GB } + { QStringLiteral( "%" ), SizeUnit::Percent }, + { QStringLiteral( "K" ), SizeUnit::KiB }, + { QStringLiteral( "KiB" ), SizeUnit::KiB }, + { QStringLiteral( "M" ), SizeUnit::MiB }, + { QStringLiteral( "MiB" ), SizeUnit::MiB }, + { QStringLiteral( "G" ), SizeUnit::GiB }, + { QStringLiteral( "GiB" ), SizeUnit::GiB }, + { QStringLiteral( "KB" ), SizeUnit::KB }, + { QStringLiteral( "MB" ), SizeUnit::MB }, + { QStringLiteral( "GB" ), SizeUnit::GB } }; + // clang-format on + // *INDENT-ON* return names; } From f31ff8b9ea4ae05aaaf349b3bf66999212a3c500 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 20:50:52 +0200 Subject: [PATCH 16/32] [libcalamares] Apply coding style to PluginFactory --- src/libcalamares/utils/PluginFactory.cpp | 4 +-- src/libcalamares/utils/PluginFactory.h | 38 +++++++++++++----------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/libcalamares/utils/PluginFactory.cpp b/src/libcalamares/utils/PluginFactory.cpp index 7e1b29921..50b88ebfd 100644 --- a/src/libcalamares/utils/PluginFactory.cpp +++ b/src/libcalamares/utils/PluginFactory.cpp @@ -6,6 +6,4 @@ #include "PluginFactory.h" -CalamaresPluginFactory::~CalamaresPluginFactory() -{ -} +CalamaresPluginFactory::~CalamaresPluginFactory() {} diff --git a/src/libcalamares/utils/PluginFactory.h b/src/libcalamares/utils/PluginFactory.h index 20c82c464..84694a83a 100644 --- a/src/libcalamares/utils/PluginFactory.h +++ b/src/libcalamares/utils/PluginFactory.h @@ -44,7 +44,10 @@ class CalamaresPluginFactory : public KPluginFactory { Q_OBJECT public: - explicit CalamaresPluginFactory() : KPluginFactory() {} + explicit CalamaresPluginFactory() + : KPluginFactory() + { + } ~CalamaresPluginFactory() override; /** @brief Create an object from the factory. @@ -52,17 +55,18 @@ public: * Ignores all the @p args since they are not used. Calls * Calamares constructors for the Jobs and ViewSteps. */ - template - static QObject *createInstance(QWidget *parentWidget, QObject *parent, const QVariantList &args) + template < class impl, class ParentType > + static QObject* createInstance( QWidget* parentWidget, QObject* parent, const QVariantList& args ) { - Q_UNUSED(parentWidget); - Q_UNUSED(args); - ParentType *p = nullptr; - if (parent) { - p = qobject_cast(parent); - Q_ASSERT(p); + Q_UNUSED( parentWidget ); + Q_UNUSED( args ); + ParentType* p = nullptr; + if ( parent ) + { + p = qobject_cast< ParentType* >( parent ); + Q_ASSERT( p ); } - return new impl(p); + return new impl( p ); } /** @brief register a plugin @@ -71,10 +75,10 @@ public: * the Calamares createInstance() version which ignores * the QVariantList of arguments. */ - template + template < class T > void registerPlugin() { - KPluginFactory::registerPlugin(QString(), &createInstance); + KPluginFactory::registerPlugin< T >( QString(), &createInstance< T, QObject > ); } }; @@ -84,18 +88,18 @@ public: * except that does not actually use the base factory class that is * passed in. */ -#define CALAMARES_PLUGIN_FACTORY_DECLARATION(name) \ +#define CALAMARES_PLUGIN_FACTORY_DECLARATION( name ) \ class name : public CalamaresPluginFactory \ { \ Q_OBJECT \ - Q_INTERFACES(KPluginFactory) \ - Q_PLUGIN_METADATA(IID CalamaresPluginFactory_iid) \ + Q_INTERFACES( KPluginFactory ) \ + Q_PLUGIN_METADATA( IID CalamaresPluginFactory_iid ) \ public: \ explicit name(); \ ~name(); \ }; -#define CALAMARES_PLUGIN_FACTORY_DEFINITION(name, pluginRegistrations) \ - K_PLUGIN_FACTORY_DEFINITION_WITH_BASEFACTORY(name,CalamaresPluginFactory,pluginRegistrations) +#define CALAMARES_PLUGIN_FACTORY_DEFINITION( name, pluginRegistrations ) \ + K_PLUGIN_FACTORY_DEFINITION_WITH_BASEFACTORY( name, CalamaresPluginFactory, pluginRegistrations ) // Q_DECLARE_INTERFACE( Calamares::PluginFactory, CalamaresPluginFactory_iid ) From 27c3a5a11d4739e5fe7081e72b48ed5318443f42 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 20:51:46 +0200 Subject: [PATCH 17/32] [calamares] Apply coding style --- src/calamares/CalamaresVersion.h.in | 2 +- src/calamares/progresstree/ProgressTreeView.cpp | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/calamares/CalamaresVersion.h.in b/src/calamares/CalamaresVersion.h.in index 13a8c9e2e..4ac7ee1d1 100644 --- a/src/calamares/CalamaresVersion.h.in +++ b/src/calamares/CalamaresVersion.h.in @@ -14,4 +14,4 @@ #cmakedefine CALAMARES_TRANSLATION_LANGUAGES "${CALAMARES_TRANSLATION_LANGUAGES}" -#endif // CALAMARES_VERSION_H +#endif // CALAMARES_VERSION_H diff --git a/src/calamares/progresstree/ProgressTreeView.cpp b/src/calamares/progresstree/ProgressTreeView.cpp index d4f652363..5c81e3851 100644 --- a/src/calamares/progresstree/ProgressTreeView.cpp +++ b/src/calamares/progresstree/ProgressTreeView.cpp @@ -76,10 +76,9 @@ ProgressTreeView::setModel( QAbstractItemModel* model ) QTreeView::setModel( model ); expandAll(); - connect( - Calamares::ViewManager::instance(), - &Calamares::ViewManager::currentStepChanged, - this, - [this]() { viewport()->update(); }, - Qt::UniqueConnection ); + connect( Calamares::ViewManager::instance(), + &Calamares::ViewManager::currentStepChanged, + this, + [this]() { viewport()->update(); }, + Qt::UniqueConnection ); } From 6224d6605b20be6580b49b6ff1dbf2badc515834 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 20:57:52 +0200 Subject: [PATCH 18/32] [libcalamaresui] Apply coding style to widgets/ --- src/libcalamaresui/widgets/ClickableLabel.cpp | 11 +++++++---- src/libcalamaresui/widgets/ClickableLabel.h | 2 +- .../widgets/FixedAspectRatioLabel.cpp | 17 +++++------------ .../widgets/FixedAspectRatioLabel.h | 4 ++-- src/libcalamaresui/widgets/WaitingWidget.h | 2 +- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/libcalamaresui/widgets/ClickableLabel.cpp b/src/libcalamaresui/widgets/ClickableLabel.cpp index b6786cab8..62985acf8 100644 --- a/src/libcalamaresui/widgets/ClickableLabel.cpp +++ b/src/libcalamaresui/widgets/ClickableLabel.cpp @@ -23,16 +23,17 @@ ClickableLabel::ClickableLabel( QWidget* parent ) : QLabel( parent ) -{} +{ +} ClickableLabel::ClickableLabel( const QString& text, QWidget* parent ) : QLabel( text, parent ) -{} +{ +} -ClickableLabel::~ClickableLabel() -{} +ClickableLabel::~ClickableLabel() {} void @@ -48,5 +49,7 @@ ClickableLabel::mouseReleaseEvent( QMouseEvent* event ) { QLabel::mouseReleaseEvent( event ); if ( m_time.elapsed() < qApp->doubleClickInterval() ) + { emit clicked(); + } } diff --git a/src/libcalamaresui/widgets/ClickableLabel.h b/src/libcalamaresui/widgets/ClickableLabel.h index ab993c721..fd66082c5 100644 --- a/src/libcalamaresui/widgets/ClickableLabel.h +++ b/src/libcalamaresui/widgets/ClickableLabel.h @@ -42,4 +42,4 @@ private: QTime m_time; }; -#endif // CLICKABLELABEL_H +#endif // CLICKABLELABEL_H diff --git a/src/libcalamaresui/widgets/FixedAspectRatioLabel.cpp b/src/libcalamaresui/widgets/FixedAspectRatioLabel.cpp index d1094bb7c..c495ca5bb 100644 --- a/src/libcalamaresui/widgets/FixedAspectRatioLabel.cpp +++ b/src/libcalamaresui/widgets/FixedAspectRatioLabel.cpp @@ -22,21 +22,18 @@ FixedAspectRatioLabel::FixedAspectRatioLabel( QWidget* parent ) : QLabel( parent ) -{} +{ +} -FixedAspectRatioLabel::~FixedAspectRatioLabel() -{} +FixedAspectRatioLabel::~FixedAspectRatioLabel() {} void FixedAspectRatioLabel::setPixmap( const QPixmap& pixmap ) { m_pixmap = pixmap; - QLabel::setPixmap( pixmap.scaled( - contentsRect().size(), - Qt::KeepAspectRatio, - Qt::SmoothTransformation ) ); + QLabel::setPixmap( pixmap.scaled( contentsRect().size(), Qt::KeepAspectRatio, Qt::SmoothTransformation ) ); } @@ -44,9 +41,5 @@ void FixedAspectRatioLabel::resizeEvent( QResizeEvent* event ) { Q_UNUSED( event ) - QLabel::setPixmap( m_pixmap.scaled( - contentsRect().size(), - Qt::KeepAspectRatio, - Qt::SmoothTransformation ) ); + QLabel::setPixmap( m_pixmap.scaled( contentsRect().size(), Qt::KeepAspectRatio, Qt::SmoothTransformation ) ); } - diff --git a/src/libcalamaresui/widgets/FixedAspectRatioLabel.h b/src/libcalamaresui/widgets/FixedAspectRatioLabel.h index 8f881753c..9466fcd15 100644 --- a/src/libcalamaresui/widgets/FixedAspectRatioLabel.h +++ b/src/libcalamaresui/widgets/FixedAspectRatioLabel.h @@ -31,11 +31,11 @@ public: virtual ~FixedAspectRatioLabel() override; public slots: - void setPixmap( const QPixmap &pixmap ); + void setPixmap( const QPixmap& pixmap ); void resizeEvent( QResizeEvent* event ) override; private: QPixmap m_pixmap; }; -#endif // FIXEDASPECTRATIOLABEL_H +#endif // FIXEDASPECTRATIOLABEL_H diff --git a/src/libcalamaresui/widgets/WaitingWidget.h b/src/libcalamaresui/widgets/WaitingWidget.h index 5c19cce26..0d8b6fd5b 100644 --- a/src/libcalamaresui/widgets/WaitingWidget.h +++ b/src/libcalamaresui/widgets/WaitingWidget.h @@ -35,4 +35,4 @@ private: QLabel* m_waitingLabel; }; -#endif // WAITINGWIDGET_H +#endif // WAITINGWIDGET_H From 1b6aed8c402f1898727833b450c269e39e0856dd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 20:58:39 +0200 Subject: [PATCH 19/32] [libcalamaresui] Apply coding style to modulesystem/ --- src/libcalamaresui/modulesystem/ProcessJobModule.cpp | 2 ++ src/libcalamaresui/modulesystem/RequirementsChecker.cpp | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcalamaresui/modulesystem/ProcessJobModule.cpp b/src/libcalamaresui/modulesystem/ProcessJobModule.cpp index 74c195b6b..fc4b5f254 100644 --- a/src/libcalamaresui/modulesystem/ProcessJobModule.cpp +++ b/src/libcalamaresui/modulesystem/ProcessJobModule.cpp @@ -77,7 +77,9 @@ ProcessJobModule::initFrom( const QVariantMap& moduleDescriptor ) { int sec = moduleDescriptor.value( "timeout" ).toInt(); if ( sec < 0 ) + { sec = 0; + } m_secondsTimeout = std::chrono::seconds( sec ); } diff --git a/src/libcalamaresui/modulesystem/RequirementsChecker.cpp b/src/libcalamaresui/modulesystem/RequirementsChecker.cpp index 916463ae4..41281c9b9 100644 --- a/src/libcalamaresui/modulesystem/RequirementsChecker.cpp +++ b/src/libcalamaresui/modulesystem/RequirementsChecker.cpp @@ -151,8 +151,7 @@ RequirementsChecker::reportProgress() m_progressTimeouts++; QStringList remainingNames; - auto remaining = std::count_if( m_watchers.cbegin(), m_watchers.cend(), - [&]( const Watcher* w ) { + auto remaining = std::count_if( m_watchers.cbegin(), m_watchers.cend(), [&]( const Watcher* w ) { if ( w && !w->isFinished() ) { remainingNames << w->objectName(); From 6f74463a80d608808c2136c617bd2672da9dacd9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 21:00:36 +0200 Subject: [PATCH 20/32] [libcalamaresui] Apply coding style to utils/ --- src/libcalamaresui/utils/CalamaresUtilsGui.cpp | 18 ++++++++++++++---- src/libcalamaresui/utils/CalamaresUtilsGui.h | 12 +++++------- src/libcalamaresui/utils/ImageRegistry.cpp | 2 +- src/libcalamaresui/utils/ImageRegistry.h | 2 +- src/libcalamaresui/utils/PythonQtUtils.cpp | 4 +++- src/libcalamaresui/utils/PythonQtUtils.h | 4 ++-- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp index 808c805cb..b6c927763 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp @@ -34,11 +34,10 @@ namespace CalamaresUtils { -static int s_defaultFontSize = 0; +static int s_defaultFontSize = 0; static int s_defaultFontHeight = 0; - QPixmap defaultPixmap( ImageType type, ImageMode mode, const QSize& size ) { @@ -152,11 +151,15 @@ createRoundedImage( const QPixmap& pixmap, const QSize& size, float frameWidthPc } if ( !height || !width ) + { return QPixmap(); + } QPixmap scaledAvatar = pixmap.scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); if ( frameWidthPct == 0.00f ) + { return scaledAvatar; + } QPixmap frame( width, height ); frame.fill( Qt::transparent ); @@ -172,7 +175,8 @@ createRoundedImage( const QPixmap& pixmap, const QSize& size, float frameWidthPc painter.setBrush( brush ); painter.setPen( pen ); - painter.drawRoundedRect( outerRect, qreal( frameWidthPct ) * 100.0, qreal( frameWidthPct ) * 100.0, Qt::RelativeSize ); + painter.drawRoundedRect( + outerRect, qreal( frameWidthPct ) * 100.0, qreal( frameWidthPct ) * 100.0, Qt::RelativeSize ); return frame; } @@ -189,7 +193,9 @@ unmarginLayout( QLayout* layout ) { QLayout* childLayout = layout->itemAt( i )->layout(); if ( childLayout ) + { unmarginLayout( childLayout ); + } } } @@ -255,13 +261,17 @@ clearLayout( QLayout* layout ) while ( QLayoutItem* item = layout->takeAt( 0 ) ) { if ( QWidget* widget = item->widget() ) + { widget->deleteLater(); + } if ( QLayout* childLayout = item->layout() ) + { clearLayout( childLayout ); + } delete item; } } -} // namespace +} // namespace CalamaresUtils diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.h b/src/libcalamaresui/utils/CalamaresUtilsGui.h index 72430a083..012795e34 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.h +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.h @@ -56,7 +56,7 @@ enum ImageType : int PartitionTable, BootEnvironment, Squid, - StatusOk, // Icons for the requirements checker + StatusOk, // Icons for the requirements checker StatusWarning, StatusError }; @@ -94,9 +94,7 @@ UIDLLEXPORT QPixmap defaultPixmap( ImageType type, * @return the transformed pixmap. * This one is currently unused. */ -UIDLLEXPORT QPixmap createRoundedImage( const QPixmap& avatar, - const QSize& size, - float frameWidthPct = 0.20f ); +UIDLLEXPORT QPixmap createRoundedImage( const QPixmap& avatar, const QSize& size, float frameWidthPct = 0.20f ); /** * @brief unmarginLayout recursively walks the QLayout tree and removes all margins. @@ -112,8 +110,8 @@ UIDLLEXPORT void unmarginLayout( QLayout* layout ); UIDLLEXPORT void clearLayout( QLayout* layout ); UIDLLEXPORT void setDefaultFontSize( int points ); -UIDLLEXPORT int defaultFontSize(); // in points -UIDLLEXPORT int defaultFontHeight(); // in pixels, DPI-specific +UIDLLEXPORT int defaultFontSize(); // in points +UIDLLEXPORT int defaultFontHeight(); // in pixels, DPI-specific UIDLLEXPORT QFont defaultFont(); UIDLLEXPORT QFont largeFont(); UIDLLEXPORT QSize defaultIconSize(); @@ -128,4 +126,4 @@ constexpr int windowPreferredHeight = 520; } // namespace CalamaresUtils -#endif // CALAMARESUTILSGUI_H +#endif // CALAMARESUTILSGUI_H diff --git a/src/libcalamaresui/utils/ImageRegistry.cpp b/src/libcalamaresui/utils/ImageRegistry.cpp index 5cffac11c..1c3b9433e 100644 --- a/src/libcalamaresui/utils/ImageRegistry.cpp +++ b/src/libcalamaresui/utils/ImageRegistry.cpp @@ -2,7 +2,7 @@ * * SPDX-License-Identifier: GPLv3+ * License-Filename: LICENSES/GPLv3+-ImageRegistry - * + * * Copyright 2019, Adriaan de Groot */ diff --git a/src/libcalamaresui/utils/ImageRegistry.h b/src/libcalamaresui/utils/ImageRegistry.h index 06ab45831..454cb500d 100644 --- a/src/libcalamaresui/utils/ImageRegistry.h +++ b/src/libcalamaresui/utils/ImageRegistry.h @@ -2,7 +2,7 @@ * * SPDX-License-Identifier: GPLv3+ * License-Filename: LICENSES/GPLv3+-ImageRegistry - * + * * Copyright 2019, Adriaan de Groot */ diff --git a/src/libcalamaresui/utils/PythonQtUtils.cpp b/src/libcalamaresui/utils/PythonQtUtils.cpp index 201fe6635..3a60839a4 100644 --- a/src/libcalamaresui/utils/PythonQtUtils.cpp +++ b/src/libcalamaresui/utils/PythonQtUtils.cpp @@ -34,11 +34,13 @@ lookupAndCall( PyObject* object, { PythonQtObjectPtr callable = PythonQt::self()->lookupCallable( object, name ); if ( callable ) + { return callable.call( args, kwargs ); + } } // If we haven't found a callable with the given names, we force an error: return PythonQt::self()->call( object, candidateNames.first(), args, kwargs ); } -} +} // namespace CalamaresUtils diff --git a/src/libcalamaresui/utils/PythonQtUtils.h b/src/libcalamaresui/utils/PythonQtUtils.h index 22a248cea..dc889b2d0 100644 --- a/src/libcalamaresui/utils/PythonQtUtils.h +++ b/src/libcalamaresui/utils/PythonQtUtils.h @@ -33,6 +33,6 @@ QVariant lookupAndCall( PyObject* object, const QVariantList& args = QVariantList(), const QVariantMap& kwargs = QVariantMap() ); -} //ns +} // namespace CalamaresUtils -#endif // PYTHONQTUTILS_H +#endif // PYTHONQTUTILS_H From d44e8f61153096595cf6272e17688696e3ddc433 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 21:02:30 +0200 Subject: [PATCH 21/32] [libcalamaresui] Apply coding style to viewpages/ --- .../viewpages/BlankViewStep.cpp | 13 +-- src/libcalamaresui/viewpages/BlankViewStep.h | 7 +- .../PythonQtGlobalStorageWrapper.cpp | 3 +- .../viewpages/PythonQtGlobalStorageWrapper.h | 2 +- src/libcalamaresui/viewpages/PythonQtJob.cpp | 28 +++---- src/libcalamaresui/viewpages/PythonQtJob.h | 15 ++-- .../viewpages/PythonQtUtilsWrapper.cpp | 61 +++++--------- .../viewpages/PythonQtUtilsWrapper.h | 26 ++---- .../viewpages/PythonQtViewStep.cpp | 81 ++++++++----------- .../viewpages/PythonQtViewStep.h | 7 +- src/libcalamaresui/viewpages/ViewStep.cpp | 25 +++--- src/libcalamaresui/viewpages/ViewStep.h | 9 +-- 12 files changed, 110 insertions(+), 167 deletions(-) diff --git a/src/libcalamaresui/viewpages/BlankViewStep.cpp b/src/libcalamaresui/viewpages/BlankViewStep.cpp index 243305c1f..af10c7a99 100644 --- a/src/libcalamaresui/viewpages/BlankViewStep.cpp +++ b/src/libcalamaresui/viewpages/BlankViewStep.cpp @@ -26,7 +26,10 @@ namespace Calamares { -BlankViewStep::BlankViewStep( const QString& title, const QString& description, const QString& details, QObject* parent) +BlankViewStep::BlankViewStep( const QString& title, + const QString& description, + const QString& details, + QObject* parent ) : Calamares::ViewStep( parent ) , m_widget( new QWidget() ) { @@ -54,14 +57,12 @@ BlankViewStep::BlankViewStep( const QString& title, const QString& description, layout->addWidget( label ); } - layout->addStretch( 1 ); // Push the rest to the top + layout->addStretch( 1 ); // Push the rest to the top m_widget->setLayout( layout ); } -BlankViewStep::~BlankViewStep() -{ -} +BlankViewStep::~BlankViewStep() {} QString BlankViewStep::prettyName() const @@ -115,4 +116,4 @@ BlankViewStep::jobs() const return JobList(); } -} // namespace +} // namespace Calamares diff --git a/src/libcalamaresui/viewpages/BlankViewStep.h b/src/libcalamaresui/viewpages/BlankViewStep.h index a3f46d1d5..17d323c85 100644 --- a/src/libcalamaresui/viewpages/BlankViewStep.h +++ b/src/libcalamaresui/viewpages/BlankViewStep.h @@ -39,7 +39,10 @@ class BlankViewStep : public Calamares::ViewStep Q_OBJECT public: - explicit BlankViewStep( const QString& title, const QString& description, const QString& details = QString(), QObject* parent = nullptr ); + explicit BlankViewStep( const QString& title, + const QString& description, + const QString& details = QString(), + QObject* parent = nullptr ); virtual ~BlankViewStep() override; QString prettyName() const override; @@ -61,5 +64,5 @@ private: QWidget* m_widget; }; -} // namespace +} // namespace Calamares #endif // BLANKVIEWSTEP_H diff --git a/src/libcalamaresui/viewpages/PythonQtGlobalStorageWrapper.cpp b/src/libcalamaresui/viewpages/PythonQtGlobalStorageWrapper.cpp index 4eae8cf98..ba7657b09 100644 --- a/src/libcalamaresui/viewpages/PythonQtGlobalStorageWrapper.cpp +++ b/src/libcalamaresui/viewpages/PythonQtGlobalStorageWrapper.cpp @@ -24,7 +24,8 @@ GlobalStorage::GlobalStorage( Calamares::GlobalStorage* gs ) : QObject( gs ) , m_gs( gs ) -{} +{ +} bool diff --git a/src/libcalamaresui/viewpages/PythonQtGlobalStorageWrapper.h b/src/libcalamaresui/viewpages/PythonQtGlobalStorageWrapper.h index 8a8b775fc..946f93e97 100644 --- a/src/libcalamaresui/viewpages/PythonQtGlobalStorageWrapper.h +++ b/src/libcalamaresui/viewpages/PythonQtGlobalStorageWrapper.h @@ -54,4 +54,4 @@ private: Calamares::GlobalStorage* m_gs; }; -#endif // PYTHONQTGLOBALSTORAGEWRAPPER_H +#endif // PYTHONQTGLOBALSTORAGEWRAPPER_H diff --git a/src/libcalamaresui/viewpages/PythonQtJob.cpp b/src/libcalamaresui/viewpages/PythonQtJob.cpp index 291cbd014..0718df95d 100644 --- a/src/libcalamaresui/viewpages/PythonQtJob.cpp +++ b/src/libcalamaresui/viewpages/PythonQtJob.cpp @@ -20,34 +20,26 @@ #include "utils/PythonQtUtils.h" -PythonQtJob::PythonQtJob( PythonQtObjectPtr cxt, - PythonQtObjectPtr pyJob, - QObject* parent ) +PythonQtJob::PythonQtJob( PythonQtObjectPtr cxt, PythonQtObjectPtr pyJob, QObject* parent ) : Calamares::Job( parent ) , m_cxt( cxt ) , m_pyJob( pyJob ) { - } QString PythonQtJob::prettyName() const { - return CalamaresUtils::lookupAndCall( m_pyJob, - { "prettyName", - "prettyname", - "pretty_name" } ).toString(); + return CalamaresUtils::lookupAndCall( m_pyJob, { "prettyName", "prettyname", "pretty_name" } ).toString(); } QString PythonQtJob::prettyDescription() const { - return CalamaresUtils::lookupAndCall( m_pyJob, - { "prettyDescription", - "prettydescription", - "pretty_description" } ).toString(); + return CalamaresUtils::lookupAndCall( m_pyJob, { "prettyDescription", "prettydescription", "pretty_description" } ) + .toString(); } @@ -55,9 +47,8 @@ QString PythonQtJob::prettyStatusMessage() const { return CalamaresUtils::lookupAndCall( m_pyJob, - { "prettyStatusMessage", - "prettystatusmessage", - "pretty_status_message" } ).toString(); + { "prettyStatusMessage", "prettystatusmessage", "pretty_status_message" } ) + .toString(); } @@ -66,12 +57,15 @@ PythonQtJob::exec() { QVariant response = m_pyJob.call( "exec" ); if ( response.isNull() ) + { return Calamares::JobResult::ok(); + } QVariantMap map = response.toMap(); if ( map.isEmpty() || map.value( "ok" ).toBool() ) + { return Calamares::JobResult::ok(); + } - return Calamares::JobResult::error( map.value( "message" ).toString(), - map.value( "details" ).toString() ); + return Calamares::JobResult::error( map.value( "message" ).toString(), map.value( "details" ).toString() ); } diff --git a/src/libcalamaresui/viewpages/PythonQtJob.h b/src/libcalamaresui/viewpages/PythonQtJob.h index 2b50c0ded..a73e7eb82 100644 --- a/src/libcalamaresui/viewpages/PythonQtJob.h +++ b/src/libcalamaresui/viewpages/PythonQtJob.h @@ -32,12 +32,11 @@ class PythonQtJobResult : public QObject, public Calamares::JobResult { Q_OBJECT public: - explicit PythonQtJobResult( bool ok, - const QString& message, - const QString& details ) + explicit PythonQtJobResult( bool ok, const QString& message, const QString& details ) : QObject( nullptr ) , Calamares::JobResult( message, details, ok ? 0 : Calamares::JobResult::GenericError ) - {} + { + } }; @@ -53,13 +52,11 @@ public: Calamares::JobResult exec() override; private: - explicit PythonQtJob( PythonQtObjectPtr cxt, - PythonQtObjectPtr pyJob, - QObject* parent = nullptr ); - friend class Calamares::PythonQtViewStep; // only this one can call the ctor + explicit PythonQtJob( PythonQtObjectPtr cxt, PythonQtObjectPtr pyJob, QObject* parent = nullptr ); + friend class Calamares::PythonQtViewStep; // only this one can call the ctor PythonQtObjectPtr m_cxt; PythonQtObjectPtr m_pyJob; }; -#endif // PYTHONQTJOB_H +#endif // PYTHONQTJOB_H diff --git a/src/libcalamaresui/viewpages/PythonQtUtilsWrapper.cpp b/src/libcalamaresui/viewpages/PythonQtUtilsWrapper.cpp index 69027d018..c13e063bd 100644 --- a/src/libcalamaresui/viewpages/PythonQtUtilsWrapper.cpp +++ b/src/libcalamaresui/viewpages/PythonQtUtilsWrapper.cpp @@ -25,7 +25,7 @@ #include -Utils::Utils(QObject* parent) +Utils::Utils( QObject* parent ) : QObject( parent ) , m_exceptionCxt( PythonQt::self()->createUniqueModule() ) { @@ -34,7 +34,7 @@ Utils::Utils(QObject* parent) void -Utils::debug(const QString& s) const +Utils::debug( const QString& s ) const { cDebug() << "PythonQt DBG>" << s; } @@ -46,35 +46,28 @@ Utils::mount( const QString& device_path, const QString& filesystem_name, const QString& options ) const { - return CalamaresUtils::System::instance()-> - mount( device_path, mount_point, filesystem_name, options ); + return CalamaresUtils::System::instance()->mount( device_path, mount_point, filesystem_name, options ); } int -Utils::target_env_call( const QString& command, - const QString& stdin, - int timeout ) const +Utils::target_env_call( const QString& command, const QString& stdin, int timeout ) const { - return CalamaresUtils::System::instance()-> - targetEnvCall( command, QString(), stdin, std::chrono::seconds( timeout > 0 ? timeout : 0 ) ); + return CalamaresUtils::System::instance()->targetEnvCall( + command, QString(), stdin, std::chrono::seconds( timeout > 0 ? timeout : 0 ) ); } int -Utils::target_env_call( const QStringList& args, - const QString& stdin, - int timeout ) const +Utils::target_env_call( const QStringList& args, const QString& stdin, int timeout ) const { - return CalamaresUtils::System::instance()-> - targetEnvCall( args, QString(), stdin, std::chrono::seconds( timeout > 0 ? timeout : 0 ) ); + return CalamaresUtils::System::instance()->targetEnvCall( + args, QString(), stdin, std::chrono::seconds( timeout > 0 ? timeout : 0 ) ); } int -Utils::check_target_env_call( const QString& command, - const QString& stdin, - int timeout ) const +Utils::check_target_env_call( const QString& command, const QString& stdin, int timeout ) const { int ec = target_env_call( command, stdin, timeout ); return _handle_check_target_env_call_error( ec, command ); @@ -82,9 +75,7 @@ Utils::check_target_env_call( const QString& command, int -Utils::check_target_env_call( const QStringList& args, - const QString& stdin, - int timeout) const +Utils::check_target_env_call( const QStringList& args, const QString& stdin, int timeout ) const { int ec = target_env_call( args, stdin, timeout ); return _handle_check_target_env_call_error( ec, args.join( ' ' ) ); @@ -92,34 +83,22 @@ Utils::check_target_env_call( const QStringList& args, QString -Utils::check_target_env_output( const QString& command, - const QString& stdin, - int timeout ) const +Utils::check_target_env_output( const QString& command, const QString& stdin, int timeout ) const { QString output; - int ec = CalamaresUtils::System::instance()-> - targetEnvOutput( command, - output, - QString(), - stdin, - std::chrono::seconds( timeout > 0 ? timeout : 0 ) ); + int ec = CalamaresUtils::System::instance()->targetEnvOutput( + command, output, QString(), stdin, std::chrono::seconds( timeout > 0 ? timeout : 0 ) ); _handle_check_target_env_call_error( ec, command ); return output; } QString -Utils::check_target_env_output( const QStringList& args, - const QString& stdin, - int timeout ) const +Utils::check_target_env_output( const QStringList& args, const QString& stdin, int timeout ) const { QString output; - int ec = CalamaresUtils::System::instance()-> - targetEnvOutput( args, - output, - QString(), - stdin, - std::chrono::seconds( timeout > 0 ? timeout : 0 ) ); + int ec = CalamaresUtils::System::instance()->targetEnvOutput( + args, output, QString(), stdin, std::chrono::seconds( timeout > 0 ? timeout : 0 ) ); _handle_check_target_env_call_error( ec, args.join( ' ' ) ); return output; } @@ -133,13 +112,11 @@ Utils::obscure( const QString& string ) const int -Utils::_handle_check_target_env_call_error( int ec, const QString& cmd) const +Utils::_handle_check_target_env_call_error( int ec, const QString& cmd ) const { if ( ec ) { - QString raise = QString( "raise subprocess.CalledProcessError(%1,\"%2\")" ) - .arg( ec ) - .arg( cmd ); + QString raise = QString( "raise subprocess.CalledProcessError(%1,\"%2\")" ).arg( ec ).arg( cmd ); PythonQt::self()->evalScript( m_exceptionCxt, raise ); } return ec; diff --git a/src/libcalamaresui/viewpages/PythonQtUtilsWrapper.h b/src/libcalamaresui/viewpages/PythonQtUtilsWrapper.h index ea6955337..19b8b623d 100644 --- a/src/libcalamaresui/viewpages/PythonQtUtilsWrapper.h +++ b/src/libcalamaresui/viewpages/PythonQtUtilsWrapper.h @@ -43,29 +43,17 @@ public slots: const QString& filesystem_name, const QString& options ) const; - int target_env_call( const QString& command, - const QString& stdin = QString(), - int timeout = 0 ) const; + int target_env_call( const QString& command, const QString& stdin = QString(), int timeout = 0 ) const; - int target_env_call( const QStringList& args, - const QString& stdin = QString(), - int timeout = 0 ) const; + int target_env_call( const QStringList& args, const QString& stdin = QString(), int timeout = 0 ) const; - int check_target_env_call( const QString& command, - const QString& stdin = QString(), - int timeout = 0 ) const; + int check_target_env_call( const QString& command, const QString& stdin = QString(), int timeout = 0 ) const; - int check_target_env_call( const QStringList& args, - const QString& stdin = QString(), - int timeout = 0 ) const; + int check_target_env_call( const QStringList& args, const QString& stdin = QString(), int timeout = 0 ) const; - QString check_target_env_output( const QString& command, - const QString& stdin = QString(), - int timeout = 0 ) const; + QString check_target_env_output( const QString& command, const QString& stdin = QString(), int timeout = 0 ) const; - QString check_target_env_output( const QStringList& args, - const QString& stdin = QString(), - int timeout = 0 ) const; + QString check_target_env_output( const QStringList& args, const QString& stdin = QString(), int timeout = 0 ) const; QString obscure( const QString& string ) const; @@ -75,4 +63,4 @@ private: PythonQtObjectPtr m_exceptionCxt; }; -#endif // PYTHONQTUTILSWRAPPER_H +#endif // PYTHONQTUTILSWRAPPER_H diff --git a/src/libcalamaresui/viewpages/PythonQtViewStep.cpp b/src/libcalamaresui/viewpages/PythonQtViewStep.cpp index 2d128d1af..5e313ff98 100644 --- a/src/libcalamaresui/viewpages/PythonQtViewStep.cpp +++ b/src/libcalamaresui/viewpages/PythonQtViewStep.cpp @@ -18,8 +18,8 @@ */ #include "PythonQtViewStep.h" -#include "utils/Logger.h" #include "utils/CalamaresUtilsGui.h" +#include "utils/Logger.h" #include "utils/PythonQtUtils.h" #include "utils/Retranslator.h" #include "viewpages/PythonQtJob.h" @@ -33,8 +33,7 @@ namespace Calamares { -PythonQtViewStep::PythonQtViewStep( PythonQtObjectPtr cxt, - QObject* parent ) +PythonQtViewStep::PythonQtViewStep( PythonQtObjectPtr cxt, QObject* parent ) : ViewStep( parent ) , m_widget( new QWidget() ) , m_cxt( cxt ) @@ -48,32 +47,26 @@ PythonQtViewStep::PythonQtViewStep( PythonQtObjectPtr cxt, // Instantiate an object of the class marked with @calamares_module and // store it as _calamares_module. - pq->evalScript( m_cxt, QString( "_calamares_module = %1()" ) - .arg( className ) ); + pq->evalScript( m_cxt, QString( "_calamares_module = %1()" ).arg( className ) ); m_obj = pq->lookupObject( m_cxt, "_calamares_module" ); - Q_ASSERT( !m_obj.isNull() ); // no entry point, no party + Q_ASSERT( !m_obj.isNull() ); // no entry point, no party // Prepare the base widget for the module's pages m_widget->setLayout( new QVBoxLayout ); CalamaresUtils::unmarginLayout( m_widget->layout() ); m_cxt.addObject( "_calamares_module_basewidget", m_widget ); - CALAMARES_RETRANSLATE_WIDGET( m_widget, - CalamaresUtils::lookupAndCall( m_obj, - { "retranslate" }, - { CalamaresUtils::translatorLocaleName() } ); - ) + CALAMARES_RETRANSLATE_WIDGET( + m_widget, + CalamaresUtils::lookupAndCall( m_obj, { "retranslate" }, { CalamaresUtils::translatorLocaleName() } ); ) } QString PythonQtViewStep::prettyName() const { - return CalamaresUtils::lookupAndCall( m_obj, - { "prettyName", - "prettyname", - "pretty_name" } ).toString(); + return CalamaresUtils::lookupAndCall( m_obj, { "prettyName", "prettyname", "pretty_name" } ).toString(); } @@ -82,12 +75,14 @@ PythonQtViewStep::widget() { if ( m_widget->layout()->count() > 1 ) cWarning() << "PythonQtViewStep wrapper widget has more than 1 child. " - "This should never happen."; + "This should never happen."; - bool nothingChanged = m_cxt.evalScript( - "_calamares_module.widget() in _calamares_module_basewidget.children()" ).toBool(); + bool nothingChanged + = m_cxt.evalScript( "_calamares_module.widget() in _calamares_module_basewidget.children()" ).toBool(); if ( nothingChanged ) + { return m_widget; + } // Else, we either don't have a child widget, or we have a child widget that // was previously set and doesn't apply any more since the Python module @@ -97,10 +92,11 @@ PythonQtViewStep::widget() // We only remove from the layout and not delete because Python is in charge // of memory management for these widgets. while ( m_widget->layout()->itemAt( 0 ) ) + { m_widget->layout()->takeAt( 0 ); + } - m_cxt.evalScript( - "_calamares_module_basewidget.layout().addWidget(_calamares_module.widget())" ); + m_cxt.evalScript( "_calamares_module_basewidget.layout().addWidget(_calamares_module.widget())" ); return m_widget; } @@ -123,58 +119,40 @@ PythonQtViewStep::back() bool PythonQtViewStep::isNextEnabled() const { - return CalamaresUtils::lookupAndCall( m_obj, - { "isNextEnabled", - "isnextenabled", - "is_next_enabled" } ).toBool(); + return CalamaresUtils::lookupAndCall( m_obj, { "isNextEnabled", "isnextenabled", "is_next_enabled" } ).toBool(); } bool PythonQtViewStep::isBackEnabled() const { - return CalamaresUtils::lookupAndCall( m_obj, - { "isBackEnabled", - "isbackenabled", - "is_back_enabled" } ).toBool(); + return CalamaresUtils::lookupAndCall( m_obj, { "isBackEnabled", "isbackenabled", "is_back_enabled" } ).toBool(); } bool PythonQtViewStep::isAtBeginning() const { - return CalamaresUtils::lookupAndCall( m_obj, - { "isAtBeginning", - "isatbeginning", - "is_at_beginning" } ).toBool(); + return CalamaresUtils::lookupAndCall( m_obj, { "isAtBeginning", "isatbeginning", "is_at_beginning" } ).toBool(); } bool PythonQtViewStep::isAtEnd() const { - return CalamaresUtils::lookupAndCall( m_obj, - { "isAtEnd", - "isatend", - "is_at_end" } ).toBool(); + return CalamaresUtils::lookupAndCall( m_obj, { "isAtEnd", "isatend", "is_at_end" } ).toBool(); } void -PythonQtViewStep::onActivate() +PythonQtViewStep::onActivate() { - CalamaresUtils::lookupAndCall( m_obj, - { "onActivate", - "onactivate", - "on_activate" }); + CalamaresUtils::lookupAndCall( m_obj, { "onActivate", "onactivate", "on_activate" } ); } void PythonQtViewStep::onLeave() { - CalamaresUtils::lookupAndCall( m_obj, - { "onLeave", - "onleave", - "on_leave" }); + CalamaresUtils::lookupAndCall( m_obj, { "onLeave", "onleave", "on_leave" } ); } @@ -185,21 +163,29 @@ PythonQtViewStep::jobs() const PythonQtObjectPtr jobsCallable = PythonQt::self()->lookupCallable( m_obj, "jobs" ); if ( jobsCallable.isNull() ) + { return jobs; + } PythonQtObjectPtr response = PythonQt::self()->callAndReturnPyObject( jobsCallable ); if ( response.isNull() ) + { return jobs; + } PythonQtObjectPtr listPopCallable = PythonQt::self()->lookupCallable( response, "pop" ); if ( listPopCallable.isNull() ) + { return jobs; + } forever { PythonQtObjectPtr aJob = PythonQt::self()->callAndReturnPyObject( listPopCallable, { 0 } ); if ( aJob.isNull() ) + { break; + } jobs.append( Calamares::job_ptr( new PythonQtJob( m_cxt, aJob ) ) ); } @@ -219,9 +205,8 @@ QWidget* PythonQtViewStep::createScriptingConsole() { PythonQtScriptingConsole* console = new PythonQtScriptingConsole( nullptr, m_cxt ); - console->setProperty( "classname", - m_cxt.getVariable( "_calamares_module_typename" ).toString() ); + console->setProperty( "classname", m_cxt.getVariable( "_calamares_module_typename" ).toString() ); return console; } -} +} // namespace Calamares diff --git a/src/libcalamaresui/viewpages/PythonQtViewStep.h b/src/libcalamaresui/viewpages/PythonQtViewStep.h index b6b7c193b..5358bc824 100644 --- a/src/libcalamaresui/viewpages/PythonQtViewStep.h +++ b/src/libcalamaresui/viewpages/PythonQtViewStep.h @@ -30,8 +30,7 @@ class PythonQtViewStep : public Calamares::ViewStep { Q_OBJECT public: - PythonQtViewStep( PythonQtObjectPtr cxt, - QObject* parent = nullptr ); + PythonQtViewStep( PythonQtObjectPtr cxt, QObject* parent = nullptr ); QString prettyName() const override; @@ -62,6 +61,6 @@ private: PythonQtObjectPtr m_obj; }; -} +} // namespace Calamares -#endif // PYTHONQTVIEWSTEP_H +#endif // PYTHONQTVIEWSTEP_H diff --git a/src/libcalamaresui/viewpages/ViewStep.cpp b/src/libcalamaresui/viewpages/ViewStep.cpp index cdfc7bbc9..af1e347eb 100644 --- a/src/libcalamaresui/viewpages/ViewStep.cpp +++ b/src/libcalamaresui/viewpages/ViewStep.cpp @@ -24,11 +24,11 @@ namespace Calamares ViewStep::ViewStep( QObject* parent ) : QObject( parent ) -{} +{ +} -ViewStep::~ViewStep() -{} +ViewStep::~ViewStep() {} QString @@ -45,20 +45,24 @@ ViewStep::createSummaryWidget() const void ViewStep::onActivate() -{} +{ +} void ViewStep::onLeave() -{} +{ +} void ViewStep::next() -{} +{ +} void ViewStep::back() -{} +{ +} void @@ -69,10 +73,7 @@ ViewStep::setModuleInstanceKey( const QString& instanceKey ) void -ViewStep::setConfigurationMap( const QVariantMap& configurationMap ) -{ - Q_UNUSED( configurationMap ) -} +ViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { Q_UNUSED( configurationMap ) } RequirementsList ViewStep::checkRequirements() @@ -80,4 +81,4 @@ RequirementsList ViewStep::checkRequirements() return RequirementsList(); } -} +} // namespace Calamares diff --git a/src/libcalamaresui/viewpages/ViewStep.h b/src/libcalamaresui/viewpages/ViewStep.h index e3d5a021e..8c5020f83 100644 --- a/src/libcalamaresui/viewpages/ViewStep.h +++ b/src/libcalamaresui/viewpages/ViewStep.h @@ -130,10 +130,7 @@ public: virtual JobList jobs() const = 0; void setModuleInstanceKey( const QString& instanceKey ); - QString moduleInstanceKey() const - { - return m_instanceKey; - } + QString moduleInstanceKey() const { return m_instanceKey; } virtual void setConfigurationMap( const QVariantMap& configurationMap ); @@ -161,6 +158,6 @@ protected: }; using ViewStepList = QList< ViewStep* >; -} +} // namespace Calamares -#endif // VIEWSTEP_H +#endif // VIEWSTEP_H From e7dedbbfe0363aa0ff0256d48d30c66bc960cf10 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 21:07:46 +0200 Subject: [PATCH 22/32] [libcalamaresui] Apply coding style to remainder --- src/libcalamaresui/Branding.cpp | 8 +++++ src/libcalamaresui/Branding.h | 43 ++++++++++++++++-------- src/libcalamaresui/ExecutionViewStep.cpp | 24 +++++++------ src/libcalamaresui/ExecutionViewStep.h | 2 +- src/libcalamaresui/UiDllMacro.h | 10 +++--- 5 files changed, 56 insertions(+), 31 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index d3b0de97d..98dbab06c 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -52,6 +52,8 @@ Branding::instance() } +// *INDENT-OFF* +// clang-format off const QStringList Branding::s_stringEntryStrings = { "productName", @@ -82,15 +84,21 @@ const QStringList Branding::s_styleEntryStrings = "sidebarTextSelect", "sidebarTextHighlight" }; +// clang-format on +// *INDENT-ON* const NamedEnumTable& Branding::WindowDimension::suffixes() { using Unit = Branding::WindowDimensionUnit; + // *INDENT-OFF* + // clang-format off static const NamedEnumTable names{ {"px", Unit::Pixies}, {"em", Unit::Fonties} }; + // clang-format on + // *INDENT-ON* return names; } diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index a3909bc00..3723fd07f 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -25,13 +25,13 @@ #include "utils/NamedSuffix.h" +#include #include #include -#include namespace YAML { - class Node; +class Node; } namespace Calamares @@ -79,27 +79,39 @@ public: }; /** @brief Setting for how much the main window may expand. */ - enum class WindowExpansion { Normal, Fullscreen, Fixed } ; + 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 + enum class WindowDimensionUnit + { + None, + Pixies, + Fonties + }; + class WindowDimension : public NamedSuffix< WindowDimensionUnit, WindowDimensionUnit::None > { public: - static const NamedEnumTable< WindowDimensionUnit >& suffixes(); + static const NamedEnumTable< WindowDimensionUnit >& suffixes(); bool isValid() const; using NamedSuffix::NamedSuffix; - WindowDimension( const QString& s ) : NamedSuffix( suffixes(), s ) {} - } ; + WindowDimension( const QString& s ) + : NamedSuffix( suffixes(), s ) + { + } + }; static Branding* instance(); - explicit Branding( const QString& brandingFilePath, - QObject* parent = nullptr ); + explicit Branding( const QString& brandingFilePath, QObject* parent = nullptr ); /** @brief Complete path of the branding descriptor file. */ QString descriptorPath() const { return m_descriptorPath; } @@ -184,11 +196,14 @@ private: WindowExpansion m_windowExpansion; WindowDimension m_windowHeight, m_windowWidth; - }; -template inline QString operator*(U e) { return Branding::instance()->string( e ); } - +template < typename U > +inline QString operator*( U e ) +{ + return Branding::instance()->string( e ); } -#endif // BRANDING_H +} // namespace Calamares + +#endif // BRANDING_H diff --git a/src/libcalamaresui/ExecutionViewStep.cpp b/src/libcalamaresui/ExecutionViewStep.cpp index e242622a0..4dd10bd93 100644 --- a/src/libcalamaresui/ExecutionViewStep.cpp +++ b/src/libcalamaresui/ExecutionViewStep.cpp @@ -23,10 +23,10 @@ #include "Branding.h" #include "Job.h" #include "JobQueue.h" -#include "modulesystem/Module.h" -#include "modulesystem/ModuleManager.h" #include "Settings.h" #include "ViewManager.h" +#include "modulesystem/Module.h" +#include "modulesystem/ModuleManager.h" #include "utils/CalamaresUtilsGui.h" #include "utils/Dirs.h" @@ -56,7 +56,7 @@ callQMLFunction( QQuickItem* qmlObject, const char* method ) QByteArray methodSignature( method ); methodSignature.append( "()" ); - if ( qmlObject && qmlObject->metaObject()->indexOfMethod( methodSignature ) >= 0 ) + if ( qmlObject && qmlObject->metaObject()->indexOfMethod( methodSignature ) >= 0 ) { QVariant returnValue; QMetaObject::invokeMethod( qmlObject, method, Q_RETURN_ARG( QVariant, returnValue ) ); @@ -117,9 +117,7 @@ ExecutionViewStep::ExecutionViewStep( QObject* parent ) QString ExecutionViewStep::prettyName() const { - return Calamares::Settings::instance()->isSetupMode() - ? tr( "Set up" ) - : tr( "Install" ); + return Calamares::Settings::instance()->isSetupMode() ? tr( "Set up" ) : tr( "Install" ); } @@ -176,8 +174,7 @@ ExecutionViewStep::loadQmlV2() { m_qmlComponent = new QQmlComponent( m_qmlShow->engine(), QUrl::fromLocalFile( Calamares::Branding::instance()->slideshowPath() ), - QQmlComponent::CompilationMode::Asynchronous - ); + QQmlComponent::CompilationMode::Asynchronous ); connect( m_qmlComponent, &QQmlComponent::statusChanged, this, &ExecutionViewStep::loadQmlV2Complete ); } } @@ -194,14 +191,17 @@ ExecutionViewStep::loadQmlV2Complete() QObject* o = m_qmlComponent->create(); m_qmlObject = qobject_cast< QQuickItem* >( o ); if ( !m_qmlObject ) + { delete o; + } else { // setContent() is public API, but not documented publicly. // It is marked \internal in the Qt sources, but does exactly // what is needed: sets up visual parent by replacing the root // item, and handling resizes. - m_qmlShow->setContent( QUrl::fromLocalFile( Calamares::Branding::instance()->slideshowPath() ), m_qmlComponent, m_qmlObject ); + m_qmlShow->setContent( + QUrl::fromLocalFile( Calamares::Branding::instance()->slideshowPath() ), m_qmlComponent, m_qmlObject ); if ( ViewManager::instance()->currentStep() == this ) { // We're alreay visible! Must have been slow QML loading, and we @@ -235,8 +235,10 @@ ExecutionViewStep::onActivate() auto jl = module->jobs(); if ( module->isEmergency() ) { - for( auto& j : jl ) + for ( auto& j : jl ) + { j->setEmergency( true ); + } } queue->enqueue( jl ); } @@ -279,4 +281,4 @@ ExecutionViewStep::onLeave() } } -} // namespace +} // namespace Calamares diff --git a/src/libcalamaresui/ExecutionViewStep.h b/src/libcalamaresui/ExecutionViewStep.h index 63594b151..8c4174cdb 100644 --- a/src/libcalamaresui/ExecutionViewStep.h +++ b/src/libcalamaresui/ExecutionViewStep.h @@ -77,6 +77,6 @@ private: void updateFromJobQueue( qreal percent, const QString& message ); }; -} +} // namespace Calamares #endif /* EXECUTIONVIEWSTEP_H */ diff --git a/src/libcalamaresui/UiDllMacro.h b/src/libcalamaresui/UiDllMacro.h index 35ad67453..3064ca68c 100644 --- a/src/libcalamaresui/UiDllMacro.h +++ b/src/libcalamaresui/UiDllMacro.h @@ -22,11 +22,11 @@ #include #ifndef UIDLLEXPORT -# if defined (UIDLLEXPORT_PRO) -# define UIDLLEXPORT Q_DECL_EXPORT -# else -# define UIDLLEXPORT Q_DECL_IMPORT -# endif +#if defined( UIDLLEXPORT_PRO ) +#define UIDLLEXPORT Q_DECL_EXPORT +#else +#define UIDLLEXPORT Q_DECL_IMPORT +#endif #endif #endif From 6b8c0129fdb2a6f3f9a82ea6b45d57b78292a5d3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 22:24:30 +0200 Subject: [PATCH 23/32] [libcalamaresui] Add one more icon (donate) from Breeze - LGPLv3 like the others --- data/images/help-donate.svg | 18 ++++++++++++++++++ src/libcalamaresui/libcalamaresui.qrc | 1 + src/libcalamaresui/utils/CalamaresUtilsGui.cpp | 4 ++++ src/libcalamaresui/utils/CalamaresUtilsGui.h | 1 + 4 files changed, 24 insertions(+) create mode 100644 data/images/help-donate.svg diff --git a/data/images/help-donate.svg b/data/images/help-donate.svg new file mode 100644 index 000000000..2370c127e --- /dev/null +++ b/data/images/help-donate.svg @@ -0,0 +1,18 @@ + + + + + + diff --git a/src/libcalamaresui/libcalamaresui.qrc b/src/libcalamaresui/libcalamaresui.qrc index 79ae4e45f..eeb3fc490 100644 --- a/src/libcalamaresui/libcalamaresui.qrc +++ b/src/libcalamaresui/libcalamaresui.qrc @@ -7,6 +7,7 @@ ../../data/images/bugs.svg ../../data/images/help.svg ../../data/images/release.svg + ../../data/images/help-donate.svg ../../data/images/partition-disk.svg ../../data/images/partition-partition.svg ../../data/images/partition-alongside.svg diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp index b6c927763..bd15d7a68 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp @@ -74,6 +74,10 @@ defaultPixmap( ImageType type, ImageMode mode, const QSize& size ) pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/release.svg", size ); break; + case Donate: + pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/donate.svg", size ); + break; + case PartitionDisk: pixmap = ImageRegistry::instance()->pixmap( RESPATH "images/partition-disk.svg", size ); break; diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.h b/src/libcalamaresui/utils/CalamaresUtilsGui.h index 012795e34..0c10dcc30 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.h +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.h @@ -47,6 +47,7 @@ enum ImageType : int Bugs, Help, Release, + Donate, PartitionDisk, PartitionPartition, PartitionAlongside, From b60ec123a0937e2a65d855ec1447534a5ab42890 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 21:21:19 +0200 Subject: [PATCH 24/32] [branding] [welcome] Document interrelationship of settings --- src/branding/default/branding.desc | 5 ++++- src/modules/welcome/welcome.conf | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index 1bd76cd29..3d1079a8c 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -56,6 +56,9 @@ windowSize: 800px,520px # Note that ANSI_COLOR and CPE_NAME don't make sense here, and # are not supported (the rest are). Remember to quote the string # if it contains substitutions, or you'll get YAML exceptions. +# +# The *Url* entries are used on the welcome page, and they +# are visible as buttons there if the corresponding *show* keys are set. strings: productName: "@{NAME}" shortProductName: Generic @@ -84,7 +87,7 @@ strings: # the window. Use `welcomeExpandingLogo` to make it non-scaled. # Recommended size is 320x150. # -# These strings can also use substitutions from os-release (see above). +# These filenames can also use substitutions from os-release (see above). images: productLogo: "squid.png" productIcon: "squid.png" diff --git a/src/modules/welcome/welcome.conf b/src/modules/welcome/welcome.conf index a89b63854..a430345a2 100644 --- a/src/modules/welcome/welcome.conf +++ b/src/modules/welcome/welcome.conf @@ -7,6 +7,7 @@ # can check requirements for installation. --- # Display settings for various buttons on the welcome page. +# The URLs themselves come from branding.desc showSupportUrl: true showKnownIssuesUrl: true showReleaseNotesUrl: true From 03e506a826dd2c72386babdae3e22171952f25d3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 22:29:01 +0200 Subject: [PATCH 25/32] [welcome] Add a donate button FIXES #1197 --- src/modules/welcome/WelcomePage.cpp | 187 ++++++++++++++---------- src/modules/welcome/WelcomePage.h | 16 +- src/modules/welcome/WelcomePage.ui | 10 ++ src/modules/welcome/WelcomeViewStep.cpp | 41 ++++-- src/modules/welcome/welcome.conf | 7 + 5 files changed, 160 insertions(+), 101 deletions(-) diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index b29b2e23e..6d0fc0d98 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -20,8 +20,8 @@ #include "WelcomePage.h" -#include "ui_WelcomePage.h" #include "checker/CheckerContainer.h" +#include "ui_WelcomePage.h" #include "Branding.h" #include "CalamaresVersion.h" @@ -48,9 +48,18 @@ WelcomePage::WelcomePage( QWidget* parent ) , m_checkingWidget( new CheckerContainer( this ) ) , m_languages( nullptr ) { - connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsResult, m_checkingWidget, &CheckerContainer::requirementsChecked ); - connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsComplete, m_checkingWidget, &CheckerContainer::requirementsComplete ); - connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsProgress, m_checkingWidget, &CheckerContainer::requirementsProgress ); + connect( Calamares::ModuleManager::instance(), + &Calamares::ModuleManager::requirementsResult, + m_checkingWidget, + &CheckerContainer::requirementsChecked ); + connect( Calamares::ModuleManager::instance(), + &Calamares::ModuleManager::requirementsComplete, + m_checkingWidget, + &CheckerContainer::requirementsComplete ); + connect( Calamares::ModuleManager::instance(), + &Calamares::ModuleManager::requirementsProgress, + m_checkingWidget, + &CheckerContainer::requirementsProgress ); ui->setupUi( this ); ui->verticalLayout->insertSpacing( 1, CalamaresUtils::defaultFontHeight() * 2 ); @@ -61,38 +70,31 @@ WelcomePage::WelcomePage( QWidget* parent ) ui->mainText->setOpenExternalLinks( true ); cDebug() << "Welcome string" << Calamares::Branding::instance()->welcomeStyleCalamares() - << *Calamares::Branding::VersionedName; + << *Calamares::Branding::VersionedName; - CALAMARES_RETRANSLATE( - QString message; + CALAMARES_RETRANSLATE( QString message; - if ( Calamares::Settings::instance()->isSetupMode() ) - message = Calamares::Branding::instance()->welcomeStyleCalamares() - ? tr( "

Welcome to the Calamares setup program for %1.

" ) - : tr( "

Welcome to %1 setup.

" ); - else - message = Calamares::Branding::instance()->welcomeStyleCalamares() - ? tr( "

Welcome to the Calamares installer for %1.

" ) - : tr( "

Welcome to the %1 installer.

" ); + if ( Calamares::Settings::instance()->isSetupMode() ) message + = Calamares::Branding::instance()->welcomeStyleCalamares() + ? tr( "

Welcome to the Calamares setup program for %1.

" ) + : tr( "

Welcome to %1 setup.

" ); + else message = Calamares::Branding::instance()->welcomeStyleCalamares() + ? tr( "

Welcome to the Calamares installer for %1.

" ) + : tr( "

Welcome to the %1 installer.

" ); - ui->mainText->setText( message.arg( *Calamares::Branding::VersionedName ) ); - ui->retranslateUi( this ); - ) + ui->mainText->setText( message.arg( *Calamares::Branding::VersionedName ) ); + ui->retranslateUi( this ); ) - ui->aboutButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Information, - CalamaresUtils::Original, - 2*QSize( CalamaresUtils::defaultFontHeight(), - CalamaresUtils::defaultFontHeight() ) ) ); - connect( ui->aboutButton, &QPushButton::clicked, - this, [ this ] - { - QString title = Calamares::Settings::instance()->isSetupMode() - ? tr( "About %1 setup" ) - : tr( "About %1 installer" ); + ui->aboutButton->setIcon( CalamaresUtils::defaultPixmap( + CalamaresUtils::Information, + CalamaresUtils::Original, + 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); + connect( ui->aboutButton, &QPushButton::clicked, this, [this] { + QString title + = Calamares::Settings::instance()->isSetupMode() ? tr( "About %1 setup" ) : tr( "About %1 installer" ); QMessageBox mb( QMessageBox::Information, title.arg( CALAMARES_APPLICATION_NAME ), - tr( - "

%1


" + tr( "

%1


" "%2
" "for %3


" "Copyright 2014-2017 Teo Mrnjavac <teo@kde.org>
" @@ -103,24 +105,23 @@ WelcomePage::WelcomePage( QWidget* parent ) "Calamares " "development is sponsored by
" "Blue Systems - " - "Liberating Software." - ) - .arg( CALAMARES_APPLICATION_NAME ) - .arg( CALAMARES_VERSION ) - .arg( *Calamares::Branding::VersionedName ), + "Liberating Software." ) + .arg( CALAMARES_APPLICATION_NAME ) + .arg( CALAMARES_VERSION ) + .arg( *Calamares::Branding::VersionedName ), QMessageBox::Ok, this ); - mb.setIconPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::Squid, - CalamaresUtils::Original, - QSize( CalamaresUtils::defaultFontHeight() * 6, - CalamaresUtils::defaultFontHeight() * 6 ) ) ); - QGridLayout* layout = reinterpret_cast( mb.layout() ); + mb.setIconPixmap( CalamaresUtils::defaultPixmap( + CalamaresUtils::Squid, + CalamaresUtils::Original, + QSize( CalamaresUtils::defaultFontHeight() * 6, CalamaresUtils::defaultFontHeight() * 6 ) ) ); + QGridLayout* layout = reinterpret_cast< QGridLayout* >( mb.layout() ); if ( layout ) layout->setColumnMinimumWidth( 2, CalamaresUtils::defaultFontHeight() * 24 ); mb.exec(); } ); - ui->verticalLayout->insertWidget( 3, m_checkingWidget); + ui->verticalLayout->insertWidget( 3, m_checkingWidget ); } @@ -139,15 +140,16 @@ WelcomePage::initLanguages() QLocale defaultLocale = QLocale( QLocale::system().name() ); cDebug() << "Matching locale" << defaultLocale; - int matchedLocaleIndex = m_languages->find( - [&](const QLocale& x){ return x.language() == defaultLocale.language() && x.country() == defaultLocale.country(); } ); + int matchedLocaleIndex = m_languages->find( [&]( const QLocale& x ) { + return x.language() == defaultLocale.language() && x.country() == defaultLocale.country(); + } ); if ( matchedLocaleIndex < 0 ) { cDebug() << Logger::SubEntry << "Matching approximate locale" << defaultLocale.language(); - matchedLocaleIndex = m_languages->find( - [&](const QLocale& x){ return x.language() == defaultLocale.language(); } ); + matchedLocaleIndex + = m_languages->find( [&]( const QLocale& x ) { return x.language() == defaultLocale.language(); } ); } if ( matchedLocaleIndex < 0 ) @@ -159,7 +161,9 @@ WelcomePage::initLanguages() // Now, if it matched, because we didn't match the system locale, switch to the one found if ( matchedLocaleIndex >= 0 ) + { QLocale::setDefault( m_languages->locale( matchedLocaleIndex ).locale() ); + } } if ( matchedLocaleIndex >= 0 ) @@ -171,44 +175,36 @@ WelcomePage::initLanguages() ui->languageWidget->setCurrentIndex( matchedLocaleIndex ); } else + { cWarning() << "No available translation matched" << defaultLocale; + } connect( ui->languageWidget, static_cast< void ( QComboBox::* )( int ) >( &QComboBox::currentIndexChanged ), this, - [&]( int newIndex ) - { + [&]( int newIndex ) { const auto& selectedLocale = m_languages->locale( newIndex ).locale(); cDebug() << "Selected locale" << selectedLocale; QLocale::setDefault( selectedLocale ); - CalamaresUtils::installTranslator( selectedLocale, - Calamares::Branding::instance()->translationsDirectory(), - qApp ); + CalamaresUtils::installTranslator( + selectedLocale, Calamares::Branding::instance()->translationsDirectory(), qApp ); } ); } void -WelcomePage::setUpLinks( bool showSupportUrl, - bool showKnownIssuesUrl, - bool showReleaseNotesUrl ) +WelcomePage::setUpLinks( bool showSupportUrl, bool showKnownIssuesUrl, bool showReleaseNotesUrl ) { using namespace Calamares; if ( showSupportUrl && !( *Branding::SupportUrl ).isEmpty() ) { - CALAMARES_RETRANSLATE( - ui->supportButton->setText( tr( "%1 support" ) - .arg( *Branding::ShortProductName ) ); - ) - ui->supportButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Help, - CalamaresUtils::Original, - 2*QSize( CalamaresUtils::defaultFontHeight(), - CalamaresUtils::defaultFontHeight() ) ) ); - connect( ui->supportButton, &QPushButton::clicked, [] - { - QDesktopServices::openUrl( *Branding::SupportUrl ); - } ); + CALAMARES_RETRANSLATE( ui->supportButton->setText( tr( "%1 support" ).arg( *Branding::ShortProductName ) ); ) + ui->supportButton->setIcon( CalamaresUtils::defaultPixmap( + CalamaresUtils::Help, + CalamaresUtils::Original, + 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); + connect( ui->supportButton, &QPushButton::clicked, [] { QDesktopServices::openUrl( *Branding::SupportUrl ); } ); } else { @@ -217,12 +213,11 @@ WelcomePage::setUpLinks( bool showSupportUrl, if ( showKnownIssuesUrl && !( *Branding::KnownIssuesUrl ).isEmpty() ) { - ui->knownIssuesButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Bugs, - CalamaresUtils::Original, - 2*QSize( CalamaresUtils::defaultFontHeight(), - CalamaresUtils::defaultFontHeight() ) ) ); - connect( ui->knownIssuesButton, &QPushButton::clicked, [] - { + ui->knownIssuesButton->setIcon( CalamaresUtils::defaultPixmap( + CalamaresUtils::Bugs, + CalamaresUtils::Original, + 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); + connect( ui->knownIssuesButton, &QPushButton::clicked, [] { QDesktopServices::openUrl( *Branding::KnownIssuesUrl ); } ); } @@ -233,12 +228,11 @@ WelcomePage::setUpLinks( bool showSupportUrl, if ( showReleaseNotesUrl && !( *Branding::ReleaseNotesUrl ).isEmpty() ) { - ui->releaseNotesButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Release, - CalamaresUtils::Original, - 2*QSize( CalamaresUtils::defaultFontHeight(), - CalamaresUtils::defaultFontHeight() ) ) ); - connect( ui->releaseNotesButton, &QPushButton::clicked, [] - { + ui->releaseNotesButton->setIcon( CalamaresUtils::defaultPixmap( + CalamaresUtils::Release, + CalamaresUtils::Original, + 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); + connect( ui->releaseNotesButton, &QPushButton::clicked, [] { QDesktopServices::openUrl( *Branding::ReleaseNotesUrl ); } ); } @@ -249,11 +243,38 @@ WelcomePage::setUpLinks( bool showSupportUrl, } +void +WelcomePage::setupDonateButton( const QString& url ) +{ + if ( url.isEmpty() ) + { + ui->donateButton->hide(); + return; + } + + QUrl u( url ); + if ( u.isValid() ) + { + ui->donateButton->setIcon( CalamaresUtils::defaultPixmap( + CalamaresUtils::Donate, + CalamaresUtils::Original, + 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); + connect( ui->donateButton, &QPushButton::clicked, [u]() { QDesktopServices::openUrl( u ); } ); + } + else + { + qWarning() << "Donate URL" << url << "is invalid."; + ui->donateButton->hide(); + } +} + void WelcomePage::focusInEvent( QFocusEvent* e ) { if ( ui->languageWidget ) + { ui->languageWidget->setFocus(); + } e->accept(); } @@ -267,7 +288,9 @@ void WelcomePage::externallySelectedLanguage( int row ) { if ( ( row >= 0 ) && ( row < ui->languageWidget->count() ) ) + { ui->languageWidget->setCurrentIndex( row ); + } } void @@ -278,8 +301,14 @@ WelcomePage::setLanguageIcon( QPixmap i ) void -LocaleTwoColumnDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const +LocaleTwoColumnDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { QStyledItemDelegate::paint( painter, option, index ); - option.widget->style()->drawItemText( painter, option.rect, Qt::AlignRight | Qt::AlignVCenter, option.palette, false, index.data( CalamaresUtils::Locale::LabelModel::EnglishLabelRole ).toString() ); + option.widget->style()->drawItemText( + painter, + option.rect, + Qt::AlignRight | Qt::AlignVCenter, + option.palette, + false, + index.data( CalamaresUtils::Locale::LabelModel::EnglishLabelRole ).toString() ); } diff --git a/src/modules/welcome/WelcomePage.h b/src/modules/welcome/WelcomePage.h index 6c244bf0c..d8a1bd4f2 100644 --- a/src/modules/welcome/WelcomePage.h +++ b/src/modules/welcome/WelcomePage.h @@ -39,9 +39,10 @@ public: explicit WelcomePage( QWidget* parent = nullptr ); /// @brief Configure the buttons for URLs from the branding configuration - void setUpLinks( bool showSupportUrl, - bool showKnownIssuesUrl, - bool showReleaseNotesUrl ); + void setUpLinks( bool showSupportUrl, bool showKnownIssuesUrl, bool showReleaseNotesUrl ); + /// @brief Configure the "Donate" button + void setupDonateButton( const QString& ); + /// @brief Set international language-selector icon void setLanguageIcon( QPixmap ); @@ -50,8 +51,9 @@ public: /// @brief Change the language from an external source. void externallySelectedLanguage( int row ); + protected: - void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus + void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus private: /// @brief Fill the list of languages with the available translations @@ -59,7 +61,7 @@ private: Ui::WelcomePage* ui; CheckerContainer* m_checkingWidget; - CalamaresUtils::Locale::LabelModel *m_languages; + CalamaresUtils::Locale::LabelModel* m_languages; }; /** @brief Delegate to display language information in two columns. @@ -72,6 +74,6 @@ public: using QStyledItemDelegate::QStyledItemDelegate; void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const override; -} ; +}; -#endif // WELCOMEPAGE_H +#endif // WELCOMEPAGE_H diff --git a/src/modules/welcome/WelcomePage.ui b/src/modules/welcome/WelcomePage.ui index 548bd5d27..0787ac6e7 100644 --- a/src/modules/welcome/WelcomePage.ui +++ b/src/modules/welcome/WelcomePage.ui @@ -134,6 +134,16 @@ + + + + &Donate + + + true + + + diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index 938fe1f45..60dd6f500 100644 --- a/src/modules/welcome/WelcomeViewStep.cpp +++ b/src/modules/welcome/WelcomeViewStep.cpp @@ -33,13 +33,16 @@ #include #include -CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeViewStepFactory, registerPlugin(); ) +CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeViewStepFactory, registerPlugin< WelcomeViewStep >(); ) WelcomeViewStep::WelcomeViewStep( QObject* parent ) : Calamares::ViewStep( parent ) , m_requirementsChecker( new GeneralRequirements( this ) ) { - connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsComplete, this, &WelcomeViewStep::nextStatusChanged ); + connect( Calamares::ModuleManager::instance(), + &Calamares::ModuleManager::requirementsComplete, + this, + &WelcomeViewStep::nextStatusChanged ); m_widget = new WelcomePage(); } @@ -47,7 +50,9 @@ WelcomeViewStep::WelcomeViewStep( QObject* parent ) WelcomeViewStep::~WelcomeViewStep() { if ( m_widget && m_widget->parent() == nullptr ) + { m_widget->deleteLater(); + } } @@ -107,16 +112,17 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) bool showKnownIssuesUrl = CalamaresUtils::getBool( configurationMap, "showKnownIssuesUrl", false ); bool showReleaseNotesUrl = CalamaresUtils::getBool( configurationMap, "showReleaseNotesUrl", false ); - m_widget->setUpLinks( showSupportUrl, - showKnownIssuesUrl, - showReleaseNotesUrl ); + m_widget->setUpLinks( showSupportUrl, showKnownIssuesUrl, showReleaseNotesUrl ); + m_widget->setupDonateButton( CalamaresUtils::getString( configurationMap, "donateUrl" ) ); - if ( configurationMap.contains( "requirements" ) && - configurationMap.value( "requirements" ).type() == QVariant::Map ) + if ( configurationMap.contains( "requirements" ) + && configurationMap.value( "requirements" ).type() == QVariant::Map ) + { m_requirementsChecker->setConfigurationMap( configurationMap.value( "requirements" ).toMap() ); + } else cWarning() << "no valid requirements map found in welcome " - "module configuration."; + "module configuration."; bool ok = false; QVariantMap geoip = CalamaresUtils::getSubMap( configurationMap, "geoip", ok ); @@ -124,15 +130,13 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { using FWString = QFutureWatcher< QString >; - auto* handler = new CalamaresUtils::GeoIP::Handler( - CalamaresUtils::getString( geoip, "style" ), - CalamaresUtils::getString( geoip, "url" ), - CalamaresUtils::getString( geoip, "selector" ) ); + auto* handler = new CalamaresUtils::GeoIP::Handler( CalamaresUtils::getString( geoip, "style" ), + CalamaresUtils::getString( geoip, "url" ), + CalamaresUtils::getString( geoip, "selector" ) ); if ( handler->type() != CalamaresUtils::GeoIP::Handler::Type::None ) { auto* future = new FWString(); - connect( future, &FWString::finished, [view=this, f=future, h=handler]() - { + connect( future, &FWString::finished, [view = this, f = future, h = handler]() { QString countryResult = f->future().result(); cDebug() << "GeoIP result for welcome=" << countryResult; view->setCountry( countryResult, h ); @@ -154,7 +158,9 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { auto icon = Calamares::Branding::instance()->image( language, QSize( 48, 48 ) ); if ( !icon.isNull() ) + { m_widget->setLanguageIcon( icon ); + } } } @@ -169,7 +175,8 @@ logGeoIPHandler( CalamaresUtils::GeoIP::Handler* handler ) { if ( handler ) { - cDebug() << Logger::SubEntry << "Obtained from" << handler->url() << " (" << static_cast( handler->type() ) << handler->selector() << ')'; + cDebug() << Logger::SubEntry << "Obtained from" << handler->url() << " (" + << static_cast< int >( handler->type() ) << handler->selector() << ')'; } } @@ -194,8 +201,12 @@ WelcomeViewStep::setCountry( const QString& countryCode, CalamaresUtils::GeoIP:: { int r = CalamaresUtils::Locale::availableTranslations()->find( countryCode ); if ( r < 0 ) + { cDebug() << "Unusable country code" << countryCode << "(no suitable translation)"; + } if ( ( r >= 0 ) && m_widget ) + { m_widget->externallySelectedLanguage( r ); + } } } diff --git a/src/modules/welcome/welcome.conf b/src/modules/welcome/welcome.conf index a430345a2..e8433c48d 100644 --- a/src/modules/welcome/welcome.conf +++ b/src/modules/welcome/welcome.conf @@ -12,6 +12,13 @@ showSupportUrl: true showKnownIssuesUrl: true showReleaseNotesUrl: true +# If this Url is set to something non-empty, a "donate" +# button is added to the welcome page alongside the +# others (see settings, above). Clicking the button opens +# the corresponding link. +# +# donateUrl: https://kde.org/community/donations/ + # Requirements checking. These are general, generic, things # that are checked. They may not match with the actual requirements # imposed by other modules in the system. From 64d4b0a46cbbb6f630cdd348610be7ee5c7d10fd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 22:43:11 +0200 Subject: [PATCH 26/32] [welcome] Switch API for buttons to an enum + string - Handle buttons and their URL-opening in a more general way with an enum; drop existing three-boot method and special setupDonateButton() - Doesn't compile because consumers haven't changed. --- src/modules/welcome/WelcomePage.cpp | 51 ++++++++++++++++++++++++----- src/modules/welcome/WelcomePage.h | 14 +++++--- 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index 6d0fc0d98..35807e93c 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -32,6 +32,7 @@ #include "modulesystem/ModuleManager.h" #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" +#include "utils/NamedEnum.h" #include "utils/Retranslator.h" #include @@ -244,27 +245,59 @@ WelcomePage::setUpLinks( bool showSupportUrl, bool showKnownIssuesUrl, bool show void -WelcomePage::setupDonateButton( const QString& url ) +WelcomePage::setupButton( Button role, const QString& url ) { + QPushButton* button = nullptr; + CalamaresUtils::ImageType icon = CalamaresUtils::Information; + + switch ( role ) + { + case Button::Donate: + button = ui->donateButton; + icon = CalamaresUtils::Donate; + break; + case Button::KnownIssues: + button = ui->knownIssuesButton; + icon = CalamaresUtils::Bugs; + break; + case Button::ReleaseNotes: + button = ui->releaseNotesButton; + icon = CalamaresUtils::Release; + break; + case Button::Support: + button = ui->supportButton; + icon = CalamaresUtils::Help; + break; + } + if ( !button ) + { + qWarning() << "Unknown button role" << smash( role ); + return; + } + if ( url.isEmpty() ) { - ui->donateButton->hide(); + button->hide(); return; } QUrl u( url ); if ( u.isValid() ) { - ui->donateButton->setIcon( CalamaresUtils::defaultPixmap( - CalamaresUtils::Donate, - CalamaresUtils::Original, - 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); - connect( ui->donateButton, &QPushButton::clicked, [u]() { QDesktopServices::openUrl( u ); } ); + auto size = 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ); + button->setIcon( CalamaresUtils::defaultPixmap( + icon, + CalamaresUtils::Original,size + ); + connect( button, &QPushButton::clicked, [u]() + { + QDesktopServices::openUrl( u ); + } ); } else { - qWarning() << "Donate URL" << url << "is invalid."; - ui->donateButton->hide(); + qWarning() << "Welcome button" << smash( role ) << "URL" << url << "is invalid."; + button->hide(); } } diff --git a/src/modules/welcome/WelcomePage.h b/src/modules/welcome/WelcomePage.h index d8a1bd4f2..3e776a5f0 100644 --- a/src/modules/welcome/WelcomePage.h +++ b/src/modules/welcome/WelcomePage.h @@ -38,10 +38,16 @@ class WelcomePage : public QWidget public: explicit WelcomePage( QWidget* parent = nullptr ); - /// @brief Configure the buttons for URLs from the branding configuration - void setUpLinks( bool showSupportUrl, bool showKnownIssuesUrl, bool showReleaseNotesUrl ); - /// @brief Configure the "Donate" button - void setupDonateButton( const QString& ); + enum class Button + { + Support, + Donate, + KnownIssues, + ReleaseNotes + }; + + /// @brief Configure the button @p n, to open @p url + void setupButton( Button b, const QString& url ); /// @brief Set international language-selector icon void setLanguageIcon( QPixmap ); From 119f84d6c146b86fa659727bd57f64aabb810383 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 22:57:33 +0200 Subject: [PATCH 27/32] [welcome] Remove setupLinks() method, use generic - the generic (enum-based) setupButton() can handle all four of the buttons, so setupLinks() can go away. Only the (re)translation of the text on the button needs to be done, so move that to the main RETRANSLATE. --- src/modules/welcome/WelcomePage.cpp | 84 ++++++----------------------- 1 file changed, 15 insertions(+), 69 deletions(-) diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index 35807e93c..8f989c47c 100644 --- a/src/modules/welcome/WelcomePage.cpp +++ b/src/modules/welcome/WelcomePage.cpp @@ -73,18 +73,20 @@ WelcomePage::WelcomePage( QWidget* parent ) cDebug() << "Welcome string" << Calamares::Branding::instance()->welcomeStyleCalamares() << *Calamares::Branding::VersionedName; - CALAMARES_RETRANSLATE( QString message; + CALAMARES_RETRANSLATE( + QString message; - if ( Calamares::Settings::instance()->isSetupMode() ) message - = Calamares::Branding::instance()->welcomeStyleCalamares() - ? tr( "

Welcome to the Calamares setup program for %1.

" ) - : tr( "

Welcome to %1 setup.

" ); - else message = Calamares::Branding::instance()->welcomeStyleCalamares() - ? tr( "

Welcome to the Calamares installer for %1.

" ) - : tr( "

Welcome to the %1 installer.

" ); + if ( Calamares::Settings::instance()->isSetupMode() ) message + = Calamares::Branding::instance()->welcomeStyleCalamares() + ? tr( "

Welcome to the Calamares setup program for %1.

" ) + : tr( "

Welcome to %1 setup.

" ); + else message = Calamares::Branding::instance()->welcomeStyleCalamares() + ? tr( "

Welcome to the Calamares installer for %1.

" ) + : tr( "

Welcome to the %1 installer.

" ); - ui->mainText->setText( message.arg( *Calamares::Branding::VersionedName ) ); - ui->retranslateUi( this ); ) + ui->mainText->setText( message.arg( *Calamares::Branding::VersionedName ) ); + ui->retranslateUi( this ); + ui->supportButton->setText( tr( "%1 support" ).arg( *Calamares::Branding::ShortProductName ) ); ) ui->aboutButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Information, @@ -194,56 +196,6 @@ WelcomePage::initLanguages() } -void -WelcomePage::setUpLinks( bool showSupportUrl, bool showKnownIssuesUrl, bool showReleaseNotesUrl ) -{ - using namespace Calamares; - if ( showSupportUrl && !( *Branding::SupportUrl ).isEmpty() ) - { - CALAMARES_RETRANSLATE( ui->supportButton->setText( tr( "%1 support" ).arg( *Branding::ShortProductName ) ); ) - ui->supportButton->setIcon( CalamaresUtils::defaultPixmap( - CalamaresUtils::Help, - CalamaresUtils::Original, - 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); - connect( ui->supportButton, &QPushButton::clicked, [] { QDesktopServices::openUrl( *Branding::SupportUrl ); } ); - } - else - { - ui->supportButton->hide(); - } - - if ( showKnownIssuesUrl && !( *Branding::KnownIssuesUrl ).isEmpty() ) - { - ui->knownIssuesButton->setIcon( CalamaresUtils::defaultPixmap( - CalamaresUtils::Bugs, - CalamaresUtils::Original, - 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); - connect( ui->knownIssuesButton, &QPushButton::clicked, [] { - QDesktopServices::openUrl( *Branding::KnownIssuesUrl ); - } ); - } - else - { - ui->knownIssuesButton->hide(); - } - - if ( showReleaseNotesUrl && !( *Branding::ReleaseNotesUrl ).isEmpty() ) - { - ui->releaseNotesButton->setIcon( CalamaresUtils::defaultPixmap( - CalamaresUtils::Release, - CalamaresUtils::Original, - 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ) ); - connect( ui->releaseNotesButton, &QPushButton::clicked, [] { - QDesktopServices::openUrl( *Branding::ReleaseNotesUrl ); - } ); - } - else - { - ui->releaseNotesButton->hide(); - } -} - - void WelcomePage::setupButton( Button role, const QString& url ) { @@ -284,15 +236,9 @@ WelcomePage::setupButton( Button role, const QString& url ) QUrl u( url ); if ( u.isValid() ) { - auto size = 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ) ); - button->setIcon( CalamaresUtils::defaultPixmap( - icon, - CalamaresUtils::Original,size - ); - connect( button, &QPushButton::clicked, [u]() - { - QDesktopServices::openUrl( u ); - } ); + auto size = 2 * QSize( CalamaresUtils::defaultFontHeight(), CalamaresUtils::defaultFontHeight() ); + button->setIcon( CalamaresUtils::defaultPixmap( icon, CalamaresUtils::Original, size ) ); + connect( button, &QPushButton::clicked, [u]() { QDesktopServices::openUrl( u ); } ); } else { From 341965c2b1f72bf34541b89bb90ec894accd38e4 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 23:01:52 +0200 Subject: [PATCH 28/32] [welcome] Use setupButton for all four buttons - the show* settings in welcome.conf are "upgraded" to allow setting the URL directly in the module configuration. --- src/modules/welcome/WelcomeViewStep.cpp | 45 ++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index 60dd6f500..b489adc9e 100644 --- a/src/modules/welcome/WelcomeViewStep.cpp +++ b/src/modules/welcome/WelcomeViewStep.cpp @@ -105,15 +105,50 @@ WelcomeViewStep::jobs() const } +/** @brief Look up a URL for a button + * + * Looks up @p key in @p map; if it is a *boolean* value, then + * assume an old-style configuration, and fetch the string from + * the branding settings @p e. If it is a string, not a boolean, + * use it as-is. If not found, or a weird type, returns empty. + * + * This allows switching the showKnownIssuesUrl and similar settings + * in welcome.conf from a boolean (deferring to branding) to an + * actual string for immediate use. Empty strings, as well as + * "false" as a setting, will hide the buttons as before. + */ +static QString +jobOrBrandingSetting( Calamares::Branding::StringEntry e, const QVariantMap& map, const QString& key ) +{ + if ( !map.contains( key ) ) + { + return QString(); + } + auto v = map.value( key ); + if ( v.type() == QVariant::Bool ) + { + return v.toBool() ? ( *e ) : QString(); + } + if ( v.type() == QVariant::String ) + { + return v.toString(); + } + + return QString(); +} + void WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { - bool showSupportUrl = CalamaresUtils::getBool( configurationMap, "showSupportUrl", false ); - bool showKnownIssuesUrl = CalamaresUtils::getBool( configurationMap, "showKnownIssuesUrl", false ); - bool showReleaseNotesUrl = CalamaresUtils::getBool( configurationMap, "showReleaseNotesUrl", false ); + using Calamares::Branding; - m_widget->setUpLinks( showSupportUrl, showKnownIssuesUrl, showReleaseNotesUrl ); - m_widget->setupDonateButton( CalamaresUtils::getString( configurationMap, "donateUrl" ) ); + m_widget->setupButton( WelcomePage::Button::Support, + jobOrBrandingSetting( Branding::SupportUrl, configurationMap, "showSupportUrl" ) ); + m_widget->setupButton( WelcomePage::Button::KnownIssues, + jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) ); + m_widget->setupButton( WelcomePage::Button::ReleaseNotes, + jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) ); + m_widget->setupButton( WelcomePage::Button::Donate, CalamaresUtils::getString( configurationMap, "donateUrl" ) ); if ( configurationMap.contains( "requirements" ) && configurationMap.value( "requirements" ).type() == QVariant::Map ) From 706cc7392520f833c077b5a76879b41efecc564c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 23:07:21 +0200 Subject: [PATCH 29/32] [branding] [welcome] Adjust documentation for welcome-overrides --- src/branding/default/branding.desc | 3 ++- src/modules/welcome/welcome.conf | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index 3d1079a8c..5d9b29c69 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -58,7 +58,8 @@ windowSize: 800px,520px # if it contains substitutions, or you'll get YAML exceptions. # # The *Url* entries are used on the welcome page, and they -# are visible as buttons there if the corresponding *show* keys are set. +# are visible as buttons there if the corresponding *show* keys +# are set to "true" (they can also be overridden). strings: productName: "@{NAME}" shortProductName: Generic diff --git a/src/modules/welcome/welcome.conf b/src/modules/welcome/welcome.conf index e8433c48d..f0f9e7394 100644 --- a/src/modules/welcome/welcome.conf +++ b/src/modules/welcome/welcome.conf @@ -7,7 +7,11 @@ # can check requirements for installation. --- # Display settings for various buttons on the welcome page. -# The URLs themselves come from branding.desc +# The URLs themselves come from branding.desc is the setting +# here is "true". If the setting is false, the button is hidden. +# The setting can also be a full URL which will then be used +# instead of the one from the branding file, or empty or not-set +# which will hide the button. showSupportUrl: true showKnownIssuesUrl: true showReleaseNotesUrl: true From c36f963954d3ad0acf4ff7ddadd9227074aaf579 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 23:08:33 +0200 Subject: [PATCH 30/32] [welcome] Adjust names of URLs to be consistent - having show*Url and donateUrl seems inconsistent, although the show*Url settings were originally boolean-only. - add "show" to the Donate button setting, to make them all consistent (putting a boolean there will generate a warning and hide the button, that's all). --- src/modules/welcome/WelcomeViewStep.cpp | 2 +- src/modules/welcome/welcome.conf | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index b489adc9e..17a10f754 100644 --- a/src/modules/welcome/WelcomeViewStep.cpp +++ b/src/modules/welcome/WelcomeViewStep.cpp @@ -148,7 +148,7 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap ) jobOrBrandingSetting( Branding::KnownIssuesUrl, configurationMap, "showKnownIssuesUrl" ) ); m_widget->setupButton( WelcomePage::Button::ReleaseNotes, jobOrBrandingSetting( Branding::ReleaseNotesUrl, configurationMap, "showReleaseNotesUrl" ) ); - m_widget->setupButton( WelcomePage::Button::Donate, CalamaresUtils::getString( configurationMap, "donateUrl" ) ); + m_widget->setupButton( WelcomePage::Button::Donate, CalamaresUtils::getString( configurationMap, "showDonateUrl" ) ); if ( configurationMap.contains( "requirements" ) && configurationMap.value( "requirements" ).type() == QVariant::Map ) diff --git a/src/modules/welcome/welcome.conf b/src/modules/welcome/welcome.conf index f0f9e7394..9488daa5e 100644 --- a/src/modules/welcome/welcome.conf +++ b/src/modules/welcome/welcome.conf @@ -19,9 +19,10 @@ showReleaseNotesUrl: true # If this Url is set to something non-empty, a "donate" # button is added to the welcome page alongside the # others (see settings, above). Clicking the button opens -# the corresponding link. +# the corresponding link. (This button has no corresponding +# branding.desc string) # -# donateUrl: https://kde.org/community/donations/ +# showDonateUrl: https://kde.org/community/donations/ # Requirements checking. These are general, generic, things # that are checked. They may not match with the actual requirements From 0b7dcf7c50559fb7a29486c2eda0751039a423b1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 13 Aug 2019 23:22:33 +0200 Subject: [PATCH 31/32] [welcome] Fix up tooltips - the "Select language" tooltip was applied to the form, so it would show up inappropriately all over the place - the buttons didn't have useful tooltips. --- src/modules/welcome/WelcomePage.ui | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/modules/welcome/WelcomePage.ui b/src/modules/welcome/WelcomePage.ui index 0787ac6e7..160daa595 100644 --- a/src/modules/welcome/WelcomePage.ui +++ b/src/modules/welcome/WelcomePage.ui @@ -13,9 +13,6 @@ Form - - Select language - @@ -69,7 +66,7 @@ - Select language + Select application and system language @@ -81,6 +78,9 @@ + + Select application and system language + 2 @@ -136,6 +136,9 @@ + + Open donations website + &Donate @@ -146,6 +149,9 @@ + + Open help and support website + &Support @@ -156,6 +162,9 @@ + + Open issues and bug-tracking website + &Known issues @@ -166,6 +175,9 @@ + + Open relead notes website + &Release notes From 2e8a106f2c82266448f13591cf3c9206ac7fee64 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 16 Aug 2019 04:21:53 -0400 Subject: [PATCH 32/32] Changes: document new stuff --- CHANGES | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGES b/CHANGES index 3f4aad749..e926da175 100644 --- a/CHANGES +++ b/CHANGES @@ -23,6 +23,13 @@ This release contains contributions from (alphabetically by first name): ## Modules ## +- The *partition* module now understands the units *KB*, *MB*, *GB* which + are powers-of-ten sizes, alongside the powers-of-two sizes that it already + used. (thanks to Arnaud) +- The *welcome* module now supports a *Donate* button if *showDonateUrl* + is set to a non-empty URL. #1197 +- The *welcome* module can have URLs for the various buttons configured + directly in the module configuration (rather than in `branding.desc`). # 3.2.12 (2019-08-07) #