diff --git a/headers/os/package/RepositoryInfo.h b/headers/os/package/RepositoryInfo.h index db59d0f8bc..f84a815ff4 100644 --- a/headers/os/package/RepositoryInfo.h +++ b/headers/os/package/RepositoryInfo.h @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -37,6 +38,8 @@ public: const BString& Summary() const; uint8 Priority() const; BPackageArchitecture Architecture() const; + const BObjectList& LicenseNames() const; + const BObjectList& 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 fLicenseNames; + BObjectList fLicenseTexts; }; diff --git a/src/kits/package/RepositoryInfo.cpp b/src/kits/package/RepositoryInfo.cpp index cbb2bf896d..4cafbafb04 100644 --- a/src/kits/package/RepositoryInfo.cpp +++ b/src/kits/package/RepositoryInfo.cpp @@ -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& +BRepositoryInfo::LicenseNames() const +{ + return fLicenseNames; +} + + +const BObjectList& +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