[libcalamaresui] Apply coding style to viewpages/

This commit is contained in:
Adriaan de Groot 2019-08-13 21:02:30 +02:00
parent 6f74463a80
commit d44e8f6115
12 changed files with 110 additions and 167 deletions

View File

@ -26,7 +26,10 @@
namespace Calamares namespace Calamares
{ {
BlankViewStep::BlankViewStep( const QString& title, const QString& description, const QString& details, QObject* parent) BlankViewStep::BlankViewStep( const QString& title,
const QString& description,
const QString& details,
QObject* parent )
: Calamares::ViewStep( parent ) : Calamares::ViewStep( parent )
, m_widget( new QWidget() ) , m_widget( new QWidget() )
{ {
@ -59,9 +62,7 @@ BlankViewStep::BlankViewStep( const QString& title, const QString& description,
m_widget->setLayout( layout ); m_widget->setLayout( layout );
} }
BlankViewStep::~BlankViewStep() BlankViewStep::~BlankViewStep() {}
{
}
QString QString
BlankViewStep::prettyName() const BlankViewStep::prettyName() const
@ -115,4 +116,4 @@ BlankViewStep::jobs() const
return JobList(); return JobList();
} }
} // namespace } // namespace Calamares

View File

@ -39,7 +39,10 @@ class BlankViewStep : public Calamares::ViewStep
Q_OBJECT Q_OBJECT
public: public:
explicit BlankViewStep( const QString& title, const QString& description, const QString& details = QString(), QObject* parent = nullptr ); explicit BlankViewStep( const QString& title,
const QString& description,
const QString& details = QString(),
QObject* parent = nullptr );
virtual ~BlankViewStep() override; virtual ~BlankViewStep() override;
QString prettyName() const override; QString prettyName() const override;
@ -61,5 +64,5 @@ private:
QWidget* m_widget; QWidget* m_widget;
}; };
} // namespace } // namespace Calamares
#endif // BLANKVIEWSTEP_H #endif // BLANKVIEWSTEP_H

View File

@ -24,7 +24,8 @@
GlobalStorage::GlobalStorage( Calamares::GlobalStorage* gs ) GlobalStorage::GlobalStorage( Calamares::GlobalStorage* gs )
: QObject( gs ) : QObject( gs )
, m_gs( gs ) , m_gs( gs )
{} {
}
bool bool

View File

@ -20,34 +20,26 @@
#include "utils/PythonQtUtils.h" #include "utils/PythonQtUtils.h"
PythonQtJob::PythonQtJob( PythonQtObjectPtr cxt, PythonQtJob::PythonQtJob( PythonQtObjectPtr cxt, PythonQtObjectPtr pyJob, QObject* parent )
PythonQtObjectPtr pyJob,
QObject* parent )
: Calamares::Job( parent ) : Calamares::Job( parent )
, m_cxt( cxt ) , m_cxt( cxt )
, m_pyJob( pyJob ) , m_pyJob( pyJob )
{ {
} }
QString QString
PythonQtJob::prettyName() const PythonQtJob::prettyName() const
{ {
return CalamaresUtils::lookupAndCall( m_pyJob, return CalamaresUtils::lookupAndCall( m_pyJob, { "prettyName", "prettyname", "pretty_name" } ).toString();
{ "prettyName",
"prettyname",
"pretty_name" } ).toString();
} }
QString QString
PythonQtJob::prettyDescription() const PythonQtJob::prettyDescription() const
{ {
return CalamaresUtils::lookupAndCall( m_pyJob, return CalamaresUtils::lookupAndCall( m_pyJob, { "prettyDescription", "prettydescription", "pretty_description" } )
{ "prettyDescription", .toString();
"prettydescription",
"pretty_description" } ).toString();
} }
@ -55,9 +47,8 @@ QString
PythonQtJob::prettyStatusMessage() const PythonQtJob::prettyStatusMessage() const
{ {
return CalamaresUtils::lookupAndCall( m_pyJob, return CalamaresUtils::lookupAndCall( m_pyJob,
{ "prettyStatusMessage", { "prettyStatusMessage", "prettystatusmessage", "pretty_status_message" } )
"prettystatusmessage", .toString();
"pretty_status_message" } ).toString();
} }
@ -66,12 +57,15 @@ PythonQtJob::exec()
{ {
QVariant response = m_pyJob.call( "exec" ); QVariant response = m_pyJob.call( "exec" );
if ( response.isNull() ) if ( response.isNull() )
{
return Calamares::JobResult::ok(); return Calamares::JobResult::ok();
}
QVariantMap map = response.toMap(); QVariantMap map = response.toMap();
if ( map.isEmpty() || map.value( "ok" ).toBool() ) if ( map.isEmpty() || map.value( "ok" ).toBool() )
{
return Calamares::JobResult::ok(); return Calamares::JobResult::ok();
}
return Calamares::JobResult::error( map.value( "message" ).toString(), return Calamares::JobResult::error( map.value( "message" ).toString(), map.value( "details" ).toString() );
map.value( "details" ).toString() );
} }

