@ -30,31 +30,71 @@
# include "utils/CommandList.h"
# include "utils/Logger.h"
/**
* Passing a CommandList to ValueCheck gives ownership of the CommandList to
* the ValueCheck , which will delete the CommandList when needed .
*/
struct ValueCheck : public QPair < QString , CalamaresUtils : : CommandList * >
{
ValueCheck ( const QString & value , CalamaresUtils : : CommandList * commands )
: QPair < QString , CalamaresUtils : : CommandList * > ( value , commands )
{
}
~ ValueCheck ( )
{
delete second ;
}
QString value ( ) const { return first ; }
CalamaresUtils : : CommandList * commands ( ) const { return second ; }
} ;
struct ContextualProcessBinding
{
ContextualProcessBinding ( const QString & _n , const QString & _v , CalamaresUtils : : CommandList * _c )
: variable ( _n )
, value ( _v )
, commands ( _c )
ContextualProcessBinding ( const QString & varname )
: variable ( varname )
{
}
~ ContextualProcessBinding ( ) ;
int count ( ) const
/**
* @ brief add commands to be executed when @ p value is matched .
*
* Ownership of the CommandList passes to the ValueCheck held
* by this binding .
*/
void append ( const QString & value , CalamaresUtils : : CommandList * commands )
{
return commands ? commands - > count ( ) : 0 ;
checks . append ( ValueCheck ( value , commands ) ) ;
if ( value = = ' * ' )
wildcard = commands ;
}
Calamares : : JobResult run ( const QString & value ) const
{
for ( const auto & c : checks )
{
if ( value = = c . value ( ) )
return c . commands ( ) - > run ( ) ;
}
if ( wildcard )
return wildcard - > run ( ) ;
return Calamares : : JobResult : : ok ( ) ;
}
QString variable ;
QString value ;
CalamaresUtils : : CommandList * commands ;
Q List< ValueCheck > checks ;
CalamaresUtils : : CommandList * wildcard{ nullptr } ;
} ;
ContextualProcessBinding : : ~ ContextualProcessBinding ( )
{
delete commands ;
wildcard = nullptr ;
}
ContextualProcessJob : : ContextualProcessJob ( QObject * parent )
@ -83,9 +123,9 @@ ContextualProcessJob::exec()
for ( const ContextualProcessBinding * binding : m_commands )
{
if ( gs - > contains ( binding - > variable ) & & ( gs - > value ( binding - > variable ) . toString ( ) = = binding - > value ) )
if ( gs - > contains ( binding - > variable ) )
{
Calamares : : JobResult r = binding - > commands- > run ( ) ;
Calamares : : JobResult r = binding - > run( gs - > value ( binding - > variable ) . toString ( ) ) ;
if ( ! r )
return r ;
}
@ -114,6 +154,8 @@ ContextualProcessJob::setConfigurationMap( const QVariantMap& configurationMap )
continue ;
}
auto binding = new ContextualProcessBinding ( variableName ) ;
m_commands . append ( binding ) ;
QVariantMap values = iter . value ( ) . toMap ( ) ;
for ( QVariantMap : : const_iterator valueiter = values . cbegin ( ) ; valueiter ! = values . cend ( ) ; + + valueiter )
{
@ -126,13 +168,7 @@ ContextualProcessJob::setConfigurationMap( const QVariantMap& configurationMap )
CalamaresUtils : : CommandList * commands = new CalamaresUtils : : CommandList ( valueiter . value ( ) , ! dontChroot , timeout ) ;
if ( commands - > count ( ) > 0 )
{
m_commands . append ( new ContextualProcessBinding ( variableName , valueString , commands ) ) ;
cDebug ( ) < < variableName < < ' = ' < < valueString < < " will execute " < < commands - > count ( ) < < " commands " ;
}
else
delete commands ;
binding - > append ( valueString , commands ) ;
}
}
}