[libcalamaresui] Initial rework of error dialog

This commit is contained in:
Artem Grinev 2021-12-05 04:50:13 +04:00
parent ceb9ec4115
commit 6bf0da7230
5 changed files with 282 additions and 34 deletions

View File

@ -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 )

View File

@ -25,6 +25,7 @@
#include "viewpages/ExecutionViewStep.h"
#include "viewpages/ViewStep.h"
#include "widgets/TranslationFix.h"
#include "utils/ErrorDialog/ErrorDialog.h"
#include <QApplication>
#include <QBoxLayout>
@ -32,6 +33,7 @@
#include <QFile>
#include <QMessageBox>
#include <QMetaObject>
#include <QDialogButtonBox>
#define UPDATE_BUTTON_PROPERTY( name, value ) \
do \
@ -159,44 +161,21 @@ ViewManager::onInstallationFailed( const QString& message, const QString& detail
cDebug() << Logger::SubEntry << "- details:" << Logger::NoQuote << details;
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>";
}
= Calamares::Settings::instance()->isSetupMode() ? tr( "Setup Failed" ) : tr( "Installation Failed" );
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 )
connect( errorDialog, &QDialog::finished, [errorDialog]( int result ) {
if ( result == QDialog::Accepted && errorDialog->shouldOfferWebPaste() )
{
CalamaresUtils::Paste::doLogUploadUI( msgBox );
CalamaresUtils::Paste::doLogUploadUI( errorDialog );
}
QApplication::quit();
} );

View File

@ -0,0 +1,89 @@
#include "ErrorDialog.h"
#include "ui_ErrorDialog.h"
#include <QIcon>
#include <QDialogButtonBox>
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 );
emit shouldOfferWebPasteChanged();
}
} // namespace Calamares

View File

@ -0,0 +1,57 @@
#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;
};
}; // namespace Calamares
#endif // ERRORDIALOG_H

View 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>