* added some more details to TODO file

* a little cleanup in PartitionList to respect the 80 chars/line limit
* added PartitionList::AddSpace() and alternative PartitionListRow
  constructor in preparation for support of empty spaces on devices
* refactored a _InsertIndexForOffset() method, the insertion index is
  now based on offset instead of partition_id (untested)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23761 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2008-01-27 12:58:29 +00:00
parent b48029b7a9
commit ebf682ef49
3 changed files with 107 additions and 26 deletions

View File

@ -28,6 +28,8 @@ enum {
PartitionListRow::PartitionListRow(BPartition* partition)
: Inherited()
, fPartitionID(partition->ID())
, fOffset(partition->Offset())
, fSize(partition->Size())
{
// SetField(new BBitmapField(NULL), kBitmapColumn);
@ -35,12 +37,6 @@ PartitionListRow::PartitionListRow(BPartition* partition)
partition->GetPath(&path);
SetField(new BStringField(path.Path()), kDeviceColumn);
// if (partition->ContainsPartitioningSystem()) {
// SetField(new BStringField(partition->ContentType()), kFilesystemColumn);
// } else {
// SetField(new BStringField(kUnavailableString), kFilesystemColumn);
// }
if (partition->ContainsFileSystem()) {
SetField(new BStringField(partition->ContentType()), kFilesystemColumn);
SetField(new BStringField(partition->ContentName()), kVolumeNameColumn);
@ -56,19 +52,46 @@ PartitionListRow::PartitionListRow(BPartition* partition)
}
char size[1024];
SetField(new BStringField(string_for_size(partition->Size(), size)), kSizeColumn);
SetField(new BStringField(string_for_size(partition->Size(), size)),
kSizeColumn);
}
PartitionListRow::PartitionListRow(partition_id id, off_t offset, off_t size)
: Inherited()
, fPartitionID(id)
, fOffset(offset)
, fSize(size)
{
// SetField(new BBitmapField(NULL), kBitmapColumn);
SetField(new BStringField("-"), kDeviceColumn);
SetField(new BStringField("Empty"), kFilesystemColumn);
SetField(new BStringField(kUnavailableString), kVolumeNameColumn);
SetField(new BStringField(kUnavailableString), kMountedAtColumn);
char sizeString[1024];
SetField(new BStringField(string_for_size(size, sizeString)), kSizeColumn);
}
PartitionListView::PartitionListView(const BRect& frame, uint32 resizeMode)
: Inherited(frame, "storagelist", resizeMode, 0, B_NO_BORDER, true)
{
// AddColumn(new BBitmapColumn("", 20, 20, 100, B_ALIGN_CENTER), kBitmapColumn);
AddColumn(new BStringColumn("Device", 150, 50, 500, B_TRUNCATE_MIDDLE), kDeviceColumn);
AddColumn(new BStringColumn("Filesystem", 100, 50, 500, B_TRUNCATE_MIDDLE), kFilesystemColumn);
AddColumn(new BStringColumn("Volume Name", 130, 50, 500, B_TRUNCATE_MIDDLE), kVolumeNameColumn);
AddColumn(new BStringColumn("Mounted At", 100, 50, 500, B_TRUNCATE_MIDDLE), kMountedAtColumn);
AddColumn(new BStringColumn("Size", 100, 50, 500, B_TRUNCATE_END, B_ALIGN_RIGHT), kSizeColumn);
// AddColumn(new BBitmapColumn("", 20, 20, 100, B_ALIGN_CENTER),
// kBitmapColumn);
AddColumn(new BStringColumn("Device", 150, 50, 500, B_TRUNCATE_MIDDLE),
kDeviceColumn);
AddColumn(new BStringColumn("Filesystem", 100, 50, 500, B_TRUNCATE_MIDDLE),
kFilesystemColumn);
AddColumn(new BStringColumn("Volume Name", 130, 50, 500, B_TRUNCATE_MIDDLE),
kVolumeNameColumn);
AddColumn(new BStringColumn("Mounted At", 100, 50, 500, B_TRUNCATE_MIDDLE),
kMountedAtColumn);
AddColumn(new BStringColumn("Size", 100, 50, 500, B_TRUNCATE_END,
B_ALIGN_RIGHT), kSizeColumn);
SetSortingEnabled(false);
}
@ -100,16 +123,15 @@ PartitionListView::AddPartition(BPartition* partition)
PartitionListRow* partitionrow = FindRow(partition->ID());
// forget about it if this partition is already in the listview
if (partitionrow != NULL) {
if (partitionrow != NULL)
return partitionrow;
}
// create the row for this partition
partitionrow = new PartitionListRow(partition);
PartitionListRow* parent = NULL;
// see if this partition has a parent, or should have
// a parent (add it in this case)
PartitionListRow* parent = NULL;
if (partition->Parent() != NULL) {
// check if it is in the listview
parent = FindRow(partition->Parent()->ID());
@ -120,15 +142,8 @@ PartitionListView::AddPartition(BPartition* partition)
}
}
// find a proper insertion index based on the id
int32 index = 0;
int32 count = CountRows(parent);
for (; index < count; index++) {
PartitionListRow* item
= dynamic_cast<PartitionListRow*>(RowAt(index, parent));
if (item && item->ID() > partition->ID())
break;
}
// find a proper insertion index based on the on-disk offset
int32 index = _InsertIndexForOffset(parent, partition->Offset());
// add the row, parent may be NULL (add at top level)
AddRow(partitionrow, index, parent);
@ -138,3 +153,52 @@ PartitionListView::AddPartition(BPartition* partition)
return partitionrow;
}
PartitionListRow*
PartitionListView::AddSpace(partition_id parentID, partition_id id,
off_t offset, off_t size)
{
PartitionListRow* partitionrow = FindRow(id);
// forget about it if this item is already in the listview
if (partitionrow != NULL)
return partitionrow;
// the parent should already be in the listview
PartitionListRow* parent = FindRow(parentID);
if (!parent)
return NULL;
// create the row for this partition
partitionrow = new PartitionListRow(id, offset, size);
// find a proper insertion index based on the on-disk offset
int32 index = _InsertIndexForOffset(parent, offset);
// add the row, parent may be NULL (add at top level)
AddRow(partitionrow, index, parent);
// make sure the row is initially expanded
ExpandOrCollapse(partitionrow, true);
return partitionrow;
}
int32
PartitionListView::_InsertIndexForOffset(PartitionListRow* parent,
off_t offset) const
{
int32 index = 0;
int32 count = CountRows(parent);
for (; index < count; index++) {
const PartitionListRow* item
= dynamic_cast<const PartitionListRow*>(RowAt(index, parent));
if (item && item->Offset() > offset)
break;
}
return index;
}

