2 * Copyright 2013, Axel Dörfler, axeld@pinc-software.de.
3 * Copyright 2009-2010, Stephan Aßmus <superstippi@gmx.de>
4 * Copyright 2009, Bryce Groff, brycegroff@gmail.com.
5 * Distributed under the terms of the MIT License.
11 #include "InitializeParameterEditor.h"
16 #include <ControlLook.h>
17 #include <GridLayoutBuilder.h>
18 #include <MenuField.h>
20 #include <Partition.h>
21 #include <PopUpMenu.h>
22 #include <SpaceLayoutItem.h>
23 #include <TextControl.h>
29 #undef B_TRANSLATION_CONTEXT
30 #define B_TRANSLATION_CONTEXT "BFS_Initialize_Parameter"
33 static uint32 MSG_BLOCK_SIZE
= 'blsz';
34 static uint32 MSG_NAME_CHANGED
= 'nmch';
37 InitializeBFSEditor::InitializeBFSEditor()
39 BPartitionParameterEditor(),
42 fBlockSizeMenuField(NULL
),
43 fUseIndicesCheckBox(NULL
)
45 _CreateViewControls();
49 InitializeBFSEditor::~InitializeBFSEditor()
55 InitializeBFSEditor::SetTo(BPartition
* partition
)
57 BString name
= partition
->Name();
59 name
= partition
->ContentName();
61 fNameControl
->SetText(name
.String());
66 InitializeBFSEditor::View()
73 InitializeBFSEditor::ValidateParameters() const
75 // The name must be set
76 return fNameControl
->TextView()->TextLength() > 0;
81 InitializeBFSEditor::ParameterChanged(const char* name
, const BVariant
& variant
)
83 if (!strcmp(name
, "name"))
84 fNameControl
->SetText(variant
.ToString());
90 InitializeBFSEditor::GetParameters(BString
& parameters
)
94 if (BMenuItem
* item
= fBlockSizeMenuField
->Menu()->FindMarked()) {
96 BMessage
* message
= item
->Message();
97 if (!message
|| message
->FindString("size", &size
) < B_OK
)
99 // TODO: use libroot driver settings API
100 parameters
<< "block_size " << size
<< ";\n";
102 if (fUseIndicesCheckBox
->Value() == B_CONTROL_OFF
)
103 parameters
<< "noindex;\n";
105 parameters
<< "name \"" << fNameControl
->Text() << "\";\n";
111 InitializeBFSEditor::_CreateViewControls()
113 fNameControl
= new BTextControl(B_TRANSLATE("Name:"), "Haiku", NULL
);
114 fNameControl
->SetModificationMessage(new BMessage(MSG_NAME_CHANGED
));
115 fNameControl
->TextView()->SetMaxBytes(31);
117 BPopUpMenu
* blocksizeMenu
= new BPopUpMenu("blocksize");
118 BMessage
* message
= new BMessage(MSG_BLOCK_SIZE
);
119 message
->AddString("size", "1024");
120 blocksizeMenu
->AddItem(new BMenuItem(
121 B_TRANSLATE("1024 (Mostly small files)"), message
));
122 message
= new BMessage(MSG_BLOCK_SIZE
);
123 message
->AddString("size", "2048");
124 BMenuItem
* defaultItem
= new BMenuItem(B_TRANSLATE("2048 (Recommended)"),
126 blocksizeMenu
->AddItem(defaultItem
);
127 message
= new BMessage(MSG_BLOCK_SIZE
);
128 message
->AddString("size", "4096");
129 blocksizeMenu
->AddItem(new BMenuItem("4096", message
));
130 message
= new BMessage(MSG_BLOCK_SIZE
);
131 message
->AddString("size", "8192");
132 blocksizeMenu
->AddItem(new BMenuItem(
133 B_TRANSLATE("8192 (Mostly large files)"), message
));
135 fBlockSizeMenuField
= new BMenuField(B_TRANSLATE("Blocksize:"),
137 defaultItem
->SetMarked(true);
139 fUseIndicesCheckBox
= new BCheckBox(B_TRANSLATE("Enable query support"),
141 fUseIndicesCheckBox
->SetValue(true);
142 fUseIndicesCheckBox
->SetToolTip(B_TRANSLATE("Disabling query support may "
143 "speed up certain file system operations, but should only be used "
144 "if one is absolutely certain that one will not need queries.\n"
145 "Any volume that is intended for booting Haiku must have query "
146 "support enabled."));
148 float spacing
= be_control_look
->DefaultItemSpacing();
150 fView
= BGridLayoutBuilder(spacing
, spacing
)
152 .Add(fNameControl
->CreateLabelLayoutItem(), 0, 0)
153 .Add(fNameControl
->CreateTextViewLayoutItem(), 1, 0)
156 .Add(fBlockSizeMenuField
->CreateLabelLayoutItem(), 0, 1)
157 .Add(fBlockSizeMenuField
->CreateMenuBarLayoutItem(), 1, 1)
160 .Add(fUseIndicesCheckBox
, 0, 2, 2).View()