1c56079fbSMatthew Wilber /*****************************************************************************/ 2c56079fbSMatthew Wilber // TranslatorSettings 319e5578eSDarkWyrm // Written by Michael Wilber, Haiku Translation Kit Team 4c56079fbSMatthew Wilber // 5c56079fbSMatthew Wilber // TranslatorSettings.h 6c56079fbSMatthew Wilber // 7c56079fbSMatthew Wilber // This class manages (saves/loads/locks/unlocks) the settings 8c56079fbSMatthew Wilber // for a Translator. 9c56079fbSMatthew Wilber // 10c56079fbSMatthew Wilber // 1119e5578eSDarkWyrm // Copyright (c) 2004 Haiku, Inc. 12c56079fbSMatthew Wilber // 13c56079fbSMatthew Wilber // Permission is hereby granted, free of charge, to any person obtaining a 14c56079fbSMatthew Wilber // copy of this software and associated documentation files (the "Software"), 15c56079fbSMatthew Wilber // to deal in the Software without restriction, including without limitation 16c56079fbSMatthew Wilber // the rights to use, copy, modify, merge, publish, distribute, sublicense, 17c56079fbSMatthew Wilber // and/or sell copies of the Software, and to permit persons to whom the 18c56079fbSMatthew Wilber // Software is furnished to do so, subject to the following conditions: 19c56079fbSMatthew Wilber // 20c56079fbSMatthew Wilber // The above copyright notice and this permission notice shall be included 21c56079fbSMatthew Wilber // in all copies or substantial portions of the Software. 22c56079fbSMatthew Wilber // 23c56079fbSMatthew Wilber // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24c56079fbSMatthew Wilber // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25c56079fbSMatthew Wilber // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26c56079fbSMatthew Wilber // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27c56079fbSMatthew Wilber // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28c56079fbSMatthew Wilber // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 29c56079fbSMatthew Wilber // DEALINGS IN THE SOFTWARE. 30c56079fbSMatthew Wilber /*****************************************************************************/ 31c56079fbSMatthew Wilber 32c56079fbSMatthew Wilber #ifndef TRANSLATOR_SETTINGS_H 33c56079fbSMatthew Wilber #define TRANSLATOR_SETTINGS_H 34c56079fbSMatthew Wilber 35c56079fbSMatthew Wilber #include <Locker.h> 36c56079fbSMatthew Wilber #include <Path.h> 37c56079fbSMatthew Wilber #include <Message.h> 38c56079fbSMatthew Wilber 39c56079fbSMatthew Wilber enum TranSettingType { 40c56079fbSMatthew Wilber TRAN_SETTING_INT32 = 0, 41c56079fbSMatthew Wilber TRAN_SETTING_BOOL 42c56079fbSMatthew Wilber }; 43c56079fbSMatthew Wilber 44c56079fbSMatthew Wilber struct TranSetting { 45c56079fbSMatthew Wilber const char *name; 46c56079fbSMatthew Wilber TranSettingType dataType; 47c56079fbSMatthew Wilber int32 defaultVal; 48c56079fbSMatthew Wilber }; 49c56079fbSMatthew Wilber 50c56079fbSMatthew Wilber class TranslatorSettings { 51c56079fbSMatthew Wilber public: 52*bf243977SPhilippe Houdoin TranslatorSettings(const char *settingsFile, const TranSetting *defaults, 53c56079fbSMatthew Wilber int32 defCount); 54c56079fbSMatthew Wilber 55c56079fbSMatthew Wilber TranslatorSettings *Acquire(); 56c56079fbSMatthew Wilber // increments the reference count, returns this 57c56079fbSMatthew Wilber TranslatorSettings *Release(); 58c56079fbSMatthew Wilber // decrements the reference count, deletes this 59c56079fbSMatthew Wilber // when count reaches zero, returns this when 60c56079fbSMatthew Wilber // ref count is greater than zero, NULL when 61c56079fbSMatthew Wilber // ref count is zero 62c56079fbSMatthew Wilber 63c56079fbSMatthew Wilber status_t LoadSettings(); 64c56079fbSMatthew Wilber status_t LoadSettings(BMessage *pmsg); 65c56079fbSMatthew Wilber status_t SaveSettings(); 66c56079fbSMatthew Wilber status_t GetConfigurationMessage(BMessage *pmsg); 67c56079fbSMatthew Wilber 68c56079fbSMatthew Wilber bool SetGetBool(const char *name, bool *pbool = NULL); 69c56079fbSMatthew Wilber int32 SetGetInt32(const char *name, int32 *pint32 = NULL); 70c56079fbSMatthew Wilber 71c56079fbSMatthew Wilber private: 72c56079fbSMatthew Wilber const TranSetting *FindTranSetting(const char *name); 73c56079fbSMatthew Wilber ~TranslatorSettings(); 74c56079fbSMatthew Wilber // private so that Release() must be used 75c56079fbSMatthew Wilber // to delete the object 76c56079fbSMatthew Wilber 77c56079fbSMatthew Wilber BLocker fLock; 78c56079fbSMatthew Wilber int32 fRefCount; 79c56079fbSMatthew Wilber BPath fSettingsPath; 80c56079fbSMatthew Wilber // where the settings file will be loaded from / 81c56079fbSMatthew Wilber // saved to 82c56079fbSMatthew Wilber 83c56079fbSMatthew Wilber BMessage fSettingsMsg; 84c56079fbSMatthew Wilber // the actual settings 85c56079fbSMatthew Wilber 86c56079fbSMatthew Wilber const TranSetting *fDefaults; 87c56079fbSMatthew Wilber int32 fDefCount; 88c56079fbSMatthew Wilber }; 89c56079fbSMatthew Wilber 90c56079fbSMatthew Wilber #endif // #ifndef TRANSLATOR_SETTTINGS_H 91c56079fbSMatthew Wilber 92