JobResult
This commit is contained in:
parent
d984489eea
commit
6881fdab6e
@ -26,6 +26,46 @@
|
|||||||
|
|
||||||
namespace Calamares {
|
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
|
class DLLEXPORT Job : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -41,7 +81,7 @@ public:
|
|||||||
virtual ~Job();
|
virtual ~Job();
|
||||||
|
|
||||||
virtual QString prettyName() = 0;
|
virtual QString prettyName() = 0;
|
||||||
virtual void exec() = 0;
|
virtual JobResult exec() = 0;
|
||||||
signals:
|
signals:
|
||||||
void running( const Calamares::job_ptr& );
|
void running( const Calamares::job_ptr& );
|
||||||
void finished( const Calamares::job_ptr& );
|
void finished( const Calamares::job_ptr& );
|
||||||
|
@ -47,7 +47,7 @@ CreatePartitionJob::prettyName()
|
|||||||
return tr( "Create partition" ); // FIXME
|
return tr( "Create partition" ); // FIXME
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
Calamares::JobResult
|
||||||
CreatePartitionJob::exec()
|
CreatePartitionJob::exec()
|
||||||
{
|
{
|
||||||
Report report( 0 );
|
Report report( 0 );
|
||||||
@ -62,33 +62,37 @@ CreatePartitionJob::exec()
|
|||||||
QString partitionPath = backendPartitionTable->createPartition( report, *m_partition );
|
QString partitionPath = backendPartitionTable->createPartition( report, *m_partition );
|
||||||
if ( partitionPath.isEmpty() )
|
if ( partitionPath.isEmpty() )
|
||||||
{
|
{
|
||||||
cLog( LOGINFO ) << "Failed to create partition";
|
return Calamares::JobResult::error(
|
||||||
cLog( LOGINFO ) << report.toText();
|
tr( "Failed to create partition" ),
|
||||||
return;
|
report.toText()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
backendPartitionTable->commit();
|
backendPartitionTable->commit();
|
||||||
|
|
||||||
FileSystem& fs = m_partition->fileSystem();
|
FileSystem& fs = m_partition->fileSystem();
|
||||||
if ( fs.type() == FileSystem::Unformatted )
|
if ( fs.type() == FileSystem::Unformatted )
|
||||||
{
|
{
|
||||||
return;
|
return Calamares::JobResult::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !fs.create( report, partitionPath ) )
|
if ( !fs.create( report, partitionPath ) )
|
||||||
{
|
{
|
||||||
cLog( LOGINFO ) << "Failed to create filesystem";
|
return Calamares::JobResult::error(
|
||||||
cLog( LOGINFO ) << report.toText();
|
tr( "Failed to create system" ),
|
||||||
return;
|
report.toText()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !backendPartitionTable->setPartitionSystemType( report, *m_partition ) )
|
if ( !backendPartitionTable->setPartitionSystemType( report, *m_partition ) )
|
||||||
{
|
{
|
||||||
cLog( LOGINFO ) << "Failed to update partition table";
|
return Calamares::JobResult::error(
|
||||||
cLog( LOGINFO ) << report.toText();
|
tr( "Failed to update partition table" ),
|
||||||
return;
|
report.toText()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
backendPartitionTable->commit();
|
backendPartitionTable->commit();
|
||||||
|
return Calamares::JobResult::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -31,7 +31,7 @@ class CreatePartitionJob : public Calamares::Job
|
|||||||
public:
|
public:
|
||||||
CreatePartitionJob( Device* device, Partition* partition );
|
CreatePartitionJob( Device* device, Partition* partition );
|
||||||
QString prettyName() override;
|
QString prettyName() override;
|
||||||
void exec() override;
|
Calamares::JobResult exec() override;
|
||||||
|
|
||||||
void updatePreview();
|
void updatePreview();
|
||||||
Device* device() const
|
Device* device() const
|
||||||
|
@ -36,9 +36,10 @@ DeletePartitionJob::prettyName()
|
|||||||
return tr( "Delete partition %1" ).arg( m_partition->partitionPath() );
|
return tr( "Delete partition %1" ).arg( m_partition->partitionPath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
Calamares::JobResult
|
||||||
DeletePartitionJob::exec()
|
DeletePartitionJob::exec()
|
||||||
{
|
{
|
||||||
|
return Calamares::JobResult::ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -31,7 +31,7 @@ class DeletePartitionJob : public Calamares::Job
|
|||||||
public:
|
public:
|
||||||
DeletePartitionJob( Device* device, Partition* partition );
|
DeletePartitionJob( Device* device, Partition* partition );
|
||||||
QString prettyName() override;
|
QString prettyName() override;
|
||||||
void exec() override;
|
Calamares::JobResult exec() override;
|
||||||
|
|
||||||
void updatePreview();
|
void updatePreview();
|
||||||
Device* device() const
|
Device* device() const
|
||||||
|
Loading…
Reference in New Issue
Block a user