source: calamares/trunk/fuentes/src/modules/partition/core/PartitionCoreModule.h @ 7538

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

sync with github

File size: 7.0 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 2014-2016, Teo Mrnjavac <teo@kde.org>
5 *
6 *   Calamares is free software: you can redistribute it and/or modify
7 *   it under the terms of the GNU General Public License as published by
8 *   the Free Software Foundation, either version 3 of the License, or
9 *   (at your option) any later version.
10 *
11 *   Calamares is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *   GNU General Public License for more details.
15 *
16 *   You should have received a copy of the GNU General Public License
17 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef PARTITIONCOREMODULE_H
21#define PARTITIONCOREMODULE_H
22
23#include "core/PartitionModel.h"
24#include "Typedefs.h"
25
26// KPMcore
27#include <kpmcore/core/partitiontable.h>
28
29// Qt
30#include <QList>
31#include <QMutex>
32#include <QObject>
33
34#include <functional>
35
36class BootLoaderModel;
37class CreatePartitionJob;
38class Device;
39class DeviceModel;
40class FileSystem;
41class Partition;
42
43class QStandardItemModel;
44
45/**
46 * The core of the module.
47 *
48 * It has two responsibilities:
49 * - Listing the devices and partitions, creating Qt models for them.
50 * - Creating jobs for any changes requested by the user interface.
51 */
52class PartitionCoreModule : public QObject
53{
54    Q_OBJECT
55public:
56    /**
57     * @brief The SummaryInfo struct is a wrapper for PartitionModel instances for
58     * a given Device.
59     * Each Device gets a mutable "after" model and an immutable "before" model.
60     */
61    struct SummaryInfo
62    {
63        QString deviceName;
64        QString deviceNode;
65        PartitionModel* partitionModelBefore;
66        PartitionModel* partitionModelAfter;
67    };
68
69    PartitionCoreModule( QObject* parent = nullptr );
70    ~PartitionCoreModule();
71
72    /**
73     * @brief init performs a devices scan and initializes all KPMcore data
74     * structures.
75     * This function is thread safe.
76     */
77    void init();
78
79    /**
80     * @brief deviceModel returns a model which exposes a list of available
81     * storage devices.
82     * @return the device model.
83     */
84    DeviceModel* deviceModel() const;
85
86    /**
87     * @brief partitionModelForDevice returns the PartitionModel for the given device.
88     * @param device the device for which to get a model.
89     * @return a PartitionModel which represents the partitions of a device.
90     */
91    PartitionModel* partitionModelForDevice( const Device* device ) const;
92
93    //HACK: all devices change over time, and together make up the state of the CoreModule.
94    //      However this makes it hard to show the *original* state of a device.
95    //      For each DeviceInfo we keep a second Device object that contains the
96    //      current state of a disk regardless of subsequent changes.
97    //              -- Teo 4/2015
98    //FIXME: make this horrible method private. -- Teo 12/2015
99    Device* immutableDeviceCopy( const Device* device );
100
101    /**
102     * @brief bootLoaderModel returns a model which represents the available boot
103     * loader locations.
104     * The single BootLoaderModel instance belongs to the PCM.
105     * @return the BootLoaderModel.
106     */
107    QAbstractItemModel* bootLoaderModel() const;
108
109    void createPartitionTable( Device* device, PartitionTable::TableType type );
110
111    void createPartition( Device* device, Partition* partition,
112                          PartitionTable::Flags flags = PartitionTable::FlagNone );
113
114    void deletePartition( Device* device, Partition* partition );
115
116    void formatPartition( Device* device, Partition* partition );
117
118    void resizePartition( Device* device, Partition* partition, qint64 first, qint64 last );
119
120    void setPartitionFlags( Device* device, Partition* partition, PartitionTable::Flags flags );
121
122    void setBootLoaderInstallPath( const QString& path );
123
124    /**
125     * @brief jobs creates and returns a list of jobs which can then apply the changes
126     * requested by the user.
127     * @return a list of jobs.
128     */
129    QList< Calamares::job_ptr > jobs() const;
130
131    bool hasRootMountPoint() const;
132
133    QList< Partition* > efiSystemPartitions() const;
134
135    /**
136     * @brief findPartitionByMountPoint returns a Partition* for a given mount point.
137     * @param mountPoint the mount point to find a partition for.
138     * @return a pointer to a Partition object.
139     * Note that this function looks for partitions in live devices (the "proposed"
140     * state), not the immutable copies. Comparisons with Partition* objects that
141     * refer to immutable Device*s will fail.
142     */
143    Partition* findPartitionByMountPoint( const QString& mountPoint ) const;
144
145    void revert();                      // full revert, thread safe, calls doInit
146    void revertAllDevices();            // convenience function, calls revertDevice
147    void revertDevice( Device* dev );   // rescans a single Device and updates DeviceInfo
148    void asyncRevertDevice( Device* dev, std::function< void() > callback ); //like revertDevice, but asynchronous
149
150    void clearJobs();   // only clear jobs, the Device* states are preserved
151
152    bool isDirty();     // true if there are pending changes, otherwise false
153
154    /**
155     * To be called when a partition has been altered, but only for changes
156     * which do not affect its size, because changes which affect the partition size
157     * affect the size of other partitions as well.
158     */
159    void refreshPartition( Device* device, Partition* partition );
160
161    /**
162     * Returns a list of SummaryInfo for devices which have pending changes.
163     * Caller is responsible for deleting the partition models
164     */
165    QList< SummaryInfo > createSummaryInfo() const;
166
167    void dumpQueue() const; // debug output
168
169    const OsproberEntryList osproberEntries() const;    // os-prober data structure, cached
170
171Q_SIGNALS:
172    void hasRootMountPointChanged( bool value );
173    void isDirtyChanged( bool value );
174    void reverted();
175    void deviceReverted( Device* device );
176
177private:
178    void refresh();
179
180    /**
181     * Owns the Device, PartitionModel and the jobs
182     */
183    struct DeviceInfo
184    {
185        DeviceInfo( Device* );
186        ~DeviceInfo();
187        QScopedPointer< Device > device;
188        QScopedPointer< PartitionModel > partitionModel;
189        const QScopedPointer< Device > immutableDevice;
190        QList< Calamares::job_ptr > jobs;
191
192        void forgetChanges();
193        bool isDirty() const;
194    };
195    QList< DeviceInfo* > m_deviceInfos;
196    QList< Partition* > m_efiSystemPartitions;
197
198    DeviceModel* m_deviceModel;
199    BootLoaderModel* m_bootLoaderModel;
200    bool m_hasRootMountPoint = false;
201    bool m_isDirty = false;
202    QString m_bootLoaderInstallPath;
203
204    void doInit();
205    void updateHasRootMountPoint();
206    void updateIsDirty();
207    void scanForEfiSystemPartitions();
208
209    DeviceInfo* infoForDevice( const Device* ) const;
210
211    OsproberEntryList m_osproberLines;
212
213    QMutex m_revertMutex;
214};
215
216#endif /* PARTITIONCOREMODULE_H */
Note: See TracBrowser for help on using the repository browser.