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 struct pref_defaults { 22 const char *key; 23 const char *item; 24 }; 25 26 #define PREF_TRUE "true" 27 #define PREF_FALSE "false" 28 29 class BMessage; 30 class BEntry; 31 32 class PrefHandler { 33 public: 34 PrefHandler(const PrefHandler* p); 35 PrefHandler(); 36 ~PrefHandler(); 37 38 static PrefHandler *Default(); 39 static void DeleteDefault(); 40 static void SetDefault(PrefHandler *handler); 41 42 status_t OpenText(const char *path); 43 void SaveDefaultAsText(); 44 void SaveAsText(const char *path, const char *minmtype = NULL, 45 const char *signature = NULL); 46 47 int32 getInt32(const char *key); 48 float getFloat(const char *key); 49 const char* getString(const char *key); 50 bool getBool(const char *key); 51 rgb_color getRGB(const char *key); 52 53 void setInt32(const char *key, int32 data); 54 void setFloat(const char *key, float data); 55 void setString(const char *key, const char *data); 56 void setBool(const char *key, bool data); 57 void setRGB(const char *key, const rgb_color data); 58 59 bool IsEmpty() const; 60 61 static status_t GetDefaultPath(BPath& path); 62 63 private: 64 void _ConfirmFont(const char *key, const BFont *fallback); 65 status_t _LoadFromDefault(const pref_defaults* defaults = NULL); 66 status_t _LoadFromTextFile(const char * path); 67 68 BMessage fContainer; 69 70 static PrefHandler *sPrefHandler; 71 }; 72 73 #endif // PREF_HANDLER_H 74