From 6881fdab6efdae6e52b1ccfdb9b16ddedfbee350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Tue, 8 Jul 2014 19:20:04 +0200 Subject: [PATCH] JobResult --- src/libcalamares/Job.h | 42 +++++++++++++++++++- src/modules/partition/CreatePartitionJob.cpp | 26 +++++++----- src/modules/partition/CreatePartitionJob.h | 2 +- src/modules/partition/DeletePartitionJob.cpp | 3 +- src/modules/partition/DeletePartitionJob.h | 2 +- 5 files changed, 60 insertions(+), 15 deletions(-) diff --git a/src/libcalamares/Job.h b/src/libcalamares/Job.h index eb08dff3b..94e71a5fc 100644 --- a/src/libcalamares/Job.h +++ b/src/libcalamares/Job.h @@ -26,6 +26,46 @@ namespace Calamares { +class DLLEXPORT JobResult +{ +public: + operator bool() const + { + return m_ok; + } + + QString message() const + { + return m_message; + } + + QString details() const + { + return m_details; + } + + static JobResult ok() + { + return JobResult( true, QString(), QString() ); + } + + static JobResult error( const QString& message, const QString& details = QString() ) + { + return JobResult( false, message, details ); + } + +private: + bool m_ok; + QString m_message; + QString m_details; + + JobResult( bool ok, const QString& message, const QString& details ) + : m_ok( ok ) + , m_message( message ) + , m_details( details ) + {} +}; + class DLLEXPORT Job : public QObject { Q_OBJECT @@ -41,7 +81,7 @@ public: virtual ~Job(); virtual QString prettyName() = 0; - virtual void exec() = 0; + virtual JobResult exec() = 0; signals: void running( const Calamares::job_ptr& ); void finished( const Calamares::job_ptr& ); diff --git a/src/modules/partition/CreatePartitionJob.cpp b/src/modules/partition/CreatePartitionJob.cpp index 633535b63..4360da605 100644 --- a/src/modules/partition/CreatePartitionJob.cpp +++ b/src/modules/partition/CreatePartitionJob.cpp @@ -47,7 +47,7 @@ CreatePartitionJob::prettyName() return tr( "Create partition" ); // FIXME } -void +Calamares::JobResult CreatePartitionJob::exec() { Report report( 0 ); @@ -62,33 +62,37 @@ CreatePartitionJob::exec() QString partitionPath = backendPartitionTable->createPartition( report, *m_partition ); if ( partitionPath.isEmpty() ) { - cLog( LOGINFO ) << "Failed to create partition"; - cLog( LOGINFO ) << report.toText(); - return; + return Calamares::JobResult::error( + tr( "Failed to create partition" ), + report.toText() + ); } backendPartitionTable->commit(); FileSystem& fs = m_partition->fileSystem(); if ( fs.type() == FileSystem::Unformatted ) { - return; + return Calamares::JobResult::ok(); } if ( !fs.create( report, partitionPath ) ) { - cLog( LOGINFO ) << "Failed to create filesystem"; - cLog( LOGINFO ) << report.toText(); - return; + return Calamares::JobResult::error( + tr( "Failed to create system" ), + report.toText() + ); } if ( !backendPartitionTable->setPartitionSystemType( report, *m_partition ) ) { - cLog( LOGINFO ) << "Failed to update partition table"; - cLog( LOGINFO ) << report.toText(); - return; + return Calamares::JobResult::error( + tr( "Failed to update partition table" ), + report.toText() + ); } backendPartitionTable->commit(); + return Calamares::JobResult::ok(); } void diff --git a/src/modules/partition/CreatePartitionJob.h b/src/modules/partition/CreatePartitionJob.h index 0309105ed..8e588f0fc 100644 --- a/src/modules/partition/CreatePartitionJob.h +++ b/src/modules/partition/CreatePartitionJob.h @@ -31,7 +31,7 @@ class CreatePartitionJob : public Calamares::Job public: CreatePartitionJob( Device* device, Partition* partition ); QString prettyName() override; - void exec() override; + Calamares::JobResult exec() override; void updatePreview(); Device* device() const diff --git a/src/modules/partition/DeletePartitionJob.cpp b/src/modules/partition/DeletePartitionJob.cpp index fa167e366..2ac859c70 100644 --- a/src/modules/partition/DeletePartitionJob.cpp +++ b/src/modules/partition/DeletePartitionJob.cpp @@ -36,9 +36,10 @@ DeletePartitionJob::prettyName() return tr( "Delete partition %1" ).arg( m_partition->partitionPath() ); } -void +Calamares::JobResult DeletePartitionJob::exec() { + return Calamares::JobResult::ok(); } void diff --git a/src/modules/partition/DeletePartitionJob.h b/src/modules/partition/DeletePartitionJob.h index ce98a5ac2..ea6b7744f 100644 --- a/src/modules/partition/DeletePartitionJob.h +++ b/src/modules/partition/DeletePartitionJob.h @@ -31,7 +31,7 @@ class DeletePartitionJob : public Calamares::Job public: DeletePartitionJob( Device* device, Partition* partition ); QString prettyName() override; - void exec() override; + Calamares::JobResult exec() override; void updatePreview(); Device* device() const