From 0f8751497ed0af74e76864ada9fbf66fca6ed060 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 3 Mar 2020 14:21:43 +0100 Subject: [PATCH 01/24] CI: give tooling a standard LANG environment --- ci/calamaresstyle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ci/calamaresstyle b/ci/calamaresstyle index 65dc83de7..ecbd798c5 100755 --- a/ci/calamaresstyle +++ b/ci/calamaresstyle @@ -6,6 +6,11 @@ # You can pass in directory names, in which case the files # in that directory (NOT below it) are processed. # +LANG=C +LC_ALL=C +LC_NUMERIC=C +export LANG LC_ALL LC_NUMERIC + AS=$( which astyle ) for _cf in clang-format-7 clang-format-8 clang-format70 clang-format80 clang-format From 623a8c2d43b94476ec077bfcb0391edd6c08ad6b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 3 Mar 2020 14:22:59 +0100 Subject: [PATCH 02/24] [removeuser] Port to C++ No changes in functionality; add a little description in the .conf file. --- src/modules/removeuser/CMakeLists.txt | 9 +++ src/modules/removeuser/RemoveUserJob.cpp | 74 ++++++++++++++++++++++++ src/modules/removeuser/RemoveUserJob.h | 49 ++++++++++++++++ src/modules/removeuser/main.py | 50 ---------------- src/modules/removeuser/module.desc | 6 -- src/modules/removeuser/removeuser.conf | 4 ++ 6 files changed, 136 insertions(+), 56 deletions(-) create mode 100644 src/modules/removeuser/CMakeLists.txt create mode 100644 src/modules/removeuser/RemoveUserJob.cpp create mode 100644 src/modules/removeuser/RemoveUserJob.h delete mode 100644 src/modules/removeuser/main.py delete mode 100644 src/modules/removeuser/module.desc diff --git a/src/modules/removeuser/CMakeLists.txt b/src/modules/removeuser/CMakeLists.txt new file mode 100644 index 000000000..55798feac --- /dev/null +++ b/src/modules/removeuser/CMakeLists.txt @@ -0,0 +1,9 @@ +calamares_add_plugin( removeuser + TYPE job + EXPORT_MACRO PLUGINDLLEXPORT_PRO + SOURCES + RemoveUserJob.cpp + LINK_PRIVATE_LIBRARIES + calamares + SHARED_LIB +) diff --git a/src/modules/removeuser/RemoveUserJob.cpp b/src/modules/removeuser/RemoveUserJob.cpp new file mode 100644 index 000000000..427d89729 --- /dev/null +++ b/src/modules/removeuser/RemoveUserJob.cpp @@ -0,0 +1,74 @@ +/* === This file is part of Calamares - === + * + * Copyright 2015, Teo Mrnjavac + * Copyright 2017. Alf Gaida + * Copyright 2019-2020, Adriaan de Groot + * + * 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 "RemoveUserJob.h" + +#include "GlobalStorage.h" +#include "JobQueue.h" +#include "utils/CalamaresUtilsSystem.h" +#include "utils/Logger.h" +#include "utils/Variant.h" + +#include + +RemoveUserJob::RemoveUserJob( QObject* parent ) + : Calamares::CppJob( parent ) +{ +} + + +RemoveUserJob::~RemoveUserJob() {} + + +QString +RemoveUserJob::prettyName() const +{ + return tr( "Remove live user from target system" ); +} + +Calamares::JobResult +RemoveUserJob::exec() +{ + if ( m_username.isEmpty() ) + { + cWarning() << "Ignoring an empty username."; + return Calamares::JobResult::ok(); + } + + auto* s = CalamaresUtils::System::instance(); + auto r = s->targetEnvCommand( { QStringLiteral( "userdel" ), + QStringLiteral( "-f" ), // force + QStringLiteral( "-r" ), // remove home-dir and mail + m_username } ); + if ( r.getExitCode() != 0 ) + { + cWarning() << "Cannot remove user `" << m_username << "`. userdel terminated with exit code" << r.getExitCode(); + } + return Calamares::JobResult::ok(); +} + + +void +RemoveUserJob::setConfigurationMap( const QVariantMap& map ) +{ + m_username = CalamaresUtils::getString( map, "username" ); +} + +CALAMARES_PLUGIN_FACTORY_DEFINITION( RemoveUserJobFactory, registerPlugin< RemoveUserJob >(); ) diff --git a/src/modules/removeuser/RemoveUserJob.h b/src/modules/removeuser/RemoveUserJob.h new file mode 100644 index 000000000..d13e834f0 --- /dev/null +++ b/src/modules/removeuser/RemoveUserJob.h @@ -0,0 +1,49 @@ +/* === This file is part of Calamares - === + * + * Copyright 2020, Adriaan de Groot + * + * 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 REMOVEUSERJOB_H +#define REMOVEUSERJOB_H + +#include "CppJob.h" +#include "DllMacro.h" +#include "utils/PluginFactory.h" + +#include +#include + +class PLUGINDLLEXPORT RemoveUserJob : public Calamares::CppJob +{ + Q_OBJECT + +public: + explicit RemoveUserJob( QObject* parent = nullptr ); + virtual ~RemoveUserJob() override; + + QString prettyName() const override; + + Calamares::JobResult exec() override; + + void setConfigurationMap( const QVariantMap& configurationMap ) override; + +private: + QString m_username; +}; + +CALAMARES_PLUGIN_FACTORY_DECLARATION( RemoveUserJobFactory ) + +#endif // REMOVEUSERJOB_H diff --git a/src/modules/removeuser/main.py b/src/modules/removeuser/main.py deleted file mode 100644 index bd876edcd..000000000 --- a/src/modules/removeuser/main.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# === This file is part of Calamares - === -# -# Copyright 2015, Teo Mrnjavac -# Copyright 2017. Alf Gaida -# Copyright 2019, Adriaan de Groot -# -# 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 . - -import subprocess -import libcalamares - -import gettext -_ = gettext.translation("calamares-python", - localedir=libcalamares.utils.gettext_path(), - languages=libcalamares.utils.gettext_languages(), - fallback=True).gettext - - -def pretty_name(): - return _("Remove live user from target system") - - -def run(): - """ - Remove live user from target system - """ - username = libcalamares.job.configuration["username"] - - try: - libcalamares.utils.check_target_env_call(["userdel", "-f", - "-r", username]) - except subprocess.CalledProcessError as e: - libcalamares.utils.debug("Cannot remove user. " - "'userdel' terminated with exit code " - "{}.".format(e.returncode)) - return None diff --git a/src/modules/removeuser/module.desc b/src/modules/removeuser/module.desc deleted file mode 100644 index 5c6fc6fb7..000000000 --- a/src/modules/removeuser/module.desc +++ /dev/null @@ -1,6 +0,0 @@ ---- -type: "job" -name: "removeuser" -interface: "python" -requires: [] -script: "main.py" diff --git a/src/modules/removeuser/removeuser.conf b/src/modules/removeuser/removeuser.conf index dab4b2526..d266e6952 100644 --- a/src/modules/removeuser/removeuser.conf +++ b/src/modules/removeuser/removeuser.conf @@ -1,6 +1,10 @@ # Removes a single user (with userdel) from the system. # This is typically used in OEM setups or if the live user # spills into the target system. +# +# The module never fails; if userdel fails, this is logged +# but the module still reports success and installation / setup +# continues as normal. --- # Username in the target system to be removed. username: live From c15022462a5bb45b1efde64034e47c705f59e50b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 3 Mar 2020 14:30:35 +0100 Subject: [PATCH 03/24] Changes: post-release housekeeping --- CHANGES | 12 ++++++++++++ CMakeLists.txt | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 67edca8f0..1c364e7f8 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,18 @@ contributors are listed. Note that Calamares does not have a historical changelog -- this log starts with version 3.2.0. The release notes on the website will have to do for older versions. +# 3.2.21 (unreleased) # + +This release contains contributions from (alphabetically by first name): + - No external contributors yet + +## Core ## + - No core changes yet + +## Modules ## + - No module changes yet + + # 3.2.20 (2020-02-27) # This release contains contributions from (alphabetically by first name): diff --git a/CMakeLists.txt b/CMakeLists.txt index eee6c01b2..b7f332c87 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,10 +40,10 @@ cmake_minimum_required( VERSION 3.3 FATAL_ERROR ) project( CALAMARES - VERSION 3.2.20 + VERSION 3.2.21 LANGUAGES C CXX ) -set( CALAMARES_VERSION_RC 0 ) # Set to 0 during release cycle, 1 during development +set( CALAMARES_VERSION_RC 1 ) # Set to 0 during release cycle, 1 during development ### OPTIONS # From ae633c7e7b323a393c9dc7236d522a9d9f193a52 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 3 Mar 2020 14:35:15 +0100 Subject: [PATCH 04/24] [removeuser] Remove superfluous formatting around logging --- src/modules/removeuser/RemoveUserJob.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/removeuser/RemoveUserJob.cpp b/src/modules/removeuser/RemoveUserJob.cpp index 427d89729..0488d19a4 100644 --- a/src/modules/removeuser/RemoveUserJob.cpp +++ b/src/modules/removeuser/RemoveUserJob.cpp @@ -59,7 +59,7 @@ RemoveUserJob::exec() m_username } ); if ( r.getExitCode() != 0 ) { - cWarning() << "Cannot remove user `" << m_username << "`. userdel terminated with exit code" << r.getExitCode(); + cWarning() << "Cannot remove user" << m_username << "userdel terminated with exit code" << r.getExitCode(); } return Calamares::JobResult::ok(); } From 3ddee8090c703bf383e814d8872360f484e55173 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 3 Mar 2020 16:30:22 +0100 Subject: [PATCH 05/24] [libcalamares] Drop intermediate CLog class - All the real work is done in CDebug, so remove the base class. --- src/libcalamares/utils/Logger.cpp | 14 ++++++++++---- src/libcalamares/utils/Logger.h | 26 ++++---------------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/libcalamares/utils/Logger.cpp b/src/libcalamares/utils/Logger.cpp index 0e207fa02..c50dd726b 100644 --- a/src/libcalamares/utils/Logger.cpp +++ b/src/libcalamares/utils/Logger.cpp @@ -172,20 +172,26 @@ setupLogfile() qInstallMessageHandler( CalamaresLogHandler ); } -CLog::CLog( unsigned int debugLevel ) +CDebug::CDebug( unsigned int debugLevel ) : QDebug( &m_msg ) , m_debugLevel( debugLevel ) { + if ( debugLevel <= LOGERROR ) + { + m_msg = QStringLiteral( "ERROR:" ); + } + else if ( debugLevel <= LOGWARNING ) + { + m_msg = QStringLiteral( "WARNING:" ); + } } -CLog::~CLog() +CDebug::~CDebug() { log( m_msg.toUtf8().data(), m_debugLevel ); } -CDebug::~CDebug() {} - const char Continuation[] = "\n "; const char SubEntry[] = " .. "; diff --git a/src/libcalamares/utils/Logger.h b/src/libcalamares/utils/Logger.h index 33954bd37..987095adc 100644 --- a/src/libcalamares/utils/Logger.h +++ b/src/libcalamares/utils/Logger.h @@ -41,35 +41,17 @@ enum LOGVERBOSE = 8 }; -class DLLEXPORT CLog : public QDebug +class DLLEXPORT CDebug : public QDebug { public: - explicit CLog( unsigned int debugLevel ); - virtual ~CLog(); + explicit CDebug( unsigned int debugLevel = LOGDEBUG ); + virtual ~CDebug(); private: QString m_msg; unsigned int m_debugLevel; }; -class DLLEXPORT CDebug : public CLog -{ -public: - CDebug( unsigned int debugLevel = LOGDEBUG ) - : CLog( debugLevel ) - { - if ( debugLevel <= LOGERROR ) - { - *this << "ERROR:"; - } - else if ( debugLevel <= LOGWARNING ) - { - *this << "WARNING:"; - } - } - virtual ~CDebug(); -}; - /** * @brief The full path of the log file. */ @@ -219,7 +201,7 @@ operator<<( QDebug& s, const DebugMap& t ) } } // namespace Logger -#define cDebug() (Logger::CDebug( Logger::LOGDEBUG ) << Q_FUNC_INFO << Logger::Continuation) +#define cDebug() ( Logger::CDebug( Logger::LOGDEBUG ) << Q_FUNC_INFO << Logger::Continuation ) #define cWarning() Logger::CDebug( Logger::LOGWARNING ) #define cError() Logger::CDebug( Logger::LOGERROR ) From 5248a37eb3ac162d8fc86f3bf4c2f9314842f467 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 3 Mar 2020 16:37:17 +0100 Subject: [PATCH 06/24] [libcalamares] Add FUNC_INFO into all debug messages - This is needlessly verbose - Chase CreatePartitionTableJob which needs to bind to a temporary --- src/libcalamares/utils/Logger.cpp | 8 +++++++- src/libcalamares/utils/Logger.h | 9 +++++---- src/modules/partition/jobs/CreatePartitionTableJob.cpp | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/libcalamares/utils/Logger.cpp b/src/libcalamares/utils/Logger.cpp index c50dd726b..c39e73c50 100644 --- a/src/libcalamares/utils/Logger.cpp +++ b/src/libcalamares/utils/Logger.cpp @@ -172,9 +172,10 @@ setupLogfile() qInstallMessageHandler( CalamaresLogHandler ); } -CDebug::CDebug( unsigned int debugLevel ) +CDebug::CDebug( unsigned int debugLevel, const char* func ) : QDebug( &m_msg ) , m_debugLevel( debugLevel ) + , m_funcinfo( func ) { if ( debugLevel <= LOGERROR ) { @@ -189,6 +190,11 @@ CDebug::CDebug( unsigned int debugLevel ) CDebug::~CDebug() { + if ( m_funcinfo ) + { + m_msg.prepend( Continuation ); + m_msg.prepend( m_funcinfo ); + } log( m_msg.toUtf8().data(), m_debugLevel ); } diff --git a/src/libcalamares/utils/Logger.h b/src/libcalamares/utils/Logger.h index 987095adc..2dfd2878f 100644 --- a/src/libcalamares/utils/Logger.h +++ b/src/libcalamares/utils/Logger.h @@ -44,12 +44,13 @@ enum class DLLEXPORT CDebug : public QDebug { public: - explicit CDebug( unsigned int debugLevel = LOGDEBUG ); + explicit CDebug( unsigned int debugLevel = LOGDEBUG, const char* func = nullptr ); virtual ~CDebug(); private: QString m_msg; unsigned int m_debugLevel; + const char* m_funcinfo = nullptr; }; /** @@ -201,8 +202,8 @@ operator<<( QDebug& s, const DebugMap& t ) } } // namespace Logger -#define cDebug() ( Logger::CDebug( Logger::LOGDEBUG ) << Q_FUNC_INFO << Logger::Continuation ) -#define cWarning() Logger::CDebug( Logger::LOGWARNING ) -#define cError() Logger::CDebug( Logger::LOGERROR ) +#define cDebug() Logger::CDebug( Logger::LOGDEBUG, Q_FUNC_INFO ) +#define cWarning() Logger::CDebug( Logger::LOGWARNING, Q_FUNC_INFO ) +#define cError() Logger::CDebug( Logger::LOGERROR, Q_FUNC_INFO ) #endif diff --git a/src/modules/partition/jobs/CreatePartitionTableJob.cpp b/src/modules/partition/jobs/CreatePartitionTableJob.cpp index 20a3c7e6a..b18f56a04 100644 --- a/src/modules/partition/jobs/CreatePartitionTableJob.cpp +++ b/src/modules/partition/jobs/CreatePartitionTableJob.cpp @@ -69,7 +69,7 @@ CreatePartitionTableJob::prettyStatusMessage() const static inline QDebug& -operator <<( QDebug& s, PartitionIterator& it ) +operator <<( QDebug&& s, PartitionIterator& it ) { s << ( ( *it ) ? ( *it )->deviceNode() : QString( "" ) ); return s; From 0abde6f1a7d12a6910a8caa53ec23dd4c7df10e1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 3 Mar 2020 16:59:26 +0100 Subject: [PATCH 07/24] [libcalamares] Don't print funcinfo in continuations - when a single function does more logging, it generally marks those as subsequent debug-messages (with Continuation, or SubEntry) and we don't need to print funcinfo for those, since it was already printed the first time. --- src/libcalamares/utils/Logger.cpp | 15 ++++++++++++--- src/libcalamares/utils/Logger.h | 25 +++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/libcalamares/utils/Logger.cpp b/src/libcalamares/utils/Logger.cpp index c39e73c50..ceca20b7a 100644 --- a/src/libcalamares/utils/Logger.cpp +++ b/src/libcalamares/utils/Logger.cpp @@ -44,6 +44,10 @@ static unsigned int s_threshold = #endif static QMutex s_mutex; +static const char s_Continuation[] = "\n "; +static const char s_SubEntry[] = " .. "; + + namespace Logger { @@ -192,14 +196,19 @@ CDebug::~CDebug() { if ( m_funcinfo ) { - m_msg.prepend( Continuation ); + m_msg.prepend( s_Continuation ); // Prepending, so back-to-front m_msg.prepend( m_funcinfo ); } log( m_msg.toUtf8().data(), m_debugLevel ); } -const char Continuation[] = "\n "; -const char SubEntry[] = " .. "; +constexpr FuncSuppressor::FuncSuppressor( const char s[] ) + : m_s( s ) +{ +} + +const constexpr FuncSuppressor Continuation( s_Continuation ); +const constexpr FuncSuppressor SubEntry( s_SubEntry ); QString toString( const QVariant& v ) diff --git a/src/libcalamares/utils/Logger.h b/src/libcalamares/utils/Logger.h index 2dfd2878f..fe4b98fd4 100644 --- a/src/libcalamares/utils/Logger.h +++ b/src/libcalamares/utils/Logger.h @@ -27,8 +27,14 @@ namespace Logger { -DLLEXPORT extern const char Continuation[]; -DLLEXPORT extern const char SubEntry[]; +struct FuncSuppressor +{ + explicit constexpr FuncSuppressor( const char[] ); + const char* m_s; +}; + +DLLEXPORT extern const FuncSuppressor Continuation; +DLLEXPORT extern const FuncSuppressor SubEntry; enum { @@ -47,12 +53,27 @@ public: explicit CDebug( unsigned int debugLevel = LOGDEBUG, const char* func = nullptr ); virtual ~CDebug(); + friend QDebug& operator<<( CDebug&&, const FuncSuppressor& ); + private: QString m_msg; unsigned int m_debugLevel; const char* m_funcinfo = nullptr; }; +inline QDebug& +operator<<( CDebug&& s, const FuncSuppressor& f ) +{ + s.m_funcinfo = nullptr; + return s << f.m_s; +} + +inline QDebug& +operator<<( QDebug& s, const FuncSuppressor& f ) +{ + return s << f.m_s; +} + /** * @brief The full path of the log file. */ From d3828a82fce4d779f9ea259390efa7982d028cbe Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 4 Mar 2020 21:31:47 -0500 Subject: [PATCH 08/24] [packages] Make dummy backend slower - insert sleeps to make it slower (easier when testing) - improve debug logging clarity by noting where the messages are coming from --- src/modules/packages/main.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/modules/packages/main.py b/src/modules/packages/main.py index adca88423..8cbde9de6 100644 --- a/src/modules/packages/main.py +++ b/src/modules/packages/main.py @@ -332,19 +332,23 @@ class PMDummy(PackageManager): backend = "dummy" def install(self, pkgs, from_local=False): - libcalamares.utils.debug("Installing " + str(pkgs)) + from time import sleep + libcalamares.utils.debug("Dummy backend: Installing " + str(pkgs)) + sleep(3) def remove(self, pkgs): - libcalamares.utils.debug("Removing " + str(pkgs)) + from time import sleep + libcalamares.utils.debug("Dummy backend: Removing " + str(pkgs)) + sleep(3) def update_db(self): - libcalamares.utils.debug("Updating DB") + libcalamares.utils.debug("Dummy backend: Updating DB") def update_system(self): - libcalamares.utils.debug("Updating System") + libcalamares.utils.debug("Dummy backend: Updating System") def run(self, script): - libcalamares.utils.debug("Running script '" + str(script) + "'") + libcalamares.utils.debug("Dummy backend: Running script '" + str(script) + "'") class PMPisi(PackageManager): @@ -502,7 +506,7 @@ def run_operations(pkgman, entry): libcalamares.utils.warning("Unknown package-operation key {!s}".format(key)) completed_packages += len(package_list) libcalamares.job.setprogress(completed_packages * 1.0 / total_packages) - libcalamares.utils.debug(pretty_name()) + libcalamares.utils.debug("Pretty name: {!s}, setting progress..".format(pretty_name())) group_packages = 0 _change_mode(None) From 6d29c19e3eaa7db758b3e493a509708492e9c934 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 4 Mar 2020 21:40:40 -0500 Subject: [PATCH 09/24] [libcalamares] Progress is float --- src/libcalamares/PythonJobApi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcalamares/PythonJobApi.cpp b/src/libcalamares/PythonJobApi.cpp index caa1cb1d2..cf7984c87 100644 --- a/src/libcalamares/PythonJobApi.cpp +++ b/src/libcalamares/PythonJobApi.cpp @@ -171,7 +171,7 @@ PythonJobInterface::PythonJobInterface( Calamares::PythonJob* parent ) void PythonJobInterface::setprogress( qreal progress ) { - if ( progress >= 0 && progress <= 1 ) + if ( progress >= 0.0 && progress <= 1.0 ) { m_parent->emitProgress( progress ); } From 3025c5383b519e796085a435f68b1c832edd7ebc Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 5 Mar 2020 08:54:42 -0500 Subject: [PATCH 10/24] [libcalamares] Document the pretty*() functions for Jobs --- src/libcalamares/Job.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/libcalamares/Job.h b/src/libcalamares/Job.h index 862a5f3f5..d93e97cf7 100644 --- a/src/libcalamares/Job.h +++ b/src/libcalamares/Job.h @@ -97,7 +97,7 @@ public: virtual ~Job(); /** @brief The job's (relative) weight. - * + * * The default implementation returns 1.0, which gives all jobs * the same weight, so they advance the overall progress the same * amount. This is nonsense, since some jobs take much longer than @@ -105,8 +105,20 @@ public: * how much work is (relatively) done. */ virtual qreal getJobWeight() const; + /** @brief The human-readable name of this job + * + * This should be a very short statement of what the job does. + * For status and state information, see prettyStatusMessage(). + */ virtual QString prettyName() const = 0; + // TODO: Unused virtual QString prettyDescription() const; + /** @brief A human-readable status for progress reporting + * + * This is called from the JobQueue when progress is made, and should + * return a not-too-long description of the job's status. This + * is made visible in the progress bar of the execution view step. + */ virtual QString prettyStatusMessage() const; virtual JobResult exec() = 0; From 9b5a391c868c3d96c8d1e4552561e64bd52e98ed Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 9 Mar 2020 10:05:01 -0500 Subject: [PATCH 11/24] [libcalamares] Factor out Python helper - the strange construction of Helper and treating it as a singleton can be factored out into a separate singleton-handling instance() function. The Helper should never be destroyed. --- src/libcalamares/PythonHelper.cpp | 66 +++++++++++++++---------------- src/libcalamares/PythonHelper.h | 9 ++--- src/libcalamares/PythonJob.cpp | 17 +------- src/libcalamares/PythonJob.h | 1 - 4 files changed, 37 insertions(+), 56 deletions(-) diff --git a/src/libcalamares/PythonHelper.cpp b/src/libcalamares/PythonHelper.cpp index d9db8581e..0b5d77ac1 100644 --- a/src/libcalamares/PythonHelper.cpp +++ b/src/libcalamares/PythonHelper.cpp @@ -204,8 +204,6 @@ variantHashFromPyDict( const boost::python::dict& pyDict ) } -Helper* Helper::s_instance = nullptr; - static inline void add_if_lib_exists( const QDir& dir, const char* name, QStringList& list ) { @@ -221,48 +219,46 @@ add_if_lib_exists( const QDir& dir, const char* name, QStringList& list ) } } -Helper::Helper( QObject* parent ) - : QObject( parent ) +Helper::Helper() + : QObject( nullptr ) { // Let's make extra sure we only call Py_Initialize once - if ( !s_instance ) + if ( !Py_IsInitialized() ) { - if ( !Py_IsInitialized() ) - { - Py_Initialize(); - } - - m_mainModule = bp::import( "__main__" ); - m_mainNamespace = m_mainModule.attr( "__dict__" ); - - // If we're running from the build dir - add_if_lib_exists( QDir::current(), "libcalamares.so", m_pythonPaths ); - - QDir calaPythonPath( CalamaresUtils::systemLibDir().absolutePath() + QDir::separator() + "calamares" ); - add_if_lib_exists( calaPythonPath, "libcalamares.so", m_pythonPaths ); - - bp::object sys = bp::import( "sys" ); - - foreach ( QString path, m_pythonPaths ) - { - bp::str dir = path.toLocal8Bit().data(); - sys.attr( "path" ).attr( "append" )( dir ); - } - } - else - { - cWarning() << "creating PythonHelper more than once. This is very bad."; - return; + Py_Initialize(); } - s_instance = this; + m_mainModule = bp::import( "__main__" ); + m_mainNamespace = m_mainModule.attr( "__dict__" ); + + // If we're running from the build dir + add_if_lib_exists( QDir::current(), "libcalamares.so", m_pythonPaths ); + + QDir calaPythonPath( CalamaresUtils::systemLibDir().absolutePath() + QDir::separator() + "calamares" ); + add_if_lib_exists( calaPythonPath, "libcalamares.so", m_pythonPaths ); + + bp::object sys = bp::import( "sys" ); + + foreach ( QString path, m_pythonPaths ) + { + bp::str dir = path.toLocal8Bit().data(); + sys.attr( "path" ).attr( "append" )( dir ); + } } -Helper::~Helper() +Helper::~Helper() {} + +Helper* +Helper::instance() { - s_instance = nullptr; -} + static Helper* s_helper = nullptr; + if ( !s_helper ) + { + s_helper = new Helper; + } + return s_helper; +} boost::python::dict Helper::createCleanNamespace() diff --git a/src/libcalamares/PythonHelper.h b/src/libcalamares/PythonHelper.h index 418c75e5f..7528732a0 100644 --- a/src/libcalamares/PythonHelper.h +++ b/src/libcalamares/PythonHelper.h @@ -50,16 +50,15 @@ class Helper : public QObject { Q_OBJECT public: - virtual ~Helper(); - boost::python::dict createCleanNamespace(); QString handleLastError(); + static Helper* instance(); + private: - friend Helper* Calamares::PythonJob::helper(); - explicit Helper( QObject* parent = nullptr ); - static Helper* s_instance; + virtual ~Helper(); + explicit Helper(); boost::python::object m_mainModule; boost::python::object m_mainNamespace; diff --git a/src/libcalamares/PythonJob.cpp b/src/libcalamares/PythonJob.cpp index d94a20981..11a963df0 100644 --- a/src/libcalamares/PythonJob.cpp +++ b/src/libcalamares/PythonJob.cpp @@ -233,7 +233,7 @@ PythonJob::exec() try { - bp::dict scriptNamespace = helper()->createCleanNamespace(); + bp::dict scriptNamespace = CalamaresPython::Helper::instance()->createCleanNamespace(); bp::object calamaresModule = bp::import( "libcalamares" ); bp::dict calamaresNamespace = bp::extract< bp::dict >( calamaresModule.attr( "__dict__" ) ); @@ -299,7 +299,7 @@ PythonJob::exec() QString msg; if ( PyErr_Occurred() ) { - msg = helper()->handleLastError(); + msg = CalamaresPython::Helper::instance()->handleLastError(); } bp::handle_exception(); PyErr_Clear(); @@ -315,17 +315,4 @@ PythonJob::emitProgress( qreal progressValue ) emit progress( progressValue ); } - -CalamaresPython::Helper* -PythonJob::helper() -{ - auto ptr = CalamaresPython::Helper::s_instance; - if ( !ptr ) - { - ptr = new CalamaresPython::Helper; - } - return ptr; -} - - } // namespace Calamares diff --git a/src/libcalamares/PythonJob.h b/src/libcalamares/PythonJob.h index 7cd1b7165..ba2b0a75f 100644 --- a/src/libcalamares/PythonJob.h +++ b/src/libcalamares/PythonJob.h @@ -57,7 +57,6 @@ private: friend class CalamaresPython::PythonJobInterface; void emitProgress( double progressValue ); - CalamaresPython::Helper* helper(); QString m_scriptFile; QString m_workingPath; QString m_description; From aa62ca639b071755789adce99677af5ca31947f8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 9 Mar 2020 10:32:41 -0500 Subject: [PATCH 12/24] [libcalamares] Start getting prettyDescription from Python --- src/libcalamares/PythonJob.cpp | 6 ++++++ src/libcalamares/PythonJob.h | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libcalamares/PythonJob.cpp b/src/libcalamares/PythonJob.cpp index 11a963df0..dd0ea47c1 100644 --- a/src/libcalamares/PythonJob.cpp +++ b/src/libcalamares/PythonJob.cpp @@ -165,6 +165,11 @@ BOOST_PYTHON_MODULE( libcalamares ) namespace Calamares { +struct PythonJob::Private +{ + bp::object m_prettyStatusMessage; + bp::object m_prettyName; +}; PythonJob::PythonJob( const ModuleSystem::InstanceKey& instance, const QString& scriptFile, @@ -172,6 +177,7 @@ PythonJob::PythonJob( const ModuleSystem::InstanceKey& instance, const QVariantMap& moduleConfiguration, QObject* parent ) : Job( parent ) + , m_d( std::make_unique< Private >() ) , m_scriptFile( scriptFile ) , m_workingPath( workingPath ) , m_description() diff --git a/src/libcalamares/PythonJob.h b/src/libcalamares/PythonJob.h index ba2b0a75f..6f8c50a9f 100644 --- a/src/libcalamares/PythonJob.h +++ b/src/libcalamares/PythonJob.h @@ -53,10 +53,12 @@ public: virtual qreal getJobWeight() const override; private: - friend class CalamaresPython::Helper; + struct Private; + friend class CalamaresPython::PythonJobInterface; void emitProgress( double progressValue ); + std::unique_ptr< Private > m_d; QString m_scriptFile; QString m_workingPath; QString m_description; From ed4cdbeacc980b499b7ede9fe4022022e506638b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 9 Mar 2020 14:37:02 -0500 Subject: [PATCH 13/24] [dummypython] Provide status --- src/modules/dummypython/main.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/modules/dummypython/main.py b/src/modules/dummypython/main.py index d2730483d..2da9b4760 100644 --- a/src/modules/dummypython/main.py +++ b/src/modules/dummypython/main.py @@ -43,6 +43,10 @@ _ = gettext.translation("calamares-python", def pretty_name(): return _("Dummy python job.") +status = _("Dummy python step {}").format(0) + +def pretty_status_message(): + return status def run(): """Dummy python job.""" @@ -92,8 +96,10 @@ def run(): except KeyError: configlist = ["no list"] + global status c = 1 for k in configlist: + status = _("Dummy python step {}").format(str(c) + ":" + repr(k)) libcalamares.utils.debug(_("Dummy python step {}").format(str(k))) sleep(1) libcalamares.job.setprogress(c * 1.0 / len(configlist)) From 252089e372a2200fe9f27fb17b15058a649bb207 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 9 Mar 2020 15:01:07 -0500 Subject: [PATCH 14/24] [libcalamares] Refactor pretty_name() call - Split out a general method-that-returns-string caller. --- src/libcalamares/PythonJob.cpp | 39 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/libcalamares/PythonJob.cpp b/src/libcalamares/PythonJob.cpp index dd0ea47c1..37859b349 100644 --- a/src/libcalamares/PythonJob.cpp +++ b/src/libcalamares/PythonJob.cpp @@ -215,6 +215,18 @@ PythonJob::prettyStatusMessage() const } } +static QString +pythonStringMethod( bp::dict& script, const char* funcName ) +{ + bp::object func = script.get( funcName, bp::object() ); + if ( !func.is_none() ) + { + bp::extract< std::string > result( func() ); + return result.check() ? QString::fromStdString( result() ).trimmed() : QString(); + } + return QString(); +} + JobResult PythonJob::exec() @@ -248,27 +260,12 @@ PythonJob::exec() calamaresNamespace[ "globalstorage" ] = CalamaresPython::GlobalStoragePythonWrapper( JobQueue::instance()->globalStorage() ); + cDebug() << "Job file" << scriptFI.absoluteFilePath(); bp::object execResult = bp::exec_file( scriptFI.absoluteFilePath().toLocal8Bit().data(), scriptNamespace, scriptNamespace ); - bp::object entryPoint = scriptNamespace[ "run" ]; - bp::object prettyNameFunc = scriptNamespace.get( "pretty_name", bp::object() ); - - cDebug() << "Job file" << scriptFI.absoluteFilePath(); - if ( !prettyNameFunc.is_none() ) - { - bp::extract< std::string > prettyNameResult( prettyNameFunc() ); - if ( prettyNameResult.check() ) - { - m_description = QString::fromStdString( prettyNameResult() ).trimmed(); - } - if ( !m_description.isEmpty() ) - { - cDebug() << "Job description from pretty_name" << prettyName() << "=" << m_description; - emit progress( 0 ); - } - } + m_description = pythonStringMethod( scriptNamespace, "pretty_name" ); if ( m_description.isEmpty() ) { bp::extract< std::string > entryPoint_doc_attr( entryPoint.attr( "__doc__" ) ); @@ -281,10 +278,14 @@ PythonJob::exec() { m_description.truncate( i_newline ); } - cDebug() << "Job description from __doc__" << prettyName() << "=" << m_description; - emit progress( 0 ); + cDebug() << "Job description from __doc__" << prettyName() << '=' << m_description; } } + else + { + cDebug() << "Job description from pretty_name" << prettyName() << '=' << m_description; + } + emit progress( 0 ); bp::object runResult = entryPoint(); From b4aaf85ccf2244de991318b19d0fb14af91e2ffe Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 9 Mar 2020 15:13:40 -0500 Subject: [PATCH 15/24] [libcalamares] Call Python function if available for status --- src/libcalamares/PythonJob.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/libcalamares/PythonJob.cpp b/src/libcalamares/PythonJob.cpp index 37859b349..8165a4c9c 100644 --- a/src/libcalamares/PythonJob.cpp +++ b/src/libcalamares/PythonJob.cpp @@ -168,7 +168,6 @@ namespace Calamares struct PythonJob::Private { bp::object m_prettyStatusMessage; - bp::object m_prettyName; }; PythonJob::PythonJob( const ModuleSystem::InstanceKey& instance, @@ -205,6 +204,21 @@ PythonJob::prettyName() const QString PythonJob::prettyStatusMessage() const { + if ( m_d && !m_d->m_prettyStatusMessage.is_none() ) + { + cDebug() << "Getting dynamic message"; + QString r; + bp::extract< std::string > result( m_d->m_prettyStatusMessage() ); + r = result.check() ? QString::fromStdString( result() ).trimmed() : QString(); + if ( !r.isEmpty() ) + { + return r; + } + } + else + { + cDebug() << "Getting static message"; + } if ( m_description.isEmpty() ) { return tr( "Running %1 operation." ).arg( QDir( m_workingPath ).dirName() ); From ef249043f986eff12509b96e4b53428037fbe342 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 9 Mar 2020 15:39:35 -0500 Subject: [PATCH 16/24] [libcalamares] call Python method only from Python thread --- src/libcalamares/PythonJob.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/libcalamares/PythonJob.cpp b/src/libcalamares/PythonJob.cpp index 8165a4c9c..9069c49dc 100644 --- a/src/libcalamares/PythonJob.cpp +++ b/src/libcalamares/PythonJob.cpp @@ -204,21 +204,7 @@ PythonJob::prettyName() const QString PythonJob::prettyStatusMessage() const { - if ( m_d && !m_d->m_prettyStatusMessage.is_none() ) - { - cDebug() << "Getting dynamic message"; - QString r; - bp::extract< std::string > result( m_d->m_prettyStatusMessage() ); - r = result.check() ? QString::fromStdString( result() ).trimmed() : QString(); - if ( !r.isEmpty() ) - { - return r; - } - } - else - { - cDebug() << "Getting static message"; - } + // The description is updated when progress is reported, see emitProgress() if ( m_description.isEmpty() ) { return tr( "Running %1 operation." ).arg( QDir( m_workingPath ).dirName() ); @@ -279,6 +265,7 @@ PythonJob::exec() = bp::exec_file( scriptFI.absoluteFilePath().toLocal8Bit().data(), scriptNamespace, scriptNamespace ); bp::object entryPoint = scriptNamespace[ "run" ]; + m_d->m_prettyStatusMessage = scriptNamespace.get( "pretty_status_message", bp::object() ); m_description = pythonStringMethod( scriptNamespace, "pretty_name" ); if ( m_description.isEmpty() ) { @@ -333,6 +320,20 @@ PythonJob::exec() void PythonJob::emitProgress( qreal progressValue ) { + // This is called from the JobApi (and only from there) from the Job thread, + // so it is safe to call into the Python interpreter. Update the description + // as needed (don't call this from prettyStatusMessage(), which can be + // called from other threads as well). + if ( m_d && !m_d->m_prettyStatusMessage.is_none() ) + { + QString r; + bp::extract< std::string > result( m_d->m_prettyStatusMessage() ); + r = result.check() ? QString::fromStdString( result() ).trimmed() : QString(); + if ( !r.isEmpty() ) + { + m_description = r; + } + } emit progress( progressValue ); } From c4bfad93990e9426e911b7b5ee4458aeed61dee5 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 9 Mar 2020 15:40:45 -0500 Subject: [PATCH 17/24] [packages] Provide status feedback - The status message should be updated; the name is constant. FIXES #1330 --- src/modules/packages/main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/packages/main.py b/src/modules/packages/main.py index 8cbde9de6..8f58cd6fb 100644 --- a/src/modules/packages/main.py +++ b/src/modules/packages/main.py @@ -56,6 +56,10 @@ def _change_mode(mode): def pretty_name(): + return _("Install packages.") + + +def pretty_status_message(): if not group_packages: if (total_packages > 0): # Outside the context of an operation From 3f18a58cca4f10d7806ab65441aceb58dcbaf466 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 9 Mar 2020 20:36:40 -0500 Subject: [PATCH 18/24] Changes: document python-progress --- CHANGES | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 1c364e7f8..ad1aa55e8 100644 --- a/CHANGES +++ b/CHANGES @@ -9,10 +9,12 @@ This release contains contributions from (alphabetically by first name): - No external contributors yet ## Core ## - - No core changes yet + - Python job modules (such as *unpackfs* or *packages*) can now provide + a `pretty_status_message()` function, like the existing `pretty_name()` + function, that is used to update the status during install. #1330 ## Modules ## - - No module changes yet + - *packages* now reports more details in the installation progress-bar. # 3.2.20 (2020-02-27) # From 841ea9ff4875da20fb81ff251dbb9a0ef1ebda5c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 9 Mar 2020 20:54:22 -0500 Subject: [PATCH 19/24] [libcalamares] Tidy up includes - Remove commented-out includes - Consistent punctuation --- src/libcalamares/utils/TestPaths.cpp | 6 ------ src/libcalamaresui/utils/ImageRegistry.cpp | 2 +- src/libcalamaresui/viewpages/ExecutionViewStep.h | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/libcalamares/utils/TestPaths.cpp b/src/libcalamares/utils/TestPaths.cpp index 2fd7b9c98..382305ad5 100644 --- a/src/libcalamares/utils/TestPaths.cpp +++ b/src/libcalamares/utils/TestPaths.cpp @@ -26,14 +26,8 @@ #include "JobQueue.h" #include -// #include - #include -// #include -// #include -// #include - class TestPaths : public QObject { Q_OBJECT diff --git a/src/libcalamaresui/utils/ImageRegistry.cpp b/src/libcalamaresui/utils/ImageRegistry.cpp index 1c3b9433e..a08bbfc7d 100644 --- a/src/libcalamaresui/utils/ImageRegistry.cpp +++ b/src/libcalamaresui/utils/ImageRegistry.cpp @@ -25,9 +25,9 @@ #include "ImageRegistry.h" +#include #include #include -#include static QHash< QString, QHash< int, QHash< qint64, QPixmap > > > s_cache; diff --git a/src/libcalamaresui/viewpages/ExecutionViewStep.h b/src/libcalamaresui/viewpages/ExecutionViewStep.h index 8c4174cdb..e797c3cb2 100644 --- a/src/libcalamaresui/viewpages/ExecutionViewStep.h +++ b/src/libcalamaresui/viewpages/ExecutionViewStep.h @@ -20,7 +20,7 @@ #ifndef EXECUTIONVIEWSTEP_H #define EXECUTIONVIEWSTEP_H -#include +#include "ViewStep.h" #include From ebb3f319cc8df05d7725a76bd66cf40d34bfe20b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 9 Mar 2020 20:45:40 -0500 Subject: [PATCH 20/24] [modules] Be more consistent in include punctuation - Use <> for Qt, system, externals - Use double-quotes for Calamares headers --- src/modules/dracutlukscfg/DracutLuksCfgJob.h | 6 +++--- src/modules/dummycpp/DummyCppJob.h | 6 +++--- src/modules/fsresizer/ResizeFSJob.h | 4 ++-- .../InteractiveTerminalViewStep.h | 6 +++--- src/modules/keyboard/KeyboardViewStep.h | 6 +++--- src/modules/keyboard/SetKeyboardLayoutJob.cpp | 2 +- src/modules/keyboard/SetKeyboardLayoutJob.h | 2 +- src/modules/license/LicenseViewStep.h | 6 +++--- src/modules/locale/SetTimezoneJob.cpp | 2 +- src/modules/locale/SetTimezoneJob.h | 2 +- src/modules/machineid/MachineIdJob.h | 6 +++--- src/modules/oemid/OEMViewStep.h | 6 +++--- src/modules/partition/gui/EncryptWidget.cpp | 2 +- src/modules/partition/gui/PartitionBarsView.cpp | 12 +++++------- src/modules/partition/gui/PartitionViewStep.h | 6 +++--- src/modules/partition/tests/PartitionJobTests.h | 2 +- src/modules/plasmalnf/PlasmaLnfJob.h | 2 +- src/modules/plasmalnf/PlasmaLnfViewStep.h | 6 +++--- src/modules/summary/SummaryViewStep.h | 6 +++--- src/modules/tracking/TrackingViewStep.h | 6 +++--- src/modules/users/CreateUserJob.cpp | 2 +- src/modules/users/CreateUserJob.h | 2 +- src/modules/users/SetHostNameJob.h | 2 +- src/modules/users/SetPasswordJob.cpp | 2 +- src/modules/users/SetPasswordJob.h | 2 +- src/modules/webview/WebViewStep.h | 6 +++--- src/modules/welcome/WelcomeViewStep.h | 6 +++--- 27 files changed, 58 insertions(+), 60 deletions(-) diff --git a/src/modules/dracutlukscfg/DracutLuksCfgJob.h b/src/modules/dracutlukscfg/DracutLuksCfgJob.h index ccf0adb70..52b290d1c 100644 --- a/src/modules/dracutlukscfg/DracutLuksCfgJob.h +++ b/src/modules/dracutlukscfg/DracutLuksCfgJob.h @@ -23,11 +23,11 @@ #include #include -#include +#include "CppJob.h" -#include +#include "utils/PluginFactory.h" -#include +#include "DllMacro.h" class PLUGINDLLEXPORT DracutLuksCfgJob : public Calamares::CppJob { diff --git a/src/modules/dummycpp/DummyCppJob.h b/src/modules/dummycpp/DummyCppJob.h index c60b01d57..bf8625950 100644 --- a/src/modules/dummycpp/DummyCppJob.h +++ b/src/modules/dummycpp/DummyCppJob.h @@ -23,11 +23,11 @@ #include #include -#include +#include "CppJob.h" -#include +#include "utils/PluginFactory.h" -#include +#include "DllMacro.h" class PLUGINDLLEXPORT DummyCppJob : public Calamares::CppJob { diff --git a/src/modules/fsresizer/ResizeFSJob.h b/src/modules/fsresizer/ResizeFSJob.h index c681fae36..f7ff676cd 100644 --- a/src/modules/fsresizer/ResizeFSJob.h +++ b/src/modules/fsresizer/ResizeFSJob.h @@ -22,13 +22,13 @@ #include #include -#include +#include "CppJob.h" #include "partition/KPMManager.h" #include "partition/PartitionSize.h" #include "utils/PluginFactory.h" -#include +#include "DllMacro.h" class CoreBackend; // From KPMCore class Device; // From KPMCore diff --git a/src/modules/interactiveterminal/InteractiveTerminalViewStep.h b/src/modules/interactiveterminal/InteractiveTerminalViewStep.h index f0af35d3c..bf26ba91e 100644 --- a/src/modules/interactiveterminal/InteractiveTerminalViewStep.h +++ b/src/modules/interactiveterminal/InteractiveTerminalViewStep.h @@ -22,10 +22,10 @@ #include -#include -#include +#include "utils/PluginFactory.h" +#include "viewpages/ViewStep.h" -#include +#include "DllMacro.h" class InteractiveTerminalPage; diff --git a/src/modules/keyboard/KeyboardViewStep.h b/src/modules/keyboard/KeyboardViewStep.h index 9f362e116..ed072c834 100644 --- a/src/modules/keyboard/KeyboardViewStep.h +++ b/src/modules/keyboard/KeyboardViewStep.h @@ -22,10 +22,10 @@ #include -#include -#include +#include "utils/PluginFactory.h" +#include "viewpages/ViewStep.h" -#include +#include "DllMacro.h" class KeyboardPage; diff --git a/src/modules/keyboard/SetKeyboardLayoutJob.cpp b/src/modules/keyboard/SetKeyboardLayoutJob.cpp index 2a62c576c..79b23d7ca 100644 --- a/src/modules/keyboard/SetKeyboardLayoutJob.cpp +++ b/src/modules/keyboard/SetKeyboardLayoutJob.cpp @@ -22,7 +22,7 @@ * along with Calamares. If not, see . */ -#include +#include "SetKeyboardLayoutJob.h" #include "JobQueue.h" #include "GlobalStorage.h" diff --git a/src/modules/keyboard/SetKeyboardLayoutJob.h b/src/modules/keyboard/SetKeyboardLayoutJob.h index 60e916fc7..37ca709ef 100644 --- a/src/modules/keyboard/SetKeyboardLayoutJob.h +++ b/src/modules/keyboard/SetKeyboardLayoutJob.h @@ -20,7 +20,7 @@ #ifndef SETKEYBOARDLAYOUTJOB_H #define SETKEYBOARDLAYOUTJOB_H -#include +#include "Job.h" class SetKeyboardLayoutJob : public Calamares::Job diff --git a/src/modules/license/LicenseViewStep.h b/src/modules/license/LicenseViewStep.h index cc1a92896..6bfab4246 100644 --- a/src/modules/license/LicenseViewStep.h +++ b/src/modules/license/LicenseViewStep.h @@ -20,9 +20,9 @@ #ifndef LICENSEPAGEPLUGIN_H #define LICENSEPAGEPLUGIN_H -#include -#include -#include +#include "DllMacro.h" +#include "utils/PluginFactory.h" +#include "viewpages/ViewStep.h" #include #include diff --git a/src/modules/locale/SetTimezoneJob.cpp b/src/modules/locale/SetTimezoneJob.cpp index adcac13c1..aa8c4c241 100644 --- a/src/modules/locale/SetTimezoneJob.cpp +++ b/src/modules/locale/SetTimezoneJob.cpp @@ -17,7 +17,7 @@ * along with Calamares. If not, see . */ -#include +#include "SetTimezoneJob.h" #include "GlobalStorage.h" #include "JobQueue.h" diff --git a/src/modules/locale/SetTimezoneJob.h b/src/modules/locale/SetTimezoneJob.h index f7f2331ad..7b93770bb 100644 --- a/src/modules/locale/SetTimezoneJob.h +++ b/src/modules/locale/SetTimezoneJob.h @@ -19,7 +19,7 @@ #ifndef SETTIMEZONEJOB_H #define SETTIMEZONEJOB_H -#include +#include "Job.h" class SetTimezoneJob : public Calamares::Job diff --git a/src/modules/machineid/MachineIdJob.h b/src/modules/machineid/MachineIdJob.h index 3e450accb..08943392a 100644 --- a/src/modules/machineid/MachineIdJob.h +++ b/src/modules/machineid/MachineIdJob.h @@ -22,11 +22,11 @@ #include #include -#include +#include "CppJob.h" -#include +#include "utils/PluginFactory.h" -#include +#include "DllMacro.h" class PLUGINDLLEXPORT MachineIdJob : public Calamares::CppJob { diff --git a/src/modules/oemid/OEMViewStep.h b/src/modules/oemid/OEMViewStep.h index 57e2bba66..1f0e58915 100644 --- a/src/modules/oemid/OEMViewStep.h +++ b/src/modules/oemid/OEMViewStep.h @@ -19,10 +19,10 @@ #ifndef OEMVIEWSTEP_H #define OEMVIEWSTEP_H -#include -#include +#include "utils/PluginFactory.h" +#include "viewpages/ViewStep.h" -#include +#include "DllMacro.h" #include diff --git a/src/modules/partition/gui/EncryptWidget.cpp b/src/modules/partition/gui/EncryptWidget.cpp index 56938dec6..e83d10c2d 100644 --- a/src/modules/partition/gui/EncryptWidget.cpp +++ b/src/modules/partition/gui/EncryptWidget.cpp @@ -19,7 +19,7 @@ #include "EncryptWidget.h" -#include +#include "utils/CalamaresUtilsGui.h" EncryptWidget::EncryptWidget( QWidget* parent ) : QWidget( parent ) diff --git a/src/modules/partition/gui/PartitionBarsView.cpp b/src/modules/partition/gui/PartitionBarsView.cpp index 22e360182..b7c21473c 100644 --- a/src/modules/partition/gui/PartitionBarsView.cpp +++ b/src/modules/partition/gui/PartitionBarsView.cpp @@ -18,16 +18,14 @@ */ #include "gui/PartitionBarsView.h" -#include -#include +#include "core/PartitionModel.h" +#include "core/ColorUtils.h" + +#include "utils/CalamaresUtilsGui.h" +#include "utils/Logger.h" #include -#include -#include - - -// Qt #include #include #include diff --git a/src/modules/partition/gui/PartitionViewStep.h b/src/modules/partition/gui/PartitionViewStep.h index 20e9f4f1c..63d11c816 100644 --- a/src/modules/partition/gui/PartitionViewStep.h +++ b/src/modules/partition/gui/PartitionViewStep.h @@ -21,10 +21,10 @@ #ifndef PARTITIONVIEWSTEP_H #define PARTITIONVIEWSTEP_H -#include -#include +#include "utils/PluginFactory.h" +#include "viewpages/ViewStep.h" -#include +#include "DllMacro.h" #include "core/PartitionActions.h" diff --git a/src/modules/partition/tests/PartitionJobTests.h b/src/modules/partition/tests/PartitionJobTests.h index 1aad945e5..4ce064ec7 100644 --- a/src/modules/partition/tests/PartitionJobTests.h +++ b/src/modules/partition/tests/PartitionJobTests.h @@ -19,7 +19,7 @@ #ifndef PARTITIONJOBTESTS_H #define PARTITIONJOBTESTS_H -#include +#include "JobQueue.h" // CalaPM #include diff --git a/src/modules/plasmalnf/PlasmaLnfJob.h b/src/modules/plasmalnf/PlasmaLnfJob.h index 65e08579f..ef9ee1257 100644 --- a/src/modules/plasmalnf/PlasmaLnfJob.h +++ b/src/modules/plasmalnf/PlasmaLnfJob.h @@ -22,7 +22,7 @@ #include #include -#include +#include "Job.h" class PlasmaLnfJob : public Calamares::Job { diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.h b/src/modules/plasmalnf/PlasmaLnfViewStep.h index e99418549..0bf76934c 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.h +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.h @@ -19,9 +19,9 @@ #ifndef PLASMALNFVIEWSTEP_H #define PLASMALNFVIEWSTEP_H -#include -#include -#include +#include "utils/PluginFactory.h" +#include "viewpages/ViewStep.h" +#include "DllMacro.h" #include #include diff --git a/src/modules/summary/SummaryViewStep.h b/src/modules/summary/SummaryViewStep.h index 2c873e168..5b2f49b8e 100644 --- a/src/modules/summary/SummaryViewStep.h +++ b/src/modules/summary/SummaryViewStep.h @@ -21,10 +21,10 @@ #include -#include -#include +#include "utils/PluginFactory.h" +#include "viewpages/ViewStep.h" -#include +#include "DllMacro.h" class SummaryPage; diff --git a/src/modules/tracking/TrackingViewStep.h b/src/modules/tracking/TrackingViewStep.h index df6497d68..bb40d292a 100644 --- a/src/modules/tracking/TrackingViewStep.h +++ b/src/modules/tracking/TrackingViewStep.h @@ -21,9 +21,9 @@ #include "TrackingType.h" -#include -#include -#include +#include "DllMacro.h" +#include "utils/PluginFactory.h" +#include "viewpages/ViewStep.h" #include #include diff --git a/src/modules/users/CreateUserJob.cpp b/src/modules/users/CreateUserJob.cpp index 53b8e1521..2e4e7429e 100644 --- a/src/modules/users/CreateUserJob.cpp +++ b/src/modules/users/CreateUserJob.cpp @@ -17,7 +17,7 @@ * along with Calamares. If not, see . */ -#include +#include "CreateUserJob.h" #include "GlobalStorage.h" #include "JobQueue.h" diff --git a/src/modules/users/CreateUserJob.h b/src/modules/users/CreateUserJob.h index 98d7c001e..f2239307e 100644 --- a/src/modules/users/CreateUserJob.h +++ b/src/modules/users/CreateUserJob.h @@ -19,7 +19,7 @@ #ifndef CREATEUSERJOB_H #define CREATEUSERJOB_H -#include +#include "Job.h" #include diff --git a/src/modules/users/SetHostNameJob.h b/src/modules/users/SetHostNameJob.h index 619e2ba59..e3867b9d0 100644 --- a/src/modules/users/SetHostNameJob.h +++ b/src/modules/users/SetHostNameJob.h @@ -21,7 +21,7 @@ #ifndef SETHOSTNAMEJOB_CPP_H #define SETHOSTNAMEJOB_CPP_H -#include +#include "Job.h" class SetHostNameJob : public Calamares::Job { diff --git a/src/modules/users/SetPasswordJob.cpp b/src/modules/users/SetPasswordJob.cpp index 363a04ccc..3199a0a76 100644 --- a/src/modules/users/SetPasswordJob.cpp +++ b/src/modules/users/SetPasswordJob.cpp @@ -17,7 +17,7 @@ * along with Calamares. If not, see . */ -#include +#include "SetPasswordJob.h" #include "GlobalStorage.h" #include "JobQueue.h" diff --git a/src/modules/users/SetPasswordJob.h b/src/modules/users/SetPasswordJob.h index d2ebf64aa..cf5b2f585 100644 --- a/src/modules/users/SetPasswordJob.h +++ b/src/modules/users/SetPasswordJob.h @@ -20,7 +20,7 @@ #ifndef SETPASSWORDJOB_H #define SETPASSWORDJOB_H -#include +#include "Job.h" class SetPasswordJob : public Calamares::Job diff --git a/src/modules/webview/WebViewStep.h b/src/modules/webview/WebViewStep.h index 9ee2dfac9..a97d465de 100644 --- a/src/modules/webview/WebViewStep.h +++ b/src/modules/webview/WebViewStep.h @@ -23,10 +23,10 @@ #include "WebViewConfig.h" -#include -#include +#include "utils/PluginFactory.h" +#include "viewpages/ViewStep.h" -#include +#include "DllMacro.h" #include diff --git a/src/modules/welcome/WelcomeViewStep.h b/src/modules/welcome/WelcomeViewStep.h index 217f827e9..a829b65d6 100644 --- a/src/modules/welcome/WelcomeViewStep.h +++ b/src/modules/welcome/WelcomeViewStep.h @@ -22,10 +22,10 @@ #include #include -#include -#include +#include "utils/PluginFactory.h" +#include "viewpages/ViewStep.h" -#include +#include "DllMacro.h" #include From c5b038587e0d31c3937f38de60dc235813d5160d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 9 Mar 2020 21:07:12 -0500 Subject: [PATCH 21/24] [welcome] Tidy up includes --- src/modules/welcome/WelcomeViewStep.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/modules/welcome/WelcomeViewStep.h b/src/modules/welcome/WelcomeViewStep.h index a829b65d6..80ce0d16c 100644 --- a/src/modules/welcome/WelcomeViewStep.h +++ b/src/modules/welcome/WelcomeViewStep.h @@ -19,14 +19,11 @@ #ifndef WELCOMEPAGEPLUGIN_H #define WELCOMEPAGEPLUGIN_H -#include - -#include +#include "DllMacro.h" #include "utils/PluginFactory.h" #include "viewpages/ViewStep.h" -#include "DllMacro.h" - +#include #include class WelcomePage; From 350627172d974fe7ff15e1513601ad95f5e9e149 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 9 Mar 2020 21:09:24 -0500 Subject: [PATCH 22/24] [partition] Tidy up includes --- src/modules/partition/tests/PartitionJobTests.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/modules/partition/tests/PartitionJobTests.cpp b/src/modules/partition/tests/PartitionJobTests.cpp index 7684ad7a8..bd2c6f879 100644 --- a/src/modules/partition/tests/PartitionJobTests.cpp +++ b/src/modules/partition/tests/PartitionJobTests.cpp @@ -17,23 +17,21 @@ * along with Calamares. If not, see . */ -#include +#include "PartitionJobTests.h" + +#include "core/KPMHelpers.h" +#include "jobs/CreatePartitionJob.h" +#include "jobs/CreatePartitionTableJob.h" +#include "jobs/ResizePartitionJob.h" #include "partition/KPMManager.h" #include "partition/PartitionQuery.h" #include "utils/Logger.h" #include "utils/Units.h" -#include -#include -#include -#include - -// CalaPM #include #include -// Qt #include #include #include From 1299c64415f300e14b555f3ecca66a5e6c248ce8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 9 Mar 2020 21:13:19 -0500 Subject: [PATCH 23/24] [interactiveterminal] Tidy up includes - The KF5/ part of the path isn't necessary, and some of the KF5 includes can be found with a shorter name (with modern ECM and imported targets) --- src/modules/interactiveterminal/InteractiveTerminalPage.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/interactiveterminal/InteractiveTerminalPage.cpp b/src/modules/interactiveterminal/InteractiveTerminalPage.cpp index d41e50cab..5b2f81bfa 100644 --- a/src/modules/interactiveterminal/InteractiveTerminalPage.cpp +++ b/src/modules/interactiveterminal/InteractiveTerminalPage.cpp @@ -23,9 +23,9 @@ #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" -#include -#include -#include +#include +#include +#include #include #include From 220fd3122631768a43710f602046d7e298f8f518 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 9 Mar 2020 21:20:03 -0500 Subject: [PATCH 24/24] [partition] Improve EncryptionWidget - Use normal translation framework. The EncryptWidget was the one place not using the "usual" translation framework, but rolled its own. - Emphasize that the checkbox-state (checked-ness) is the parameter, not a state of the EncryptWidget. - All other instances of UI classes from Designer use a pointer-to-UI, not multiple inheritance. - Convenience method for setting the pixmap in response to changes in the passphrase - Tighten up types: enum -> enum class - Reduce the scope for int-confusion by using an enum-class for the encryption state of the widget - Include UI implementation header only in .cpp - Apply coding style - Update copyright --- src/modules/partition/gui/ChoicePage.cpp | 12 +- .../partition/gui/CreatePartitionDialog.cpp | 2 +- src/modules/partition/gui/EncryptWidget.cpp | 121 +++++++++--------- src/modules/partition/gui/EncryptWidget.h | 34 +++-- 4 files changed, 89 insertions(+), 80 deletions(-) diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index aebf9a7f6..89393262d 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -587,19 +587,19 @@ ChoicePage::doAlongsideSetupSplitter( const QModelIndex& current, void ChoicePage::onEncryptWidgetStateChanged() { - EncryptWidget::State state = m_encryptWidget->state(); + EncryptWidget::Encryption state = m_encryptWidget->state(); if ( m_choice == Erase ) { - if ( state == EncryptWidget::EncryptionConfirmed || - state == EncryptWidget::EncryptionDisabled ) + if ( state == EncryptWidget::Encryption::Confirmed || + state == EncryptWidget::Encryption::Disabled ) applyActionChoice( m_choice ); } else if ( m_choice == Replace ) { if ( m_beforePartitionBarsView && m_beforePartitionBarsView->selectionModel()->currentIndex().isValid() && - ( state == EncryptWidget::EncryptionConfirmed || - state == EncryptWidget::EncryptionDisabled ) ) + ( state == EncryptWidget::Encryption::Confirmed || + state == EncryptWidget::Encryption::Disabled ) ) { doReplaceSelectedPartition( m_beforePartitionBarsView-> selectionModel()-> @@ -1474,7 +1474,7 @@ ChoicePage::updateNextEnabled() if ( m_choice != Manual && m_encryptWidget->isVisible() && - m_encryptWidget->state() == EncryptWidget::EncryptionUnconfirmed ) + m_encryptWidget->state() == EncryptWidget::Encryption::Unconfirmed ) enabled = false; if ( enabled == m_nextEnabled ) diff --git a/src/modules/partition/gui/CreatePartitionDialog.cpp b/src/modules/partition/gui/CreatePartitionDialog.cpp index e69137740..a73441bc3 100644 --- a/src/modules/partition/gui/CreatePartitionDialog.cpp +++ b/src/modules/partition/gui/CreatePartitionDialog.cpp @@ -204,7 +204,7 @@ CreatePartitionDialog::createPartition() Partition* partition = nullptr; QString luksPassphrase = m_ui->encryptWidget->passphrase(); - if ( m_ui->encryptWidget->state() == EncryptWidget::EncryptionConfirmed && + if ( m_ui->encryptWidget->state() == EncryptWidget::Encryption::Confirmed && !luksPassphrase.isEmpty() ) { partition = KPMHelpers::createNewEncryptedPartition( diff --git a/src/modules/partition/gui/EncryptWidget.cpp b/src/modules/partition/gui/EncryptWidget.cpp index e83d10c2d..42a073db7 100644 --- a/src/modules/partition/gui/EncryptWidget.cpp +++ b/src/modules/partition/gui/EncryptWidget.cpp @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2016, Teo Mrnjavac + * Copyright 2020, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,42 +20,45 @@ #include "EncryptWidget.h" +#include "ui_EncryptWidget.h" + #include "utils/CalamaresUtilsGui.h" +#include "utils/Retranslator.h" EncryptWidget::EncryptWidget( QWidget* parent ) : QWidget( parent ) - , m_state( EncryptionDisabled ) + , m_ui( new Ui::EncryptWidget ) + , m_state( Encryption::Disabled ) { - setupUi( this ); + m_ui->setupUi( this ); - m_iconLabel->setFixedWidth( m_iconLabel->height() ); - m_passphraseLineEdit->hide(); - m_confirmLineEdit->hide(); - m_iconLabel->hide(); + m_ui->m_iconLabel->setFixedWidth( m_ui->m_iconLabel->height() ); + m_ui->m_passphraseLineEdit->hide(); + m_ui->m_confirmLineEdit->hide(); + m_ui->m_iconLabel->hide(); - connect( m_encryptCheckBox, &QCheckBox::stateChanged, - this, &EncryptWidget::onCheckBoxStateChanged ); - connect( m_passphraseLineEdit, &QLineEdit::textEdited, - this, &EncryptWidget::onPassphraseEdited ); - connect( m_confirmLineEdit, &QLineEdit::textEdited, - this, &EncryptWidget::onPassphraseEdited ); + connect( m_ui->m_encryptCheckBox, &QCheckBox::stateChanged, this, &EncryptWidget::onCheckBoxStateChanged ); + connect( m_ui->m_passphraseLineEdit, &QLineEdit::textEdited, this, &EncryptWidget::onPassphraseEdited ); + connect( m_ui->m_confirmLineEdit, &QLineEdit::textEdited, this, &EncryptWidget::onPassphraseEdited ); - setFixedHeight( m_passphraseLineEdit->height() ); // Avoid jumping up and down + setFixedHeight( m_ui->m_passphraseLineEdit->height() ); // Avoid jumping up and down updateState(); + + CALAMARES_RETRANSLATE_SLOT( &EncryptWidget::retranslate ) } void EncryptWidget::reset() { - m_passphraseLineEdit->clear(); - m_confirmLineEdit->clear(); + m_ui->m_passphraseLineEdit->clear(); + m_ui->m_confirmLineEdit->clear(); - m_encryptCheckBox->setChecked( false ); + m_ui->m_encryptCheckBox->setChecked( false ); } -EncryptWidget::State +EncryptWidget::Encryption EncryptWidget::state() const { return m_state; @@ -64,53 +68,48 @@ EncryptWidget::state() const void EncryptWidget::setText( const QString& text ) { - m_encryptCheckBox->setText( text ); + m_ui->m_encryptCheckBox->setText( text ); } QString EncryptWidget::passphrase() const { - if ( m_state == EncryptionConfirmed ) - return m_passphraseLineEdit->text(); + if ( m_state == Encryption::Confirmed ) + { + return m_ui->m_passphraseLineEdit->text(); + } return QString(); } void -EncryptWidget::changeEvent( QEvent* e ) +EncryptWidget::retranslate() { - QWidget::changeEvent( e ); - switch ( e->type() ) - { - case QEvent::LanguageChange: - retranslateUi( this ); - break; - default: - break; - } + m_ui->retranslateUi( this ); + onPassphraseEdited(); // For the tooltip } void EncryptWidget::updateState() { - State newState; - if ( m_encryptCheckBox->isChecked() ) + Encryption newState; + if ( m_ui->m_encryptCheckBox->isChecked() ) { - if ( !m_passphraseLineEdit->text().isEmpty() && - m_passphraseLineEdit->text() == m_confirmLineEdit->text() ) + if ( !m_ui->m_passphraseLineEdit->text().isEmpty() + && m_ui->m_passphraseLineEdit->text() == m_ui->m_confirmLineEdit->text() ) { - newState = EncryptionConfirmed; + newState = Encryption::Confirmed; } else { - newState = EncryptionUnconfirmed; + newState = Encryption::Unconfirmed; } } else { - newState = EncryptionDisabled; + newState = Encryption::Disabled; } if ( newState != m_state ) @@ -120,35 +119,38 @@ EncryptWidget::updateState() } } +///@brief Give @p label the @p pixmap from the standard-pixmaps +static void +applyPixmap( QLabel* label, CalamaresUtils::ImageType pixmap ) +{ + label->setFixedWidth( label->height() ); + label->setPixmap( CalamaresUtils::defaultPixmap( pixmap, CalamaresUtils::Original, label->size() ) ); +} void EncryptWidget::onPassphraseEdited() { - if ( !m_iconLabel->isVisible() ) - m_iconLabel->show(); + if ( !m_ui->m_iconLabel->isVisible() ) + { + m_ui->m_iconLabel->show(); + } - QString p1 = m_passphraseLineEdit->text(); - QString p2 = m_confirmLineEdit->text(); + QString p1 = m_ui->m_passphraseLineEdit->text(); + QString p2 = m_ui->m_confirmLineEdit->text(); - m_iconLabel->setToolTip( QString() ); + m_ui->m_iconLabel->setToolTip( QString() ); if ( p1.isEmpty() && p2.isEmpty() ) { - m_iconLabel->clear(); + m_ui->m_iconLabel->clear(); } else if ( p1 == p2 ) { - m_iconLabel->setFixedWidth( m_iconLabel->height() ); - m_iconLabel->setPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::Yes, - CalamaresUtils::Original, - m_iconLabel->size() ) ); + applyPixmap( m_ui->m_iconLabel, CalamaresUtils::Yes ); } else { - m_iconLabel->setFixedWidth( m_iconLabel->height() ); - m_iconLabel->setPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::No, - CalamaresUtils::Original, - m_iconLabel->size() ) ); - m_iconLabel->setToolTip( tr( "Please enter the same passphrase in both boxes." ) ); + applyPixmap( m_ui->m_iconLabel, CalamaresUtils::No ); + m_ui->m_iconLabel->setToolTip( tr( "Please enter the same passphrase in both boxes." ) ); } updateState(); @@ -156,14 +158,15 @@ EncryptWidget::onPassphraseEdited() void -EncryptWidget::onCheckBoxStateChanged( int state ) +EncryptWidget::onCheckBoxStateChanged( int checked ) { - m_passphraseLineEdit->setVisible( state ); - m_confirmLineEdit->setVisible( state ); - m_iconLabel->setVisible( state ); - m_passphraseLineEdit->clear(); - m_confirmLineEdit->clear(); - m_iconLabel->clear(); + // @p checked is a Qt::CheckState, 0 is "unchecked" and 2 is "checked" + m_ui->m_passphraseLineEdit->setVisible( checked ); + m_ui->m_confirmLineEdit->setVisible( checked ); + m_ui->m_iconLabel->setVisible( checked ); + m_ui->m_passphraseLineEdit->clear(); + m_ui->m_confirmLineEdit->clear(); + m_ui->m_iconLabel->clear(); updateState(); } diff --git a/src/modules/partition/gui/EncryptWidget.h b/src/modules/partition/gui/EncryptWidget.h index 3f3cb1681..79beb1fa7 100644 --- a/src/modules/partition/gui/EncryptWidget.h +++ b/src/modules/partition/gui/EncryptWidget.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2016, Teo Mrnjavac + * Copyright 2020, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,41 +21,46 @@ #ifndef ENCRYPTWIDGET_H #define ENCRYPTWIDGET_H -#include "ui_EncryptWidget.h" +#include -class EncryptWidget : public QWidget, private Ui::EncryptWidget +namespace Ui +{ + class EncryptWidget; +} + +class EncryptWidget : public QWidget { Q_OBJECT public: - enum State : unsigned short + enum class Encryption : unsigned short { - EncryptionDisabled = 0, - EncryptionUnconfirmed, - EncryptionConfirmed + Disabled = 0, + Unconfirmed, + Confirmed }; explicit EncryptWidget( QWidget* parent = nullptr ); void reset(); - State state() const; + Encryption state() const; void setText( const QString& text ); QString passphrase() const; -signals: - void stateChanged( State ); + void retranslate(); -protected: - void changeEvent( QEvent* e ); +signals: + void stateChanged( Encryption ); private: void updateState(); void onPassphraseEdited(); - void onCheckBoxStateChanged( int state ); + void onCheckBoxStateChanged( int checked ); - State m_state; + Ui::EncryptWidget* m_ui; + Encryption m_state; }; -#endif // ENCRYPTWIDGET_H +#endif // ENCRYPTWIDGET_H