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 */ 7 8 9 #include <stdio.h> 10 11 #include "InitializeParameterEditor.h" 12 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> 27 28 29 #undef B_TRANSLATION_CONTEXT 30 #define B_TRANSLATION_CONTEXT "BFS_Initialize_Parameter" 31 32 33 static uint32 MSG_BLOCK_SIZE = 'blsz'; 34 static uint32 MSG_NAME_CHANGED = 'nmch'; 35 36 37 InitializeBFSEditor::InitializeBFSEditor() 38 : 39 BPartitionParameterEditor(), 40 fView(NULL), 41 fNameControl(NULL), 42 fBlockSizeMenuField(NULL), 43 fUseIndicesCheckBox(NULL) 44 { 45 _CreateViewControls(); 46 } 47 48 49 InitializeBFSEditor::~InitializeBFSEditor() 50 { 51 } 52 53 54 void 55 InitializeBFSEditor::SetTo(BPartition* partition) 56 { 57 BString name = partition->ContentName(); 58 if (!name.IsEmpty()) 59 fNameControl->SetText(name.String()); 60 } 61 62 63 BView* 64 InitializeBFSEditor::View() 65 { 66 return fView; 67 } 68 69 70 bool 71 InitializeBFSEditor::ValidateParameters() const 72 { 73 // The name must be set 74 return fNameControl->TextView()->TextLength() > 0; 75 } 76 77 78 status_t 79 InitializeBFSEditor::ParameterChanged(const char* name, const BVariant& variant) 80 { 81 if (!strcmp(name, "name")) 82 fNameControl->SetText(variant.ToString()); 83 return B_OK; 84 } 85 86 87 status_t 88 InitializeBFSEditor::GetParameters(BString& parameters) 89 { 90 parameters = ""; 91 92 if (BMenuItem* item = fBlockSizeMenuField->Menu()->FindMarked()) { 93 const char* size; 94 BMessage* message = item->Message(); 95 if (!message || message->FindString("size", &size) < B_OK) 96 size = "2048"; 97 // TODO: use libroot driver settings API 98 parameters << "block_size " << size << ";\n"; 99 } 100 if (fUseIndicesCheckBox->Value() == B_CONTROL_OFF) 101 parameters << "noindex;\n"; 102 103 parameters << "name \"" << fNameControl->Text() << "\";\n"; 104 return B_OK; 105 } 106 107 108 void 109 InitializeBFSEditor::_CreateViewControls() 110 { 111 fNameControl = new BTextControl(B_TRANSLATE("Name:"), "Haiku", NULL); 112 fNameControl->SetModificationMessage(new BMessage(MSG_NAME_CHANGED)); 113 fNameControl->TextView()->SetMaxBytes(31); 114 115 BPopUpMenu* blocksizeMenu = new BPopUpMenu("blocksize"); 116 BMessage* message = new BMessage(MSG_BLOCK_SIZE); 117 message->AddString("size", "1024"); 118 blocksizeMenu->AddItem(new BMenuItem( 119 B_TRANSLATE("1024 (Mostly small files)"), message)); 120 message = new BMessage(MSG_BLOCK_SIZE); 121 message->AddString("size", "2048"); 122 BMenuItem* defaultItem = new BMenuItem(B_TRANSLATE("2048 (Recommended)"), 123 message); 124 blocksizeMenu->AddItem(defaultItem); 125 message = new BMessage(MSG_BLOCK_SIZE); 126 message->AddString("size", "4096"); 127 blocksizeMenu->AddItem(new BMenuItem("4096", message)); 128 message = new BMessage(MSG_BLOCK_SIZE); 129 message->AddString("size", "8192"); 130 blocksizeMenu->AddItem(new BMenuItem( 131 B_TRANSLATE("8192 (Mostly large files)"), message)); 132 133 fBlockSizeMenuField = new BMenuField(B_TRANSLATE("Blocksize:"), 134 blocksizeMenu); 135 defaultItem->SetMarked(true); 136 137 fUseIndicesCheckBox = new BCheckBox(B_TRANSLATE("Enable query support"), 138 NULL); 139 fUseIndicesCheckBox->SetValue(true); 140 fUseIndicesCheckBox->SetToolTip(B_TRANSLATE("Disabling query support may " 141 "speed up certain file system operations, but should only be used " 142 "if one is absolutely certain that one will not need queries.\n" 143 "Any volume that is intended for booting Haiku must have query " 144 "support enabled.")); 145 146 float spacing = be_control_look->DefaultItemSpacing(); 147 148 fView = BGridLayoutBuilder(spacing, spacing) 149 // row 1 150 .Add(fNameControl->CreateLabelLayoutItem(), 0, 0) 151 .Add(fNameControl->CreateTextViewLayoutItem(), 1, 0) 152 153 // row 2 154 .Add(fBlockSizeMenuField->CreateLabelLayoutItem(), 0, 1) 155 .Add(fBlockSizeMenuField->CreateMenuBarLayoutItem(), 1, 1) 156 157 // row 3 158 .Add(fUseIndicesCheckBox, 0, 2, 2).View() 159 ; 160 } 161