Skip to content

Commit

Permalink
HaikuDepot: Store the screenshot info...
Browse files Browse the repository at this point in the history
... from the bulk request results in each PackageInfo.
  • Loading branch information
stippi committed Sep 5, 2014
1 parent 72b52fd commit 1d9d487
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/apps/haikudepot/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
Expand Down
74 changes: 74 additions & 0 deletions src/apps/haikudepot/PackageInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -565,6 +627,7 @@ PackageInfo::PackageInfo()
fChangelog(),
fUserRatings(),
fCachedRatingSummary(),
fScreenshotInfos(),
fScreenshots(),
fState(NONE),
fDownloadProgress(0.0),
Expand All @@ -590,6 +653,7 @@ PackageInfo::PackageInfo(const BString& title,
fCategories(),
fUserRatings(),
fCachedRatingSummary(),
fScreenshotInfos(),
fScreenshots(),
fState(NONE),
fDownloadProgress(0.0),
Expand All @@ -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),
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -840,6 +907,13 @@ PackageInfo::CalculateRatingSummary() const
}


bool
PackageInfo::AddScreenshotInfo(const ScreenshotInfo& info)
{
return fScreenshotInfos.Add(info);
}


bool
PackageInfo::AddScreenshot(const BitmapRef& screenshot)
{
Expand Down
37 changes: 37 additions & 0 deletions src/apps/haikudepot/PackageInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -286,6 +318,10 @@ class PackageInfo : public BReferenceable {
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; }
Expand All @@ -309,6 +345,7 @@ class PackageInfo : public BReferenceable {
CategoryList fCategories;
UserRatingList fUserRatings;
RatingSummary fCachedRatingSummary;
ScreenshotInfoList fScreenshotInfos;
BitmapList fScreenshots;
PackageState fState;
PackageInstallationLocationSet
Expand Down

0 comments on commit 1d9d487

Please sign in to comment.