btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / mediaplayer / support / SettingsMessage.cpp
blobdad98820b292e1b6658bdddc9a7111368c59a92d
1 /*
2 * Copyright 2008, Stephan Aßmus <superstippi@gmx.de>.
3 * Copyright 1998, Eric Shepherd.
4 * All rights reserved. Distributed under the terms of the Be Sample Code
5 * license.
6 */
8 //! Be Newsletter Volume II, Issue 35; September 2, 1998 (Eric Shepherd)
10 #include "SettingsMessage.h"
12 #include <Entry.h>
13 #include <File.h>
14 #include <String.h>
17 SettingsMessage::SettingsMessage(directory_which directory,
18 const char* filename)
19 : BMessage('pref')
21 fStatus = find_directory(directory, &fPath);
23 if (fStatus == B_OK)
24 fStatus = fPath.Append(filename);
26 if (fStatus == B_OK)
27 fStatus = Load();
31 SettingsMessage::~SettingsMessage()
33 Save();
37 status_t
38 SettingsMessage::InitCheck() const
40 return fStatus;
44 status_t
45 SettingsMessage::Load()
47 BFile file(fPath.Path(), B_READ_ONLY);
48 status_t status = file.InitCheck();
50 if (status == B_OK)
51 status = Unflatten(&file);
53 return status;
57 status_t
58 SettingsMessage::Save() const
60 BFile file(fPath.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
61 status_t status = file.InitCheck();
63 if (status == B_OK)
64 status = Flatten(&file);
66 return status;
70 // #pragma mark -
73 status_t
74 SettingsMessage::SetValue(const char* name, bool value)
76 if (ReplaceBool(name, value) == B_OK)
77 return B_OK;
78 return AddBool(name, value);
82 status_t
83 SettingsMessage::SetValue(const char* name, int8 value)
85 if (ReplaceInt8(name, value) == B_OK)
86 return B_OK;
87 return AddInt8(name, value);
91 status_t
92 SettingsMessage::SetValue(const char* name, int16 value)
94 if (ReplaceInt16(name, value) == B_OK)
95 return B_OK;
96 return AddInt16(name, value);
100 status_t
101 SettingsMessage::SetValue(const char* name, int32 value)
103 if (ReplaceInt32(name, value) == B_OK)
104 return B_OK;
105 return AddInt32(name, value);
109 status_t
110 SettingsMessage::SetValue(const char* name, uint32 value)
112 if (ReplaceInt32(name, (int32)value) == B_OK)
113 return B_OK;
114 return AddInt32(name, (int32)value);
118 status_t
119 SettingsMessage::SetValue(const char* name, int64 value)
121 if (ReplaceInt64(name, value) == B_OK)
122 return B_OK;
123 return AddInt64(name, value);
127 status_t
128 SettingsMessage::SetValue(const char* name, float value)
130 if (ReplaceFloat(name, value) == B_OK)
131 return B_OK;
132 return AddFloat(name, value);
136 status_t
137 SettingsMessage::SetValue(const char* name, double value)
139 if (ReplaceDouble(name, value) == B_OK)
140 return B_OK;
141 return AddDouble(name, value);
145 status_t
146 SettingsMessage::SetValue(const char* name, const char* value)
148 if (ReplaceString(name, value) == B_OK)
149 return B_OK;
150 return AddString(name, value);
154 status_t
155 SettingsMessage::SetValue(const char* name, const BString& value)
157 return SetValue(name, value.String());
161 status_t
162 SettingsMessage::SetValue(const char* name, const BPoint& value)
164 if (ReplacePoint(name, value) == B_OK)
165 return B_OK;
166 return AddPoint(name, value);
170 status_t
171 SettingsMessage::SetValue(const char* name, const BRect& value)
173 if (ReplaceRect(name, value) == B_OK)
174 return B_OK;
175 return AddRect(name, value);
179 status_t
180 SettingsMessage::SetValue(const char* name, const entry_ref& value)
182 if (ReplaceRef(name, &value) == B_OK)
183 return B_OK;
184 return AddRef(name, &value);
188 status_t
189 SettingsMessage::SetValue(const char* name, const BMessage* value)
191 if (ReplaceMessage(name, value) == B_OK)
192 return B_OK;
193 return AddMessage(name, value);
197 status_t
198 SettingsMessage::SetValue(const char* name, const BFlattenable* value)
200 if (ReplaceFlat(name, const_cast<BFlattenable*>(value)) == B_OK)
201 return B_OK;
202 return AddFlat(name, const_cast<BFlattenable*>(value));
206 // #pragma mark -
208 bool
209 SettingsMessage::GetValue(const char* name, bool defaultValue) const
211 bool value;
212 if (FindBool(name, &value) != B_OK)
213 return defaultValue;
214 return value;
218 int8
219 SettingsMessage::GetValue(const char* name, int8 defaultValue) const
221 int8 value;
222 if (FindInt8(name, &value) != B_OK)
223 return defaultValue;
224 return value;
228 int16
229 SettingsMessage::GetValue(const char* name, int16 defaultValue) const
231 int16 value;
232 if (FindInt16(name, &value) != B_OK)
233 return defaultValue;
234 return value;
238 int32
239 SettingsMessage::GetValue(const char* name, int32 defaultValue) const
241 int32 value;
242 if (FindInt32(name, &value) != B_OK)
243 return defaultValue;
244 return value;
248 uint32
249 SettingsMessage::GetValue(const char* name, uint32 defaultValue) const
251 int32 value;
252 if (FindInt32(name, &value) != B_OK)
253 return defaultValue;
254 return (uint32)value;
258 int64
259 SettingsMessage::GetValue(const char* name, int64 defaultValue) const
261 int64 value;
262 if (FindInt64(name, &value) != B_OK)
263 return defaultValue;
264 return value;
268 float
269 SettingsMessage::GetValue(const char* name, float defaultValue) const
271 float value;
272 if (FindFloat(name, &value) != B_OK)
273 return defaultValue;
274 return value;
278 double
279 SettingsMessage::GetValue(const char* name, double defaultValue) const
281 double value;
282 if (FindDouble(name, &value) != B_OK)
283 return defaultValue;
284 return value;
288 BString
289 SettingsMessage::GetValue(const char* name, const BString& defaultValue) const
291 BString value;
292 if (FindString(name, &value) != B_OK)
293 return defaultValue;
294 return value;
298 BPoint
299 SettingsMessage::GetValue(const char *name, BPoint defaultValue) const
301 BPoint value;
302 if (FindPoint(name, &value) != B_OK)
303 return defaultValue;
304 return value;
308 BRect
309 SettingsMessage::GetValue(const char* name, BRect defaultValue) const
311 BRect value;
312 if (FindRect(name, &value) != B_OK)
313 return defaultValue;
314 return value;
318 entry_ref
319 SettingsMessage::GetValue(const char* name, const entry_ref& defaultValue) const
321 entry_ref value;
322 if (FindRef(name, &value) != B_OK)
323 return defaultValue;
324 return value;
328 BMessage
329 SettingsMessage::GetValue(const char* name, const BMessage& defaultValue) const
331 BMessage value;
332 if (FindMessage(name, &value) != B_OK)
333 return defaultValue;
334 return value;