From 165d28fc232da8b7a59c52ba5340873ff0333db0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Thu, 10 Jul 2014 14:46:08 +0200 Subject: [PATCH] Abort installation when a job fails --- src/libcalamares/JobQueue.cpp | 15 +++++++++++++- src/libcalamares/JobQueue.h | 1 + src/libcalamaresui/ViewManager.cpp | 32 +++++++++++++++++++++++++++--- src/libcalamaresui/ViewManager.h | 1 + 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/libcalamares/JobQueue.cpp b/src/libcalamares/JobQueue.cpp index 334914828..edd437d84 100644 --- a/src/libcalamares/JobQueue.cpp +++ b/src/libcalamares/JobQueue.cpp @@ -46,7 +46,12 @@ public: for( auto job : m_jobs ) { emitProgress( current, total, job->prettyName() ); - job->exec(); + JobResult result = job->exec(); + if ( !result ) + { + emitFailed( result.message(), result.details() ); + return; + } ++current; } emitProgress( total, total, QString() ); @@ -64,6 +69,14 @@ private: Q_ARG( QString, prettyName ) ); } + + void emitFailed( const QString& message, const QString& details ) + { + QMetaObject::invokeMethod( m_queue, "failed", Qt::QueuedConnection, + Q_ARG( QString, message ), + Q_ARG( QString, details ) + ); + } }; diff --git a/src/libcalamares/JobQueue.h b/src/libcalamares/JobQueue.h index 014b3d4ce..2772707be 100644 --- a/src/libcalamares/JobQueue.h +++ b/src/libcalamares/JobQueue.h @@ -43,6 +43,7 @@ public: signals: void progress( int current, int total, const QString& prettyName ); + void failed( const QString& message, const QString& details ); private: static JobQueue* s_instance; diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 9bdfe08ae..38ffd7494 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -23,8 +23,8 @@ #include "JobQueue.h" #include -#include #include +#include namespace Calamares { @@ -194,11 +194,37 @@ ViewManager::back() void ViewManager::startInstallation() { + JobQueue* queue = JobQueue::instance(); for( ViewStep* step : m_prepareSteps ) { - JobQueue::instance()->enqueue( step->jobs() ); + queue->enqueue( step->jobs() ); } - JobQueue::instance()->start(); + connect( queue, &JobQueue::failed, this, &ViewManager::onInstallationFailed ); + queue->start(); +} + +void +ViewManager::onInstallationFailed( const QString& message, const QString& details ) +{ + QString text = tr( + "

Installation Failed

" + "

%1

" + ).arg( message ); + + if ( !details.isEmpty() ) + { + text += tr( + "

%1

" + ).arg( details ); + } + + QMessageBox::critical( + QApplication::activeWindow(), + tr( "Error" ), + text, + QMessageBox::Close + ); + QApplication::quit(); } } diff --git a/src/libcalamaresui/ViewManager.h b/src/libcalamaresui/ViewManager.h index 9b18a1828..fd1c85c5f 100644 --- a/src/libcalamaresui/ViewManager.h +++ b/src/libcalamaresui/ViewManager.h @@ -73,6 +73,7 @@ private: void insertViewStep( int before, ViewStep* step ); void startInstallation(); + void onInstallationFailed( const QString& message, const QString& details ); }; }