HaikuDepot: PackageInfo, added SharedBitmap and BitmapRef classes

* Use in UserInfo for avatar field.
 * Use in PackageInfo for icon.
 * Use in PackageListView.
This commit is contained in:
Stephan Aßmus 2013-07-30 22:57:30 +02:00
parent 3a98600e80
commit cdbf478fbf
4 changed files with 88 additions and 21 deletions

View File

@ -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.",

View File

@ -7,26 +7,55 @@
#include <stdio.h>
#include <Bitmap.h>
// #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

View File

@ -6,24 +6,50 @@
#define PACKAGE_INFO_H
#include <Referenceable.h>
#include <String.h>
#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<SharedBitmap> 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<UserRating, false> 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;

View File

@ -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