From 0d507ec2651fcfa98ea4834ed6590350e08a1920 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 8 Jun 2019 17:20:13 +0200 Subject: [PATCH 01/11] [calamares] Tidy up application code - remove commented code, fix logging around it - misplaced include --- src/calamares/CalamaresApplication.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 704cde71c..2593518fa 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -16,7 +16,6 @@ * You should have received a copy of the GNU General Public License * along with Calamares. If not, see . */ -#include #include "CalamaresApplication.h" #include "CalamaresConfig.h" @@ -37,6 +36,7 @@ #include "viewpages/ViewStep.h" #include "ViewManager.h" +#include #include #include @@ -90,16 +90,8 @@ CalamaresApplication::init() CalamaresApplication::~CalamaresApplication() { - cDebug( Logger::LOGVERBOSE ) << "Shutting down Calamares..."; - -// if ( JobQueue::instance() ) -// JobQueue::instance()->stop(); - -// delete m_mainwindow; - -// delete JobQueue::instance(); - - cDebug( Logger::LOGVERBOSE ) << "Finished shutdown."; + cLog( Logger::LOGVERBOSE ) << "Shutting down Calamares..."; + cLog( Logger::LOGVERBOSE ) << Logger::SubEntry << "Finished shutdown."; } From 39675655a0f52f38e27381aabf689d916bb4bd00 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Jun 2019 10:30:19 +0200 Subject: [PATCH 02/11] [calamares] Tidy up include-guard comments --- src/calamares/CalamaresApplication.h | 2 +- src/calamares/CalamaresWindow.h | 2 +- src/calamares/progresstree/ProgressTreeDelegate.h | 2 +- src/calamares/progresstree/ProgressTreeItem.h | 2 +- src/calamares/progresstree/ProgressTreeModel.h | 2 +- src/calamares/progresstree/ProgressTreeView.h | 2 +- src/calamares/progresstree/ViewStepItem.h | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/calamares/CalamaresApplication.h b/src/calamares/CalamaresApplication.h index 9f53726ae..f337c54e5 100644 --- a/src/calamares/CalamaresApplication.h +++ b/src/calamares/CalamaresApplication.h @@ -82,4 +82,4 @@ private: bool m_debugMode; }; -#endif //CALAMARESAPPLICATION_H +#endif // CALAMARESAPPLICATION_H diff --git a/src/calamares/CalamaresWindow.h b/src/calamares/CalamaresWindow.h index faca8974a..310aa3eab 100644 --- a/src/calamares/CalamaresWindow.h +++ b/src/calamares/CalamaresWindow.h @@ -55,4 +55,4 @@ private: Calamares::ViewManager* m_viewManager; }; -#endif //CALAMARESWINDOW_H +#endif // CALAMARESWINDOW_H diff --git a/src/calamares/progresstree/ProgressTreeDelegate.h b/src/calamares/progresstree/ProgressTreeDelegate.h index 83b281696..554824e06 100644 --- a/src/calamares/progresstree/ProgressTreeDelegate.h +++ b/src/calamares/progresstree/ProgressTreeDelegate.h @@ -45,4 +45,4 @@ private: const QModelIndex& index ) const; }; -#endif // PROGRESSTREEDELEGATE_H +#endif // PROGRESSTREEDELEGATE_H diff --git a/src/calamares/progresstree/ProgressTreeItem.h b/src/calamares/progresstree/ProgressTreeItem.h index c7d7fcf05..fd93ab0ef 100644 --- a/src/calamares/progresstree/ProgressTreeItem.h +++ b/src/calamares/progresstree/ProgressTreeItem.h @@ -57,4 +57,4 @@ public: virtual QVariant data( int role ) const; }; -#endif // PROGRESSTREEITEM_H +#endif // PROGRESSTREEITEM_H diff --git a/src/calamares/progresstree/ProgressTreeModel.h b/src/calamares/progresstree/ProgressTreeModel.h index 0e9574516..e424f9d8d 100644 --- a/src/calamares/progresstree/ProgressTreeModel.h +++ b/src/calamares/progresstree/ProgressTreeModel.h @@ -57,4 +57,4 @@ private: ProgressTreeRoot* m_rootItem; }; -#endif // PROGRESSTREEMODEL_H +#endif // PROGRESSTREEMODEL_H diff --git a/src/calamares/progresstree/ProgressTreeView.h b/src/calamares/progresstree/ProgressTreeView.h index 68787984a..0b48a5f2a 100644 --- a/src/calamares/progresstree/ProgressTreeView.h +++ b/src/calamares/progresstree/ProgressTreeView.h @@ -48,4 +48,4 @@ private: ProgressTreeDelegate* m_delegate; }; -#endif // PROGRESSTREEVIEW_H +#endif // PROGRESSTREEVIEW_H diff --git a/src/calamares/progresstree/ViewStepItem.h b/src/calamares/progresstree/ViewStepItem.h index ea473fe5e..5a7c79b4a 100644 --- a/src/calamares/progresstree/ViewStepItem.h +++ b/src/calamares/progresstree/ViewStepItem.h @@ -51,4 +51,4 @@ private: }; -#endif // VIEWSTEPITEM_H +#endif // VIEWSTEPITEM_H From 0a1b27fcfa912ec117dc69c9c72facb5d183022f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Jun 2019 11:18:48 +0200 Subject: [PATCH 03/11] CI: add clang-format as a tool - update the style guide to require braces around blocks - add a clang-format file that is pretty close to the astyle configuration --- .clang-format | 33 +++++++++++++++++++++++++++++++++ ci/HACKING.md | 12 ++++++++---- 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..1eb0867e1 --- /dev/null +++ b/.clang-format @@ -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 + +... diff --git a/ci/HACKING.md b/ci/HACKING.md index f2e6308d1..10d1ac46b 100644 --- a/ci/HACKING.md +++ b/ci/HACKING.md @@ -56,7 +56,7 @@ some PEP8 guidelines. * 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`. * `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. * A function implementation's return type is on its own line. * `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 -[astyle](http://astyle.sf.net) on your code and have it formatted the right -way. +You can use `clang-format` (version 7) to have Calamares sources formatted +the right way. There is a `.clang-format` file that specifies the details. +In general: +``` + $ clang-format-7 -i -style=file +``` +` **NOTE:** An .editorconfig file is included to assist with formatting. In order to take advantage of this functionality you will need to acquire the From 94bea9baaf40cd99f4207d2492f6833ee970260b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Jun 2019 10:45:31 +0200 Subject: [PATCH 04/11] CI: update documentation of debug-levels --- ci/HACKING.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ci/HACKING.md b/ci/HACKING.md index 10d1ac46b..1ffa4db8d 100644 --- a/ci/HACKING.md +++ b/ci/HACKING.md @@ -184,14 +184,18 @@ connect( m_moduleManager, &Calamares::ModuleManager::modulesLoaded, [this] Debugging --------- Use `cDebug()` and `cLog()` from `utils/Logger.h`. You can pass a debug-level to -either macro (1 is debugging, higher is less important). Use `cLog()` for warning -messages. It is recommended to add *WARNING* as the first part of a warning -message. +either macro (6 is debugging, higher is less important). Use `cWarning()` for warning +messages (equivalent to level 2) and `cError()` for errors (level 1). Warnings +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()`, in particular listing things, conventional formatting is as follows: * 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 From 54c3adb466844d8ad81f5bdddaf532369bd00469 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Jun 2019 11:50:36 +0200 Subject: [PATCH 05/11] CI: add brackets to one-line blocks - since we mix Python (indentation is important) with C++ (it isn't), having indented one-line blocks which suddenly need {} when a statment is added is confusing and error-prone. Instead, make the blocks explicit, always, in C++. --- ci/astylerc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/astylerc b/ci/astylerc index 043e81f0f..7fb769a9d 100644 --- a/ci/astylerc +++ b/ci/astylerc @@ -5,7 +5,7 @@ indent=spaces=4 # Brackets style=break -remove-brackets # Remove brackets on single-line `if` and `for` (requires astyle 2.04) +add-brackets # Spaces pad-paren-in From 8053bf6f3a2df7f8f710d163bc26df00f52e1668 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Jun 2019 12:51:33 +0200 Subject: [PATCH 06/11] CI: use both tools for code-formatting - astyle can do some things that clang-format doesn't (e.g. adding brackets; you need clang-tidy for that), - clang-format does a much nicer job with lambdas and certain other constructions, - allow passing in directories at a time for formatting. --- ci/calamaresstyle | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/ci/calamaresstyle b/ci/calamaresstyle index 2bb9b2578..11c587ada 100755 --- a/ci/calamaresstyle +++ b/ci/calamaresstyle @@ -1,6 +1,42 @@ #!/bin/sh +# # 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 -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 From 9235499f7f0c688c379fa0307f8a3a912b278359 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Jun 2019 13:19:53 +0200 Subject: [PATCH 07/11] [calamares] Reformat the progresstree - add { } to single-line blocks - group some includes better - lines broken at a different length, some shuffling around of parameter lists. --- .../progresstree/ProgressTreeDelegate.cpp | 45 +++++++++++-------- .../progresstree/ProgressTreeDelegate.h | 11 ++--- .../progresstree/ProgressTreeItem.cpp | 8 ++-- .../progresstree/ProgressTreeModel.cpp | 44 +++++++++++++++--- .../progresstree/ProgressTreeView.cpp | 25 +++++------ src/calamares/progresstree/ViewStepItem.cpp | 18 ++++---- src/calamares/progresstree/ViewStepItem.h | 3 +- 7 files changed, 94 insertions(+), 60 deletions(-) diff --git a/src/calamares/progresstree/ProgressTreeDelegate.cpp b/src/calamares/progresstree/ProgressTreeDelegate.cpp index 67dfeebda..5fb9dbf8b 100644 --- a/src/calamares/progresstree/ProgressTreeDelegate.cpp +++ b/src/calamares/progresstree/ProgressTreeDelegate.cpp @@ -20,23 +20,28 @@ #include "ProgressTreeDelegate.h" #include "ProgressTreeModel.h" -#include "Branding.h" #include "CalamaresApplication.h" #include "CalamaresWindow.h" +#include "Branding.h" #include "utils/CalamaresUtilsGui.h" #include 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 -ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option, - const QModelIndex& index ) const +ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const { if ( !index.isValid() ) + { return option.rect.size(); + } QFont font = qApp->font(); @@ -51,9 +56,7 @@ ProgressTreeDelegate::sizeHint( const QStyleOptionViewItem& option, void -ProgressTreeDelegate::paint( QPainter* painter, - const QStyleOptionViewItem& option, - const QModelIndex& index) const +ProgressTreeDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { QStyleOptionViewItem opt = option; @@ -62,10 +65,9 @@ ProgressTreeDelegate::paint( QPainter* painter, initStyleOption( &opt, index ); opt.text.clear(); - painter->setBrush( QColor( Calamares::Branding::instance()-> - styleString( Calamares::Branding::SidebarBackground ) ) ); - painter->setPen( QColor( Calamares::Branding::instance()-> - styleString( Calamares::Branding::SidebarText ) ) ); + painter->setBrush( + QColor( Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarBackground ) ) ); + painter->setPen( QColor( Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarText ) ) ); paintViewStep( painter, opt, index ); @@ -89,14 +91,17 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter, if ( isCurrent ) { - painter->setPen( Calamares::Branding::instance()-> - styleString( Calamares::Branding::SidebarTextSelect ) ); - QString textHighlight = Calamares::Branding::instance()-> - styleString( Calamares::Branding::SidebarTextHighlight ); + painter->setPen( Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarTextSelect ) ); + QString textHighlight + = Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarTextHighlight ); if ( textHighlight.isEmpty() ) + { painter->setBrush( CalamaresApplication::instance()->mainWindow()->palette().background() ); + } else + { painter->setBrush( QColor( textHighlight ) ); + } } @@ -114,17 +119,19 @@ ProgressTreeDelegate::paintViewStep( QPainter* painter, shrinkSteps++; 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 // it in the next iteration of the loop anyway. - if ( ( shrinkSteps <= maximumShrink ) && (boundingBox.width() > textRect.width() ) ) + if ( ( shrinkSteps <= maximumShrink ) && ( boundingBox.width() > textRect.width() ) ) { font.setPointSize( item_fontsize() - shrinkSteps ); painter->setFont( font ); } else + { break; // It fits - } - while ( shrinkSteps <= maximumShrink ); + } + } while ( shrinkSteps <= maximumShrink ); } diff --git a/src/calamares/progresstree/ProgressTreeDelegate.h b/src/calamares/progresstree/ProgressTreeDelegate.h index 554824e06..d36bd4d14 100644 --- a/src/calamares/progresstree/ProgressTreeDelegate.h +++ b/src/calamares/progresstree/ProgressTreeDelegate.h @@ -33,16 +33,11 @@ public: using QStyledItemDelegate::QStyledItemDelegate; protected: - QSize sizeHint( const QStyleOptionViewItem& option, - const QModelIndex& index ) const override; - void paint( QPainter* painter, - const QStyleOptionViewItem& option, - const QModelIndex& index ) const override; + QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const override; + void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const override; private: - void paintViewStep( QPainter* painter, - const QStyleOptionViewItem& option, - const QModelIndex& index ) const; + void paintViewStep( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; }; #endif // PROGRESSTREEDELEGATE_H diff --git a/src/calamares/progresstree/ProgressTreeItem.cpp b/src/calamares/progresstree/ProgressTreeItem.cpp index 0445962ab..4c5b5b0c3 100644 --- a/src/calamares/progresstree/ProgressTreeItem.cpp +++ b/src/calamares/progresstree/ProgressTreeItem.cpp @@ -65,8 +65,9 @@ int ProgressTreeItem::row() const { 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; } @@ -80,7 +81,8 @@ ProgressTreeItem::parent() ProgressTreeRoot::ProgressTreeRoot() : ProgressTreeItem() -{} +{ +} QVariant diff --git a/src/calamares/progresstree/ProgressTreeModel.cpp b/src/calamares/progresstree/ProgressTreeModel.cpp index e3b4fa030..d4b5a0321 100644 --- a/src/calamares/progresstree/ProgressTreeModel.cpp +++ b/src/calamares/progresstree/ProgressTreeModel.cpp @@ -19,7 +19,8 @@ #include "ProgressTreeModel.h" -#include "progresstree/ViewStepItem.h" +#include "ViewStepItem.h" + #include "ViewManager.h" ProgressTreeModel::ProgressTreeModel( QObject* parent ) @@ -40,7 +41,9 @@ Qt::ItemFlags ProgressTreeModel::flags( const QModelIndex& index ) const { if ( !index.isValid() ) + { return Qt::ItemFlags(); + } return Qt::ItemIsEnabled; } @@ -50,20 +53,30 @@ QModelIndex ProgressTreeModel::index( int row, int column, const QModelIndex& parent ) const { if ( !hasIndex( row, column, parent ) ) + { return QModelIndex(); + } ProgressTreeItem* parentItem; if ( !parent.isValid() ) + { parentItem = m_rootItem; + } else + { parentItem = static_cast< ProgressTreeItem* >( parent.internalPointer() ); + } ProgressTreeItem* childItem = parentItem->child( row ); if ( childItem ) + { return createIndex( row, column, childItem ); + } else + { return QModelIndex(); + } } @@ -71,13 +84,17 @@ QModelIndex ProgressTreeModel::parent( const QModelIndex& index ) const { if ( !index.isValid() ) + { return QModelIndex(); + } ProgressTreeItem* childItem = static_cast< ProgressTreeItem* >( index.internalPointer() ); ProgressTreeItem* parentItem = childItem->parent(); if ( parentItem == m_rootItem ) + { return QModelIndex(); + } return createIndex( parentItem->row(), 0, parentItem ); } @@ -87,7 +104,9 @@ QVariant ProgressTreeModel::data( const QModelIndex& index, int role ) const { if ( !index.isValid() ) + { return QVariant(); + } ProgressTreeItem* item = static_cast< ProgressTreeItem* >( index.internalPointer() ); @@ -111,12 +130,18 @@ ProgressTreeModel::rowCount( const QModelIndex& parent ) const { ProgressTreeItem* parentItem; if ( parent.column() > 0 ) + { return 0; + } if ( !parent.isValid() ) + { parentItem = m_rootItem; + } else + { parentItem = static_cast< ProgressTreeItem* >( parent.internalPointer() ); + } return parentItem->childCount(); } @@ -126,9 +151,13 @@ int ProgressTreeModel::columnCount( const QModelIndex& parent ) const { if ( parent.isValid() ) + { return static_cast< ProgressTreeItem* >( parent.internalPointer() )->columnCount(); + } else + { return m_rootItem->columnCount(); + } } @@ -152,7 +181,9 @@ QModelIndex ProgressTreeModel::indexFromItem( ProgressTreeItem* item ) { if ( !item || !item->parent() ) + { return QModelIndex(); + } // 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 @@ -172,10 +203,13 @@ ProgressTreeModel::indexFromItem( ProgressTreeItem* item ) **/ QList< int > childIndexList; ProgressTreeItem* curItem = item; - while ( curItem != m_rootItem ) { - int row = curItem->row(); //relative to its parent - if ( row < 0 ) // something went wrong, bail + while ( curItem != m_rootItem ) + { + int row = curItem->row(); //relative to its parent + if ( row < 0 ) // something went wrong, bail + { return QModelIndex(); + } childIndexList << row; @@ -184,7 +218,7 @@ ProgressTreeModel::indexFromItem( ProgressTreeItem* item ) // Now we rebuild the QModelIndex we need QModelIndex idx; - for ( int i = childIndexList.size() - 1; i >= 0 ; i-- ) + for ( int i = childIndexList.size() - 1; i >= 0; i-- ) { idx = index( childIndexList[ i ], 0, idx ); } diff --git a/src/calamares/progresstree/ProgressTreeView.cpp b/src/calamares/progresstree/ProgressTreeView.cpp index 079592848..5c81e3851 100644 --- a/src/calamares/progresstree/ProgressTreeView.cpp +++ b/src/calamares/progresstree/ProgressTreeView.cpp @@ -19,8 +19,9 @@ #include "ProgressTreeView.h" #include "ProgressTreeDelegate.h" -#include "ViewManager.h" + #include "Branding.h" +#include "ViewManager.h" ProgressTreeView* ProgressTreeView::s_instance = nullptr; @@ -33,9 +34,9 @@ ProgressTreeView::instance() ProgressTreeView::ProgressTreeView( QWidget* parent ) : QTreeView( parent ) { - s_instance = this; //FIXME: should assert when s_instance gets written and it wasn't nullptr + s_instance = this; //FIXME: should assert when s_instance gets written and it wasn't nullptr - this->setObjectName("sidebarMenuApp"); + this->setObjectName( "sidebarMenuApp" ); setFrameShape( QFrame::NoFrame ); setContentsMargins( 0, 0, 0, 0 ); @@ -55,31 +56,29 @@ ProgressTreeView::ProgressTreeView( QWidget* parent ) setItemDelegate( m_delegate ); QPalette plt = palette(); - plt.setColor( QPalette::Base, Calamares::Branding::instance()-> - styleString( Calamares::Branding::SidebarBackground ) ); + plt.setColor( QPalette::Base, + Calamares::Branding::instance()->styleString( Calamares::Branding::SidebarBackground ) ); setPalette( plt ); } -ProgressTreeView::~ProgressTreeView() -{ -} +ProgressTreeView::~ProgressTreeView() {} void ProgressTreeView::setModel( QAbstractItemModel* model ) { if ( ProgressTreeView::model() ) + { return; + } QTreeView::setModel( model ); expandAll(); connect( Calamares::ViewManager::instance(), &Calamares::ViewManager::currentStepChanged, - this, [this]() - { - viewport()->update(); - }, - Qt::UniqueConnection ); + this, + [this]() { viewport()->update(); }, + Qt::UniqueConnection ); } diff --git a/src/calamares/progresstree/ViewStepItem.cpp b/src/calamares/progresstree/ViewStepItem.cpp index fe2fe6034..5af73fcfd 100644 --- a/src/calamares/progresstree/ViewStepItem.cpp +++ b/src/calamares/progresstree/ViewStepItem.cpp @@ -19,6 +19,7 @@ #include "ViewStepItem.h" #include "ProgressTreeModel.h" + #include "Settings.h" #include "ViewManager.h" #include "viewpages/ViewStep.h" @@ -35,8 +36,7 @@ ViewStepItem::ViewStepItem( std::function< QString() > prettyName, } -ViewStepItem::ViewStepItem( const Calamares::ViewStep* step, - ProgressTreeItem* parent ) +ViewStepItem::ViewStepItem( const Calamares::ViewStep* step, ProgressTreeItem* parent ) : ProgressTreeItem( parent ) { m_step = step; @@ -55,8 +55,7 @@ ViewStepItem::data( int role ) const { if ( role == Qt::DisplayRole ) { - return m_step ? m_step->prettyName() - : m_prettyName(); + return m_step ? m_step->prettyName() : m_prettyName(); } if ( Calamares::Settings::instance()->debugMode() && role == Qt::ToolTipRole ) { @@ -66,9 +65,9 @@ ViewStepItem::data( int role ) const toolTip.append( "
Type:\tViewStep" ); toolTip.append( QString( "
Pretty:\t%1" ).arg( m_step->prettyName() ) ); toolTip.append( QString( "
Status:\t%1" ).arg( m_step->prettyStatus() ) ); - toolTip.append( QString( "
Source:\t%1" ).arg( - m_step->moduleInstanceKey().isEmpty() ? "built-in" - : m_step->moduleInstanceKey() ) ); + toolTip.append( + QString( "
Source:\t%1" ) + .arg( m_step->moduleInstanceKey().isEmpty() ? "built-in" : m_step->moduleInstanceKey() ) ); } else { @@ -78,8 +77,7 @@ ViewStepItem::data( int role ) const return toolTip; } if ( role == ProgressTreeModel::ProgressTreeItemCurrentRole ) - return m_step ? - ( Calamares::ViewManager::instance()->currentStep() == m_step ) : - ( Calamares::ViewManager::instance()->currentStep() == m_accessor() ); + return m_step ? ( Calamares::ViewManager::instance()->currentStep() == m_step ) + : ( Calamares::ViewManager::instance()->currentStep() == m_accessor() ); return QVariant(); } diff --git a/src/calamares/progresstree/ViewStepItem.h b/src/calamares/progresstree/ViewStepItem.h index 5a7c79b4a..3095ef43b 100644 --- a/src/calamares/progresstree/ViewStepItem.h +++ b/src/calamares/progresstree/ViewStepItem.h @@ -37,8 +37,7 @@ public: std::function< const Calamares::ViewStep*() > accessor, ProgressTreeItem* parent = nullptr ); - explicit ViewStepItem( const Calamares::ViewStep* step, - ProgressTreeItem* parent = nullptr ); + explicit ViewStepItem( const Calamares::ViewStep* step, ProgressTreeItem* parent = nullptr ); void appendChild( ProgressTreeItem* item ) override; From a6d7fcdadf914579edde145f7cbcfefb99f88ef5 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Jun 2019 13:33:42 +0200 Subject: [PATCH 08/11] [calamares] Reformat the rest of the application --- src/calamares/CalamaresApplication.cpp | 83 +++++++++++++-------- src/calamares/CalamaresApplication.h | 2 +- src/calamares/CalamaresWindow.cpp | 58 ++++++++------- src/calamares/CalamaresWindow.h | 4 +- src/calamares/main.cpp | 32 ++++++--- src/calamares/testmain.cpp | 99 +++++++++++++++++--------- 6 files changed, 179 insertions(+), 99 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 2593518fa..0f9a8a208 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -19,22 +19,22 @@ #include "CalamaresApplication.h" #include "CalamaresConfig.h" -#include "CalamaresWindow.h" #include "CalamaresVersion.h" -#include "progresstree/ProgressTreeView.h" +#include "CalamaresWindow.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 "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsSystem.h" #include "utils/Dirs.h" #include "utils/Logger.h" #include "utils/Retranslator.h" -#include "JobQueue.h" -#include "Branding.h" -#include "Settings.h" #include "viewpages/ViewStep.h" -#include "ViewManager.h" #include #include @@ -77,12 +77,11 @@ CalamaresApplication::init() initSettings(); initBranding(); - setWindowIcon( QIcon( Calamares::Branding::instance()-> - imagePath( Calamares::Branding::ProductIcon ) ) ); + setWindowIcon( QIcon( Calamares::Branding::instance()->imagePath( Calamares::Branding::ProductIcon ) ) ); cDebug() << "STARTUP: initQmlPath, initSettings, initBranding done"; - initModuleManager(); //also shows main window + initModuleManager(); //also shows main window cDebug() << "STARTUP: initModuleManager: module init started"; } @@ -130,14 +129,20 @@ qmlDirCandidates( bool assumeBuilddir ) QStringList qmlDirs; if ( CalamaresUtils::isAppDataDirOverridden() ) + { qmlDirs << CalamaresUtils::appDataDir().absoluteFilePath( QML ); + } else { if ( assumeBuilddir ) + { qmlDirs << QDir::current().absoluteFilePath( "src/qml" ); // In build-dir + } if ( CalamaresUtils::haveExtraDirs() ) for ( auto s : CalamaresUtils::extraDataDirs() ) + { qmlDirs << ( s + QML ); + } qmlDirs << CalamaresUtils::appDataDir().absoluteFilePath( QML ); } @@ -152,14 +157,20 @@ settingsFileCandidates( bool assumeBuilddir ) QStringList settingsPaths; if ( CalamaresUtils::isAppDataDirOverridden() ) + { settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings ); + } else { if ( assumeBuilddir ) + { settingsPaths << QDir::current().absoluteFilePath( settings ); + } if ( CalamaresUtils::haveExtraDirs() ) for ( auto s : CalamaresUtils::extraConfigDirs() ) + { settingsPaths << ( s + settings ); + } settingsPaths << CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/settings.conf"; // String concat settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings ); } @@ -173,16 +184,22 @@ brandingFileCandidates( bool assumeBuilddir, const QString& brandingFilename ) { QStringList brandingPaths; if ( CalamaresUtils::isAppDataDirOverridden() ) + { brandingPaths << CalamaresUtils::appDataDir().absoluteFilePath( brandingFilename ); + } else { if ( assumeBuilddir ) + { brandingPaths << ( QDir::currentPath() + QStringLiteral( "/src/" ) + brandingFilename ); + } if ( CalamaresUtils::haveExtraDirs() ) for ( auto s : CalamaresUtils::extraDataDirs() ) + { brandingPaths << ( s + brandingFilename ); + } brandingPaths << QDir( CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/" ).absoluteFilePath( brandingFilename ); - brandingPaths << CalamaresUtils::appDataDir().absoluteFilePath( brandingFilename); + brandingPaths << CalamaresUtils::appDataDir().absoluteFilePath( brandingFilename ); } return brandingPaths; @@ -210,11 +227,15 @@ CalamaresApplication::initQmlPath() if ( !found || !importPath.exists() || !importPath.isReadable() ) { cError() << "Cowardly refusing to continue startup without a QML directory." - << Logger::DebugList( qmlDirCandidatesByPriority ); + << Logger::DebugList( qmlDirCandidatesByPriority ); if ( CalamaresUtils::isAppDataDirOverridden() ) + { cError() << "FATAL: explicitly configured application data directory is missing qml/"; + } else + { cError() << "FATAL: none of the expected QML paths exist."; + } ::exit( EXIT_FAILURE ); } @@ -245,11 +266,15 @@ CalamaresApplication::initSettings() if ( !found || !settingsFile.exists() || !settingsFile.isReadable() ) { cError() << "Cowardly refusing to continue startup without settings." - << Logger::DebugList( settingsFileCandidatesByPriority ); + << Logger::DebugList( settingsFileCandidatesByPriority ); if ( CalamaresUtils::isAppDataDirOverridden() ) + { cError() << "FATAL: explicitly configured application data directory is missing settings.conf"; + } else + { cError() << "FATAL: none of the expected configuration file paths exist."; + } ::exit( EXIT_FAILURE ); } @@ -273,7 +298,7 @@ CalamaresApplication::initBranding() } QString brandingDescriptorSubpath = QString( "branding/%1/branding.desc" ).arg( brandingComponentName ); - QStringList brandingFileCandidatesByPriority = brandingFileCandidates( isDebug(), brandingDescriptorSubpath); + QStringList brandingFileCandidatesByPriority = brandingFileCandidates( isDebug(), brandingDescriptorSubpath ); QFileInfo brandingFile; bool found = false; @@ -292,11 +317,15 @@ CalamaresApplication::initBranding() if ( !found || !brandingFile.exists() || !brandingFile.isReadable() ) { cError() << "Cowardly refusing to continue startup without branding." - << Logger::DebugList( brandingFileCandidatesByPriority ); + << Logger::DebugList( brandingFileCandidatesByPriority ); if ( CalamaresUtils::isAppDataDirOverridden() ) + { cError() << "FATAL: explicitly configured application data directory is missing" << brandingComponentName; + } else + { cError() << "FATAL: none of the expected branding descriptor file paths exist."; + } ::exit( EXIT_FAILURE ); } @@ -307,10 +336,8 @@ CalamaresApplication::initBranding() void CalamaresApplication::initModuleManager() { - m_moduleManager = new Calamares::ModuleManager( - Calamares::Settings::instance()->modulesSearchPaths(), this ); - connect( m_moduleManager, &Calamares::ModuleManager::initDone, - this, &CalamaresApplication::initView ); + m_moduleManager = new Calamares::ModuleManager( Calamares::Settings::instance()->modulesSearchPaths(), this ); + connect( m_moduleManager, &Calamares::ModuleManager::initDone, this, &CalamaresApplication::initView ); m_moduleManager->init(); } @@ -322,18 +349,14 @@ CalamaresApplication::initView() initJobQueue(); cDebug() << "STARTUP: initJobQueue done"; - m_mainwindow = new CalamaresWindow(); //also creates ViewManager + m_mainwindow = new CalamaresWindow(); //also creates ViewManager - connect( m_moduleManager, &Calamares::ModuleManager::modulesLoaded, - this, &CalamaresApplication::initViewSteps ); - connect( m_moduleManager, &Calamares::ModuleManager::modulesFailed, - this, &CalamaresApplication::initFailed ); + connect( m_moduleManager, &Calamares::ModuleManager::modulesLoaded, this, &CalamaresApplication::initViewSteps ); + connect( m_moduleManager, &Calamares::ModuleManager::modulesFailed, this, &CalamaresApplication::initFailed ); m_moduleManager->loadModules(); - m_mainwindow->move( - this->desktop()->availableGeometry().center() - - m_mainwindow->rect().center() ); + m_mainwindow->move( this->desktop()->availableGeometry().center() - m_mainwindow->rect().center() ); cDebug() << "STARTUP: CalamaresWindow created; loadModules started"; } @@ -350,7 +373,9 @@ CalamaresApplication::initViewSteps() m_mainwindow->showMaximized(); } else + { m_mainwindow->show(); + } ProgressTreeModel* m = new ProgressTreeModel( nullptr ); ProgressTreeView::instance()->setModel( m ); @@ -360,11 +385,13 @@ CalamaresApplication::initViewSteps() cDebug() << Logger::SubEntry << steps.count() << "view steps loaded."; // Tell the first view that it's been shown. if ( steps.count() > 0 ) - steps[0]->onActivate(); + { + steps[ 0 ]->onActivate(); + } } void -CalamaresApplication::initFailed(const QStringList& l) +CalamaresApplication::initFailed( const QStringList& l ) { cError() << "STARTUP: failed modules are" << l; m_mainwindow->show(); diff --git a/src/calamares/CalamaresApplication.h b/src/calamares/CalamaresApplication.h index f337c54e5..634f4cdb2 100644 --- a/src/calamares/CalamaresApplication.h +++ b/src/calamares/CalamaresApplication.h @@ -82,4 +82,4 @@ private: bool m_debugMode; }; -#endif // CALAMARESAPPLICATION_H +#endif // CALAMARESAPPLICATION_H diff --git a/src/calamares/CalamaresWindow.cpp b/src/calamares/CalamaresWindow.cpp index 626b8588c..d80b6cb67 100644 --- a/src/calamares/CalamaresWindow.cpp +++ b/src/calamares/CalamaresWindow.cpp @@ -21,33 +21,39 @@ #include "CalamaresWindow.h" +#include "Branding.h" +#include "Settings.h" #include "ViewManager.h" #include "progresstree/ProgressTreeView.h" #include "utils/CalamaresUtilsGui.h" -#include "utils/Logger.h" #include "utils/DebugWindow.h" +#include "utils/Logger.h" #include "utils/Retranslator.h" -#include "Settings.h" -#include "Branding.h" #include #include #include #include -#include -#include #include #include +#include +#include static inline int windowDimensionToPixels( const Calamares::Branding::WindowDimension& u ) { if ( !u.isValid() ) + { return 0; + } if ( u.unit() == Calamares::Branding::WindowDimensionUnit::Pixies ) + { return u.value(); + } if ( u.unit() == Calamares::Branding::WindowDimensionUnit::Fonties ) + { return u.value() * CalamaresUtils::defaultFontHeight(); + } return 0; } @@ -58,14 +64,13 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) { // If we can never cancel, don't show the window-close button if ( Calamares::Settings::instance()->disableCancel() ) + { setWindowFlag( Qt::WindowCloseButtonHint, false ); + } - CALAMARES_RETRANSLATE( - setWindowTitle( Calamares::Settings::instance()->isSetupMode() - ? tr( "%1 Setup Program" ).arg( *Calamares::Branding::ProductName ) - : tr( "%1 Installer" ).arg( *Calamares::Branding::ProductName ) - ); - ) + CALAMARES_RETRANSLATE( setWindowTitle( Calamares::Settings::instance()->isSetupMode() + ? tr( "%1 Setup Program" ).arg( *Calamares::Branding::ProductName ) + : tr( "%1 Installer" ).arg( *Calamares::Branding::ProductName ) ); ) const Calamares::Branding* const branding = Calamares::Branding::instance(); @@ -75,7 +80,7 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) using CalamaresUtils::windowPreferredWidth; // Needs to match what's checked in DebugWindow - this->setObjectName("mainApp"); + this->setObjectName( "mainApp" ); QSize availableSize = qApp->desktop()->availableGeometry( this ).size(); QSize minimumSize( qBound( windowMinimumWidth, availableSize.width(), windowPreferredWidth ), @@ -87,7 +92,7 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) auto brandingSizes = branding->windowSize(); int w = qBound( minimumSize.width(), windowDimensionToPixels( brandingSizes.first ), availableSize.width() ); - int h = qBound( minimumSize.height(), windowDimensionToPixels( brandingSizes.second ), availableSize.height() ); + int h = qBound( minimumSize.height(), windowDimensionToPixels( brandingSizes.second ), availableSize.height() ); cDebug() << Logger::SubEntry << "Proposed window size:" << w << h; resize( w, h ); @@ -96,25 +101,26 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) setLayout( mainLayout ); QWidget* sideBox = new QWidget( this ); - sideBox->setObjectName("sidebarApp"); + sideBox->setObjectName( "sidebarApp" ); mainLayout->addWidget( sideBox ); QBoxLayout* sideLayout = new QVBoxLayout; sideBox->setLayout( sideLayout ); // 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 ); QHBoxLayout* logoLayout = new QHBoxLayout; sideLayout->addLayout( logoLayout ); logoLayout->addStretch(); QLabel* logoLabel = new QLabel( sideBox ); - logoLabel->setObjectName("logoApp"); + logoLabel->setObjectName( "logoApp" ); //Define all values into qss file { QPalette plt = sideBox->palette(); sideBox->setAutoFillBackground( true ); - plt.setColor( sideBox->backgroundRole(),branding->styleString( Calamares::Branding::SidebarBackground ) ); + plt.setColor( sideBox->backgroundRole(), branding->styleString( Calamares::Branding::SidebarBackground ) ); plt.setColor( sideBox->foregroundRole(), branding->styleString( Calamares::Branding::SidebarText ) ); sideBox->setPalette( plt ); logoLabel->setPalette( plt ); @@ -133,22 +139,16 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) { QPushButton* debugWindowBtn = new QPushButton; debugWindowBtn->setObjectName( "debugButton" ); - CALAMARES_RETRANSLATE( - debugWindowBtn->setText( tr( "Show debug information" ) ); - ) + CALAMARES_RETRANSLATE( debugWindowBtn->setText( tr( "Show debug information" ) ); ) sideLayout->addWidget( debugWindowBtn ); debugWindowBtn->setFlat( true ); debugWindowBtn->setCheckable( true ); - connect( debugWindowBtn, &QPushButton::clicked, - this, [ = ]( bool checked ) - { + connect( debugWindowBtn, &QPushButton::clicked, this, [=]( bool checked ) { if ( checked ) { m_debugWindow = new Calamares::DebugWindow(); m_debugWindow->show(); - connect( m_debugWindow.data(), &Calamares::DebugWindow::closed, - this, [ = ]() - { + connect( m_debugWindow.data(), &Calamares::DebugWindow::closed, this, [=]() { m_debugWindow->deleteLater(); debugWindowBtn->setChecked( false ); } ); @@ -156,7 +156,9 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) else { if ( m_debugWindow ) + { m_debugWindow->deleteLater(); + } } } ); } @@ -166,7 +168,9 @@ CalamaresWindow::CalamaresWindow( QWidget* parent ) m_viewManager = Calamares::ViewManager::instance( this ); if ( branding->windowExpands() ) + { connect( m_viewManager, &Calamares::ViewManager::enlarge, this, &CalamaresWindow::enlarge ); + } // NOTE: Although the ViewManager has a signal cancelEnabled() that // signals when the state of the cancel button changes (in // particular, to disable cancel during the exec phase), @@ -201,5 +205,7 @@ CalamaresWindow::closeEvent( QCloseEvent* event ) qApp->quit(); } else + { event->ignore(); + } } diff --git a/src/calamares/CalamaresWindow.h b/src/calamares/CalamaresWindow.h index 310aa3eab..03ae560ec 100644 --- a/src/calamares/CalamaresWindow.h +++ b/src/calamares/CalamaresWindow.h @@ -27,7 +27,7 @@ namespace Calamares { class DebugWindow; class ViewManager; -} +} // namespace Calamares /** * @brief The CalamaresWindow class represents the main window of the Calamares UI. @@ -55,4 +55,4 @@ private: Calamares::ViewManager* m_viewManager; }; -#endif // CALAMARESWINDOW_H +#endif // CALAMARESWINDOW_H diff --git a/src/calamares/main.cpp b/src/calamares/main.cpp index f218b8ab9..d463b789d 100644 --- a/src/calamares/main.cpp +++ b/src/calamares/main.cpp @@ -24,11 +24,10 @@ #include "kdsingleapplicationguard/kdsingleapplicationguard.h" #include "utils/Dirs.h" #include "utils/Logger.h" -#include "CalamaresConfig.h" #ifdef WITH_KF5Crash -#include #include +#include #endif #include @@ -38,14 +37,13 @@ static void handle_args( CalamaresApplication& a ) { - QCommandLineOption debugOption( QStringList{ "d", "debug"}, + QCommandLineOption debugOption( QStringList { "d", "debug" }, "Also look in current directory for configuration. Implies -D8." ); - QCommandLineOption debugLevelOption( QStringLiteral("D"), - "Verbose output for debugging purposes (0-8).", "level" ); - QCommandLineOption configOption( QStringList{ "c", "config"}, - "Configuration directory to use, for testing purposes.", "config" ); - QCommandLineOption xdgOption( QStringList{"X", "xdg-config"}, - "Use XDG_{CONFIG,DATA}_DIRS as well." ); + QCommandLineOption debugLevelOption( + QStringLiteral( "D" ), "Verbose output for debugging purposes (0-8).", "level" ); + QCommandLineOption configOption( + QStringList { "c", "config" }, "Configuration directory to use, for testing purposes.", "config" ); + QCommandLineOption xdgOption( QStringList { "X", "xdg-config" }, "Use XDG_{CONFIG,DATA}_DIRS as well." ); QCommandLineParser parser; parser.setApplicationDescription( "Distribution-independent installer framework" ); @@ -61,22 +59,32 @@ handle_args( CalamaresApplication& a ) a.setDebug( parser.isSet( debugOption ) ); if ( parser.isSet( debugOption ) ) + { Logger::setupLogLevel( Logger::LOGVERBOSE ); + } else if ( parser.isSet( debugLevelOption ) ) { bool ok = true; int l = parser.value( debugLevelOption ).toInt( &ok ); unsigned int dlevel = 0; if ( !ok || ( l < 0 ) ) + { dlevel = Logger::LOGVERBOSE; + } else - dlevel = static_cast( l ); // l >= 0 + { + dlevel = static_cast< unsigned int >( l ); // l >= 0 + } Logger::setupLogLevel( dlevel ); } if ( parser.isSet( configOption ) ) + { CalamaresUtils::setAppDataDir( QDir( parser.value( configOption ) ) ); + } if ( parser.isSet( xdgOption ) ) + { CalamaresUtils::setXdgDirs(); + } } int @@ -118,9 +126,13 @@ main( int argc, char* argv[] ) auto instancelist = guard.instances(); qDebug() << "Calamares is already running, shutting down."; if ( instancelist.count() > 0 ) + { qDebug() << "Other running Calamares instances:"; + } for ( const auto& i : instancelist ) + { qDebug() << " " << i.isValid() << i.pid() << i.arguments(); + } } return returnCode; diff --git a/src/calamares/testmain.cpp b/src/calamares/testmain.cpp index 11ea9eaca..0f07e6e13 100644 --- a/src/calamares/testmain.cpp +++ b/src/calamares/testmain.cpp @@ -22,9 +22,9 @@ * bindings. */ +#include "modulesystem/Module.h" #include "utils/Logger.h" #include "utils/Yaml.h" -#include "modulesystem/Module.h" #include "GlobalStorage.h" #include "Job.h" @@ -40,28 +40,47 @@ struct ModuleConfig { - QString moduleName() const { return m_module; } - QString configFile() const { return m_jobConfig; } - QString language() const { return m_language; } - QString globalConfigFile() const { return m_globalConfig; } + QString + moduleName() const + { + 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_jobConfig; QString m_globalConfig; QString m_language; -} ; +}; static ModuleConfig handle_args( QCoreApplication& a ) { - QCommandLineOption debugLevelOption( QStringLiteral("D"), - "Verbose output for debugging purposes (0-8).", "level" ); - QCommandLineOption globalOption( QStringList() << QStringLiteral( "g" ) << QStringLiteral( "global "), - QStringLiteral( "Global settings document" ), "global.yaml" ); - QCommandLineOption jobOption( QStringList() << QStringLiteral( "j" ) << QStringLiteral( "job"), - QStringLiteral( "Job settings document" ), "job.yaml" ); + QCommandLineOption debugLevelOption( + QStringLiteral( "D" ), "Verbose output for debugging purposes (0-8).", "level" ); + QCommandLineOption globalOption( QStringList() << QStringLiteral( "g" ) << QStringLiteral( "global " ), + QStringLiteral( "Global settings document" ), + "global.yaml" ); + QCommandLineOption jobOption( QStringList() << QStringLiteral( "j" ) << QStringLiteral( "job" ), + QStringLiteral( "Job settings document" ), + "job.yaml" ); QCommandLineOption langOption( QStringList() << QStringLiteral( "l" ) << QStringLiteral( "language" ), - QStringLiteral( "Language (global)" ), "languagecode" ); + QStringLiteral( "Language (global)" ), + "languagecode" ); QCommandLineParser parser; parser.setApplicationDescription( "Calamares module tester" ); @@ -73,7 +92,7 @@ handle_args( QCoreApplication& a ) parser.addOption( jobOption ); parser.addOption( langOption ); parser.addPositionalArgument( "module", "Path or name of module to run." ); - parser.addPositionalArgument( "job.yaml", "Path of job settings document to use.", "[job.yaml]"); + parser.addPositionalArgument( "job.yaml", "Path of job settings document to use.", "[job.yaml]" ); parser.process( a ); @@ -83,9 +102,13 @@ handle_args( QCoreApplication& a ) unsigned int l = parser.value( debugLevelOption ).toUInt( &ok ); unsigned int dlevel = 0; if ( !ok ) + { dlevel = Logger::LOGVERBOSE; + } else + { dlevel = l; + } Logger::setupLogLevel( dlevel ); } @@ -104,9 +127,11 @@ handle_args( QCoreApplication& a ) { QString jobSettings( parser.value( jobOption ) ); 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 ) }; } } @@ -120,14 +145,18 @@ load_module( const ModuleConfig& moduleConfig ) bool ok = false; QVariantMap descriptor; - for ( const QString& prefix : QStringList{ "./", "src/modules/", "modules/" } ) + for ( const QString& prefix : QStringList { "./", "src/modules/", "modules/" } ) { // Could be a complete path, eg. src/modules/dummycpp/module.desc fi = QFileInfo( prefix + moduleName ); if ( fi.exists() && fi.isFile() ) + { descriptor = CalamaresUtils::loadYaml( fi, &ok ); + } if ( ok ) + { break; + } // Could be a path without module.desc fi = QFileInfo( prefix + moduleName ); @@ -135,8 +164,13 @@ load_module( const ModuleConfig& moduleConfig ) { fi = QFileInfo( prefix + moduleName + "/module.desc" ); if ( fi.exists() && fi.isFile() ) + { 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 configFile( - moduleConfig.configFile().isEmpty() - ? moduleDirectory + '/' + name + ".conf" - : moduleConfig.configFile() ); + QString configFile( moduleConfig.configFile().isEmpty() ? moduleDirectory + '/' + name + ".conf" + : moduleConfig.configFile() ); cDebug() << "Module" << moduleName << "job-configuration:" << configFile; - Calamares::Module* module = Calamares::Module::fromDescriptor( - descriptor, name, configFile, moduleDirectory ); + Calamares::Module* module = Calamares::Module::fromDescriptor( descriptor, name, configFile, moduleDirectory ); return module; } @@ -174,14 +205,18 @@ main( int argc, char* argv[] ) ModuleConfig module = handle_args( a ); if ( module.moduleName().isEmpty() ) + { return 1; + } std::unique_ptr< Calamares::Settings > settings_p( new Calamares::Settings( QString(), true ) ); std::unique_ptr< Calamares::JobQueue > jobqueue_p( new Calamares::JobQueue( nullptr ) ); auto gs = jobqueue_p->globalStorage(); if ( !module.globalConfigFile().isEmpty() ) + { gs->loadYaml( module.globalConfigFile() ); + } if ( !module.language().isEmpty() ) { QVariantMap vm; @@ -199,7 +234,9 @@ main( int argc, char* argv[] ) } if ( !m->isLoaded() ) + { m->loadSelf(); + } if ( !m->isLoaded() ) { @@ -207,12 +244,10 @@ main( int argc, char* argv[] ) return 1; } - using TR = Logger::DebugRow; + using TR = Logger::DebugRow< const char*, const QString >; - cDebug() << "Module metadata" - << TR( "name", m->name() ) - << TR( "type", m->typeString() ) - << TR( "interface", m->interfaceString() ); + cDebug() << "Module metadata" << TR( "name", m->name() ) << TR( "type", m->typeString() ) + << TR( "interface", m->interfaceString() ); cDebug() << "Job outputs:"; Calamares::JobList jobList = m->jobs(); @@ -224,11 +259,11 @@ main( int argc, char* argv[] ) Calamares::JobResult r = p->exec(); if ( !r ) { - cError() << "Job #" << count << "failed" - << TR( "summary", r.message() ) - << TR( "details", r.details() ); + cError() << "Job #" << count << "failed" << TR( "summary", r.message() ) << TR( "details", r.details() ); if ( r.errorCode() > 0 ) + { ++failure_count; + } } ++count; } From 85845c9b3eb7e448954f08a26c6f8f1850e0de50 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Jun 2019 08:32:28 +0200 Subject: [PATCH 09/11] [calamares] cLog() isn't a thing, return to cDebug() --- src/calamares/CalamaresApplication.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 0f9a8a208..755808f5f 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -89,8 +89,8 @@ CalamaresApplication::init() CalamaresApplication::~CalamaresApplication() { - cLog( Logger::LOGVERBOSE ) << "Shutting down Calamares..."; - cLog( Logger::LOGVERBOSE ) << Logger::SubEntry << "Finished shutdown."; + cDebug( Logger::LOGVERBOSE ) << "Shutting down Calamares..."; + cDebug( Logger::LOGVERBOSE ) << Logger::SubEntry << "Finished shutdown."; } From 5dfc4884b3b038895bf1cb8ce908bb233c44b48f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Jun 2019 12:45:47 +0200 Subject: [PATCH 10/11] [calamares] Increase constness - The model shouldn't change items at all. --- src/calamares/progresstree/ViewStepItem.cpp | 6 +++--- src/calamares/progresstree/ViewStepItem.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/calamares/progresstree/ViewStepItem.cpp b/src/calamares/progresstree/ViewStepItem.cpp index 5af73fcfd..27e56ef55 100644 --- a/src/calamares/progresstree/ViewStepItem.cpp +++ b/src/calamares/progresstree/ViewStepItem.cpp @@ -29,17 +29,17 @@ ViewStepItem::ViewStepItem( std::function< QString() > prettyName, std::function< const Calamares::ViewStep*() > accessor, ProgressTreeItem* parent ) : ProgressTreeItem( parent ) + , m_accessor( accessor ) + , m_prettyName( prettyName ) , m_step( nullptr ) { - m_prettyName = prettyName; - m_accessor = accessor; } ViewStepItem::ViewStepItem( const Calamares::ViewStep* step, ProgressTreeItem* parent ) : ProgressTreeItem( parent ) + , m_step( step ) { - m_step = step; } void diff --git a/src/calamares/progresstree/ViewStepItem.h b/src/calamares/progresstree/ViewStepItem.h index 3095ef43b..84b9e0e98 100644 --- a/src/calamares/progresstree/ViewStepItem.h +++ b/src/calamares/progresstree/ViewStepItem.h @@ -44,9 +44,9 @@ public: QVariant data( int role ) const override; private: - std::function< const Calamares::ViewStep*() > m_accessor; - std::function< QString() > m_prettyName; - const Calamares::ViewStep* m_step; + const std::function< const Calamares::ViewStep*() > m_accessor; + const std::function< QString() > m_prettyName; + const Calamares::ViewStep* const m_step; }; From 3b146d47d07f3ea48646988c2803f7c4ae84b03d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Jun 2019 11:06:44 +0200 Subject: [PATCH 11/11] CI: Remove mention of cLog from documentation --- ci/HACKING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/HACKING.md b/ci/HACKING.md index 1ffa4db8d..02eb8fd17 100644 --- a/ci/HACKING.md +++ b/ci/HACKING.md @@ -183,8 +183,8 @@ connect( m_moduleManager, &Calamares::ModuleManager::modulesLoaded, [this] Debugging --------- -Use `cDebug()` and `cLog()` from `utils/Logger.h`. You can pass a debug-level to -either macro (6 is debugging, higher is less important). Use `cWarning()` for warning +Use `cDebug()` from `utils/Logger.h`. You can pass a debug-level to the +macro (6 is debugging, higher is less important). Use `cWarning()` for warning messages (equivalent to level 2) and `cError()` for errors (level 1). Warnings and errors will add relevant text automatically. See `libcalamares/utils/Logger.h` for details.