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
8 //! Be Newsletter Volume II, Issue 35; September 2, 1998 (Eric Shepherd)
10 #include "SettingsMessage.h"
17 SettingsMessage::SettingsMessage(directory_which directory
,
21 fStatus
= find_directory(directory
, &fPath
);
24 fStatus
= fPath
.Append(filename
);
31 SettingsMessage::~SettingsMessage()
38 SettingsMessage::InitCheck() const
45 SettingsMessage::Load()
47 BFile
file(fPath
.Path(), B_READ_ONLY
);
48 status_t status
= file
.InitCheck();
51 status
= Unflatten(&file
);
58 SettingsMessage::Save() const
60 BFile
file(fPath
.Path(), B_WRITE_ONLY
| B_CREATE_FILE
| B_ERASE_FILE
);
61 status_t status
= file
.InitCheck();
64 status
= Flatten(&file
);
74 SettingsMessage::SetValue(const char* name
, bool value
)
76 if (ReplaceBool(name
, value
) == B_OK
)
78 return AddBool(name
, value
);
83 SettingsMessage::SetValue(const char* name
, int8 value
)
85 if (ReplaceInt8(name
, value
) == B_OK
)
87 return AddInt8(name
, value
);
92 SettingsMessage::SetValue(const char* name
, int16 value
)
94 if (ReplaceInt16(name
, value
) == B_OK
)
96 return AddInt16(name
, value
);
101 SettingsMessage::SetValue(const char* name
, int32 value
)
103 if (ReplaceInt32(name
, value
) == B_OK
)
105 return AddInt32(name
, value
);
110 SettingsMessage::SetValue(const char* name
, uint32 value
)
112 if (ReplaceInt32(name
, (int32
)value
) == B_OK
)
114 return AddInt32(name
, (int32
)value
);
119 SettingsMessage::SetValue(const char* name
, int64 value
)
121 if (ReplaceInt64(name
, value
) == B_OK
)
123 return AddInt64(name
, value
);
128 SettingsMessage::SetValue(const char* name
, float value
)
130 if (ReplaceFloat(name
, value
) == B_OK
)
132 return AddFloat(name
, value
);
137 SettingsMessage::SetValue(const char* name
, double value
)
139 if (ReplaceDouble(name
, value
) == B_OK
)
141 return AddDouble(name
, value
);
146 SettingsMessage::SetValue(const char* name
, const char* value
)
148 if (ReplaceString(name
, value
) == B_OK
)
150 return AddString(name
, value
);
155 SettingsMessage::SetValue(const char* name
, const BString
& value
)
157 return SetValue(name
, value
.String());
162 SettingsMessage::SetValue(const char* name
, const BPoint
& value
)
164 if (ReplacePoint(name
, value
) == B_OK
)
166 return AddPoint(name
, value
);
171 SettingsMessage::SetValue(const char* name
, const BRect
& value
)
173 if (ReplaceRect(name
, value
) == B_OK
)
175 return AddRect(name
, value
);
180 SettingsMessage::SetValue(const char* name
, const entry_ref
& value
)
182 if (ReplaceRef(name
, &value
) == B_OK
)
184 return AddRef(name
, &value
);
189 SettingsMessage::SetValue(const char* name
, const BMessage
* value
)
191 if (ReplaceMessage(name
, value
) == B_OK
)
193 return AddMessage(name
, value
);
198 SettingsMessage::SetValue(const char* name
, const BFlattenable
* value
)
200 if (ReplaceFlat(name
, const_cast<BFlattenable
*>(value
)) == B_OK
)
202 return AddFlat(name
, const_cast<BFlattenable
*>(value
));
209 SettingsMessage::GetValue(const char* name
, bool defaultValue
) const
212 if (FindBool(name
, &value
) != B_OK
)
219 SettingsMessage::GetValue(const char* name
, int8 defaultValue
) const
222 if (FindInt8(name
, &value
) != B_OK
)
229 SettingsMessage::GetValue(const char* name
, int16 defaultValue
) const
232 if (FindInt16(name
, &value
) != B_OK
)
239 SettingsMessage::GetValue(const char* name
, int32 defaultValue
) const
242 if (FindInt32(name
, &value
) != B_OK
)
249 SettingsMessage::GetValue(const char* name
, uint32 defaultValue
) const
252 if (FindInt32(name
, &value
) != B_OK
)
254 return (uint32
)value
;
259 SettingsMessage::GetValue(const char* name
, int64 defaultValue
) const
262 if (FindInt64(name
, &value
) != B_OK
)
269 SettingsMessage::GetValue(const char* name
, float defaultValue
) const
272 if (FindFloat(name
, &value
) != B_OK
)
279 SettingsMessage::GetValue(const char* name
, double defaultValue
) const
282 if (FindDouble(name
, &value
) != B_OK
)
289 SettingsMessage::GetValue(const char* name
, const BString
& defaultValue
) const
292 if (FindString(name
, &value
) != B_OK
)
299 SettingsMessage::GetValue(const char *name
, BPoint defaultValue
) const
302 if (FindPoint(name
, &value
) != B_OK
)
309 SettingsMessage::GetValue(const char* name
, BRect defaultValue
) const
312 if (FindRect(name
, &value
) != B_OK
)
319 SettingsMessage::GetValue(const char* name
, const entry_ref
& defaultValue
) const
322 if (FindRef(name
, &value
) != B_OK
)
329 SettingsMessage::GetValue(const char* name
, const BMessage
& defaultValue
) const
332 if (FindMessage(name
, &value
) != B_OK
)