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 const 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 static PrefHandler *Default(); 65 static void DeleteDefault(); 66 static void SetDefault(PrefHandler *handler); 67 68 status_t Open(const char *name); 69 status_t OpenText(const char *path); 70 status_t Save(const char *name); 71 void SaveDefaultAsText(); 72 void SaveAsText(const char *path, const char *minmtype = NULL, 73 const char *signature = NULL); 74 75 int32 getInt32(const char *key); 76 float getFloat(const char *key); 77 const char* getString(const char *key); 78 bool getBool(const char *key); 79 rgb_color getRGB(const char *key); 80 81 void setInt32(const char *key, int32 data); 82 void setFloat(const char *key, float data); 83 void setString(const char *key, const char *data); 84 void setBool(const char *key, bool data); 85 void setRGB(const char *key, const rgb_color data); 86 87 bool IsEmpty() const; 88 89 static status_t GetDefaultPath(BPath& path); 90 91 private: 92 void _ConfirmFont(const char *key, const BFont *fallback); 93 status_t _LoadFromFile(const char* path); 94 status_t _LoadFromDefault(const pref_defaults* defaults = NULL); 95 status_t _LoadFromTextFile(const char * path); 96 97 BMessage fContainer; 98 99 static PrefHandler *sPrefHandler; 100 }; 101 102 #endif // PREF_HANDLER_H 103