1 /* 2 * Copyright 2013, Axel Dörfler, axeld@pinc-software.de. 3 * Copyright 2009, Bryce Groff, brycegroff@gmail.com. 4 * Distributed under the terms of the MIT License. 5 */ 6 7 8 #include "PrimaryParameterEditor.h" 9 10 #include <Catalog.h> 11 #include <DiskDeviceTypes.h> 12 #include <GroupView.h> 13 #include <Partition.h> 14 #include <PartitionParameterEditor.h> 15 #include <Variant.h> 16 #include <View.h> 17 #include <driver_settings.h> 18 19 20 #undef B_TRANSLATION_CONTEXT 21 #define B_TRANSLATION_CONTEXT "PrimaryPartitionEditor" 22 23 24 PrimaryPartitionEditor::PrimaryPartitionEditor(bool create) 25 : 26 fCreate(create) 27 { 28 fActiveCheckBox = new BCheckBox("active", B_TRANSLATE("Active partition"), 29 NULL); 30 fView = new BGroupView(B_VERTICAL); 31 fView->AddChild(fActiveCheckBox); 32 } 33 34 35 PrimaryPartitionEditor::~PrimaryPartitionEditor() 36 { 37 } 38 39 40 void 41 PrimaryPartitionEditor::SetTo(BPartition* partition) 42 { 43 bool active = false; 44 if (fCreate) { 45 active = partition->CountChildren() == 0; 46 } else { 47 void* handle = parse_driver_settings_string(partition->Parameters()); 48 active = get_driver_boolean_parameter(handle, "active", false, true); 49 unload_driver_settings(handle); 50 } 51 fActiveCheckBox->SetValue(active ? B_CONTROL_ON : B_CONTROL_OFF); 52 } 53 54 55 BView* 56 PrimaryPartitionEditor::View() 57 { 58 return fView; 59 } 60 61 62 status_t 63 PrimaryPartitionEditor::ParameterChanged(const char* name, 64 const BVariant& variant) 65 { 66 if (strcmp(name, "type") == 0) { 67 fActiveCheckBox->SetEnabled(strcmp(variant.ToString(), 68 kPartitionTypeIntelExtended) != 0); 69 fActiveCheckBox->SetValue(false); 70 } 71 72 if (strcmp(name, "active") == 0) 73 fActiveCheckBox->SetValue(variant.ToBool()); 74 75 return B_OK; 76 } 77 78 79 status_t 80 PrimaryPartitionEditor::GetParameters(BString& parameters) 81 { 82 if (fActiveCheckBox->IsEnabled()) { 83 if (fActiveCheckBox->Value() == B_CONTROL_ON) 84 parameters.SetTo("active true ;"); 85 else 86 parameters.SetTo("active false ;"); 87 } else 88 parameters.SetTo(""); 89 90 return B_OK; 91 } 92