1 #ifndef SETTINGS_HANDLER_H
2 #define SETTINGS_HANDLER_H
10 #include <SupportDefs.h>
19 typedef const char* (*ArgvHandler
)(int argc
, const char *const *argv
, void *params
);
20 // return 0 or error string if parsing failed
23 const int32 kBufferSize
= 1024;
28 static status_t
EachArgv(const char* name
,
29 ArgvHandler argvHandlerFunc
, void* passThru
);
32 ArgvParser(const char* name
);
35 status_t
EachArgvPrivate(const char* name
,
36 ArgvHandler argvHandlerFunc
, void* passThru
);
39 status_t
SendArgv(ArgvHandler argvHandlerFunc
, void* passThru
);
40 // done with a whole line of argv, send it off and get ready
44 // done with current string, get ready to start building next
45 void NextArgvIfNotEmpty();
46 // as above, don't commint current string if empty
58 int32 fCurrentArgsPos
;
59 char fCurrentArgs
[1024];
67 const char* fFileName
;
71 class SettingsArgvDispatcher
{
72 // base class for a single setting item
74 SettingsArgvDispatcher(const char* name
);
75 virtual ~SettingsArgvDispatcher() {};
77 void SaveSettings(Settings
* settings
, bool onlyIfNonDefault
);
79 const char* Name() const
84 virtual const char* Handle(const char* const *argv
) = 0;
85 // override this adding an argv parser that reads in the
86 // values in argv format for this setting
87 // return a pointer to an error message or null if parsed OK
89 bool HandleRectValue(BRect
&, const char* const *argv
,
90 bool printError
= true);
92 // static bool HandleColorValue(rgb_color &, const char *const *argv, bool printError = true);
93 void WriteRectValue(Settings
*, BRect
);
94 // void WriteColorValue(BRect);
97 virtual void SaveSettingValue(Settings
* settings
) = 0;
98 // override this to save the current value of this setting in a
101 virtual bool NeedsSaving() const
105 // override to return false if current value is equal to the default
106 // and does not need saving
114 Settings(const char* filename
, const char* settingsDirName
);
116 void TryReadingSettings();
117 void SaveSettings(bool onlyIfNonDefault
= true);
119 #ifdef SINGLE_SETTING_FILE
120 static Settings
* SettingsHandler()
122 return settingsHandler
;
125 Settings
* SettingsHandler()
131 bool Add(SettingsArgvDispatcher
*);
133 void Write(const char* format
, ...);
134 void VSWrite(const char*, va_list);
136 #ifdef SINGLE_SETTING_FILE
137 static Settings
* settingsHandler
;
141 void _MakeSettingsDirectory(BDirectory
*);
143 SettingsArgvDispatcher
* _Find(const char*);
144 static const char* _ParseUserSettings(int, const char *const *argv
, void*);
145 void _SaveCurrentSettings(bool onlyIfNonDefault
);
147 const char* fFileName
;
148 const char* fSettingsDir
;
149 SettingsArgvDispatcher
** fList
;
152 BFile
* fCurrentSettings
;
155 #endif // SETTINGS_HANDLER_H