View File

@ -32,12 +32,11 @@ class PythonQtJobResult : public QObject, public Calamares::JobResult
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit PythonQtJobResult( bool ok, explicit PythonQtJobResult( bool ok, const QString& message, const QString& details )
const QString& message,
const QString& details )
: QObject( nullptr ) : QObject( nullptr )
, Calamares::JobResult( message, details, ok ? 0 : Calamares::JobResult::GenericError ) , Calamares::JobResult( message, details, ok ? 0 : Calamares::JobResult::GenericError )
{} {
}
}; };
@ -53,9 +52,7 @@ public:
Calamares::JobResult exec() override; Calamares::JobResult exec() override;
private: private:
explicit PythonQtJob( PythonQtObjectPtr cxt, explicit PythonQtJob( PythonQtObjectPtr cxt, PythonQtObjectPtr pyJob, QObject* parent = nullptr );
PythonQtObjectPtr pyJob,
QObject* parent = nullptr );
friend class Calamares::PythonQtViewStep; // only this one can call the ctor friend class Calamares::PythonQtViewStep; // only this one can call the ctor
PythonQtObjectPtr m_cxt; PythonQtObjectPtr m_cxt;

View File

@ -25,7 +25,7 @@
#include <PythonQt.h> #include <PythonQt.h>
Utils::Utils(QObject* parent) Utils::Utils( QObject* parent )
: QObject( parent ) : QObject( parent )
, m_exceptionCxt( PythonQt::self()->createUniqueModule() ) , m_exceptionCxt( PythonQt::self()->createUniqueModule() )
{ {
@ -34,7 +34,7 @@ Utils::Utils(QObject* parent)
void void
Utils::debug(const QString& s) const Utils::debug( const QString& s ) const
{ {
cDebug() << "PythonQt DBG>" << s; cDebug() << "PythonQt DBG>" << s;
} }
@ -46,35 +46,28 @@ Utils::mount( const QString& device_path,
const QString& filesystem_name, const QString& filesystem_name,
const QString& options ) const const QString& options ) const
{ {
return CalamaresUtils::System::instance()-> return CalamaresUtils::System::instance()->mount( device_path, mount_point, filesystem_name, options );
mount( device_path, mount_point, filesystem_name, options );
} }
int int
Utils::target_env_call( const QString& command, Utils::target_env_call( const QString& command, const QString& stdin, int timeout ) const
const QString& stdin,
int timeout ) const
{ {
return CalamaresUtils::System::instance()-> return CalamaresUtils::System::instance()->targetEnvCall(
targetEnvCall( command, QString(), stdin, std::chrono::seconds( timeout > 0 ? timeout : 0 ) ); command, QString(), stdin, std::chrono::seconds( timeout > 0 ? timeout : 0 ) );
} }
int int
Utils::target_env_call( const QStringList& args, Utils::target_env_call( const QStringList& args, const QString& stdin, int timeout ) const
const QString& stdin,
int timeout ) const
{ {
return CalamaresUtils::System::instance()-> return CalamaresUtils::System::instance()->targetEnvCall(
targetEnvCall( args, QString(), stdin, std::chrono::seconds( timeout > 0 ? timeout : 0 ) ); args, QString(), stdin, std::chrono::seconds( timeout > 0 ? timeout : 0 ) );
} }
int int
Utils::check_target_env_call( const QString& command, Utils::check_target_env_call( const QString& command, const QString& stdin, int timeout ) const
const QString& stdin,
int timeout ) const
{ {
int ec = target_env_call( command, stdin, timeout ); int ec = target_env_call( command, stdin, timeout );
return _handle_check_target_env_call_error( ec, command ); return _handle_check_target_env_call_error( ec, command );
@ -82,9 +75,7 @@ Utils::check_target_env_call( const QString& command,
int int
Utils::check_target_env_call( const QStringList& args, Utils::check_target_env_call( const QStringList& args, const QString& stdin, int timeout ) const
const QString& stdin,
int timeout) const
{ {
int ec = target_env_call( args, stdin, timeout ); int ec = target_env_call( args, stdin, timeout );
return _handle_check_target_env_call_error( ec, args.join( ' ' ) ); return _handle_check_target_env_call_error( ec, args.join( ' ' ) );
@ -92,34 +83,22 @@ Utils::check_target_env_call( const QStringList& args,
QString QString
Utils::check_target_env_output( const QString& command, Utils::check_target_env_output( const QString& command, const QString& stdin, int timeout ) const
const QString& stdin,
int timeout ) const
{ {
QString output; QString output;
int ec = CalamaresUtils::System::instance()-> int ec = CalamaresUtils::System::instance()->targetEnvOutput(
targetEnvOutput( command, command, output, QString(), stdin, std::chrono::seconds( timeout > 0 ? timeout : 0 ) );
output,
QString(),
stdin,
std::chrono::seconds( timeout > 0 ? timeout : 0 ) );
_handle_check_target_env_call_error( ec, command ); _handle_check_target_env_call_error( ec, command );
return output; return output;
} }
QString QString
Utils::check_target_env_output( const QStringList& args, Utils::check_target_env_output( const QStringList& args, const QString& stdin, int timeout ) const
const QString& stdin,
int timeout ) const
{ {
QString output; QString output;
int ec = CalamaresUtils::System::instance()-> int ec = CalamaresUtils::System::instance()->targetEnvOutput(
targetEnvOutput( args, args, output, QString(), stdin, std::chrono::seconds( timeout > 0 ? timeout : 0 ) );
output,
QString(),
stdin,
std::chrono::seconds( timeout > 0 ? timeout : 0 ) );
_handle_check_target_env_call_error( ec, args.join( ' ' ) ); _handle_check_target_env_call_error( ec, args.join( ' ' ) );
return output; return output;
} }
@ -133,13 +112,11 @@ Utils::obscure( const QString& string ) const
int int
Utils::_handle_check_target_env_call_error( int ec, const QString& cmd) const Utils::_handle_check_target_env_call_error( int ec, const QString& cmd ) const
{ {
if ( ec ) if ( ec )
{ {
QString raise = QString( "raise subprocess.CalledProcessError(%1,\"%2\")" ) QString raise = QString( "raise subprocess.CalledProcessError(%1,\"%2\")" ).arg( ec ).arg( cmd );
.arg( ec )
.arg( cmd );
PythonQt::self()->evalScript( m_exceptionCxt, raise ); PythonQt::self()->evalScript( m_exceptionCxt, raise );
} }
return ec; return ec;

View File

@ -43,29 +43,17 @@ public slots:
const QString& filesystem_name, const QString& filesystem_name,
const QString& options ) const; const QString& options ) const;
int target_env_call( const QString& command, int target_env_call( const QString& command, const QString& stdin = QString(), int timeout = 0 ) const;
const QString& stdin = QString(),
int timeout = 0 ) const;
int target_env_call( const QStringList& args, int target_env_call( const QStringList& args, const QString& stdin = QString(), int timeout = 0 ) const;
const QString& stdin = QString(),
int timeout = 0 ) const;
int check_target_env_call( const QString& command, int check_target_env_call( const QString& command, const QString& stdin = QString(), int timeout = 0 ) const;
const QString& stdin = QString(),
int timeout = 0 ) const;
int check_target_env_call( const QStringList& args, int check_target_env_call( const QStringList& args, const QString& stdin = QString(), int timeout = 0 ) const;
const QString& stdin = QString(),
int timeout = 0 ) const;
QString check_target_env_output( const QString& command, QString check_target_env_output( const QString& command, const QString& stdin = QString(), int timeout = 0 ) const;
const QString& stdin = QString(),
int timeout = 0 ) const;
QString check_target_env_output( const QStringList& args, QString check_target_env_output( const QStringList& args, const QString& stdin = QString(), int timeout = 0 ) const;
const QString& stdin = QString(),
int timeout = 0 ) const;
QString obscure( const QString& string ) const; QString obscure( const QString& string ) const;

View File

@ -18,8 +18,8 @@
*/ */
#include "PythonQtViewStep.h" #include "PythonQtViewStep.h"
#include "utils/Logger.h"
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
#include "utils/Logger.h"
#include "utils/PythonQtUtils.h" #include "utils/PythonQtUtils.h"
#include "utils/Retranslator.h" #include "utils/Retranslator.h"
#include "viewpages/PythonQtJob.h" #include "viewpages/PythonQtJob.h"
@ -33,8 +33,7 @@
namespace Calamares namespace Calamares
{ {
PythonQtViewStep::PythonQtViewStep( PythonQtObjectPtr cxt, PythonQtViewStep::PythonQtViewStep( PythonQtObjectPtr cxt, QObject* parent )
QObject* parent )
: ViewStep( parent ) : ViewStep( parent )
, m_widget( new QWidget() ) , m_widget( new QWidget() )
, m_cxt( cxt ) , m_cxt( cxt )
@ -48,8 +47,7 @@ PythonQtViewStep::PythonQtViewStep( PythonQtObjectPtr cxt,
// Instantiate an object of the class marked with @calamares_module and // Instantiate an object of the class marked with @calamares_module and
// store it as _calamares_module. // store it as _calamares_module.
pq->evalScript( m_cxt, QString( "_calamares_module = %1()" ) pq->evalScript( m_cxt, QString( "_calamares_module = %1()" ).arg( className ) );
.arg( className ) );
m_obj = pq->lookupObject( m_cxt, "_calamares_module" ); m_obj = pq->lookupObject( m_cxt, "_calamares_module" );
Q_ASSERT( !m_obj.isNull() ); // no entry point, no party Q_ASSERT( !m_obj.isNull() ); // no entry point, no party
@ -59,21 +57,16 @@ PythonQtViewStep::PythonQtViewStep( PythonQtObjectPtr cxt,
CalamaresUtils::unmarginLayout( m_widget->layout() ); CalamaresUtils::unmarginLayout( m_widget->layout() );
m_cxt.addObject( "_calamares_module_basewidget", m_widget ); m_cxt.addObject( "_calamares_module_basewidget", m_widget );
CALAMARES_RETRANSLATE_WIDGET( m_widget, CALAMARES_RETRANSLATE_WIDGET(
CalamaresUtils::lookupAndCall( m_obj, m_widget,
{ "retranslate" }, CalamaresUtils::lookupAndCall( m_obj, { "retranslate" }, { CalamaresUtils::translatorLocaleName() } ); )
{ CalamaresUtils::translatorLocaleName() } );
)
} }
QString QString
PythonQtViewStep::prettyName() const PythonQtViewStep::prettyName() const
{ {
return CalamaresUtils::lookupAndCall( m_obj, return CalamaresUtils::lookupAndCall( m_obj, { "prettyName", "prettyname", "pretty_name" } ).toString();
{ "prettyName",
"prettyname",
"pretty_name" } ).toString();
} }
@ -84,10 +77,12 @@ PythonQtViewStep::widget()
cWarning() << "PythonQtViewStep wrapper widget has more than 1 child. " cWarning() << "PythonQtViewStep wrapper widget has more than 1 child. "
"This should never happen."; "This should never happen.";
bool nothingChanged = m_cxt.evalScript( bool nothingChanged
"_calamares_module.widget() in _calamares_module_basewidget.children()" ).toBool(); = m_cxt.evalScript( "_calamares_module.widget() in _calamares_module_basewidget.children()" ).toBool();
if ( nothingChanged ) if ( nothingChanged )
{
return m_widget; return m_widget;
}
// Else, we either don't have a child widget, or we have a child widget that // Else, we either don't have a child widget, or we have a child widget that
// was previously set and doesn't apply any more since the Python module // was previously set and doesn't apply any more since the Python module
@ -97,10 +92,11 @@ PythonQtViewStep::widget()
// We only remove from the layout and not delete because Python is in charge // We only remove from the layout and not delete because Python is in charge
// of memory management for these widgets. // of memory management for these widgets.
while ( m_widget->layout()->itemAt( 0 ) ) while ( m_widget->layout()->itemAt( 0 ) )
{
m_widget->layout()->takeAt( 0 ); m_widget->layout()->takeAt( 0 );
}
m_cxt.evalScript( m_cxt.evalScript( "_calamares_module_basewidget.layout().addWidget(_calamares_module.widget())" );
"_calamares_module_basewidget.layout().addWidget(_calamares_module.widget())" );
return m_widget; return m_widget;
} }
@ -123,58 +119,40 @@ PythonQtViewStep::back()
bool bool
PythonQtViewStep::isNextEnabled() const PythonQtViewStep::isNextEnabled() const
{ {
return CalamaresUtils::lookupAndCall( m_obj, return CalamaresUtils::lookupAndCall( m_obj, { "isNextEnabled", "isnextenabled", "is_next_enabled" } ).toBool();
{ "isNextEnabled",
"isnextenabled",
"is_next_enabled" } ).toBool();
} }
bool bool
PythonQtViewStep::isBackEnabled() const PythonQtViewStep::isBackEnabled() const
{ {
return CalamaresUtils::lookupAndCall( m_obj, return CalamaresUtils::lookupAndCall( m_obj, { "isBackEnabled", "isbackenabled", "is_back_enabled" } ).toBool();
{ "isBackEnabled",
"isbackenabled",
"is_back_enabled" } ).toBool();
} }
bool bool
PythonQtViewStep::isAtBeginning() const PythonQtViewStep::isAtBeginning() const
{ {
return CalamaresUtils::lookupAndCall( m_obj, return CalamaresUtils::lookupAndCall( m_obj, { "isAtBeginning", "isatbeginning", "is_at_beginning" } ).toBool();
{ "isAtBeginning",
"isatbeginning",
"is_at_beginning" } ).toBool();
} }
bool bool
PythonQtViewStep::isAtEnd() const PythonQtViewStep::isAtEnd() const
{ {
return CalamaresUtils::lookupAndCall( m_obj, return CalamaresUtils::lookupAndCall( m_obj, { "isAtEnd", "isatend", "is_at_end" } ).toBool();
{ "isAtEnd",
"isatend",
"is_at_end" } ).toBool();
} }
void void
PythonQtViewStep::onActivate() PythonQtViewStep::onActivate()
{ {
CalamaresUtils::lookupAndCall( m_obj, CalamaresUtils::lookupAndCall( m_obj, { "onActivate", "onactivate", "on_activate" } );
{ "onActivate",
"onactivate",
"on_activate" });
} }
void void
PythonQtViewStep::onLeave() PythonQtViewStep::onLeave()
{ {
CalamaresUtils::lookupAndCall( m_obj, CalamaresUtils::lookupAndCall( m_obj, { "onLeave", "onleave", "on_leave" } );
{ "onLeave",
"onleave",
"on_leave" });
} }
@ -185,21 +163,29 @@ PythonQtViewStep::jobs() const
PythonQtObjectPtr jobsCallable = PythonQt::self()->lookupCallable( m_obj, "jobs" ); PythonQtObjectPtr jobsCallable = PythonQt::self()->lookupCallable( m_obj, "jobs" );
if ( jobsCallable.isNull() ) if ( jobsCallable.isNull() )
{
return jobs; return jobs;
}
PythonQtObjectPtr response = PythonQt::self()->callAndReturnPyObject( jobsCallable ); PythonQtObjectPtr response = PythonQt::self()->callAndReturnPyObject( jobsCallable );
if ( response.isNull() ) if ( response.isNull() )
{
return jobs; return jobs;
}
PythonQtObjectPtr listPopCallable = PythonQt::self()->lookupCallable( response, "pop" ); PythonQtObjectPtr listPopCallable = PythonQt::self()->lookupCallable( response, "pop" );
if ( listPopCallable.isNull() ) if ( listPopCallable.isNull() )
{
return jobs; return jobs;
}
forever forever
{ {
PythonQtObjectPtr aJob = PythonQt::self()->callAndReturnPyObject( listPopCallable, { 0 } ); PythonQtObjectPtr aJob = PythonQt::self()->callAndReturnPyObject( listPopCallable, { 0 } );
if ( aJob.isNull() ) if ( aJob.isNull() )
{
break; break;
}
jobs.append( Calamares::job_ptr( new PythonQtJob( m_cxt, aJob ) ) ); jobs.append( Calamares::job_ptr( new PythonQtJob( m_cxt, aJob ) ) );
} }
@ -219,9 +205,8 @@ QWidget*
PythonQtViewStep::createScriptingConsole() PythonQtViewStep::createScriptingConsole()
{ {
PythonQtScriptingConsole* console = new PythonQtScriptingConsole( nullptr, m_cxt ); PythonQtScriptingConsole* console = new PythonQtScriptingConsole( nullptr, m_cxt );
console->setProperty( "classname", console->setProperty( "classname", m_cxt.getVariable( "_calamares_module_typename" ).toString() );
m_cxt.getVariable( "_calamares_module_typename" ).toString() );
return console; return console;
} }
} } // namespace Calamares

View File

@ -30,8 +30,7 @@ class PythonQtViewStep : public Calamares::ViewStep
{ {
Q_OBJECT Q_OBJECT
public: public:
PythonQtViewStep( PythonQtObjectPtr cxt, PythonQtViewStep( PythonQtObjectPtr cxt, QObject* parent = nullptr );
QObject* parent = nullptr );
QString prettyName() const override; QString prettyName() const override;
@ -62,6 +61,6 @@ private:
PythonQtObjectPtr m_obj; PythonQtObjectPtr m_obj;
}; };
} } // namespace Calamares
#endif // PYTHONQTVIEWSTEP_H #endif // PYTHONQTVIEWSTEP_H

View File

@ -24,11 +24,11 @@ namespace Calamares
ViewStep::ViewStep( QObject* parent ) ViewStep::ViewStep( QObject* parent )
: QObject( parent ) : QObject( parent )
{} {
}
ViewStep::~ViewStep() ViewStep::~ViewStep() {}
{}
QString QString
@ -45,20 +45,24 @@ ViewStep::createSummaryWidget() const
void void
ViewStep::onActivate() ViewStep::onActivate()
{} {
}
void void
ViewStep::onLeave() ViewStep::onLeave()
{} {
}
void void
ViewStep::next() ViewStep::next()
{} {
}
void void
ViewStep::back() ViewStep::back()
{} {
}
void void
@ -69,10 +73,7 @@ ViewStep::setModuleInstanceKey( const QString& instanceKey )
void void
ViewStep::setConfigurationMap( const QVariantMap& configurationMap ) ViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { Q_UNUSED( configurationMap ) }
{
Q_UNUSED( configurationMap )
}
RequirementsList ViewStep::checkRequirements() RequirementsList ViewStep::checkRequirements()
@ -80,4 +81,4 @@ RequirementsList ViewStep::checkRequirements()
return RequirementsList(); return RequirementsList();
} }
} } // namespace Calamares

View File

@ -130,10 +130,7 @@ public:
virtual JobList jobs() const = 0; virtual JobList jobs() const = 0;
void setModuleInstanceKey( const QString& instanceKey ); void setModuleInstanceKey( const QString& instanceKey );
QString moduleInstanceKey() const QString moduleInstanceKey() const { return m_instanceKey; }
{
return m_instanceKey;
}
virtual void setConfigurationMap( const QVariantMap& configurationMap ); virtual void setConfigurationMap( const QVariantMap& configurationMap );
@ -161,6 +158,6 @@ protected:
}; };
using ViewStepList = QList< ViewStep* >; using ViewStepList = QList< ViewStep* >;
} } // namespace Calamares
#endif // VIEWSTEP_H #endif // VIEWSTEP_H