xref: /haiku/src/apps/codycam/Settings.h (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
1 #ifndef SETTINGS_H
2 #define SETTINGS_H
3 
4 #include "SettingsHandler.h"
5 
6 void SetUpSettings(char* filename);
7 void QuitSettings();
8 
9 class StringValueSetting : public SettingsArgvDispatcher {
10 	// simple string setting
11 public:
12 	StringValueSetting(const char* name, const char* defaultValue,
13 		const char* valueExpectedErrorString,
14 		const char* wrongValueErrorString);
15 
16 	virtual ~StringValueSetting();
17 
18 	void ValueChanged(const char* newValue);
19 	const char* Value() const;
20 	virtual const char* Handle(const char *const *argv);
21 
22 protected:
23 	virtual void SaveSettingValue(Settings*);
24 	virtual bool NeedsSaving() const;
25 
26 	const char* fDefaultValue;
27 	const char* fValueExpectedErrorString;
28 	const char* fWrongValueErrorString;
29 	char* fValue;
30 };
31 
32 
33 class EnumeratedStringValueSetting : public StringValueSetting {
34 	// string setting, values that do not match string enumeration
35 	// are rejected
36 	public:
37 		EnumeratedStringValueSetting(const char* name, const char* defaultValue,
38 			const char *const *values, const char* valueExpectedErrorString,
39 			const char* wrongValueErrorString);
40 
41 		void ValueChanged(const char* newValue);
42 		virtual const char* Handle(const char *const *argv);
43 
44 	protected:
45 		const char *const *fValues;
46 		char* fValue;
47 };
48 
49 
50 class ScalarValueSetting : public SettingsArgvDispatcher {
51 	// simple int32 setting
52 public:
53 	ScalarValueSetting(const char* name, int32 defaultValue,
54 		const char* valueExpectedErrorString, const char* wrongValueErrorString,
55 		int32 min = LONG_MIN, int32 max = LONG_MAX);
56 	virtual ~ScalarValueSetting();
57 
58 	void ValueChanged(int32 newValue);
59 	int32 Value() const;
60 	void GetValueAsString(char*) const;
61 	virtual const char* Handle(const char *const *argv);
62 
63 protected:
64 	virtual void SaveSettingValue(Settings*);
65 	virtual bool NeedsSaving() const;
66 
67 	int32 fDefaultValue;
68 	int32 fValue;
69 	int32 fMax;
70 	int32 fMin;
71 	const char* fValueExpectedErrorString;
72 	const char* fWrongValueErrorString;
73 };
74 
75 class BooleanValueSetting : public ScalarValueSetting {
76 	// on-off setting
77 	public:
78 		BooleanValueSetting(const char* name, bool defaultValue);
79 		virtual ~BooleanValueSetting();
80 
81 		bool Value() const;
82 		virtual const char* Handle(const char *const *argv);
83 
84 	protected:
85 		virtual void SaveSettingValue(Settings *);
86 };
87 
88 #endif	// SETTINGS_H
89