1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:48:11 +00:00
serenity/Userland/Applications/PartitionEditor/PartitionModel.h
Ben Wiederhake 3d6b838df3 LibPartition: Migrate from DeprecatedFile to File
The implemented cloning mechanism should be sound:
- If a PartitionTable is passed a File with
  ShouldCloseFileDescriptor::Yes, then it will keep it alive until the
  PartitionTable is destroyed.
- If a PartitionTable is passed a File with
  ShouldCloseFileDescriptor::No, then the caller has to ensure that the
  file descriptor remains alive.
If the caller is EBRPartitionTable, the same consideration holds.
If the caller is PartitionEditor::PartitionModel, this is satisfied by
keeping an OwnPtr<Core::File> around which is the originally opened
file.

Therefore, we never leak any fds, and never access a Core::File or fd
after destroying it.
2023-06-05 14:50:09 +02:00

43 lines
1.1 KiB
C++

/*
* Copyright (c) 2022, Samuel Bowman <sam@sambowman.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibCore/File.h>
#include <LibGUI/Model.h>
#include <LibPartition/PartitionTable.h>
namespace PartitionEditor {
class PartitionModel final : public GUI::Model {
public:
enum Column {
Partition,
StartBlock,
EndBlock,
TotalBlocks,
Size,
__Count,
};
static NonnullRefPtr<PartitionModel> create();
virtual ~PartitionModel() override = default;
virtual int row_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return m_partition_table->partitions_count(); }
virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return Column::__Count; }
virtual String column_name(int) const override;
virtual GUI::Variant data(GUI::ModelIndex const&, GUI::ModelRole) const override;
ErrorOr<void> set_device_path(DeprecatedString const&);
private:
PartitionModel() = default;
OwnPtr<Partition::PartitionTable> m_partition_table;
OwnPtr<Core::File> m_backing_file;
};
}