[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
{
BlankViewStep::BlankViewStep( const QString& title, const QString& description, const QString& details, QObject* parent)
BlankViewStep::BlankViewStep( const QString& title,
const QString& description,
const QString& details,
QObject* parent )
: Calamares::ViewStep( parent )
, m_widget( new QWidget() )
{
@ -54,14 +57,12 @@ BlankViewStep::BlankViewStep( const QString& title, const QString& description,
layout->addWidget( label );
}
layout->addStretch( 1 ); // Push the rest to the top
layout->addStretch( 1 ); // Push the rest to the top
m_widget->setLayout( layout );
}
BlankViewStep::~BlankViewStep()
{
}
BlankViewStep::~BlankViewStep() {}
QString
BlankViewStep::prettyName() const
@ -115,4 +116,4 @@ BlankViewStep::jobs() const
return JobList();
}
} // namespace
} // namespace Calamares

View File

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

View File

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

View File

@ -54,4 +54,4 @@ private:
Calamares::GlobalStorage* m_gs;
};
#endif // PYTHONQTGLOBALSTORAGEWRAPPER_H
#endif // PYTHONQTGLOBALSTORAGEWRAPPER_H

View File

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

View File

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

View File

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

View File

@ -43,29 +43,17 @@ public slots:
const QString& filesystem_name,
const QString& options ) const;
int target_env_call( const QString& command,
const QString& stdin = QString(),
int timeout = 0 ) const;
int target_env_call( const QString& command, const QString& stdin = QString(), int timeout = 0 ) const;
int target_env_call( const QStringList& args,
const QString& stdin = QString(),
int timeout = 0 ) const;
int target_env_call( const QStringList& args, const QString& stdin = QString(), int timeout = 0 ) const;
int check_target_env_call( const QString& command,
const QString& stdin = QString(),
int timeout = 0 ) const;
int check_target_env_call( const QString& command, const QString& stdin = QString(), int timeout = 0 ) const;
int check_target_env_call( const QStringList& args,
const QString& stdin = QString(),
int timeout = 0 ) const;
int check_target_env_call( const QStringList& args, const QString& stdin = QString(), int timeout = 0 ) const;
QString check_target_env_output( const QString& command,
const QString& stdin = QString(),
int timeout = 0 ) const;
QString check_target_env_output( const QString& command, const QString& stdin = QString(), int timeout = 0 ) const;
QString check_target_env_output( const QStringList& args,
const QString& stdin = QString(),
int timeout = 0 ) const;
QString check_target_env_output( const QStringList& args, const QString& stdin = QString(), int timeout = 0 ) const;
QString obscure( const QString& string ) const;
@ -75,4 +63,4 @@ private:
PythonQtObjectPtr m_exceptionCxt;
};
#endif // PYTHONQTUTILSWRAPPER_H
#endif // PYTHONQTUTILSWRAPPER_H

View File

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

View File

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

View File

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

View File

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