* Now listens to disk device notifications, and rescans its device list when

something comes in -- this could be greatly improved, though.
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29583 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-03-18 08:56:49 +00:00
parent 3f78b216ad
commit a7ea0713b4
6 changed files with 121 additions and 116 deletions
+22 -19
View File
@@ -1,10 +1,11 @@
/*
* Copyright 2007-2008 Haiku Inc. All rights reserved.
* Copyright 2007-2009 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
* Stephan Aßmus <[email protected]>
*/
#include "DiskView.h"
#include "MainWindow.h"
@@ -28,14 +29,14 @@ class PartitionView : public BView {
public:
PartitionView(const char* name, float weight, off_t offset,
int32 level, partition_id id)
: BView(name, B_WILL_DRAW | B_SUPPORTS_LAYOUT | B_FULL_UPDATE_ON_RESIZE)
, fID(id)
, fWeight(weight)
, fOffset(offset)
, fLevel(level)
, fSelected(false)
, fMouseOver(false)
, fGroupLayout(new BGroupLayout(B_HORIZONTAL, kLayoutInset))
: BView(name, B_WILL_DRAW | B_SUPPORTS_LAYOUT | B_FULL_UPDATE_ON_RESIZE),
fID(id),
fWeight(weight),
fOffset(offset),
fLevel(level),
fSelected(false),
fMouseOver(false),
fGroupLayout(new BGroupLayout(B_HORIZONTAL, kLayoutInset))
{
SetLayout(fGroupLayout);
@@ -184,10 +185,11 @@ private:
class DiskView::PartitionLayout : public BDiskDeviceVisitor {
public:
PartitionLayout(BView* view, SpaceIDMap& spaceIDMap)
: fView(view)
, fViewMap()
, fSelectedPartition(-1)
, fSpaceIDMap(spaceIDMap)
:
fView(view),
fViewMap(),
fSelectedPartition(-1),
fSpaceIDMap(spaceIDMap)
{
}
@@ -273,7 +275,7 @@ public:
// TODO: remove again once Disk Device API is fixed
if (!is_valid_partitionable_space(size))
continue;
//
//
double scale = (double)size / parentSize;
partition_id id
= fSpaceIDMap.SpaceIDFor(partition->ID(), offset);
@@ -319,11 +321,11 @@ public:
DiskView::DiskView(const BRect& frame, uint32 resizeMode,
SpaceIDMap& spaceIDMap)
: Inherited(frame, "diskview", resizeMode,
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE)
, fDiskCount(0)
, fDisk(NULL)
, fSpaceIDMap(spaceIDMap)
, fPartitionLayout(new PartitionLayout(this, fSpaceIDMap))
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
fDiskCount(0),
fDisk(NULL),
fSpaceIDMap(spaceIDMap),
fPartitionLayout(new PartitionLayout(this, fSpaceIDMap))
{
BGroupLayout* layout = new BGroupLayout(B_HORIZONTAL, kLayoutInset);
SetLayout(layout);
@@ -415,6 +417,7 @@ DiskView::SetDiskCount(int32 count)
fDiskCount = count;
}
void
DiskView::SetDisk(BDiskDevice* disk, partition_id selectedPartition)
{
+15 -16
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 Haiku Inc. All rights reserved.
* Copyright 2002-2009 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
@@ -7,6 +7,7 @@
* Ithamar R. Adema <ithamar@unet.nl>
* Stephan Aßmus <superstippi@gmx.de>
*/
#include "DriveSetup.h"
#include "MainWindow.h"
@@ -18,22 +19,10 @@
#include <Path.h>
int
main(int, char**)
{
DriveSetup app;
app.Run();
return 0;
}
// #pragma mark -
DriveSetup::DriveSetup()
: BApplication("application/x-vnd.Haiku-DriveSetup")
, fWindow(NULL)
, fSettings(0UL)
: BApplication("application/x-vnd.Haiku-DriveSetup"),
fWindow(NULL),
fSettings(0UL)
{
}
@@ -152,3 +141,13 @@ DriveSetup::_GetSettingsFile(BFile& file, bool forWriting) const
}
// #pragma mark -
int
main(int, char**)
{
DriveSetup app;
app.Run();
return 0;
}
+10 -16
View File
@@ -1,10 +1,11 @@
/*
* Copyright 2008 Haiku Inc. All rights reserved.
* Copyright 2008-2009 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
#include "InitParamsPanel.h"
#include <stdio.h>
@@ -27,7 +28,7 @@ class InitParamsPanel::EscapeFilter : public BMessageFilter {
public:
EscapeFilter(InitParamsPanel* target)
: BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE),
fPanel(target)
fPanel(target)
{
}
virtual ~EscapeFilter()
@@ -68,15 +69,14 @@ enum {
};
InitParamsPanel::InitParamsPanel(BWindow* window)
: BWindow(BRect(300.0, 200.0, 600.0, 300.0), 0, B_MODAL_WINDOW_LOOK,
B_MODAL_SUBSET_WINDOW_FEEL,
B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS)
, fEscapeFilter(new EscapeFilter(this))
, fExitSemaphore(create_sem(0, "InitParamsPanel exit"))
, fWindow(window)
, fReturnValue(GO_CANCELED)
B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS),
fEscapeFilter(new EscapeFilter(this)),
fExitSemaphore(create_sem(0, "InitParamsPanel exit")),
fWindow(window),
fReturnValue(GO_CANCELED)
{
AddCommonFilter(fEscapeFilter);
@@ -211,7 +211,7 @@ InitParamsPanel::Go(BString& name, BString& parameters)
B_CAN_INTERRUPT | B_RELATIVE_TIMEOUT, 50000);
if (err != B_TIMED_OUT && err != B_INTERRUPTED)
break;
fWindow->UpdateIfNeeded();
fWindow->UpdateIfNeeded();
}
if (!Lock())
@@ -226,7 +226,7 @@ InitParamsPanel::Go(BString& name, BString& parameters)
if (!message || message->FindString("size", &size) < B_OK)
size = "2048";
// TODO: use libroot driver settings API
parameters << "block_size " << size << ";\n";
parameters << "block_size " << size << ";\n";
}
}
@@ -245,9 +245,3 @@ InitParamsPanel::Cancel()
fReturnValue = GO_CANCELED;
release_sem(fExitSemaphore);
}
+46 -38
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 Haiku Inc. All rights reserved.
* Copyright 2002-2009 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
@@ -7,6 +7,7 @@
* Ithamar R. Adema <ithamar@unet.nl>
* Stephan Aßmus <superstippi@gmx.de>
*/
#include "MainWindow.h"
#include "DiskView.h"
#include "InitParamsPanel.h"
@@ -37,9 +38,10 @@ class ListPopulatorVisitor : public BDiskDeviceVisitor {
public:
ListPopulatorVisitor(PartitionListView* list, int32& diskCount,
SpaceIDMap& spaceIDMap)
: fPartitionList(list)
, fDiskCount(diskCount)
, fSpaceIDMap(spaceIDMap)
:
fPartitionList(list),
fDiskCount(diskCount),
fSpaceIDMap(spaceIDMap)
{
fDiskCount = 0;
fSpaceIDMap.Clear();
@@ -88,7 +90,7 @@ private:
// TODO: remove again once Disk Device API is fixed
if (!is_valid_partitionable_space(size))
continue;
//
//
partition_id id = fSpaceIDMap.SpaceIDFor(parentID, offset);
fPartitionList->AddSpace(parentID, id, offset, size);
}
@@ -145,10 +147,10 @@ enum {
MainWindow::MainWindow(BRect frame)
: BWindow(frame, "DriveSetup", B_DOCUMENT_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
, fCurrentDisk(NULL)
, fCurrentPartitionID(-1)
, fSpaceIDMap()
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE),
fCurrentDisk(NULL),
fCurrentPartitionID(-1),
fSpaceIDMap()
{
BMenuBar* menuBar = new BMenuBar(Bounds(), "root menu");
@@ -161,7 +163,7 @@ MainWindow::MainWindow(BRect frame)
fDeleteMI = new BMenuItem("Delete (not implemented)",
new BMessage(MSG_DELETE));
fDeleteMI->SetEnabled(false);
fDeleteMI->SetEnabled(false);
fMountMI = new BMenuItem("Mount", new BMessage(MSG_MOUNT), 'M');
fUnmountMI = new BMenuItem("Unmount", new BMessage(MSG_UNMOUNT), 'U');
@@ -170,38 +172,37 @@ fDeleteMI->SetEnabled(false);
// Disk menu
fDiskMenu = new BMenu("Disk");
fDiskMenu->AddItem(fFormatMI);
fDiskMenu->AddItem(fEjectMI);
fDiskMenu->AddItem(fSurfaceTestMI);
fDiskMenu->AddItem(fFormatMI);
fDiskMenu->AddItem(fEjectMI);
fDiskMenu->AddItem(fSurfaceTestMI);
fDiskMenu->AddSeparatorItem();
fDiskMenu->AddSeparatorItem();
fDiskMenu->AddItem(fRescanMI);
fDiskMenu->AddItem(fRescanMI);
menuBar->AddItem(fDiskMenu);
// Parition menu
fPartitionMenu = new BMenu("Partition");
fCreateMenu = new BMenu("Create (not implemented)");
fPartitionMenu->AddItem(fCreateMenu);
fCreateMenu = new BMenu("Create (not implemented)");
fPartitionMenu->AddItem(fCreateMenu);
fInitMenu = new BMenu("Initialize");
fPartitionMenu->AddItem(fInitMenu);
fInitMenu = new BMenu("Initialize");
fPartitionMenu->AddItem(fInitMenu);
fPartitionMenu->AddItem(fDeleteMI);
fPartitionMenu->AddItem(fDeleteMI);
fPartitionMenu->AddSeparatorItem();
fPartitionMenu->AddSeparatorItem();
fPartitionMenu->AddItem(fMountMI);
fPartitionMenu->AddItem(fUnmountMI);
fPartitionMenu->AddItem(fMountMI);
fPartitionMenu->AddItem(fUnmountMI);
fPartitionMenu->AddSeparatorItem();
fPartitionMenu->AddSeparatorItem();
fPartitionMenu->AddItem(fMountAllMI);
fPartitionMenu->AddItem(fMountAllMI);
menuBar->AddItem(fPartitionMenu);
AddChild(menuBar);
// add DiskView
BRect r(Bounds());
r.top = menuBar->Frame().bottom + 1;
@@ -221,6 +222,8 @@ fDeleteMI->SetEnabled(false);
fListView->SetSelectionMessage(new BMessage(MSG_PARTITION_ROW_SELECTED));
fListView->SetTarget(this);
BDiskDeviceRoster().StartWatching(this);
// populate the Initialiaze menu with the available file systems
_ScanFileSystems();
@@ -231,6 +234,7 @@ fDeleteMI->SetEnabled(false);
MainWindow::~MainWindow()
{
BDiskDeviceRoster().StopWatching(this);
delete fCurrentDisk;
}
@@ -281,6 +285,9 @@ MainWindow::MessageReceived(BMessage* message)
case MSG_SURFACE_TEST:
printf("MSG_SURFACE_TEST\n");
break;
// TODO: this could probably be done better!
case B_DEVICE_UPDATE:
case MSG_RESCAN:
_ScanDrives();
break;
@@ -309,7 +316,7 @@ MainWindow::MessageReceived(BMessage* message)
}
bool
bool
MainWindow::QuitRequested()
{
// TODO: ask about any unsaved changes
@@ -327,7 +334,7 @@ MainWindow::StoreSettings(BMessage* archive) const
{
if (archive->ReplaceRect("window frame", Frame()) < B_OK)
archive->AddRect("window frame", Frame());
BMessage columnSettings;
fListView->SaveState(&columnSettings);
if (archive->ReplaceMessage("column settings", &columnSettings) < B_OK)
@@ -425,7 +432,7 @@ MainWindow::_AdaptToSelectedPartition()
= dynamic_cast<PartitionListRow*>(_topLevelRow);
PartitionListRow* selectedRow
= dynamic_cast<PartitionListRow*>(_selectedRow);
if (topLevelRow)
diskID = topLevelRow->ID();
if (selectedRow) {
@@ -482,10 +489,10 @@ MainWindow::_EnabledDisableMenuItems(BDiskDevice* disk,
fPartitionMenu->SetEnabled(false);
} else {
// fFormatMI->SetEnabled(true);
fFormatMI->SetEnabled(false);
fFormatMI->SetEnabled(false);
fEjectMI->SetEnabled(disk->IsRemovableMedia());
// fSurfaceTestMI->SetEnabled(true);
fSurfaceTestMI->SetEnabled(false);
fSurfaceTestMI->SetEnabled(false);
// Create menu and items
fPartitionMenu->SetEnabled(true);
@@ -524,16 +531,16 @@ fSurfaceTestMI->SetEnabled(false);
if (partition) {
fInitMenu->SetEnabled(!partition->IsMounted());
// fDeleteMI->SetEnabled(!partition->IsMounted());
fDeleteMI->SetEnabled(false);
fDeleteMI->SetEnabled(false);
fMountMI->SetEnabled(!partition->IsMounted());
bool unMountable = false;
if (partition->IsMounted()) {
// see if this partition is the boot volume
BVolume volume;
BVolume bootVolume;
BVolume volume;
BVolume bootVolume;
if (BVolumeRoster().GetBootVolume(&bootVolume) == B_OK
&& partition->GetVolume(&volume) == B_OK) {
&& partition->GetVolume(&volume) == B_OK) {
unMountable = volume != bootVolume;
} else
unMountable = true;
@@ -555,7 +562,7 @@ MainWindow::_DisplayPartitionError(BString _message,
const BPartition* partition, status_t error) const
{
char message[1024];
if (partition && _message.FindFirst("%s") >= 0) {
BString name;
name << " \"" << partition->ContentName() << "\"";
@@ -659,8 +666,9 @@ MainWindow::_MountAll()
class ModificationPreparer {
public:
ModificationPreparer(BDiskDevice* disk)
: fDisk(disk)
, fModificationStatus(fDisk->PrepareModifications())
:
fDisk(disk),
fModificationStatus(fDisk->PrepareModifications())
{
}
~ModificationPreparer()
+22 -22
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2008 Haiku Inc. All rights reserved.
* Copyright 2006-2009 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
@@ -18,8 +18,8 @@
BBitmapStringField::BBitmapStringField(BBitmap* bitmap, const char* string)
: Inherited(string)
, fBitmap(bitmap)
: Inherited(string),
fBitmap(bitmap)
{
}
@@ -114,7 +114,7 @@ PartitionColumn::DrawField(BField* field, BRect rect, BView* parent)
} else if (stringField) {
float width = rect.Width() - (2 * fTextMargin);
if (width != stringField->Width()) {
BString truncatedString(stringField->String());
@@ -156,7 +156,7 @@ PartitionColumn::GetPreferredWidth(BField *_field, BView* parent) const
}
bool
bool
PartitionColumn::AcceptsField(const BField* field) const
{
return dynamic_cast<const BStringField*>(field) != NULL;
@@ -178,11 +178,11 @@ enum {
PartitionListRow::PartitionListRow(BPartition* partition)
: Inherited()
, fPartitionID(partition->ID())
, fParentID(partition->Parent() ? partition->Parent()->ID() : -1)
, fOffset(partition->Offset())
, fSize(partition->Size())
: Inherited(),
fPartitionID(partition->ID()),
fParentID(partition->Parent() ? partition->Parent()->ID() : -1),
fOffset(partition->Offset()),
fSize(partition->Size())
{
BPath path;
partition->GetPath(&path);
@@ -206,7 +206,7 @@ PartitionListRow::PartitionListRow(BPartition* partition)
SetField(new BStringField(kUnavailableString), kFilesystemColumn);
SetField(new BStringField(kUnavailableString), kVolumeNameColumn);
}
if (partition->IsMounted() && partition->GetMountPoint(&path) == B_OK) {
SetField(new BStringField(path.Path()), kMountedAtColumn);
} else {
@@ -221,18 +221,18 @@ PartitionListRow::PartitionListRow(BPartition* partition)
PartitionListRow::PartitionListRow(partition_id parentID, partition_id id,
off_t offset, off_t size)
: Inherited()
, fPartitionID(id)
, fParentID(parentID)
, fOffset(offset)
, fSize(size)
: Inherited(),
fPartitionID(id),
fParentID(parentID),
fOffset(offset),
fSize(size)
{
// TODO: design icon for spaces on partitions
SetField(new BBitmapStringField(NULL, "-"), kDeviceColumn);
SetField(new BStringField("<empty>"), kFilesystemColumn);
SetField(new BStringField(kUnavailableString), kVolumeNameColumn);
SetField(new BStringField(kUnavailableString), kMountedAtColumn);
char sizeString[1024];
@@ -282,11 +282,11 @@ PartitionListRow*
PartitionListView::AddPartition(BPartition* partition)
{
PartitionListRow* partitionrow = FindRow(partition->ID());
// forget about it if this partition is already in the listview
if (partitionrow != NULL)
return partitionrow;
// create the row for this partition
partitionrow = new PartitionListRow(partition);
@@ -311,7 +311,7 @@ PartitionListView::AddPartition(BPartition* partition)
// make sure the row is initially expanded
ExpandOrCollapse(partitionrow, true);
return partitionrow;
}
@@ -324,7 +324,7 @@ PartitionListView::AddSpace(partition_id parentID, partition_id id,
PartitionListRow* parent = FindRow(parentID);
if (!parent)
return NULL;
// create the row for this partition
PartitionListRow* partitionrow = new PartitionListRow(parentID,
id, offset, size);
@@ -337,7 +337,7 @@ PartitionListView::AddSpace(partition_id parentID, partition_id id,
// make sure the row is initially expanded
ExpandOrCollapse(partitionrow, true);
return partitionrow;
}
+6 -5
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 Haiku Inc. All rights reserved.
* Copyright 2002-2009 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
@@ -7,6 +7,7 @@
* Ithamar R. Adema <ithamar@unet.nl>
* Stephan Aßmus <superstippi@gmx.de>
*/
#include "Support.h"
#include <Partition.h>
@@ -78,11 +79,12 @@ is_valid_partitionable_space(size_t size)
}
// #pragma mark -SpaceIDMap
// #pragma mark - SpaceIDMap
SpaceIDMap::SpaceIDMap()
: HashMap<HashString, partition_id>()
, fNextSpaceID(-2)
: HashMap<HashString, partition_id>(),
fNextSpaceID(-2)
{
}
@@ -107,4 +109,3 @@ SpaceIDMap::SpaceIDFor(partition_id parentID, off_t spaceOffset)
return newID;
}