[dummycpp] Reduce warnings and apply coding style
- tired of the (IMO, bogus) clang warnings from the switch() statement with a default:, so swap it out for some cascaded ifs.
This commit is contained in:
parent
e81bd52fb5
commit
76041a2184
@ -20,13 +20,13 @@
|
|||||||
|
|
||||||
#include "DummyCppJob.h"
|
#include "DummyCppJob.h"
|
||||||
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QProcess>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
#include "CalamaresVersion.h"
|
#include "CalamaresVersion.h"
|
||||||
#include "JobQueue.h"
|
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
|
#include "JobQueue.h"
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
@ -36,9 +36,7 @@ DummyCppJob::DummyCppJob( QObject* parent )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DummyCppJob::~DummyCppJob()
|
DummyCppJob::~DummyCppJob() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
@ -56,19 +54,20 @@ static QString variantHashToString( const QVariantHash& variantHash );
|
|||||||
static QString
|
static QString
|
||||||
variantToString( const QVariant& variant )
|
variantToString( const QVariant& variant )
|
||||||
{
|
{
|
||||||
switch ( variant.type() )
|
if ( variant.type() == QVariant::Map )
|
||||||
{
|
{
|
||||||
case QVariant::Map:
|
|
||||||
return variantMapToString( variant.toMap() );
|
return variantMapToString( variant.toMap() );
|
||||||
|
}
|
||||||
case QVariant::Hash:
|
else if ( variant.type() == QVariant::Hash )
|
||||||
|
{
|
||||||
return variantHashToString( variant.toHash() );
|
return variantHashToString( variant.toHash() );
|
||||||
|
}
|
||||||
case QVariant::List:
|
else if ( ( variant.type() == QVariant::List ) || ( variant.type() == QVariant::StringList ) )
|
||||||
case QVariant::StringList:
|
{
|
||||||
return variantListToString( variant.toList() );
|
return variantListToString( variant.toList() );
|
||||||
|
}
|
||||||
default:
|
else
|
||||||
|
{
|
||||||
return variant.toString();
|
return variant.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,8 +78,10 @@ variantListToString( const QVariantList& variantList )
|
|||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
for ( const QVariant& variant : variantList )
|
for ( const QVariant& variant : variantList )
|
||||||
|
{
|
||||||
result.append( variantToString( variant ) );
|
result.append( variantToString( variant ) );
|
||||||
return '{' + result.join(',') + '}';
|
}
|
||||||
|
return '{' + result.join( ',' ) + '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -89,8 +90,10 @@ variantMapToString( const QVariantMap& variantMap )
|
|||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
for ( auto it = variantMap.constBegin(); it != variantMap.constEnd(); ++it )
|
for ( auto it = variantMap.constBegin(); it != variantMap.constEnd(); ++it )
|
||||||
|
{
|
||||||
result.append( it.key() + '=' + variantToString( it.value() ) );
|
result.append( it.key() + '=' + variantToString( it.value() ) );
|
||||||
return '[' + result.join(',') + ']';
|
}
|
||||||
|
return '[' + result.join( ',' ) + ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -99,8 +102,10 @@ variantHashToString( const QVariantHash& variantHash )
|
|||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
for ( auto it = variantHash.constBegin(); it != variantHash.constEnd(); ++it )
|
for ( auto it = variantHash.constBegin(); it != variantHash.constEnd(); ++it )
|
||||||
|
{
|
||||||
result.append( it.key() + '=' + variantToString( it.value() ) );
|
result.append( it.key() + '=' + variantToString( it.value() ) );
|
||||||
return '<' + result.join(',') + '>';
|
}
|
||||||
|
return '<' + result.join( ',' ) + '>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -108,22 +113,26 @@ Calamares::JobResult
|
|||||||
DummyCppJob::exec()
|
DummyCppJob::exec()
|
||||||
{
|
{
|
||||||
// Ported from dummypython
|
// Ported from dummypython
|
||||||
QProcess::execute( "/bin/sh", QStringList() << "-c" << "touch ~/calamares-dummycpp" );
|
QProcess::execute( "/bin/sh",
|
||||||
|
QStringList() << "-c"
|
||||||
|
<< "touch ~/calamares-dummycpp" );
|
||||||
QString accumulator = QDateTime::currentDateTimeUtc().toString( Qt::ISODate ) + '\n';
|
QString accumulator = QDateTime::currentDateTimeUtc().toString( Qt::ISODate ) + '\n';
|
||||||
accumulator += QStringLiteral( "Calamares version: " ) + CALAMARES_VERSION_SHORT + '\n';
|
accumulator += QStringLiteral( "Calamares version: " ) + CALAMARES_VERSION_SHORT + '\n';
|
||||||
accumulator += QStringLiteral( "This job's name: " ) + prettyName() + '\n';
|
accumulator += QStringLiteral( "This job's name: " ) + prettyName() + '\n';
|
||||||
accumulator += QStringLiteral( "Configuration map: %1\n" ).arg( variantMapToString( m_configurationMap ) );
|
accumulator += QStringLiteral( "Configuration map: %1\n" ).arg( variantMapToString( m_configurationMap ) );
|
||||||
accumulator += QStringLiteral( " *** globalstorage test ***\n" );
|
accumulator += QStringLiteral( " *** globalstorage test ***\n" );
|
||||||
Calamares::GlobalStorage *globalStorage = Calamares::JobQueue::instance()->globalStorage();
|
Calamares::GlobalStorage* globalStorage = Calamares::JobQueue::instance()->globalStorage();
|
||||||
accumulator += QStringLiteral( "lala: " ) + (globalStorage->contains( "lala" ) ? QStringLiteral( "true" ) : QStringLiteral( "false" )) + '\n';
|
accumulator += QStringLiteral( "lala: " )
|
||||||
accumulator += QStringLiteral( "foo: " ) + (globalStorage->contains( "foo" ) ? QStringLiteral( "true" ) : QStringLiteral( "false" )) + '\n';
|
+ ( globalStorage->contains( "lala" ) ? QStringLiteral( "true" ) : QStringLiteral( "false" ) ) + '\n';
|
||||||
|
accumulator += QStringLiteral( "foo: " )
|
||||||
|
+ ( globalStorage->contains( "foo" ) ? QStringLiteral( "true" ) : QStringLiteral( "false" ) ) + '\n';
|
||||||
accumulator += QStringLiteral( "count: " ) + QString::number( globalStorage->count() ) + '\n';
|
accumulator += QStringLiteral( "count: " ) + QString::number( globalStorage->count() ) + '\n';
|
||||||
globalStorage->insert( "item2", "value2" );
|
globalStorage->insert( "item2", "value2" );
|
||||||
globalStorage->insert( "item3", 3 );
|
globalStorage->insert( "item3", 3 );
|
||||||
accumulator += QStringLiteral( "keys: %1\n" ).arg( globalStorage->keys().join( ',' ) );
|
accumulator += QStringLiteral( "keys: %1\n" ).arg( globalStorage->keys().join( ',' ) );
|
||||||
accumulator += QStringLiteral( "remove: %1\n" ).arg( QString::number( globalStorage->remove( "item2" ) ) );
|
accumulator += QStringLiteral( "remove: %1\n" ).arg( QString::number( globalStorage->remove( "item2" ) ) );
|
||||||
accumulator += QStringLiteral( "values: %1 %2 %3\n" ).arg(
|
accumulator += QStringLiteral( "values: %1 %2 %3\n" )
|
||||||
globalStorage->value( "foo" ).toString(),
|
.arg( globalStorage->value( "foo" ).toString(),
|
||||||
globalStorage->value( "item2" ).toString(),
|
globalStorage->value( "item2" ).toString(),
|
||||||
globalStorage->value( "item3" ).toString() );
|
globalStorage->value( "item3" ).toString() );
|
||||||
|
|
||||||
@ -145,4 +154,4 @@ DummyCppJob::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
m_configurationMap = configurationMap;
|
m_configurationMap = configurationMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
CALAMARES_PLUGIN_FACTORY_DEFINITION( DummyCppJobFactory, registerPlugin<DummyCppJob>(); )
|
CALAMARES_PLUGIN_FACTORY_DEFINITION( DummyCppJobFactory, registerPlugin< DummyCppJob >(); )
|
||||||
|
Loading…
Reference in New Issue
Block a user