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

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

sync with github

File size: 5.1 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2016, Teo Mrnjavac <teo@kde.org>
4 *
5 *   Based on the SetPartFlagsJob class from KDE Partition Manager,
6 *   Copyright 2008, 2010, Volker Lanz <vl@fidra.de>
7 *
8 *   Calamares is free software: you can redistribute it and/or modify
9 *   it under the terms of the GNU General Public License as published by
10 *   the Free Software Foundation, either version 3 of the License, or
11 *   (at your option) any later version.
12 *
13 *   Calamares is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "SetPartitionFlagsJob.h"
23
24#include "utils/Logger.h"
25#include "utils/Units.h"
26
27// KPMcore
28#include <core/device.h>
29#include <core/partition.h>
30#include <fs/filesystem.h>
31#include <ops/setpartflagsoperation.h>
32#include <util/report.h>
33
34using CalamaresUtils::BytesToMiB;
35
36SetPartFlagsJob::SetPartFlagsJob( Device* device,
37                                  Partition* partition,
38                                  PartitionTable::Flags flags )
39    : PartitionJob( partition )
40    , m_device( device )
41    , m_flags( flags )
42{}
43
44
45QString
46SetPartFlagsJob::prettyName() const
47{
48    if ( !partition()->partitionPath().isEmpty() )
49        return tr( "Set flags on partition %1." ).arg( partition()->partitionPath() );
50
51    if ( !partition()->fileSystem().name().isEmpty() )
52        return tr( "Set flags on %1MB %2 partition." )
53               .arg( BytesToMiB( partition()->capacity() ) )
54               .arg( partition()->fileSystem().name() );
55
56    return tr( "Set flags on new partition." );
57}
58
59
60QString
61SetPartFlagsJob::prettyDescription() const
62{
63    QStringList flagsList = PartitionTable::flagNames( m_flags );
64    if ( flagsList.count() == 0 )
65    {
66        if ( !partition()->partitionPath().isEmpty() )
67            return tr( "Clear flags on partition <strong>%1</strong>." )
68                   .arg( partition()->partitionPath() );
69
70        if ( !partition()->fileSystem().name().isEmpty() )
71            return tr( "Clear flags on %1MB <strong>%2</strong> partition." )
72                   .arg( BytesToMiB( partition()->capacity() ) )
73                   .arg( partition()->fileSystem().name() );
74
75        return tr( "Clear flags on new partition." );
76    }
77
78    if ( !partition()->partitionPath().isEmpty() )
79        return tr( "Flag partition <strong>%1</strong> as "
80                   "<strong>%2</strong>." )
81               .arg( partition()->partitionPath() )
82               .arg( flagsList.join( ", " ) );
83
84    if ( !partition()->fileSystem().name().isEmpty() )
85        return tr( "Flag %1MB <strong>%2</strong> partition as "
86                   "<strong>%3</strong>." )
87               .arg( BytesToMiB( partition()->capacity() ) )
88               .arg( partition()->fileSystem().name() )
89               .arg( flagsList.join( ", " ) );
90
91    return tr( "Flag new partition as <strong>%1</strong>." )
92           .arg( flagsList.join( ", " ) );
93}
94
95
96QString
97SetPartFlagsJob::prettyStatusMessage() const
98{
99    QStringList flagsList = PartitionTable::flagNames( m_flags );
100    if ( flagsList.count() == 0 )
101    {
102        if ( !partition()->partitionPath().isEmpty() )
103            return tr( "Clearing flags on partition <strong>%1</strong>." )
104                   .arg( partition()->partitionPath() );
105
106        if ( !partition()->fileSystem().name().isEmpty() )
107            return tr( "Clearing flags on %1MB <strong>%2</strong> partition." )
108                   .arg( BytesToMiB( partition()->capacity() ) )
109                   .arg( partition()->fileSystem().name() );
110
111        return tr( "Clearing flags on new partition." );
112    }
113
114    if ( !partition()->partitionPath().isEmpty() )
115        return tr( "Setting flags <strong>%2</strong> on partition "
116                   "<strong>%1</strong>." )
117               .arg( partition()->partitionPath() )
118               .arg( flagsList.join( ", " ) );
119
120    if ( !partition()->fileSystem().name().isEmpty() )
121        return tr( "Setting flags <strong>%3</strong> on "
122                   "%1MB <strong>%2</strong> partition." )
123               .arg( BytesToMiB( partition()->capacity() ) )
124               .arg( partition()->fileSystem().name() )
125               .arg( flagsList.join( ", " ) );
126
127    return tr( "Setting flags <strong>%1</strong> on new partition." )
128           .arg( flagsList.join( ", " ) );
129}
130
131
132Calamares::JobResult
133SetPartFlagsJob::exec()
134{
135    Report report ( nullptr );
136    SetPartFlagsOperation op( *m_device, *partition(), m_flags );
137    op.setStatus( Operation::StatusRunning );
138    connect( &op, &Operation::progress, this, &SetPartFlagsJob::iprogress );
139
140    QString errorMessage = tr( "The installer failed to set flags on partition %1." )
141                           .arg( m_partition->partitionPath() );
142    if ( op.execute( report ) )
143        return Calamares::JobResult::ok();
144
145    return Calamares::JobResult::error( errorMessage, report.toText() );
146}
Note: See TracBrowser for help on using the repository browser.