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 bool warn_on_exit; 45 char unknown[2]; 46 }; 47 48 struct pref_defaults { 49 const char *key; 50 const char *item; 51 }; 52 53 #define PREF_TRUE "true" 54 #define PREF_FALSE "false" 55 56 class BMessage; 57 class BEntry; 58 59 class PrefHandler { 60 public: 61 PrefHandler(const PrefHandler* p); 62 PrefHandler(); 63 ~PrefHandler(); 64 65 static PrefHandler *Default(); 66 static void DeleteDefault(); 67 static void SetDefault(PrefHandler *handler); 68 69 status_t Open(const char *name); 70 status_t OpenText(const char *path); 71 status_t Save(const char *name); 72 void SaveDefaultAsText(); 73 void SaveAsText(const char *path, const char *minmtype = NULL, 74 const char *signature = NULL); 75 76 int32 getInt32(const char *key); 77 float getFloat(const char *key); 78 const char* getString(const char *key); 79 bool getBool(const char *key); 80 rgb_color getRGB(const char *key); 81 82 void setInt32(const char *key, int32 data); 83 void setFloat(const char *key, float data); 84 void setString(const char *key, const char *data); 85 void setBool(const char *key, bool data); 86 void setRGB(const char *key, const rgb_color data); 87 88 bool IsEmpty() const; 89 90 static status_t GetDefaultPath(BPath& path); 91 92 private: 93 void _ConfirmFont(const char *key, const BFont *fallback); 94 status_t _LoadFromFile(const char* path); 95 status_t _LoadFromDefault(const pref_defaults* defaults = NULL); 96 status_t _LoadFromTextFile(const char * path); 97 98 BMessage fContainer; 99 100 static PrefHandler *sPrefHandler; 101 }; 102 103 #endif // PREF_HANDLER_H 104