2 * Copyright 2003-2011 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Michael Pfeiffer, laplace@haiku-os.org
10 #include "ShowImageSettings.h"
13 #include <FindDirectory.h>
17 ShowImageSettings::ShowImageSettings()
19 fLock("settings lock"),
26 ShowImageSettings::~ShowImageSettings()
38 ShowImageSettings::Lock()
45 ShowImageSettings::Unlock()
52 ShowImageSettings::GetBool(const char* name
, bool defaultValue
)
55 if (fSettings
.FindBool(name
, &value
) == B_OK
)
63 ShowImageSettings::GetInt32(const char* name
, int32 defaultValue
)
66 if (fSettings
.FindInt32(name
, &value
) == B_OK
)
74 ShowImageSettings::GetFloat(const char* name
, float defaultValue
)
77 if (fSettings
.FindFloat(name
, &value
) == B_OK
)
85 ShowImageSettings::GetRect(const char* name
, BRect defaultValue
)
88 if (fSettings
.FindRect(name
, &value
) == B_OK
)
96 ShowImageSettings::GetTime(const char* name
, bigtime_t defaultValue
)
99 if (fSettings
.FindInt64(name
, &value
) == B_OK
)
107 ShowImageSettings::GetString(const char* name
, const char* defaultValue
)
110 if (fSettings
.FindString(name
, &value
) == B_OK
)
118 ShowImageSettings::SetBool(const char* name
, bool value
)
120 if (fSettings
.HasBool(name
))
121 fSettings
.ReplaceBool(name
, value
);
123 fSettings
.AddBool(name
, value
);
130 ShowImageSettings::SetInt32(const char* name
, int32 value
)
132 if (fSettings
.HasInt32(name
))
133 fSettings
.ReplaceInt32(name
, value
);
135 fSettings
.AddInt32(name
, value
);
142 ShowImageSettings::SetFloat(const char* name
, float value
)
144 if (fSettings
.HasFloat(name
))
145 fSettings
.ReplaceFloat(name
, value
);
147 fSettings
.AddFloat(name
, value
);
154 ShowImageSettings::SetRect(const char* name
, BRect value
)
156 if (fSettings
.HasRect(name
))
157 fSettings
.ReplaceRect(name
, value
);
159 fSettings
.AddRect(name
, value
);
166 ShowImageSettings::SetTime(const char* name
, bigtime_t value
)
168 if (fSettings
.ReplaceInt64(name
, value
) != B_OK
)
169 fSettings
.AddInt64(name
, value
);
176 ShowImageSettings::SetString(const char* name
, const char* value
)
178 if (fSettings
.HasString(name
))
179 fSettings
.ReplaceString(name
, value
);
181 fSettings
.AddString(name
, value
);
188 ShowImageSettings::_OpenSettingsFile(BFile
* file
, bool forReading
)
191 status_t status
= find_directory(B_USER_SETTINGS_DIRECTORY
, &path
);
195 path
.Append("ShowImage_settings");
197 return file
->SetTo(path
.Path(), forReading
198 ? B_READ_ONLY
: B_WRITE_ONLY
| B_CREATE_FILE
| B_ERASE_FILE
) == B_OK
;
203 ShowImageSettings::_Load()
206 if (_OpenSettingsFile(&file
, true))
207 fSettings
.Unflatten(&file
);
212 ShowImageSettings::_Save()
215 if (_OpenSettingsFile(&file
, false))
216 fSettings
.Flatten(&file
);