HaikuDepot: Use PackageInfoRefs instead of PackageInfos

Instead of storing PackageInfo objects directly in the
 PackageLists, store PackageInfoRefs instead. This makes a
 lot of operations much cheaper, and it also allows making
 changes to a PackageInfo (which now exists only once)
 and have those changes reflect everywhere. In particular,
 it will be easier to populate some information of the
 PackageInfo lazily, and to listen for changes on a
 PackageInfo object.
This commit is contained in:
Stephan Aßmus 2013-09-15 17:21:11 +02:00 committed by Rene Gollent
parent 02cac49250
commit 779d8213e9
8 changed files with 62 additions and 50 deletions

View File

@ -160,9 +160,9 @@ MainWindow::_AdoptModel()
void
MainWindow::_AdoptPackage(const PackageInfo& package)
MainWindow::_AdoptPackage(const PackageInfoRef& package)
{
fPackageInfoView->SetPackage(package);
fPackageInfoView->SetPackage(*package.Get());
}
@ -183,7 +183,7 @@ MainWindow::_InitDummyModel()
DepotInfo depot(B_TRANSLATE("Default"));
// WonderBrush
PackageInfo wonderbrush(
PackageInfoRef wonderbrush(new(std::nothrow) PackageInfo(
BitmapRef(new SharedBitmap(601), true),
"WonderBrush",
"2.1.2",
@ -196,24 +196,24 @@ MainWindow::_InitDummyModel()
"WonderBrush is YellowBites' software for doing graphics design "
"on Haiku. It combines many great under-the-hood features with "
"powerful tools and an efficient and intuitive interface.",
"2.1.2 - Initial Haiku release.");
wonderbrush.AddUserRating(
"2.1.2 - Initial Haiku release."), true);
wonderbrush->AddUserRating(
UserRating(UserInfo("humdinger"), 4.5f,
"Awesome!", "en", "2.1.2", 0, 0)
);
wonderbrush.AddUserRating(
wonderbrush->AddUserRating(
UserRating(UserInfo("bonefish"), 5.0f,
"The best!", "en", "2.1.2", 3, 1)
);
wonderbrush.AddScreenshot(
wonderbrush->AddScreenshot(
BitmapRef(new SharedBitmap(603), true));
wonderbrush.AddCategory(fModel.CategoryGraphics());
wonderbrush.AddCategory(fModel.CategoryProductivity());
wonderbrush->AddCategory(fModel.CategoryGraphics());
wonderbrush->AddCategory(fModel.CategoryProductivity());
depot.AddPackage(wonderbrush);
// Paladin
PackageInfo paladin(
PackageInfoRef paladin(new(std::nothrow) PackageInfo(
BitmapRef(new SharedBitmap(602), true),
"Paladin",
"1.2.0",
@ -227,30 +227,30 @@ MainWindow::_InitDummyModel()
"The interface is streamlined, it has some features sorely "
"missing from BeIDE, like running a project in the Terminal, "
"and has a bundled text editor based upon Pe.",
"");
paladin.AddUserRating(
""), true);
paladin->AddUserRating(
UserRating(UserInfo("stippi"), 3.5f,
"Could be more integrated from the sounds of it.",
"en", "1.2.0", 0, 1)
);
paladin.AddUserRating(
paladin->AddUserRating(
UserRating(UserInfo("mmadia"), 5.0f,
"It rocks! Give a try",
"en", "1.1.0", 1, 0)
);
paladin.AddUserRating(
paladin->AddUserRating(
UserRating(UserInfo("bonefish"), 2.0f,
"It just needs to use my jam-rewrite 'ham' and it will be great.",
"en", "1.1.0", 3, 1)
);
paladin.AddScreenshot(
paladin->AddScreenshot(
BitmapRef(new SharedBitmap(605), true));
paladin.AddCategory(fModel.CategoryDevelopment());
paladin->AddCategory(fModel.CategoryDevelopment());
depot.AddPackage(paladin);
// Sequitur
PackageInfo sequitur(
PackageInfoRef sequitur(new(std::nothrow) PackageInfo(
BitmapRef(new SharedBitmap(604), true),
"Sequitur",
"2.1.0",
@ -314,8 +314,8 @@ MainWindow::_InitDummyModel()
"pressure events. The new tool Broken Down Line uses this "
"filter.\n\n"
" * ''Note to filter developers:'' The filter API has changed. You "
"will need to recompile your filters.");
sequitur.AddUserRating(
"will need to recompile your filters."), true);
sequitur->AddUserRating(
UserRating(UserInfo("pete"), 4.5f,
"I can weave a web of sound! And it connects to PatchBay. Check "
"it out, I can wholeheartly recommend this app!! This rating "
@ -326,14 +326,14 @@ MainWindow::_InitDummyModel()
"please the programmer with the text layouting and scrolling of "
"long ratings!", "en", "2.1.0", 4, 1)
);
sequitur.AddUserRating(
sequitur->AddUserRating(
UserRating(UserInfo("stippi"), 3.5f,
"It seems very capable. Still runs fine on Haiku. The interface "
"is composed of many small, hard to click items. But you can "
"configure a tool for each mouse button, which is great for the "
"work flow.", "en", "2.1.0", 2, 1)
);
sequitur.AddCategory(fModel.CategoryAudio());
sequitur->AddCategory(fModel.CategoryAudio());
depot.AddPackage(sequitur);

View File

@ -35,7 +35,7 @@ private:
void _BuildMenu(BMenuBar* menuBar);
void _AdoptModel();
void _AdoptPackage(const PackageInfo& package);
void _AdoptPackage(const PackageInfoRef& package);
void _ClearPackage();
void _InitDummyModel();

View File

@ -24,7 +24,7 @@ PackageFilter::~PackageFilter()
class AnyFilter : public PackageFilter {
public:
virtual bool AcceptsPackage(const PackageInfo& package) const
virtual bool AcceptsPackage(const PackageInfoRef& package) const
{
return true;
}
@ -39,7 +39,7 @@ public:
{
}
virtual bool AcceptsPackage(const PackageInfo& package) const
virtual bool AcceptsPackage(const PackageInfoRef& package) const
{
// TODO: Maybe a PackageInfo ought to know the Depot it came from?
// But right now the same package could theoretically be provided
@ -68,9 +68,11 @@ public:
{
}
virtual bool AcceptsPackage(const PackageInfo& package) const
virtual bool AcceptsPackage(const PackageInfoRef& package) const
{
const CategoryList& categories = package.Categories();
if (package.Get() == NULL)
return false;
const CategoryList& categories = package->Categories();
for (int i = categories.CountItems() - 1; i >= 0; i--) {
const CategoryRef& category = categories.ItemAtFast(i);
if (category.Get() == NULL)
@ -94,7 +96,7 @@ public:
{
}
virtual bool AcceptsPackage(const PackageInfo& package) const
virtual bool AcceptsPackage(const PackageInfoRef& package) const
{
return fPackageList.Contains(package);
}
@ -114,7 +116,7 @@ public:
{
}
virtual bool AcceptsPackage(const PackageInfo& package) const
virtual bool AcceptsPackage(const PackageInfoRef& package) const
{
return fPackageListA.Contains(package)
|| fPackageListB.Contains(package);
@ -146,15 +148,17 @@ public:
}
}
virtual bool AcceptsPackage(const PackageInfo& package) const
virtual bool AcceptsPackage(const PackageInfoRef& package) const
{
if (package.Get() == NULL)
return false;
// Every search term must be found in one of the package texts
for (int32 i = fSearchTerms.CountItems() - 1; i >= 0; i--) {
const BString& term = fSearchTerms.ItemAtFast(i);
if (!_TextContains(package.Title(), term)
&& !_TextContains(package.Publisher().Name(), term)
&& !_TextContains(package.ShortDescription(), term)
&& !_TextContains(package.FullDescription(), term)) {
if (!_TextContains(package->Title(), term)
&& !_TextContains(package->Publisher().Name(), term)
&& !_TextContains(package->ShortDescription(), term)
&& !_TextContains(package->FullDescription(), term)) {
return false;
}
}
@ -263,7 +267,7 @@ Model::CreatePackageList() const
const PackageList& packages = depot.Packages();
for (int32 j = 0; j < packages.CountItems(); j++) {
const PackageInfo& package = packages.ItemAtFast(j);
const PackageInfoRef& package = packages.ItemAtFast(j);
if (fCategoryFilter->AcceptsPackage(package)
&& fSearchTermsFilter->AcceptsPackage(package)) {
resultList.Add(package);
@ -283,7 +287,7 @@ Model::AddDepot(const DepotInfo& depot)
void
Model::SetPackageState(const PackageInfo& package, PackageState state)
Model::SetPackageState(const PackageInfoRef& package, PackageState state)
{
switch (state) {
default:

View File

@ -14,7 +14,7 @@ public:
virtual ~PackageFilter();
virtual bool AcceptsPackage(
const PackageInfo& package) const = 0;
const PackageInfoRef& package) const = 0;
};
typedef BReference<PackageFilter> PackageFilterRef;
@ -55,7 +55,7 @@ public:
{ return fProgressCategories; }
void SetPackageState(
const PackageInfo& package,
const PackageInfoRef& package,
PackageState state);
// Configure PackageFilters

View File

@ -640,7 +640,7 @@ DepotInfo::operator!=(const DepotInfo& other) const
bool
DepotInfo::AddPackage(const PackageInfo& package)
DepotInfo::AddPackage(const PackageInfoRef& package)
{
return fPackages.Add(package);
}

View File

@ -181,7 +181,7 @@ typedef BReference<PackageCategory> CategoryRef;
typedef List<CategoryRef, false> CategoryList;
class PackageInfo {
class PackageInfo : public BReferenceable {
public:
PackageInfo();
PackageInfo(const BitmapRef& icon,
@ -239,7 +239,10 @@ private:
};
typedef List<PackageInfo, false> PackageList;
typedef BReference<PackageInfo> PackageInfoRef;
typedef List<PackageInfoRef, false> PackageList;
enum PackageState {
@ -266,7 +269,7 @@ public:
const PackageList& Packages() const
{ return fPackages; }
bool AddPackage(const PackageInfo& package);
bool AddPackage(const PackageInfoRef& package);
private:
BString fName;

View File

@ -80,13 +80,13 @@ private:
class PackageRow : public BRow {
typedef BRow Inherited;
public:
PackageRow(const PackageInfo& package);
PackageRow(const PackageInfoRef& package);
const PackageInfo& Package() const
const PackageInfoRef& Package() const
{ return fPackage; }
private:
PackageInfo fPackage;
PackageInfoRef fPackage;
};
@ -374,11 +374,16 @@ enum {
};
PackageRow::PackageRow(const PackageInfo& package)
PackageRow::PackageRow(const PackageInfoRef& packageRef)
:
Inherited(ceilf(be_plain_font->Size() * 1.8f)),
fPackage(package)
fPackage(packageRef)
{
if (packageRef.Get() == NULL)
return;
const PackageInfo& package = *packageRef.Get();
// Package icon and title
// NOTE: The icon BBitmap is referenced by the fPackage member.
const BBitmap* icon = NULL;
@ -553,7 +558,7 @@ PackageListView::SelectionChanged()
void
PackageListView::AddPackage(const PackageInfo& package)
PackageListView::AddPackage(const PackageInfoRef& package)
{
PackageRow* packageRow = _FindRow(package);
@ -575,7 +580,7 @@ PackageListView::AddPackage(const PackageInfo& package)
PackageRow*
PackageListView::_FindRow(const PackageInfo& package, PackageRow* parent)
PackageListView::_FindRow(const PackageInfoRef& package, PackageRow* parent)
{
for (int32 i = CountRows(parent) - 1; i >= 0; i--) {
PackageRow* row = dynamic_cast<PackageRow*>(RowAt(i, parent));

View File

@ -29,10 +29,10 @@ public:
virtual void SelectionChanged();
void AddPackage(const PackageInfo& package);
void AddPackage(const PackageInfoRef& package);
private:
PackageRow* _FindRow(const PackageInfo& package,
PackageRow* _FindRow(const PackageInfoRef& package,
PackageRow* parent = NULL);
private:
class ItemCountView;