From bec6af721ffee36d733d823f509b07364a30c1c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 9 Dec 2007 15:41:31 +0000 Subject: [PATCH] * 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 --- src/preferences/drivesetup/DiskView.cpp | 158 +++++++++++++++++++ src/preferences/drivesetup/DiskView.h | 31 ++++ src/preferences/drivesetup/DriveSetup.cpp | 1 - src/preferences/drivesetup/Jamfile | 15 +- src/preferences/drivesetup/MainWindow.cpp | 54 ++++++- src/preferences/drivesetup/MainWindow.h | 8 +- src/preferences/drivesetup/PartitionList.cpp | 14 +- src/preferences/drivesetup/PartitionList.h | 3 +- src/preferences/drivesetup/run | 18 +++ 9 files changed, 282 insertions(+), 20 deletions(-) create mode 100644 src/preferences/drivesetup/DiskView.cpp create mode 100644 src/preferences/drivesetup/DiskView.h create mode 100644 src/preferences/drivesetup/run diff --git a/src/preferences/drivesetup/DiskView.cpp b/src/preferences/drivesetup/DiskView.cpp new file mode 100644 index 0000000000..90860a7e8e --- /dev/null +++ b/src/preferences/drivesetup/DiskView.cpp @@ -0,0 +1,158 @@ +/* + * Copyright 2007 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT license. + * + * Authors: + * Stephan Aßmus + */ +#include "DiskView.h" + +#include +#include + +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 PartitionKey; + typedef HashMap 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(); +} diff --git a/src/preferences/drivesetup/DiskView.h b/src/preferences/drivesetup/DiskView.h new file mode 100644 index 0000000000..64172ea597 --- /dev/null +++ b/src/preferences/drivesetup/DiskView.h @@ -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 +#include + + +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 diff --git a/src/preferences/drivesetup/DriveSetup.cpp b/src/preferences/drivesetup/DriveSetup.cpp index 7a6f03e5ac..0beefe96b9 100644 --- a/src/preferences/drivesetup/DriveSetup.cpp +++ b/src/preferences/drivesetup/DriveSetup.cpp @@ -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) { diff --git a/src/preferences/drivesetup/Jamfile b/src/preferences/drivesetup/Jamfile index f5decdbad6..f665751a63 100644 --- a/src/preferences/drivesetup/Jamfile +++ b/src/preferences/drivesetup/Jamfile @@ -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 ; +} + diff --git a/src/preferences/drivesetup/MainWindow.cpp b/src/preferences/drivesetup/MainWindow.cpp index acb302275d..2ee7cb0b84 100644 --- a/src/preferences/drivesetup/MainWindow.cpp +++ b/src/preferences/drivesetup/MainWindow.cpp @@ -8,6 +8,7 @@ * Stephan Aßmus */ #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(_topLevelRow); + PartitionListRow* selectedRow + = dynamic_cast(_selectedRow); + + if (!topLevelRow || !selectedRow) + return; + + BDiskDevice* disk = new BDiskDevice(); + disk->SetTo(topLevelRow->ID()); + fDiskView->SetDisk(disk, selectedRow->ID()); +} + + // #pragma mark - DriveVisitor diff --git a/src/preferences/drivesetup/MainWindow.h b/src/preferences/drivesetup/MainWindow.h index 7d400be562..52b924d280 100644 --- a/src/preferences/drivesetup/MainWindow.h +++ b/src/preferences/drivesetup/MainWindow.h @@ -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; }; diff --git a/src/preferences/drivesetup/PartitionList.cpp b/src/preferences/drivesetup/PartitionList.cpp index beb01f4b69..86530370d9 100644 --- a/src/preferences/drivesetup/PartitionList.cpp +++ b/src/preferences/drivesetup/PartitionList.cpp @@ -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); diff --git a/src/preferences/drivesetup/PartitionList.h b/src/preferences/drivesetup/PartitionList.h index f0ef4a925a..44481b7281 100644 --- a/src/preferences/drivesetup/PartitionList.h +++ b/src/preferences/drivesetup/PartitionList.h @@ -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); diff --git a/src/preferences/drivesetup/run b/src/preferences/drivesetup/run new file mode 100644 index 0000000000..aa1f8de50a --- /dev/null +++ b/src/preferences/drivesetup/run @@ -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 +