xref: /haiku/src/add-ons/translators/shared/TranslatorSettings.h (revision c56079fb2280536dcae1e0f481f127a78a9acb83)
1*c56079fbSMatthew Wilber /*****************************************************************************/
2*c56079fbSMatthew Wilber // TranslatorSettings
3*c56079fbSMatthew Wilber // Written by Michael Wilber, OBOS Translation Kit Team
4*c56079fbSMatthew Wilber //
5*c56079fbSMatthew Wilber // TranslatorSettings.h
6*c56079fbSMatthew Wilber //
7*c56079fbSMatthew Wilber // This class manages (saves/loads/locks/unlocks) the settings
8*c56079fbSMatthew Wilber // for a Translator.
9*c56079fbSMatthew Wilber //
10*c56079fbSMatthew Wilber //
11*c56079fbSMatthew Wilber // Copyright (c) 2004 OpenBeOS Project
12*c56079fbSMatthew Wilber //
13*c56079fbSMatthew Wilber // Permission is hereby granted, free of charge, to any person obtaining a
14*c56079fbSMatthew Wilber // copy of this software and associated documentation files (the "Software"),
15*c56079fbSMatthew Wilber // to deal in the Software without restriction, including without limitation
16*c56079fbSMatthew Wilber // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17*c56079fbSMatthew Wilber // and/or sell copies of the Software, and to permit persons to whom the
18*c56079fbSMatthew Wilber // Software is furnished to do so, subject to the following conditions:
19*c56079fbSMatthew Wilber //
20*c56079fbSMatthew Wilber // The above copyright notice and this permission notice shall be included
21*c56079fbSMatthew Wilber // in all copies or substantial portions of the Software.
22*c56079fbSMatthew Wilber //
23*c56079fbSMatthew Wilber // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24*c56079fbSMatthew Wilber // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25*c56079fbSMatthew Wilber // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26*c56079fbSMatthew Wilber // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27*c56079fbSMatthew Wilber // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28*c56079fbSMatthew Wilber // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29*c56079fbSMatthew Wilber // DEALINGS IN THE SOFTWARE.
30*c56079fbSMatthew Wilber /*****************************************************************************/
31*c56079fbSMatthew Wilber 
32*c56079fbSMatthew Wilber #ifndef TRANSLATOR_SETTINGS_H
33*c56079fbSMatthew Wilber #define TRANSLATOR_SETTINGS_H
34*c56079fbSMatthew Wilber 
35*c56079fbSMatthew Wilber #include <Locker.h>
36*c56079fbSMatthew Wilber #include <Path.h>
37*c56079fbSMatthew Wilber #include <Message.h>
38*c56079fbSMatthew Wilber 
39*c56079fbSMatthew Wilber enum TranSettingType {
40*c56079fbSMatthew Wilber 	TRAN_SETTING_INT32 = 0,
41*c56079fbSMatthew Wilber 	TRAN_SETTING_BOOL
42*c56079fbSMatthew Wilber };
43*c56079fbSMatthew Wilber 
44*c56079fbSMatthew Wilber struct TranSetting {
45*c56079fbSMatthew Wilber 	const char *name;
46*c56079fbSMatthew Wilber 	TranSettingType dataType;
47*c56079fbSMatthew Wilber 	int32 defaultVal;
48*c56079fbSMatthew Wilber };
49*c56079fbSMatthew Wilber 
50*c56079fbSMatthew Wilber class TranslatorSettings {
51*c56079fbSMatthew Wilber public:
52*c56079fbSMatthew Wilber 	TranslatorSettings(const char *settingsFile, TranSetting *defaults,
53*c56079fbSMatthew Wilber 		int32 defCount);
54*c56079fbSMatthew Wilber 
55*c56079fbSMatthew Wilber 	TranslatorSettings *Acquire();
56*c56079fbSMatthew Wilber 		// increments the reference count, returns this
57*c56079fbSMatthew Wilber 	TranslatorSettings *Release();
58*c56079fbSMatthew Wilber 		// decrements the reference count, deletes this
59*c56079fbSMatthew Wilber 		// when count reaches zero, returns this when
60*c56079fbSMatthew Wilber 		// ref count is greater than zero, NULL when
61*c56079fbSMatthew Wilber 		// ref count is zero
62*c56079fbSMatthew Wilber 
63*c56079fbSMatthew Wilber 	status_t LoadSettings();
64*c56079fbSMatthew Wilber 	status_t LoadSettings(BMessage *pmsg);
65*c56079fbSMatthew Wilber 	status_t SaveSettings();
66*c56079fbSMatthew Wilber 	status_t GetConfigurationMessage(BMessage *pmsg);
67*c56079fbSMatthew Wilber 
68*c56079fbSMatthew Wilber 	bool SetGetBool(const char *name, bool *pbool = NULL);
69*c56079fbSMatthew Wilber 	int32 SetGetInt32(const char *name, int32 *pint32 = NULL);
70*c56079fbSMatthew Wilber 
71*c56079fbSMatthew Wilber private:
72*c56079fbSMatthew Wilber 	const TranSetting *FindTranSetting(const char *name);
73*c56079fbSMatthew Wilber 	~TranslatorSettings();
74*c56079fbSMatthew Wilber 		// private so that Release() must be used
75*c56079fbSMatthew Wilber 		// to delete the object
76*c56079fbSMatthew Wilber 
77*c56079fbSMatthew Wilber 	BLocker fLock;
78*c56079fbSMatthew Wilber 	int32 fRefCount;
79*c56079fbSMatthew Wilber 	BPath fSettingsPath;
80*c56079fbSMatthew Wilber 		// where the settings file will be loaded from /
81*c56079fbSMatthew Wilber 		// saved to
82*c56079fbSMatthew Wilber 
83*c56079fbSMatthew Wilber 	BMessage fSettingsMsg;
84*c56079fbSMatthew Wilber 		// the actual settings
85*c56079fbSMatthew Wilber 
86*c56079fbSMatthew Wilber 	const TranSetting *fDefaults;
87*c56079fbSMatthew Wilber 	int32 fDefCount;
88*c56079fbSMatthew Wilber };
89*c56079fbSMatthew Wilber 
90*c56079fbSMatthew Wilber #endif // #ifndef TRANSLATOR_SETTTINGS_H
91*c56079fbSMatthew Wilber 
92