xref: /haiku/src/apps/codycam/Settings.h (revision d5cd5d63ff0ad395989db6cf4841a64d5b545d1d)
1 #ifndef __SETTINGS__
2 #define __SETTINGS__
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 *defaultValue;
27 	const char *valueExpectedErrorString;
28 	const char *wrongValueErrorString;
29 	char *value;
30 };
31 
32 class EnumeratedStringValueSetting : public StringValueSetting {
33 	// string setting, values that do not match string enumeration
34 	// are rejected
35 public:
36 	EnumeratedStringValueSetting(const char *name, const char *defaultValue,
37 		const char *const *values, const char *valueExpectedErrorString,
38 		const char *wrongValueErrorString);
39 
40 	void ValueChanged(const char *newValue);
41 	virtual const char *Handle(const char *const *argv);
42 
43 protected:
44 	const char *const *values;
45 	char *value;
46 };
47 
48 class ScalarValueSetting : public SettingsArgvDispatcher {
49 	// simple int32 setting
50 public:
51 	ScalarValueSetting(const char *name, int32 defaultValue,
52 		const char *valueExpectedErrorString, const char *wrongValueErrorString,
53 		int32 min = LONG_MIN, int32 max = LONG_MAX);
54 
55 	void ValueChanged(int32 newValue);
56 	int32 Value() const;
57 	void GetValueAsString(char *) const;
58 	virtual const char *Handle(const char *const *argv);
59 
60 protected:
61 	virtual void SaveSettingValue(Settings *);
62 	virtual bool NeedsSaving() const;
63 
64 	int32 defaultValue;
65 	int32 value;
66 	int32 max;
67 	int32 min;
68 	const char *valueExpectedErrorString;
69 	const char *wrongValueErrorString;
70 };
71 
72 class BooleanValueSetting : public ScalarValueSetting {
73 	// on-off setting
74 public:
75 	BooleanValueSetting(const char *name, bool defaultValue);
76 
77 	bool Value() const;
78 	virtual const char *Handle(const char *const *argv);
79 
80 protected:
81 	virtual void SaveSettingValue(Settings *);
82 };
83 
84 #endif
85