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