[calamares] Make UI work for test-loader
- Need to create just one QApplication (subclass) with the right parameters for the UI to work. - If the UI is enabled and it's a View module, then show the widget rather than running the jobs.
This commit is contained in:
parent
f2fb49ce26
commit
ff6c6a360b
@ -40,6 +40,7 @@
|
|||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QLabel>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -96,8 +97,6 @@ handle_args( QCoreApplication& a )
|
|||||||
|
|
||||||
parser.process( a );
|
parser.process( a );
|
||||||
|
|
||||||
Logger::setupLogLevel( Logger::LOGVERBOSE );
|
|
||||||
|
|
||||||
const QStringList args = parser.positionalArguments();
|
const QStringList args = parser.positionalArguments();
|
||||||
if ( args.isEmpty() )
|
if ( args.isEmpty() )
|
||||||
{
|
{
|
||||||
@ -189,13 +188,38 @@ load_module( const ModuleConfig& moduleConfig )
|
|||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief Create the right kind of QApplication
|
||||||
|
*
|
||||||
|
* Does primitive parsing of argv[] to find the --ui option and returns
|
||||||
|
* a UI-enabled application if it does.
|
||||||
|
*
|
||||||
|
* @p argc must be a reference (to main's argc) because the QCoreApplication
|
||||||
|
* constructors take a reference as well, and that would otherwise be a
|
||||||
|
* reference to a temporary.
|
||||||
|
*/
|
||||||
|
QCoreApplication*
|
||||||
|
createApplication( int& argc, char* argv[] )
|
||||||
|
{
|
||||||
|
for ( int i = 1; i < argc; ++i )
|
||||||
|
{
|
||||||
|
if ( !qstrcmp( argv[ i ], "--ui" ) || !qstrcmp( argv[ i ], "-U" ) )
|
||||||
|
{
|
||||||
|
auto* aw = new QApplication( argc, argv );
|
||||||
|
aw->setQuitOnLastWindowClosed( true );
|
||||||
|
return aw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new QCoreApplication( argc, argv );
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main( int argc, char* argv[] )
|
main( int argc, char* argv[] )
|
||||||
{
|
{
|
||||||
QCoreApplication a( argc, argv );
|
QCoreApplication* aw = createApplication( argc, argv );
|
||||||
QApplication* aw = nullptr;
|
|
||||||
|
|
||||||
ModuleConfig module = handle_args( a );
|
Logger::setupLogLevel( Logger::LOGVERBOSE );
|
||||||
|
|
||||||
|
ModuleConfig module = handle_args( *aw );
|
||||||
if ( module.moduleName().isEmpty() )
|
if ( module.moduleName().isEmpty() )
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
@ -203,6 +227,7 @@ main( int argc, char* argv[] )
|
|||||||
|
|
||||||
std::unique_ptr< Calamares::Settings > settings_p( new Calamares::Settings( QString(), true ) );
|
std::unique_ptr< Calamares::Settings > settings_p( new Calamares::Settings( QString(), true ) );
|
||||||
std::unique_ptr< Calamares::JobQueue > jobqueue_p( new Calamares::JobQueue( nullptr ) );
|
std::unique_ptr< Calamares::JobQueue > jobqueue_p( new Calamares::JobQueue( nullptr ) );
|
||||||
|
QMainWindow* mw = nullptr;
|
||||||
|
|
||||||
auto gs = jobqueue_p->globalStorage();
|
auto gs = jobqueue_p->globalStorage();
|
||||||
if ( !module.globalConfigFile().isEmpty() )
|
if ( !module.globalConfigFile().isEmpty() )
|
||||||
@ -228,8 +253,8 @@ main( int argc, char* argv[] )
|
|||||||
cDebug() << " .. got" << m->name() << m->typeString() << m->interfaceString();
|
cDebug() << " .. got" << m->name() << m->typeString() << m->interfaceString();
|
||||||
if ( m->type() == Calamares::Module::Type::View )
|
if ( m->type() == Calamares::Module::Type::View )
|
||||||
{
|
{
|
||||||
aw = new QApplication( argc, argv );
|
mw = module.m_ui ? new QMainWindow() : nullptr;
|
||||||
QMainWindow* mw = module.m_ui ? new QMainWindow() : nullptr;
|
|
||||||
(void)new Calamares::Branding( module.m_branding );
|
(void)new Calamares::Branding( module.m_branding );
|
||||||
(void)new Calamares::ModuleManager( QStringList(), nullptr );
|
(void)new Calamares::ModuleManager( QStringList(), nullptr );
|
||||||
(void)Calamares::ViewManager::instance( mw );
|
(void)Calamares::ViewManager::instance( mw );
|
||||||
@ -246,6 +271,16 @@ main( int argc, char* argv[] )
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( mw )
|
||||||
|
{
|
||||||
|
QWidget* w = Calamares::ViewManager::instance()->currentStep()->widget();
|
||||||
|
w->setParent( mw );
|
||||||
|
mw->setCentralWidget( w );
|
||||||
|
w->show();
|
||||||
|
mw->show();
|
||||||
|
return aw->exec();
|
||||||
|
}
|
||||||
|
|
||||||
using TR = Logger::DebugRow< const char*, const QString >;
|
using TR = Logger::DebugRow< const char*, const QString >;
|
||||||
|
|
||||||
cDebug() << "Module metadata" << TR( "name", m->name() ) << TR( "type", m->typeString() )
|
cDebug() << "Module metadata" << TR( "name", m->name() ) << TR( "type", m->typeString() )
|
||||||
|
Loading…
Reference in New Issue
Block a user