xref: /haiku/src/apps/codycam/Settings.h (revision bb83316a5811a550c4f850d07fa8e328e7ac0a94)
1 /*
2  * Copyright 1998-1999 Be, Inc. All Rights Reserved.
3  * Copyright 2003-2019 Haiku, Inc. All rights reserved.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef SETTINGS_H
7 #define SETTINGS_H
8 
9 #include "SettingsHandler.h"
10 
11 void SetUpSettings(char* filename);
12 void QuitSettings();
13 
14 class StringValueSetting : public SettingsArgvDispatcher {
15 	// simple string setting
16 public:
17 								StringValueSetting(const char* name,
18 									const char* defaultValue,
19 									const char* valueExpectedErrorString,
20 									const char* wrongValueErrorString = "");
21 
22 	virtual						~StringValueSetting();
23 
24 			void				ValueChanged(const char* newValue);
25 			const char*			Value() const;
26 	virtual const char*			Handle(const char* const *argv);
27 
28 protected:
29 	virtual	void				SaveSettingValue(Settings*);
30 	virtual	bool				NeedsSaving() const;
31 
32 			const char*			fDefaultValue;
33 			const char*			fValueExpectedErrorString;
34 			const char*			fWrongValueErrorString;
35 			char*				fValue;
36 };
37 
38 
39 // string setting, values that do not match string enumeration
40 // are rejected
41 class EnumeratedStringValueSetting : public StringValueSetting {
42 public:
43 	// A pointer to a function returning a string for an index, or NULL
44 	// if the index is out of bounds.
45 	typedef const char* (*StringEnumerator)(int32);
46 
47 								EnumeratedStringValueSetting(const char* name,
48 									const char* defaultValue,
49 									StringEnumerator enumerator,
50 									const char* valueExpectedErrorString,
51 									const char* wrongValueErrorString);
52 
53 			void				ValueChanged(const char* newValue);
54 	virtual const char*			Handle(const char* const *argv);
55 
56 private:
57 			bool				_ValidateString(const char* string);
58 			StringEnumerator	fEnumerator;
59 };
60 
61 
62 // simple int32 setting
63 class ScalarValueSetting : public SettingsArgvDispatcher {
64 public:
65 								ScalarValueSetting(const char* name,
66 									int32 defaultValue,
67 									const char* valueExpectedErrorString,
68 									const char* wrongValueErrorString,
69 									int32 min = INT32_MIN,
70 									int32 max = INT32_MAX);
71 	virtual						~ScalarValueSetting();
72 
73 			void				ValueChanged(int32 newValue);
74 			int32				Value() const;
75 			void				GetValueAsString(char*) const;
76 	virtual const char*			Handle(const char* const *argv);
77 
78 protected:
79 	virtual void				SaveSettingValue(Settings*);
80 	virtual bool				NeedsSaving() const;
81 
82 			int32				fDefaultValue;
83 			int32				fValue;
84 			int32				fMax;
85 			int32				fMin;
86 			const char*			fValueExpectedErrorString;
87 			const char*			fWrongValueErrorString;
88 };
89 
90 
91 class BooleanValueSetting : public ScalarValueSetting {
92 public:
93 								BooleanValueSetting(const char* name,
94 									bool defaultValue);
95 	virtual						~BooleanValueSetting();
96 
97 			bool				Value() const;
98 	virtual	const char*			Handle(const char* const *argv);
99 
100 protected:
101 	virtual	void				SaveSettingValue(Settings*);
102 };
103 
104 #endif	// SETTINGS_H
105