From cdbf478fbf2aa409e060bfb273e239b07389ccbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Tue, 30 Jul 2013 22:57:30 +0200 Subject: [PATCH] HaikuDepot: PackageInfo, added SharedBitmap and BitmapRef classes * Use in UserInfo for avatar field. * Use in PackageInfo for icon. * Use in PackageListView. --- src/apps/haiku-depot/MainWindow.cpp | 2 + src/apps/haiku-depot/PackageInfo.cpp | 50 ++++++++++++++++++++---- src/apps/haiku-depot/PackageInfo.h | 34 +++++++++++++++- src/apps/haiku-depot/PackageListView.cpp | 23 ++++++----- 4 files changed, 88 insertions(+), 21 deletions(-) diff --git a/src/apps/haiku-depot/MainWindow.cpp b/src/apps/haiku-depot/MainWindow.cpp index 1a140cbbca..768b566bee 100644 --- a/src/apps/haiku-depot/MainWindow.cpp +++ b/src/apps/haiku-depot/MainWindow.cpp @@ -153,6 +153,7 @@ MainWindow::_InitDummyModel() DepotInfo depot(B_TRANSLATE("Default")); PackageInfo wonderbrush( + BitmapRef(), "WonderBrush", "2.1.2", "A vector based graphics editor.", @@ -171,6 +172,7 @@ MainWindow::_InitDummyModel() depot.AddPackage(wonderbrush); PackageInfo paladin( + BitmapRef(), "Paladin", "1.2.0", "A C/C++ IDE based on Pe.", diff --git a/src/apps/haiku-depot/PackageInfo.cpp b/src/apps/haiku-depot/PackageInfo.cpp index a90c4716e5..dc718da679 100644 --- a/src/apps/haiku-depot/PackageInfo.cpp +++ b/src/apps/haiku-depot/PackageInfo.cpp @@ -7,26 +7,55 @@ #include +#include + + +// #pragma mark - SharedBitmap + + +SharedBitmap::SharedBitmap(BBitmap* bitmap) + : + fBitmap(bitmap) +{ +} + + +SharedBitmap::~SharedBitmap() +{ + delete fBitmap; +} + // #pragma mark - UserInfo UserInfo::UserInfo() : + fAvatar(), fNickName() { } -UserInfo::UserInfo(const BString& fNickName) +UserInfo::UserInfo(const BString& nickName) : - fNickName(fNickName) + fAvatar(), + fNickName(nickName) +{ +} + + +UserInfo::UserInfo(const BitmapRef& avatar, const BString& nickName) + : + fAvatar(avatar), + fNickName(nickName) { } UserInfo::UserInfo(const UserInfo& other) : + fAvatar(other.fAvatar), fNickName(other.fNickName) { } @@ -35,6 +64,7 @@ UserInfo::UserInfo(const UserInfo& other) UserInfo& UserInfo::operator=(const UserInfo& other) { + fAvatar = other.fAvatar; fNickName = other.fNickName; return *this; } @@ -43,7 +73,8 @@ UserInfo::operator=(const UserInfo& other) bool UserInfo::operator==(const UserInfo& other) const { - return fNickName == other.fNickName; + return fAvatar == other.fAvatar + && fNickName == other.fNickName; } @@ -128,6 +159,7 @@ UserRating::operator!=(const UserRating& other) const PackageInfo::PackageInfo() : + fIcon(), fTitle(), fVersion(), fShortDescription(), @@ -138,10 +170,11 @@ PackageInfo::PackageInfo() } -PackageInfo::PackageInfo(const BString& title, const BString& version, - const BString& shortDescription, const BString& fullDescription, - const BString& changelog) +PackageInfo::PackageInfo(const BitmapRef& icon, const BString& title, + const BString& version, const BString& shortDescription, + const BString& fullDescription, const BString& changelog) : + fIcon(icon), fTitle(title), fVersion(version), fShortDescription(shortDescription), @@ -154,6 +187,7 @@ PackageInfo::PackageInfo(const BString& title, const BString& version, PackageInfo::PackageInfo(const PackageInfo& other) : + fIcon(other.fIcon), fTitle(other.fTitle), fVersion(other.fVersion), fShortDescription(other.fShortDescription), @@ -167,6 +201,7 @@ PackageInfo::PackageInfo(const PackageInfo& other) PackageInfo& PackageInfo::operator=(const PackageInfo& other) { + fIcon = other.fIcon; fTitle = other.fTitle; fVersion = other.fVersion; fShortDescription = other.fShortDescription; @@ -180,7 +215,8 @@ PackageInfo::operator=(const PackageInfo& other) bool PackageInfo::operator==(const PackageInfo& other) const { - return fTitle == other.fTitle + return fIcon == other.fIcon + && fTitle == other.fTitle && fVersion == other.fVersion && fShortDescription == other.fShortDescription && fFullDescription == other.fFullDescription diff --git a/src/apps/haiku-depot/PackageInfo.h b/src/apps/haiku-depot/PackageInfo.h index d0a4b31866..aa86e72b28 100644 --- a/src/apps/haiku-depot/PackageInfo.h +++ b/src/apps/haiku-depot/PackageInfo.h @@ -6,24 +6,50 @@ #define PACKAGE_INFO_H +#include #include #include "List.h" +class BBitmap; + + +class SharedBitmap : public BReferenceable { +public: + SharedBitmap(BBitmap* bitmap); + ~SharedBitmap(); + + const BBitmap* Bitmap() const + { return fBitmap; } + +private: + BBitmap* fBitmap; +}; + + +typedef BReference BitmapRef; + + class UserInfo { public: UserInfo(); UserInfo(const BString& nickName); + UserInfo(const BitmapRef& avatar, + const BString& nickName); UserInfo(const UserInfo& other); UserInfo& operator=(const UserInfo& other); bool operator==(const UserInfo& other) const; bool operator!=(const UserInfo& other) const; - const BString& NickName() const; + const BitmapRef& Avatar() const + { return fAvatar; } + const BString& NickName() const + { return fNickName; } private: + BitmapRef fAvatar; BString fNickName; }; @@ -68,7 +94,8 @@ typedef List UserRatingList; class PackageInfo { public: PackageInfo(); - PackageInfo(const BString& title, + PackageInfo(const BitmapRef& icon, + const BString& title, const BString& version, const BString& shortDescription, const BString& fullDescription, @@ -79,6 +106,8 @@ public: bool operator==(const PackageInfo& other) const; bool operator!=(const PackageInfo& other) const; + const BitmapRef& Icon() const + { return fIcon; } const BString& Title() const { return fTitle; } const BString& Version() const @@ -93,6 +122,7 @@ public: bool AddUserRating(const UserRating& rating); private: + BitmapRef fIcon; BString fTitle; BString fVersion; BString fShortDescription; diff --git a/src/apps/haiku-depot/PackageListView.cpp b/src/apps/haiku-depot/PackageListView.cpp index 5588f4dc08..961f7c57d0 100644 --- a/src/apps/haiku-depot/PackageListView.cpp +++ b/src/apps/haiku-depot/PackageListView.cpp @@ -22,16 +22,16 @@ class BBitmapStringField : public BStringField { typedef BStringField Inherited; public: - BBitmapStringField(BBitmap* bitmap, + BBitmapStringField(const BBitmap* bitmap, const char* string); virtual ~BBitmapStringField(); - void SetBitmap(BBitmap* bitmap); + void SetBitmap(const BBitmap* bitmap); const BBitmap* Bitmap() const { return fBitmap; } private: - BBitmap* fBitmap; + const BBitmap* fBitmap; }; @@ -79,7 +79,8 @@ private: // TODO: Code-duplication with DriveSetup PartitionList.cpp -BBitmapStringField::BBitmapStringField(BBitmap* bitmap, const char* string) +BBitmapStringField::BBitmapStringField(const BBitmap* bitmap, + const char* string) : Inherited(string), fBitmap(bitmap) @@ -89,14 +90,12 @@ BBitmapStringField::BBitmapStringField(BBitmap* bitmap, const char* string) BBitmapStringField::~BBitmapStringField() { - delete fBitmap; } void -BBitmapStringField::SetBitmap(BBitmap* bitmap) +BBitmapStringField::SetBitmap(const BBitmap* bitmap) { - delete fBitmap; fBitmap = bitmap; // TODO: cause a redraw? } @@ -248,11 +247,11 @@ PackageRow::PackageRow(const PackageInfo& package) Inherited(), fPackage(package) { - // Package icon - - BBitmap* icon = NULL; - // TODO: Fetch package icon - + // Package icon and title + // NOTE: The icon BBitmap is referenced by the fPackage member. + const BBitmap* icon = NULL; + if (package.Icon().Get() != NULL) + icon = package.Icon()->Bitmap(); SetField(new BBitmapStringField(icon, package.Title()), kTitleColumn); // Rating