DriveSetup: Added support for changing partition parameters.

* Does not seem to work yet, though. The intel disk system should support it
  now, but apparently the partition's delegate is not yet fully initialized
  for whatever reason.
This commit is contained in:
Axel Dörfler
2013-02-12 23:28:24 +01:00
parent 1b2662019b
commit 8940ad259a
10 changed files with 484 additions and 172 deletions
@@ -298,7 +298,8 @@ PartitionMapHandle::GetParameterEditor(B_PARAMETER_EDITOR_TYPE type,
BPartitionParameterEditor** editor)
{
*editor = NULL;
if (type == B_CREATE_PARAMETER_EDITOR) {
if (type == B_CREATE_PARAMETER_EDITOR
|| type == B_PROPERTIES_PARAMETER_EDITOR) {
try {
*editor = new PrimaryPartitionEditor();
} catch (std::bad_alloc) {
@@ -200,7 +200,7 @@ AbstractParametersPanel::Go(BString& parameters, BMessage& storage)
// Without an editor, we cannot change anything, anyway
if (fEditor == NULL && NeedsEditor()) {
parameters = "";
if (fReturnStatus == B_CANCELED)
if (ValidWithoutEditor() && fReturnStatus == B_CANCELED)
fReturnStatus = B_OK;
if (!Lock())
@@ -257,6 +257,12 @@ AbstractParametersPanel::NeedsEditor() const
}
bool
AbstractParametersPanel::ValidWithoutEditor() const
{
return true;
}
status_t
AbstractParametersPanel::ParametersReceived(const BString& parameters,
BMessage& storage)
@@ -40,6 +40,7 @@ protected:
status_t Go(BString& parameters, BMessage& storage);
virtual bool NeedsEditor() const;
virtual bool ValidWithoutEditor() const;
virtual status_t ParametersReceived(const BString& parameters,
BMessage& storage);
virtual void AddControls(BLayoutBuilder::Group<>& builder,
@@ -0,0 +1,196 @@
/*
* Copyright 2008-2013 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
* Axel Dörfler, axeld@pinc-software.de.
* Bryce Groff <bgroff@hawaii.edu>
* Karsten Heimrich <host.haiku@gmx.de>
*/
#include "ChangeParametersPanel.h"
#include <Button.h>
#include <Catalog.h>
#include <ControlLook.h>
#include <DiskDeviceTypes.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <MessageFilter.h>
#include <PopUpMenu.h>
#include <String.h>
#include <TextControl.h>
#include <Variant.h>
#include "Support.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "ChangeParametersPanel"
enum {
MSG_PARTITION_TYPE = 'type',
};
ChangeParametersPanel::ChangeParametersPanel(BWindow* window,
BPartition* partition)
:
AbstractParametersPanel(window)
{
CreateChangeControls(partition);
Init(B_PROPERTIES_PARAMETER_EDITOR, "", partition);
}
ChangeParametersPanel::~ChangeParametersPanel()
{
}
status_t
ChangeParametersPanel::Go(BString& name, BString& type, BString& parameters)
{
BMessage storage;
return Go(name, type, parameters, storage);
}
void
ChangeParametersPanel::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_PARTITION_TYPE:
if (fEditor != NULL) {
const char* type;
if (message->FindString("type", &type) == B_OK)
fEditor->ParameterChanged("type", BVariant(type));
}
break;
default:
AbstractParametersPanel::MessageReceived(message);
}
}
// #pragma mark - protected
ChangeParametersPanel::ChangeParametersPanel(BWindow* window)
:
AbstractParametersPanel(window)
{
}
status_t
ChangeParametersPanel::Go(BString& name, BString& type, BString& parameters,
BMessage& storage)
{
// The object will be deleted in Go(), so we need to get the values via
// a BMessage
status_t status = AbstractParametersPanel::Go(parameters, storage);
if (status != B_OK)
return status;
// get name
name.SetTo(storage.GetString("name", NULL));
// get type
type.SetTo(storage.GetString("type", NULL));
return B_OK;
}
void
ChangeParametersPanel::CreateChangeControls(BPartition* parent)
{
fNameTextControl = new BTextControl("Name Control",
B_TRANSLATE("Partition name:"), "", NULL);
fSupportsName = parent->SupportsChildName();
fTypePopUpMenu = new BPopUpMenu("Partition Type");
int32 cookie = 0;
BString supportedType;
while (parent->GetNextSupportedChildType(&cookie, &supportedType) == B_OK) {
BMessage* message = new BMessage(MSG_PARTITION_TYPE);
message->AddString("type", supportedType);
BMenuItem* item = new BMenuItem(supportedType, message);
fTypePopUpMenu->AddItem(item);
if (strcmp(supportedType, kPartitionTypeBFS) == 0)
item->SetMarked(true);
}
fTypeMenuField = new BMenuField(B_TRANSLATE("Partition type:"),
fTypePopUpMenu);
fSupportsType = fTypePopUpMenu->CountItems() != 0;
fOkButton->SetLabel(B_TRANSLATE("Change"));
}
bool
ChangeParametersPanel::NeedsEditor() const
{
return !fSupportsName && !fSupportsType;
}
bool
ChangeParametersPanel::ValidWithoutEditor() const
{
return !NeedsEditor();
}
status_t
ChangeParametersPanel::ParametersReceived(const BString& parameters,
BMessage& storage)
{
// get name
status_t status = storage.SetString("name", fNameTextControl->Text());
// get type
if (BMenuItem* item = fTypeMenuField->Menu()->FindMarked()) {
const char* type;
BMessage* message = item->Message();
if (!message || message->FindString("type", &type) != B_OK)
type = kPartitionTypeBFS;
if (status == B_OK)
status = storage.SetString("type", type);
}
return status;
}
void
ChangeParametersPanel::AddControls(BLayoutBuilder::Group<>& builder,
BView* editorView)
{
if (fSupportsName || fSupportsType) {
BLayoutBuilder::Group<>::GridBuilder gridBuilder
= builder.AddGrid(0.0, B_USE_DEFAULT_SPACING);
if (fSupportsName) {
gridBuilder.Add(fNameTextControl->CreateLabelLayoutItem(), 0, 0)
.Add(fNameTextControl->CreateTextViewLayoutItem(), 1, 0);
}
if (fSupportsType) {
gridBuilder.Add(fTypeMenuField->CreateLabelLayoutItem(), 0, 1)
.Add(fTypeMenuField->CreateMenuBarLayoutItem(), 1, 1);
}
}
if (editorView != NULL)
builder.Add(editorView);
}
@@ -0,0 +1,56 @@
/*
* Copyright 2008-2013 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
* Axel Dörfler, axeld@pinc-software.de.
* Bryce Groff <bgroff@hawaii.edu>
*/
#ifndef CHANGE_PARAMS_PANEL_H
#define CHANGE_PARAMS_PANEL_H
#include "AbstractParametersPanel.h"
class BMenuField;
class BPopUpMenu;
class BTextControl;
class ChangeParametersPanel : public AbstractParametersPanel {
public:
ChangeParametersPanel(BWindow* window,
BPartition* parent);
virtual ~ChangeParametersPanel();
status_t Go(BString& name, BString& type,
BString& parameters);
virtual void MessageReceived(BMessage* message);
protected:
ChangeParametersPanel(BWindow* window);
status_t Go(BString& name, BString& type,
BString& parameters, BMessage& storage);
void CreateChangeControls(BPartition* parent);
virtual bool NeedsEditor() const;
virtual bool ValidWithoutEditor() const;
virtual status_t ParametersReceived(const BString& parameters,
BMessage& storage);
virtual void AddControls(BLayoutBuilder::Group<>& builder,
BView* editorView);
protected:
BPopUpMenu* fTypePopUpMenu;
BMenuField* fTypeMenuField;
BTextControl* fNameTextControl;
bool fSupportsName;
bool fSupportsType;
};
#endif // CHANGE_PARAMS_PANEL_H
+11 -71
View File
@@ -43,9 +43,9 @@ static const uint32 kMegaByte = 0x100000;
CreateParametersPanel::CreateParametersPanel(BWindow* window,
BPartition* partition, off_t offset, off_t size)
:
AbstractParametersPanel(window)
ChangeParametersPanel(window)
{
_CreateViewControls(partition, offset, size);
_CreateCreateControls(partition, offset, size);
Init(B_CREATE_PARAMETER_EDITOR, "", partition);
}
@@ -64,7 +64,8 @@ CreateParametersPanel::Go(off_t& offset, off_t& size, BString& name,
// a BMessage
BMessage storage;
status_t status = AbstractParametersPanel::Go(parameters, storage);
status_t status = ChangeParametersPanel::Go(name, type, parameters,
storage);
if (status != B_OK)
return status;
@@ -72,12 +73,6 @@ CreateParametersPanel::Go(off_t& offset, off_t& size, BString& name,
size = storage.GetInt64("size", 0);
offset = storage.GetInt64("offset", 0);
// get name
name.SetTo(storage.GetString("name", NULL));
// get type
type.SetTo(storage.GetString("type", NULL));
return B_OK;
}
@@ -86,14 +81,6 @@ void
CreateParametersPanel::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_PARTITION_TYPE:
if (fEditor != NULL) {
const char* type;
if (message->FindString("type", &type) == B_OK)
fEditor->ParameterChanged("type", BVariant(type));
}
break;
case MSG_SIZE_SLIDER:
_UpdateSizeTextControl();
break;
@@ -109,7 +96,7 @@ CreateParametersPanel::MessageReceived(BMessage* message)
}
default:
AbstractParametersPanel::MessageReceived(message);
ChangeParametersPanel::MessageReceived(message);
}
}
@@ -130,22 +117,10 @@ CreateParametersPanel::ParametersReceived(const BString& parameters,
if (status == B_OK)
status = storage.SetInt64("offset", fSizeSlider->Offset());
// get name
if (status == B_OK)
status = storage.SetString("name", fNameTextControl->Text());
if (status != B_OK)
return status;
// get type
if (BMenuItem* item = fTypeMenuField->Menu()->FindMarked()) {
const char* type;
BMessage* message = item->Message();
if (!message || message->FindString("type", &type) != B_OK)
type = kPartitionTypeBFS;
if (status == B_OK)
status = storage.SetString("type", type);
}
return status;
return ChangeParametersPanel::ParametersReceived(parameters, storage);
}
@@ -157,27 +132,12 @@ CreateParametersPanel::AddControls(BLayoutBuilder::Group<>& builder,
.Add(fSizeSlider)
.Add(fSizeTextControl);
if (fSupportsName || fSupportsType) {
BLayoutBuilder::Group<>::GridBuilder gridBuilder
= builder.AddGrid(0.0, B_USE_DEFAULT_SPACING);
if (fSupportsName) {
gridBuilder.Add(fNameTextControl->CreateLabelLayoutItem(), 0, 0)
.Add(fNameTextControl->CreateTextViewLayoutItem(), 1, 0);
}
if (fSupportsType) {
gridBuilder.Add(fTypeMenuField->CreateLabelLayoutItem(), 0, 1)
.Add(fTypeMenuField->CreateMenuBarLayoutItem(), 1, 1);
}
}
if (editorView != NULL)
builder.Add(editorView);
ChangeParametersPanel::AddControls(builder, editorView);
}
void
CreateParametersPanel::_CreateViewControls(BPartition* parent, off_t offset,
CreateParametersPanel::_CreateCreateControls(BPartition* parent, off_t offset,
off_t size)
{
// Setup the controls
@@ -197,27 +157,7 @@ CreateParametersPanel::_CreateViewControls(BPartition* parent, off_t offset,
fSizeTextControl->SetModificationMessage(
new BMessage(MSG_SIZE_TEXTCONTROL));
fNameTextControl = new BTextControl("Name Control",
B_TRANSLATE("Partition name:"), "", NULL);
fSupportsName = parent->SupportsChildName();
fTypePopUpMenu = new BPopUpMenu("Partition Type");
int32 cookie = 0;
BString supportedType;
while (parent->GetNextSupportedChildType(&cookie, &supportedType) == B_OK) {
BMessage* message = new BMessage(MSG_PARTITION_TYPE);
message->AddString("type", supportedType);
BMenuItem* item = new BMenuItem(supportedType, message);
fTypePopUpMenu->AddItem(item);
if (strcmp(supportedType, kPartitionTypeBFS) == 0)
item->SetMarked(true);
}
fTypeMenuField = new BMenuField(B_TRANSLATE("Partition type:"),
fTypePopUpMenu);
fSupportsType = fTypePopUpMenu->CountItems() != 0;
CreateChangeControls(parent);
fOkButton->SetLabel(B_TRANSLATE("Create"));
}
+3 -11
View File
@@ -11,16 +11,13 @@
#define CREATE_PARAMS_PANEL_H
#include "AbstractParametersPanel.h"
#include "ChangeParametersPanel.h"
class BMenuField;
class BPopUpMenu;
class BTextControl;
class SizeSlider;
class CreateParametersPanel : public AbstractParametersPanel {
class CreateParametersPanel : public ChangeParametersPanel {
public:
CreateParametersPanel(BWindow* window,
BPartition* parent, off_t offset,
@@ -40,19 +37,14 @@ protected:
BView* editorView);
private:
void _CreateViewControls(BPartition* parent,
void _CreateCreateControls(BPartition* parent,
off_t offset, off_t size);
void _UpdateSizeTextControl();
private:
BPopUpMenu* fTypePopUpMenu;
BMenuField* fTypeMenuField;
BTextControl* fNameTextControl;
SizeSlider* fSizeSlider;
BTextControl* fSizeTextControl;
bool fSupportsName;
bool fSupportsType;
};
+2
View File
@@ -6,6 +6,7 @@ UsePrivateHeaders interface shared storage tracker ;
Preference DriveSetup :
AbstractParametersPanel.cpp
ChangeParametersPanel.cpp
CreateParametersPanel.cpp
DiskView.cpp
DriveSetup.cpp
@@ -23,6 +24,7 @@ DoCatalogs DriveSetup :
x-vnd.Haiku-DriveSetup
:
AbstractParametersPanel.cpp
ChangeParametersPanel.cpp
CreateParametersPanel.cpp
DiskView.cpp
InitParametersPanel.cpp
+201 -86
View File
@@ -40,6 +40,7 @@
#include <tracker_private.h>
#include "ChangeParametersPanel.h"
#include "CreateParametersPanel.h"
#include "DiskView.h"
#include "InitParametersPanel.h"
@@ -51,6 +52,23 @@
#define B_TRANSLATION_CONTEXT "MainWindow"
enum {
MSG_MOUNT_ALL = 'mnta',
MSG_MOUNT = 'mnts',
MSG_UNMOUNT = 'unmt',
MSG_FORMAT = 'frmt',
MSG_CREATE = 'crtp',
MSG_CHANGE = 'chgp',
MSG_INITIALIZE = 'init',
MSG_DELETE = 'delt',
MSG_EJECT = 'ejct',
MSG_SURFACE_TEST = 'sfct',
MSG_RESCAN = 'rscn',
MSG_PARTITION_ROW_SELECTED = 'prsl',
};
class ListPopulatorVisitor : public BDiskDeviceVisitor {
public:
ListPopulatorVisitor(PartitionListView* list, int32& diskCount,
@@ -96,8 +114,8 @@ private:
// add any available space on it
BPartitioningInfo info;
status_t ret = partition->GetPartitioningInfo(&info);
if (ret >= B_OK) {
status_t status = partition->GetPartitioningInfo(&info);
if (status >= B_OK) {
partition_id parentID = partition->ID();
off_t offset;
off_t size;
@@ -162,11 +180,11 @@ public:
}
status_t CommitModifications()
{
status_t ret = fDisk->CommitModifications();
if (ret == B_OK)
status_t status = fDisk->CommitModifications();
if (status == B_OK)
fModificationStatus = B_ERROR;
return ret;
return status;
}
private:
@@ -175,22 +193,6 @@ private:
};
enum {
MSG_MOUNT_ALL = 'mnta',
MSG_MOUNT = 'mnts',
MSG_UNMOUNT = 'unmt',
MSG_FORMAT = 'frmt',
MSG_CREATE = 'crtp',
MSG_INITIALIZE = 'init',
MSG_DELETE = 'delt',
MSG_EJECT = 'ejct',
MSG_SURFACE_TEST = 'sfct',
MSG_RESCAN = 'rscn',
MSG_PARTITION_ROW_SELECTED = 'prsl',
};
// #pragma mark -
@@ -217,6 +219,9 @@ MainWindow::MainWindow()
fCreateMenuItem = new BMenuItem(B_TRANSLATE("Create" B_UTF8_ELLIPSIS),
new BMessage(MSG_CREATE), 'C');
fChangeMenuItem = new BMenuItem(
B_TRANSLATE("Change parameters" B_UTF8_ELLIPSIS),
new BMessage(MSG_CHANGE));
fDeleteMenuItem = new BMenuItem(B_TRANSLATE("Delete"),
new BMessage(MSG_DELETE), 'D');
@@ -249,6 +254,7 @@ MainWindow::MainWindow()
fFormatMenu = new BMenu(B_TRANSLATE("Format"));
fPartitionMenu->AddItem(fFormatMenu);
fPartitionMenu->AddItem(fChangeMenuItem);
fPartitionMenu->AddItem(fDeleteMenuItem);
fPartitionMenu->AddSeparatorItem();
@@ -284,10 +290,10 @@ MainWindow::MainWindow()
fListView->SetTarget(this);
fListView->MakeFocus(true);
status_t ret = fDDRoster.StartWatching(BMessenger(this));
if (ret != B_OK) {
status_t status = fDiskDeviceRoster.StartWatching(BMessenger(this));
if (status != B_OK) {
fprintf(stderr, "Failed to start watching for device changes: %s\n",
strerror(ret));
strerror(status));
}
// visit all disks in the system and show their contents
@@ -323,10 +329,9 @@ MainWindow::MessageReceived(BMessage* message)
printf("MSG_FORMAT\n");
break;
case MSG_CREATE: {
case MSG_CREATE:
_Create(fCurrentDisk, fCurrentPartitionID);
break;
}
case MSG_INITIALIZE: {
BString diskSystemName;
@@ -336,6 +341,10 @@ MainWindow::MessageReceived(BMessage* message)
break;
}
case MSG_CHANGE:
_ChangeParameters(fCurrentDisk, fCurrentPartitionID);
break;
case MSG_DELETE:
_Delete(fCurrentDisk, fCurrentPartitionID);
break;
@@ -476,7 +485,7 @@ MainWindow::_ScanDrives()
fSpaceIDMap.Clear();
int32 diskCount = 0;
ListPopulatorVisitor driveVisitor(fListView, diskCount, fSpaceIDMap);
fDDRoster.VisitEachPartition(&driveVisitor);
fDiskDeviceRoster.VisitEachPartition(&driveVisitor);
fDiskView->SetDiskCount(diskCount);
// restore selection
@@ -541,9 +550,9 @@ MainWindow::_SetToDiskAndPartition(partition_id disk, partition_id partition,
fCurrentDisk = NULL;
if (disk >= 0) {
BDiskDevice* newDisk = new BDiskDevice();
status_t ret = newDisk->SetTo(disk);
if (ret < B_OK) {
printf("error switching disks: %s\n", strerror(ret));
status_t status = newDisk->SetTo(disk);
if (status != B_OK) {
printf("error switching disks: %s\n", strerror(status));
delete newDisk;
} else
fCurrentDisk = newDisk;
@@ -597,12 +606,13 @@ MainWindow::_UpdateMenus(BDiskDevice* disk,
bool prepared = disk->PrepareModifications() == B_OK;
fFormatMenu->SetEnabled(prepared);
fDeleteMenuItem->SetEnabled(prepared);
fChangeMenuItem->SetEnabled(prepared);
BPartition* partition = disk->FindDescendant(selectedPartition);
BDiskSystem diskSystem;
fDDRoster.RewindDiskSystems();
while (fDDRoster.GetNextDiskSystem(&diskSystem) == B_OK) {
fDiskDeviceRoster.RewindDiskSystems();
while (fDiskDeviceRoster.GetNextDiskSystem(&diskSystem) == B_OK) {
if (!diskSystem.SupportsInitializing())
continue;
@@ -630,18 +640,20 @@ MainWindow::_UpdateMenus(BDiskDevice* disk,
// Mount items
if (partition != NULL) {
fFormatMenu->SetEnabled(!partition->IsMounted()
bool notMountedAndWritable = !partition->IsMounted()
&& !partition->IsReadOnly()
&& partition->Device()->HasMedia()
&& partition->Device()->HasMedia();
fFormatMenu->SetEnabled(notMountedAndWritable
&& fFormatMenu->CountItems() > 0);
fDiskInitMenu->SetEnabled(!partition->IsMounted()
&& !partition->IsReadOnly()
&& partition->Device()->HasMedia()
fDiskInitMenu->SetEnabled(notMountedAndWritable
&& partition->IsDevice()
&& fDiskInitMenu->CountItems() > 0);
fDeleteMenuItem->SetEnabled(!partition->IsMounted()
fChangeMenuItem->SetEnabled(notMountedAndWritable);
fDeleteMenuItem->SetEnabled(notMountedAndWritable
&& !partition->IsDevice());
fMountMenuItem->SetEnabled(!partition->IsMounted());
@@ -660,6 +672,7 @@ MainWindow::_UpdateMenus(BDiskDevice* disk,
fUnmountMenuItem->SetEnabled(unMountable);
} else {
fDeleteMenuItem->SetEnabled(false);
fChangeMenuItem->SetEnabled(false);
fMountMenuItem->SetEnabled(false);
fFormatMenu->SetEnabled(false);
fDiskInitMenu->SetEnabled(false);
@@ -672,6 +685,7 @@ MainWindow::_UpdateMenus(BDiskDevice* disk,
}
if (selectedPartition < 0) {
fDeleteMenuItem->SetEnabled(false);
fChangeMenuItem->SetEnabled(false);
fMountMenuItem->SetEnabled(false);
}
}
@@ -727,10 +741,10 @@ MainWindow::_Mount(BDiskDevice* disk, partition_id selectedPartition)
}
if (!partition->IsMounted()) {
status_t ret = partition->Mount();
if (ret < B_OK) {
_DisplayPartitionError(
B_TRANSLATE("Could not mount partition %s."), partition, ret);
status_t status = partition->Mount();
if (status != B_OK) {
_DisplayPartitionError(B_TRANSLATE("Could not mount partition %s."),
partition, status);
} else {
// successful mount, adapt to the changes
_ScanDrives();
@@ -761,11 +775,11 @@ MainWindow::_Unmount(BDiskDevice* disk, partition_id selectedPartition)
if (partition->IsMounted()) {
BPath path;
partition->GetMountPoint(&path);
status_t ret = partition->Unmount();
if (ret < B_OK) {
status_t status = partition->Unmount();
if (status != B_OK) {
_DisplayPartitionError(
B_TRANSLATE("Could not unmount partition %s."),
partition, ret);
partition, status);
} else {
if (dev_for_path(path.Path()) == dev_for_path("/"))
rmdir(path.Path());
@@ -784,7 +798,7 @@ void
MainWindow::_MountAll()
{
MountAllVisitor visitor;
fDDRoster.VisitEachPartition(&visitor);
fDiskDeviceRoster.VisitEachPartition(&visitor);
}
@@ -821,9 +835,9 @@ MainWindow::_Initialize(BDiskDevice* disk, partition_id selectedPartition,
}
BDiskSystem diskSystem;
fDDRoster.RewindDiskSystems();
fDiskDeviceRoster.RewindDiskSystems();
bool found = false;
while (fDDRoster.GetNextDiskSystem(&diskSystem) == B_OK) {
while (fDiskDeviceRoster.GetNextDiskSystem(&diskSystem) == B_OK) {
if (diskSystem.SupportsInitializing()) {
if (diskSystemName == diskSystem.PrettyName()) {
found = true;
@@ -874,10 +888,10 @@ MainWindow::_Initialize(BDiskDevice* disk, partition_id selectedPartition,
return;
ModificationPreparer modificationPreparer(disk);
status_t ret = modificationPreparer.ModificationStatus();
if (ret != B_OK) {
status_t status = modificationPreparer.ModificationStatus();
if (status != B_OK) {
_DisplayPartitionError(B_TRANSLATE("There was an error preparing the "
"disk for modifications."), NULL, ret);
"disk for modifications."), NULL, status);
return;
}
@@ -890,21 +904,22 @@ MainWindow::_Initialize(BDiskDevice* disk, partition_id selectedPartition,
bool supportsName = diskSystem.SupportsContentName();
BString validatedName(name);
ret = partition->ValidateInitialize(diskSystem.PrettyName(),
status = partition->ValidateInitialize(diskSystem.PrettyName(),
supportsName ? &validatedName : NULL, parameters.String());
if (ret != B_OK) {
if (status != B_OK) {
_DisplayPartitionError(B_TRANSLATE("Validation of the given "
"initialization parameters failed."), partition, ret);
"initialization parameters failed."), partition, status);
return;
}
BString previousName = partition->ContentName();
ret = partition->Initialize(diskSystem.PrettyName(),
status = partition->Initialize(diskSystem.PrettyName(),
supportsName ? validatedName.String() : NULL, parameters.String());
if (ret != B_OK) {
if (status != B_OK) {
_DisplayPartitionError(B_TRANSLATE("Initialization of the partition "
"%s failed. (Nothing has been written to disk.)"), partition, ret);
"%s failed. (Nothing has been written to disk.)"), partition,
status);
return;
}
@@ -947,13 +962,13 @@ MainWindow::_Initialize(BDiskDevice* disk, partition_id selectedPartition,
return;
// commit
ret = modificationPreparer.CommitModifications();
status = modificationPreparer.CommitModifications();
// The partition pointer is toast now! Use the partition ID to
// retrieve it again.
partition = disk->FindDescendant(selectedPartition);
if (ret == B_OK) {
if (status == B_OK) {
if (diskSystem.IsFileSystem()) {
_DisplayPartitionError(B_TRANSLATE("The partition %s has been "
"successfully formatted.\n"), partition);
@@ -964,10 +979,10 @@ MainWindow::_Initialize(BDiskDevice* disk, partition_id selectedPartition,
} else {
if (diskSystem.IsFileSystem()) {
_DisplayPartitionError(B_TRANSLATE("Failed to format the "
"partition %s!\n"), partition, ret);
"partition %s!\n"), partition, status);
} else {
_DisplayPartitionError(B_TRANSLATE("Failed to initialize the "
"disk %s!\n"), partition, ret);
"disk %s!\n"), partition, status);
}
}
@@ -1011,10 +1026,10 @@ MainWindow::_Create(BDiskDevice* disk, partition_id selectedPartition)
}
ModificationPreparer modificationPreparer(disk);
status_t ret = modificationPreparer.ModificationStatus();
if (ret != B_OK) {
status_t status = modificationPreparer.ModificationStatus();
if (status != B_OK) {
_DisplayPartitionError(B_TRANSLATE("There was an error preparing the "
"disk for modifications."), NULL, ret);
"disk for modifications."), NULL, status);
return;
}
@@ -1040,15 +1055,21 @@ MainWindow::_Create(BDiskDevice* disk, partition_id selectedPartition)
CreateParametersPanel* panel = new CreateParametersPanel(this, parent,
offset, size);
if (panel->Go(offset, size, name, type, parameters) != B_OK)
status = panel->Go(offset, size, name, type, parameters);
if (status != B_OK) {
if (status != B_CANCELED) {
_DisplayPartitionError(B_TRANSLATE("The panel could not return "
"successfully."), NULL, status);
}
return;
}
ret = parent->ValidateCreateChild(&offset, &size, type.String(),
status = parent->ValidateCreateChild(&offset, &size, type.String(),
&name, parameters.String());
if (ret != B_OK) {
if (status != B_OK) {
_DisplayPartitionError(B_TRANSLATE("Validation of the given creation "
"parameters failed."));
"parameters failed."), NULL, status);
return;
}
@@ -1064,27 +1085,27 @@ MainWindow::_Create(BDiskDevice* disk, partition_id selectedPartition)
if (choice == 1)
return;
ret = parent->CreateChild(offset, size, type.String(),
name.String(), parameters.String());
status = parent->CreateChild(offset, size, type.String(), name.String(),
parameters.String());
if (ret != B_OK) {
if (status != B_OK) {
_DisplayPartitionError(B_TRANSLATE("Creation of the partition has "
"failed."), NULL, ret);
"failed."), NULL, status);
return;
}
// commit
ret = modificationPreparer.CommitModifications();
status = modificationPreparer.CommitModifications();
if (ret != B_OK) {
if (status != B_OK) {
_DisplayPartitionError(B_TRANSLATE("Failed to format the "
"partition. No changes have been written to disk."), NULL, ret);
"partition. No changes have been written to disk."), NULL, status);
return;
}
// The disk layout has changed, update disk information
bool updated;
ret = disk->Update(&updated);
status = disk->Update(&updated);
_ScanDrives();
fDiskView->ForceUpdate();
@@ -1120,10 +1141,10 @@ MainWindow::_Delete(BDiskDevice* disk, partition_id selectedPartition)
}
ModificationPreparer modificationPreparer(disk);
status_t ret = modificationPreparer.ModificationStatus();
if (ret != B_OK) {
status_t status = modificationPreparer.ModificationStatus();
if (status != B_OK) {
_DisplayPartitionError(B_TRANSLATE("There was an error preparing the "
"disk for modifications."), NULL, ret);
"disk for modifications."), NULL, status);
return;
}
@@ -1145,18 +1166,112 @@ MainWindow::_Delete(BDiskDevice* disk, partition_id selectedPartition)
if (choice == 1)
return;
ret = parent->DeleteChild(partition->Index());
if (ret != B_OK) {
_DisplayPartitionError(
B_TRANSLATE("Could not delete the selected partition."), NULL, ret);
status = parent->DeleteChild(partition->Index());
if (status != B_OK) {
_DisplayPartitionError(B_TRANSLATE("Could not delete the selected "
"partition."), NULL, status);
return;
}
ret = modificationPreparer.CommitModifications();
status = modificationPreparer.CommitModifications();
if (ret != B_OK) {
if (status != B_OK) {
_DisplayPartitionError(B_TRANSLATE("Failed to delete the partition. "
"No changes have been written to disk."), NULL, ret);
"No changes have been written to disk."), NULL, status);
return;
}
_ScanDrives();
fDiskView->ForceUpdate();
}
void
MainWindow::_ChangeParameters(BDiskDevice* disk, partition_id selectedPartition)
{
if (disk == NULL || selectedPartition < 0) {
_DisplayPartitionError(B_TRANSLATE("You need to select a partition "
"entry from the list."));
return;
}
if (disk->IsReadOnly()) {
_DisplayPartitionError(B_TRANSLATE("The selected disk is read-only."));
return;
}
BPartition* partition = disk->FindDescendant(selectedPartition);
if (partition == NULL) {
_DisplayPartitionError(B_TRANSLATE("Unable to find the selected "
"partition by ID."));
return;
}
ModificationPreparer modificationPreparer(disk);
status_t status = modificationPreparer.ModificationStatus();
if (status != B_OK) {
_DisplayPartitionError(B_TRANSLATE("There was an error preparing the "
"disk for modifications."), NULL, status);
return;
}
ChangeParametersPanel* panel = new ChangeParametersPanel(this, partition);
BString name, type, parameters;
status = panel->Go(name, type, parameters);
if (status != B_OK) {
if (status != B_CANCELED) {
_DisplayPartitionError(B_TRANSLATE("The panel experienced a "
"problem!"), NULL, status);
}
// TODO: disk systems without an editor and support for name/type
// changing will return B_CANCELED here -- we need to check this
// before, and disable the menu entry instead
return;
}
if (partition->CanSetType())
status = partition->ValidateSetType(type.String());
if (status == B_OK && partition->CanSetName())
status = partition->ValidateSetName(&name);
if (status != B_OK) {
_DisplayPartitionError(B_TRANSLATE("Validation of the given parameters "
"failed."));
return;
}
// Warn the user one more time...
BAlert* alert = new BAlert("final notice", B_TRANSLATE("Are you sure you "
"want to change parameters of the selected partition?\n\n"
"The partition may no longer be recognized by other operating systems "
"anymore!"), B_TRANSLATE("Change parameters"), B_TRANSLATE("Cancel"),
NULL, B_WIDTH_FROM_WIDEST, B_WARNING_ALERT);
alert->SetShortcut(1, B_ESCAPE);
int32 choice = alert->Go();
if (choice == 1)
return;
if (partition->CanSetType())
status = partition->SetType(type.String());
if (status == B_OK && partition->CanSetName())
status = partition->SetName(name.String());
if (status == B_OK && partition->CanEditParameters())
status = partition->SetParameters(parameters.String());
if (status != B_OK) {
_DisplayPartitionError(
B_TRANSLATE("Could not change the parameters of the selected "
"partition."), NULL, status);
return;
}
status = modificationPreparer.CommitModifications();
if (status != B_OK) {
_DisplayPartitionError(B_TRANSLATE("Failed to change the parameters "
"of the partition. No changes have been written to disk."), NULL,
status);
return;
}
+5 -2
View File
@@ -71,9 +71,11 @@ private:
partition_id selectedPartition);
void _Delete(BDiskDevice* disk,
partition_id selectedPartition);
void _ChangeParameters(BDiskDevice* disk,
partition_id selectedPartition);
BDiskDeviceRoster fDDRoster;
private:
BDiskDeviceRoster fDiskDeviceRoster;
BDiskDevice* fCurrentDisk;
partition_id fCurrentPartitionID;
@@ -94,6 +96,7 @@ private:
BMenuItem* fRescanMenuItem;
BMenuItem* fCreateMenuItem;
BMenuItem* fChangeMenuItem;
BMenuItem* fDeleteMenuItem;
BMenuItem* fMountMenuItem;
BMenuItem* fUnmountMenuItem;