Extend Settings to allow value restoration via message.

This commit is contained in:
Rene Gollent 2013-04-16 21:17:44 -04:00
parent 2b9c68af5d
commit ba2c3d57f6
2 changed files with 22 additions and 0 deletions

View File

@ -1,4 +1,5 @@
/*
* Copyright 2013, Rene Gollent, rene@gollent.com.
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
@ -81,6 +82,24 @@ Settings::SetValue(Setting* setting, const BVariant& value)
}
bool
Settings::RestoreValues(const BMessage& message)
{
AutoLocker<BLocker> locker(fLock);
for (int32 i = 0; i < fDescription->CountSettings(); i++) {
Setting* setting = fDescription->SettingAt(i);
BVariant value;
if (value.SetFromMessage(message, setting->ID()) == B_OK) {
if (!SetValue(setting, value))
return false;
}
}
return true;
}
SettingsOption*
Settings::OptionValue(OptionsSetting* setting) const
{

View File

@ -1,4 +1,5 @@
/*
* Copyright 2013, Rene Gollent, rene@gollent.com.
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
@ -40,6 +41,8 @@ public:
bool SetValue(Setting* setting,
const BVariant& value);
bool RestoreValues(const BMessage& message);
bool BoolValue(BoolSetting* setting) const
{ return Value(setting).ToBool(); }
SettingsOption* OptionValue(OptionsSetting* setting) const;