HaikuDepot: Store the screenshot info...

... from the bulk request results in each PackageInfo.
This commit is contained in:
Stephan Aßmus
2014-09-05 23:12:46 +02:00
parent 72b52fdf92
commit 1d9d48738e
3 changed files with 142 additions and 0 deletions
+31
View File
@@ -910,6 +910,7 @@ Model::_PopulatePackageInfo(const PackageInfoRef& package, const BMessage& data)
if (foundCategory)
append_word_list(foundInfo, "categories");
}
double derivedRating;
double derivedRatingSampleSize;
if (data.FindDouble("derivedRating", &derivedRating) == B_OK
@@ -924,6 +925,36 @@ Model::_PopulatePackageInfo(const PackageInfoRef& package, const BMessage& data)
append_word_list(foundInfo, "rating");
}
}
BMessage screenshots;
if (data.FindMessage("pkgScreenshots", &screenshots) == B_OK) {
bool foundScreenshot = false;
int32 index = 0;
while (true) {
BString name;
name << index++;
BMessage screenshot;
if (screenshots.FindMessage(name, &screenshot) != B_OK)
break;
BString code;
double width;
double height;
double dataSize;
if (screenshot.FindString("code", &code) == B_OK
&& screenshot.FindDouble("width", &width) == B_OK
&& screenshot.FindDouble("height", &height) == B_OK
&& screenshot.FindDouble("length", &dataSize) == B_OK) {
package->AddScreenshotInfo(ScreenshotInfo(code, (int32)width,
(int32)height, (int32)dataSize));
foundScreenshot = true;
}
}
if (foundScreenshot)
append_word_list(foundInfo, "screenshots");
}
if (foundInfo.Length() > 0) {
printf("Populated package info for %s: %s\n",
package->Title().String(), foundInfo.String());
+74
View File
@@ -551,6 +551,68 @@ PackageCategory::operator!=(const PackageCategory& other) const
}
// #pragma mark - ScreenshotInfo
ScreenshotInfo::ScreenshotInfo()
:
fCode(),
fWidth(),
fHeight(),
fDataSize()
{
}
ScreenshotInfo::ScreenshotInfo(const BString& code,
int32 width, int32 height, int32 dataSize)
:
fCode(code),
fWidth(width),
fHeight(height),
fDataSize(dataSize)
{
}
ScreenshotInfo::ScreenshotInfo(const ScreenshotInfo& other)
:
fCode(other.fCode),
fWidth(other.fWidth),
fHeight(other.fHeight),
fDataSize(other.fDataSize)
{
}
ScreenshotInfo&
ScreenshotInfo::operator=(const ScreenshotInfo& other)
{
fCode = other.fCode;
fWidth = other.fWidth;
fHeight = other.fHeight;
fDataSize = other.fDataSize;
return *this;
}
bool
ScreenshotInfo::operator==(const ScreenshotInfo& other) const
{
return fCode == other.fCode
&& fWidth == other.fWidth
&& fHeight == other.fHeight
&& fDataSize == other.fDataSize;
}
bool
ScreenshotInfo::operator!=(const ScreenshotInfo& other) const
{
return !(*this == other);
}
// #pragma mark - PackageInfo
@@ -565,6 +627,7 @@ PackageInfo::PackageInfo()
fChangelog(),
fUserRatings(),
fCachedRatingSummary(),
fScreenshotInfos(),
fScreenshots(),
fState(NONE),
fDownloadProgress(0.0),
@@ -590,6 +653,7 @@ PackageInfo::PackageInfo(const BString& title,
fCategories(),
fUserRatings(),
fCachedRatingSummary(),
fScreenshotInfos(),
fScreenshots(),
fState(NONE),
fDownloadProgress(0.0),
@@ -612,6 +676,7 @@ PackageInfo::PackageInfo(const PackageInfo& other)
fCategories(other.fCategories),
fUserRatings(other.fUserRatings),
fCachedRatingSummary(other.fCachedRatingSummary),
fScreenshotInfos(other.fScreenshotInfos),
fScreenshots(other.fScreenshots),
fState(other.fState),
fInstallationLocations(other.fInstallationLocations),
@@ -636,6 +701,7 @@ PackageInfo::operator=(const PackageInfo& other)
fCategories = other.fCategories;
fUserRatings = other.fUserRatings;
fCachedRatingSummary = other.fCachedRatingSummary;
fScreenshotInfos = other.fScreenshotInfos;
fScreenshots = other.fScreenshots;
fState = other.fState;
fInstallationLocations = other.fInstallationLocations;
@@ -660,6 +726,7 @@ PackageInfo::operator==(const PackageInfo& other) const
&& fCategories == other.fCategories
&& fUserRatings == other.fUserRatings
&& fCachedRatingSummary == other.fCachedRatingSummary
&& fScreenshotInfos == other.fScreenshotInfos
&& fScreenshots == other.fScreenshots
&& fState == other.fState
&& fFlags == other.fFlags
@@ -840,6 +907,13 @@ PackageInfo::CalculateRatingSummary() const
}
bool
PackageInfo::AddScreenshotInfo(const ScreenshotInfo& info)
{
return fScreenshotInfos.Add(info);
}
bool
PackageInfo::AddScreenshot(const BitmapRef& screenshot)
{
+37
View File
@@ -202,9 +202,41 @@ typedef BReference<PackageCategory> CategoryRef;
typedef List<CategoryRef, false> CategoryList;
class ScreenshotInfo {
public:
ScreenshotInfo();
ScreenshotInfo(const BString& code,
int32 width, int32 height, int32 dataSize);
ScreenshotInfo(const ScreenshotInfo& other);
ScreenshotInfo& operator=(const ScreenshotInfo& other);
bool operator==(const ScreenshotInfo& other) const;
bool operator!=(const ScreenshotInfo& other) const;
const BString& Code() const
{ return fCode; }
int32 Width() const
{ return fWidth; }
int32 Height() const
{ return fHeight; }
int32 DataSize() const
{ return fDataSize; }
private:
BString fCode;
int32 fWidth;
int32 fHeight;
int32 fDataSize;
};
typedef List<ScreenshotInfo, false, 2> ScreenshotInfoList;
typedef List<PackageInfoListenerRef, false, 2> PackageListenerList;
typedef std::set<int32> PackageInstallationLocationSet;
enum PackageState {
NONE = 0,
INSTALLED = 1,
@@ -286,6 +318,10 @@ public:
void SetRatingSummary(const RatingSummary& summary);
RatingSummary CalculateRatingSummary() const;
bool AddScreenshotInfo(const ScreenshotInfo& info);
const ScreenshotInfoList& ScreenshotInfos() const
{ return fScreenshotInfos; }
bool AddScreenshot(const BitmapRef& screenshot);
const BitmapList& Screenshots() const
{ return fScreenshots; }
@@ -309,6 +345,7 @@ private:
CategoryList fCategories;
UserRatingList fUserRatings;
RatingSummary fCachedRatingSummary;
ScreenshotInfoList fScreenshotInfos;
BitmapList fScreenshots;
PackageState fState;
PackageInstallationLocationSet