BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / add-ons / disk_systems / bfs / InitializeParameterEditor.cpp
blob42ed26d3c745e4f3ee226d354bcf0c916182a82f
1 /*
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.
6 */
9 #include <stdio.h>
11 #include "InitializeParameterEditor.h"
13 #include <Button.h>
14 #include <Catalog.h>
15 #include <CheckBox.h>
16 #include <ControlLook.h>
17 #include <GridLayoutBuilder.h>
18 #include <MenuField.h>
19 #include <MenuItem.h>
20 #include <Partition.h>
21 #include <PopUpMenu.h>
22 #include <SpaceLayoutItem.h>
23 #include <TextControl.h>
24 #include <Variant.h>
25 #include <View.h>
26 #include <Window.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(),
40 fView(NULL),
41 fNameControl(NULL),
42 fBlockSizeMenuField(NULL),
43 fUseIndicesCheckBox(NULL)
45 _CreateViewControls();
49 InitializeBFSEditor::~InitializeBFSEditor()
54 void
55 InitializeBFSEditor::SetTo(BPartition* partition)
57 BString name = partition->Name();
58 if (name.IsEmpty())
59 name = partition->ContentName();
60 if (!name.IsEmpty())
61 fNameControl->SetText(name.String());
65 BView*
66 InitializeBFSEditor::View()
68 return fView;
72 bool
73 InitializeBFSEditor::ValidateParameters() const
75 // The name must be set
76 return fNameControl->TextView()->TextLength() > 0;
80 status_t
81 InitializeBFSEditor::ParameterChanged(const char* name, const BVariant& variant)
83 if (!strcmp(name, "name"))
84 fNameControl->SetText(variant.ToString());
85 return B_OK;
89 status_t
90 InitializeBFSEditor::GetParameters(BString& parameters)
92 parameters = "";
94 if (BMenuItem* item = fBlockSizeMenuField->Menu()->FindMarked()) {
95 const char* size;
96 BMessage* message = item->Message();
97 if (!message || message->FindString("size", &size) < B_OK)
98 size = "2048";
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";
106 return B_OK;
110 void
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)"),
125 message);
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:"),
136 blocksizeMenu);
137 defaultItem->SetMarked(true);
139 fUseIndicesCheckBox = new BCheckBox(B_TRANSLATE("Enable query support"),
140 NULL);
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)
151 // row 1
152 .Add(fNameControl->CreateLabelLayoutItem(), 0, 0)
153 .Add(fNameControl->CreateTextViewLayoutItem(), 1, 0)
155 // row 2
156 .Add(fBlockSizeMenuField->CreateLabelLayoutItem(), 0, 1)
157 .Add(fBlockSizeMenuField->CreateMenuBarLayoutItem(), 1, 1)
159 // row 3
160 .Add(fUseIndicesCheckBox, 0, 2, 2).View()