source: calamares/trunk/fuentes/src/modules/partition/jobs/CreatePartitionJob.cpp @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 2.9 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2014, Aurélien Gâteau <agateau@kde.org>
4 *   Copyright 2015, Teo Mrnjavac <teo@kde.org>
5 *   Copyright 2017, Adriaan de Groot <groot@kde.org>
6 *
7 *   Calamares is free software: you can redistribute it and/or modify
8 *   it under the terms of the GNU General Public License as published by
9 *   the Free Software Foundation, either version 3 of the License, or
10 *   (at your option) any later version.
11 *
12 *   Calamares is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "jobs/CreatePartitionJob.h"
22
23#include "utils/Logger.h"
24#include "utils/Units.h"
25
26// KPMcore
27#include <kpmcore/core/device.h>
28#include <kpmcore/core/lvmdevice.h>
29#include <kpmcore/core/partition.h>
30#include <kpmcore/core/partitiontable.h>
31#include <kpmcore/fs/filesystem.h>
32#include <kpmcore/ops/newoperation.h>
33#include <kpmcore/util/report.h>
34
35CreatePartitionJob::CreatePartitionJob( Device* device, Partition* partition )
36    : PartitionJob( partition )
37    , m_device( device )
38{
39}
40
41QString
42CreatePartitionJob::prettyName() const
43{
44    return tr( "Create new %2MB partition on %4 (%3) with file system %1." )
45            .arg( m_partition->fileSystem().name() )
46            .arg( CalamaresUtils::BytesToMiB( m_partition->capacity() ) )
47            .arg( m_device->name() )
48            .arg( m_device->deviceNode() );
49}
50
51
52QString
53CreatePartitionJob::prettyDescription() const
54{
55    return tr( "Create new <strong>%2MB</strong> partition on <strong>%4</strong> "
56               "(%3) with file system <strong>%1</strong>." )
57            .arg( m_partition->fileSystem().name() )
58            .arg( CalamaresUtils::BytesToMiB( m_partition->capacity() ) )
59            .arg( m_device->name() )
60            .arg( m_device->deviceNode() );
61}
62
63
64QString
65CreatePartitionJob::prettyStatusMessage() const
66{
67    return tr( "Creating new %1 partition on %2." )
68            .arg( m_partition->fileSystem().name() )
69            .arg( m_device->deviceNode() );
70}
71
72Calamares::JobResult
73CreatePartitionJob::exec()
74{
75    Report report( nullptr );
76    NewOperation op(*m_device, m_partition);
77    op.setStatus(Operation::StatusRunning);
78
79    QString message = tr( "The installer failed to create partition on disk '%1'." ).arg( m_device->name() );
80    if (op.execute(report))
81        return Calamares::JobResult::ok();
82
83    return Calamares::JobResult::error(message, report.toText());
84}
85
86void
87CreatePartitionJob::updatePreview()
88{
89    m_device->partitionTable()->removeUnallocated();
90    m_partition->parent()->insert( m_partition );
91    m_device->partitionTable()->updateUnallocated( *m_device );
92}
Note: See TracBrowser for help on using the repository browser.