3rdparty/licenseReport: Add seperate LGPL checks
[haiku.git] / src / add-ons / disk_systems / fat / InitializeParameterEditor.cpp
blob95148eff2e55e222b02962076a9324b3cdad1870
1 /*
2 * Copyright 2015, François Revol <revol@free.fr>
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 "FAT_Initialize_Parameter"
33 static uint32 MSG_NAME_CHANGED = 'nmch';
34 static uint32 MSG_FAT_BITS = 'fatb';
36 InitializeFATEditor::InitializeFATEditor()
38 BPartitionParameterEditor(),
39 fView(NULL),
40 fNameControl(NULL),
41 fFatBitsMenuField(NULL),
42 fParameters(NULL)
44 _CreateViewControls();
48 InitializeFATEditor::~InitializeFATEditor()
53 void
54 InitializeFATEditor::SetTo(BPartition* partition)
56 BString name = partition->Name();
57 if (name.IsEmpty())
58 name = partition->ContentName();
59 if (!name.IsEmpty())
60 fNameControl->SetText(name.String());
64 BView*
65 InitializeFATEditor::View()
67 return fView;
71 bool
72 InitializeFATEditor::ValidateParameters() const
74 // The name must be set
75 return fNameControl->TextView()->TextLength() > 0;
79 status_t
80 InitializeFATEditor::ParameterChanged(const char* name,
81 const BVariant& variant)
83 if (!strcmp(name, "name"))
84 fNameControl->SetText(variant.ToString());
85 return B_OK;
89 status_t
90 InitializeFATEditor::GetParameters(BString& parameters)
92 parameters = "";
94 if (BMenuItem* item = fFatBitsMenuField->Menu()->FindMarked()) {
95 const char* size;
96 BMessage* message = item->Message();
97 if (!message || message->FindString("fat", &size) < B_OK)
98 size = "0"; // autodetect
99 // TODO: use libroot driver settings API
100 parameters << "fat " << size << ";\n";
103 parameters << "name \"";
104 parameters << fNameControl->Text() << "\";\n";
105 printf("p:%s", parameters.String());
106 return B_OK;
110 void
111 InitializeFATEditor::_CreateViewControls()
113 fNameControl = new BTextControl(B_TRANSLATE("Name:"), "New FAT Vol",
114 NULL);
115 fNameControl->SetModificationMessage(new BMessage(MSG_NAME_CHANGED));
116 // TODO find out what is the max length for this specific FS partition name
117 fNameControl->TextView()->SetMaxBytes(11);
119 BPopUpMenu* fatBitsMenu = new BPopUpMenu("fat size");
120 BMessage* message = new BMessage(MSG_FAT_BITS);
121 message->AddString("fat", "0");
122 BMenuItem* defaultItem = new BMenuItem(
123 B_TRANSLATE("Auto (default)"), message);
124 fatBitsMenu->AddItem(defaultItem);
125 message = new BMessage(MSG_FAT_BITS);
126 message->AddString("fat", "12");
127 fatBitsMenu->AddItem(new BMenuItem("12", message));
128 message = new BMessage(MSG_FAT_BITS);
129 message->AddString("fat", "16");
130 fatBitsMenu->AddItem(new BMenuItem("16", message));
131 message = new BMessage(MSG_FAT_BITS);
132 message->AddString("fat", "32");
133 fatBitsMenu->AddItem(new BMenuItem("32", message));
135 fFatBitsMenuField = new BMenuField(B_TRANSLATE("FAT bits:"),
136 fatBitsMenu);
137 defaultItem->SetMarked(true);
139 float spacing = be_control_look->DefaultItemSpacing();
141 fView = BGridLayoutBuilder(spacing, spacing)
142 // row 1
143 .Add(fNameControl->CreateLabelLayoutItem(), 0, 0)
144 .Add(fNameControl->CreateTextViewLayoutItem(), 1, 0)
146 // row 2
147 .Add(fFatBitsMenuField->CreateLabelLayoutItem(), 0, 1)
148 .Add(fFatBitsMenuField->CreateMenuBarLayoutItem(), 1, 1).View()