diff --git a/CHANGES b/CHANGES index dbdcb3523..e926da175 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 ## @@ -13,9 +15,21 @@ 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 ## +- 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) # 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/README.md b/README.md index f35b012c8..e2e87fddf 100644 --- a/README.md +++ b/README.md @@ -13,28 +13,23 @@ ### 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) +* KDE Frameworks KCoreAddons (>= 5.58 recommended) +* 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 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/branding/default/branding.desc b/src/branding/default/branding.desc index 1bd76cd29..5d9b29c69 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -56,6 +56,10 @@ 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 to "true" (they can also be overridden). strings: productName: "@{NAME}" shortProductName: Generic @@ -84,7 +88,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/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/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/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 ); 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 ); } diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 790d4b6ac..f2063813c 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -120,6 +120,7 @@ target_link_libraries( calamares LINK_PUBLIC ${YAMLCPP_LIBRARY} Qt5::Core + KF5::CoreAddons ${OPTIONAL_PUBLIC_LIBRARIES} ) 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/libcalamares/partition/PartitionSize.cpp b/src/libcalamares/partition/PartitionSize.cpp index 3f4463f3c..fc8d72582 100644 --- a/src/libcalamares/partition/PartitionSize.cpp +++ b/src/libcalamares/partition/PartitionSize.cpp @@ -29,12 +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( "%" ), 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; } @@ -50,7 +60,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; @@ -90,8 +100,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 +138,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 +177,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 +205,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 +236,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 +262,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 +288,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/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/PluginFactory.cpp b/src/libcalamares/utils/PluginFactory.cpp index 878182ea4..50b88ebfd 100644 --- a/src/libcalamares/utils/PluginFactory.cpp +++ b/src/libcalamares/utils/PluginFactory.cpp @@ -1,127 +1,9 @@ /* === This file is part of Calamares - === * - * Copyright 2015, Teo Mrnjavac - * Copyright 2017-2018, Adriaan de Groot + * Copyright 2019, 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; -} - -} +CalamaresPluginFactory::~CalamaresPluginFactory() {} diff --git a/src/libcalamares/utils/PluginFactory.h b/src/libcalamares/utils/PluginFactory.h index f2481f10d..84694a83a 100644 --- a/src/libcalamares/utils/PluginFactory.h +++ b/src/libcalamares/utils/PluginFactory.h @@ -24,298 +24,84 @@ #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 +/** @brief Plugin factory for Calamares * - * CALAMARES_PLUGIN_FACTORY_DECLARATION declares the PluginFactory subclass. This macro - * can be used in a header file. + * 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). * - * \param name The name of the PluginFactory derived class. - * - * \see CALAMARES_PLUGIN_FACTORY - * \see CALAMARES_PLUGIN_FACTORY_DEFINITION + * 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. */ -#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 - */ -#define CALAMARES_PLUGIN_FACTORY_DEFINITION(name, pluginRegistrations) \ - name::name() \ - { \ - pluginRegistrations \ - } \ - name::~name() {} - -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 +class CalamaresPluginFactory : public KPluginFactory { 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 + explicit CalamaresPluginFactory() + : KPluginFactory() { - 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 ); } + ~CalamaresPluginFactory() override; - PluginFactoryPrivate* const pd_ptr; - - /** - * This function is called when the factory asked to create an Object. + /** @brief Create an object from the factory. * - * 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. + * Ignores all the @p args since they are not used. Calls + * Calamares constructors for the Jobs and ViewSteps. */ - virtual QObject* create( const char* iface, QWidget* parentWidget, QObject* parent, const QString& keyword ); - - template - static QObject* createInstance( QWidget* parentWidget, QObject* parent ) + template < class impl, class ParentType > + static QObject* createInstance( QWidget* parentWidget, QObject* parent, const QVariantList& args ) { - Q_UNUSED( parentWidget ) + Q_UNUSED( parentWidget ); + Q_UNUSED( args ); ParentType* p = nullptr; if ( parent ) { - p = qobject_cast( parent ); + p = qobject_cast< ParentType* >( parent ); Q_ASSERT( p ); } return new impl( p ); } -private: - void doRegisterPlugin( const QString& keyword, const QMetaObject* metaObject, CreateInstanceFunction instanceFunction ); + /** @brief register a plugin + * + * The Calamares version doesn't accept keywords, and uses + * the Calamares createInstance() version which ignores + * the QVariantList of arguments. + */ + template < class T > + void registerPlugin() + { + KPluginFactory::registerPlugin< T >( QString(), &createInstance< T, QObject > ); + } }; -template -inline T* PluginFactory::create( QObject* parent ) -{ - QObject* o = create( T::staticMetaObject.className(), - parent && parent->isWidgetType() ? reinterpret_cast( parent ) : nullptr, - parent, - QString() ); +/** @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 ) \ + 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_WITH_BASEFACTORY( name, CalamaresPluginFactory, pluginRegistrations ) - 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 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 ) { 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 ) ) { 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/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() 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 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/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/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(); 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(); diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp index 808c805cb..bd15d7a68 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 ) { @@ -75,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; @@ -152,11 +155,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 +179,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 +197,9 @@ unmarginLayout( QLayout* layout ) { QLayout* childLayout = layout->itemAt( i )->layout(); if ( childLayout ) + { unmarginLayout( childLayout ); + } } } @@ -255,13 +265,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..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, @@ -56,7 +57,7 @@ enum ImageType : int PartitionTable, BootEnvironment, Squid, - StatusOk, // Icons for the requirements checker + StatusOk, // Icons for the requirements checker StatusWarning, StatusError }; @@ -94,9 +95,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 +111,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 +127,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 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 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 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() 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'] diff --git a/src/modules/welcome/WelcomePage.cpp b/src/modules/welcome/WelcomePage.cpp index b29b2e23e..8f989c47c 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" @@ -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 @@ -48,9 +49,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 +71,33 @@ 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; - 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->supportButton->setText( tr( "%1 support" ).arg( *Calamares::Branding::ShortProductName ) ); ) - 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 +108,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 +143,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 +164,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,89 +178,82 @@ 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::setupButton( Button role, const QString& url ) { - using namespace Calamares; - if ( showSupportUrl && !( *Branding::SupportUrl ).isEmpty() ) + QPushButton* button = nullptr; + CalamaresUtils::ImageType icon = CalamaresUtils::Information; + + switch ( role ) { - 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 ); - } ); + 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; } - else + if ( !button ) { - ui->supportButton->hide(); + qWarning() << "Unknown button role" << smash( role ); + return; } - if ( showKnownIssuesUrl && !( *Branding::KnownIssuesUrl ).isEmpty() ) + if ( url.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(); + button->hide(); + return; } - if ( showReleaseNotesUrl && !( *Branding::ReleaseNotesUrl ).isEmpty() ) + QUrl u( url ); + if ( u.isValid() ) { - ui->releaseNotesButton->setIcon( CalamaresUtils::defaultPixmap( CalamaresUtils::Release, - CalamaresUtils::Original, - 2*QSize( CalamaresUtils::defaultFontHeight(), - CalamaresUtils::defaultFontHeight() ) ) ); - connect( ui->releaseNotesButton, &QPushButton::clicked, [] - { - QDesktopServices::openUrl( *Branding::ReleaseNotesUrl ); - } ); + 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 { - ui->releaseNotesButton->hide(); + qWarning() << "Welcome button" << smash( role ) << "URL" << url << "is invalid."; + button->hide(); } } - void WelcomePage::focusInEvent( QFocusEvent* e ) { if ( ui->languageWidget ) + { ui->languageWidget->setFocus(); + } e->accept(); } @@ -267,7 +267,9 @@ void WelcomePage::externallySelectedLanguage( int row ) { if ( ( row >= 0 ) && ( row < ui->languageWidget->count() ) ) + { ui->languageWidget->setCurrentIndex( row ); + } } void @@ -278,8 +280,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..3e776a5f0 100644 --- a/src/modules/welcome/WelcomePage.h +++ b/src/modules/welcome/WelcomePage.h @@ -38,10 +38,17 @@ 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 ); + 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 ); @@ -50,8 +57,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 +67,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 +80,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..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 @@ -134,8 +134,24 @@ + + + + Open donations website + + + &Donate + + + true + + + + + Open help and support website + &Support @@ -146,6 +162,9 @@ + + Open issues and bug-tracking website + &Known issues @@ -156,6 +175,9 @@ + + Open relead notes website + &Release notes diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index 938fe1f45..17a10f754 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(); + } } @@ -100,23 +105,59 @@ 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->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, "showDonateUrl" ) ); - 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 +165,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 +193,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 +210,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 +236,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/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 ); diff --git a/src/modules/welcome/welcome.conf b/src/modules/welcome/welcome.conf index a89b63854..9488daa5e 100644 --- a/src/modules/welcome/welcome.conf +++ b/src/modules/welcome/welcome.conf @@ -7,10 +7,23 @@ # can check requirements for installation. --- # Display settings for various buttons on the welcome page. +# 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 +# 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. (This button has no corresponding +# branding.desc string) +# +# showDonateUrl: 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.