1 /* 2 * Copyright 2008-2010 Stephan Aßmus <superstippi@gmx.de>. 3 * Copyright 1998 Eric Shepherd. 4 * All rights reserved. Distributed under the terms of the Be Sample Code 5 * license. 6 */ 7 #ifndef SETTINGS_MESSAGE_H 8 #define SETTINGS_MESSAGE_H 9 10 11 #include <FindDirectory.h> 12 #include <Font.h> 13 #include <List.h> 14 #include <Locker.h> 15 #include <Message.h> 16 #include <Path.h> 17 18 class BMessenger; 19 class BString; 20 21 22 enum { 23 SETTINGS_VALUE_CHANGED = '_svc' 24 }; 25 26 27 class SettingsMessage : public BMessage, public BLocker { 28 public: 29 SettingsMessage(directory_which directory, 30 const char* filename); 31 virtual ~SettingsMessage(); 32 33 34 status_t InitCheck() const; 35 status_t Load(); 36 status_t Save() const; 37 38 bool AddListener(const BMessenger& listener); 39 void RemoveListener(const BMessenger& listener); 40 41 status_t SetValue(const char* name, bool value); 42 status_t SetValue(const char* name, int8 value); 43 status_t SetValue(const char* name, int16 value); 44 status_t SetValue(const char* name, uint16 value); 45 status_t SetValue(const char* name, int32 value); 46 status_t SetValue(const char* name, uint32 value); 47 status_t SetValue(const char* name, int64 value); 48 status_t SetValue(const char* name, uint64 value); 49 status_t SetValue(const char* name, float value); 50 status_t SetValue(const char* name, double value); 51 status_t SetValue(const char* name, 52 const char* value); 53 status_t SetValue(const char* name, 54 const BString& value); 55 status_t SetValue(const char *name, 56 const BPoint& value); 57 status_t SetValue(const char* name, const BRect& value); 58 status_t SetValue(const char* name, 59 const entry_ref& value); 60 status_t SetValue(const char* name, 61 const BMessage& value); 62 status_t SetValue(const char* name, 63 const BFlattenable* value); 64 status_t SetValue(const char* name, 65 const BFont& value); 66 status_t SetValue(const char* name, type_code type, 67 const void* data, ssize_t numBytes); 68 69 bool GetValue(const char* name, 70 bool defaultValue) const; 71 int8 GetValue(const char* name, 72 int8 defaultValue) const; 73 int16 GetValue(const char* name, 74 int16 defaultValue) const; 75 uint16 GetValue(const char* name, 76 uint16 defaultValue) const; 77 int32 GetValue(const char* name, 78 int32 defaultValue) const; 79 uint32 GetValue(const char* name, 80 uint32 defaultValue) const; 81 int64 GetValue(const char* name, 82 int64 defaultValue) const; 83 uint64 GetValue(const char* name, 84 uint64 defaultValue) const; 85 float GetValue(const char* name, 86 float defaultValue) const; 87 double GetValue(const char* name, 88 double defaultValue) const; 89 const char* GetValue(const char* name, 90 const char* defaultValue) const; 91 BString GetValue(const char* name, 92 const BString& defaultValue) const; 93 BPoint GetValue(const char *name, 94 BPoint defaultValue) const; 95 BRect GetValue(const char* name, 96 BRect defaultValue) const; 97 entry_ref GetValue(const char* name, 98 const entry_ref& defaultValue) const; 99 BMessage GetValue(const char* name, 100 const BMessage& defaultValue) const; 101 BFont GetValue(const char* name, 102 const BFont& defaultValue) const; 103 void* GetValue(const char* name, type_code type, 104 ssize_t numBytes, 105 const void** defaultValue)const; 106 107 private: 108 void _NotifyValueChanged(const char* name) const; 109 110 private: 111 BPath fPath; 112 status_t fStatus; 113 BList fListeners; 114 }; 115 116 #endif // SETTINGS_MESSAGE_H 117