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