Skip to content

Commit

Permalink
DriveSetup: solved a few issues of CreateParametersPanel.
Browse files Browse the repository at this point in the history
* I obviously wasn't really done last time: now the panel behaves as it should.
  • Loading branch information
axeld committed Feb 12, 2013
1 parent d2239cb commit 32da57f
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 61 deletions.
121 changes: 73 additions & 48 deletions src/apps/drivesetup/AbstractParametersPanel.cpp
Expand Up @@ -136,54 +136,8 @@ AbstractParametersPanel::MessageReceived(BMessage* 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;
BMessage storage;
return Go(parameters, storage);
}


Expand Down Expand Up @@ -240,6 +194,77 @@ AbstractParametersPanel::Init(B_PARAMETER_EDITOR_TYPE type,
}


status_t
AbstractParametersPanel::Go(BString& parameters, BMessage& storage)
{
// Without an editor, we cannot change anything, anyway
if (fEditor == NULL && NeedsEditor()) {
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 != NULL && fEditor->ValidateParameters()) {
status_t status = fEditor->GetParameters(parameters);
if (status != B_OK)
fReturnStatus = status;
}
if (fReturnStatus == B_OK)
fReturnStatus = ParametersReceived(parameters, storage);
}
}

status_t status = fReturnStatus;

Quit();
// NOTE: this object is toast now!

return status;
}


bool
AbstractParametersPanel::NeedsEditor() const
{
return true;
}


status_t
AbstractParametersPanel::ParametersReceived(const BString& parameters,
BMessage& storage)
{
return B_OK;
}


void
AbstractParametersPanel::AddControls(BLayoutBuilder::Group<>& builder,
BView* editorView)
Expand Down
4 changes: 4 additions & 0 deletions src/apps/drivesetup/AbstractParametersPanel.h
Expand Up @@ -37,7 +37,11 @@ class AbstractParametersPanel : public BWindow {
void Init(B_PARAMETER_EDITOR_TYPE type,
const BString& diskSystem,
BPartition* partition);
status_t Go(BString& parameters, BMessage& storage);

virtual bool NeedsEditor() const;
virtual status_t ParametersReceived(const BString& parameters,
BMessage& storage);
virtual void AddControls(BLayoutBuilder::Group<>& builder,
BView* editorView);

Expand Down
62 changes: 49 additions & 13 deletions src/apps/drivesetup/CreateParametersPanel.cpp
Expand Up @@ -60,25 +60,25 @@ status_t
CreateParametersPanel::Go(off_t& offset, off_t& size, BString& name,
BString& type, BString& parameters)
{
// The object will be deleted in Go(), so we need to get the values before
// The object will be deleted in Go(), so we need to get the values via
// a BMessage

BMessage storage;
status_t status = AbstractParametersPanel::Go(parameters, storage);
if (status != B_OK)
return status;

// Return the value back as bytes.
size = fSizeSlider->Size();
offset = fSizeSlider->Offset();
size = storage.GetInt64("size", 0);
offset = storage.GetInt64("offset", 0);

// get name
name.SetTo(fNameTextControl->Text());
name.SetTo(storage.GetString("name", NULL));

// 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;
}
type.SetTo(storage.GetString("type", NULL));

return AbstractParametersPanel::Go(parameters);
return B_OK;
}


Expand Down Expand Up @@ -114,6 +114,41 @@ CreateParametersPanel::MessageReceived(BMessage* message)
}


bool
CreateParametersPanel::NeedsEditor() const
{
return false;
}


status_t
CreateParametersPanel::ParametersReceived(const BString& parameters,
BMessage& storage)
{
// Return the value back as bytes.
status_t status = storage.SetInt64("size", fSizeSlider->Size());
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);
}

return status;
}


void
CreateParametersPanel::AddControls(BLayoutBuilder::Group<>& builder,
BView* editorView)
Expand All @@ -136,7 +171,8 @@ CreateParametersPanel::AddControls(BLayoutBuilder::Group<>& builder,
}
}

builder.Add(editorView);
if (editorView != NULL)
builder.Add(editorView);
}


Expand Down
3 changes: 3 additions & 0 deletions src/apps/drivesetup/CreateParametersPanel.h
Expand Up @@ -33,6 +33,9 @@ class CreateParametersPanel : public AbstractParametersPanel {
virtual void MessageReceived(BMessage* message);

protected:
virtual bool NeedsEditor() const;
virtual status_t ParametersReceived(const BString& parameters,
BMessage& storage);
virtual void AddControls(BLayoutBuilder::Group<>& builder,
BView* editorView);

Expand Down

0 comments on commit 32da57f

Please sign in to comment.