1/*
2 * Copyright (c) 2003-2013, Haiku, Inc. All Rights Reserved.
3 * Copyright (c) 2004 Daniel Furrer <assimil8or@users.sourceforge.net>
4 * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
5 * Copyright (c) 1998,99 Kazuho Okui and Takashi Murai.
6 *
7 * Distributed unter the terms of the MIT License.
8 *
9 * Authors:
10 *		Kian Duffy, myob@users.sourceforge.net
11 *		Daniel Furrer, assimil8or@users.sourceforge.net
12 *		Siarzhuk Zharski, zharik@gmx.li
13 */
14#ifndef PREF_HANDLER_H
15#define PREF_HANDLER_H
16
17
18#include <SupportDefs.h>
19#include <GraphicsDefs.h>
20#include <Message.h>
21#include <String.h>
22
23class BFont;
24class BPath;
25
26
27struct color_scheme;
28
29struct pref_defaults {
30	const char *key;
31	const char *item;
32};
33
34#define PREF_TRUE "true"
35#define PREF_FALSE "false"
36
37#define PREF_BLOCK_CURSOR "block"
38#define PREF_IBEAM_CURSOR "ibeam"
39#define PREF_UNDERLINE_CURSOR "underline"
40
41
42class BMessage;
43class BEntry;
44
45class PrefHandler {
46	public:
47		PrefHandler(const PrefHandler* p);
48		PrefHandler(bool loadSettings = true);
49		~PrefHandler();
50
51	static	PrefHandler *Default();
52	static	void DeleteDefault();
53	static	void SetDefault(PrefHandler *handler);
54
55		status_t    OpenText(const char *path);
56		void		SaveDefaultAsText();
57		void        SaveAsText(const char *path, const char *minmtype = NULL,
58						const char *signature = NULL);
59
60		int32       getInt32(const char *key);
61		float       getFloat(const char *key);
62		const char* getString(const char *key);
63		bool        getBool(const char *key);
64		rgb_color   getRGB(const char *key);
65		int			getCursor(const char *key);
66
67		void        setInt32(const char *key, int32 data);
68		void        setFloat(const char *key, float data);
69		void        setString(const char *key, const char *data);
70		void        setBool(const char *key, bool data);
71		void        setRGB(const char *key, const rgb_color data);
72
73		bool        IsEmpty() const;
74
75		static status_t GetDefaultPath(BPath& path);
76
77		void LoadThemes();
78		void LoadColorScheme(color_scheme* scheme);
79
80	private:
81		void		_ConfirmFont(const BFont *fallbackFont);
82		status_t    _LoadFromDefault(const pref_defaults* defaults = NULL);
83		status_t    _LoadFromTextFile(const char * path);
84	static bool _LoadThemesFromDirectory(const BString &directory);
85
86		BMessage    fContainer;
87
88	static	PrefHandler *sPrefHandler;
89};
90
91#endif	// PREF_HANDLER_H
92