diff --git a/src/libcalamaresui/CMakeLists.txt b/src/libcalamaresui/CMakeLists.txt index a704b7484..e745681f3 100644 --- a/src/libcalamaresui/CMakeLists.txt +++ b/src/libcalamaresui/CMakeLists.txt @@ -20,6 +20,7 @@ set( calamaresui_SOURCES utils/CalamaresUtilsGui.cpp utils/ImageRegistry.cpp utils/Paste.cpp + utils/ErrorDialog/ErrorDialog.cpp viewpages/BlankViewStep.cpp viewpages/ExecutionViewStep.cpp @@ -75,6 +76,8 @@ calamares_add_library( calamaresui Qt5::Svg RESOURCES libcalamaresui.qrc EXPORT Calamares + UI + utils/ErrorDialog/ErrorDialog.ui VERSION ${CALAMARES_VERSION_SHORT} ) target_link_libraries( calamaresui PRIVATE yamlcpp::yamlcpp ) diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 57570ad64..87024ea6b 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -17,6 +17,7 @@ #include "JobQueue.h" #include "Settings.h" +#include "utils/ErrorDialog/ErrorDialog.h" #include "utils/Logger.h" #include "utils/Paste.h" #include "utils/Retranslator.h" @@ -29,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -160,46 +162,26 @@ ViewManager::onInstallationFailed( const QString& message, const QString& detail QString heading = Calamares::Settings::instance()->isSetupMode() ? tr( "Setup Failed" ) : tr( "Installation Failed" ); - QString pasteMsg = tr( "Would you like to paste the install log to the web?" ); - QString text = "

" + message + "

"; - if ( !details.isEmpty() ) - { - text += "

" - + CalamaresUtils::truncateMultiLine( details, CalamaresUtils::LinesStartEnd { 6, 2 } ) - .replace( '\n', QStringLiteral( "
" ) ) - + "

"; - } - if ( shouldOfferWebPaste ) - { - text += "

" + pasteMsg + "

"; - } - QMessageBox* msgBox = new QMessageBox(); - msgBox->setIcon( QMessageBox::Critical ); - msgBox->setWindowTitle( tr( "Error" ) ); - msgBox->setText( "" + heading + "" ); - msgBox->setInformativeText( text ); - if ( shouldOfferWebPaste ) - { - msgBox->setStandardButtons( QMessageBox::Yes | QMessageBox::No ); - msgBox->setDefaultButton( QMessageBox::No ); - } - else - { - msgBox->setStandardButtons( QMessageBox::Close ); - msgBox->setDefaultButton( QMessageBox::Close ); - } - Calamares::fixButtonLabels( msgBox ); - msgBox->show(); + ErrorDialog* errorDialog = new ErrorDialog(); + errorDialog->setWindowTitle( tr( "Error" ) ); + errorDialog->setHeading( "" + heading + "" ); + errorDialog->setInformativeText( message ); + errorDialog->setShouldOfferWebPaste( shouldOfferWebPaste ); + errorDialog->setDetails( details ); + errorDialog->show(); cDebug() << "Calamares will quit when the dialog closes."; - connect( msgBox, &QMessageBox::buttonClicked, [msgBox]( QAbstractButton* button ) { - if ( msgBox->buttonRole( button ) == QMessageBox::ButtonRole::YesRole ) - { - CalamaresUtils::Paste::doLogUploadUI( msgBox ); - } - QApplication::quit(); - } ); + connect( errorDialog, + &QDialog::finished, + [ errorDialog ]( int result ) + { + if ( result == QDialog::Accepted && errorDialog->shouldOfferWebPaste() ) + { + CalamaresUtils::Paste::doLogUploadUI( errorDialog ); + } + QApplication::quit(); + } ); } diff --git a/src/libcalamaresui/utils/ErrorDialog/ErrorDialog.cpp b/src/libcalamaresui/utils/ErrorDialog/ErrorDialog.cpp new file mode 100644 index 000000000..4ffe20384 --- /dev/null +++ b/src/libcalamaresui/utils/ErrorDialog/ErrorDialog.cpp @@ -0,0 +1,108 @@ +/* === This file is part of Calamares - === + * + * SPDX-FileCopyrightText: 2021 Artem Grinev + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Calamares is Free Software: see the License-Identifier above. + * + */ + +#include "ErrorDialog.h" +#include "ui_ErrorDialog.h" + +#include "widgets/TranslationFix.h" +#include +#include + +namespace Calamares +{ + + +ErrorDialog::ErrorDialog( QWidget* parent ) + : QDialog( parent ) + , ui( new Ui::ErrorDialog ) +{ + ui->setupUi( this ); + ui->iconLabel->setPixmap( QIcon::fromTheme( "dialog-error" ).pixmap( 64 ) ); + ui->detailsWidget->hide(); + ui->offerWebPasteLabel->hide(); +} + +ErrorDialog::~ErrorDialog() +{ + delete ui; +} + + +QString +ErrorDialog::heading() const +{ + return ui->headingLabel->text(); +} + +QString +ErrorDialog::informativeText() const +{ + return ui->informativeTextLabel->text(); +} + +QString +ErrorDialog::details() const +{ + return ui->detailsBrowser->toPlainText(); +} + +void +ErrorDialog::setHeading( const QString& newHeading ) +{ + if ( ui->headingLabel->text() == newHeading ) + return; + ui->headingLabel->setText( newHeading ); + emit headingChanged(); +} + +void +ErrorDialog::setInformativeText( const QString& newInformativeText ) +{ + if ( ui->informativeTextLabel->text() == newInformativeText ) + return; + ui->informativeTextLabel->setText( newInformativeText ); + emit informativeTextChanged(); +} + +void +ErrorDialog::setDetails( const QString& newDetails ) +{ + if ( ui->detailsBrowser->toPlainText() == newDetails ) + return; + ui->detailsBrowser->setPlainText( newDetails ); + + ui->detailsWidget->setVisible( !ui->detailsBrowser->toPlainText().trimmed().isEmpty() ); + + emit detailsChanged(); +} + +bool +ErrorDialog::shouldOfferWebPaste() const +{ + return m_shouldOfferWebPaste; +} + +void +ErrorDialog::setShouldOfferWebPaste( bool newShouldOfferWebPaste ) +{ + if ( m_shouldOfferWebPaste == newShouldOfferWebPaste ) + return; + m_shouldOfferWebPaste = newShouldOfferWebPaste; + + ui->offerWebPasteLabel->setVisible( m_shouldOfferWebPaste ); + + ui->buttonBox->setStandardButtons( m_shouldOfferWebPaste ? ( QDialogButtonBox::Yes | QDialogButtonBox::No ) + : QDialogButtonBox::Close ); + + fixButtonLabels( ui->buttonBox ); + + emit shouldOfferWebPasteChanged(); +} + +} // namespace Calamares diff --git a/src/libcalamaresui/utils/ErrorDialog/ErrorDialog.h b/src/libcalamaresui/utils/ErrorDialog/ErrorDialog.h new file mode 100644 index 000000000..a0126c2ce --- /dev/null +++ b/src/libcalamaresui/utils/ErrorDialog/ErrorDialog.h @@ -0,0 +1,68 @@ +/* === This file is part of Calamares - === + * + * SPDX-FileCopyrightText: 2021 Artem Grinev + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Calamares is Free Software: see the License-Identifier above. + * + */ + +#ifndef ERRORDIALOG_H +#define ERRORDIALOG_H + +#include + + +namespace Ui +{ +class ErrorDialog; +} +class QDialogButtonBox; +namespace Calamares +{ +class ErrorDialog : public QDialog +{ + Q_OBJECT + + Q_PROPERTY( QString heading READ heading WRITE setHeading NOTIFY headingChanged ) + Q_PROPERTY( QString informativeText READ informativeText WRITE setInformativeText NOTIFY informativeTextChanged ) + Q_PROPERTY( QString details READ details WRITE setDetails NOTIFY detailsChanged ) + Q_PROPERTY( bool shouldOfferWebPaste READ shouldOfferWebPaste WRITE setShouldOfferWebPaste NOTIFY + shouldOfferWebPasteChanged ) + +public: + explicit ErrorDialog( QWidget* parent = nullptr ); + ~ErrorDialog(); + + QString heading() const; + + QString informativeText() const; + + QString details() const; + + void setHeading( const QString& newHeading ); + + void setInformativeText( const QString& newInformativeText ); + + void setDetails( const QString& newDetails ); + + bool shouldOfferWebPaste() const; + void setShouldOfferWebPaste( bool newShouldOfferWebPaste ); + +signals: + void headingChanged(); + + void informativeTextChanged(); + + void detailsChanged(); + + void shouldOfferWebPasteChanged(); + +private: + Ui::ErrorDialog* ui; + bool m_shouldOfferWebPaste = false; +}; + +}; // namespace Calamares + +#endif // ERRORDIALOG_H diff --git a/src/libcalamaresui/utils/ErrorDialog/ErrorDialog.ui b/src/libcalamaresui/utils/ErrorDialog/ErrorDialog.ui new file mode 100644 index 000000000..2632af617 --- /dev/null +++ b/src/libcalamaresui/utils/ErrorDialog/ErrorDialog.ui @@ -0,0 +1,120 @@ + + + ErrorDialog + + + + 0 + 0 + 425 + 262 + + + + Dialog + + + + + + + 0 + 0 + + + + + + + + + + + + + + Details: + + + + + + + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + Would you like to paste the install log to the web? + + + + + + + + + buttonBox + accepted() + ErrorDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ErrorDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/libcalamaresui/widgets/TranslationFix.cpp b/src/libcalamaresui/widgets/TranslationFix.cpp index 1262fceb5..dbfd0bd83 100644 --- a/src/libcalamaresui/widgets/TranslationFix.cpp +++ b/src/libcalamaresui/widgets/TranslationFix.cpp @@ -11,30 +11,34 @@ #include #include +#include #include +#include namespace Calamares { +//Using QMessageBox's StandardButton enum here but according to headers they should be kept in-sync between multiple classes. +static std::pair< decltype( QMessageBox::Ok ), const char* > maps[] = { + { QMessageBox::Ok, QT_TRANSLATE_NOOP( "StandardButtons", "&OK" ) }, + { QMessageBox::Yes, QT_TRANSLATE_NOOP( "StandardButtons", "&Yes" ) }, + { QMessageBox::No, QT_TRANSLATE_NOOP( "StandardButtons", "&No" ) }, + { QMessageBox::Cancel, QT_TRANSLATE_NOOP( "StandardButtons", "&Cancel" ) }, + { QMessageBox::Close, QT_TRANSLATE_NOOP( "StandardButtons", "&Close" ) }, +}; + +template < typename TButtonBox > void -fixButtonLabels( QMessageBox* box ) +fixButtonLabels( TButtonBox* box ) { if ( !box ) { return; } - static std::pair< decltype( QMessageBox::Ok ), const char* > maps[] = { - { QMessageBox::Ok, QT_TRANSLATE_NOOP( "StandardButtons", "&OK" ) }, - { QMessageBox::Yes, QT_TRANSLATE_NOOP( "StandardButtons", "&Yes" ) }, - { QMessageBox::No, QT_TRANSLATE_NOOP( "StandardButtons", "&No" ) }, - { QMessageBox::Cancel, QT_TRANSLATE_NOOP( "StandardButtons", "&Cancel" ) }, - { QMessageBox::Close, QT_TRANSLATE_NOOP( "StandardButtons", "&Close" ) }, - }; - for ( auto [ sb, label ] : maps ) { - auto* button = box->button( sb ); + auto* button = box->button( static_cast< typename TButtonBox::StandardButton >( int( sb ) ) ); if ( button ) { button->setText( QCoreApplication::translate( "StandardButtons", label ) ); @@ -42,4 +46,16 @@ fixButtonLabels( QMessageBox* box ) } } +void +fixButtonLabels( QMessageBox* box ) +{ + fixButtonLabels< QMessageBox >( box ); +} + +void +fixButtonLabels( QDialogButtonBox* box ) +{ + fixButtonLabels< QDialogButtonBox >( box ); +} + } // namespace Calamares diff --git a/src/libcalamaresui/widgets/TranslationFix.h b/src/libcalamaresui/widgets/TranslationFix.h index 107dad67d..89ee9a51a 100644 --- a/src/libcalamaresui/widgets/TranslationFix.h +++ b/src/libcalamaresui/widgets/TranslationFix.h @@ -13,6 +13,7 @@ #include "DllMacro.h" class QMessageBox; +class QDialogButtonBox; namespace Calamares { @@ -26,6 +27,8 @@ namespace Calamares * guess the context. */ void UIDLLEXPORT fixButtonLabels( QMessageBox* ); + +void UIDLLEXPORT fixButtonLabels( QDialogButtonBox* ); } // namespace Calamares #endif