2015-03-04 19:35:10 +01:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
2016-03-15 11:15:09 +01:00
|
|
|
* Copyright 2015-2016, Teo Mrnjavac <teo@kde.org>
|
2015-03-04 19:35:10 +01:00
|
|
|
*
|
|
|
|
* 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 "DebugWindow.h"
|
2016-03-15 11:15:09 +01:00
|
|
|
#include "utils/CalamaresUtils.h"
|
2015-03-04 19:35:10 +01:00
|
|
|
#include "utils/Retranslator.h"
|
2015-03-04 20:24:30 +01:00
|
|
|
#include "utils/qjsonmodel.h"
|
|
|
|
#include "JobQueue.h"
|
2015-03-06 18:56:07 +01:00
|
|
|
#include "Job.h"
|
2015-03-04 20:24:30 +01:00
|
|
|
#include "GlobalStorage.h"
|
2015-03-10 19:48:48 +01:00
|
|
|
#include "modulesystem/ModuleManager.h"
|
|
|
|
#include "modulesystem/Module.h"
|
2015-03-04 20:24:30 +01:00
|
|
|
|
2016-10-04 15:35:48 +02:00
|
|
|
#ifdef WITH_PYTHONQT
|
|
|
|
#include <gui/PythonQtScriptingConsole.h>
|
|
|
|
#include "ViewManager.h"
|
|
|
|
#include "viewpages/PythonQtViewStep.h"
|
|
|
|
#endif
|
|
|
|
|
2015-03-04 20:24:30 +01:00
|
|
|
#include <QJsonDocument>
|
2015-03-10 19:48:48 +01:00
|
|
|
#include <QSplitter>
|
|
|
|
#include <QStringListModel>
|
2015-03-04 20:24:30 +01:00
|
|
|
#include <QTreeView>
|
2015-03-04 19:35:10 +01:00
|
|
|
|
|
|
|
namespace Calamares {
|
|
|
|
|
|
|
|
DebugWindow::DebugWindow()
|
|
|
|
: QWidget( nullptr )
|
|
|
|
{
|
|
|
|
setupUi( this );
|
|
|
|
|
2015-03-10 19:48:48 +01:00
|
|
|
// GlobalStorage page
|
2015-03-04 20:24:30 +01:00
|
|
|
QJsonModel* jsonModel = new QJsonModel( this );
|
|
|
|
|
|
|
|
globalStorageView->setModel( jsonModel );
|
2015-03-05 19:39:12 +01:00
|
|
|
GlobalStorage* gs = JobQueue::instance()->globalStorage();
|
|
|
|
|
2015-07-15 17:49:25 +02:00
|
|
|
connect( gs, &GlobalStorage::changed,
|
|
|
|
this, [ = ]
|
2015-03-05 19:39:12 +01:00
|
|
|
{
|
|
|
|
jsonModel->loadJson( QJsonDocument::fromVariant( gs->m ).toJson() );
|
2015-03-05 19:40:53 +01:00
|
|
|
globalStorageView->expandAll();
|
2015-03-05 19:39:12 +01:00
|
|
|
} );
|
|
|
|
jsonModel->loadJson( QJsonDocument::fromVariant( gs->m ).toJson() );
|
2015-03-05 19:40:53 +01:00
|
|
|
globalStorageView->expandAll();
|
2015-03-04 20:24:30 +01:00
|
|
|
|
2015-03-10 19:48:48 +01:00
|
|
|
// JobQueue page
|
2015-03-06 18:56:07 +01:00
|
|
|
jobQueueText->setReadOnly( true );
|
|
|
|
connect( JobQueue::instance(), &JobQueue::queueChanged,
|
2015-07-15 17:49:25 +02:00
|
|
|
this, [ this ]( const QList< Calamares::job_ptr >& jobs )
|
2015-03-06 18:56:07 +01:00
|
|
|
{
|
|
|
|
QStringList text;
|
2016-09-01 14:21:05 +02:00
|
|
|
for ( const auto &job : jobs )
|
2015-03-06 18:56:07 +01:00
|
|
|
{
|
|
|
|
text.append( job->prettyName() );
|
|
|
|
}
|
|
|
|
|
|
|
|
jobQueueText->setText( text.join( '\n' ) );
|
|
|
|
} );
|
|
|
|
|
2015-03-10 19:48:48 +01:00
|
|
|
// Modules page
|
2015-09-09 19:03:39 +02:00
|
|
|
QStringListModel* modulesModel = new QStringListModel( ModuleManager::instance()->loadedInstanceKeys() );
|
2015-03-10 19:48:48 +01:00
|
|
|
modulesListView->setModel( modulesModel );
|
|
|
|
modulesListView->setSelectionMode( QAbstractItemView::SingleSelection );
|
|
|
|
|
|
|
|
QJsonModel* moduleConfigModel = new QJsonModel( this );
|
|
|
|
moduleConfigView->setModel( moduleConfigModel );
|
|
|
|
|
2016-10-04 15:35:48 +02:00
|
|
|
#ifdef WITH_PYTHONQT
|
|
|
|
QPushButton* pythonConsoleButton = new QPushButton;
|
|
|
|
pythonConsoleButton->setText( "Attach Python console" );
|
|
|
|
modulesVerticalLayout->insertWidget( 1, pythonConsoleButton );
|
|
|
|
pythonConsoleButton->hide();
|
|
|
|
|
|
|
|
QObject::connect( pythonConsoleButton, &QPushButton::clicked,
|
|
|
|
this, [ this, moduleConfigModel ]
|
|
|
|
{
|
|
|
|
QString moduleName = modulesListView->currentIndex().data().toString();
|
|
|
|
Module* module = ModuleManager::instance()->moduleInstance( moduleName );
|
|
|
|
if ( module->interface() != Module::PythonQtInterface ||
|
|
|
|
module->type() != Module::View )
|
|
|
|
return;
|
|
|
|
|
|
|
|
for ( ViewStep* step : ViewManager::instance()->viewSteps() )
|
|
|
|
{
|
|
|
|
if ( step->moduleInstanceKey() == module->instanceKey() )
|
|
|
|
{
|
|
|
|
PythonQtViewStep* pqvs =
|
|
|
|
qobject_cast< PythonQtViewStep* >( step );
|
|
|
|
if ( pqvs )
|
|
|
|
{
|
|
|
|
QWidget* consoleWindow = new QWidget;
|
|
|
|
|
|
|
|
QWidget* console = pqvs->createScriptingConsole();
|
|
|
|
console->setParent( consoleWindow );
|
|
|
|
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout;
|
|
|
|
consoleWindow->setLayout( layout );
|
|
|
|
layout->addWidget( console );
|
|
|
|
|
|
|
|
QHBoxLayout* bottomLayout = new QHBoxLayout;
|
|
|
|
layout->addLayout( bottomLayout );
|
|
|
|
|
|
|
|
QLabel* bottomLabel = new QLabel( consoleWindow );
|
|
|
|
bottomLayout->addWidget( bottomLabel );
|
|
|
|
QString line =
|
|
|
|
QString( "Module: <font color=\"#008000\"><code>%1</code></font><br/>"
|
|
|
|
"Python class: <font color=\"#008000\"><code>%2</code></font>" )
|
|
|
|
.arg( module->instanceKey() )
|
|
|
|
.arg( console->property( "classname" ).toString() );
|
|
|
|
bottomLabel->setText( line );
|
|
|
|
|
|
|
|
QPushButton* closeButton = new QPushButton( consoleWindow );
|
|
|
|
closeButton->setText( "&Close" );
|
|
|
|
QObject::connect( closeButton, &QPushButton::clicked,
|
|
|
|
[ consoleWindow ]
|
|
|
|
{
|
|
|
|
consoleWindow->close();
|
|
|
|
} );
|
|
|
|
bottomLayout->addWidget( closeButton );
|
|
|
|
bottomLabel->setSizePolicy( QSizePolicy::Expanding,
|
|
|
|
QSizePolicy::Preferred );
|
|
|
|
|
|
|
|
consoleWindow->setParent( this );
|
|
|
|
consoleWindow->setWindowFlags( Qt::Window );
|
|
|
|
consoleWindow->setWindowTitle( "Calamares Python console" );
|
|
|
|
consoleWindow->setAttribute( Qt::WA_DeleteOnClose, true );
|
|
|
|
consoleWindow->showNormal();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2015-03-10 19:48:48 +01:00
|
|
|
connect( modulesListView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
2016-10-31 12:38:57 +01:00
|
|
|
this, [ this, moduleConfigModel
|
|
|
|
#ifdef WITH_PYTHONQT
|
|
|
|
, pythonConsoleButton
|
|
|
|
#endif
|
|
|
|
]
|
2015-03-10 19:48:48 +01:00
|
|
|
{
|
|
|
|
QString moduleName = modulesListView->currentIndex().data().toString();
|
2015-09-09 19:03:39 +02:00
|
|
|
Module* module = ModuleManager::instance()->moduleInstance( moduleName );
|
2015-03-10 19:48:48 +01:00
|
|
|
if ( module )
|
|
|
|
{
|
|
|
|
moduleConfigModel->loadJson( QJsonDocument::fromVariant( module->configurationMap() ).toJson() );
|
|
|
|
moduleConfigView->expandAll();
|
2016-10-04 15:35:48 +02:00
|
|
|
moduleTypeLabel->setText( module->typeString() );
|
|
|
|
moduleInterfaceLabel->setText( module->interfaceString() );
|
|
|
|
#ifdef WITH_PYTHONQT
|
|
|
|
pythonConsoleButton->setVisible(
|
|
|
|
module->interface() == Module::PythonQtInterface &&
|
|
|
|
module->type() == Module::View );
|
|
|
|
#endif
|
2015-03-10 19:48:48 +01:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2016-03-15 11:15:09 +01:00
|
|
|
connect( crashButton, &QPushButton::clicked,
|
|
|
|
this, [] {
|
|
|
|
CalamaresUtils::crash();
|
|
|
|
} );
|
|
|
|
|
2015-03-11 12:42:08 +01:00
|
|
|
CALAMARES_RETRANSLATE(
|
|
|
|
retranslateUi( this );
|
|
|
|
setWindowTitle( tr( "Debug information" ) );
|
|
|
|
)
|
2015-03-04 19:35:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
DebugWindow::closeEvent( QCloseEvent* e )
|
|
|
|
{
|
|
|
|
Q_UNUSED( e )
|
|
|
|
emit closed();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Calamares
|