2 * Copyright 2008-2011, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Axel Dörfler, <axeld@pinc-software.de>
7 * Michael Pfeiffer, laplace@users.sourceforge.net
8 * Ingo Weinhold <bonefish@cs.tu-berlin.de>
12 #include "PartitionsPage.h"
19 #include <ControlLook.h>
20 #include <LayoutBuilder.h>
21 #include <RadioButton.h>
22 #include <ScrollView.h>
23 #include <SeparatorView.h>
24 #include <StringView.h>
25 #include <TextControl.h>
29 #include <StringForSize.h>
32 #undef B_TRANSLATION_CONTEXT
33 #define B_TRANSLATION_CONTEXT "PartitionsPage"
36 const uint32 kMessageShow
= 'show';
37 const uint32 kMessageName
= 'name';
40 PartitionsPage::PartitionsPage(BMessage
* settings
, const char* name
)
42 WizardPageView(settings
, name
)
48 PartitionsPage::~PartitionsPage()
54 PartitionsPage::PageCompleted()
56 BGridLayout
* layout
= (BGridLayout
*)fPartitions
->GetLayout();
59 for (int32 row
= 0; row
< layout
->CountRows(); row
+= 3, index
++) {
61 = dynamic_cast<BCheckBox
*>(layout
->ItemAt(0, row
)->View());
62 BTextControl
* nameControl
63 = dynamic_cast<BTextControl
*>(layout
->ItemAt(1, row
)->View());
64 if (nameControl
== NULL
|| showBox
== NULL
)
65 debugger("partitions page is broken");
68 if (fSettings
->FindMessage("partition", index
, &partition
) != B_OK
)
71 partition
.ReplaceBool("show", showBox
->Value() != 0);
72 partition
.ReplaceString("name", nameControl
->Text());
74 fSettings
->ReplaceMessage("partition", index
, &partition
);
80 PartitionsPage::_BuildUI()
83 text
<< B_TRANSLATE_COMMENT("Partitions", "Title") << "\n"
84 << B_TRANSLATE("The following partitions were detected. Please "
85 "check the box next to the partitions to be included "
86 "in the boot menu. You can also set the names of the "
87 "partitions as you would like them to appear in the "
89 fDescription
= CreateDescription("description", text
);
90 MakeHeading(fDescription
);
92 fPartitions
= new BGridView("partitions", 0,
93 be_control_look
->DefaultItemSpacing() / 3);
95 BLayoutBuilder::Grid
<>(fPartitions
)
96 .SetInsets(B_USE_DEFAULT_SPACING
, B_USE_DEFAULT_SPACING
,
97 B_USE_DEFAULT_SPACING
, B_USE_DEFAULT_SPACING
)
98 .SetColumnWeight(0, 0)
99 .SetColumnWeight(1, 1)
100 .SetColumnWeight(2, 0.5)
101 .SetColumnWeight(3, 0.5);
102 _FillPartitionsView(fPartitions
);
104 BViewPort
* viewPort
= new BViewPort(fPartitions
);
106 BScrollView
* scrollView
= new BScrollView("scrollView", viewPort
, 0,
109 SetLayout(new BGroupLayout(B_VERTICAL
));
111 BLayoutBuilder::Group
<>((BGroupLayout
*)GetLayout())
118 PartitionsPage::_FillPartitionsView(BView
* view
)
120 // show | name | type | size | path
125 for (int32 i
= 0; fSettings
->FindMessage("partition", i
, &message
) == B_OK
;
127 // get partition data
133 message
.FindBool("show", &show
);
134 message
.FindString("name", &name
);
135 message
.FindString("type", &type
);
136 message
.FindString("path", &path
);
137 message
.FindInt64("size", &size
);
140 BCheckBox
* checkBox
= new BCheckBox("show", "",
141 _CreateControlMessage(kMessageShow
, i
));
143 checkBox
->SetValue(1);
146 BTextControl
* nameControl
= new BTextControl("name", "",
147 name
.String(), _CreateControlMessage(kMessageName
, i
));
148 nameControl
->SetExplicitMinSize(BSize(StringWidth("WWWWWWWWWWWWWW"),
153 _CreateSizeText(size
, &sizeText
);
154 sizeText
<< ", " << type
.String();
155 BStringView
* typeView
= new BStringView("type", sizeText
.String());
156 typeView
->SetExplicitAlignment(
157 BAlignment(B_ALIGN_LEFT
, B_ALIGN_VERTICAL_UNSET
));
160 BStringView
* pathView
= new BStringView("path", path
.String());
161 pathView
->SetExplicitAlignment(
162 BAlignment(B_ALIGN_LEFT
, B_ALIGN_VERTICAL_UNSET
));
165 BLayoutBuilder::Grid
<>((BGridLayout
*)view
->GetLayout())
166 .Add(new BSeparatorView(B_HORIZONTAL
), 0, rowNumber
, 4, 1)
167 .SetRowWeight(rowNumber
, 0);
171 BLayoutBuilder::Grid
<>((BGridLayout
*)view
->GetLayout())
172 .Add(checkBox
, 0, rowNumber
, 1, 2)
173 .Add(nameControl
, 1, rowNumber
, 1, 2)
174 .Add(BSpaceLayoutItem::CreateHorizontalStrut(10), 2, rowNumber
)
175 .Add(typeView
, 3, rowNumber
)
176 .Add(pathView
, 3, rowNumber
+ 1)
177 .SetRowWeight(rowNumber
+ 1, 1);
184 PartitionsPage::_CreateSizeText(int64 size
, BString
* text
)
187 *text
= string_for_size(size
, buffer
, sizeof(buffer
));
192 PartitionsPage::_CreateControlMessage(uint32 what
, int32 index
)
194 BMessage
* message
= new BMessage(what
);
195 message
->AddInt32("index", index
);