* some work in progress to display a view of the selected disk device

* build DriveSetup for the test environment, though it doesn't display anything
  in that mode... just to work on some general things, maybe I add a fake
  partition tree just to test things later
* cleanup


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23095 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2007-12-09 15:41:31 +00:00
parent c9d5e8255e
commit bec6af721f
9 changed files with 282 additions and 20 deletions
+158
View File
@@ -0,0 +1,158 @@
/*
* Copyright 2007 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
* Stephan Aßmus <[email protected]>
*/
#include "DiskView.h"
#include <DiskDeviceVisitor.h>
#include <HashMap.h>
using BPrivate::HashMap;
using BPrivate::HashKey32;
static const pattern kStripes = { { 0xc7, 0x8f, 0x1f, 0x3e,
0x7c, 0xf8, 0xf1, 0xe3 } };
static const rgb_color kInvalidColor = { 0, 0, 0, 0 };
static const rgb_color kStripesHigh = { 112, 112, 112, 255 };
static const rgb_color kStripesLow = { 104, 104, 104, 255 };
static const int32 kMaxPartitionColors = 256;
static rgb_color kPartitionColors[kMaxPartitionColors];
struct PartitionBox {
PartitionBox()
: frame(0, 0, -1, -1)
, color(kInvalidColor)
{
}
PartitionBox(const BRect& frame, const rgb_color& color)
: frame(frame)
, color(color)
{
}
PartitionBox(const PartitionBox& other)
: frame(other.frame)
, color(other.color)
{
}
~PartitionBox()
{
}
PartitionBox& operator=(const PartitionBox& other)
{
frame = other.frame;
color = other.color;
return *this;
}
BRect frame;
rgb_color color;
};
class PartitionDrawer : public BDiskDeviceVisitor {
public:
PartitionDrawer(BView* view)
: fView(view)
, fBoxMap()
, fColorIndex(0)
{
}
virtual bool Visit(BDiskDevice* device)
{
fBoxMap.Put(device->ID(), PartitionBox(fView->Bounds(), _NextColor()));
return true;
}
virtual bool Visit(BPartition* partition, int32 level)
{
if (!partition->Parent() || !fBoxMap.ContainsKey(partition->Parent()->ID()))
return false;
PartitionBox parent = fBoxMap.Get(partition->Parent()->ID());
BRect frame = parent.frame;
// TODO .... calculate frame within parent frame (inset...)
fBoxMap.Put(partition->ID(), PartitionBox(frame, _NextColor()));
return true;
}
private:
rgb_color _NextColor()
{
fColorIndex++;
if (fColorIndex > kMaxPartitionColors)
fColorIndex = 0;
return kPartitionColors[fColorIndex];
}
typedef HashKey32<partition_id> PartitionKey;
typedef HashMap<PartitionKey, PartitionBox > PartitionBoxMap;
BView* fView;
PartitionBoxMap fBoxMap;
int32 fColorIndex;
};
// #pragma mark -
DiskView::DiskView(const BRect& frame, uint32 resizeMode)
: Inherited(frame, "diskview", resizeMode, B_WILL_DRAW)
, fDisk(NULL)
, fSelectedParition(-1)
{
for (int32 i = 0; i < 256; i++) {
kPartitionColors[i].red = (i * 1675) & 0xff;
kPartitionColors[i].green = (i * 318) & 0xff;
kPartitionColors[i].blue = (i * 9328) & 0xff;
kPartitionColors[i].alpha = 255;
}
}
DiskView::~DiskView()
{
SetDisk(NULL, -1);
}
void
DiskView::Draw(BRect updateRect)
{
BRect bounds(Bounds());
if (!fDisk) {
SetHighColor(kStripesHigh);
SetLowColor(kStripesLow);
FillRect(bounds, kStripes);
return;
}
// TODO: render the partitions (use PartitionDrawer to iterate our disk)
SetHighColor(255, 255, 120);
FillRect(bounds);
}
void
DiskView::SetDisk(BDiskDevice* disk, partition_id selectedPartition)
{
delete fDisk;
fDisk = disk;
fSelectedParition = selectedPartition;
Invalidate();
}
+31
View File
@@ -0,0 +1,31 @@
/*
* Copyright 2007 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*/
#ifndef DISK_VIEW_H
#define DISK_VIEW_H
#include <DiskDevice.h>
#include <View.h>
class DiskView : public BView {
typedef BView Inherited;
public:
DiskView(const BRect& frame,
uint32 resizeMode);
virtual ~DiskView();
// BView interface
virtual void Draw(BRect updateRect);
void SetDisk(BDiskDevice* disk,
partition_id selectedPartition);
private:
BDiskDevice* fDisk;
partition_id fSelectedParition;
};
#endif // DISK_VIEW_H
@@ -111,7 +111,6 @@ DriveSetup::_RestoreSettings()
fprintf(stderr, "failed to unflatten settings: %s\n", strerror(ret));
return ret;
}
fSettings.PrintToStream();
ret = fWindow->RestoreSettings(&fSettings);
if (ret < B_OK) {
+11 -4
View File
@@ -1,16 +1,23 @@
SubDir HAIKU_TOP src preferences drivesetup ;
SetSubDirSupportedPlatformsBeOSCompatible ;
AddSubDirSupportedPlatforms libbe_test ;
UsePrivateHeaders interface storage shared ;
AddResources DriveSetup : DriveSetup.rdef ;
UsePrivateHeaders interface shared storage ;
Preference DriveSetup :
DiskView.cpp
DriveSetup.cpp
MainWindow.cpp
PartitionList.cpp
Support.cpp
:
be
:
DriveSetup.rdef
;
if ( $(TARGET_PLATFORM) = libbe_test ) {
HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : DriveSetup
: tests!apps ;
}
+52 -2
View File
@@ -8,6 +8,7 @@
* Stephan Aßmus <[email protected]>
*/
#include "MainWindow.h"
#include "DiskView.h"
#include "PartitionList.h"
#include "Support.h"
@@ -51,6 +52,8 @@ enum {
MSG_EJECT = 'ejct',
MSG_SURFACE_TEST = 'sfct',
MSG_RESCAN = 'rscn',
MSG_PARTITION_ROW_SELECTED = 'prsl',
};
@@ -93,11 +96,24 @@ MainWindow::MainWindow(BRect frame)
createMenu->AddItem(new BMenuItem("Logical",
new BMessage(MSG_CREATE_LOGICAL)));
// add DiskView
BRect r(Bounds());
r.top = rootMenu->Frame().bottom + 1;
fListView = new PartitionListView(r);
r.bottom = floorf(r.top + r.Height() * 0.33);
fDiskView = new DiskView(r, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
AddChild(fDiskView);
// add PartitionListView
r.top = r.bottom + 2;
r.bottom = Bounds().bottom;
r.InsetBy(-1, -1);
fListView = new PartitionListView(r, B_FOLLOW_ALL);
AddChild(fListView);
// configure PartitionListView
fListView->SetSelectionMessage(new BMessage(MSG_PARTITION_ROW_SELECTED));
fListView->SetTarget(this);
// Populate the Initialiaze menu with the available file systems
_ScanFileSystems();
@@ -147,7 +163,12 @@ MainWindow::MessageReceived(BMessage* message)
case MSG_RESCAN:
_ScanDrives();
break;
case MSG_PARTITION_ROW_SELECTED:
printf("MSG_PARTITION_ROW_SELECTED\n");
_AdaptToSelectedPartition();
break;
default:
BWindow::MessageReceived(message);
break;
@@ -227,6 +248,35 @@ MainWindow::_ScanFileSystems()
}
void
MainWindow::_AdaptToSelectedPartition()
{
BRow* _selectedRow = fListView->CurrentSelection();
if (!_selectedRow) {
fDiskView->SetDisk(NULL, -1);
return;
}
// recurse to top level row
BRow* _topLevelRow = _selectedRow;
BRow* parent = NULL;
while (fListView->FindParent(_topLevelRow, &parent, NULL))
_topLevelRow = parent;
PartitionListRow* topLevelRow
= dynamic_cast<PartitionListRow*>(_topLevelRow);
PartitionListRow* selectedRow
= dynamic_cast<PartitionListRow*>(_selectedRow);
if (!topLevelRow || !selectedRow)
return;
BDiskDevice* disk = new BDiskDevice();
disk->SetTo(topLevelRow->ID());
fDiskView->SetDisk(disk, selectedRow->ID());
}
// #pragma mark - DriveVisitor
+3 -5
View File
@@ -13,6 +13,7 @@
class BDiskDevice;
class BPartition;
class BMenu;
class DiskView;
class PartitionListView;
@@ -28,18 +29,15 @@ public:
status_t StoreSettings(BMessage* archive) const;
status_t RestoreSettings(BMessage* archive);
// These are public for visitor....
void AddPartition(BPartition* partition,
int32 level);
void AddDrive(BDiskDevice* device);
private:
void _ScanDrives();
void _ScanFileSystems();
void _AdaptToSelectedPartition();
BDiskDeviceRoster fDDRoster;
PartitionListView* fListView;
DiskView* fDiskView;
BMenu* fInitMenu;
};
+7 -7
View File
@@ -21,7 +21,7 @@ PartitionListRow::PartitionListRow(BPartition* partition)
partition->GetPath(&path);
// SetField(new BBitmapField(NULL), 0);
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);
@@ -38,24 +38,24 @@ PartitionListRow::PartitionListRow(BPartition* partition)
SetField(new BStringField(partition->ContentType()), 2); // Filesystem
SetField(new BStringField(partition->ContentName()), 3); // Volume Name
} else {
SetField(new BStringField(""), 2);
SetField(new BStringField(""), 3);
SetField(new BStringField("n/a"), 2);
SetField(new BStringField("n/a"), 3);
}
if (partition->IsMounted() && partition->GetMountPoint(&path) == B_OK) {
SetField(new BStringField(path.Path()), 4);
} else {
SetField(new BStringField(""), 4);
SetField(new BStringField("n/a"), 4);
}
SetField(new BStringField(string_for_size(partition->Size(), size)), 5);
}
PartitionListView::PartitionListView(const BRect& frame)
: Inherited(frame, "storagelist", B_FOLLOW_ALL, 0, B_NO_BORDER, true)
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 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);
+2 -1
View File
@@ -32,7 +32,8 @@ private:
class PartitionListView : public BColumnListView {
typedef BColumnListView Inherited;
public:
PartitionListView(const BRect& frame);
PartitionListView(const BRect& frame,
uint32 resizeMode);
PartitionListRow* FindRow(partition_id id,
PartitionListRow* parent = NULL);
+18
View File
@@ -0,0 +1,18 @@
#!/bin/sh
../../../generated/tests/libbe_test/x86/apps/run_haiku_registrar || exit
if test -f ../../../generated/tests/libbe_test/x86/apps/haiku_app_server; then
../../../generated/tests/libbe_test/x86/apps//haiku_app_server &
else
echo "You need to \"TARGET_PLATFORM=libbe_test jam install-test-apps\" first."
fi
sleep 1s
if test -f ../../../generated/tests/libbe_test/x86/apps/DriveSetup; then
../../../generated/tests/libbe_test/x86/apps/DriveSetup
else
echo "You need to \"TARGET_PLATFORM=libbe_test jam install-test-apps\" first."
fi