* add support to storing names and texts of licenses that require

approval to repository-info

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40427 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe 2011-02-10 19:07:21 +00:00
parent 4dcc52327b
commit 84d9977244
2 changed files with 77 additions and 1 deletions

View File

@ -8,6 +8,7 @@
#include <Archivable.h>
#include <Entry.h>
#include <ObjectList.h>
#include <String.h>
#include <package/PackageArchitecture.h>
@ -37,6 +38,8 @@ public:
const BString& Summary() const;
uint8 Priority() const;
BPackageArchitecture Architecture() const;
const BObjectList<BString>& LicenseNames() const;
const BObjectList<BString>& LicenseTexts() const;
void SetName(const BString& name);
void SetOriginalBaseURL(const BString& url);
@ -45,6 +48,10 @@ public:
void SetPriority(uint8 priority);
void SetArchitecture(BPackageArchitecture arch);
status_t AddLicense(const BString& licenseName,
const BString& licenseText);
void ClearLicenses();
public:
static BRepositoryInfo* Instantiate(BMessage* data);
@ -56,6 +63,8 @@ public:
static const char* kSummaryField;
static const char* kPriorityField;
static const char* kArchitectureField;
static const char* kLicenseNameField;
static const char* kLicenseTextField;
private:
status_t fInitStatus;
@ -66,6 +75,8 @@ private:
BString fSummary;
uint8 fPriority;
BPackageArchitecture fArchitecture;
BObjectList<BString> fLicenseNames;
BObjectList<BString> fLicenseTexts;
};

View File

@ -30,6 +30,8 @@ const char* BRepositoryInfo::kVendorField = "vendor";
const char* BRepositoryInfo::kSummaryField = "summary";
const char* BRepositoryInfo::kPriorityField = "priority";
const char* BRepositoryInfo::kArchitectureField = "architecture";
const char* BRepositoryInfo::kLicenseNameField = "licenseName";
const char* BRepositoryInfo::kLicenseTextField = "licenseText";
BRepositoryInfo::BRepositoryInfo()
@ -43,7 +45,8 @@ BRepositoryInfo::BRepositoryInfo()
BRepositoryInfo::BRepositoryInfo(BMessage* data)
:
inherited(data)
inherited(data),
fLicenseTexts(5, true)
{
fInitStatus = SetTo(data);
}
@ -90,6 +93,16 @@ BRepositoryInfo::Archive(BMessage* data, bool deep) const
return result;
if ((result = data->AddUInt8(kArchitectureField, fArchitecture)) != B_OK)
return result;
for (int i = 0; i < fLicenseNames.CountItems(); ++i) {
result = data->AddString(kLicenseNameField, *fLicenseNames.ItemAt(i));
if (result != B_OK)
return result;
}
for (int i = 0; i < fLicenseTexts.CountItems(); ++i) {
result = data->AddString(kLicenseTextField, *fLicenseTexts.ItemAt(i));
if (result != B_OK)
return result;
}
return B_OK;
}
@ -124,6 +137,20 @@ BRepositoryInfo::SetTo(const BMessage* data)
if (result != B_OK)
return result;
const char* licenseName;
const char* licenseText;
for (int i = 0;
data->FindString(kLicenseNameField, i, &licenseName) == B_OK
&& data->FindString(kLicenseTextField, i, &licenseText) == B_OK;
++i) {
BString* newLicenseName = new (std::nothrow) BString(licenseName);
if (newLicenseName == NULL || !fLicenseNames.AddItem(newLicenseName))
return B_NO_MEMORY;
BString* newLicenseText = new (std::nothrow) BString(licenseText);
if (newLicenseText == NULL || !fLicenseTexts.AddItem(newLicenseText))
return B_NO_MEMORY;
}
return B_OK;
}
@ -239,6 +266,20 @@ BRepositoryInfo::Architecture() const
}
const BObjectList<BString>&
BRepositoryInfo::LicenseNames() const
{
return fLicenseNames;
}
const BObjectList<BString>&
BRepositoryInfo::LicenseTexts() const
{
return fLicenseTexts;
}
void
BRepositoryInfo::SetName(const BString& name)
{
@ -281,4 +322,28 @@ BRepositoryInfo::SetArchitecture(BPackageArchitecture architecture)
}
status_t
BRepositoryInfo::AddLicense(const BString& licenseName,
const BString& licenseText)
{
BString* newLicenseName = new (std::nothrow) BString(licenseName);
if (newLicenseName == NULL || !fLicenseNames.AddItem(newLicenseName))
return B_NO_MEMORY;
BString* newLicenseText = new (std::nothrow) BString(licenseText);
if (newLicenseText == NULL || !fLicenseTexts.AddItem(newLicenseText))
return B_NO_MEMORY;
return B_OK;
}
void
BRepositoryInfo::ClearLicenses()
{
fLicenseNames.MakeEmpty();
fLicenseTexts.MakeEmpty();
}
} // namespace BPackageKit