2 * Copyright 2017 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
10 #include "RepositoriesSettings.h"
12 #include <FindDirectory.h>
13 #include <StringList.h>
15 #include "constants.h"
17 const char* settingsFilename
= "Repositories_settings";
20 RepositoriesSettings::RepositoriesSettings()
22 status_t status
= find_directory(B_USER_SETTINGS_DIRECTORY
, &fFilePath
);
24 status
= fFilePath
.Append(settingsFilename
);
30 RepositoriesSettings::GetFrame()
32 BMessage
settings(_ReadFromFile());
34 status_t status
= settings
.FindRect(key_frame
, &frame
);
35 // Set default off screen so it will center itself
37 frame
.Set(-10, -10, 750, 300);
43 RepositoriesSettings::SetFrame(BRect frame
)
45 BMessage
settings(_ReadFromFile());
46 settings
.RemoveData(key_frame
);
47 settings
.AddRect(key_frame
, frame
);
48 _SaveToFile(settings
);
53 RepositoriesSettings::GetRepositories(int32
& repoCount
, BStringList
& nameList
,
56 BMessage
settings(_ReadFromFile());
59 settings
.GetInfo(key_name
, &type
, &count
);
61 status_t result
= B_OK
;
62 int32 index
, total
= 0;
63 BString foundName
, foundUrl
;
64 // get each repository and add to lists
65 for (index
= 0; index
< count
; index
++) {
66 status_t result1
= settings
.FindString(key_name
, index
, &foundName
);
67 status_t result2
= settings
.FindString(key_url
, index
, &foundUrl
);
68 if (result1
== B_OK
&& result2
== B_OK
) {
69 nameList
.Add(foundName
);
70 urlList
.Add(foundUrl
);
81 RepositoriesSettings::SetRepositories(BStringList
& nameList
, BStringList
& urlList
)
83 BMessage
settings(_ReadFromFile());
84 settings
.RemoveName(key_name
);
85 settings
.RemoveName(key_url
);
87 int32 index
, count
= nameList
.CountStrings();
88 for (index
= 0; index
< count
; index
++) {
89 settings
.AddString(key_name
, nameList
.StringAt(index
));
90 settings
.AddString(key_url
, urlList
.StringAt(index
));
92 _SaveToFile(settings
);
97 RepositoriesSettings::_ReadFromFile()
100 status_t status
= fFile
.SetTo(fFilePath
.Path(), B_READ_ONLY
);
102 status
= settings
.Unflatten(&fFile
);
109 RepositoriesSettings::_SaveToFile(BMessage settings
)
111 status_t status
= fFile
.SetTo(fFilePath
.Path(),
112 B_WRITE_ONLY
| B_CREATE_FILE
| B_ERASE_FILE
);
114 status
= settings
.Flatten(&fFile
);