xref: /haiku/src/apps/terminal/PrefHandler.h (revision 1ce9b0cb59525cee96af4e8838b152ec7261bf33)
1 /*
2  * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
3  * Copyright (c) 2004 Daniel Furrer <assimil8or@users.sourceforge.net>
4  * Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files or portions
8  * thereof (the "Software"), to deal in the Software without restriction,
9  * including without limitation the rights to use, copy, modify, merge,
10  * publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so, subject
12  * to the following conditions:
13  *
14  *  * Redistributions of source code must retain the above copyright notice,
15  *    this list of conditions and the following disclaimer.
16  *
17  *  * Redistributions in binary form must reproduce the above copyright notice
18  *    in the  binary, as well as this list of conditions and the following
19  *    disclaimer in the documentation and/or other materials provided with
20  *    the distribution.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28  * THE SOFTWARE.
29  *
30  */
31 #ifndef PREFHANDLER_H_INCLUDED
32 #define PREFHANDLER_H_INCLUDED
33 
34 #include <SupportDefs.h>
35 #include <Errors.h>
36 #include <GraphicsDefs.h>
37 #include <Message.h>
38 
39 #define TP_MAGIC 0xf1f2f3f4
40 #define TP_VERSION 0x02
41 #define TP_FONT_NAME_SZ 128
42 
43 struct termprefs {
44 	uint32 magic;
45 	uint32 version;
46 	float x;
47 	float y;
48 	uint32 cols;
49 	uint32 rows;
50 	uint32 tab_width;
51 	uint32 font_size;
52 	char font[TP_FONT_NAME_SZ]; // "Family/Style"
53 	uint32 cursor_blink_rate; // blinktime in µs = 1000000
54 	uint32 refresh_rate; // ??? = 0
55 	rgb_color bg;
56 	rgb_color fg;
57 	rgb_color curbg;
58 	rgb_color curfg;
59 	rgb_color selbg;
60 	rgb_color selfg;
61 	char encoding; // index in the menu (0 = UTF-8)
62 	char unknown[3];
63 };
64 
65 struct prefDefaults {
66 	const char *key;
67 	char *item;
68 };
69 
70 #define PREF_TRUE "true"
71 #define PREF_FALSE "false"
72 
73 class BMessage;
74 class BEntry;
75 
76 class PrefHandler {
77 	public:
78 		PrefHandler(const PrefHandler* p);
79 		PrefHandler();
80 		~PrefHandler();
81 
82 		status_t    Open(const char *name, const prefDefaults *defaults = NULL);
83 		status_t    OpenText(const char *path, const prefDefaults *defaults = NULL);
84 		status_t    Save(const char *name);
85 		void        SaveAsText(const char *path, const char *minmtype = NULL,
86 						const char *signature = NULL);
87 
88 		int32       getInt32(const char *key);
89 		float       getFloat(const char *key);
90 		const char* getString(const char *key);
91 		bool        getBool(const char *key);
92 		rgb_color   getRGB(const char *key);
93 
94 		void        setInt32(const char *key, int32 data);
95 		void        setFloat(const char *key, float data);
96 		void        setString(const char *key, const char *data);
97 		void        setBool(const char *key, bool data);
98 		void        setRGB(const char *key, const rgb_color data);
99 
100 		bool        IsEmpty() const;
101 
102 		static status_t GetDefaultPath(BPath& path);
103 
104 	private:
105 		void		_ConfirmFont(const char *key, const BFont *fallback);
106 		status_t    _LoadFromFile(BEntry *ent);
107 		status_t    _LoadFromDefault(const prefDefaults* defaluts = NULL);
108 		status_t    _LoadFromTextFile(const char * path);
109 
110 		BMessage    fContainer;
111 };
112 
113 #endif // PREFHANDLER_H_INCLUDED
114