Skip to content

Commit

Permalink
HaikuDepot: Added the notion of package categories
Browse files Browse the repository at this point in the history
 * Defined PackageCategory class (icon, label and internal name)
 * Each PackageInfo has a list of PackageCategories
 * Model defines global PackageCategories, referenced by PackageInfos
 * Added Model.cpp to files needing translation
 * Added categories to dummy package infos
  • Loading branch information
stippi committed Aug 10, 2013
1 parent 3785b9b commit f75ec10
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/apps/haiku-depot/Jamfile
Expand Up @@ -24,6 +24,7 @@ DoCatalogs HaikuDepot :
App.cpp
FilterView.cpp
MainWindow.cpp
Model.cpp
PackageInfoView.cpp
PackageListView.cpp
PackageManager.cpp
Expand Down
4 changes: 4 additions & 0 deletions src/apps/haiku-depot/MainWindow.cpp
Expand Up @@ -175,6 +175,8 @@ MainWindow::_InitDummyModel()
);
wonderbrush.AddScreenshot(
BitmapRef(new SharedBitmap(603), true));
wonderbrush.AddCategory(fModel.CategoryGraphics());
wonderbrush.AddCategory(fModel.CategoryProductivity());

depot.AddPackage(wonderbrush);

Expand Down Expand Up @@ -210,6 +212,8 @@ MainWindow::_InitDummyModel()
);
paladin.AddScreenshot(
BitmapRef(new SharedBitmap(604), true));
paladin.AddCategory(fModel.CategoryDevelopment());

depot.AddPackage(paladin);

fModel.AddDepot(depot);
Expand Down
27 changes: 26 additions & 1 deletion src/apps/haiku-depot/Model.cpp
Expand Up @@ -7,11 +7,36 @@

#include <stdio.h>

#include <Catalog.h>


#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Model"


Model::Model()
:
fSearchTerms(),
fDepots()
fDepots(),

fCategoryAudio(new PackageCategory(
BitmapRef(),
B_TRANSLATE("Audio"), "audio"), true),
fCategoryVideo(new PackageCategory(
BitmapRef(),
B_TRANSLATE("Video"), "video"), true),
fCategoryGraphics(new PackageCategory(
BitmapRef(),
B_TRANSLATE("Graphics"), "graphics"), true),
fCategoryProductivity(new PackageCategory(
BitmapRef(),
B_TRANSLATE("Productivity"), "productivity"), true),
fCategoryDevelopment(new PackageCategory(
BitmapRef(),
B_TRANSLATE("Development"), "development"), true),
fCategoryCommandLine(new PackageCategory(
BitmapRef(),
B_TRANSLATE("Command line"), "command-line"), true)
{
}

Expand Down
22 changes: 22 additions & 0 deletions src/apps/haiku-depot/Model.h
Expand Up @@ -18,10 +18,32 @@ class Model {

bool AddDepot(const DepotInfo& depot);

// Access to global categories
const CategoryRef& CategoryAudio() const
{ return fCategoryAudio; }
const CategoryRef& CategoryVideo() const
{ return fCategoryVideo; }
const CategoryRef& CategoryGraphics() const
{ return fCategoryGraphics; }
const CategoryRef& CategoryProductivity() const
{ return fCategoryProductivity; }
const CategoryRef& CategoryDevelopment() const
{ return fCategoryDevelopment; }
const CategoryRef& CategoryCommandLine() const
{ return fCategoryCommandLine; }

private:
BString fSearchTerms;

DepotInfoList fDepots;

CategoryRef fCategoryAudio;
CategoryRef fCategoryVideo;
CategoryRef fCategoryGraphics;
CategoryRef fCategoryProductivity;
CategoryRef fCategoryDevelopment;
CategoryRef fCategoryCommandLine;
// TODO: More categories
};


Expand Down
73 changes: 73 additions & 0 deletions src/apps/haiku-depot/PackageInfo.cpp
Expand Up @@ -22,6 +22,7 @@

