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->Name(); 58 if (name.IsEmpty()) 59 name = partition->ContentName(); 60 if (!name.IsEmpty()) 61 fNameControl->SetText(name.String()); 62 } 63 64 65 BView* 66 InitializeBFSEditor::View() 67 { 68 return fView; 69 } 70 71 72 bool 73 InitializeBFSEditor::ValidateParameters() const 74 { 75 // The name must be set 76 return fNameControl->TextView()->TextLength() > 0; 77 } 78 79 80 status_t 81 InitializeBFSEditor::ParameterChanged(const char* name, const BVariant& variant) 82 { 83 if (!strcmp(name, "name")) 84 fNameControl->SetText(variant.ToString()); 85 return B_OK; 86 } 87 88 89 status_t 90 InitializeBFSEditor::GetParameters(BString& parameters) 91 { 92 parameters = ""; 93 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"; 101 } 102 if (fUseIndicesCheckBox->Value() == B_CONTROL_OFF) 103 parameters << "noindex;\n"; 104 105 parameters << "name \"" << fNameControl->Text() << "\";\n"; 106 return B_OK; 107 } 108 109 110 void 111 InitializeBFSEditor::_CreateViewControls() 112 { 113 fNameControl = new BTextControl(B_TRANSLATE("Name:"), "Haiku", NULL); 114 fNameControl->SetModificationMessage(new BMessage(MSG_NAME_CHANGED)); 115 fNameControl->TextView()->SetMaxBytes(31); 116 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)); 134 135 fBlockSizeMenuField = new BMenuField(B_TRANSLATE("Blocksize:"), 136 blocksizeMenu); 137 defaultItem->SetMarked(true); 138 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.")); 147 148 float spacing = be_control_look->DefaultItemSpacing(); 149 150 fView = BGridLayoutBuilder(spacing, spacing) 151 // row 1 152 .Add(fNameControl->CreateLabelLayoutItem(), 0, 0) 153 .Add(fNameControl->CreateTextViewLayoutItem(), 1, 0) 154 155 // row 2 156 .Add(fBlockSizeMenuField->CreateLabelLayoutItem(), 0, 1) 157 .Add(fBlockSizeMenuField->CreateMenuBarLayoutItem(), 1, 1) 158 159 // row 3 160 .Add(fUseIndicesCheckBox, 0, 2, 2).View() 161 ; 162 } 163