[libcalamaresui] activate -> change state

- since we also need to *disable* the shortcuts, and should tell a
   V1 slideshow that it no longer is running,
 - use existing function to set the property to true / false depending.
 - instead of changeState( true ) or changeStage( false ), use
   meaningful enum names so that the code at the call site
   becomes readable; make the boolean part internal to the
   state-changing method.
This commit is contained in:
Adriaan de Groot 2019-08-27 15:30:45 +02:00
parent 1e3e53d30a
commit be5388abcd

View File

@ -179,28 +179,53 @@ ExecutionViewStep::loadQmlV2()
} }
} }
static void /// @brief State-change of the slideshow, for changeSlideShowState()
activateSlideShow( QQuickItem* slideshow, QQuickWidget* widget) enum class Slideshow
{ {
Start,
Stop
};
/** @brief Tells the slideshow we activated or left the show.
*
* If @p state is @c Slideshow::Start, calls suitable activation procedures.
* If @p state is @c Slideshow::Stop, calls deactivation procedures.
*
* Applies V1 and V2 QML activation / deactivation:
* - V1 loads the QML in @p widget on activation. Sets root object property
* *activatedInCalamares* as appropriate.
* - V2 calls onActivate() or onLeave() in the QML as appropriate. Also
* sets the *activatedInCalamares* property.
*/
static void
changeSlideShowState( Slideshow state, QQuickItem* slideshow, QQuickWidget* widget )
{
bool activate = state == Slideshow::Start;
if ( Branding::instance()->slideshowAPI() == 2 ) if ( Branding::instance()->slideshowAPI() == 2 )
{ {
// The QML was already loaded in the constructor, need to start it // The QML was already loaded in the constructor, need to start it
callQMLFunction( slideshow, "onActivate" ); callQMLFunction( slideshow, activate ? "onActivate" : "onLeave" );
} }
else if ( !Calamares::Branding::instance()->slideshowPath().isEmpty() ) else if ( !Calamares::Branding::instance()->slideshowPath().isEmpty() )
{ {
// API version 1 assumes onCompleted is the trigger // API version 1 assumes onCompleted is the trigger
if ( activate )
{
widget->setSource( QUrl::fromLocalFile( Calamares::Branding::instance()->slideshowPath() ) ); widget->setSource( QUrl::fromLocalFile( Calamares::Branding::instance()->slideshowPath() ) );
}
// needs the root object for property setting, below
slideshow = widget->rootObject(); slideshow = widget->rootObject();
} }
// V1 API has picked up the root object for use, V2 passed it in.
if ( slideshow ) if ( slideshow )
{ {
static const char propertyName[] = "activatedInCalamares"; static const char propertyName[] = "activatedInCalamares";
auto active = slideshow->property( propertyName ); auto property = slideshow->property( propertyName );
if ( active.isValid() && ( active.type() == QVariant::Bool ) && !active.toBool() ) if ( property.isValid() && ( property.type() == QVariant::Bool ) && ( property.toBool() != activate ) )
{ {
slideshow->setProperty( propertyName, true ); slideshow->setProperty( propertyName, activate );
} }
} }
} }
@ -234,7 +259,7 @@ ExecutionViewStep::loadQmlV2Complete()
{ {
// We're alreay visible! Must have been slow QML loading, and we // We're alreay visible! Must have been slow QML loading, and we
// passed onActivate already. // passed onActivate already.
activateSlideShow( m_qmlObject, m_qmlShow ); changeSlideShowState( Slideshow::Start, m_qmlObject, m_qmlShow );
} }
} }
} }
@ -243,7 +268,7 @@ ExecutionViewStep::loadQmlV2Complete()
void void
ExecutionViewStep::onActivate() ExecutionViewStep::onActivate()
{ {
activateSlideShow( m_qmlObject, m_qmlShow ); changeSlideShowState( Slideshow::Start, m_qmlObject, m_qmlShow );
JobQueue* queue = JobQueue::instance(); JobQueue* queue = JobQueue::instance();
foreach ( const QString& instanceKey, m_jobInstanceKeys ) foreach ( const QString& instanceKey, m_jobInstanceKeys )
@ -291,10 +316,10 @@ ExecutionViewStep::updateFromJobQueue( qreal percent, const QString& message )
void void
ExecutionViewStep::onLeave() ExecutionViewStep::onLeave()
{ {
changeSlideShowState( Slideshow::Stop, m_qmlObject, m_qmlShow );
// API version 2 is explicitly stopped; version 1 keeps running // API version 2 is explicitly stopped; version 1 keeps running
if ( Branding::instance()->slideshowAPI() == 2 ) if ( Branding::instance()->slideshowAPI() == 2 )
{ {
callQMLFunction( m_qmlObject, "onLeave" );
delete m_qmlObject; delete m_qmlObject;
m_qmlObject = nullptr; m_qmlObject = nullptr;
} }