View File

@ -25,11 +25,19 @@ class PartitionListRow : public BRow {
typedef BRow Inherited;
public:
PartitionListRow(BPartition* partition);
PartitionListRow(partition_id id,
off_t offset, off_t size);
partition_id ID() const
{ return fPartitionID; }
off_t Offset() const
{ return fOffset; }
off_t Size() const
{ return fSize; }
private:
partition_id fPartitionID;
off_t fOffset;
off_t fSize;
};
@ -42,6 +50,12 @@ public:
PartitionListRow* FindRow(partition_id id,
PartitionListRow* parent = NULL);
PartitionListRow* AddPartition(BPartition* partition);
PartitionListRow* AddSpace(partition_id parent,
partition_id id, off_t offset, off_t size);
private:
int32 _InsertIndexForOffset(PartitionListRow* parent,
off_t offset) const;
};

View File

@ -2,6 +2,9 @@
* The offsets of partitions should be used to detect free space on container partition types (disks and extended partitions). Items for these free spaces should be placed into the partition list and disk view, so that they can be selected. Only if such a space item is selected should the Partition->Create menu be enabled. If the space is on a disk, the "Primary" and "Extended" items could be enabled. If the space is on an extended partition, the "Logical" item could be enabled. Maybe the Disk Device API allows to query for the ability to create either partition type on the parent device, depending on the partitioning system in use, so that DriveSetup remains neutral towards the partitioning system.
* When the Partition->Create menu items are invoked on free space items, DriveSetup would show a simple panel asking for the size of the to be created partition.
* When the Partition->Create menu items are invoked on free space items, DriveSetup would show a simple panel asking for the size of the to be created partition. The panel could display a slider as the main means to change the size, with the slider already at the maximum position. Below the slider, there could be one text field with a popup for the unit, or three text fields, one for bytes, one for megabytes and one for gigabytes.
* Support of more advanced options, partiticularily the option to resize (shrink) existing partitions to free up space.
* Possibly support the option to do virtual changes to the disk at a higher level. Ie, write back any changes until the user invokes a command to that effect. The drawback is that warnings become more complicated and less direct. For example, if you delete a partition, there is no warning really necessary at this point, but when you later write the changes to disk, there should be a summary of warnings for all partitions you deleted, because only at this point, they really deleted. The indirection could be confusing. On the other hand, future support to resize partitions could take a long time to execute. Then it is nice to setup a list of jobs and execute them without having to sit in front of the machine.