From 443522551e70c8a595525700b2b7b445db37865d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 2 Feb 2013 00:59:55 +0100 Subject: [PATCH] Fixed design issues in BPartitionParameterEditor. * The user of an editor needed knowledge about the editor in order to make use of it. * Furthermore, the BPartitionParameterEditor exposed type specific functionality that it shouldn't know anything about, either. * We may now define a number of known parameters per editor type; right now there is only "type" as it's needed by DriveSetup. * Adapted all disk systems, and DriveSetup to the new API. * Renamed CreateParamsPanel, and InitializeParamsPanel to *ParametersPanel in DriveSetup. * They now share a common base class AbstractParametersPanel. --- .../storage/PartitionParameterEditor.h | 29 +- src/add-ons/disk_systems/bfs/BFSAddOn.rdef | 6 +- .../bfs/InitializeParameterEditor.cpp | 93 +++--- .../bfs/InitializeParameterEditor.h | 23 +- .../intel/CreationParameterEditor.cpp | 48 ++- .../intel/CreationParameterEditor.h | 11 +- src/add-ons/disk_systems/intel/Jamfile | 2 +- .../ntfs/InitializeParameterEditor.cpp | 58 ++-- .../ntfs/InitializeParameterEditor.h | 17 +- src/add-ons/disk_systems/ntfs/Jamfile | 6 + src/add-ons/disk_systems/ntfs/NTFSAddOn.rdef | 14 +- .../drivesetup/AbstractParametersPanel.cpp | 248 +++++++++++++++ src/apps/drivesetup/AbstractParametersPanel.h | 58 ++++ src/apps/drivesetup/CreateParamsPanel.cpp | 287 +++++------------- src/apps/drivesetup/CreateParamsPanel.h | 35 +-- src/apps/drivesetup/InitParamsPanel.cpp | 236 ++------------ src/apps/drivesetup/InitParamsPanel.h | 44 +-- src/apps/drivesetup/Jamfile | 1 + src/apps/drivesetup/MainWindow.cpp | 10 +- src/apps/drivesetup/Support.h | 5 - .../disk_device/PartitionParameterEditor.cpp | 109 ++++--- 21 files changed, 667 insertions(+), 673 deletions(-) create mode 100644 src/apps/drivesetup/AbstractParametersPanel.cpp create mode 100644 src/apps/drivesetup/AbstractParametersPanel.h diff --git a/headers/private/storage/PartitionParameterEditor.h b/headers/private/storage/PartitionParameterEditor.h index 701d84e759..757d6d14f4 100644 --- a/headers/private/storage/PartitionParameterEditor.h +++ b/headers/private/storage/PartitionParameterEditor.h @@ -1,4 +1,5 @@ /* + * Copyright 2013, Axel Dörfler, axeld@pinc-software.de. * Copyright 2009, Bryce Groff, brycegroff@gmail.com. * Distributed under the terms of the MIT License. */ @@ -9,26 +10,32 @@ #include -// BPartitionParameterEditor +class BMessage; +class BPartition; +class BVariant; + + class BPartitionParameterEditor { public: BPartitionParameterEditor(); virtual ~BPartitionParameterEditor(); - virtual bool FinishedEditing(); + virtual void SetTo(BPartition* partition); + + void SetModificationMessage(BMessage* message); + BMessage* ModificationMessage() const; virtual BView* View(); - virtual status_t GetParameters(BString* parameters); + virtual bool ValidateParameters() const; + virtual status_t ParameterChanged(const char* name, + const BVariant& variant); - // TODO: Those are child creation specific and shouldn't be in a generic - // interface. Something like a - // GenericPartitionParameterChanged(partition_parameter_type, - // const BVariant&) - // would be better. - virtual status_t PartitionTypeChanged(const char* type); - virtual status_t PartitionNameChanged(const char* name); + virtual status_t GetParameters(BString& parameters); + +private: + BMessage* fModificationMessage; }; -#endif //_PARTITION_PARAMETER_EDITOR_H +#endif // _PARTITION_PARAMETER_EDITOR_H diff --git a/src/add-ons/disk_systems/bfs/BFSAddOn.rdef b/src/add-ons/disk_systems/bfs/BFSAddOn.rdef index 862d9dbe33..3c2589d5db 100644 --- a/src/add-ons/disk_systems/bfs/BFSAddOn.rdef +++ b/src/add-ons/disk_systems/bfs/BFSAddOn.rdef @@ -1,7 +1,3 @@ -/* - * BFSAddOn.rdef - */ - resource app_signature "application/x-vnd.Haiku-BFSAddOn"; resource app_version { @@ -11,5 +7,5 @@ resource app_version { variety = 0, internal = 0, short_info = "1.0.0", - long_info = "Haiku BFS disk add-on." + long_info = "BFS disk add-on." }; diff --git a/src/add-ons/disk_systems/bfs/InitializeParameterEditor.cpp b/src/add-ons/disk_systems/bfs/InitializeParameterEditor.cpp index 50e12534af..99ac65215a 100644 --- a/src/add-ons/disk_systems/bfs/InitializeParameterEditor.cpp +++ b/src/add-ons/disk_systems/bfs/InitializeParameterEditor.cpp @@ -1,4 +1,5 @@ /* + * Copyright 2013, Axel Dörfler, axeld@pinc-software.de. * Copyright 2009-2010, Stephan Aßmus * Copyright 2009, Bryce Groff, brycegroff@gmail.com. * Distributed under the terms of the MIT License. @@ -16,10 +17,11 @@ #include #include #include -#include +#include #include #include #include +#include #include #include @@ -36,10 +38,9 @@ InitializeBFSEditor::InitializeBFSEditor() : BPartitionParameterEditor(), fView(NULL), - fNameTC(NULL), - fBlockSizeMF(NULL), - fUseIndicesCB(NULL), - fParameters(NULL) + fNameControl(NULL), + fBlockSizeMenuField(NULL), + fUseIndicesCheckBox(NULL) { _CreateViewControls(); } @@ -50,6 +51,15 @@ InitializeBFSEditor::~InitializeBFSEditor() } +void +InitializeBFSEditor::SetTo(BPartition* partition) +{ + BString name = partition->ContentName(); + if (!name.IsEmpty()) + fNameControl->SetText(name.String()); +} + + BView* InitializeBFSEditor::View() { @@ -58,41 +68,39 @@ InitializeBFSEditor::View() bool -InitializeBFSEditor::FinishedEditing() +InitializeBFSEditor::ValidateParameters() const { - fParameters = ""; - if (BMenuItem* item = fBlockSizeMF->Menu()->FindMarked()) { - const char* size; - BMessage* message = item->Message(); - if (!message || message->FindString("size", &size) < B_OK) - size = "2048"; - // TODO: use libroot driver settings API - fParameters << "block_size " << size << ";\n"; - } - if (fUseIndicesCB->Value() == B_CONTROL_OFF) - fParameters << "noindex;\n"; - - fParameters << "name \"" << fNameTC->Text() << "\";\n"; - - return true; + // The name must be set + return fNameControl->TextView()->TextLength() > 0; } status_t -InitializeBFSEditor::GetParameters(BString* parameters) +InitializeBFSEditor::ParameterChanged(const char* name, const BVariant& variant) { - if (parameters == NULL) - return B_BAD_VALUE; - - *parameters = fParameters; + if (!strcmp(name, "name")) + fNameControl->SetText(variant.ToString()); return B_OK; } status_t -InitializeBFSEditor::PartitionNameChanged(const char* name) +InitializeBFSEditor::GetParameters(BString& parameters) { - fNameTC->SetText(name); + parameters = ""; + + if (BMenuItem* item = fBlockSizeMenuField->Menu()->FindMarked()) { + const char* size; + BMessage* message = item->Message(); + if (!message || message->FindString("size", &size) < B_OK) + size = "2048"; + // TODO: use libroot driver settings API + parameters << "block_size " << size << ";\n"; + } + if (fUseIndicesCheckBox->Value() == B_CONTROL_OFF) + parameters << "noindex;\n"; + + parameters << "name \"" << fNameControl->Text() << "\";\n"; return B_OK; } @@ -100,10 +108,9 @@ InitializeBFSEditor::PartitionNameChanged(const char* name) void InitializeBFSEditor::_CreateViewControls() { - fNameTC = new BTextControl(B_TRANSLATE("Name:"), "Haiku", NULL); - fNameTC->SetModificationMessage(new BMessage(MSG_NAME_CHANGED)); - // TODO find out what is the max length for this specific FS partition name - fNameTC->TextView()->SetMaxBytes(31); + fNameControl = new BTextControl(B_TRANSLATE("Name:"), "Haiku", NULL); + fNameControl->SetModificationMessage(new BMessage(MSG_NAME_CHANGED)); + fNameControl->TextView()->SetMaxBytes(31); BPopUpMenu* blocksizeMenu = new BPopUpMenu("blocksize"); BMessage* message = new BMessage(MSG_BLOCK_SIZE); @@ -123,13 +130,15 @@ InitializeBFSEditor::_CreateViewControls() blocksizeMenu->AddItem(new BMenuItem( B_TRANSLATE("8192 (Mostly large files)"), message)); - fBlockSizeMF = new BMenuField(B_TRANSLATE("Blocksize:"), blocksizeMenu); + fBlockSizeMenuField = new BMenuField(B_TRANSLATE("Blocksize:"), + blocksizeMenu); defaultItem->SetMarked(true); - fUseIndicesCB = new BCheckBox(B_TRANSLATE("Enable query support"), NULL); - fUseIndicesCB->SetValue(true); - fUseIndicesCB->SetToolTip(B_TRANSLATE("Disabling query support may speed " - "up certain file system operations, but should only be used " + fUseIndicesCheckBox = new BCheckBox(B_TRANSLATE("Enable query support"), + NULL); + fUseIndicesCheckBox->SetValue(true); + fUseIndicesCheckBox->SetToolTip(B_TRANSLATE("Disabling query support may " + "speed up certain file system operations, but should only be used " "if one is absolutely certain that one will not need queries.\n" "Any volume that is intended for booting Haiku must have query " "support enabled.")); @@ -138,14 +147,14 @@ InitializeBFSEditor::_CreateViewControls() fView = BGridLayoutBuilder(spacing, spacing) // row 1 - .Add(fNameTC->CreateLabelLayoutItem(), 0, 0) - .Add(fNameTC->CreateTextViewLayoutItem(), 1, 0) + .Add(fNameControl->CreateLabelLayoutItem(), 0, 0) + .Add(fNameControl->CreateTextViewLayoutItem(), 1, 0) // row 2 - .Add(fBlockSizeMF->CreateLabelLayoutItem(), 0, 1) - .Add(fBlockSizeMF->CreateMenuBarLayoutItem(), 1, 1) + .Add(fBlockSizeMenuField->CreateLabelLayoutItem(), 0, 1) + .Add(fBlockSizeMenuField->CreateMenuBarLayoutItem(), 1, 1) // row 3 - .Add(fUseIndicesCB, 0, 2, 2).View() + .Add(fUseIndicesCheckBox, 0, 2, 2).View() ; } diff --git a/src/add-ons/disk_systems/bfs/InitializeParameterEditor.h b/src/add-ons/disk_systems/bfs/InitializeParameterEditor.h index 339cea0519..9f7abc32e9 100644 --- a/src/add-ons/disk_systems/bfs/InitializeParameterEditor.h +++ b/src/add-ons/disk_systems/bfs/InitializeParameterEditor.h @@ -1,4 +1,5 @@ /* + * Copyright 2013, Axel Dörfler, axeld@pinc-software.de. * Copyright 2009-2010, Stephan Aßmus * Copyright 2009, Bryce Groff, brycegroff@gmail.com. * Distributed under the terms of the MIT License. @@ -10,6 +11,7 @@ #include #include + class BCheckBox; class BMenuField; class BTextControl; @@ -21,21 +23,24 @@ public: InitializeBFSEditor(); virtual ~InitializeBFSEditor(); - virtual bool FinishedEditing(); - virtual BView* View(); - virtual status_t GetParameters(BString* parameters); + virtual void SetTo(BPartition* partition); - virtual status_t PartitionNameChanged(const char* name); + virtual bool ValidateParameters() const; + virtual status_t ParameterChanged(const char* name, + const BVariant& variant); + + virtual BView* View(); + + virtual status_t GetParameters(BString& parameters); private: void _CreateViewControls(); +private: BView* fView; - BTextControl* fNameTC; - BMenuField* fBlockSizeMF; - BCheckBox* fUseIndicesCB; - - BString fParameters; + BTextControl* fNameControl; + BMenuField* fBlockSizeMenuField; + BCheckBox* fUseIndicesCheckBox; }; diff --git a/src/add-ons/disk_systems/intel/CreationParameterEditor.cpp b/src/add-ons/disk_systems/intel/CreationParameterEditor.cpp index 881a6e07b9..75c3819b9e 100644 --- a/src/add-ons/disk_systems/intel/CreationParameterEditor.cpp +++ b/src/add-ons/disk_systems/intel/CreationParameterEditor.cpp @@ -1,4 +1,5 @@ /* + * Copyright 2013, Axel Dörfler, axeld@pinc-software.de. * Copyright 2009, Bryce Groff, brycegroff@gmail.com. * Distributed under the terms of the MIT License. */ @@ -10,15 +11,15 @@ #include #include #include +#include #include + #undef B_TRANSLATION_CONTEXT -#define B_TRANSLATION_CONTEXT "BFS_Creation_Parameter" +#define B_TRANSLATION_CONTEXT "PrimaryPartitionEditor" PrimaryPartitionEditor::PrimaryPartitionEditor() - : - fParameters(NULL) { fActiveCheckBox = new BCheckBox("active", B_TRANSLATE("Active partition"), NULL); @@ -39,35 +40,28 @@ PrimaryPartitionEditor::View() } -bool -PrimaryPartitionEditor::FinishedEditing() +status_t +PrimaryPartitionEditor::ParameterChanged(const char* name, + const BVariant& variant) +{ + if (!strcmp(name, "type")) { + fActiveCheckBox->SetEnabled(strcmp(variant.ToString(), + kPartitionTypeIntelExtended) != 0); + } + return B_OK; +} + + +status_t +PrimaryPartitionEditor::GetParameters(BString& parameters) { if (fActiveCheckBox->IsEnabled()) { if (fActiveCheckBox->Value() == B_CONTROL_ON) - fParameters.SetTo("active true ;"); + parameters.SetTo("active true ;"); else - fParameters.SetTo("active false ;"); + parameters.SetTo("active false ;"); } else - fParameters.SetTo(""); + parameters.SetTo(""); - return true; -} - - -status_t -PrimaryPartitionEditor::GetParameters(BString* parameters) -{ - if (fParameters == NULL) - return B_BAD_VALUE; - - *parameters = fParameters; - return B_OK; -} - - -status_t -PrimaryPartitionEditor::PartitionTypeChanged(const char* type) -{ - fActiveCheckBox->SetEnabled(strcmp(type, kPartitionTypeIntelExtended) != 0); return B_OK; } diff --git a/src/add-ons/disk_systems/intel/CreationParameterEditor.h b/src/add-ons/disk_systems/intel/CreationParameterEditor.h index ff2374db21..e165560668 100644 --- a/src/add-ons/disk_systems/intel/CreationParameterEditor.h +++ b/src/add-ons/disk_systems/intel/CreationParameterEditor.h @@ -1,4 +1,5 @@ /* + * Copyright 2013, Axel Dörfler, axeld@pinc-software.de. * Copyright 2009, Bryce Groff, brycegroff@gmail.com. * Distributed under the terms of the MIT License. */ @@ -18,17 +19,17 @@ public: PrimaryPartitionEditor(); virtual ~PrimaryPartitionEditor(); - virtual bool FinishedEditing(); virtual BView* View(); - virtual status_t GetParameters(BString* parameters); - virtual status_t PartitionTypeChanged(const char* type); + virtual status_t ParameterChanged(const char* name, + const BVariant& variant); + + virtual status_t GetParameters(BString& parameters); private: BView* fView; BCheckBox* fActiveCheckBox; - BString fParameters; }; -#endif //_CREATION_PARAMETER_EDITOR +#endif // _CREATION_PARAMETER_EDITOR diff --git a/src/add-ons/disk_systems/intel/Jamfile b/src/add-ons/disk_systems/intel/Jamfile index fac4f5d0db..db47924aba 100644 --- a/src/add-ons/disk_systems/intel/Jamfile +++ b/src/add-ons/disk_systems/intel/Jamfile @@ -23,7 +23,7 @@ Addon intel : # kernel sources PartitionMap.cpp - : be $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSUPC++) + : be libshared.a $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSUPC++) ; DoCatalogs intel : diff --git a/src/add-ons/disk_systems/ntfs/InitializeParameterEditor.cpp b/src/add-ons/disk_systems/ntfs/InitializeParameterEditor.cpp index ba14586b9f..a5c9a134b4 100644 --- a/src/add-ons/disk_systems/ntfs/InitializeParameterEditor.cpp +++ b/src/add-ons/disk_systems/ntfs/InitializeParameterEditor.cpp @@ -1,4 +1,5 @@ /* + * Copyright 2013, Axel Dörfler, axeld@pinc-software.de. * Copyright 2009-2010, Stephan Aßmus * Copyright 2009, Bryce Groff, brycegroff@gmail.com. * Distributed under the terms of the MIT License. @@ -11,19 +12,20 @@ #include #include -#include #include #include -#include -#include -#include -#include +#include #include #include +#include #include #include +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "NTFS_Initialize_Parameter" + + static uint32 MSG_NAME_CHANGED = 'nmch'; @@ -31,7 +33,7 @@ InitializeNTFSEditor::InitializeNTFSEditor() : BPartitionParameterEditor(), fView(NULL), - fNameTC(NULL), + fNameControl(NULL), fParameters(NULL) { _CreateViewControls(); @@ -43,6 +45,15 @@ InitializeNTFSEditor::~InitializeNTFSEditor() } +void +InitializeNTFSEditor::SetTo(BPartition* partition) +{ + BString name = partition->ContentName(); + if (!name.IsEmpty()) + fNameControl->SetText(name.String()); +} + + BView* InitializeNTFSEditor::View() { @@ -51,30 +62,28 @@ InitializeNTFSEditor::View() bool -InitializeNTFSEditor::FinishedEditing() +InitializeNTFSEditor::ValidateParameters() const { - fParameters = ""; - fParameters << "name \"" << fNameTC->Text() << "\";\n"; - - return true; + // The name must be set + return fNameControl->TextView()->TextLength() > 0; } status_t -InitializeNTFSEditor::GetParameters(BString* parameters) +InitializeNTFSEditor::ParameterChanged(const char* name, + const BVariant& variant) { - if (parameters == NULL) - return B_BAD_VALUE; - - *parameters = fParameters; + if (!strcmp(name, "name")) + fNameControl->SetText(variant.ToString()); return B_OK; } status_t -InitializeNTFSEditor::PartitionNameChanged(const char* name) +InitializeNTFSEditor::GetParameters(BString& parameters) { - fNameTC->SetText(name); + parameters = "name \""; + parameters << fNameControl->Text() << "\";\n"; return B_OK; } @@ -82,16 +91,15 @@ InitializeNTFSEditor::PartitionNameChanged(const char* name) void InitializeNTFSEditor::_CreateViewControls() { - fNameTC = new BTextControl("Name:", "New NTFS Volume", NULL); - fNameTC->SetModificationMessage(new BMessage(MSG_NAME_CHANGED)); - // TODO find out what is the max length for this specific FS partition name - fNameTC->TextView()->SetMaxBytes(31); + fNameControl = new BTextControl(B_TRANSLATE("Name:"), "New NTFS Volume", + NULL); + fNameControl->SetModificationMessage(new BMessage(MSG_NAME_CHANGED)); + fNameControl->TextView()->SetMaxBytes(127); float spacing = be_control_look->DefaultItemSpacing(); fView = BGridLayoutBuilder(spacing, spacing) - // row 1 - .Add(fNameTC->CreateLabelLayoutItem(), 0, 0) - .Add(fNameTC->CreateTextViewLayoutItem(), 1, 0).View() + .Add(fNameControl->CreateLabelLayoutItem(), 0, 0) + .Add(fNameControl->CreateTextViewLayoutItem(), 1, 0).View() ; } diff --git a/src/add-ons/disk_systems/ntfs/InitializeParameterEditor.h b/src/add-ons/disk_systems/ntfs/InitializeParameterEditor.h index bdb66471d8..5a4ce7db96 100644 --- a/src/add-ons/disk_systems/ntfs/InitializeParameterEditor.h +++ b/src/add-ons/disk_systems/ntfs/InitializeParameterEditor.h @@ -1,4 +1,5 @@ /* + * Copyright 2013, Axel Dörfler, axeld@pinc-software.de. * Copyright 2009-2010, Stephan Aßmus * Copyright 2009, Bryce Groff, brycegroff@gmail.com. * Distributed under the terms of the MIT License. @@ -10,6 +11,7 @@ #include #include + class BCheckBox; class BMenuField; class BTextControl; @@ -21,17 +23,22 @@ public: InitializeNTFSEditor(); virtual ~InitializeNTFSEditor(); - virtual bool FinishedEditing(); - virtual BView* View(); - virtual status_t GetParameters(BString* parameters); + virtual void SetTo(BPartition* partition); - virtual status_t PartitionNameChanged(const char* name); + virtual bool ValidateParameters() const; + virtual status_t ParameterChanged(const char* name, + const BVariant& variant); + + virtual BView* View(); + + virtual status_t GetParameters(BString& parameters); private: void _CreateViewControls(); +private: BView* fView; - BTextControl* fNameTC; + BTextControl* fNameControl; BString fParameters; }; diff --git a/src/add-ons/disk_systems/ntfs/Jamfile b/src/add-ons/disk_systems/ntfs/Jamfile index 342108b552..4abdcfbb85 100644 --- a/src/add-ons/disk_systems/ntfs/Jamfile +++ b/src/add-ons/disk_systems/ntfs/Jamfile @@ -13,3 +13,9 @@ Addon ntfs : : be $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSUPC++) libshared.a ; + +DoCatalogs ntfs : + x-vnd.Haiku-NTFSDiskAddOn + : + InitializeParameterEditor.cpp +; diff --git a/src/add-ons/disk_systems/ntfs/NTFSAddOn.rdef b/src/add-ons/disk_systems/ntfs/NTFSAddOn.rdef index 44435fe18f..7cb9cd547b 100644 --- a/src/add-ons/disk_systems/ntfs/NTFSAddOn.rdef +++ b/src/add-ons/disk_systems/ntfs/NTFSAddOn.rdef @@ -1,15 +1,11 @@ -/* - * NTFSAddOn.rdef - */ - -resource app_signature "application/x-vnd.Haiku-NTFSAddOn"; +resource app_signature "application/x-vnd.Haiku-NTFSDiskAddOn"; resource app_version { - major = 0, + major = 1, middle = 0, - minor = 1, + minor = 0, variety = 0, internal = 0, - short_info = "0.0.1", - long_info = "Haiku NTFS disk add-on." + short_info = "1.0.0", + long_info = "NTFS disk add-on." }; diff --git a/src/apps/drivesetup/AbstractParametersPanel.cpp b/src/apps/drivesetup/AbstractParametersPanel.cpp new file mode 100644 index 0000000000..1c38f64029 --- /dev/null +++ b/src/apps/drivesetup/AbstractParametersPanel.cpp @@ -0,0 +1,248 @@ +/* + * 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. + * Karsten Heimrich. + */ + + +#include "AbstractParametersPanel.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "AbstractParametersPanel" + + +static const uint32 kMsgOk = 'okok'; +static const uint32 kParameterChanged = 'pmch'; + + +class AbstractParametersPanel::EscapeFilter : public BMessageFilter { +public: + EscapeFilter(AbstractParametersPanel* target) + : + BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE), + fPanel(target) + { + } + + virtual ~EscapeFilter() + { + } + + virtual filter_result Filter(BMessage* message, BHandler** target) + { + filter_result result = B_DISPATCH_MESSAGE; + switch (message->what) { + case B_KEY_DOWN: + case B_UNMAPPED_KEY_DOWN: { + uint32 key; + if (message->FindInt32("raw_char", (int32*)&key) >= B_OK) { + if (key == B_ESCAPE) { + result = B_SKIP_MESSAGE; + fPanel->Cancel(); + } + } + break; + } + default: + break; + } + return result; + } + +private: + AbstractParametersPanel* fPanel; +}; + + +// #pragma mark - + + +AbstractParametersPanel::AbstractParametersPanel(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), + fOkButton(new BButton(B_TRANSLATE("OK"), new BMessage(kMsgOk))), + fReturnStatus(B_CANCELED), + fEditor(NULL), + fEscapeFilter(new EscapeFilter(this)), + fExitSemaphore(create_sem(0, "AbstractParametersPanel exit")), + fWindow(window) +{ + AddCommonFilter(fEscapeFilter); + AddToSubset(fWindow); +} + + +AbstractParametersPanel::~AbstractParametersPanel() +{ + RemoveCommonFilter(fEscapeFilter); + delete fEscapeFilter; + + delete_sem(fExitSemaphore); + + if (fEditor == NULL) + delete fOkButton; +} + + +bool +AbstractParametersPanel::QuitRequested() +{ + release_sem(fExitSemaphore); + return false; +} + + +void +AbstractParametersPanel::MessageReceived(BMessage* message) +{ + switch (message->what) { + case B_CANCEL: + Cancel(); + break; + + case kMsgOk: + fReturnStatus = B_OK; + release_sem(fExitSemaphore); + break; + + case kParameterChanged: + fOkButton->SetEnabled(fEditor->ValidateParameters()); + break; + + default: + BWindow::MessageReceived(message); + } +} + + +status_t +AbstractParametersPanel::Go(BString& parameters) +{ + // Without an editor, we cannot change anything, anyway + if (fEditor == NULL) { + parameters = ""; + if (fReturnStatus == B_CANCELED) + fReturnStatus = B_OK; + + if (!Lock()) + return B_ERROR; + } else { + // run the window thread, to get an initial layout of the controls + Hide(); + Show(); + if (!Lock()) + return B_CANCELED; + + // center the panel above the parent window + CenterIn(fWindow->Frame()); + + Show(); + Unlock(); + + // block this thread now, but keep the window repainting + while (true) { + status_t status = acquire_sem_etc(fExitSemaphore, 1, + B_CAN_INTERRUPT | B_RELATIVE_TIMEOUT, 50000); + if (status != B_TIMED_OUT && status != B_INTERRUPTED) + break; + fWindow->UpdateIfNeeded(); + } + + if (!Lock()) + return B_CANCELED; + + if (fReturnStatus == B_OK) { + if (fEditor->ValidateParameters()) { + status_t err = fEditor->GetParameters(parameters); + if (err != B_OK) + fReturnStatus = err; + } + } + } + + status_t status = fReturnStatus; + + Quit(); + // NOTE: this object is toast now! + + return status; +} + + +void +AbstractParametersPanel::Cancel() +{ + fReturnStatus = B_CANCELED; + release_sem(fExitSemaphore); +} + + +void +AbstractParametersPanel::Init(B_PARAMETER_EDITOR_TYPE type, + const BString& diskSystem, BPartition* partition) +{ + // Create partition parameter editor + + status_t status = B_ERROR; + if (diskSystem.IsEmpty()) { + status = partition->GetParameterEditor(type, &fEditor); + } else { + DiskSystemAddOnManager* manager = DiskSystemAddOnManager::Default(); + BDiskSystemAddOn* addOn = manager->GetAddOn(diskSystem); + if (addOn != NULL) { + // put the add-on + manager->PutAddOn(addOn); + + status = addOn->GetParameterEditor(type, &fEditor); + } + } + if (status != B_OK && status != B_NOT_SUPPORTED) + fReturnStatus = status; + + if (fEditor == NULL) + return; + + // Create controls + + BLayoutBuilder::Group<> builder = BLayoutBuilder::Group<>(this, + B_VERTICAL); + AddControls(builder, fEditor->View()); + + builder.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING) + .AddGlue() + .Add(new BButton(B_TRANSLATE("Cancel"), new BMessage(B_CANCEL))) + .Add(fOkButton) + .End() + .SetInsets(B_USE_DEFAULT_SPACING); + + SetDefaultButton(fOkButton); + + fEditor->SetTo(partition); + fEditor->SetModificationMessage(new BMessage(kParameterChanged)); +} + + +void +AbstractParametersPanel::AddControls(BLayoutBuilder::Group<>& builder, + BView* editorView) +{ + builder.Add(editorView); +} diff --git a/src/apps/drivesetup/AbstractParametersPanel.h b/src/apps/drivesetup/AbstractParametersPanel.h new file mode 100644 index 0000000000..123e9574c6 --- /dev/null +++ b/src/apps/drivesetup/AbstractParametersPanel.h @@ -0,0 +1,58 @@ +/* + * 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. + */ +#ifndef ABSTRACT_PARAMETERS_PANEL_H +#define ABSTRACT_PARAMETERS_PANEL_H + + +#include +#include +#include +#include + +#include "Support.h" + + +class BMenuField; +class BTextControl; + + +class AbstractParametersPanel : public BWindow { +public: + AbstractParametersPanel(BWindow* window); + virtual ~AbstractParametersPanel(); + + virtual bool QuitRequested(); + virtual void MessageReceived(BMessage* message); + + status_t Go(BString& parameters); + void Cancel(); + +protected: + void Init(B_PARAMETER_EDITOR_TYPE type, + const BString& diskSystem, + BPartition* partition); + + virtual void AddControls(BLayoutBuilder::Group<>& builder, + BView* editorView); + +protected: + BButton* fOkButton; + status_t fReturnStatus; + + BPartitionParameterEditor* fEditor; + +private: + class EscapeFilter; + EscapeFilter* fEscapeFilter; + sem_id fExitSemaphore; + BWindow* fWindow; +}; + + +#endif // ABSTRACT_PARAMETERS_PANEL_H diff --git a/src/apps/drivesetup/CreateParamsPanel.cpp b/src/apps/drivesetup/CreateParamsPanel.cpp index deeee1219a..42abf27031 100644 --- a/src/apps/drivesetup/CreateParamsPanel.cpp +++ b/src/apps/drivesetup/CreateParamsPanel.cpp @@ -1,9 +1,10 @@ /* - * Copyright 2008-2012 Haiku Inc. All rights reserved. + * 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 */ @@ -15,89 +16,34 @@ #include #include #include -#include -#include -#include -#include #include #include -#include #include #include -#include -#include #include +#include +#include #include "Support.h" #undef B_TRANSLATION_CONTEXT -#define B_TRANSLATION_CONTEXT "CreateParamsPanel" - - -class CreateParamsPanel::EscapeFilter : public BMessageFilter { -public: - EscapeFilter(CreateParamsPanel* target) - : - BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE), - fPanel(target) - { - } - - virtual ~EscapeFilter() - { - } - - virtual filter_result Filter(BMessage* message, BHandler** target) - { - filter_result result = B_DISPATCH_MESSAGE; - switch (message->what) { - case B_KEY_DOWN: - case B_UNMAPPED_KEY_DOWN: { - uint32 key; - if (message->FindInt32("raw_char", (int32*)&key) >= B_OK) { - if (key == B_ESCAPE) { - result = B_SKIP_MESSAGE; - fPanel->Cancel(); - } - } - break; - } - default: - break; - } - return result; - } - -private: - CreateParamsPanel* fPanel; -}; - - -// #pragma mark - +#define B_TRANSLATION_CONTEXT "CreateParametersPanel" enum { - MSG_OK = 'okok', - MSG_CANCEL = 'cncl', MSG_PARTITION_TYPE = 'type', MSG_SIZE_SLIDER = 'ssld', MSG_SIZE_TEXTCONTROL = 'stct' }; -CreateParamsPanel::CreateParamsPanel(BWindow* window, BPartition* partition, - off_t offset, off_t size) +CreateParametersPanel::CreateParametersPanel(BWindow* window, + BPartition* partition, off_t offset, off_t size) : - 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, "CreateParamsPanel exit")), - fWindow(window), - fReturnValue(GO_CANCELED) + AbstractParametersPanel(window) { - AddCommonFilter(fEscapeFilter); + Init(B_CREATE_PARAMETER_EDITOR, "", partition); // Scale offset, and size from bytes to megabytes (2^20) // so that we do not run over a signed int32. @@ -107,138 +53,56 @@ CreateParamsPanel::CreateParamsPanel(BWindow* window, BPartition* partition, } -CreateParamsPanel::~CreateParamsPanel() +CreateParametersPanel::~CreateParametersPanel() { - RemoveCommonFilter(fEscapeFilter); - delete fEscapeFilter; - - delete_sem(fExitSemaphore); } -bool -CreateParamsPanel::QuitRequested() -{ - release_sem(fExitSemaphore); - return false; -} - - -void -CreateParamsPanel::MessageReceived(BMessage* message) -{ - switch (message->what) { - case MSG_CANCEL: - Cancel(); - break; - - case MSG_OK: - fReturnValue = GO_SUCCESS; - release_sem(fExitSemaphore); - break; - - case MSG_PARTITION_TYPE: - if (fEditor != NULL) { - const char* type; - message->FindString("type", &type); - fEditor->PartitionTypeChanged(type); - } - break; - - case MSG_SIZE_SLIDER: - _UpdateSizeTextControl(); - break; - - case MSG_SIZE_TEXTCONTROL: - { - int32 size = atoi(fSizeTextControl->Text()); - if (size >= 0 && size <= fSizeSlider->MaxPartitionSize()) - fSizeSlider->SetValue(size + fSizeSlider->Offset()); - else - _UpdateSizeTextControl(); - break; - } - - default: - BWindow::MessageReceived(message); - } -} - - -int32 -CreateParamsPanel::Go(off_t& offset, off_t& size, BString& name, +status_t +CreateParametersPanel::Go(off_t& offset, off_t& size, BString& name, BString& type, BString& parameters) { - // run the window thread, to get an initial layout of the controls - Hide(); - Show(); - if (!Lock()) - return GO_CANCELED; + // The object will be deleted in Go(), so we need to get the values before - // center the panel above the parent window - CenterIn(fWindow->Frame()); + // Return the value back as bytes. + size = (off_t)fSizeSlider->Size() * kMegaByte; + offset = (off_t)fSizeSlider->Offset() * kMegaByte; - Show(); - Unlock(); + // get name + name.SetTo(fNameTextControl->Text()); - // block this thread now, but keep the window repainting - while (true) { - status_t err = acquire_sem_etc(fExitSemaphore, 1, - B_CAN_INTERRUPT | B_RELATIVE_TIMEOUT, 50000); - if (err != B_TIMED_OUT && err != B_INTERRUPTED) - break; - fWindow->UpdateIfNeeded(); + // 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; + type << _type; } - if (!Lock()) - return GO_CANCELED; - - if (fReturnValue == GO_SUCCESS) { - // Return the value back as bytes. - size = (off_t)fSizeSlider->Size() * kMegaByte; - offset = (off_t)fSizeSlider->Offset() * kMegaByte; - - // get name - name.SetTo(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; - type << _type; - } - - // get editors parameters - if (fEditor != NULL) { - if (fEditor->FinishedEditing()) { - status_t status = fEditor->GetParameters(¶meters); - if (status != B_OK) - fReturnValue = status; - } - } - } - - int32 value = fReturnValue; - - Quit(); - // NOTE: this object is toast now! - - return value; + return AbstractParametersPanel::Go(parameters); } void -CreateParamsPanel::Cancel() +CreateParametersPanel::AddControls(BLayoutBuilder::Group<>& builder, + BView* editorView) { - fReturnValue = GO_CANCELED; - release_sem(fExitSemaphore); + builder + .Add(fSizeSlider) + .Add(fSizeTextControl) + .AddGrid(0.0, 5.0) + .Add(fNameTextControl->CreateLabelLayoutItem(), 0, 0) + .Add(fNameTextControl->CreateTextViewLayoutItem(), 1, 0) + .Add(fTypeMenuField->CreateLabelLayoutItem(), 0, 1) + .Add(fTypeMenuField->CreateMenuBarLayoutItem(), 1, 1) + .End() + .Add(editorView); } void -CreateParamsPanel::_CreateViewControls(BPartition* parent, off_t offset, +CreateParametersPanel::_CreateViewControls(BPartition* parent, off_t offset, off_t size) { // Setup the controls @@ -265,8 +129,7 @@ CreateParamsPanel::_CreateViewControls(BPartition* parent, off_t offset, int32 cookie = 0; BString supportedType; - while (parent->GetNextSupportedChildType(&cookie, &supportedType) - == B_OK) { + while (parent->GetNextSupportedChildType(&cookie, &supportedType) == B_OK) { BMessage* message = new BMessage(MSG_PARTITION_TYPE); message->AddString("type", supportedType); BMenuItem* item = new BMenuItem(supportedType, message); @@ -279,46 +142,44 @@ CreateParamsPanel::_CreateViewControls(BPartition* parent, off_t offset, fTypeMenuField = new BMenuField(B_TRANSLATE("Partition type:"), fTypePopUpMenu); - const float spacing = be_control_look->DefaultItemSpacing(); - BGroupLayout* layout = new BGroupLayout(B_VERTICAL, spacing); - layout->SetInsets(spacing, spacing, spacing, spacing); - - SetLayout(layout); - - AddChild(BGroupLayoutBuilder(B_VERTICAL, spacing) - .Add(fSizeSlider) - .Add(fSizeTextControl) - .Add(BGridLayoutBuilder(0.0, 5.0) - .Add(fNameTextControl->CreateLabelLayoutItem(), 0, 0) - .Add(fNameTextControl->CreateTextViewLayoutItem(), 1, 0) - .Add(fTypeMenuField->CreateLabelLayoutItem(), 0, 1) - .Add(fTypeMenuField->CreateMenuBarLayoutItem(), 1, 1) - ) - ); - - status_t err = parent->GetParameterEditor(B_CREATE_PARAMETER_EDITOR, - &fEditor); - if (err == B_OK && fEditor != NULL) - AddChild(fEditor->View()); - else - fEditor = NULL; - - BButton* okButton = new BButton(B_TRANSLATE("Create"), - new BMessage(MSG_OK)); - AddChild(BGroupLayoutBuilder(B_HORIZONTAL, spacing) - .AddGlue() - .Add(new BButton(B_TRANSLATE("Cancel"), new BMessage(MSG_CANCEL))) - .Add(okButton) - ); - SetDefaultButton(okButton); - - AddToSubset(fWindow); - layout->View()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + fOkButton->SetLabel(B_TRANSLATE("Create")); } void -CreateParamsPanel::_UpdateSizeTextControl() +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; + + case MSG_SIZE_TEXTCONTROL: + { + int32 size = atoi(fSizeTextControl->Text()); + if (size >= 0 && size <= fSizeSlider->MaxPartitionSize()) + fSizeSlider->SetValue(size + fSizeSlider->Offset()); + else + _UpdateSizeTextControl(); + break; + } + + default: + AbstractParametersPanel::MessageReceived(message); + } +} + + +void +CreateParametersPanel::_UpdateSizeTextControl() { BString sizeString; sizeString << fSizeSlider->Value() - fSizeSlider->Offset(); diff --git a/src/apps/drivesetup/CreateParamsPanel.h b/src/apps/drivesetup/CreateParamsPanel.h index eef3cc2011..4746397985 100644 --- a/src/apps/drivesetup/CreateParamsPanel.h +++ b/src/apps/drivesetup/CreateParamsPanel.h @@ -1,40 +1,40 @@ /* - * Copyright 2008-2012 Haiku Inc. All rights reserved. + * 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 CREATE_PARAMS_PANEL_H #define CREATE_PARAMS_PANEL_H -#include -#include -#include -#include +#include "AbstractParametersPanel.h" class BMenuField; +class BPopUpMenu; class BTextControl; class SizeSlider; -class CreateParamsPanel : public BWindow { +class CreateParametersPanel : public AbstractParametersPanel { public: - CreateParamsPanel(BWindow* window, + CreateParametersPanel(BWindow* window, BPartition* parent, off_t offset, off_t size); - virtual ~CreateParamsPanel(); + virtual ~CreateParametersPanel(); + + status_t Go(off_t& offset, off_t& size, BString& name, + BString& type, BString& parameters); - virtual bool QuitRequested(); virtual void MessageReceived(BMessage* message); - int32 Go(off_t& offset, off_t& size, BString& name, - BString& type, BString& parameters); - void Cancel(); - +protected: + virtual void AddControls(BLayoutBuilder::Group<>& builder, + BView* editorView); private: void _CreateViewControls(BPartition* parent, @@ -43,15 +43,6 @@ private: void _UpdateSizeTextControl(); private: - class EscapeFilter; - - EscapeFilter* fEscapeFilter; - sem_id fExitSemaphore; - BWindow* fWindow; - int32 fReturnValue; - - BPartitionParameterEditor* fEditor; - BPopUpMenu* fTypePopUpMenu; BMenuField* fTypeMenuField; BTextControl* fNameTextControl; diff --git a/src/apps/drivesetup/InitParamsPanel.cpp b/src/apps/drivesetup/InitParamsPanel.cpp index 6d03f83fc3..9c8ae569b3 100644 --- a/src/apps/drivesetup/InitParamsPanel.cpp +++ b/src/apps/drivesetup/InitParamsPanel.cpp @@ -4,6 +4,7 @@ * * Authors: * Stephan Aßmus + * Axel Dörfler, axeld@pinc-software.de. * Karsten Heimrich. */ @@ -15,240 +16,41 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #undef B_TRANSLATION_CONTEXT -#define B_TRANSLATION_CONTEXT "InitParamsPanel" +#define B_TRANSLATION_CONTEXT "InitializeParametersPanel" -class InitParamsPanel::EscapeFilter : public BMessageFilter { -public: - EscapeFilter(InitParamsPanel* target) - : - BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE), - fPanel(target) - { - } - - virtual ~EscapeFilter() - { - } - - virtual filter_result Filter(BMessage* message, BHandler** target) - { - filter_result result = B_DISPATCH_MESSAGE; - switch (message->what) { - case B_KEY_DOWN: - case B_UNMAPPED_KEY_DOWN: { - uint32 key; - if (message->FindInt32("raw_char", (int32*)&key) >= B_OK) { - if (key == B_ESCAPE) { - result = B_SKIP_MESSAGE; - fPanel->Cancel(); - } - } - break; - } - default: - break; - } - return result; - } - -private: - InitParamsPanel* fPanel; -}; - - -// #pragma mark - - - -// TODO: MSG_NAME_CHANGED is shared with the disk system add-ons, so it should -// be in some private shared header. -// TODO: there is already B_CANCEL, why not use that one? -enum { - MSG_OK = 'okok', - MSG_CANCEL = 'cncl', - MSG_NAME_CHANGED = 'nmch' -}; - - -InitParamsPanel::InitParamsPanel(BWindow* window, const BString& diskSystem, - BPartition* partition) +InitParametersPanel::InitParametersPanel(BWindow* window, + const BString& diskSystem, BPartition* partition) : - 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) + AbstractParametersPanel(window) { - AddCommonFilter(fEscapeFilter); + Init(B_INITIALIZE_PARAMETER_EDITOR, diskSystem, partition); - fOkButton = new BButton(B_TRANSLATE("Initialize"), new BMessage(MSG_OK)); - - DiskSystemAddOnManager* manager = DiskSystemAddOnManager::Default(); - BDiskSystemAddOn* addOn = manager->GetAddOn(diskSystem); - if (addOn) { - // put the add-on - manager->PutAddOn(addOn); - - status_t err = addOn->GetParameterEditor(B_INITIALIZE_PARAMETER_EDITOR, - &fEditor); - if (err != B_OK) - fEditor = NULL; - } else { - fEditor = NULL; - } - if (fEditor == NULL) - return; - - SetLayout(new BGroupLayout(B_HORIZONTAL)); - const float spacing = be_control_look->DefaultItemSpacing(); - AddChild(BGroupLayoutBuilder(B_VERTICAL, spacing) - .Add(fEditor->View()) - .AddGroup(B_HORIZONTAL, spacing) - .AddGlue() - .Add(new BButton(B_TRANSLATE("Cancel"), new BMessage(MSG_CANCEL))) - .Add(fOkButton) - .End() - .SetInsets(spacing, spacing, spacing, spacing) - ); - - SetDefaultButton(fOkButton); - - // If the partition had a previous name, set to that name. - BString name = partition->ContentName(); - if (name.Length() > 0) - fEditor->PartitionNameChanged(name.String()); - - AddToSubset(fWindow); + fOkButton->SetLabel(B_TRANSLATE("Initialize")); } -InitParamsPanel::~InitParamsPanel() +InitParametersPanel::~InitParametersPanel() { - RemoveCommonFilter(fEscapeFilter); - delete fEscapeFilter; - - delete_sem(fExitSemaphore); } -bool -InitParamsPanel::QuitRequested() +status_t +InitParametersPanel::Go(BString& name, BString& parameters) { - release_sem(fExitSemaphore); - return false; -} - - -void -InitParamsPanel::MessageReceived(BMessage* message) -{ - switch (message->what) { - case MSG_CANCEL: - Cancel(); - break; - - case MSG_OK: - fReturnValue = GO_SUCCESS; - release_sem(fExitSemaphore); - break; - - case MSG_NAME_CHANGED: - // message comes from fEditor's BTextControl - BTextControl* control; - if (message->FindPointer("source", (void**)&control) != B_OK) - break; - if (control->TextView()->TextLength() == 0 - && fOkButton->IsEnabled()) - fOkButton->SetEnabled(false); - else if (control->TextView()->TextLength() > 0 - && !fOkButton->IsEnabled()) - fOkButton->SetEnabled(true); - break; - - default: - BWindow::MessageReceived(message); - } -} - - -int32 -InitParamsPanel::Go(BString& name, BString& parameters) -{ - // Without an editor, we cannot change anything, anyway - if (fEditor == NULL) - return GO_SUCCESS; - - // run the window thread, to get an initial layout of the controls - Hide(); - Show(); - if (!Lock()) - return GO_CANCELED; - - // center the panel above the parent window - CenterIn(fWindow->Frame()); - - Show(); - Unlock(); - - // block this thread now, but keep the window repainting - while (true) { - status_t err = acquire_sem_etc(fExitSemaphore, 1, - B_CAN_INTERRUPT | B_RELATIVE_TIMEOUT, 50000); - if (err != B_TIMED_OUT && err != B_INTERRUPTED) - break; - fWindow->UpdateIfNeeded(); - } - - if (!Lock()) - return GO_CANCELED; - - if (fEditor == NULL) - fReturnValue = B_BAD_VALUE; - - if (fReturnValue == GO_SUCCESS) { - if (fEditor->FinishedEditing()) { - status_t err = fEditor->GetParameters(¶meters); - if (err == B_OK) { - void* handle = parse_driver_settings_string( - parameters.String()); - if (handle != NULL) { - const char* string = get_driver_parameter(handle, "name", - NULL, NULL); - name.SetTo(string); - delete_driver_settings(handle); - } - } else - fReturnValue = err; + status_t status = AbstractParametersPanel::Go(parameters); + if (status == B_OK) { + void* handle = parse_driver_settings_string(parameters.String()); + if (handle != NULL) { + const char* string = get_driver_parameter(handle, "name", + NULL, NULL); + name.SetTo(string); + delete_driver_settings(handle); } } - int32 value = fReturnValue; - - Quit(); - // NOTE: this object is toast now! - - return value; -} - - -void -InitParamsPanel::Cancel() -{ - fReturnValue = GO_CANCELED; - release_sem(fExitSemaphore); + return status; } diff --git a/src/apps/drivesetup/InitParamsPanel.h b/src/apps/drivesetup/InitParamsPanel.h index 98b1022446..338eac9481 100644 --- a/src/apps/drivesetup/InitParamsPanel.h +++ b/src/apps/drivesetup/InitParamsPanel.h @@ -1,45 +1,27 @@ /* - * Copyright 2008 Haiku Inc. All rights reserved. + * 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. */ -#ifndef INIT_PARAMS_PANEL_H -#define INIT_PARAMS_PANEL_H - -#include "Support.h" - -#include -#include -#include - -class BMenuField; -class BTextControl; +#ifndef INIT_PARAMETERS_PANEL_H +#define INIT_PARAMETERS_PANEL_H -class InitParamsPanel : public BWindow { +#include "AbstractParametersPanel.h" + + +class InitParametersPanel : public AbstractParametersPanel { public: - InitParamsPanel(BWindow* window, + InitParametersPanel(BWindow* window, const BString& diskSystem, BPartition* partition); - virtual ~InitParamsPanel(); + virtual ~InitParametersPanel(); - virtual bool QuitRequested(); - virtual void MessageReceived(BMessage* message); - - int32 Go(BString& name, BString& parameters); - void Cancel(); - -private: - class EscapeFilter; - EscapeFilter* fEscapeFilter; - sem_id fExitSemaphore; - BWindow* fWindow; - BButton* fOkButton; - int32 fReturnValue; - - BPartitionParameterEditor* fEditor; + status_t Go(BString& name, BString& parameters); }; -#endif // INIT_PARAMS_PANEL_H + +#endif // INIT_PARAMETERS_PANEL_H diff --git a/src/apps/drivesetup/Jamfile b/src/apps/drivesetup/Jamfile index 1e9b483d77..44a4a68536 100644 --- a/src/apps/drivesetup/Jamfile +++ b/src/apps/drivesetup/Jamfile @@ -5,6 +5,7 @@ AddSubDirSupportedPlatforms libbe_test ; UsePrivateHeaders interface shared storage tracker ; Preference DriveSetup : + AbstractParametersPanel.cpp CreateParamsPanel.cpp DiskView.cpp DriveSetup.cpp diff --git a/src/apps/drivesetup/MainWindow.cpp b/src/apps/drivesetup/MainWindow.cpp index 6660cd512a..2816b06ae4 100644 --- a/src/apps/drivesetup/MainWindow.cpp +++ b/src/apps/drivesetup/MainWindow.cpp @@ -882,9 +882,9 @@ MainWindow::_Initialize(BDiskDevice* disk, partition_id selectedPartition, BString name; BString parameters; - InitParamsPanel* panel = new InitParamsPanel(this, diskSystemName, + InitParametersPanel* panel = new InitParametersPanel(this, diskSystemName, partition); - if (panel->Go(name, parameters) == GO_CANCELED) + if (panel->Go(name, parameters) != B_OK) return; bool supportsName = diskSystem.SupportsContentName(); @@ -1037,9 +1037,9 @@ MainWindow::_Create(BDiskDevice* disk, partition_id selectedPartition) off_t offset = currentSelection->Offset(); off_t size = currentSelection->Size(); - CreateParamsPanel* panel = new CreateParamsPanel(this, parent, offset, - size); - if (panel->Go(offset, size, name, type, parameters) == GO_CANCELED) + CreateParametersPanel* panel = new CreateParametersPanel(this, parent, + offset, size); + if (panel->Go(offset, size, name, type, parameters) != B_OK) return; ret = parent->ValidateCreateChild(&offset, &size, type.String(), diff --git a/src/apps/drivesetup/Support.h b/src/apps/drivesetup/Support.h index 9314446d67..b7540c6363 100644 --- a/src/apps/drivesetup/Support.h +++ b/src/apps/drivesetup/Support.h @@ -21,11 +21,6 @@ void dump_partition_info(const BPartition* partition); bool is_valid_partitionable_space(size_t size); -enum { - GO_CANCELED = 0, - GO_SUCCESS -}; - static const uint32 kMegaByte = 0x100000; diff --git a/src/kits/storage/disk_device/PartitionParameterEditor.cpp b/src/kits/storage/disk_device/PartitionParameterEditor.cpp index 6c6a80627d..f1dfde69af 100644 --- a/src/kits/storage/disk_device/PartitionParameterEditor.cpp +++ b/src/kits/storage/disk_device/PartitionParameterEditor.cpp @@ -1,4 +1,5 @@ /* + * Copyright 2013, Axel Dörfler, axeld@pinc-software.de. * Copyright 2009, Bryce Groff, brycegroff@gmail.com. * Distributed under the terms of the MIT License. */ @@ -10,12 +11,52 @@ BPartitionParameterEditor::BPartitionParameterEditor() + : + fModificationMessage(NULL) { } BPartitionParameterEditor::~BPartitionParameterEditor() { + delete fModificationMessage; +} + + +/*! \brief Sets the controls of the editor to match the parameters + of the given \a partition. + + For \c B_CREATE_PARAMETER_EDITOR editors, this will be the parent + partition. +*/ +void +BPartitionParameterEditor::SetTo(BPartition* partition) +{ +} + + +/*! \brief Sets the modification message. + + This message needs to be sent whenever an internal parameter changed. + This call takes over ownership of the provided message. + + The message may contain a string field "parameter" with the value set + to the name of the changed parameter. +*/ +void +BPartitionParameterEditor::SetModificationMessage(BMessage* message) +{ + delete fModificationMessage; + fModificationMessage = message; +} + + +/*! \brief The currently set modification message, if any. +*/ +BMessage* +BPartitionParameterEditor::ModificationMessage() const +{ + return fModificationMessage; } @@ -40,7 +81,6 @@ BPartitionParameterEditor::View() } -// FinishedEditing /*! \brief Called when the user finishes editing the parameters. To be overridden by derived classes. @@ -52,9 +92,31 @@ BPartitionParameterEditor::View() \return \c true, if the current parameters are valid, \c false otherwise. */ bool -BPartitionParameterEditor::FinishedEditing() +BPartitionParameterEditor::ValidateParameters() const { - return false; + return true; +} + + +/*! \brief Called when a parameter has changed. + + Each editor type comes with a number of predefined parameters that + may be changed from the outside while the editor is open. You can + either accept the changes, and update your controls correspondingly, + or else reject the change by returning an appropriate error code. + + To be overridden by derived classes. + The base class version returns B_OK. + + \param name The name of the changed parameter. + \param variant The new value of the parameter. + \return \c B_OK, if everything went fine, another error code otherwise. +*/ +status_t +BPartitionParameterEditor::ParameterChanged(const char* name, + const BVariant& variant) +{ + return B_NOT_SUPPORTED; } @@ -68,43 +130,8 @@ BPartitionParameterEditor::FinishedEditing() \return \c B_OK, if everything went fine, another error code otherwise. */ status_t -BPartitionParameterEditor::GetParameters(BString* parameters) +BPartitionParameterEditor::GetParameters(BString& parameters) { - status_t error = (parameters ? B_OK : B_BAD_VALUE); - if (error == B_OK) - parameters->SetTo(""); - return error; + parameters.SetTo(""); + return B_OK; } - - -/*! \brief Called when type information has changed. - - To be overridden by derived classes. - The base class version returns B_OK. - - \param type A string that is the new type. - - \return \c B_OK, if everything went fine, another error code otherwise. -*/ -status_t -BPartitionParameterEditor::PartitionTypeChanged(const char* type) -{ - return B_NOT_SUPPORTED; -} - - -/*! \brief Called when name information has changed. - - To be overridden by derived classes. - The base class version returns B_OK. - - \param name A string that is the new name. - - \return \c B_OK, if everything went fine, another error code otherwise. -*/ -status_t -BPartitionParameterEditor::PartitionNameChanged(const char* name) -{ - return B_NOT_SUPPORTED; -} -