1 /* 2 * Copyright (c) 2004 Daniel Furrer <assimil8or@users.sourceforge.net> 3 * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net> 4 * Copyright (c) 1998,99 Kazuho Okui and Takashi Murai. 5 * 6 * Distributed unter the terms of the MIT License. 7 */ 8 #ifndef PREF_HANDLER_H 9 #define PREF_HANDLER_H 10 11 12 #include <SupportDefs.h> 13 #include <GraphicsDefs.h> 14 #include <Message.h> 15 16 class BFont; 17 class BPath; 18 19 20 #define TP_MAGIC 0xf1f2f3f4 21 #define TP_VERSION 0x02 22 #define TP_FONT_NAME_SZ 128 23 24 struct termprefs { 25 uint32 magic; 26 uint32 version; 27 float x; 28 float y; 29 uint32 cols; 30 uint32 rows; 31 uint32 tab_width; 32 uint32 font_size; 33 char font[TP_FONT_NAME_SZ]; // "Family/Style" 34 uint32 cursor_blink_rate; // blinktime in µs = 1000000 35 uint32 refresh_rate; // ??? = 0 36 rgb_color bg; 37 rgb_color fg; 38 rgb_color curbg; 39 rgb_color curfg; 40 rgb_color selbg; 41 rgb_color selfg; 42 char encoding; // index in the menu (0 = UTF-8) 43 char unknown[3]; 44 }; 45 46 struct prefDefaults { 47 const char *key; 48 char *item; 49 }; 50 51 #define PREF_TRUE "true" 52 #define PREF_FALSE "false" 53 54 class BMessage; 55 class BEntry; 56 57 class PrefHandler { 58 public: 59 PrefHandler(const PrefHandler* p); 60 PrefHandler(); 61 ~PrefHandler(); 62 63 status_t Open(const char *name, const prefDefaults *defaults = NULL); 64 status_t OpenText(const char *path, const prefDefaults *defaults = NULL); 65 status_t Save(const char *name); 66 void SaveAsText(const char *path, const char *minmtype = NULL, 67 const char *signature = NULL); 68 69 int32 getInt32(const char *key); 70 float getFloat(const char *key); 71 const char* getString(const char *key); 72 bool getBool(const char *key); 73 rgb_color getRGB(const char *key); 74 75 void setInt32(const char *key, int32 data); 76 void setFloat(const char *key, float data); 77 void setString(const char *key, const char *data); 78 void setBool(const char *key, bool data); 79 void setRGB(const char *key, const rgb_color data); 80 81 bool IsEmpty() const; 82 83 static status_t GetDefaultPath(BPath& path); 84 85 private: 86 void _ConfirmFont(const char *key, const BFont *fallback); 87 status_t _LoadFromFile(BEntry *ent); 88 status_t _LoadFromDefault(const prefDefaults* defaluts = NULL); 89 status_t _LoadFromTextFile(const char * path); 90 91 BMessage fContainer; 92 }; 93 94 #endif // PREF_HANDLER_H 95