1e1f99aaeSthreedeyes /*
244352255SAxel Dörfler * Copyright 2013, Axel Dörfler, axeld@pinc-software.de.
3e1f99aaeSthreedeyes * Copyright 2009-2010, Stephan Aßmus <superstippi@gmx.de>
4e1f99aaeSthreedeyes * Copyright 2009, Bryce Groff, brycegroff@gmail.com.
5e1f99aaeSthreedeyes * Distributed under the terms of the MIT License.
6e1f99aaeSthreedeyes */
7e1f99aaeSthreedeyes
8e1f99aaeSthreedeyes
9e1f99aaeSthreedeyes #include <stdio.h>
10e1f99aaeSthreedeyes
11e1f99aaeSthreedeyes #include "InitializeParameterEditor.h"
12e1f99aaeSthreedeyes
13e1f99aaeSthreedeyes #include <Button.h>
14e1f99aaeSthreedeyes #include <Catalog.h>
15e1f99aaeSthreedeyes #include <ControlLook.h>
16e1f99aaeSthreedeyes #include <GridLayoutBuilder.h>
1744352255SAxel Dörfler #include <Partition.h>
18e1f99aaeSthreedeyes #include <SpaceLayoutItem.h>
19e1f99aaeSthreedeyes #include <TextControl.h>
2044352255SAxel Dörfler #include <Variant.h>
21e1f99aaeSthreedeyes #include <View.h>
22e1f99aaeSthreedeyes #include <Window.h>
23e1f99aaeSthreedeyes
24e1f99aaeSthreedeyes
2544352255SAxel Dörfler #undef B_TRANSLATION_CONTEXT
2644352255SAxel Dörfler #define B_TRANSLATION_CONTEXT "NTFS_Initialize_Parameter"
2744352255SAxel Dörfler
2844352255SAxel Dörfler
29e1f99aaeSthreedeyes static uint32 MSG_NAME_CHANGED = 'nmch';
30e1f99aaeSthreedeyes
31e1f99aaeSthreedeyes
InitializeNTFSEditor()32e1f99aaeSthreedeyes InitializeNTFSEditor::InitializeNTFSEditor()
33e1f99aaeSthreedeyes :
34e1f99aaeSthreedeyes BPartitionParameterEditor(),
35e1f99aaeSthreedeyes fView(NULL),
3644352255SAxel Dörfler fNameControl(NULL),
37e1f99aaeSthreedeyes fParameters(NULL)
38e1f99aaeSthreedeyes {
39e1f99aaeSthreedeyes _CreateViewControls();
40e1f99aaeSthreedeyes }
41e1f99aaeSthreedeyes
42e1f99aaeSthreedeyes
~InitializeNTFSEditor()43e1f99aaeSthreedeyes InitializeNTFSEditor::~InitializeNTFSEditor()
44e1f99aaeSthreedeyes {
45e1f99aaeSthreedeyes }
46e1f99aaeSthreedeyes
47e1f99aaeSthreedeyes
4844352255SAxel Dörfler void
SetTo(BPartition * partition)4944352255SAxel Dörfler InitializeNTFSEditor::SetTo(BPartition* partition)
5044352255SAxel Dörfler {
519ba5f873SJessica Hamilton BString name = partition->Name();
529ba5f873SJessica Hamilton if (name.IsEmpty())
53*e065d697SJérôme Duval name = partition->RawContentName();
5444352255SAxel Dörfler if (!name.IsEmpty())
5544352255SAxel Dörfler fNameControl->SetText(name.String());
5644352255SAxel Dörfler }
5744352255SAxel Dörfler
5844352255SAxel Dörfler
59e1f99aaeSthreedeyes BView*
View()60e1f99aaeSthreedeyes InitializeNTFSEditor::View()
61e1f99aaeSthreedeyes {
62e1f99aaeSthreedeyes return fView;
63e1f99aaeSthreedeyes }
64e1f99aaeSthreedeyes
65e1f99aaeSthreedeyes
66e1f99aaeSthreedeyes bool
ValidateParameters() const6744352255SAxel Dörfler InitializeNTFSEditor::ValidateParameters() const
68e1f99aaeSthreedeyes {
6944352255SAxel Dörfler // The name must be set
7044352255SAxel Dörfler return fNameControl->TextView()->TextLength() > 0;
71e1f99aaeSthreedeyes }
72e1f99aaeSthreedeyes
73e1f99aaeSthreedeyes
74e1f99aaeSthreedeyes status_t
ParameterChanged(const char * name,const BVariant & variant)7544352255SAxel Dörfler InitializeNTFSEditor::ParameterChanged(const char* name,
7644352255SAxel Dörfler const BVariant& variant)
77e1f99aaeSthreedeyes {
7844352255SAxel Dörfler if (!strcmp(name, "name"))
7944352255SAxel Dörfler fNameControl->SetText(variant.ToString());
80e1f99aaeSthreedeyes return B_OK;
81e1f99aaeSthreedeyes }
82e1f99aaeSthreedeyes
83e1f99aaeSthreedeyes
84e1f99aaeSthreedeyes status_t
GetParameters(BString & parameters)8544352255SAxel Dörfler InitializeNTFSEditor::GetParameters(BString& parameters)
86e1f99aaeSthreedeyes {
8744352255SAxel Dörfler parameters = "name \"";
8844352255SAxel Dörfler parameters << fNameControl->Text() << "\";\n";
89e1f99aaeSthreedeyes return B_OK;
90e1f99aaeSthreedeyes }
91e1f99aaeSthreedeyes
92e1f99aaeSthreedeyes
93e1f99aaeSthreedeyes void
_CreateViewControls()94e1f99aaeSthreedeyes InitializeNTFSEditor::_CreateViewControls()
95e1f99aaeSthreedeyes {
9644352255SAxel Dörfler fNameControl = new BTextControl(B_TRANSLATE("Name:"), "New NTFS Volume",
9744352255SAxel Dörfler NULL);
9844352255SAxel Dörfler fNameControl->SetModificationMessage(new BMessage(MSG_NAME_CHANGED));
9944352255SAxel Dörfler fNameControl->TextView()->SetMaxBytes(127);
100e1f99aaeSthreedeyes
101e1f99aaeSthreedeyes float spacing = be_control_look->DefaultItemSpacing();
102e1f99aaeSthreedeyes
103e1f99aaeSthreedeyes fView = BGridLayoutBuilder(spacing, spacing)
10444352255SAxel Dörfler .Add(fNameControl->CreateLabelLayoutItem(), 0, 0)
10544352255SAxel Dörfler .Add(fNameControl->CreateTextViewLayoutItem(), 1, 0).View()
106e1f99aaeSthreedeyes ;
107e1f99aaeSthreedeyes }
108