Merge branch 'master' of https://github.com/calamares/calamares into development

This commit is contained in:
Philip Müller 2020-03-10 10:50:58 +01:00
commit 6af4da1db3
44 changed files with 278 additions and 249 deletions

View File

@ -9,10 +9,12 @@ This release contains contributions from (alphabetically by first name):
- No external contributors yet - No external contributors yet
## Core ## ## 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 ## ## Modules ##
- No module changes yet - *packages* now reports more details in the installation progress-bar.
# 3.2.20 (2020-02-27) # # 3.2.20 (2020-02-27) #

View File

@ -105,8 +105,20 @@ public:
* how much work is (relatively) done. * how much work is (relatively) done.
*/ */
virtual qreal getJobWeight() const; 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; virtual QString prettyName() const = 0;
// TODO: Unused
virtual QString prettyDescription() const; 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 QString prettyStatusMessage() const;
virtual JobResult exec() = 0; virtual JobResult exec() = 0;

View File

@ -204,8 +204,6 @@ variantHashFromPyDict( const boost::python::dict& pyDict )
} }
Helper* Helper::s_instance = nullptr;
static inline void static inline void
add_if_lib_exists( const QDir& dir, const char* name, QStringList& list ) 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 ) Helper::Helper()
: QObject( parent ) : QObject( nullptr )
{ {
// Let's make extra sure we only call Py_Initialize once // Let's make extra sure we only call Py_Initialize once
if ( !s_instance ) if ( !Py_IsInitialized() )
{ {
if ( !Py_IsInitialized() ) Py_Initialize();
{
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;
} }
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 boost::python::dict
Helper::createCleanNamespace() Helper::createCleanNamespace()

View File

@ -50,16 +50,15 @@ class Helper : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
virtual ~Helper();
boost::python::dict createCleanNamespace(); boost::python::dict createCleanNamespace();
QString handleLastError(); QString handleLastError();
static Helper* instance();
private: private:
friend Helper* Calamares::PythonJob::helper(); virtual ~Helper();
explicit Helper( QObject* parent = nullptr ); explicit Helper();
static Helper* s_instance;
boost::python::object m_mainModule; boost::python::object m_mainModule;
boost::python::object m_mainNamespace; boost::python::object m_mainNamespace;

View File

@ -165,6 +165,10 @@ BOOST_PYTHON_MODULE( libcalamares )
namespace Calamares namespace Calamares
{ {
struct PythonJob::Private
{
bp::object m_prettyStatusMessage;
};
PythonJob::PythonJob( const ModuleSystem::InstanceKey& instance, PythonJob::PythonJob( const ModuleSystem::InstanceKey& instance,
const QString& scriptFile, const QString& scriptFile,
@ -172,6 +176,7 @@ PythonJob::PythonJob( const ModuleSystem::InstanceKey& instance,
const QVariantMap& moduleConfiguration, const QVariantMap& moduleConfiguration,
QObject* parent ) QObject* parent )
: Job( parent ) : Job( parent )
, m_d( std::make_unique< Private >() )
, m_scriptFile( scriptFile ) , m_scriptFile( scriptFile )
, m_workingPath( workingPath ) , m_workingPath( workingPath )
, m_description() , m_description()
@ -199,6 +204,7 @@ PythonJob::prettyName() const
QString QString
PythonJob::prettyStatusMessage() const PythonJob::prettyStatusMessage() const
{ {
// The description is updated when progress is reported, see emitProgress()
if ( m_description.isEmpty() ) if ( m_description.isEmpty() )
{ {
return tr( "Running %1 operation." ).arg( QDir( m_workingPath ).dirName() ); return tr( "Running %1 operation." ).arg( QDir( m_workingPath ).dirName() );
@ -209,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 JobResult
PythonJob::exec() PythonJob::exec()
@ -233,7 +251,7 @@ PythonJob::exec()
try try
{ {
bp::dict scriptNamespace = helper()->createCleanNamespace(); bp::dict scriptNamespace = CalamaresPython::Helper::instance()->createCleanNamespace();
bp::object calamaresModule = bp::import( "libcalamares" ); bp::object calamaresModule = bp::import( "libcalamares" );
bp::dict calamaresNamespace = bp::extract< bp::dict >( calamaresModule.attr( "__dict__" ) ); bp::dict calamaresNamespace = bp::extract< bp::dict >( calamaresModule.attr( "__dict__" ) );
@ -242,27 +260,13 @@ PythonJob::exec()
calamaresNamespace[ "globalstorage" ] calamaresNamespace[ "globalstorage" ]
= CalamaresPython::GlobalStoragePythonWrapper( JobQueue::instance()->globalStorage() ); = CalamaresPython::GlobalStoragePythonWrapper( JobQueue::instance()->globalStorage() );
cDebug() << "Job file" << scriptFI.absoluteFilePath();
bp::object execResult bp::object execResult
= bp::exec_file( scriptFI.absoluteFilePath().toLocal8Bit().data(), scriptNamespace, scriptNamespace ); = bp::exec_file( scriptFI.absoluteFilePath().toLocal8Bit().data(), scriptNamespace, scriptNamespace );
bp::object entryPoint = scriptNamespace[ "run" ]; 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_d->m_prettyStatusMessage = scriptNamespace.get( "pretty_status_message", bp::object() );
m_description = pythonStringMethod( scriptNamespace, "pretty_name" );
if ( m_description.isEmpty() ) if ( m_description.isEmpty() )
{ {
bp::extract< std::string > entryPoint_doc_attr( entryPoint.attr( "__doc__" ) ); bp::extract< std::string > entryPoint_doc_attr( entryPoint.attr( "__doc__" ) );
@ -275,10 +279,14 @@ PythonJob::exec()
{ {
m_description.truncate( i_newline ); m_description.truncate( i_newline );
} }
cDebug() << "Job description from __doc__" << prettyName() << "=" << m_description; cDebug() << "Job description from __doc__" << prettyName() << '=' << m_description;
emit progress( 0 );
} }
} }
else
{
cDebug() << "Job description from pretty_name" << prettyName() << '=' << m_description;
}
emit progress( 0 );
bp::object runResult = entryPoint(); bp::object runResult = entryPoint();
@ -299,7 +307,7 @@ PythonJob::exec()
QString msg; QString msg;
if ( PyErr_Occurred() ) if ( PyErr_Occurred() )
{ {
msg = helper()->handleLastError(); msg = CalamaresPython::Helper::instance()->handleLastError();
} }
bp::handle_exception(); bp::handle_exception();
PyErr_Clear(); PyErr_Clear();
@ -312,20 +320,21 @@ PythonJob::exec()
void void
PythonJob::emitProgress( qreal progressValue ) 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 ); emit progress( progressValue );
} }
CalamaresPython::Helper*
PythonJob::helper()
{
auto ptr = CalamaresPython::Helper::s_instance;
if ( !ptr )
{
ptr = new CalamaresPython::Helper;
}
return ptr;
}
} // namespace Calamares } // namespace Calamares

View File

@ -53,11 +53,12 @@ public:
virtual qreal getJobWeight() const override; virtual qreal getJobWeight() const override;
private: private:
friend class CalamaresPython::Helper; struct Private;
friend class CalamaresPython::PythonJobInterface; friend class CalamaresPython::PythonJobInterface;
void emitProgress( double progressValue ); void emitProgress( double progressValue );
CalamaresPython::Helper* helper(); std::unique_ptr< Private > m_d;
QString m_scriptFile; QString m_scriptFile;
QString m_workingPath; QString m_workingPath;
QString m_description; QString m_description;

View File

@ -171,7 +171,7 @@ PythonJobInterface::PythonJobInterface( Calamares::PythonJob* parent )
void void
PythonJobInterface::setprogress( qreal progress ) PythonJobInterface::setprogress( qreal progress )
{ {
if ( progress >= 0 && progress <= 1 ) if ( progress >= 0.0 && progress <= 1.0 )
{ {
m_parent->emitProgress( progress ); m_parent->emitProgress( progress );
} }

View File

@ -26,14 +26,8 @@
#include "JobQueue.h" #include "JobQueue.h"
#include <QDir> #include <QDir>
// #include <QTemporaryFile>
#include <QtTest/QtTest> #include <QtTest/QtTest>
// #include <fcntl.h>
// #include <sys/stat.h>
// #include <unistd.h>
class TestPaths : public QObject class TestPaths : public QObject
{ {
Q_OBJECT Q_OBJECT

View File

@ -25,9 +25,9 @@
#include "ImageRegistry.h" #include "ImageRegistry.h"
#include <QIcon>
#include <QPainter> #include <QPainter>
#include <QSvgRenderer> #include <QSvgRenderer>
#include <qicon.h>
static QHash< QString, QHash< int, QHash< qint64, QPixmap > > > s_cache; static QHash< QString, QHash< int, QHash< qint64, QPixmap > > > s_cache;

View File

@ -20,7 +20,7 @@
#ifndef EXECUTIONVIEWSTEP_H #ifndef EXECUTIONVIEWSTEP_H
#define EXECUTIONVIEWSTEP_H #define EXECUTIONVIEWSTEP_H
#include <viewpages/ViewStep.h> #include "ViewStep.h"
#include <QStringList> #include <QStringList>

View File

@ -23,11 +23,11 @@
#include <QObject> #include <QObject>
#include <QVariantMap> #include <QVariantMap>
#include <CppJob.h> #include "CppJob.h"
#include <utils/PluginFactory.h> #include "utils/PluginFactory.h"
#include <DllMacro.h> #include "DllMacro.h"
class PLUGINDLLEXPORT DracutLuksCfgJob : public Calamares::CppJob class PLUGINDLLEXPORT DracutLuksCfgJob : public Calamares::CppJob
{ {

View File

@ -23,11 +23,11 @@
#include <QObject> #include <QObject>
#include <QVariantMap> #include <QVariantMap>
#include <CppJob.h> #include "CppJob.h"
#include <utils/PluginFactory.h> #include "utils/PluginFactory.h"
#include <DllMacro.h> #include "DllMacro.h"
class PLUGINDLLEXPORT DummyCppJob : public Calamares::CppJob class PLUGINDLLEXPORT DummyCppJob : public Calamares::CppJob
{ {

View File

@ -43,6 +43,10 @@ _ = gettext.translation("calamares-python",
def pretty_name(): def pretty_name():
return _("Dummy python job.") return _("Dummy python job.")
status = _("Dummy python step {}").format(0)
def pretty_status_message():
return status
def run(): def run():
"""Dummy python job.""" """Dummy python job."""
@ -92,8 +96,10 @@ def run():
except KeyError: except KeyError:
configlist = ["no list"] configlist = ["no list"]
global status
c = 1 c = 1
for k in configlist: for k in configlist:
status = _("Dummy python step {}").format(str(c) + ":" + repr(k))
libcalamares.utils.debug(_("Dummy python step {}").format(str(k))) libcalamares.utils.debug(_("Dummy python step {}").format(str(k)))
sleep(1) sleep(1)
libcalamares.job.setprogress(c * 1.0 / len(configlist)) libcalamares.job.setprogress(c * 1.0 / len(configlist))

View File

@ -22,13 +22,13 @@
#include <QObject> #include <QObject>
#include <QVariantMap> #include <QVariantMap>
#include <CppJob.h> #include "CppJob.h"
#include "partition/KPMManager.h" #include "partition/KPMManager.h"
#include "partition/PartitionSize.h" #include "partition/PartitionSize.h"
#include "utils/PluginFactory.h" #include "utils/PluginFactory.h"
#include <DllMacro.h> #include "DllMacro.h"
class CoreBackend; // From KPMCore class CoreBackend; // From KPMCore
class Device; // From KPMCore class Device; // From KPMCore

View File

@ -23,9 +23,9 @@
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include <KF5/KService/kservice.h> #include <KService>
#include <KF5/KParts/kde_terminal_interface.h> #include <KParts/kde_terminal_interface.h>
#include <KF5/KParts/kparts/readonlypart.h> #include <KParts/ReadOnlyPart>
#include <QApplication> #include <QApplication>
#include <QDir> #include <QDir>

View File

@ -22,10 +22,10 @@
#include <QObject> #include <QObject>
#include <utils/PluginFactory.h> #include "utils/PluginFactory.h"
#include <viewpages/ViewStep.h> #include "viewpages/ViewStep.h"
#include <DllMacro.h> #include "DllMacro.h"
class InteractiveTerminalPage; class InteractiveTerminalPage;

View File

@ -22,10 +22,10 @@
#include <QObject> #include <QObject>
#include <utils/PluginFactory.h> #include "utils/PluginFactory.h"
#include <viewpages/ViewStep.h> #include "viewpages/ViewStep.h"
#include <DllMacro.h> #include "DllMacro.h"
class KeyboardPage; class KeyboardPage;

View File

@ -22,7 +22,7 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <SetKeyboardLayoutJob.h> #include "SetKeyboardLayoutJob.h"
#include "JobQueue.h" #include "JobQueue.h"
#include "GlobalStorage.h" #include "GlobalStorage.h"

View File

@ -20,7 +20,7 @@
#ifndef SETKEYBOARDLAYOUTJOB_H #ifndef SETKEYBOARDLAYOUTJOB_H
#define SETKEYBOARDLAYOUTJOB_H #define SETKEYBOARDLAYOUTJOB_H
#include <Job.h> #include "Job.h"
class SetKeyboardLayoutJob : public Calamares::Job class SetKeyboardLayoutJob : public Calamares::Job

View File

@ -20,9 +20,9 @@
#ifndef LICENSEPAGEPLUGIN_H #ifndef LICENSEPAGEPLUGIN_H
#define LICENSEPAGEPLUGIN_H #define LICENSEPAGEPLUGIN_H
#include <DllMacro.h> #include "DllMacro.h"
#include <utils/PluginFactory.h> #include "utils/PluginFactory.h"
#include <viewpages/ViewStep.h> #include "viewpages/ViewStep.h"
#include <QObject> #include <QObject>
#include <QUrl> #include <QUrl>

View File

@ -17,7 +17,7 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <SetTimezoneJob.h> #include "SetTimezoneJob.h"
#include "GlobalStorage.h" #include "GlobalStorage.h"
#include "JobQueue.h" #include "JobQueue.h"

View File

@ -19,7 +19,7 @@
#ifndef SETTIMEZONEJOB_H #ifndef SETTIMEZONEJOB_H
#define SETTIMEZONEJOB_H #define SETTIMEZONEJOB_H
#include <Job.h> #include "Job.h"
class SetTimezoneJob : public Calamares::Job class SetTimezoneJob : public Calamares::Job

View File

@ -22,11 +22,11 @@
#include <QObject> #include <QObject>
#include <QVariantMap> #include <QVariantMap>
#include <CppJob.h> #include "CppJob.h"
#include <utils/PluginFactory.h> #include "utils/PluginFactory.h"
#include <DllMacro.h> #include "DllMacro.h"
class PLUGINDLLEXPORT MachineIdJob : public Calamares::CppJob class PLUGINDLLEXPORT MachineIdJob : public Calamares::CppJob
{ {

View File

@ -19,10 +19,10 @@
#ifndef OEMVIEWSTEP_H #ifndef OEMVIEWSTEP_H
#define OEMVIEWSTEP_H #define OEMVIEWSTEP_H
#include <utils/PluginFactory.h> #include "utils/PluginFactory.h"
#include <viewpages/ViewStep.h> #include "viewpages/ViewStep.h"
#include <DllMacro.h> #include "DllMacro.h"
#include <QVariantMap> #include <QVariantMap>

View File

@ -56,6 +56,10 @@ def _change_mode(mode):
def pretty_name(): def pretty_name():
return _("Install packages.")
def pretty_status_message():
if not group_packages: if not group_packages:
if (total_packages > 0): if (total_packages > 0):
# Outside the context of an operation # Outside the context of an operation
@ -332,19 +336,23 @@ class PMDummy(PackageManager):
backend = "dummy" backend = "dummy"
def install(self, pkgs, from_local=False): 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): 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): def update_db(self):
libcalamares.utils.debug("Updating DB") libcalamares.utils.debug("Dummy backend: Updating DB")
def update_system(self): def update_system(self):
libcalamares.utils.debug("Updating System") libcalamares.utils.debug("Dummy backend: Updating System")
def run(self, script): def run(self, script):
libcalamares.utils.debug("Running script '" + str(script) + "'") libcalamares.utils.debug("Dummy backend: Running script '" + str(script) + "'")
class PMPisi(PackageManager): class PMPisi(PackageManager):
@ -502,7 +510,7 @@ def run_operations(pkgman, entry):
libcalamares.utils.warning("Unknown package-operation key {!s}".format(key)) libcalamares.utils.warning("Unknown package-operation key {!s}".format(key))
completed_packages += len(package_list) completed_packages += len(package_list)
libcalamares.job.setprogress(completed_packages * 1.0 / total_packages) 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 group_packages = 0
_change_mode(None) _change_mode(None)

View File

@ -587,19 +587,19 @@ ChoicePage::doAlongsideSetupSplitter( const QModelIndex& current,
void void
ChoicePage::onEncryptWidgetStateChanged() ChoicePage::onEncryptWidgetStateChanged()
{ {
EncryptWidget::State state = m_encryptWidget->state(); EncryptWidget::Encryption state = m_encryptWidget->state();
if ( m_choice == Erase ) if ( m_choice == Erase )
{ {
if ( state == EncryptWidget::EncryptionConfirmed || if ( state == EncryptWidget::Encryption::Confirmed ||
state == EncryptWidget::EncryptionDisabled ) state == EncryptWidget::Encryption::Disabled )
applyActionChoice( m_choice ); applyActionChoice( m_choice );
} }
else if ( m_choice == Replace ) else if ( m_choice == Replace )
{ {
if ( m_beforePartitionBarsView && if ( m_beforePartitionBarsView &&
m_beforePartitionBarsView->selectionModel()->currentIndex().isValid() && m_beforePartitionBarsView->selectionModel()->currentIndex().isValid() &&
( state == EncryptWidget::EncryptionConfirmed || ( state == EncryptWidget::Encryption::Confirmed ||
state == EncryptWidget::EncryptionDisabled ) ) state == EncryptWidget::Encryption::Disabled ) )
{ {
doReplaceSelectedPartition( m_beforePartitionBarsView-> doReplaceSelectedPartition( m_beforePartitionBarsView->
selectionModel()-> selectionModel()->
@ -1474,7 +1474,7 @@ ChoicePage::updateNextEnabled()
if ( m_choice != Manual && if ( m_choice != Manual &&
m_encryptWidget->isVisible() && m_encryptWidget->isVisible() &&
m_encryptWidget->state() == EncryptWidget::EncryptionUnconfirmed ) m_encryptWidget->state() == EncryptWidget::Encryption::Unconfirmed )
enabled = false; enabled = false;
if ( enabled == m_nextEnabled ) if ( enabled == m_nextEnabled )

View File

@ -204,7 +204,7 @@ CreatePartitionDialog::createPartition()
Partition* partition = nullptr; Partition* partition = nullptr;
QString luksPassphrase = m_ui->encryptWidget->passphrase(); QString luksPassphrase = m_ui->encryptWidget->passphrase();
if ( m_ui->encryptWidget->state() == EncryptWidget::EncryptionConfirmed && if ( m_ui->encryptWidget->state() == EncryptWidget::Encryption::Confirmed &&
!luksPassphrase.isEmpty() ) !luksPassphrase.isEmpty() )
{ {
partition = KPMHelpers::createNewEncryptedPartition( partition = KPMHelpers::createNewEncryptedPartition(

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> === /* === This file is part of Calamares - <https://github.com/calamares> ===
* *
* Copyright 2016, Teo Mrnjavac <teo@kde.org> * Copyright 2016, Teo Mrnjavac <teo@kde.org>
* Copyright 2020, Adriaan de Groot <groot@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -19,42 +20,45 @@
#include "EncryptWidget.h" #include "EncryptWidget.h"
#include <utils/CalamaresUtilsGui.h> #include "ui_EncryptWidget.h"
#include "utils/CalamaresUtilsGui.h"
#include "utils/Retranslator.h"
EncryptWidget::EncryptWidget( QWidget* parent ) EncryptWidget::EncryptWidget( QWidget* parent )
: 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_ui->m_iconLabel->setFixedWidth( m_ui->m_iconLabel->height() );
m_passphraseLineEdit->hide(); m_ui->m_passphraseLineEdit->hide();
m_confirmLineEdit->hide(); m_ui->m_confirmLineEdit->hide();
m_iconLabel->hide(); m_ui->m_iconLabel->hide();
connect( m_encryptCheckBox, &QCheckBox::stateChanged, connect( m_ui->m_encryptCheckBox, &QCheckBox::stateChanged, this, &EncryptWidget::onCheckBoxStateChanged );
this, &EncryptWidget::onCheckBoxStateChanged ); connect( m_ui->m_passphraseLineEdit, &QLineEdit::textEdited, this, &EncryptWidget::onPassphraseEdited );
connect( m_passphraseLineEdit, &QLineEdit::textEdited, connect( m_ui->m_confirmLineEdit, &QLineEdit::textEdited, this, &EncryptWidget::onPassphraseEdited );
this, &EncryptWidget::onPassphraseEdited );
connect( 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(); updateState();
CALAMARES_RETRANSLATE_SLOT( &EncryptWidget::retranslate )
} }
void void
EncryptWidget::reset() EncryptWidget::reset()
{ {
m_passphraseLineEdit->clear(); m_ui->m_passphraseLineEdit->clear();
m_confirmLineEdit->clear(); m_ui->m_confirmLineEdit->clear();
m_encryptCheckBox->setChecked( false ); m_ui->m_encryptCheckBox->setChecked( false );
} }
EncryptWidget::State EncryptWidget::Encryption
EncryptWidget::state() const EncryptWidget::state() const
{ {
return m_state; return m_state;
@ -64,53 +68,48 @@ EncryptWidget::state() const
void void
EncryptWidget::setText( const QString& text ) EncryptWidget::setText( const QString& text )
{ {
m_encryptCheckBox->setText( text ); m_ui->m_encryptCheckBox->setText( text );
} }
QString QString
EncryptWidget::passphrase() const EncryptWidget::passphrase() const
{ {
if ( m_state == EncryptionConfirmed ) if ( m_state == Encryption::Confirmed )
return m_passphraseLineEdit->text(); {
return m_ui->m_passphraseLineEdit->text();
}
return QString(); return QString();
} }
void void
EncryptWidget::changeEvent( QEvent* e ) EncryptWidget::retranslate()
{ {
QWidget::changeEvent( e ); m_ui->retranslateUi( this );
switch ( e->type() ) onPassphraseEdited(); // For the tooltip
{
case QEvent::LanguageChange:
retranslateUi( this );
break;
default:
break;
}
} }
void void
EncryptWidget::updateState() EncryptWidget::updateState()
{ {
State newState; Encryption newState;
if ( m_encryptCheckBox->isChecked() ) if ( m_ui->m_encryptCheckBox->isChecked() )
{ {
if ( !m_passphraseLineEdit->text().isEmpty() && if ( !m_ui->m_passphraseLineEdit->text().isEmpty()
m_passphraseLineEdit->text() == m_confirmLineEdit->text() ) && m_ui->m_passphraseLineEdit->text() == m_ui->m_confirmLineEdit->text() )
{ {
newState = EncryptionConfirmed; newState = Encryption::Confirmed;
} }
else else
{ {
newState = EncryptionUnconfirmed; newState = Encryption::Unconfirmed;
} }
} }
else else
{ {
newState = EncryptionDisabled; newState = Encryption::Disabled;
} }
if ( newState != m_state ) 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 void
EncryptWidget::onPassphraseEdited() EncryptWidget::onPassphraseEdited()
{ {
if ( !m_iconLabel->isVisible() ) if ( !m_ui->m_iconLabel->isVisible() )
m_iconLabel->show(); {
m_ui->m_iconLabel->show();
}
QString p1 = m_passphraseLineEdit->text(); QString p1 = m_ui->m_passphraseLineEdit->text();
QString p2 = m_confirmLineEdit->text(); QString p2 = m_ui->m_confirmLineEdit->text();
m_iconLabel->setToolTip( QString() ); m_ui->m_iconLabel->setToolTip( QString() );
if ( p1.isEmpty() && p2.isEmpty() ) if ( p1.isEmpty() && p2.isEmpty() )
{ {
m_iconLabel->clear(); m_ui->m_iconLabel->clear();
} }
else if ( p1 == p2 ) else if ( p1 == p2 )
{ {
m_iconLabel->setFixedWidth( m_iconLabel->height() ); applyPixmap( m_ui->m_iconLabel, CalamaresUtils::Yes );
m_iconLabel->setPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::Yes,
CalamaresUtils::Original,
m_iconLabel->size() ) );
} }
else else
{ {
m_iconLabel->setFixedWidth( m_iconLabel->height() ); applyPixmap( m_ui->m_iconLabel, CalamaresUtils::No );
m_iconLabel->setPixmap( CalamaresUtils::defaultPixmap( CalamaresUtils::No, m_ui->m_iconLabel->setToolTip( tr( "Please enter the same passphrase in both boxes." ) );
CalamaresUtils::Original,
m_iconLabel->size() ) );
m_iconLabel->setToolTip( tr( "Please enter the same passphrase in both boxes." ) );
} }
updateState(); updateState();
@ -156,14 +158,15 @@ EncryptWidget::onPassphraseEdited()
void void
EncryptWidget::onCheckBoxStateChanged( int state ) EncryptWidget::onCheckBoxStateChanged( int checked )
{ {
m_passphraseLineEdit->setVisible( state ); // @p checked is a Qt::CheckState, 0 is "unchecked" and 2 is "checked"
m_confirmLineEdit->setVisible( state ); m_ui->m_passphraseLineEdit->setVisible( checked );
m_iconLabel->setVisible( state ); m_ui->m_confirmLineEdit->setVisible( checked );
m_passphraseLineEdit->clear(); m_ui->m_iconLabel->setVisible( checked );
m_confirmLineEdit->clear(); m_ui->m_passphraseLineEdit->clear();
m_iconLabel->clear(); m_ui->m_confirmLineEdit->clear();
m_ui->m_iconLabel->clear();
updateState(); updateState();
} }

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> === /* === This file is part of Calamares - <https://github.com/calamares> ===
* *
* Copyright 2016, Teo Mrnjavac <teo@kde.org> * Copyright 2016, Teo Mrnjavac <teo@kde.org>
* Copyright 2020, Adriaan de Groot <groot@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -20,41 +21,46 @@
#ifndef ENCRYPTWIDGET_H #ifndef ENCRYPTWIDGET_H
#define ENCRYPTWIDGET_H #define ENCRYPTWIDGET_H
#include "ui_EncryptWidget.h" #include <QWidget>
class EncryptWidget : public QWidget, private Ui::EncryptWidget namespace Ui
{
class EncryptWidget;
}
class EncryptWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
enum State : unsigned short enum class Encryption : unsigned short
{ {
EncryptionDisabled = 0, Disabled = 0,
EncryptionUnconfirmed, Unconfirmed,
EncryptionConfirmed Confirmed
}; };
explicit EncryptWidget( QWidget* parent = nullptr ); explicit EncryptWidget( QWidget* parent = nullptr );
void reset(); void reset();
State state() const; Encryption state() const;
void setText( const QString& text ); void setText( const QString& text );
QString passphrase() const; QString passphrase() const;
signals: void retranslate();
void stateChanged( State );
protected: signals:
void changeEvent( QEvent* e ); void stateChanged( Encryption );
private: private:
void updateState(); void updateState();
void onPassphraseEdited(); 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

View File

@ -18,16 +18,14 @@
*/ */
#include "gui/PartitionBarsView.h" #include "gui/PartitionBarsView.h"
#include <core/PartitionModel.h> #include "core/PartitionModel.h"
#include <core/ColorUtils.h> #include "core/ColorUtils.h"
#include "utils/CalamaresUtilsGui.h"
#include "utils/Logger.h"
#include <kpmcore/core/device.h> #include <kpmcore/core/device.h>
#include <utils/CalamaresUtilsGui.h>
#include <utils/Logger.h>
// Qt
#include <QDebug> #include <QDebug>
#include <QGuiApplication> #include <QGuiApplication>
#include <QMouseEvent> #include <QMouseEvent>

View File

@ -21,10 +21,10 @@
#ifndef PARTITIONVIEWSTEP_H #ifndef PARTITIONVIEWSTEP_H
#define PARTITIONVIEWSTEP_H #define PARTITIONVIEWSTEP_H
#include <utils/PluginFactory.h> #include "utils/PluginFactory.h"
#include <viewpages/ViewStep.h> #include "viewpages/ViewStep.h"
#include <DllMacro.h> #include "DllMacro.h"
#include "core/PartitionActions.h" #include "core/PartitionActions.h"

View File

@ -18,23 +18,21 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <PartitionJobTests.h> #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/KPMManager.h"
#include "partition/PartitionQuery.h" #include "partition/PartitionQuery.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Units.h" #include "utils/Units.h"
#include <core/KPMHelpers.h>
#include <jobs/CreatePartitionJob.h>
#include <jobs/CreatePartitionTableJob.h>
#include <jobs/ResizePartitionJob.h>
// CalaPM
#include <backend/corebackend.h> #include <backend/corebackend.h>
#include <fs/filesystemfactory.h> #include <fs/filesystemfactory.h>
// Qt
#include <QEventLoop> #include <QEventLoop>
#include <QProcess> #include <QProcess>
#include <QtTest/QtTest> #include <QtTest/QtTest>

View File

@ -19,7 +19,7 @@
#ifndef PARTITIONJOBTESTS_H #ifndef PARTITIONJOBTESTS_H
#define PARTITIONJOBTESTS_H #define PARTITIONJOBTESTS_H
#include <JobQueue.h> #include "JobQueue.h"
// CalaPM // CalaPM
#include <core/device.h> #include <core/device.h>

View File

@ -22,7 +22,7 @@
#include <QObject> #include <QObject>
#include <QVariantMap> #include <QVariantMap>
#include <Job.h> #include "Job.h"
class PlasmaLnfJob : public Calamares::Job class PlasmaLnfJob : public Calamares::Job
{ {

View File

@ -19,9 +19,9 @@
#ifndef PLASMALNFVIEWSTEP_H #ifndef PLASMALNFVIEWSTEP_H
#define PLASMALNFVIEWSTEP_H #define PLASMALNFVIEWSTEP_H
#include <utils/PluginFactory.h> #include "utils/PluginFactory.h"
#include <viewpages/ViewStep.h> #include "viewpages/ViewStep.h"
#include <DllMacro.h> #include "DllMacro.h"
#include <QObject> #include <QObject>
#include <QUrl> #include <QUrl>

View File

@ -21,10 +21,10 @@
#include <QObject> #include <QObject>
#include <utils/PluginFactory.h> #include "utils/PluginFactory.h"
#include <viewpages/ViewStep.h> #include "viewpages/ViewStep.h"
#include <DllMacro.h> #include "DllMacro.h"
class SummaryPage; class SummaryPage;

View File

@ -21,9 +21,9 @@
#include "TrackingType.h" #include "TrackingType.h"
#include <DllMacro.h> #include "DllMacro.h"
#include <utils/PluginFactory.h> #include "utils/PluginFactory.h"
#include <viewpages/ViewStep.h> #include "viewpages/ViewStep.h"
#include <QObject> #include <QObject>
#include <QUrl> #include <QUrl>

View File

@ -17,7 +17,7 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <CreateUserJob.h> #include "CreateUserJob.h"
#include "GlobalStorage.h" #include "GlobalStorage.h"
#include "JobQueue.h" #include "JobQueue.h"

View File

@ -19,7 +19,7 @@
#ifndef CREATEUSERJOB_H #ifndef CREATEUSERJOB_H
#define CREATEUSERJOB_H #define CREATEUSERJOB_H
#include <Job.h> #include "Job.h"
#include <QStringList> #include <QStringList>

View File

@ -21,7 +21,7 @@
#ifndef SETHOSTNAMEJOB_CPP_H #ifndef SETHOSTNAMEJOB_CPP_H
#define SETHOSTNAMEJOB_CPP_H #define SETHOSTNAMEJOB_CPP_H
#include <Job.h> #include "Job.h"
class SetHostNameJob : public Calamares::Job class SetHostNameJob : public Calamares::Job
{ {

View File

@ -17,7 +17,7 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <SetPasswordJob.h> #include "SetPasswordJob.h"
#include "GlobalStorage.h" #include "GlobalStorage.h"
#include "JobQueue.h" #include "JobQueue.h"

View File

@ -20,7 +20,7 @@
#ifndef SETPASSWORDJOB_H #ifndef SETPASSWORDJOB_H
#define SETPASSWORDJOB_H #define SETPASSWORDJOB_H
#include <Job.h> #include "Job.h"
class SetPasswordJob : public Calamares::Job class SetPasswordJob : public Calamares::Job

View File

@ -23,10 +23,10 @@
#include "WebViewConfig.h" #include "WebViewConfig.h"
#include <utils/PluginFactory.h> #include "utils/PluginFactory.h"
#include <viewpages/ViewStep.h> #include "viewpages/ViewStep.h"
#include <DllMacro.h> #include "DllMacro.h"
#include <QVariantMap> #include <QVariantMap>

View File

@ -19,14 +19,11 @@
#ifndef WELCOMEPAGEPLUGIN_H #ifndef WELCOMEPAGEPLUGIN_H
#define WELCOMEPAGEPLUGIN_H #define WELCOMEPAGEPLUGIN_H
#include "DllMacro.h"
#include "utils/PluginFactory.h"
#include "viewpages/ViewStep.h"
#include <QObject> #include <QObject>
#include <modulesystem/Requirement.h>
#include <utils/PluginFactory.h>
#include <viewpages/ViewStep.h>
#include <DllMacro.h>
#include <QVariantMap> #include <QVariantMap>
class WelcomePage; class WelcomePage;