2016-10-04 15:29:17 +02:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2016, Teo Mrnjavac <teo@kde.org>
|
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PythonQtViewStep.h"
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
#include "utils/CalamaresUtilsGui.h"
|
2016-10-07 19:12:28 +02:00
|
|
|
#include "utils/PythonQtUtils.h"
|
2016-10-04 15:29:17 +02:00
|
|
|
|
|
|
|
#include <gui/PythonQtScriptingConsole.h>
|
|
|
|
|
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QWidget>
|
|
|
|
|
2016-10-19 17:35:23 +02:00
|
|
|
|
2016-10-07 19:12:28 +02:00
|
|
|
namespace Calamares
|
|
|
|
{
|
2016-10-04 15:29:17 +02:00
|
|
|
|
|
|
|
PythonQtViewStep::PythonQtViewStep( PythonQtObjectPtr cxt,
|
|
|
|
QObject* parent )
|
|
|
|
: ViewStep( parent )
|
|
|
|
, m_widget( new QWidget() )
|
|
|
|
, m_cxt( cxt )
|
|
|
|
{
|
2016-10-19 17:35:23 +02:00
|
|
|
PythonQt* pq = PythonQt::self();
|
|
|
|
Q_ASSERT( pq );
|
|
|
|
|
2016-10-07 19:12:28 +02:00
|
|
|
// The @calamares_module decorator should have filled _calamares_module_typename
|
|
|
|
// for us.
|
2016-10-04 15:29:17 +02:00
|
|
|
QString className = m_cxt.getVariable( "_calamares_module_typename" ).toString();
|
|
|
|
|
2016-10-07 19:12:28 +02:00
|
|
|
// Instantiate an object of the class marked with @calamares_module and
|
|
|
|
// store it as _calamares_module.
|
2016-10-19 17:35:23 +02:00
|
|
|
pq->evalScript( m_cxt, QString( "_calamares_module = %1()" )
|
2016-10-04 15:29:17 +02:00
|
|
|
.arg( className ) );
|
2016-10-19 17:35:23 +02:00
|
|
|
m_obj = pq->lookupObject( m_cxt, "_calamares_module" );
|
2016-10-04 15:29:17 +02:00
|
|
|
|
2016-10-07 19:12:28 +02:00
|
|
|
Q_ASSERT( !m_obj.isNull() ); // no entry point, no party
|
2016-10-04 15:29:17 +02:00
|
|
|
|
2016-10-19 17:35:23 +02:00
|
|
|
// Prepare the base widget for the module's pages
|
2016-10-04 15:29:17 +02:00
|
|
|
m_widget->setLayout( new QVBoxLayout );
|
|
|
|
CalamaresUtils::unmarginLayout( m_widget->layout() );
|
|
|
|
m_cxt.addObject( "_calamares_module_basewidget", m_widget );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
PythonQtViewStep::prettyName() const
|
|
|
|
{
|
2016-10-07 19:12:28 +02:00
|
|
|
return CalamaresUtils::lookupAndCall( m_obj,
|
|
|
|
{ "prettyName",
|
|
|
|
"pretty_name" } ).toString();
|
2016-10-04 15:29:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget*
|
|
|
|
PythonQtViewStep::widget()
|
|
|
|
{
|
2016-10-07 19:12:28 +02:00
|
|
|
if ( m_widget->layout()->count() > 1 )
|
|
|
|
cDebug() << "WARNING: PythonQtViewStep wrapper widget has more than 1 child. "
|
|
|
|
"This should never happen.";
|
|
|
|
|
|
|
|
bool nothingChanged = m_cxt.evalScript(
|
2016-10-19 17:35:23 +02:00
|
|
|
"_calamares_module.widget() in _calamares_module_basewidget.children()" ).toBool();
|
2016-10-07 19:12:28 +02:00
|
|
|
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
|
|
|
|
// set a new one.
|
|
|
|
|
|
|
|
// First we clear the layout, which should only ever have 1 item.
|
|
|
|
// 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 );
|
|
|
|
|
2016-10-04 15:29:17 +02:00
|
|
|
m_cxt.evalScript(
|
|
|
|
"_calamares_module_basewidget.layout().addWidget(_calamares_module.widget())" );
|
2016-10-07 19:12:28 +02:00
|
|
|
|
2016-10-04 15:29:17 +02:00
|
|
|
return m_widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PythonQtViewStep::next()
|
|
|
|
{
|
2016-10-07 19:12:28 +02:00
|
|
|
CalamaresUtils::lookupAndCall( m_obj, { "next" } );
|
2016-10-04 15:29:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
PythonQtViewStep::back()
|
|
|
|
{
|
2016-10-07 19:12:28 +02:00
|
|
|
CalamaresUtils::lookupAndCall( m_obj, { "back" } );
|
2016-10-04 15:29:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
PythonQtViewStep::isNextEnabled() const
|
|
|
|
{
|
2016-10-07 19:12:28 +02:00
|
|
|
return CalamaresUtils::lookupAndCall( m_obj,
|
|
|
|
{ "isNextEnabled",
|
|
|
|
"is_next_enabled" } ).toBool();
|
2016-10-04 15:29:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
PythonQtViewStep::isBackEnabled() const
|
|
|
|
{
|
2016-10-07 19:12:28 +02:00
|
|
|
return CalamaresUtils::lookupAndCall( m_obj,
|
|
|
|
{ "isBackEnabled",
|
|
|
|
"is_back_enabled" } ).toBool();
|
2016-10-04 15:29:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
PythonQtViewStep::isAtBeginning() const
|
|
|
|
{
|
2016-10-07 19:12:28 +02:00
|
|
|
return CalamaresUtils::lookupAndCall( m_obj,
|
|
|
|
{ "isAtBeginning",
|
|
|
|
"is_at_beginning" } ).toBool();
|
2016-10-04 15:29:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
PythonQtViewStep::isAtEnd() const
|
|
|
|
{
|
2016-10-07 19:12:28 +02:00
|
|
|
return CalamaresUtils::lookupAndCall( m_obj,
|
|
|
|
{ "isAtEnd",
|
|
|
|
"is_at_end" } ).toBool();
|
2016-10-04 15:29:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QList< Calamares::job_ptr >
|
|
|
|
PythonQtViewStep::jobs() const
|
|
|
|
{
|
|
|
|
#warning "Not implemented yet."
|
|
|
|
return QList< Calamares::job_ptr >();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-07 19:12:28 +02:00
|
|
|
void
|
|
|
|
PythonQtViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
|
|
|
{
|
|
|
|
#warning "Not implemented yet."
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-04 15:29:17 +02:00
|
|
|
QWidget*
|
|
|
|
PythonQtViewStep::createScriptingConsole()
|
|
|
|
{
|
|
|
|
PythonQtScriptingConsole* console = new PythonQtScriptingConsole( nullptr, m_cxt );
|
|
|
|
console->setProperty( "classname",
|
|
|
|
m_cxt.getVariable( "_calamares_module_typename" ).toString() );
|
|
|
|
return console;
|
|
|
|
}
|
2016-10-07 19:12:28 +02:00
|
|
|
|
|
|
|
}
|