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:
committed by
Rene Gollent
parent
02cac49250
commit
779d8213e9
@@ -160,9 +160,9 @@ MainWindow::_AdoptModel()
|
|||||||
|
|
||||||
|
|
||||||
void
|
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"));
|
DepotInfo depot(B_TRANSLATE("Default"));
|
||||||
|
|
||||||
// WonderBrush
|
// WonderBrush
|
||||||
PackageInfo wonderbrush(
|
PackageInfoRef wonderbrush(new(std::nothrow) PackageInfo(
|
||||||
BitmapRef(new SharedBitmap(601), true),
|
BitmapRef(new SharedBitmap(601), true),
|
||||||
"WonderBrush",
|
"WonderBrush",
|
||||||
"2.1.2",
|
"2.1.2",
|
||||||
@@ -196,24 +196,24 @@ MainWindow::_InitDummyModel()
|
|||||||
"WonderBrush is YellowBites' software for doing graphics design "
|
"WonderBrush is YellowBites' software for doing graphics design "
|
||||||
"on Haiku. It combines many great under-the-hood features with "
|
"on Haiku. It combines many great under-the-hood features with "
|
||||||
"powerful tools and an efficient and intuitive interface.",
|
"powerful tools and an efficient and intuitive interface.",
|
||||||
"2.1.2 - Initial Haiku release.");
|
"2.1.2 - Initial Haiku release."), true);
|
||||||
wonderbrush.AddUserRating(
|
wonderbrush->AddUserRating(
|
||||||
UserRating(UserInfo("humdinger"), 4.5f,
|
UserRating(UserInfo("humdinger"), 4.5f,
|
||||||
"Awesome!", "en", "2.1.2", 0, 0)
|
"Awesome!", "en", "2.1.2", 0, 0)
|
||||||
);
|
);
|
||||||
wonderbrush.AddUserRating(
|
wonderbrush->AddUserRating(
|
||||||
UserRating(UserInfo("bonefish"), 5.0f,
|
UserRating(UserInfo("bonefish"), 5.0f,
|
||||||
"The best!", "en", "2.1.2", 3, 1)
|
"The best!", "en", "2.1.2", 3, 1)
|
||||||
);
|
);
|
||||||
wonderbrush.AddScreenshot(
|
wonderbrush->AddScreenshot(
|
||||||
BitmapRef(new SharedBitmap(603), true));
|
BitmapRef(new SharedBitmap(603), true));
|
||||||
wonderbrush.AddCategory(fModel.CategoryGraphics());
|
wonderbrush->AddCategory(fModel.CategoryGraphics());
|
||||||
wonderbrush.AddCategory(fModel.CategoryProductivity());
|
wonderbrush->AddCategory(fModel.CategoryProductivity());
|
||||||
|
|
||||||
depot.AddPackage(wonderbrush);
|
depot.AddPackage(wonderbrush);
|
||||||
|
|
||||||
// Paladin
|
// Paladin
|
||||||
PackageInfo paladin(
|
PackageInfoRef paladin(new(std::nothrow) PackageInfo(
|
||||||
BitmapRef(new SharedBitmap(602), true),
|
BitmapRef(new SharedBitmap(602), true),
|
||||||
"Paladin",
|
"Paladin",
|
||||||
"1.2.0",
|
"1.2.0",
|
||||||
@@ -227,30 +227,30 @@ MainWindow::_InitDummyModel()
|
|||||||
"The interface is streamlined, it has some features sorely "
|
"The interface is streamlined, it has some features sorely "
|
||||||
"missing from BeIDE, like running a project in the Terminal, "
|
"missing from BeIDE, like running a project in the Terminal, "
|
||||||
"and has a bundled text editor based upon Pe.",
|
"and has a bundled text editor based upon Pe.",
|
||||||
"");
|
""), true);
|
||||||
paladin.AddUserRating(
|
paladin->AddUserRating(
|
||||||
UserRating(UserInfo("stippi"), 3.5f,
|
UserRating(UserInfo("stippi"), 3.5f,
|
||||||
"Could be more integrated from the sounds of it.",
|
"Could be more integrated from the sounds of it.",
|
||||||
"en", "1.2.0", 0, 1)
|
"en", "1.2.0", 0, 1)
|
||||||
);
|
);
|
||||||
paladin.AddUserRating(
|
paladin->AddUserRating(
|
||||||
UserRating(UserInfo("mmadia"), 5.0f,
|
UserRating(UserInfo("mmadia"), 5.0f,
|
||||||
"It rocks! Give a try",
|
"It rocks! Give a try",
|
||||||
"en", "1.1.0", 1, 0)
|
"en", "1.1.0", 1, 0)
|
||||||
);
|
);
|
||||||
paladin.AddUserRating(
|
paladin->AddUserRating(
|
||||||
UserRating(UserInfo("bonefish"), 2.0f,
|
UserRating(UserInfo("bonefish"), 2.0f,
|
||||||
"It just needs to use my jam-rewrite 'ham' and it will be great.",
|
"It just needs to use my jam-rewrite 'ham' and it will be great.",
|
||||||
"en", "1.1.0", 3, 1)
|
"en", "1.1.0", 3, 1)
|
||||||
);
|
);
|
||||||
paladin.AddScreenshot(
|
paladin->AddScreenshot(
|
||||||
BitmapRef(new SharedBitmap(605), true));
|
BitmapRef(new SharedBitmap(605), true));
|
||||||
paladin.AddCategory(fModel.CategoryDevelopment());
|
paladin->AddCategory(fModel.CategoryDevelopment());
|
||||||
|
|
||||||
depot.AddPackage(paladin);
|
depot.AddPackage(paladin);
|
||||||
|
|
||||||
// Sequitur
|
// Sequitur
|
||||||
PackageInfo sequitur(
|
PackageInfoRef sequitur(new(std::nothrow) PackageInfo(
|
||||||
BitmapRef(new SharedBitmap(604), true),
|
BitmapRef(new SharedBitmap(604), true),
|
||||||
"Sequitur",
|
"Sequitur",
|
||||||
"2.1.0",
|
"2.1.0",
|
||||||
@@ -314,8 +314,8 @@ MainWindow::_InitDummyModel()
|
|||||||
"pressure events. The new tool Broken Down Line uses this "
|
"pressure events. The new tool Broken Down Line uses this "
|
||||||
"filter.\n\n"
|
"filter.\n\n"
|
||||||
" * ''Note to filter developers:'' The filter API has changed. You "
|
" * ''Note to filter developers:'' The filter API has changed. You "
|
||||||
"will need to recompile your filters.");
|
"will need to recompile your filters."), true);
|
||||||
sequitur.AddUserRating(
|
sequitur->AddUserRating(
|
||||||
UserRating(UserInfo("pete"), 4.5f,
|
UserRating(UserInfo("pete"), 4.5f,
|
||||||
"I can weave a web of sound! And it connects to PatchBay. Check "
|
"I can weave a web of sound! And it connects to PatchBay. Check "
|
||||||
"it out, I can wholeheartly recommend this app!! This rating "
|
"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 "
|
"please the programmer with the text layouting and scrolling of "
|
||||||
"long ratings!", "en", "2.1.0", 4, 1)
|
"long ratings!", "en", "2.1.0", 4, 1)
|
||||||
);
|
);
|
||||||
sequitur.AddUserRating(
|
sequitur->AddUserRating(
|
||||||
UserRating(UserInfo("stippi"), 3.5f,
|
UserRating(UserInfo("stippi"), 3.5f,
|
||||||
"It seems very capable. Still runs fine on Haiku. The interface "
|
"It seems very capable. Still runs fine on Haiku. The interface "
|
||||||
"is composed of many small, hard to click items. But you can "
|
"is composed of many small, hard to click items. But you can "
|
||||||
"configure a tool for each mouse button, which is great for the "
|
"configure a tool for each mouse button, which is great for the "
|
||||||
"work flow.", "en", "2.1.0", 2, 1)
|
"work flow.", "en", "2.1.0", 2, 1)
|
||||||
);
|
);
|
||||||
sequitur.AddCategory(fModel.CategoryAudio());
|
sequitur->AddCategory(fModel.CategoryAudio());
|
||||||
|
|
||||||
depot.AddPackage(sequitur);
|
depot.AddPackage(sequitur);
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ private:
|
|||||||
void _BuildMenu(BMenuBar* menuBar);
|
void _BuildMenu(BMenuBar* menuBar);
|
||||||
void _AdoptModel();
|
void _AdoptModel();
|
||||||
|
|
||||||
void _AdoptPackage(const PackageInfo& package);
|
void _AdoptPackage(const PackageInfoRef& package);
|
||||||
void _ClearPackage();
|
void _ClearPackage();
|
||||||
|
|
||||||
void _InitDummyModel();
|
void _InitDummyModel();
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ PackageFilter::~PackageFilter()
|
|||||||
|
|
||||||
class AnyFilter : public PackageFilter {
|
class AnyFilter : public PackageFilter {
|
||||||
public:
|
public:
|
||||||
virtual bool AcceptsPackage(const PackageInfo& package) const
|
virtual bool AcceptsPackage(const PackageInfoRef& package) const
|
||||||
{
|
{
|
||||||
return true;
|
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?
|
// TODO: Maybe a PackageInfo ought to know the Depot it came from?
|
||||||
// But right now the same package could theoretically be provided
|
// 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--) {
|
for (int i = categories.CountItems() - 1; i >= 0; i--) {
|
||||||
const CategoryRef& category = categories.ItemAtFast(i);
|
const CategoryRef& category = categories.ItemAtFast(i);
|
||||||
if (category.Get() == NULL)
|
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);
|
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)
|
return fPackageListA.Contains(package)
|
||||||
|| fPackageListB.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
|
// Every search term must be found in one of the package texts
|
||||||
for (int32 i = fSearchTerms.CountItems() - 1; i >= 0; i--) {
|
for (int32 i = fSearchTerms.CountItems() - 1; i >= 0; i--) {
|
||||||
const BString& term = fSearchTerms.ItemAtFast(i);
|
const BString& term = fSearchTerms.ItemAtFast(i);
|
||||||
if (!_TextContains(package.Title(), term)
|
if (!_TextContains(package->Title(), term)
|
||||||
&& !_TextContains(package.Publisher().Name(), term)
|
&& !_TextContains(package->Publisher().Name(), term)
|
||||||
&& !_TextContains(package.ShortDescription(), term)
|
&& !_TextContains(package->ShortDescription(), term)
|
||||||
&& !_TextContains(package.FullDescription(), term)) {
|
&& !_TextContains(package->FullDescription(), term)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -263,7 +267,7 @@ Model::CreatePackageList() const
|
|||||||
const PackageList& packages = depot.Packages();
|
const PackageList& packages = depot.Packages();
|
||||||
|
|
||||||
for (int32 j = 0; j < packages.CountItems(); j++) {
|
for (int32 j = 0; j < packages.CountItems(); j++) {
|
||||||
const PackageInfo& package = packages.ItemAtFast(j);
|
const PackageInfoRef& package = packages.ItemAtFast(j);
|
||||||
if (fCategoryFilter->AcceptsPackage(package)
|
if (fCategoryFilter->AcceptsPackage(package)
|
||||||
&& fSearchTermsFilter->AcceptsPackage(package)) {
|
&& fSearchTermsFilter->AcceptsPackage(package)) {
|
||||||
resultList.Add(package);
|
resultList.Add(package);
|
||||||
@@ -283,7 +287,7 @@ Model::AddDepot(const DepotInfo& depot)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Model::SetPackageState(const PackageInfo& package, PackageState state)
|
Model::SetPackageState(const PackageInfoRef& package, PackageState state)
|
||||||
{
|
{
|
||||||
switch (state) {
|
switch (state) {
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public:
|
|||||||
virtual ~PackageFilter();
|
virtual ~PackageFilter();
|
||||||
|
|
||||||
virtual bool AcceptsPackage(
|
virtual bool AcceptsPackage(
|
||||||
const PackageInfo& package) const = 0;
|
const PackageInfoRef& package) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef BReference<PackageFilter> PackageFilterRef;
|
typedef BReference<PackageFilter> PackageFilterRef;
|
||||||
@@ -55,7 +55,7 @@ public:
|
|||||||
{ return fProgressCategories; }
|
{ return fProgressCategories; }
|
||||||
|
|
||||||
void SetPackageState(
|
void SetPackageState(
|
||||||
const PackageInfo& package,
|
const PackageInfoRef& package,
|
||||||
PackageState state);
|
PackageState state);
|
||||||
|
|
||||||
// Configure PackageFilters
|
// Configure PackageFilters
|
||||||
|
|||||||
@@ -640,7 +640,7 @@ DepotInfo::operator!=(const DepotInfo& other) const
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
DepotInfo::AddPackage(const PackageInfo& package)
|
DepotInfo::AddPackage(const PackageInfoRef& package)
|
||||||
{
|
{
|
||||||
return fPackages.Add(package);
|
return fPackages.Add(package);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ typedef BReference<PackageCategory> CategoryRef;
|
|||||||
typedef List<CategoryRef, false> CategoryList;
|
typedef List<CategoryRef, false> CategoryList;
|
||||||
|
|
||||||
|
|
||||||
class PackageInfo {
|
class PackageInfo : public BReferenceable {
|
||||||
public:
|
public:
|
||||||
PackageInfo();
|
PackageInfo();
|
||||||
PackageInfo(const BitmapRef& icon,
|
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 {
|
enum PackageState {
|
||||||
@@ -266,7 +269,7 @@ public:
|
|||||||
const PackageList& Packages() const
|
const PackageList& Packages() const
|
||||||
{ return fPackages; }
|
{ return fPackages; }
|
||||||
|
|
||||||
bool AddPackage(const PackageInfo& package);
|
bool AddPackage(const PackageInfoRef& package);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BString fName;
|
BString fName;
|
||||||
|
|||||||
@@ -80,13 +80,13 @@ private:
|
|||||||
class PackageRow : public BRow {
|
class PackageRow : public BRow {
|
||||||
typedef BRow Inherited;
|
typedef BRow Inherited;
|
||||||
public:
|
public:
|
||||||
PackageRow(const PackageInfo& package);
|
PackageRow(const PackageInfoRef& package);
|
||||||
|
|
||||||
const PackageInfo& Package() const
|
const PackageInfoRef& Package() const
|
||||||
{ return fPackage; }
|
{ return fPackage; }
|
||||||
|
|
||||||
private:
|
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)),
|
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
|
// Package icon and title
|
||||||
// NOTE: The icon BBitmap is referenced by the fPackage member.
|
// NOTE: The icon BBitmap is referenced by the fPackage member.
|
||||||
const BBitmap* icon = NULL;
|
const BBitmap* icon = NULL;
|
||||||
@@ -553,7 +558,7 @@ PackageListView::SelectionChanged()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PackageListView::AddPackage(const PackageInfo& package)
|
PackageListView::AddPackage(const PackageInfoRef& package)
|
||||||
{
|
{
|
||||||
PackageRow* packageRow = _FindRow(package);
|
PackageRow* packageRow = _FindRow(package);
|
||||||
|
|
||||||
@@ -575,7 +580,7 @@ PackageListView::AddPackage(const PackageInfo& package)
|
|||||||
|
|
||||||
|
|
||||||
PackageRow*
|
PackageRow*
|
||||||
PackageListView::_FindRow(const PackageInfo& package, PackageRow* parent)
|
PackageListView::_FindRow(const PackageInfoRef& package, PackageRow* parent)
|
||||||
{
|
{
|
||||||
for (int32 i = CountRows(parent) - 1; i >= 0; i--) {
|
for (int32 i = CountRows(parent) - 1; i >= 0; i--) {
|
||||||
PackageRow* row = dynamic_cast<PackageRow*>(RowAt(i, parent));
|
PackageRow* row = dynamic_cast<PackageRow*>(RowAt(i, parent));
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ public:
|
|||||||
|
|
||||||
virtual void SelectionChanged();
|
virtual void SelectionChanged();
|
||||||
|
|
||||||
void AddPackage(const PackageInfo& package);
|
void AddPackage(const PackageInfoRef& package);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PackageRow* _FindRow(const PackageInfo& package,
|
PackageRow* _FindRow(const PackageInfoRef& package,
|
||||||
PackageRow* parent = NULL);
|
PackageRow* parent = NULL);
|
||||||
private:
|
private:
|
||||||
class ItemCountView;
|
class ItemCountView;
|
||||||
|
|||||||
Reference in New Issue
Block a user