SharedBitmap::SharedBitmap(BBitmap* bitmap)
:
BReferenceable(),
fResourceID(-1),
fMimeType()
{
Expand All @@ -33,6 +34,7 @@ SharedBitmap::SharedBitmap(BBitmap* bitmap)

SharedBitmap::SharedBitmap(int32 resourceID)
:
BReferenceable(),
fResourceID(resourceID),
fMimeType()
{
Expand All @@ -44,6 +46,7 @@ SharedBitmap::SharedBitmap(int32 resourceID)

SharedBitmap::SharedBitmap(const char* mimeType)
:
BReferenceable(),
fResourceID(-1),
fMimeType(mimeType)
{
Expand Down Expand Up @@ -361,6 +364,65 @@ PublisherInfo::operator!=(const PublisherInfo& other) const
}


// #pragma mark - PackageCategory


PackageCategory::PackageCategory()
:
BReferenceable(),
fIcon(),
fName()
{
}


PackageCategory::PackageCategory(const BitmapRef& icon, const BString& label,
const BString& name)
:
BReferenceable(),
fIcon(icon),
fLabel(label),
fName(name)
{
}


PackageCategory::PackageCategory(const PackageCategory& other)
:
BReferenceable(),
fIcon(other.fIcon),
fLabel(other.fLabel),
fName(other.fName)
{
}


PackageCategory&
PackageCategory::operator=(const PackageCategory& other)
{
fIcon = other.fIcon;
fName = other.fName;
fLabel = other.fLabel;
return *this;
}


bool
PackageCategory::operator==(const PackageCategory& other) const
{
return fIcon == other.fIcon
&& fLabel == other.fLabel
&& fName == other.fName;
}


bool
PackageCategory::operator!=(const PackageCategory& other) const
{
return !(*this == other);
}


// #pragma mark - PackageInfo


Expand Down Expand Up @@ -391,6 +453,7 @@ PackageInfo::PackageInfo(const BitmapRef& icon, const BString& title,
fShortDescription(shortDescription),
fFullDescription(fullDescription),
fChangelog(changelog),
fCategories(),
fUserRatings(),
fScreenshots()
{
Expand All @@ -406,6 +469,7 @@ PackageInfo::PackageInfo(const PackageInfo& other)
fShortDescription(other.fShortDescription),
fFullDescription(other.fFullDescription),
fChangelog(other.fChangelog),
fCategories(other.fCategories),
fUserRatings(other.fUserRatings),
fScreenshots(other.fScreenshots)
{
Expand All @@ -422,6 +486,7 @@ PackageInfo::operator=(const PackageInfo& other)
fShortDescription = other.fShortDescription;
fFullDescription = other.fFullDescription;
fChangelog = other.fChangelog;
fCategories = other.fCategories;
fUserRatings = other.fUserRatings;
fScreenshots = other.fScreenshots;
return *this;
Expand All @@ -438,6 +503,7 @@ PackageInfo::operator==(const PackageInfo& other) const
&& fShortDescription == other.fShortDescription
&& fFullDescription == other.fFullDescription
&& fChangelog == other.fChangelog
&& fCategories == other.fCategories
&& fUserRatings == other.fUserRatings
&& fScreenshots == other.fScreenshots;
}
Expand All @@ -450,6 +516,13 @@ PackageInfo::operator!=(const PackageInfo& other) const
}


bool
PackageInfo::AddCategory(const CategoryRef& category)
{
return fCategories.Add(category);
}


bool
PackageInfo::AddUserRating(const UserRating& rating)
{
Expand Down
37 changes: 34 additions & 3 deletions src/apps/haiku-depot/PackageInfo.h
Expand Up @@ -145,6 +145,35 @@ class PublisherInfo {
};


class PackageCategory : public BReferenceable {
public:
PackageCategory();
PackageCategory(const BitmapRef& icon,
const BString& label,
const BString& name);
PackageCategory(const PackageCategory& other);

PackageCategory& operator=(const PackageCategory& other);
bool operator==(const PackageCategory& other) const;
bool operator!=(const PackageCategory& other) const;

const BitmapRef& Icon() const
{ return fIcon; }
const BString& Label() const
{ return fLabel; }
const BString& Name() const
{ return fName; }
private:
BitmapRef fIcon;
BString fLabel;
BString fName;
};


typedef BReference<PackageCategory> CategoryRef;
typedef List<CategoryRef, false> CategoryList;


class PackageInfo {
public:
PackageInfo();
Expand Down Expand Up @@ -176,15 +205,16 @@ class PackageInfo {
const BString& Changelog() const
{ return fChangelog; }

bool AddUserRating(const UserRating& rating);
bool AddCategory(const CategoryRef& category);
const CategoryList& Categories() const
{ return fCategories; }

bool AddUserRating(const UserRating& rating);
const UserRatingList& UserRatings() const
{ return fUserRatings; }

RatingSummary CalculateRatingSummary() const;

bool AddScreenshot(const BitmapRef& screenshot);

const BitmapList& Screenshots() const
{ return fScreenshots; }

Expand All @@ -196,6 +226,7 @@ class PackageInfo {
BString fShortDescription;
BString fFullDescription;
BString fChangelog;
CategoryList fCategories;
UserRatingList fUserRatings;
BitmapList fScreenshots;
};
Expand Down

0 comments on commit f75ec10

Please sign in to comment.