Skip to content

Commit

Permalink
DriveSetup: Added support for changing partition parameters.
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
axeld committed Feb 12, 2013
1 parent 1b26620 commit 8940ad2
Show file tree
Hide file tree
Showing 10 changed files with 484 additions and 172 deletions.
3 changes: 2 additions & 1 deletion src/add-ons/disk_systems/intel/PartitionMapAddOn.cpp
Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion src/apps/drivesetup/AbstractParametersPanel.cpp
Expand Up @@ -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())
Expand Down Expand Up @@ -257,6 +257,12 @@ AbstractParametersPanel::NeedsEditor() const
}


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

status_t
AbstractParametersPanel::ParametersReceived(const BString& parameters,
BMessage& storage)
Expand Down
1 change: 1 addition & 0 deletions src/apps/drivesetup/AbstractParametersPanel.h
Expand Up @@ -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,
Expand Down
196 changes: 196 additions & 0 deletions 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 <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);
}
56 changes: 56 additions & 0 deletions 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 <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

0 comments on commit 8940ad2

Please sign in to comment.