JobResult

main
Aurélien Gâteau 11 years ago
parent d984489eea
commit 6881fdab6e

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

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

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

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

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

Loading…
Cancel
Save