Merge pull request #1843 from LordTermor/calamares
Rework of error dialog
This commit is contained in:
commit
6e59177f54
@ -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 )
|
||||
|
@ -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 <QApplication>
|
||||
#include <QBoxLayout>
|
||||
#include <QClipboard>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFile>
|
||||
#include <QMessageBox>
|
||||
#include <QMetaObject>
|
||||
@ -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 = "<p>" + message + "</p>";
|
||||
if ( !details.isEmpty() )
|
||||
{
|
||||
text += "<p>"
|
||||
+ CalamaresUtils::truncateMultiLine( details, CalamaresUtils::LinesStartEnd { 6, 2 } )
|
||||
.replace( '\n', QStringLiteral( "<br/>" ) )
|
||||
+ "</p>";
|
||||
}
|
||||
if ( shouldOfferWebPaste )
|
||||
{
|
||||
text += "<p>" + pasteMsg + "</p>";
|
||||
}
|
||||
|
||||
QMessageBox* msgBox = new QMessageBox();
|
||||
msgBox->setIcon( QMessageBox::Critical );
|
||||
msgBox->setWindowTitle( tr( "Error" ) );
|
||||
msgBox->setText( "<strong>" + heading + "</strong>" );
|
||||
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( "<strong>" + heading + "</strong>" );
|
||||
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();
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
|
108
src/libcalamaresui/utils/ErrorDialog/ErrorDialog.cpp
Normal file
108
src/libcalamaresui/utils/ErrorDialog/ErrorDialog.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2021 Artem Grinev <agrinev@manjaro.org>
|
||||
* 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 <QDialogButtonBox>
|
||||
#include <QIcon>
|
||||
|
||||
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
|
68
src/libcalamaresui/utils/ErrorDialog/ErrorDialog.h
Normal file
68
src/libcalamaresui/utils/ErrorDialog/ErrorDialog.h
Normal file
@ -0,0 +1,68 @@
|
||||
/* === This file is part of Calamares - <https://calamares.io> ===
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2021 Artem Grinev <agrinev@manjaro.org>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* Calamares is Free Software: see the License-Identifier above.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ERRORDIALOG_H
|
||||
#define ERRORDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
|
||||
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
|
120
src/libcalamaresui/utils/ErrorDialog/ErrorDialog.ui
Normal file
120
src/libcalamaresui/utils/ErrorDialog/ErrorDialog.ui
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ErrorDialog</class>
|
||||
<widget class="QDialog" name="ErrorDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>425</width>
|
||||
<height>262</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="headingLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QWidget" name="detailsWidget" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Details:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextBrowser" name="detailsBrowser"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" rowspan="2">
|
||||
<widget class="QLabel" name="iconLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="informativeTextLabel">
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="offerWebPasteLabel">
|
||||
<property name="text">
|
||||
<string>Would you like to paste the install log to the web?</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>ErrorDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>ErrorDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
@ -11,30 +11,34 @@
|
||||
|
||||
#include <QAbstractButton>
|
||||
#include <QCoreApplication>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user