From f75ec10dc6be224f669e626e50e2aea44a28dd15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 10 Aug 2013 16:30:30 +0200 Subject: [PATCH] HaikuDepot: Added the notion of package categories * 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 --- src/apps/haiku-depot/Jamfile | 1 + src/apps/haiku-depot/MainWindow.cpp | 4 ++ src/apps/haiku-depot/Model.cpp | 27 +++++++++- src/apps/haiku-depot/Model.h | 22 +++++++++ src/apps/haiku-depot/PackageInfo.cpp | 73 ++++++++++++++++++++++++++++ src/apps/haiku-depot/PackageInfo.h | 37 ++++++++++++-- 6 files changed, 160 insertions(+), 4 deletions(-) diff --git a/src/apps/haiku-depot/Jamfile b/src/apps/haiku-depot/Jamfile index b0e02175779..97499e26893 100644 --- a/src/apps/haiku-depot/Jamfile +++ b/src/apps/haiku-depot/Jamfile @@ -24,6 +24,7 @@ DoCatalogs HaikuDepot : App.cpp FilterView.cpp MainWindow.cpp + Model.cpp PackageInfoView.cpp PackageListView.cpp PackageManager.cpp diff --git a/src/apps/haiku-depot/MainWindow.cpp b/src/apps/haiku-depot/MainWindow.cpp index 0071cd6060a..563694c8f85 100644 --- a/src/apps/haiku-depot/MainWindow.cpp +++ b/src/apps/haiku-depot/MainWindow.cpp @@ -175,6 +175,8 @@ MainWindow::_InitDummyModel() ); wonderbrush.AddScreenshot( BitmapRef(new SharedBitmap(603), true)); + wonderbrush.AddCategory(fModel.CategoryGraphics()); + wonderbrush.AddCategory(fModel.CategoryProductivity()); depot.AddPackage(wonderbrush); @@ -210,6 +212,8 @@ MainWindow::_InitDummyModel() ); paladin.AddScreenshot( BitmapRef(new SharedBitmap(604), true)); + paladin.AddCategory(fModel.CategoryDevelopment()); + depot.AddPackage(paladin); fModel.AddDepot(depot); diff --git a/src/apps/haiku-depot/Model.cpp b/src/apps/haiku-depot/Model.cpp index 78c7c2d5b17..74c536571cf 100644 --- a/src/apps/haiku-depot/Model.cpp +++ b/src/apps/haiku-depot/Model.cpp @@ -7,11 +7,36 @@ #include +#include + + +#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) { } diff --git a/src/apps/haiku-depot/Model.h b/src/apps/haiku-depot/Model.h index d498a32db59..d748edc4784 100644 --- a/src/apps/haiku-depot/Model.h +++ b/src/apps/haiku-depot/Model.h @@ -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 }; diff --git a/src/apps/haiku-depot/PackageInfo.cpp b/src/apps/haiku-depot/PackageInfo.cpp index cf125919619..e338a9d78c4 100644 --- a/src/apps/haiku-depot/PackageInfo.cpp +++ b/src/apps/haiku-depot/PackageInfo.cpp @@ -22,6 +22,7 @@ SharedBitmap::SharedBitmap(BBitmap* bitmap) : + BReferenceable(), fResourceID(-1), fMimeType() { @@ -33,6 +34,7 @@ SharedBitmap::SharedBitmap(BBitmap* bitmap) SharedBitmap::SharedBitmap(int32 resourceID) : + BReferenceable(), fResourceID(resourceID), fMimeType() { @@ -44,6 +46,7 @@ SharedBitmap::SharedBitmap(int32 resourceID) SharedBitmap::SharedBitmap(const char* mimeType) : + BReferenceable(), fResourceID(-1), fMimeType(mimeType) { @@ -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 @@ -391,6 +453,7 @@ PackageInfo::PackageInfo(const BitmapRef& icon, const BString& title, fShortDescription(shortDescription), fFullDescription(fullDescription), fChangelog(changelog), + fCategories(), fUserRatings(), fScreenshots() { @@ -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) { @@ -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; @@ -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; } @@ -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) { diff --git a/src/apps/haiku-depot/PackageInfo.h b/src/apps/haiku-depot/PackageInfo.h index bf082c57e47..019fd1f0782 100644 --- a/src/apps/haiku-depot/PackageInfo.h +++ b/src/apps/haiku-depot/PackageInfo.h @@ -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 CategoryRef; +typedef List CategoryList; + + class PackageInfo { public: PackageInfo(); @@ -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; } @@ -196,6 +226,7 @@ class PackageInfo { BString fShortDescription; BString fFullDescription; BString fChangelog; + CategoryList fCategories; UserRatingList fUserRatings; BitmapList fScreenshots; };