1 /*****************************************************************************/
3 // Written by Michael Wilber
7 // This class manages (saves/loads/locks/unlocks) a collection of BMessage
8 // based settings. This class allows you to share settings between different
9 // classes in different threads and receive notifications when the settings
10 // change. This class makes it easy to share settings between a Translator
11 // and its config panel or a Screen Saver and its config panel.
14 // Copyright (C) Haiku
16 // Permission is hereby granted, free of charge, to any person obtaining a
17 // copy of this software and associated documentation files (the "Software"),
18 // to deal in the Software without restriction, including without limitation
19 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
20 // and/or sell copies of the Software, and to permit persons to whom the
21 // Software is furnished to do so, subject to the following conditions:
23 // The above copyright notice and this permission notice shall be included
24 // in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
29 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
31 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 // DEALINGS IN THE SOFTWARE.
33 /*****************************************************************************/
35 #ifndef LIVE_SETTINGS_H
36 #define LIVE_SETTINGS_H
43 #include "LiveSettingsObserver.h"
44 #include "LiveSetting.h"
48 LiveSettings(const char *settingsFile
, LiveSetting
*defaults
,
51 LiveSettings
*Acquire();
52 // increments the reference count, returns this
53 LiveSettings
*Release();
54 // decrements the reference count, deletes this
55 // when count reaches zero, returns this when
56 // ref count is greater than zero, NULL when
59 bool AddObserver(LiveSettingsObserver
*observer
);
60 // returns true if observer was added sucessfully,
61 // false if observer already in the list or error
62 bool RemoveObserver(LiveSettingsObserver
*observer
);
63 // returns true if observer was removed successfully,
64 // false if observer not found or error
66 status_t
LoadSettings();
67 status_t
LoadSettings(BMessage
*pmsg
);
68 status_t
SaveSettings();
69 status_t
GetConfigurationMessage(BMessage
*pmsg
);
71 bool SetGetBool(const char *name
, bool *pVal
= NULL
);
72 int32
SetGetInt32(const char *name
, int32
*pVal
= NULL
);
74 void SetString(const char *name
, const BString
&str
);
75 void GetString(const char *name
, BString
&str
);
78 const LiveSetting
*FindLiveSetting(const char *name
);
80 // private so that Release() must be used
81 // to delete the object
83 void NotifySettingChanged(uint32 setting
);
86 bool GetValue(const char *name
, T
&val
);
89 bool SetValue(const char *name
, const T
&val
);
94 // where the settings file will be loaded from /
97 BMessage fSettingsMsg
;
98 // the actual settings
100 const LiveSetting
*fDefaults
;
103 typedef std::vector
<LiveSettingsObserver
*> ObserverList
;
104 ObserverList fObservers
;
107 #endif // #ifndef LIVE_SETTTINGS_H