* the DiskView is now displaying the partition layout grafically and draws a
frame around the currently selected partition (in the listview) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23290 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
#include "DiskView.h"
|
||||
|
||||
#include <DiskDeviceRoster.h>
|
||||
#include <DiskDeviceVisitor.h>
|
||||
#include <HashMap.h>
|
||||
|
||||
@@ -61,17 +62,18 @@ struct PartitionBox {
|
||||
|
||||
class PartitionDrawer : public BDiskDeviceVisitor {
|
||||
public:
|
||||
PartitionDrawer(BView* view)
|
||||
PartitionDrawer(BView* view, partition_id selectedPartition)
|
||||
: fView(view)
|
||||
, fBoxMap()
|
||||
, fColorIndex(0)
|
||||
, fSelectedPartition(selectedPartition)
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool Visit(BDiskDevice* device)
|
||||
{
|
||||
fBoxMap.Put(device->ID(), PartitionBox(fView->Bounds(), _NextColor()));
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool Visit(BPartition* partition, int32 level)
|
||||
@@ -81,10 +83,45 @@ public:
|
||||
|
||||
PartitionBox parent = fBoxMap.Get(partition->Parent()->ID());
|
||||
BRect frame = parent.frame;
|
||||
// TODO .... calculate frame within parent frame (inset...)
|
||||
// calculate frame within parent frame
|
||||
off_t offset = partition->Offset();
|
||||
off_t size = partition->Size();
|
||||
off_t parentOffset = partition->Parent()->Offset();
|
||||
off_t parentSize = partition->Parent()->Size();
|
||||
float width = frame.Width() * size / parentSize;
|
||||
frame.left = roundf(frame.left + frame.Width()
|
||||
* (offset - parentOffset) / parentSize);
|
||||
frame.right = frame.left + width;
|
||||
|
||||
fBoxMap.Put(partition->ID(), PartitionBox(frame, _NextColor()));
|
||||
return true;
|
||||
frame.InsetBy(4, 4);
|
||||
if (frame.right < frame.left)
|
||||
frame.right = frame.left;
|
||||
|
||||
rgb_color color = _NextColor();
|
||||
fBoxMap.Put(partition->ID(), PartitionBox(frame, color));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Draw(BView* view)
|
||||
{
|
||||
PartitionBoxMap::Iterator iterator = fBoxMap.GetIterator();
|
||||
while (iterator.HasNext()) {
|
||||
PartitionBoxMap::Entry entry = iterator.Next();
|
||||
PartitionBox box = entry.value;
|
||||
BRect frame = box.frame;
|
||||
if (entry.key == fSelectedPartition) {
|
||||
fView->SetHighColor(80, 80, 80);
|
||||
frame.InsetBy(-2, -2);
|
||||
fView->StrokeRect(frame);
|
||||
frame.InsetBy(1, 1);
|
||||
fView->StrokeRect(frame);
|
||||
frame.InsetBy(1, 1);
|
||||
}
|
||||
|
||||
fView->SetHighColor(box.color);
|
||||
fView->FillRect(frame);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -103,6 +140,7 @@ public:
|
||||
BView* fView;
|
||||
PartitionBoxMap fBoxMap;
|
||||
int32 fColorIndex;
|
||||
partition_id fSelectedPartition;
|
||||
};
|
||||
|
||||
|
||||
@@ -114,7 +152,7 @@ DiskView::DiskView(const BRect& frame, uint32 resizeMode)
|
||||
, fDisk(NULL)
|
||||
, fSelectedParition(-1)
|
||||
{
|
||||
for (int32 i = 0; i < 256; i++) {
|
||||
for (int32 i = 0; i < kMaxPartitionColors; i++) {
|
||||
kPartitionColors[i].red = (i * 1675) & 0xff;
|
||||
kPartitionColors[i].green = (i * 318) & 0xff;
|
||||
kPartitionColors[i].blue = (i * 9328) & 0xff;
|
||||
@@ -144,12 +182,19 @@ DiskView::Draw(BRect updateRect)
|
||||
// TODO: render the partitions (use PartitionDrawer to iterate our disk)
|
||||
SetHighColor(255, 255, 120);
|
||||
FillRect(bounds);
|
||||
|
||||
PartitionDrawer drawer(this, fSelectedParition);
|
||||
BDiskDeviceRoster roster;
|
||||
roster.VisitEachPartition(&drawer, fDisk);
|
||||
|
||||
drawer.Draw(this);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DiskView::SetDisk(BDiskDevice* disk, partition_id selectedPartition)
|
||||
{
|
||||
printf("DiskView::SetDisk(%p, %ld)\n", disk, selectedPartition);
|
||||
delete fDisk;
|
||||
fDisk = disk;
|
||||
fSelectedParition = selectedPartition;
|
||||
|
||||
@@ -298,8 +298,8 @@ DriveVisitor::Visit(BDiskDevice* device)
|
||||
{
|
||||
fPartitionList->AddPartition(device);
|
||||
|
||||
printf("Visit(%p)\n", device);
|
||||
dump_partition_info(device);
|
||||
// printf("Visit(%p)\n", device);
|
||||
// dump_partition_info(device);
|
||||
|
||||
return false; // Don't stop yet!
|
||||
}
|
||||
@@ -310,8 +310,8 @@ DriveVisitor::Visit(BPartition* partition, int32 level)
|
||||
{
|
||||
fPartitionList->AddPartition(partition);
|
||||
|
||||
printf("Visit(%p, %ld)\n", partition, level);
|
||||
dump_partition_info(partition);
|
||||
// printf("Visit(%p, %ld)\n", partition, level);
|
||||
// dump_partition_info(partition);
|
||||
|
||||
return false; // Don't stop yet!
|
||||
}
|
||||
|
||||
@@ -12,55 +12,62 @@
|
||||
#include <Path.h>
|
||||
|
||||
|
||||
static const char* kUnavailableString = "";
|
||||
|
||||
enum {
|
||||
// kBitmapColumn,
|
||||
kDeviceColumn,
|
||||
kFilesystemColumn,
|
||||
kVolumeNameColumn,
|
||||
kMountedAtColumn,
|
||||
kSizeColumn
|
||||
};
|
||||
|
||||
|
||||
PartitionListRow::PartitionListRow(BPartition* partition)
|
||||
: Inherited()
|
||||
, fPartitionID(partition->ID())
|
||||
{
|
||||
// SetField(new BBitmapField(NULL), kBitmapColumn);
|
||||
|
||||
BPath path;
|
||||
char size[1024];
|
||||
|
||||
partition->GetPath(&path);
|
||||
|
||||
SetField(new BBitmapField(NULL), 0);
|
||||
|
||||
// if (partition->IsDevice()) // Only show device path for actual devices (so only for /dev/disk/..../raw entries)
|
||||
SetField(new BStringField(path.Path()), 1);
|
||||
// else
|
||||
// SetField(new BStringField("n/a"), 1);
|
||||
SetField(new BStringField(path.Path()), kDeviceColumn);
|
||||
|
||||
// if (partition->ContainsPartitioningSystem()) {
|
||||
// SetField(new BStringField(partition->ContentType()), 2);
|
||||
// SetField(new BStringField(partition->ContentType()), kFilesystemColumn);
|
||||
// } else {
|
||||
// SetField(new BStringField("n/a"), 2);
|
||||
// SetField(new BStringField(kUnavailableString), kFilesystemColumn);
|
||||
// }
|
||||
|
||||
if (partition->ContainsFileSystem()) {
|
||||
SetField(new BStringField(partition->ContentType()), 2); // Filesystem
|
||||
SetField(new BStringField(partition->ContentName()), 3); // Volume Name
|
||||
SetField(new BStringField(partition->ContentType()), kFilesystemColumn);
|
||||
SetField(new BStringField(partition->ContentName()), kVolumeNameColumn);
|
||||
} else {
|
||||
SetField(new BStringField("n/a"), 2);
|
||||
SetField(new BStringField("n/a"), 3);
|
||||
SetField(new BStringField(kUnavailableString), kFilesystemColumn);
|
||||
SetField(new BStringField(kUnavailableString), kVolumeNameColumn);
|
||||
}
|
||||
|
||||
if (partition->IsMounted() && partition->GetMountPoint(&path) == B_OK) {
|
||||
SetField(new BStringField(path.Path()), 4);
|
||||
SetField(new BStringField(path.Path()), kMountedAtColumn);
|
||||
} else {
|
||||
SetField(new BStringField("n/a"), 4);
|
||||
SetField(new BStringField(kUnavailableString), kMountedAtColumn);
|
||||
}
|
||||
|
||||
SetField(new BStringField(string_for_size(partition->Size(), size)), 5);
|
||||
char size[1024];
|
||||
SetField(new BStringField(string_for_size(partition->Size(), size)), 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), 0);
|
||||
AddColumn(new BStringColumn("Device", 100, 50, 500, B_TRUNCATE_MIDDLE), 1);
|
||||
AddColumn(new BStringColumn("Filesystem", 100, 50, 500, B_TRUNCATE_MIDDLE), 2);
|
||||
AddColumn(new BStringColumn("Volume Name", 100, 50, 500, B_TRUNCATE_MIDDLE), 3);
|
||||
AddColumn(new BStringColumn("Mounted At", 100, 50, 500, B_TRUNCATE_MIDDLE), 4);
|
||||
AddColumn(new BStringColumn("Size", 100, 50, 500, B_TRUNCATE_END), 5);
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user