xref: /haiku/src/kits/storage/disk_device/PartitionParameterEditor.cpp (revision 95c9effd68127df2dce202d5e254a7c86560010a)
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 #include <PartitionParameterEditor.h>
8 
9 #include <String.h>
10 #include <View.h>
11 
12 
13 BPartitionParameterEditor::BPartitionParameterEditor()
14 	:
15 	fModificationMessage(NULL)
16 {
17 }
18 
19 
20 BPartitionParameterEditor::~BPartitionParameterEditor()
21 {
22 	delete fModificationMessage;
23 }
24 
25 
26 /*!	\brief Sets the controls of the editor to match the parameters
27 		of the given \a partition.
28 
29 	For \c B_CREATE_PARAMETER_EDITOR editors, this will be the parent
30 	partition.
31 */
32 void
33 BPartitionParameterEditor::SetTo(BPartition* partition)
34 {
35 }
36 
37 
38 /*!	\brief Sets the modification message.
39 
40 	This message needs to be sent whenever an internal parameter changed.
41 	This call takes over ownership of the provided message.
42 
43 	The message may contain a string field "parameter" with the value set
44 	to the name of the changed parameter.
45 */
46 void
47 BPartitionParameterEditor::SetModificationMessage(BMessage* message)
48 {
49 	delete fModificationMessage;
50 	fModificationMessage = message;
51 }
52 
53 
54 /*!	\brief The currently set modification message, if any.
55 */
56 BMessage*
57 BPartitionParameterEditor::ModificationMessage() const
58 {
59 	return fModificationMessage;
60 }
61 
62 
63 /*!	\brief Returns a view containing the controls needed for editing the
64 		   parameters.
65 
66 	To be overridden by derived classes.
67 	The base class version returns \c NULL.
68 
69 	The returned BView is added to a window occasionally and removed, when
70 	editing is done. The view belongs to the editor and needs to be deleted
71 	by it. Subsequent calls to this method may return the same view, or each
72 	time delete the old one and return a new one.
73 
74 	\return A view containing the controls needed for editing the parameters.
75 			\c NULL can be returned, if no parameters are needed.
76 */
77 BView*
78 BPartitionParameterEditor::View()
79 {
80 	return NULL;
81 }
82 
83 
84 /*!	\brief Called when the user finishes editing the parameters.
85 
86 	To be overridden by derived classes.
87 	The base class version returns \c true.
88 
89 	The method is supposed to check whether the parameters the user set,
90 	are valid, and, if so, return \c true. Otherwise return \c false.
91 
92 	\return \c true, if the current parameters are valid, \c false otherwise.
93 */
94 bool
95 BPartitionParameterEditor::ValidateParameters() const
96 {
97 	return true;
98 }
99 
100 
101 /*!	\brief Called when a parameter has changed.
102 
103 	Each editor type comes with a number of predefined parameters that
104 	may be changed from the outside while the editor is open. You can
105 	either accept the changes, and update your controls correspondingly,
106 	or else reject the change by returning an appropriate error code.
107 
108 	To be overridden by derived classes.
109 	The base class version returns B_OK.
110 
111 	\param name The name of the changed parameter.
112 	\param variant The new value of the parameter.
113 	\return \c B_OK, if everything went fine, another error code otherwise.
114 */
115 status_t
116 BPartitionParameterEditor::ParameterChanged(const char* name,
117 	const BVariant& variant)
118 {
119 	return B_NOT_SUPPORTED;
120 }
121 
122 
123 /*!	\brief Returns the edited parameters.
124 
125 	To be overridden by derived classes.
126 	The base class version returns an empty string.
127 
128 	\param parameters A BString to be set to the edited parameters.
129 
130 	\return \c B_OK, if everything went fine, another error code otherwise.
131 */
132 status_t
133 BPartitionParameterEditor::GetParameters(BString& parameters)
134 {
135 	parameters.SetTo("");
136 	return B_OK;
137 }
138