From 8940ad259ab803eff8176766a73f8f531142c3b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 12 Feb 2013 23:28:24 +0100 Subject: [PATCH] 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. --- .../disk_systems/intel/PartitionMapAddOn.cpp | 3 +- .../drivesetup/AbstractParametersPanel.cpp | 8 +- src/apps/drivesetup/AbstractParametersPanel.h | 1 + src/apps/drivesetup/ChangeParametersPanel.cpp | 196 ++++++++++++ src/apps/drivesetup/ChangeParametersPanel.h | 56 ++++ src/apps/drivesetup/CreateParametersPanel.cpp | 82 +---- src/apps/drivesetup/CreateParametersPanel.h | 14 +- src/apps/drivesetup/Jamfile | 2 + src/apps/drivesetup/MainWindow.cpp | 287 ++++++++++++------ src/apps/drivesetup/MainWindow.h | 7 +- 10 files changed, 484 insertions(+), 172 deletions(-) create mode 100644 src/apps/drivesetup/ChangeParametersPanel.cpp create mode 100644 src/apps/drivesetup/ChangeParametersPanel.h diff --git a/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp b/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp index fa7e6171084..1da8e2a9a5b 100644 --- a/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp +++ b/src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp @@ -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) { diff --git a/src/apps/drivesetup/AbstractParametersPanel.cpp b/src/apps/drivesetup/AbstractParametersPanel.cpp index b161494eb60..c86b5d3233b 100644 --- a/src/apps/drivesetup/AbstractParametersPanel.cpp +++ b/src/apps/drivesetup/AbstractParametersPanel.cpp @@ -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) diff --git a/src/apps/drivesetup/AbstractParametersPanel.h b/src/apps/drivesetup/AbstractParametersPanel.h index 9e24a3383dd..4a83defecd9 100644 --- a/src/apps/drivesetup/AbstractParametersPanel.h +++ b/src/apps/drivesetup/AbstractParametersPanel.h @@ -40,6 +40,7 @@ class AbstractParametersPanel : public BWindow { 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, diff --git a/src/apps/drivesetup/ChangeParametersPanel.cpp b/src/apps/drivesetup/ChangeParametersPanel.cpp new file mode 100644 index 00000000000..978177802a9 --- /dev/null +++ b/src/apps/drivesetup/ChangeParametersPanel.cpp @@ -0,0 +1,196 @@ +/* + * Copyright 2008-2013 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT license. + * + * Authors: + * Stephan Aßmus + * Axel Dörfler, axeld@pinc-software.de. + * Bryce Groff + * Karsten Heimrich + */ + + +#include "ChangeParametersPanel.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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); +} diff --git a/src/apps/drivesetup/ChangeParametersPanel.h b/src/apps/drivesetup/ChangeParametersPanel.h new file mode 100644 index 00000000000..54e96c52cee --- /dev/null +++ b/src/apps/drivesetup/ChangeParametersPanel.h @@ -0,0 +1,56 @@ +/* + * Copyright 2008-2013 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT license. + * + * Authors: + * Stephan Aßmus + * Axel Dörfler, axeld@pinc-software.de. + * Bryce Groff + */ +#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 diff --git a/src/apps/drivesetup/CreateParametersPanel.cpp b/src/apps/drivesetup/CreateParametersPanel.cpp index 145809c97c7..8f3252b014c 100644 --- a/src/apps/drivesetup/CreateParametersPanel.cpp +++ b/src/apps/drivesetup/CreateParametersPanel.cpp @@ -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()); - - // 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); - } + if (status != B_OK) + return status; - 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")); } diff --git a/src/apps/drivesetup/CreateParametersPanel.h b/src/apps/drivesetup/CreateParametersPanel.h index 3ae1ca75d76..9d86451b356 100644 --- a/src/apps/drivesetup/CreateParametersPanel.h +++ b/src/apps/drivesetup/CreateParametersPanel.h @@ -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 @@ class CreateParametersPanel : public AbstractParametersPanel { 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; }; diff --git a/src/apps/drivesetup/Jamfile b/src/apps/drivesetup/Jamfile index b2884801263..7f82eb13eb6 100644 --- a/src/apps/drivesetup/Jamfile +++ b/src/apps/drivesetup/Jamfile @@ -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 diff --git a/src/apps/drivesetup/MainWindow.cpp b/src/apps/drivesetup/MainWindow.cpp index 346a8856ae5..30b6c8fbdee 100644 --- a/src/apps/drivesetup/MainWindow.cpp +++ b/src/apps/drivesetup/MainWindow.cpp @@ -40,6 +40,7 @@ #include +#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 @@ class ListPopulatorVisitor : public BDiskDeviceVisitor { // 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 @@ class ModificationPreparer { } 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 @@ class ModificationPreparer { }; -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; } diff --git a/src/apps/drivesetup/MainWindow.h b/src/apps/drivesetup/MainWindow.h index 26c7df420b0..dbf3f593ce5 100644 --- a/src/apps/drivesetup/MainWindow.h +++ b/src/apps/drivesetup/MainWindow.h @@ -71,9 +71,11 @@ class MainWindow : public BWindow { 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 @@ class MainWindow : public BWindow { BMenuItem* fRescanMenuItem; BMenuItem* fCreateMenuItem; + BMenuItem* fChangeMenuItem; BMenuItem* fDeleteMenuItem; BMenuItem* fMountMenuItem; BMenuItem* fUnmountMenuItem;