* 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 "DiskView.h"
|
||||||
|
|
||||||
|
#include <DiskDeviceRoster.h>
|
||||||
#include <DiskDeviceVisitor.h>
|
#include <DiskDeviceVisitor.h>
|
||||||
#include <HashMap.h>
|
#include <HashMap.h>
|
||||||
|
|
||||||
@@ -61,17 +62,18 @@ struct PartitionBox {
|
|||||||
|
|
||||||
class PartitionDrawer : public BDiskDeviceVisitor {
|
class PartitionDrawer : public BDiskDeviceVisitor {
|
||||||
public:
|
public:
|
||||||
PartitionDrawer(BView* view)
|
PartitionDrawer(BView* view, partition_id selectedPartition)
|
||||||
: fView(view)
|
: fView(view)
|
||||||
, fBoxMap()
|
, fBoxMap()
|
||||||
, fColorIndex(0)
|
, fColorIndex(0)
|
||||||
|
, fSelectedPartition(selectedPartition)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool Visit(BDiskDevice* device)
|
virtual bool Visit(BDiskDevice* device)
|
||||||
{
|
{
|
||||||
fBoxMap.Put(device->ID(), PartitionBox(fView->Bounds(), _NextColor()));
|
fBoxMap.Put(device->ID(), PartitionBox(fView->Bounds(), _NextColor()));
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool Visit(BPartition* partition, int32 level)
|
virtual bool Visit(BPartition* partition, int32 level)
|
||||||
@@ -81,10 +83,45 @@ public:
|
|||||||
|
|
||||||
PartitionBox parent = fBoxMap.Get(partition->Parent()->ID());
|
PartitionBox parent = fBoxMap.Get(partition->Parent()->ID());
|
||||||
BRect frame = parent.frame;
|
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()));
|
frame.InsetBy(4, 4);
|
||||||
return true;
|
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:
|
private:
|
||||||
@@ -103,6 +140,7 @@ public:
|
|||||||
BView* fView;
|
BView* fView;
|
||||||
PartitionBoxMap fBoxMap;
|
PartitionBoxMap fBoxMap;
|
||||||
int32 fColorIndex;
|
int32 fColorIndex;
|
||||||
|
partition_id fSelectedPartition;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -114,7 +152,7 @@ DiskView::DiskView(const BRect& frame, uint32 resizeMode)
|
|||||||
, fDisk(NULL)
|
, fDisk(NULL)
|
||||||
, fSelectedParition(-1)
|
, fSelectedParition(-1)
|
||||||
{
|
{
|
||||||
for (int32 i = 0; i < 256; i++) {
|
for (int32 i = 0; i < kMaxPartitionColors; i++) {
|
||||||
kPartitionColors[i].red = (i * 1675) & 0xff;
|
kPartitionColors[i].red = (i * 1675) & 0xff;
|
||||||
kPartitionColors[i].green = (i * 318) & 0xff;
|
kPartitionColors[i].green = (i * 318) & 0xff;
|
||||||
kPartitionColors[i].blue = (i * 9328) & 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)
|
// TODO: render the partitions (use PartitionDrawer to iterate our disk)
|
||||||
SetHighColor(255, 255, 120);
|
SetHighColor(255, 255, 120);
|
||||||
FillRect(bounds);
|
FillRect(bounds);
|
||||||
|
|
||||||
|
PartitionDrawer drawer(this, fSelectedParition);
|
||||||
|
BDiskDeviceRoster roster;
|
||||||
|
roster.VisitEachPartition(&drawer, fDisk);
|
||||||
|
|
||||||
|
drawer.Draw(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DiskView::SetDisk(BDiskDevice* disk, partition_id selectedPartition)
|
DiskView::SetDisk(BDiskDevice* disk, partition_id selectedPartition)
|
||||||
{
|
{
|
||||||
|
printf("DiskView::SetDisk(%p, %ld)\n", disk, selectedPartition);
|
||||||
delete fDisk;
|
delete fDisk;
|
||||||
fDisk = disk;
|
fDisk = disk;
|
||||||
fSelectedParition = selectedPartition;
|
fSelectedParition = selectedPartition;
|
||||||
|
|||||||
@@ -298,8 +298,8 @@ DriveVisitor::Visit(BDiskDevice* device)
|
|||||||
{
|
{
|
||||||
fPartitionList->AddPartition(device);
|
fPartitionList->AddPartition(device);
|
||||||
|
|
||||||
printf("Visit(%p)\n", device);
|
// printf("Visit(%p)\n", device);
|
||||||
dump_partition_info(device);
|
// dump_partition_info(device);
|
||||||
|
|
||||||
return false; // Don't stop yet!
|
return false; // Don't stop yet!
|
||||||
}
|
}
|
||||||
@@ -310,8 +310,8 @@ DriveVisitor::Visit(BPartition* partition, int32 level)
|
|||||||
{
|
{
|
||||||
fPartitionList->AddPartition(partition);
|
fPartitionList->AddPartition(partition);
|
||||||
|
|
||||||
printf("Visit(%p, %ld)\n", partition, level);
|
// printf("Visit(%p, %ld)\n", partition, level);
|
||||||
dump_partition_info(partition);
|
// dump_partition_info(partition);
|
||||||
|
|
||||||
return false; // Don't stop yet!
|
return false; // Don't stop yet!
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,55 +12,62 @@
|
|||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
|
||||||
|
|
||||||
|
static const char* kUnavailableString = "";
|
||||||
|
|
||||||
|
enum {
|
||||||
|
// kBitmapColumn,
|
||||||
|
kDeviceColumn,
|
||||||
|
kFilesystemColumn,
|
||||||
|
kVolumeNameColumn,
|
||||||
|
kMountedAtColumn,
|
||||||
|
kSizeColumn
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
PartitionListRow::PartitionListRow(BPartition* partition)
|
PartitionListRow::PartitionListRow(BPartition* partition)
|
||||||
: Inherited()
|
: Inherited()
|
||||||
, fPartitionID(partition->ID())
|
, fPartitionID(partition->ID())
|
||||||
{
|
{
|
||||||
|
// SetField(new BBitmapField(NULL), kBitmapColumn);
|
||||||
|
|
||||||
BPath path;
|
BPath path;
|
||||||
char size[1024];
|
|
||||||
|
|
||||||
partition->GetPath(&path);
|
partition->GetPath(&path);
|
||||||
|
SetField(new BStringField(path.Path()), kDeviceColumn);
|
||||||
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);
|
|
||||||
|
|
||||||
// if (partition->ContainsPartitioningSystem()) {
|
// if (partition->ContainsPartitioningSystem()) {
|
||||||
// SetField(new BStringField(partition->ContentType()), 2);
|
// SetField(new BStringField(partition->ContentType()), kFilesystemColumn);
|
||||||
// } else {
|
// } else {
|
||||||
// SetField(new BStringField("n/a"), 2);
|
// SetField(new BStringField(kUnavailableString), kFilesystemColumn);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (partition->ContainsFileSystem()) {
|
if (partition->ContainsFileSystem()) {
|
||||||
SetField(new BStringField(partition->ContentType()), 2); // Filesystem
|
SetField(new BStringField(partition->ContentType()), kFilesystemColumn);
|
||||||
SetField(new BStringField(partition->ContentName()), 3); // Volume Name
|
SetField(new BStringField(partition->ContentName()), kVolumeNameColumn);
|
||||||
} else {
|
} else {
|
||||||
SetField(new BStringField("n/a"), 2);
|
SetField(new BStringField(kUnavailableString), kFilesystemColumn);
|
||||||
SetField(new BStringField("n/a"), 3);
|
SetField(new BStringField(kUnavailableString), kVolumeNameColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (partition->IsMounted() && partition->GetMountPoint(&path) == B_OK) {
|
if (partition->IsMounted() && partition->GetMountPoint(&path) == B_OK) {
|
||||||
SetField(new BStringField(path.Path()), 4);
|
SetField(new BStringField(path.Path()), kMountedAtColumn);
|
||||||
} else {
|
} 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)
|
PartitionListView::PartitionListView(const BRect& frame, uint32 resizeMode)
|
||||||
: Inherited(frame, "storagelist", resizeMode, 0, B_NO_BORDER, true)
|
: Inherited(frame, "storagelist", resizeMode, 0, B_NO_BORDER, true)
|
||||||
{
|
{
|
||||||
AddColumn(new BBitmapColumn("", 20, 20, 100, B_ALIGN_CENTER), 0);
|
// AddColumn(new BBitmapColumn("", 20, 20, 100, B_ALIGN_CENTER), kBitmapColumn);
|
||||||
AddColumn(new BStringColumn("Device", 100, 50, 500, B_TRUNCATE_MIDDLE), 1);
|
AddColumn(new BStringColumn("Device", 150, 50, 500, B_TRUNCATE_MIDDLE), kDeviceColumn);
|
||||||
AddColumn(new BStringColumn("Filesystem", 100, 50, 500, B_TRUNCATE_MIDDLE), 2);
|
AddColumn(new BStringColumn("Filesystem", 100, 50, 500, B_TRUNCATE_MIDDLE), kFilesystemColumn);
|
||||||
AddColumn(new BStringColumn("Volume Name", 100, 50, 500, B_TRUNCATE_MIDDLE), 3);
|
AddColumn(new BStringColumn("Volume Name", 130, 50, 500, B_TRUNCATE_MIDDLE), kVolumeNameColumn);
|
||||||
AddColumn(new BStringColumn("Mounted At", 100, 50, 500, B_TRUNCATE_MIDDLE), 4);
|
AddColumn(new BStringColumn("Mounted At", 100, 50, 500, B_TRUNCATE_MIDDLE), kMountedAtColumn);
|
||||||
AddColumn(new BStringColumn("Size", 100, 50, 500, B_TRUNCATE_END), 5);
|
AddColumn(new BStringColumn("Size", 100, 50, 500, B_TRUNCATE_END, B_ALIGN_RIGHT), kSizeColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user