More work on DriveSetup. Will now show all recognized disks/partitions in hierarchical format.

It still looks aweful, partly because of BColumnListView drawing.
Please note that the partition-order is wrong, due to funky sorting in BColumnListView. This will be fixed tommorow :)



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18084 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ithamar R. Adema
2006-07-10 00:53:57 +00:00
parent d3eab0eb78
commit 9e17884040
6 changed files with 213 additions and 148 deletions
+1 -1
View File
@@ -4,6 +4,6 @@ UsePrivateHeaders interface storage shared ;
AddResources DriveSetup : DriveSetup.rdef ;
Preference DriveSetup : main.cpp MainWindow.cpp PosSettings.cpp ;
Preference DriveSetup : main.cpp MainWindow.cpp PartitionList.cpp PosSettings.cpp ;
LinkAgainst DriveSetup : be ;
+71 -113
View File
@@ -6,7 +6,7 @@
*/
#include "MainWindow.h"
#include "PartitionList.h"
#include "PosSettings.h"
#include <interface/MenuItem.h>
@@ -19,6 +19,7 @@
#include <app/Application.h>
#include <storage/DiskDeviceVisitor.h>
#include <storage/DiskSystem.h>
#include <storage/DiskDevice.h>
#include <storage/Partition.h>
#include <storage/Path.h>
@@ -26,12 +27,12 @@
class DriveVisitor : public BDiskDeviceVisitor
{
public:
DriveVisitor(MainWindow* win);
DriveVisitor(PartitionListView* list);
bool Visit(BDiskDevice *device);
bool Visit(BPartition *partition, int32 level);
private:
MainWindow* fDSWindow;
PartitionListView* fPartitionList;
};
const char*
@@ -61,24 +62,45 @@ SizeAsString(off_t size, char *string)
return string;
}
#if DEBUG
static void
dump_partition_info(BPartition* partition)
{
char size[1024];
printf("\tOffset(): %Ld\n", partition->Offset());
printf("\tSize(): %s\n", SizeAsString(partition->Size(),size));
printf("\tContentSize(): %s\n", SizeAsString(partition->ContentSize(), size));
printf("\tBlockSize(): %ld\n", partition->BlockSize());
printf("\tIndex(): %ld\n", partition->Index());
printf("\tStatus(): %ld\n\n", partition->Status());
printf("\tContainsFileSystem(): %s\n", partition->ContainsFileSystem() ? "true" : "false");
printf("\tContainsPartitioningSystem(): %s\n\n", partition->ContainsPartitioningSystem() ? "true" : "false");
printf("\tIsDevice(): %s\n", partition->IsDevice() ? "true" : "false");
printf("\tIsReadOnly(): %s\n", partition->IsReadOnly() ? "true" : "false");
printf("\tIsMounted(): %s\n", partition->IsMounted() ? "true" : "false");
printf("\tIsBusy(): %s\n\n", partition->IsBusy() ? "true" : "false");
printf("\tFlags(): %lx\n\n", partition->Flags());
printf("\tName(): %s\n", partition->Name());
printf("\tContentName(): %s\n", partition->ContentName());
printf("\tType(): %s\n", partition->Type());
printf("\tContentType(): %s\n", partition->ContentType());
printf("\tID(): %lx\n\n", partition->ID());
}
#endif
/**
* Constructor.
* @param frame The size to make the window.
*/
MainWindow::MainWindow(BRect frame, PosSettings *Settings)
: BWindow(frame, "DriveSetup", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
: BWindow(frame, "DriveSetup", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
{
BRect bRect;
BMenu *partitionMenu, *initMenu;
BMenu *menu;
BMenu *tmpMenu;
BMenuItem *emptyItem;
fSettings = Settings;
bRect = Bounds();
bRect.bottom = 18.0;
BMenuBar* rootMenu = new BMenuBar(bRect, "root menu");
BMenuBar* rootMenu = new BMenuBar(Bounds(), "root menu");
//Setup Mount menu
menu = new BMenu("Mount");
menu->AddItem(new BMenuItem("Mount All Partitions", new BMessage(MOUNT_MOUNT_ALL_MSG), 'M'));
@@ -87,19 +109,16 @@ MainWindow::MainWindow(BRect frame, PosSettings *Settings)
//Setup Unmount menu
menu = new BMenu("Unmount");
emptyItem = new BMenuItem("<empty>", NULL);
emptyItem->SetEnabled(false);
menu->AddItem(emptyItem);
rootMenu->AddItem(menu);
//Setup Setup menu
menu = new BMenu("Setup");
menu->AddItem(new BMenuItem("Format", new BMessage(SETUP_FORMAT_MSG), 'F'));
tmpMenu = new BMenu("Partition");
menu->AddItem(tmpMenu);
tmpMenu = new BMenu("Initialize");
partitionMenu = new BMenu("Partition");
menu->AddItem(partitionMenu);
initMenu = new BMenu("Initialize");
//add menu for formats
menu->AddItem(tmpMenu);
menu->AddItem(initMenu);
rootMenu->AddItem(menu);
//Setup Options menu
@@ -118,18 +137,26 @@ MainWindow::MainWindow(BRect frame, PosSettings *Settings)
BRect r(Bounds());
r.top = rootMenu->Frame().bottom +1;
fListView = new BColumnListView(r, "storagelist", B_FOLLOW_ALL, 0, B_PLAIN_BORDER, true);
fListView->AddColumn(new BStringColumn("Device", 100, 500, 50, 0), 1);
fListView->AddColumn(new BStringColumn("Map style", 100, 500, 50, 0), 2);
fListView->AddColumn(new BStringColumn("Partition Type", 100, 500, 50, 0), 3);
fListView->AddColumn(new BStringColumn("Filesystem", 100, 500, 50, 0), 4);
fListView->AddColumn(new BStringColumn("Volume Name", 100, 500, 50, 0), 5);
fListView->AddColumn(new BStringColumn("Mounted At", 100, 500, 50, 0), 6);
fListView->AddColumn(new BStringColumn("Size", 100, 500, 50, 0), 7);
fListView = new PartitionListView(r);
AddChild(fListView);
// Now update filesystem/partition menus with values
BDiskSystem diskSystem;
fDDRoster.RewindDiskSystems();
while(fDDRoster.GetNextDiskSystem(&diskSystem) == B_OK) {
if (diskSystem.IsPartitioningSystem()) {
BMessage* msg = new BMessage(SETUP_PARTITION_SELECTED_MSG);
msg->AddString("bdisksystem:name", diskSystem.Name());
partitionMenu->AddItem(new BMenuItem(diskSystem.PrettyName(), msg));
} else if (diskSystem.IsFileSystem()) {
BMessage* msg = new BMessage(SETUP_INITIALIZE_MSG);
msg->AddString("bdisksystem:name", diskSystem.Name());
initMenu->AddItem(new BMenuItem(diskSystem.PrettyName(), msg));
}
}
// Now visit all disks in the system and show their contents
DriveVisitor driveVisitor(this);
DriveVisitor driveVisitor(fListView);
BPartition *partition = NULL;
BDiskDevice device;
fDDRoster.VisitEachPartition(&driveVisitor, &device, &partition);
@@ -211,95 +238,21 @@ MainWindow::QuitRequested()
return accepted;
}
static void
dump_partition_info(BPartition* partition)
{
printf("\tOffset(): %Ld\n", partition->Offset());
printf("\tSize(): %Ld\n", partition->Size());
printf("\tContentSize(): %Ld\n", partition->ContentSize());
printf("\tBlockSize(): %ld\n", partition->BlockSize());
printf("\tIndex(): %ld\n", partition->Index());
printf("\tStatus(): %ld\n\n", partition->Status());
printf("\tContainsFileSystem(): %s\n", partition->ContainsFileSystem() ? "true" : "false");
printf("\tContainsPartitioningSystem(): %s\n\n", partition->ContainsPartitioningSystem() ? "true" : "false");
printf("\tIsDevice(): %s\n", partition->IsDevice() ? "true" : "false");
printf("\tIsReadOnly(): %s\n", partition->IsReadOnly() ? "true" : "false");
printf("\tIsMounted(): %s\n", partition->IsMounted() ? "true" : "false");
printf("\tIsBusy(): %s\n\n", partition->IsBusy() ? "true" : "false");
printf("\tFlags(): %lx\n\n", partition->Flags());
printf("\tName(): %s\n", partition->Name());
printf("\tContentName(): %s\n", partition->ContentName());
printf("\tType(): %s\n", partition->Type());
printf("\tContentType(): %s\n", partition->ContentType());
printf("\tID(): %x\n\n", partition->ID());
}
void
MainWindow::AddDrive(BDiskDevice* device)
{
printf("AddDrive(%p)\n", device);
BPath path;
if (device->GetPath(&path) == B_OK) {
BRow* row = new BRow();
row->SetField(new BStringField(path.Path()), 1);
printf("\tPath=%s\n", path.Path());
if (device->ContainsPartitioningSystem()) {
row->SetField(new BStringField(device->Type()), 3);
}
char size[1024];
row->SetField(new BStringField(SizeAsString(device->Size(), size)), 7);
fListView->AddRow(row);
}
dump_partition_info(device);
}
void
MainWindow::AddPartition(BPartition *partition, int32 level)
{
printf("AddPartition(%p, %d)\n", partition, level);
BPath path;
if (partition->GetPath(&path) == B_OK) {
BRow* row = new BRow();
row->SetField(new BStringField(path.Path()), 1);
printf("\tPath=%s\n", path.Path());
if (partition->ContainsFileSystem()) {
row->SetField(new BStringField(partition->Type()), 3); // Partition Type
row->SetField(new BStringField(partition->ContentType()), 4); // Filesystem
row->SetField(new BStringField(partition->ContentName()), 5); // Volume Name
if (partition->GetMountPoint(&path) == B_OK)
row->SetField(new BStringField(path.Path()), 6);
}
char size[1024];
row->SetField(new BStringField(SizeAsString(partition->Size(), size)), 7);
fListView->AddRow(row);
}
dump_partition_info(partition);
}
DriveVisitor::DriveVisitor(MainWindow* win)
: fDSWindow(win)
DriveVisitor::DriveVisitor(PartitionListView* list)
: fPartitionList(list)
{
}
bool
DriveVisitor::Visit(BDiskDevice* device)
{
if (fDSWindow != NULL)
fDSWindow->AddDrive(device);
if (fPartitionList != NULL)
fPartitionList->AddPartition(device);
DEBUG_ONLY(
printf("Visit(%p)\n", device);
dump_partition_info(device);
);
return false; // Don't stop yet!
}
@@ -307,8 +260,13 @@ DriveVisitor::Visit(BDiskDevice* device)
bool
DriveVisitor::Visit(BPartition* partition, int32 level)
{
if (fDSWindow != NULL)
fDSWindow->AddPartition(partition, level);
if (fPartitionList != NULL)
fPartitionList->AddPartition(partition);
DEBUG_ONLY(
printf("Visit(%p, %d)\n", partition, level);
dump_partition_info(partition);
);
return false; // Don't stop yet!
}
+2 -2
View File
@@ -24,7 +24,7 @@
class PosSettings;
class BPartition;
class BDiskDevice;
class BColumnListView;
class PartitionListView;
/**
* The main window of the app.
@@ -37,7 +37,7 @@
private:
PosSettings* fSettings;
BDiskDeviceRoster fDDRoster;
BColumnListView* fListView;
PartitionListView* fListView;
public:
MainWindow(BRect frame, PosSettings *fSettings);
@@ -0,0 +1,105 @@
#include "PartitionList.h"
#include <interface/ColumnTypes.h>
#include <storage/Path.h>
extern const char*
SizeAsString(off_t size, char *string);; //FIXME: from MainWindow.cpp
PartitionListRow::PartitionListRow(BPartition* partition)
: Inherited(),
fPartitionID(partition->ID())
{
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(""), 1);
if (partition->ContainsPartitioningSystem()) {
SetField(new BStringField(partition->ContentType()), 2);
} else {
SetField(new BStringField("n/a"), 2);
}
// For now, Partition type is always empty (as we do not care)
SetField(new BStringField(""), 3);
if (partition->ContainsFileSystem()) {
SetField(new BStringField(partition->ContentType()), 4); // Filesystem
SetField(new BStringField(partition->ContentName()), 5); // Volume Name
} else {
SetField(new BStringField(""), 4);
SetField(new BStringField(""), 5);
}
if (partition->IsMounted() && partition->GetMountPoint(&path) == B_OK) {
SetField(new BStringField(path.Path()), 6);
} else {
SetField(new BStringField(""), 6);
}
SetField(new BStringField(SizeAsString(partition->Size(), size)), 7);
}
PartitionListView::PartitionListView(const BRect& frame)
: Inherited(frame, "storagelist", B_FOLLOW_ALL, 0, B_PLAIN_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("Map style", 100, 50, 500, B_TRUNCATE_MIDDLE), 2);
AddColumn(new BStringColumn("Partition Type", 100, 50, 500, B_TRUNCATE_MIDDLE), 3);
AddColumn(new BStringColumn("Filesystem", 100, 50, 500, B_TRUNCATE_MIDDLE), 4);
AddColumn(new BStringColumn("Volume Name", 100, 50, 500, B_TRUNCATE_MIDDLE), 5);
AddColumn(new BStringColumn("Mounted At", 100, 50, 500, B_TRUNCATE_MIDDLE), 6);
AddColumn(new BStringColumn("Size", 100, 50, 500, B_TRUNCATE_END), 7);
}
PartitionListRow*
PartitionListView::FindRow(partition_id id)
{
for (int32 idx=0; idx < CountRows(); idx++) {
PartitionListRow* item = dynamic_cast<PartitionListRow*>(RowAt(idx));
if (item != NULL && item->ID() == id)
return item;
}
return NULL;
}
PartitionListRow*
PartitionListView::AddPartition(BPartition* partition)
{
PartitionListRow* parent = NULL;
PartitionListRow* partitionrow = NULL;
// Forget about it if this partition is already in the listview
if ((partitionrow=FindRow(partition->ID())) != NULL)
return partitionrow;
// Create the row for this partition
partitionrow = new PartitionListRow(partition);
// If this partition has a parent...
if (partition->Parent() != NULL) {
// check if it is in the listview
parent = FindRow(partition->Parent()->ID());
// If parent of this partition is not yet in the list
if (parent == NULL) //add it
parent = AddPartition(partition->Parent());
// Now it is ok to add this partition under its parent
AddRow(partitionrow, parent);
} else {
// If this partition has no parent, add it in the 'root'
AddRow(partitionrow);
}
return partitionrow;
}
@@ -0,0 +1,34 @@
#ifndef PARTITIONLIST_H
#define PARTITIONLIST_H
class PartitionListRow;
class PartitionListView;
#include <interface/ColumnListView.h>
#include <storage/Partition.h>
// Forward declarations
class BPartition;
class PartitionListRow : public BRow
{
typedef BRow Inherited;
public:
PartitionListRow(BPartition* partition);
partition_id ID() { return fPartitionID; }
private:
partition_id fPartitionID;
};
class PartitionListView : public BColumnListView
{
typedef BColumnListView Inherited;
public:
PartitionListView(const BRect& frame);
PartitionListRow* FindRow(partition_id id);
PartitionListRow* AddPartition(BPartition* partition);
};
#endif /* PARTITIONLIST_H */
-32
View File
@@ -1,32 +0,0 @@
/*! \file structs.h
\brief Holds the structs used.
*/
#ifndef STRUCTS_H
#define STRUCTS_H
struct partition_info{
int32 type; /* partition type */
/* Maybe get this from the type mapping? */
char *fs; /* file system */
char *name; /* volume name */
char *mount_pt; /* mounted at */
double size; /* size (in MB) */
bool mounted; /* TRUE if mounted, FALSE if not */
};
struct dev_info{
char *device; /* the path to the device */
int map; /* 0 for none, 1 for intel, 2 for apple */
int numParts; /* number of partitions */
partition_info parts[4]; /* information on the partitions on the device */
};
#endif