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 * Copyright 2019, Les De Ridder, les@lesderid.net 6 * 7 * Distributed under the terms of the MIT License. 8 */ 9 10 11 #include <cstdio> 12 13 #include "InitializeParameterEditor.h" 14 15 #include <Button.h> 16 #include <Catalog.h> 17 #include <ControlLook.h> 18 #include <GridLayoutBuilder.h> 19 #include <Partition.h> 20 #include <SpaceLayoutItem.h> 21 #include <TextControl.h> 22 #include <Variant.h> 23 #include <View.h> 24 #include <Window.h> 25 26 #include "btrfs.h" 27 28 29 #undef B_TRANSLATION_CONTEXT 30 #define B_TRANSLATION_CONTEXT "BTRFS_Initialize_Parameter" 31 32 33 static uint32 MSG_NAME_CHANGED = 'nmch'; 34 35 36 InitializeBTRFSEditor::InitializeBTRFSEditor() 37 : 38 BPartitionParameterEditor(), 39 fView(NULL), 40 fNameControl(NULL), 41 fParameters(NULL) 42 { 43 _CreateViewControls(); 44 } 45 46 47 InitializeBTRFSEditor::~InitializeBTRFSEditor() 48 { 49 } 50 51 52 void 53 InitializeBTRFSEditor::SetTo(BPartition* partition) 54 { 55 BString name = partition->Name(); 56 if (name.IsEmpty()) 57 name = partition->RawContentName(); 58 if (!name.IsEmpty()) 59 fNameControl->SetText(name.String()); 60 } 61 62 63 BView* 64 InitializeBTRFSEditor::View() 65 { 66 return fView; 67 } 68 69 70 bool 71 InitializeBTRFSEditor::ValidateParameters() const 72 { 73 // The name must be set 74 return fNameControl->TextView()->TextLength() > 0; 75 } 76 77 78 status_t 79 InitializeBTRFSEditor::ParameterChanged(const char* name, 80 const BVariant& variant) 81 { 82 if (!strcmp(name, "name")) 83 fNameControl->SetText(variant.ToString()); 84 return B_OK; 85 } 86 87 88 status_t 89 InitializeBTRFSEditor::GetParameters(BString& parameters) 90 { 91 parameters = "name \""; 92 parameters << fNameControl->Text() << "\";\n"; 93 return B_OK; 94 } 95 96 97 void 98 InitializeBTRFSEditor::_CreateViewControls() 99 { 100 fNameControl = new BTextControl(B_TRANSLATE("Name:"), "New Btrfs Volume", 101 NULL); 102 fNameControl->SetModificationMessage(new BMessage(MSG_NAME_CHANGED)); 103 fNameControl->TextView()->SetMaxBytes(BTRFS_LABEL_SIZE); 104 105 // TODO(lesderid): Controls for block size, sector size, uuid, etc. 106 107 float spacing = be_control_look->DefaultItemSpacing(); 108 109 fView = BGridLayoutBuilder(spacing, spacing) 110 .Add(fNameControl->CreateLabelLayoutItem(), 0, 0) 111 .Add(fNameControl->CreateTextViewLayoutItem(), 1, 0).View() 112 ; 113 } 114