Merge branch 'master' of https://github.com/calamares/calamares into development

This commit is contained in:
Philip Müller 2019-06-15 21:47:31 +02:00
commit 719812ffd6
20 changed files with 375 additions and 192 deletions

33
.clang-format Normal file
View File

@ -0,0 +1,33 @@
---
BasedOnStyle: WebKit
AlignAfterOpenBracket: Align
AllowAllParametersOfDeclarationOnNextLine: 'false'
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: 'false'
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakAfterDefinitionReturnType: All
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: 'false'
BinPackParameters: 'false'
BreakBeforeBraces: Allman
BreakBeforeTernaryOperators: 'true'
BreakConstructorInitializers: BeforeComma
ColumnLimit: 120
Cpp11BracedListStyle: 'false'
FixNamespaceComments: 'true'
IncludeBlocks: Preserve
IndentWidth: '4'
MaxEmptyLinesToKeep: '2'
NamespaceIndentation: Inner
PointerAlignment: Left
ReflowComments: 'false'
SortIncludes: 'true'
SpaceAfterCStyleCast: 'false'
SpacesBeforeTrailingComments: '2'
SpacesInAngles: 'true'
SpacesInParentheses: 'true'
SpacesInSquareBrackets: 'true'
Standard: Cpp11
...

View File

