1*fe8567ecSFrançois Revol #include "settings.h" 2*fe8567ecSFrançois Revol #include <iostream.h> 3*fe8567ecSFrançois Revol 4*fe8567ecSFrançois Revol #define CONF_ADDPROP(_type, _name) \ 5*fe8567ecSFrançois Revol void AutoRaiseSettings::Set##_name(_type value)\ 6*fe8567ecSFrançois Revol {\ 7*fe8567ecSFrançois Revol _conf##_name = value;\ 8*fe8567ecSFrançois Revol }\ 9*fe8567ecSFrançois Revol \ 10*fe8567ecSFrançois Revol _type AutoRaiseSettings::##_name()\ 11*fe8567ecSFrançois Revol {\ 12*fe8567ecSFrançois Revol return _conf##_name;\ 13*fe8567ecSFrançois Revol }\ 14*fe8567ecSFrançois Revol 15*fe8567ecSFrançois Revol 16*fe8567ecSFrançois Revol CONF_ADDPROP(bool, Active) 17*fe8567ecSFrançois Revol CONF_ADDPROP(bigtime_t, Delay) 18*fe8567ecSFrançois Revol CONF_ADDPROP(int32, Mode) 19*fe8567ecSFrançois Revol //CONF_ADDPROP(BPath, AppPath) 20*fe8567ecSFrançois Revol CONF_ADDPROP(entry_ref, AppPath) 21*fe8567ecSFrançois Revol #undef CONF_ADDPROP 22*fe8567ecSFrançois Revol 23*fe8567ecSFrançois Revol AutoRaiseSettings::AutoRaiseSettings() 24*fe8567ecSFrançois Revol { 25*fe8567ecSFrançois Revol _confActive = false; 26*fe8567ecSFrançois Revol _confDelay = DEFAULT_DELAY; 27*fe8567ecSFrançois Revol _confMode = Mode_All; 28*fe8567ecSFrançois Revol BPath prefPath; 29*fe8567ecSFrançois Revol 30*fe8567ecSFrançois Revol find_directory(B_USER_SETTINGS_DIRECTORY, &prefPath); 31*fe8567ecSFrançois Revol prefPath.Append(SETTINGS_FILE); 32*fe8567ecSFrançois Revol 33*fe8567ecSFrançois Revol _settingsFile.SetTo(prefPath.Path(), B_READ_WRITE | B_CREATE_FILE); 34*fe8567ecSFrançois Revol 35*fe8567ecSFrançois Revol if (_settingsMessage.Unflatten(&_settingsFile) == B_OK){ 36*fe8567ecSFrançois Revol 37*fe8567ecSFrançois Revol if (_settingsMessage.FindBool(AR_ACTIVE, &_confActive) != B_OK) 38*fe8567ecSFrançois Revol printf("AutoRaiseSettings::AutoRaiseSettings();\tFailed to load active boolean from settings file. Using default\n"); 39*fe8567ecSFrançois Revol 40*fe8567ecSFrançois Revol if (_settingsMessage.FindInt64(AR_DELAY, &_confDelay) != B_OK) 41*fe8567ecSFrançois Revol printf("AutoRaiseSettings::AutoRaiseSettings();\tFailed to load delay from settings file. Using default\n"); 42*fe8567ecSFrançois Revol 43*fe8567ecSFrançois Revol if (_settingsMessage.FindInt32(AR_MODE, &_confMode) != B_OK) 44*fe8567ecSFrançois Revol printf("AutoRaiseSettings::AutoRaiseSettings();\tFailed to load mode from settings file. Using default\n"); 45*fe8567ecSFrançois Revol 46*fe8567ecSFrançois Revol // if (_settingsMessage.FindFlat(AR_APP_PATH, (BFlattenable *) &_appPath) != B_OK) 47*fe8567ecSFrançois Revol // printf("AutoRaiseSettings::AutoRaiseSettings();\tFailed to load application path.\n"); 48*fe8567ecSFrançois Revol 49*fe8567ecSFrançois Revol if (_settingsMessage.FindRef(AR_APP_PATH, &_confAppPath) != B_OK) 50*fe8567ecSFrançois Revol printf("AutoRaiseSettings::AutoRaiseSettings();\tFailed to load application path.\n"); 51*fe8567ecSFrançois Revol } 52*fe8567ecSFrançois Revol else 53*fe8567ecSFrançois Revol { 54*fe8567ecSFrançois Revol printf("AutoRaiseSettings::AutoRaiseSettings()\nUnable to open settings file (either corrupted or doesn't exist), using defaults.\n"); 55*fe8567ecSFrançois Revol } 56*fe8567ecSFrançois Revol 57*fe8567ecSFrançois Revol _settingsFile.Unset(); 58*fe8567ecSFrançois Revol } 59*fe8567ecSFrançois Revol 60*fe8567ecSFrançois Revol AutoRaiseSettings::~AutoRaiseSettings() 61*fe8567ecSFrançois Revol { 62*fe8567ecSFrançois Revol BPath prefPath; 63*fe8567ecSFrançois Revol find_directory(B_USER_SETTINGS_DIRECTORY, &prefPath); 64*fe8567ecSFrançois Revol prefPath.Append(SETTINGS_FILE); 65*fe8567ecSFrançois Revol 66*fe8567ecSFrançois Revol //clobber existing settings and write in new ones 67*fe8567ecSFrançois Revol _settingsFile.SetTo(prefPath.Path(), B_READ_WRITE | B_ERASE_FILE); 68*fe8567ecSFrançois Revol 69*fe8567ecSFrançois Revol 70*fe8567ecSFrançois Revol //empty message and refill it with whatever has been set 71*fe8567ecSFrançois Revol _settingsMessage.MakeEmpty(); 72*fe8567ecSFrançois Revol 73*fe8567ecSFrançois Revol _settingsMessage.AddBool(AR_ACTIVE, _confActive); 74*fe8567ecSFrançois Revol _settingsMessage.AddInt64(AR_DELAY, _confDelay); 75*fe8567ecSFrançois Revol _settingsMessage.AddInt32(AR_MODE, _confMode); 76*fe8567ecSFrançois Revol // _settingsMessage.AddFlat(AR_APP_PATH, &_appPath); 77*fe8567ecSFrançois Revol _settingsMessage.AddRef(AR_APP_PATH, &_confAppPath); 78*fe8567ecSFrançois Revol 79*fe8567ecSFrançois Revol //write message to settings file 80*fe8567ecSFrançois Revol if (_settingsMessage.Flatten(&_settingsFile) != B_OK) 81*fe8567ecSFrançois Revol printf("Error occurred writing settings\n"); 82*fe8567ecSFrançois Revol 83*fe8567ecSFrançois Revol _settingsFile.Unset(); 84*fe8567ecSFrançois Revol } 85*fe8567ecSFrançois Revol 86