BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / drivesetup / ChangeParametersPanel.cpp
blob978177802a90fef0f61dd50a335654d8a35ca718
1 /*
2 * Copyright 2008-2013 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
5 * Authors:
6 * Stephan Aßmus <superstippi@gmx.de>
7 * Axel Dörfler, axeld@pinc-software.de.
8 * Bryce Groff <bgroff@hawaii.edu>
9 * Karsten Heimrich <host.haiku@gmx.de>
13 #include "ChangeParametersPanel.h"
15 #include <Button.h>
16 #include <Catalog.h>
17 #include <ControlLook.h>
18 #include <DiskDeviceTypes.h>
19 #include <MenuField.h>
20 #include <MenuItem.h>
21 #include <MessageFilter.h>
22 #include <PopUpMenu.h>
23 #include <String.h>
24 #include <TextControl.h>
25 #include <Variant.h>
27 #include "Support.h"
30 #undef B_TRANSLATION_CONTEXT
31 #define B_TRANSLATION_CONTEXT "ChangeParametersPanel"
34 enum {
35 MSG_PARTITION_TYPE = 'type',
39 ChangeParametersPanel::ChangeParametersPanel(BWindow* window,
40 BPartition* partition)
42 AbstractParametersPanel(window)
44 CreateChangeControls(partition);
46 Init(B_PROPERTIES_PARAMETER_EDITOR, "", partition);
50 ChangeParametersPanel::~ChangeParametersPanel()
55 status_t
56 ChangeParametersPanel::Go(BString& name, BString& type, BString& parameters)
58 BMessage storage;
59 return Go(name, type, parameters, storage);
63 void
64 ChangeParametersPanel::MessageReceived(BMessage* message)
66 switch (message->what) {
67 case MSG_PARTITION_TYPE:
68 if (fEditor != NULL) {
69 const char* type;
70 if (message->FindString("type", &type) == B_OK)
71 fEditor->ParameterChanged("type", BVariant(type));
73 break;
75 default:
76 AbstractParametersPanel::MessageReceived(message);
81 // #pragma mark - protected
84 ChangeParametersPanel::ChangeParametersPanel(BWindow* window)
86 AbstractParametersPanel(window)
91 status_t
92 ChangeParametersPanel::Go(BString& name, BString& type, BString& parameters,
93 BMessage& storage)
95 // The object will be deleted in Go(), so we need to get the values via
96 // a BMessage
97 status_t status = AbstractParametersPanel::Go(parameters, storage);
98 if (status != B_OK)
99 return status;
101 // get name
102 name.SetTo(storage.GetString("name", NULL));
104 // get type
105 type.SetTo(storage.GetString("type", NULL));
107 return B_OK;
111 void
112 ChangeParametersPanel::CreateChangeControls(BPartition* parent)
114 fNameTextControl = new BTextControl("Name Control",
115 B_TRANSLATE("Partition name:"), "", NULL);
116 fSupportsName = parent->SupportsChildName();
118 fTypePopUpMenu = new BPopUpMenu("Partition Type");
120 int32 cookie = 0;
121 BString supportedType;
122 while (parent->GetNextSupportedChildType(&cookie, &supportedType) == B_OK) {
123 BMessage* message = new BMessage(MSG_PARTITION_TYPE);
124 message->AddString("type", supportedType);
125 BMenuItem* item = new BMenuItem(supportedType, message);
126 fTypePopUpMenu->AddItem(item);
128 if (strcmp(supportedType, kPartitionTypeBFS) == 0)
129 item->SetMarked(true);
132 fTypeMenuField = new BMenuField(B_TRANSLATE("Partition type:"),
133 fTypePopUpMenu);
134 fSupportsType = fTypePopUpMenu->CountItems() != 0;
136 fOkButton->SetLabel(B_TRANSLATE("Change"));
140 bool
141 ChangeParametersPanel::NeedsEditor() const
143 return !fSupportsName && !fSupportsType;
147 bool
148 ChangeParametersPanel::ValidWithoutEditor() const
150 return !NeedsEditor();
154 status_t
155 ChangeParametersPanel::ParametersReceived(const BString& parameters,
156 BMessage& storage)
158 // get name
159 status_t status = storage.SetString("name", fNameTextControl->Text());
161 // get type
162 if (BMenuItem* item = fTypeMenuField->Menu()->FindMarked()) {
163 const char* type;
164 BMessage* message = item->Message();
165 if (!message || message->FindString("type", &type) != B_OK)
166 type = kPartitionTypeBFS;
168 if (status == B_OK)
169 status = storage.SetString("type", type);
172 return status;
176 void
177 ChangeParametersPanel::AddControls(BLayoutBuilder::Group<>& builder,
178 BView* editorView)
180 if (fSupportsName || fSupportsType) {
181 BLayoutBuilder::Group<>::GridBuilder gridBuilder
182 = builder.AddGrid(0.0, B_USE_DEFAULT_SPACING);
184 if (fSupportsName) {
185 gridBuilder.Add(fNameTextControl->CreateLabelLayoutItem(), 0, 0)
186 .Add(fNameTextControl->CreateTextViewLayoutItem(), 1, 0);
188 if (fSupportsType) {
189 gridBuilder.Add(fTypeMenuField->CreateLabelLayoutItem(), 0, 1)
190 .Add(fTypeMenuField->CreateMenuBarLayoutItem(), 1, 1);
194 if (editorView != NULL)
195 builder.Add(editorView);