@ -56,7 +56,7 @@ some PEP8 guidelines.
* For pointer and reference variable declarations, put a space before the variable name * For pointer and reference variable declarations, put a space before the variable name
and no space between the type and the `*` or `&`, e.g. `int* p`. and no space between the type and the `*` or `&`, e.g. `int* p`.
* `for`, `if`, `else`, `while` and similar statements put the braces on the next line, * `for`, `if`, `else`, `while` and similar statements put the braces on the next line,
if the following block is more than one statement. Use no braces for single statements. if the following block is more than one statement. Always use braces.
* Function and class definitions have their braces on separate lines. * Function and class definitions have their braces on separate lines.
* A function implementation's return type is on its own line. * A function implementation's return type is on its own line.
* `CamelCase.{cpp,h}` style file names. * `CamelCase.{cpp,h}` style file names.
@ -86,9 +86,13 @@ MyClass::myMethod( QStringList list, const QString& name )
} }
``` ```
You can use the `ci/calamaresstyle` script to run You can use `clang-format` (version 7) to have Calamares sources formatted
[astyle](http://astyle.sf.net) on your code and have it formatted the right the right way. There is a `.clang-format` file that specifies the details.
way. In general:
```
$ clang-format-7 -i -style=file <files>
```
`
**NOTE:** An .editorconfig file is included to assist with formatting. In **NOTE:** An .editorconfig file is included to assist with formatting. In
order to take advantage of this functionality you will need to acquire the order to take advantage of this functionality you will need to acquire the
@ -179,15 +183,19 @@ connect( m_moduleManager, &Calamares::ModuleManager::modulesLoaded, [this]
Debugging Debugging
--------- ---------
Use `cDebug()` and `cLog()` from `utils/Logger.h`. You can pass a debug-level to Use `cDebug()` from `utils/Logger.h`. You can pass a debug-level to the
either macro (1 is debugging, higher is less important). Use `cLog()` for warning macro (6 is debugging, higher is less important). Use `cWarning()` for warning
messages. It is recommended to add *WARNING* as the first part of a warning messages (equivalent to level 2) and `cError()` for errors (level 1). Warnings
message. and errors will add relevant text automatically. See `libcalamares/utils/Logger.h`
for details.
For log messages that are continued across multiple calls to `cDebug()`, For log messages that are continued across multiple calls to `cDebug()`,
in particular listing things, conventional formatting is as follows: in particular listing things, conventional formatting is as follows:
* End the first debug message with ` ..` * End the first debug message with ` ..`
* Indent following lines with ` ..` * Start the next debug message by outputting `Logger::SubEntry`
For single-outputs that need to be split across multiplt lines,
output `Logger::Continuation`.
Commit Messages Commit Messages

View File

@ -5,7 +5,7 @@ indent=spaces=4
# Brackets # Brackets
style=break style=break
remove-brackets # Remove brackets on single-line `if` and `for` (requires astyle 2.04) add-brackets
# Spaces # Spaces
pad-paren-in pad-paren-in

View File

@ -1,6 +1,42 @@
#!/bin/sh #!/bin/sh
#
# Calls astyle with settings matching Calamares coding style # Calls astyle with settings matching Calamares coding style
# Requires astyle >= 2.04 # Requires astyle >= 2.04 and clang-format-7
#
# You can pass in directory names, in which case the files
# in that directory (NOT below it) are processed.
#
set -e set -e
astyle --options=$(dirname $0)/astylerc "$@" AS=$( which astyle )
CF=$( which clang-format-7 )
test -n "$AS" || { echo "! No astyle found in PATH"; exit 1 ; }
test -n "$CF" || { echo "! No clang-format-7 found in PATH"; exit 1 ; }
test -x "$AS" || { echo "! $AS is not executable."; exit 1 ; }
test -x "$CF" || { echo "! $CF is not executable."; exit 1 ; }
any_dirs=no
for d in "$@"
do
test -d "$d" && any_dirs=yes
done
style_some()
{
$AS --options=$(dirname $0)/astylerc --quiet "$@"
$CF -i -style=file "$@"
}
if test "x$any_dirs" = "xyes" ; then
for d in "$@"
do
if test -d "$@" ; then
style_some $( find "$d" -maxdepth 1 -type f -name '*.cpp' -o -name '*.h' )
else
style_some "$d"
fi
done
else
style_some "$@"
fi

View File

@ -16,27 +16,27 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with Calamares. If not, see <http://www.gnu.org/licenses/>. * along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QDesktopWidget>
#include "CalamaresApplication.h" #include "CalamaresApplication.h"
#include "CalamaresConfig.h" #include "CalamaresConfig.h"
#include "CalamaresWindow.h"
#include "CalamaresVersion.h" #include "CalamaresVersion.h"
#include "progresstree/ProgressTreeView.h" #include "CalamaresWindow.h"
#include "progresstree/ProgressTreeModel.h" #include "progresstree/ProgressTreeModel.h"
#include "progresstree/ProgressTreeView.h"
#include "Branding.h"
#include "JobQueue.h"
#include "Settings.h"
#include "ViewManager.h"
#include "modulesystem/ModuleManager.h" #include "modulesystem/ModuleManager.h"
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
#include "utils/CalamaresUtilsSystem.h" #include "utils/CalamaresUtilsSystem.h"
#include "utils/Dirs.h" #include "utils/Dirs.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Retranslator.h" #include "utils/Retranslator.h"
#include "JobQueue.h"
#include "Branding.h"
#include "Settings.h"
#include "viewpages/ViewStep.h" #include "viewpages/ViewStep.h"
#include "ViewManager.h"
#include <QDesktopWidget>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
@ -77,8 +77,7 @@ CalamaresApplication::init()
initSettings(); initSettings();
initBranding(); initBranding();
setWindowIcon( QIcon( Calamares::Branding::instance()-> setWindowIcon( QIcon( Calamares::Branding::instance()->imagePath( Calamares::Branding::ProductIcon ) ) );
imagePath( Calamares::Branding::ProductIcon ) ) );
cDebug() << "STARTUP: initQmlPath, initSettings, initBranding done"; cDebug() << "STARTUP: initQmlPath, initSettings, initBranding done";
@ -91,15 +90,7 @@ CalamaresApplication::init()
CalamaresApplication::~CalamaresApplication() CalamaresApplication::~CalamaresApplication()
{ {
cDebug( Logger::LOGVERBOSE ) << "Shutting down Calamares..."; cDebug( Logger::LOGVERBOSE ) << "Shutting down Calamares...";
cDebug( Logger::LOGVERBOSE ) << Logger::SubEntry << "Finished shutdown.";
// if ( JobQueue::instance() )
// JobQueue::instance()->stop();
// delete m_mainwindow;
// delete JobQueue::instance();
cDebug( Logger::LOGVERBOSE ) << "Finished shutdown.";
} }
@ -138,14 +129,20 @@ qmlDirCandidates( bool assumeBuilddir )
QStringList qmlDirs; QStringList qmlDirs;
if ( CalamaresUtils::isAppDataDirOverridden() ) if ( CalamaresUtils::isAppDataDirOverridden() )
{
qmlDirs << CalamaresUtils::appDataDir().absoluteFilePath( QML ); qmlDirs << CalamaresUtils::appDataDir().absoluteFilePath( QML );
}
else else
{ {
if ( assumeBuilddir ) if ( assumeBuilddir )
{
qmlDirs << QDir::current().absoluteFilePath( "src/qml" ); // In build-dir qmlDirs << QDir::current().absoluteFilePath( "src/qml" ); // In build-dir
}
if ( CalamaresUtils::haveExtraDirs() ) if ( CalamaresUtils::haveExtraDirs() )
for ( auto s : CalamaresUtils::extraDataDirs() ) for ( auto s : CalamaresUtils::extraDataDirs() )
{
qmlDirs << ( s + QML ); qmlDirs << ( s + QML );
}
qmlDirs << CalamaresUtils::appDataDir().absoluteFilePath( QML ); qmlDirs << CalamaresUtils::appDataDir().absoluteFilePath( QML );
} }
@ -160,14 +157,20 @@ settingsFileCandidates( bool assumeBuilddir )
QStringList settingsPaths; QStringList settingsPaths;
if ( CalamaresUtils::isAppDataDirOverridden() ) if ( CalamaresUtils::isAppDataDirOverridden() )
{
settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings ); settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings );
}
else else
{ {
if ( assumeBuilddir ) if ( assumeBuilddir )
{
settingsPaths << QDir::current().absoluteFilePath( settings ); settingsPaths << QDir::current().absoluteFilePath( settings );
}
if ( CalamaresUtils::haveExtraDirs() ) if ( CalamaresUtils::haveExtraDirs() )
for ( auto s : CalamaresUtils::extraConfigDirs() ) for ( auto s : CalamaresUtils::extraConfigDirs() )
{
settingsPaths << ( s + settings ); settingsPaths << ( s + settings );
}
settingsPaths << CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/settings.conf"; // String concat settingsPaths << CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/settings.conf"; // String concat
settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings ); settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings );
} }
@ -181,14 +184,20 @@ brandingFileCandidates( bool assumeBuilddir, const QString& brandingFilename )
{ {
QStringList brandingPaths; QStringList brandingPaths;
if ( CalamaresUtils::isAppDataDirOverridden() ) if ( CalamaresUtils::isAppDataDirOverridden() )
{
brandingPaths << CalamaresUtils::appDataDir().absoluteFilePath( brandingFilename ); brandingPaths << CalamaresUtils::appDataDir().absoluteFilePath( brandingFilename );
}
else else
{ {
if ( assumeBuilddir ) if ( assumeBuilddir )
{
brandingPaths << ( QDir::currentPath() + QStringLiteral( "/src/" ) + brandingFilename ); brandingPaths << ( QDir::currentPath() + QStringLiteral( "/src/" ) + brandingFilename );
}
if ( CalamaresUtils::haveExtraDirs() ) if ( CalamaresUtils::haveExtraDirs() )
for ( auto s : CalamaresUtils::extraDataDirs() ) for ( auto s : CalamaresUtils::extraDataDirs() )
{
brandingPaths << ( s + brandingFilename ); brandingPaths << ( s + brandingFilename );
}
brandingPaths << QDir( CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/" ).absoluteFilePath( brandingFilename ); brandingPaths << QDir( CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/" ).absoluteFilePath( brandingFilename );
brandingPaths << CalamaresUtils::appDataDir().absoluteFilePath( brandingFilename ); brandingPaths << CalamaresUtils::appDataDir().absoluteFilePath( brandingFilename );
} }
@ -220,9 +229,13 @@ CalamaresApplication::initQmlPath()
cError() << "Cowardly refusing to continue startup without a QML directory." cError() << "Cowardly refusing to continue startup without a QML directory."
<< Logger::DebugList( qmlDirCandidatesByPriority ); << Logger::DebugList( qmlDirCandidatesByPriority );
if ( CalamaresUtils::isAppDataDirOverridden() ) if ( CalamaresUtils::isAppDataDirOverridden() )
{
cError() << "FATAL: explicitly configured application data directory is missing qml/"; cError() << "FATAL: explicitly configured application data directory is missing qml/";
}
else else
{
cError() << "FATAL: none of the expected QML paths exist."; cError() << "FATAL: none of the expected QML paths exist.";
}
::exit( EXIT_FAILURE ); ::exit( EXIT_FAILURE );
} }
@ -255,9 +268,13 @@ CalamaresApplication::initSettings()
cError() << "Cowardly refusing to continue startup without settings." cError() << "Cowardly refusing to continue startup without settings."
<< Logger::DebugList( settingsFileCandidatesByPriority ); << Logger::DebugList( settingsFileCandidatesByPriority );
if ( CalamaresUtils::isAppDataDirOverridden() ) if ( CalamaresUtils::isAppDataDirOverridden() )
{
cError() << "FATAL: explicitly configured application data directory is missing settings.conf"; cError() << "FATAL: explicitly configured application data directory is missing settings.conf";
}
else else
{
cError() << "FATAL: none of the expected configuration file paths exist."; cError() << "FATAL: none of the expected configuration file paths exist.";
}
::exit( EXIT_FAILURE ); ::exit( EXIT_FAILURE );
} }
@ -302,9 +319,13 @@ CalamaresApplication::initBranding()
cError() << "Cowardly refusing to continue startup without branding." cError() << "Cowardly refusing to continue startup without branding."
<< Logger::DebugList( brandingFileCandidatesByPriority ); << Logger::DebugList( brandingFileCandidatesByPriority );
if ( CalamaresUtils::isAppDataDirOverridden() ) if ( CalamaresUtils::isAppDataDirOverridden() )
{
cError() << "FATAL: explicitly configured application data directory is missing" << brandingComponentName; cError() << "FATAL: explicitly configured application data directory is missing" << brandingComponentName;
}
else else
{
cError() << "FATAL: none of the expected branding descriptor file paths exist."; cError() << "FATAL: none of the expected branding descriptor file paths exist.";
}
::exit( EXIT_FAILURE ); ::exit( EXIT_FAILURE );
} }
@ -315,10 +336,8 @@ CalamaresApplication::initBranding()
void void
CalamaresApplication::initModuleManager() CalamaresApplication::initModuleManager()
{ {
m_moduleManager = new Calamares::ModuleManager( m_moduleManager = new Calamares::ModuleManager( Calamares::Settings::instance()->modulesSearchPaths(), this );
Calamares::Settings::instance()->modulesSearchPaths(), this ); connect( m_moduleManager, &Calamares::ModuleManager::initDone, this, &CalamaresApplication::initView );
connect( m_moduleManager, &Calamares::ModuleManager::initDone,
this, &CalamaresApplication::initView );
m_moduleManager->init(); m_moduleManager->init();
} }
@ -332,16 +351,12 @@ CalamaresApplication::initView()
m_mainwindow = new CalamaresWindow(); //also creates ViewManager m_mainwindow = new CalamaresWindow(); //also creates ViewManager
connect( m_moduleManager, &Calamares::ModuleManager::modulesLoaded, connect( m_moduleManager, &Calamares::ModuleManager::modulesLoaded, this, &CalamaresApplication::initViewSteps );
this, &CalamaresApplication::initViewSteps ); connect( m_moduleManager, &Calamares::ModuleManager::modulesFailed, this, &CalamaresApplication::initFailed );
connect( m_moduleManager, &Calamares::ModuleManager::modulesFailed,
this, &CalamaresApplication::initFailed );
m_moduleManager->loadModules(); m_moduleManager->loadModules();
m_mainwindow->move( m_mainwindow->move( this->desktop()->availableGeometry().center() - m_mainwindow->rect().center() );
this->desktop()->availableGeometry().center() -
m_mainwindow->rect().center() );
cDebug() << "STARTUP: CalamaresWindow created; loadModules started"; cDebug() << "STARTUP: CalamaresWindow created; loadModules started";
} }
@ -358,7 +373,9 @@ CalamaresApplication::initViewSteps()
m_mainwindow->showMaximized(); m_mainwindow->showMaximized();
} }
else else
{
m_mainwindow->show(); m_mainwindow->show();
}
ProgressTreeModel* m = new ProgressTreeModel( nullptr ); ProgressTreeModel* m = new ProgressTreeModel( nullptr );
ProgressTreeView::instance()->setModel( m ); ProgressTreeView::instance()->setModel( m );
@ -368,8 +385,10 @@ CalamaresApplication::initViewSteps()
cDebug() << Logger::SubEntry << steps.count() << "view steps loaded."; cDebug() << Logger::SubEntry << steps.count() << "view steps loaded.";
// Tell the first view that it's been shown. // Tell the first view that it's been shown.
if ( steps.count() > 0 ) if ( steps.count() > 0 )
{
steps[ 0 ]->onActivate(); steps[ 0 ]->onActivate();
} }
}
void void
CalamaresApplication::initFailed( const QStringList& l ) CalamaresApplication::initFailed( const QStringList& l )

View File

@ -21,33 +21,39 @@
#include "CalamaresWindow.h" #include "CalamaresWindow.h"
#include "Branding.h"
#include "Settings.h"
#include "ViewManager.h" #include "ViewManager.h"
#include "progresstree/ProgressTreeView.h" #include "progresstree/ProgressTreeView.h"
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
#include "utils/Logger.h"
#include "utils/DebugWindow.h" #include "utils/DebugWindow.h"
#include "utils/Logger.h"
#include "utils/Retranslator.h" #include "utils/Retranslator.h"
#include "Settings.h"
#include "Branding.h"
#include <QApplication> #include <QApplication>
#include <QBoxLayout> #include <QBoxLayout>
#include <QCloseEvent> #include <QCloseEvent>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QLabel>
#include <QTreeView>
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QLabel>
#include <QTreeView>
static inline int static inline int
windowDimensionToPixels( const Calamares::Branding::WindowDimension& u ) windowDimensionToPixels( const Calamares::Branding::WindowDimension& u )
{ {
if ( !u.isValid() ) if ( !u.isValid() )
{
return 0; return 0;
}
if ( u.unit() == Calamares::Branding::WindowDimensionUnit::Pixies ) if ( u.unit() == Calamares::Branding::WindowDimensionUnit::Pixies )
{
return u.value(); return u.value();
}
if ( u.unit() == Calamares::Branding::WindowDimensionUnit::Fonties ) if ( u.unit() == Calamares::Branding::WindowDimensionUnit::Fonties )
{
return u.value() * CalamaresUtils::defaultFontHeight(); return u.value() * CalamaresUtils::defaultFontHeight();
}
return 0; return 0;
} }
@ -58,14 +64,13 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
{ {
// If we can never cancel, don't show the window-close button // If we can never cancel, don't show the window-close button
if ( Calamares::Settings::instance()->disableCancel() ) if ( Calamares::Settings::instance()->disableCancel() )
{
setWindowFlag( Qt::WindowCloseButtonHint, false ); setWindowFlag( Qt::WindowCloseButtonHint, false );
}
CALAMARES_RETRANSLATE( CALAMARES_RETRANSLATE( setWindowTitle( Calamares::Settings::instance()->isSetupMode()
setWindowTitle( Calamares::Settings::instance()->isSetupMode()
? tr( "%1 Setup Program" ).arg( *Calamares::Branding::ProductName ) ? tr( "%1 Setup Program" ).arg( *Calamares::Branding::ProductName )
: tr( "%1 Installer" ).arg( *Calamares::Branding::ProductName ) : tr( "%1 Installer" ).arg( *Calamares::Branding::ProductName ) ); )
);
)
const Calamares::Branding* const branding = Calamares::Branding::instance(); const Calamares::Branding* const branding = Calamares::Branding::instance();
@ -102,7 +107,8 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
QBoxLayout* sideLayout = new QVBoxLayout; QBoxLayout* sideLayout = new QVBoxLayout;
sideBox->setLayout( sideLayout ); sideBox->setLayout( sideLayout );
// Set this attribute into qss file // Set this attribute into qss file
sideBox->setFixedWidth( qBound( 100, CalamaresUtils::defaultFontHeight() * 12, w < windowPreferredWidth ? 100 : 190 ) ); sideBox->setFixedWidth(
qBound( 100, CalamaresUtils::defaultFontHeight() * 12, w < windowPreferredWidth ? 100 : 190 ) );
sideBox->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); sideBox->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
QHBoxLayout* logoLayout = new QHBoxLayout; QHBoxLayout* logoLayout = new QHBoxLayout;
@ -133,22 +139,16 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
{ {
QPushButton* debugWindowBtn = new QPushButton; QPushButton* debugWindowBtn = new QPushButton;
debugWindowBtn->setObjectName( "debugButton" ); debugWindowBtn->setObjectName( "debugButton" );
CALAMARES_RETRANSLATE( CALAMARES_RETRANSLATE( debugWindowBtn->setText( tr( "Show debug information" ) ); )
debugWindowBtn->setText( tr( "Show debug information" ) );
)
sideLayout->addWidget( debugWindowBtn ); sideLayout->addWidget( debugWindowBtn );
debugWindowBtn->setFlat( true ); debugWindowBtn->setFlat( true );
debugWindowBtn->setCheckable( true ); debugWindowBtn->setCheckable( true );
connect( debugWindowBtn, &QPushButton::clicked, connect( debugWindowBtn, &QPushButton::clicked, this, [=]( bool checked ) {
this, [ = ]( bool checked )
{
if ( checked ) if ( checked )
{ {
m_debugWindow = new Calamares::DebugWindow(); m_debugWindow = new Calamares::DebugWindow();
m_debugWindow->show(); m_debugWindow->show();
connect( m_debugWindow.data(), &Calamares::DebugWindow::closed, connect( m_debugWindow.data(), &Calamares::DebugWindow::closed, this, [=]() {
this, [ = ]()
{
m_debugWindow->deleteLater(); m_debugWindow->deleteLater();
debugWindowBtn->setChecked( false ); debugWindowBtn->setChecked( false );
} ); } );
@ -156,8 +156,10 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
else else
{ {
if ( m_debugWindow ) if ( m_debugWindow )
{
m_debugWindow->deleteLater(); m_debugWindow->deleteLater();
} }
}
} ); } );
} }
@ -166,7 +168,9 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
m_viewManager = Calamares::ViewManager::instance( this ); m_viewManager = Calamares::ViewManager::instance( this );
if ( branding->windowExpands() ) if ( branding->windowExpands() )
{
connect( m_viewManager, &Calamares::ViewManager::enlarge, this, &CalamaresWindow::enlarge ); connect( m_viewManager, &Calamares::ViewManager::enlarge, this, &CalamaresWindow::enlarge );
}
// NOTE: Although the ViewManager has a signal cancelEnabled() that // NOTE: Although the ViewManager has a signal cancelEnabled() that
// signals when the state of the cancel button changes (in // signals when the state of the cancel button changes (in
// particular, to disable cancel during the exec phase), // particular, to disable cancel during the exec phase),
@ -201,5 +205,7 @@ CalamaresWindow::closeEvent( QCloseEvent* event )
qApp->quit(); qApp->quit();
} }
else else
{
event->ignore(); event->ignore();
} }
}

View File

@ -27,7 +27,7 @@ namespace Calamares
{ {
class DebugWindow; class DebugWindow;
class ViewManager; class ViewManager;
} } // namespace Calamares
/** /**
* @brief The CalamaresWindow class represents the main window of the Calamares UI. * @brief The CalamaresWindow class represents the main window of the Calamares UI.

View File

@ -24,11 +24,10 @@
#include "kdsingleapplicationguard/kdsingleapplicationguard.h" #include "kdsingleapplicationguard/kdsingleapplicationguard.h"
#include "utils/Dirs.h" #include "utils/Dirs.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "CalamaresConfig.h"
#ifdef WITH_KF5Crash #ifdef WITH_KF5Crash
#include <KF5/KCrash/KCrash>
#include <KF5/KCoreAddons/KAboutData> #include <KF5/KCoreAddons/KAboutData>
#include <KF5/KCrash/KCrash>
#endif #endif
#include <QCommandLineParser> #include <QCommandLineParser>
@ -40,12 +39,11 @@ handle_args( CalamaresApplication& a )
{ {
QCommandLineOption debugOption( QStringList { "d", "debug" }, QCommandLineOption debugOption( QStringList { "d", "debug" },
"Also look in current directory for configuration. Implies -D8." ); "Also look in current directory for configuration. Implies -D8." );
QCommandLineOption debugLevelOption( QStringLiteral("D"), QCommandLineOption debugLevelOption(
"Verbose output for debugging purposes (0-8).", "level" ); QStringLiteral( "D" ), "Verbose output for debugging purposes (0-8).", "level" );
QCommandLineOption configOption( QStringList{ "c", "config"}, QCommandLineOption configOption(
"Configuration directory to use, for testing purposes.", "config" ); QStringList { "c", "config" }, "Configuration directory to use, for testing purposes.", "config" );
QCommandLineOption xdgOption( QStringList{"X", "xdg-config"}, QCommandLineOption xdgOption( QStringList { "X", "xdg-config" }, "Use XDG_{CONFIG,DATA}_DIRS as well." );
"Use XDG_{CONFIG,DATA}_DIRS as well." );
QCommandLineParser parser; QCommandLineParser parser;
parser.setApplicationDescription( "Distribution-independent installer framework" ); parser.setApplicationDescription( "Distribution-independent installer framework" );
@ -61,23 +59,33 @@ handle_args( CalamaresApplication& a )
a.setDebug( parser.isSet( debugOption ) ); a.setDebug( parser.isSet( debugOption ) );
if ( parser.isSet( debugOption ) ) if ( parser.isSet( debugOption ) )
{
Logger::setupLogLevel( Logger::LOGVERBOSE ); Logger::setupLogLevel( Logger::LOGVERBOSE );
}
else if ( parser.isSet( debugLevelOption ) ) else if ( parser.isSet( debugLevelOption ) )
{ {
bool ok = true; bool ok = true;
int l = parser.value( debugLevelOption ).toInt( &ok ); int l = parser.value( debugLevelOption ).toInt( &ok );
unsigned int dlevel = 0; unsigned int dlevel = 0;
if ( !ok || ( l < 0 ) ) if ( !ok || ( l < 0 ) )
{
dlevel = Logger::LOGVERBOSE; dlevel = Logger::LOGVERBOSE;
}
else else
{
dlevel = static_cast< unsigned int >( l ); // l >= 0 dlevel = static_cast< unsigned int >( l ); // l >= 0
}
Logger::setupLogLevel( dlevel ); Logger::setupLogLevel( dlevel );
} }
if ( parser.isSet( configOption ) ) if ( parser.isSet( configOption ) )
{
CalamaresUtils::setAppDataDir( QDir( parser.value( configOption ) ) ); CalamaresUtils::setAppDataDir( QDir( parser.value( configOption ) ) );
}
if ( parser.isSet( xdgOption ) ) if ( parser.isSet( xdgOption ) )
{
CalamaresUtils::setXdgDirs(); CalamaresUtils::setXdgDirs();
} }
}
int int
main( int argc, char* argv[] ) main( int argc, char* argv[] )
@ -118,10 +126,14 @@ main( int argc, char* argv[] )
auto instancelist = guard.instances(); auto instancelist = guard.instances();
qDebug() << "Calamares is already running, shutting down."; qDebug() << "Calamares is already running, shutting down.";
if ( instancelist.count() > 0 ) if ( instancelist.count() > 0 )
{
qDebug() << "Other running Calamares instances:"; qDebug() << "Other running Calamares instances:";
}
for ( const auto& i : instancelist ) for ( const auto& i : instancelist )
{
qDebug() << " " << i.isValid() << i.pid() << i.arguments(); qDebug() << " " << i.isValid() << i.pid() << i.arguments();
} }
}
return returnCode; return returnCode;
} }

View File

@ -20,23 +20,28 @@
#include "ProgressTreeDelegate.h" #include "ProgressTreeDelegate.h"
#include "ProgressTreeModel.h" #include "ProgressTreeModel.h"
#include "Branding.h"
#include "CalamaresApplication.h" #include "CalamaresApplication.h"
#include "CalamaresWindow.h" #include "CalamaresWindow.h"
#include "Branding.h"
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
#include <QPainter> #include <QPainter>
static constexpr int const item_margin = 8; static constexpr int const item_margin = 8;
static inline int item_fontsize() { return CalamaresUtils::defaultFontSize() + 4; } static inline int
item_fontsize()
{
return CalamaresUtils::defaultFontSize() + 4;
}
QSize QSize
ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option, ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const
const QModelIndex& index ) const
{ {
if ( !index.isValid() ) if ( !index.isValid() )
{
return option.rect.size(); return option.rect.size();
}
QFont font = qApp->font(); QFont font = qApp->font();
@ -51,9 +56,7 @@ ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option,
void void
ProgressTreeDelegate::paint( QPainter* painter, ProgressTreeDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
const QStyleOptionViewItem& option,
const QModelIndex& index) const
{ {
QStyleOptionViewItem opt = option; QStyleOptionViewItem opt = option;
@ -62,10 +65,9 @@ ProgressTreeDelegate::paint( QPainter* painter,
initStyleOption( &opt, index ); initStyleOption( &opt, index );
opt.text.clear(); opt.text.clear();
painter->setBrush( QColor( Calamares::Branding::instance()-> painter->setBrush(
styleString( Calamares::Branding::SidebarBackground ) ) ); QColor( Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarBackground ) ) );
painter->setPen( QColor( Calamares::Branding::instance()-> painter->setPen( QColor( Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarText ) ) );
styleString( Calamares::Branding::SidebarText ) ) );
paintViewStep( painter, opt, index ); paintViewStep( painter, opt, index );
@ -89,15 +91,18 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter,
if ( isCurrent ) if ( isCurrent )
{ {
painter->setPen( Calamares::Branding::instance()-> painter->setPen( Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarTextSelect ) );
styleString( Calamares::Branding::SidebarTextSelect ) ); QString textHighlight
QString textHighlight = Calamares::Branding::instance()-> = Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarTextHighlight );
styleString( Calamares::Branding::SidebarTextHighlight );
if ( textHighlight.isEmpty() ) if ( textHighlight.isEmpty() )
{
painter->setBrush( CalamaresApplication::instance()->mainWindow()->palette().background() ); painter->setBrush( CalamaresApplication::instance()->mainWindow()->palette().background() );
}
else else
{
painter->setBrush( QColor( textHighlight ) ); painter->setBrush( QColor( textHighlight ) );
} }
}
// Draw the text at least once. If it doesn't fit, then shrink the font // Draw the text at least once. If it doesn't fit, then shrink the font
@ -114,7 +119,8 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter,
shrinkSteps++; shrinkSteps++;
QRectF boundingBox; QRectF boundingBox;
painter->drawText( textRect, Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine, index.data().toString(), &boundingBox ); painter->drawText(
textRect, Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextSingleLine, index.data().toString(), &boundingBox );
// The extra check here is to avoid the changing-font-size if we're not going to use // The extra check here is to avoid the changing-font-size if we're not going to use
// it in the next iteration of the loop anyway. // it in the next iteration of the loop anyway.
@ -124,7 +130,8 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter,
painter->setFont( font ); painter->setFont( font );
} }
else else
{
break; // It fits break; // It fits
} }
while ( shrinkSteps <= maximumShrink ); } while ( shrinkSteps <= maximumShrink );
} }

View File

@ -33,16 +33,11 @@ public:
using QStyledItemDelegate::QStyledItemDelegate; using QStyledItemDelegate::QStyledItemDelegate;
protected: protected:
QSize sizeHint( const QStyleOptionViewItem& option, QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const override;
const QModelIndex& index ) const override; void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const override;
void paint( QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index ) const override;
private: private:
void paintViewStep( QPainter* painter, void paintViewStep( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
const QStyleOptionViewItem& option,
const QModelIndex& index ) const;
}; };
#endif // PROGRESSTREEDELEGATE_H #endif // PROGRESSTREEDELEGATE_H

View File

@ -65,8 +65,9 @@ int
ProgressTreeItem::row() const ProgressTreeItem::row() const
{ {
if ( m_parentItem ) if ( m_parentItem )
return m_parentItem->m_childItems.indexOf( {
const_cast< ProgressTreeItem* >( this ) ); return m_parentItem->m_childItems.indexOf( const_cast< ProgressTreeItem* >( this ) );
}
return 0; return 0;
} }
@ -80,7 +81,8 @@ ProgressTreeItem::parent()
ProgressTreeRoot::ProgressTreeRoot() ProgressTreeRoot::ProgressTreeRoot()
: ProgressTreeItem() : ProgressTreeItem()
{} {
}
QVariant QVariant

View File

@ -19,7 +19,8 @@
#include "ProgressTreeModel.h" #include "ProgressTreeModel.h"
#include "progresstree/ViewStepItem.h" #include "ViewStepItem.h"
#include "ViewManager.h" #include "ViewManager.h"
ProgressTreeModel::ProgressTreeModel( QObject* parent ) ProgressTreeModel::ProgressTreeModel( QObject* parent )
@ -40,7 +41,9 @@ Qt::ItemFlags
ProgressTreeModel::flags( const QModelIndex& index ) const ProgressTreeModel::flags( const QModelIndex& index ) const
{ {
if ( !index.isValid() ) if ( !index.isValid() )
{
return Qt::ItemFlags(); return Qt::ItemFlags();
}
return Qt::ItemIsEnabled; return Qt::ItemIsEnabled;
} }
@ -50,34 +53,48 @@ QModelIndex
ProgressTreeModel::index( int row, int column, const QModelIndex& parent ) const ProgressTreeModel::index( int row, int column, const QModelIndex& parent ) const
{ {
if ( !hasIndex( row, column, parent ) ) if ( !hasIndex( row, column, parent ) )
{
return QModelIndex(); return QModelIndex();
}
ProgressTreeItem* parentItem; ProgressTreeItem* parentItem;
if ( !parent.isValid() ) if ( !parent.isValid() )
{
parentItem = m_rootItem; parentItem = m_rootItem;
}
else else
{
parentItem = static_cast< ProgressTreeItem* >( parent.internalPointer() ); parentItem = static_cast< ProgressTreeItem* >( parent.internalPointer() );
}
ProgressTreeItem* childItem = parentItem->child( row ); ProgressTreeItem* childItem = parentItem->child( row );
if ( childItem ) if ( childItem )
{
return createIndex( row, column, childItem ); return createIndex( row, column, childItem );
}
else else
{
return QModelIndex(); return QModelIndex();
} }
}
QModelIndex QModelIndex
ProgressTreeModel::parent( const QModelIndex& index ) const ProgressTreeModel::parent( const QModelIndex& index ) const
{ {
if ( !index.isValid() ) if ( !index.isValid() )
{
return QModelIndex(); return QModelIndex();
}
ProgressTreeItem* childItem = static_cast< ProgressTreeItem* >( index.internalPointer() ); ProgressTreeItem* childItem = static_cast< ProgressTreeItem* >( index.internalPointer() );
ProgressTreeItem* parentItem = childItem->parent(); ProgressTreeItem* parentItem = childItem->parent();
if ( parentItem == m_rootItem ) if ( parentItem == m_rootItem )
{
return QModelIndex(); return QModelIndex();
}
return createIndex( parentItem->row(), 0, parentItem ); return createIndex( parentItem->row(), 0, parentItem );
} }
@ -87,7 +104,9 @@ QVariant
ProgressTreeModel::data( const QModelIndex& index, int role ) const ProgressTreeModel::data( const QModelIndex& index, int role ) const
{ {
if ( !index.isValid() ) if ( !index.isValid() )
{
return QVariant(); return QVariant();
}
ProgressTreeItem* item = static_cast< ProgressTreeItem* >( index.internalPointer() ); ProgressTreeItem* item = static_cast< ProgressTreeItem* >( index.internalPointer() );
@ -111,12 +130,18 @@ ProgressTreeModel::rowCount( const QModelIndex& parent ) const
{ {
ProgressTreeItem* parentItem; ProgressTreeItem* parentItem;
if ( parent.column() > 0 ) if ( parent.column() > 0 )
{
return 0; return 0;
}
if ( !parent.isValid() ) if ( !parent.isValid() )
{
parentItem = m_rootItem; parentItem = m_rootItem;
}
else else
{
parentItem = static_cast< ProgressTreeItem* >( parent.internalPointer() ); parentItem = static_cast< ProgressTreeItem* >( parent.internalPointer() );
}
return parentItem->childCount(); return parentItem->childCount();
} }
@ -126,10 +151,14 @@ int
ProgressTreeModel::columnCount( const QModelIndex& parent ) const ProgressTreeModel::columnCount( const QModelIndex& parent ) const
{ {
if ( parent.isValid() ) if ( parent.isValid() )
{
return static_cast< ProgressTreeItem* >( parent.internalPointer() )->columnCount(); return static_cast< ProgressTreeItem* >( parent.internalPointer() )->columnCount();
}
else else
{
return m_rootItem->columnCount(); return m_rootItem->columnCount();
} }
}
void void
@ -152,7 +181,9 @@ QModelIndex
ProgressTreeModel::indexFromItem( ProgressTreeItem* item ) ProgressTreeModel::indexFromItem( ProgressTreeItem* item )
{ {
if ( !item || !item->parent() ) if ( !item || !item->parent() )
{
return QModelIndex(); return QModelIndex();
}
// Reconstructs a QModelIndex from a ProgressTreeItem that is somewhere in the tree. // Reconstructs a QModelIndex from a ProgressTreeItem that is somewhere in the tree.
// Traverses the item to the root node, then rebuilds the qmodelindices from there // Traverses the item to the root node, then rebuilds the qmodelindices from there
@ -172,10 +203,13 @@ ProgressTreeModel::indexFromItem( ProgressTreeItem* item )
**/ **/
QList< int > childIndexList; QList< int > childIndexList;
ProgressTreeItem* curItem = item; ProgressTreeItem* curItem = item;
while ( curItem != m_rootItem ) { while ( curItem != m_rootItem )
{
int row = curItem->row(); //relative to its parent int row = curItem->row(); //relative to its parent
if ( row < 0 ) // something went wrong, bail if ( row < 0 ) // something went wrong, bail
{
return QModelIndex(); return QModelIndex();
}
childIndexList << row; childIndexList << row;

View File

@ -19,8 +19,9 @@
#include "ProgressTreeView.h" #include "ProgressTreeView.h"
#include "ProgressTreeDelegate.h" #include "ProgressTreeDelegate.h"
#include "ViewManager.h"
#include "Branding.h" #include "Branding.h"
#include "ViewManager.h"
ProgressTreeView* ProgressTreeView::s_instance = nullptr; ProgressTreeView* ProgressTreeView::s_instance = nullptr;
@ -55,31 +56,29 @@ ProgressTreeView::ProgressTreeView( QWidget* parent )
setItemDelegate( m_delegate ); setItemDelegate( m_delegate );
QPalette plt = palette(); QPalette plt = palette();
plt.setColor( QPalette::Base, Calamares::Branding::instance()-> plt.setColor( QPalette::Base,
styleString( Calamares::Branding::SidebarBackground ) ); Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarBackground ) );
setPalette( plt ); setPalette( plt );
} }
ProgressTreeView::~ProgressTreeView() ProgressTreeView::~ProgressTreeView() {}
{
}
void void
ProgressTreeView::setModel( QAbstractItemModel* model ) ProgressTreeView::setModel( QAbstractItemModel* model )
{ {
if ( ProgressTreeView::model() ) if ( ProgressTreeView::model() )
{
return; return;
}
QTreeView::setModel( model ); QTreeView::setModel( model );
expandAll(); expandAll();
connect( Calamares::ViewManager::instance(), connect( Calamares::ViewManager::instance(),
&Calamares::ViewManager::currentStepChanged, &Calamares::ViewManager::currentStepChanged,
this, [this]() this,
{ [this]() { viewport()->update(); },
viewport()->update();
},
Qt::UniqueConnection ); Qt::UniqueConnection );
} }

View File

@ -19,6 +19,7 @@
#include "ViewStepItem.h" #include "ViewStepItem.h"
#include "ProgressTreeModel.h" #include "ProgressTreeModel.h"
#include "Settings.h" #include "Settings.h"
#include "ViewManager.h" #include "ViewManager.h"
#include "viewpages/ViewStep.h" #include "viewpages/ViewStep.h"
@ -28,18 +29,17 @@ ViewStepItem::ViewStepItem( std::function< QString() > prettyName,
std::function< const Calamares::ViewStep*() > accessor, std::function< const Calamares::ViewStep*() > accessor,
ProgressTreeItem* parent ) ProgressTreeItem* parent )
: ProgressTreeItem( parent ) : ProgressTreeItem( parent )
, m_accessor( accessor )
, m_prettyName( prettyName )
, m_step( nullptr ) , m_step( nullptr )
{ {
m_prettyName = prettyName;
m_accessor = accessor;
} }
ViewStepItem::ViewStepItem( const Calamares::ViewStep* step, ViewStepItem::ViewStepItem( const Calamares::ViewStep* step, ProgressTreeItem* parent )
ProgressTreeItem* parent )
: ProgressTreeItem( parent ) : ProgressTreeItem( parent )
, m_step( step )
{ {
m_step = step;
} }
void void
@ -55,8 +55,7 @@ ViewStepItem::data( int role ) const
{ {
if ( role == Qt::DisplayRole ) if ( role == Qt::DisplayRole )
{ {
return m_step ? m_step->prettyName() return m_step ? m_step->prettyName() : m_prettyName();
: m_prettyName();
} }
if ( Calamares::Settings::instance()->debugMode() && role == Qt::ToolTipRole ) if ( Calamares::Settings::instance()->debugMode() && role == Qt::ToolTipRole )
{ {
@ -66,9 +65,9 @@ ViewStepItem::data( int role ) const
toolTip.append( "<br/>Type:\tViewStep" ); toolTip.append( "<br/>Type:\tViewStep" );
toolTip.append( QString( "<br/>Pretty:\t%1" ).arg( m_step->prettyName() ) ); toolTip.append( QString( "<br/>Pretty:\t%1" ).arg( m_step->prettyName() ) );
toolTip.append( QString( "<br/>Status:\t%1" ).arg( m_step->prettyStatus() ) ); toolTip.append( QString( "<br/>Status:\t%1" ).arg( m_step->prettyStatus() ) );
toolTip.append( QString( "<br/>Source:\t%1" ).arg( toolTip.append(
m_step->moduleInstanceKey().isEmpty() ? "built-in" QString( "<br/>Source:\t%1" )
: m_step->moduleInstanceKey() ) ); .arg( m_step->moduleInstanceKey().isEmpty() ? "built-in" : m_step->moduleInstanceKey() ) );
} }
else else
{ {
@ -78,8 +77,7 @@ ViewStepItem::data( int role ) const
return toolTip; return toolTip;
} }
if ( role == ProgressTreeModel::ProgressTreeItemCurrentRole ) if ( role == ProgressTreeModel::ProgressTreeItemCurrentRole )
return m_step ? return m_step ? ( Calamares::ViewManager::instance()->currentStep() == m_step )
( Calamares::ViewManager::instance()->currentStep() == m_step ) : : ( Calamares::ViewManager::instance()->currentStep() == m_accessor() );
( Calamares::ViewManager::instance()->currentStep() == m_accessor() );
return QVariant(); return QVariant();
} }

View File

@ -37,17 +37,16 @@ public:
std::function< const Calamares::ViewStep*() > accessor, std::function< const Calamares::ViewStep*() > accessor,
ProgressTreeItem* parent = nullptr ); ProgressTreeItem* parent = nullptr );
explicit ViewStepItem( const Calamares::ViewStep* step, explicit ViewStepItem( const Calamares::ViewStep* step, ProgressTreeItem* parent = nullptr );
ProgressTreeItem* parent = nullptr );
void appendChild( ProgressTreeItem* item ) override; void appendChild( ProgressTreeItem* item ) override;
QVariant data( int role ) const override; QVariant data( int role ) const override;
private: private:
std::function< const Calamares::ViewStep*() > m_accessor; const std::function< const Calamares::ViewStep*() > m_accessor;
std::function< QString() > m_prettyName; const std::function< QString() > m_prettyName;
const Calamares::ViewStep* m_step; const Calamares::ViewStep* const m_step;
}; };

View File

@ -22,9 +22,9 @@
* bindings. * bindings.
*/ */
#include "modulesystem/Module.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Yaml.h" #include "utils/Yaml.h"
#include "modulesystem/Module.h"
#include "GlobalStorage.h" #include "GlobalStorage.h"
#include "Job.h" #include "Job.h"
@ -40,10 +40,26 @@
struct ModuleConfig struct ModuleConfig
{ {
QString moduleName() const { return m_module; } QString
QString configFile() const { return m_jobConfig; } moduleName() const
QString language() const { return m_language; } {
QString globalConfigFile() const { return m_globalConfig; } return m_module;
}
QString
configFile() const
{
return m_jobConfig;
}
QString
language() const
{
return m_language;
}
QString
globalConfigFile() const
{
return m_globalConfig;
}
QString m_module; QString m_module;
QString m_jobConfig; QString m_jobConfig;
@ -54,14 +70,17 @@ struct ModuleConfig
static ModuleConfig static ModuleConfig
handle_args( QCoreApplication& a ) handle_args( QCoreApplication& a )
{ {
QCommandLineOption debugLevelOption( QStringLiteral("D"), QCommandLineOption debugLevelOption(
"Verbose output for debugging purposes (0-8).", "level" ); QStringLiteral( "D" ), "Verbose output for debugging purposes (0-8).", "level" );
QCommandLineOption globalOption( QStringList() << QStringLiteral( "g" ) << QStringLiteral( "global " ), QCommandLineOption globalOption( QStringList() << QStringLiteral( "g" ) << QStringLiteral( "global " ),
QStringLiteral( "Global settings document" ), "global.yaml" ); QStringLiteral( "Global settings document" ),
"global.yaml" );
QCommandLineOption jobOption( QStringList() << QStringLiteral( "j" ) << QStringLiteral( "job" ), QCommandLineOption jobOption( QStringList() << QStringLiteral( "j" ) << QStringLiteral( "job" ),
QStringLiteral( "Job settings document" ), "job.yaml" ); QStringLiteral( "Job settings document" ),
"job.yaml" );
QCommandLineOption langOption( QStringList() << QStringLiteral( "l" ) << QStringLiteral( "language" ), QCommandLineOption langOption( QStringList() << QStringLiteral( "l" ) << QStringLiteral( "language" ),
QStringLiteral( "Language (global)" ), "languagecode" ); QStringLiteral( "Language (global)" ),
"languagecode" );
QCommandLineParser parser; QCommandLineParser parser;
parser.setApplicationDescription( "Calamares module tester" ); parser.setApplicationDescription( "Calamares module tester" );
@ -83,9 +102,13 @@ handle_args( QCoreApplication& a )
unsigned int l = parser.value( debugLevelOption ).toUInt( &ok ); unsigned int l = parser.value( debugLevelOption ).toUInt( &ok );
unsigned int dlevel = 0; unsigned int dlevel = 0;
if ( !ok ) if ( !ok )
{
dlevel = Logger::LOGVERBOSE; dlevel = Logger::LOGVERBOSE;
}
else else
{
dlevel = l; dlevel = l;
}
Logger::setupLogLevel( dlevel ); Logger::setupLogLevel( dlevel );
} }
@ -104,7 +127,9 @@ handle_args( QCoreApplication& a )
{ {
QString jobSettings( parser.value( jobOption ) ); QString jobSettings( parser.value( jobOption ) );
if ( jobSettings.isEmpty() && ( args.size() == 2 ) ) if ( jobSettings.isEmpty() && ( args.size() == 2 ) )
{
jobSettings = args.at( 1 ); jobSettings = args.at( 1 );
}
return ModuleConfig { args.first(), jobSettings, parser.value( globalOption ), parser.value( langOption ) }; return ModuleConfig { args.first(), jobSettings, parser.value( globalOption ), parser.value( langOption ) };
} }
@ -125,9 +150,13 @@ load_module( const ModuleConfig& moduleConfig )
// Could be a complete path, eg. src/modules/dummycpp/module.desc // Could be a complete path, eg. src/modules/dummycpp/module.desc
fi = QFileInfo( prefix + moduleName ); fi = QFileInfo( prefix + moduleName );
if ( fi.exists() && fi.isFile() ) if ( fi.exists() && fi.isFile() )
{
descriptor = CalamaresUtils::loadYaml( fi, &ok ); descriptor = CalamaresUtils::loadYaml( fi, &ok );
}
if ( ok ) if ( ok )
{
break; break;
}
// Could be a path without module.desc // Could be a path without module.desc
fi = QFileInfo( prefix + moduleName ); fi = QFileInfo( prefix + moduleName );
@ -135,8 +164,13 @@ load_module( const ModuleConfig& moduleConfig )
{ {
fi = QFileInfo( prefix + moduleName + "/module.desc" ); fi = QFileInfo( prefix + moduleName + "/module.desc" );
if ( fi.exists() && fi.isFile() ) if ( fi.exists() && fi.isFile() )
{
descriptor = CalamaresUtils::loadYaml( fi, &ok ); descriptor = CalamaresUtils::loadYaml( fi, &ok );
if ( ok ) break; }
if ( ok )
{
break;
}
} }
} }
@ -154,15 +188,12 @@ load_module( const ModuleConfig& moduleConfig )
} }
QString moduleDirectory = fi.absolutePath(); QString moduleDirectory = fi.absolutePath();
QString configFile( QString configFile( moduleConfig.configFile().isEmpty() ? moduleDirectory + '/' + name + ".conf"
moduleConfig.configFile().isEmpty()
? moduleDirectory + '/' + name + ".conf"
: moduleConfig.configFile() ); : moduleConfig.configFile() );
cDebug() << "Module" << moduleName << "job-configuration:" << configFile; cDebug() << "Module" << moduleName << "job-configuration:" << configFile;
Calamares::Module* module = Calamares::Module::fromDescriptor( Calamares::Module* module = Calamares::Module::fromDescriptor( descriptor, name, configFile, moduleDirectory );
descriptor, name, configFile, moduleDirectory );
return module; return module;
} }
@ -174,14 +205,18 @@ main( int argc, char* argv[] )
ModuleConfig module = handle_args( a ); ModuleConfig module = handle_args( a );
if ( module.moduleName().isEmpty() ) if ( module.moduleName().isEmpty() )
{
return 1; return 1;
}
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 ) );
auto gs = jobqueue_p->globalStorage(); auto gs = jobqueue_p->globalStorage();
if ( !module.globalConfigFile().isEmpty() ) if ( !module.globalConfigFile().isEmpty() )
{
gs->loadYaml( module.globalConfigFile() ); gs->loadYaml( module.globalConfigFile() );
}
if ( !module.language().isEmpty() ) if ( !module.language().isEmpty() )
{ {
QVariantMap vm; QVariantMap vm;
@ -199,7 +234,9 @@ main( int argc, char* argv[] )
} }
if ( !m->isLoaded() ) if ( !m->isLoaded() )
{
m->loadSelf(); m->loadSelf();
}
if ( !m->isLoaded() ) if ( !m->isLoaded() )
{ {
@ -209,9 +246,7 @@ main( int argc, char* argv[] )
using TR = Logger::DebugRow< const char*, const QString >; using TR = Logger::DebugRow< const char*, const QString >;
cDebug() << "Module metadata" cDebug() << "Module metadata" << TR( "name", m->name() ) << TR( "type", m->typeString() )
<< TR( "name", m->name() )
<< TR( "type", m->typeString() )
<< TR( "interface", m->interfaceString() ); << TR( "interface", m->interfaceString() );
cDebug() << "Job outputs:"; cDebug() << "Job outputs:";
@ -224,12 +259,12 @@ main( int argc, char* argv[] )
Calamares::JobResult r = p->exec(); Calamares::JobResult r = p->exec();
if ( !r ) if ( !r )
{ {
cError() << "Job #" << count << "failed" cError() << "Job #" << count << "failed" << TR( "summary", r.message() ) << TR( "details", r.details() );
<< TR( "summary", r.message() )
<< TR( "details", r.details() );
if ( r.errorCode() > 0 ) if ( r.errorCode() > 0 )
{
++failure_count; ++failure_count;
} }
}
++count; ++count;
} }