HaikuDepot: Beginnings of supporting filters...
... to reduce the package list. No filters can be defined via the UI, but a DepotFilter is already implemented, although its performance will probably need to improve.
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
#include <PopUpMenu.h>
|
||||
#include <TextControl.h>
|
||||
|
||||
#include "Model.h"
|
||||
|
||||
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
#define B_TRANSLATION_CONTEXT "FilterView"
|
||||
@@ -28,7 +30,7 @@ enum {
|
||||
};
|
||||
|
||||
|
||||
FilterView::FilterView()
|
||||
FilterView::FilterView(const Model& model)
|
||||
:
|
||||
BGroupView("filter view")
|
||||
{
|
||||
@@ -36,21 +38,27 @@ FilterView::FilterView()
|
||||
BPopUpMenu* categoryMenu = new BPopUpMenu(B_TRANSLATE("Show"));
|
||||
categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("All packages"), NULL));
|
||||
categoryMenu->AddItem(new BSeparatorItem());
|
||||
categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("Audio"), NULL));
|
||||
categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("Games"), NULL));
|
||||
categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("Graphics"), NULL));
|
||||
categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("Development"), NULL));
|
||||
categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("Miscellaneous"), NULL));
|
||||
categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("Shell"), NULL));
|
||||
categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("Video"), NULL));
|
||||
|
||||
const CategoryList& categories = model.Categories();
|
||||
for (int i = 0; i < categories.CountItems(); i++) {
|
||||
const CategoryRef& category = categories.ItemAtFast(i);
|
||||
BMessage* message = new BMessage(MSG_CATEGORY_SELECTED);
|
||||
message->AddString("name", category->Name());
|
||||
BMenuItem* item = new BMenuItem(category->Label(), message);
|
||||
categoryMenu->AddItem(item);
|
||||
}
|
||||
|
||||
categoryMenu->AddItem(new BSeparatorItem());
|
||||
|
||||
categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("Installed packages"),
|
||||
NULL));
|
||||
categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("Uninstalled packages"),
|
||||
NULL));
|
||||
categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("User selected packages"),
|
||||
NULL));
|
||||
|
||||
categoryMenu->AddItem(new BSeparatorItem());
|
||||
|
||||
categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("Downloading"), NULL));
|
||||
categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("Update available"), NULL));
|
||||
categoryMenu->ItemAt(0)->SetMarked(true);
|
||||
|
||||
@@ -10,11 +10,12 @@
|
||||
|
||||
class BMenuField;
|
||||
class BTextControl;
|
||||
class Model;
|
||||
|
||||
|
||||
class FilterView : public BGroupView {
|
||||
public:
|
||||
FilterView();
|
||||
FilterView(const Model& model);
|
||||
virtual ~FilterView();
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
|
||||
@@ -36,7 +36,7 @@ MainWindow::MainWindow(BRect frame)
|
||||
BMenuBar* menuBar = new BMenuBar(B_TRANSLATE("Main Menu"));
|
||||
_BuildMenu(menuBar);
|
||||
|
||||
fFilterView = new FilterView();
|
||||
fFilterView = new FilterView(fModel);
|
||||
fPackageListView = new PackageListView();
|
||||
fPackageInfoView = new PackageInfoView(&fPackageManager);
|
||||
|
||||
|
||||
@@ -14,6 +14,55 @@
|
||||
#define B_TRANSLATION_CONTEXT "Model"
|
||||
|
||||
|
||||
// #pragma mark - PackageFilters
|
||||
|
||||
|
||||
PackageFilter::~PackageFilter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
class AnyFilter : public PackageFilter {
|
||||
public:
|
||||
virtual bool AcceptsPackage(const PackageInfo& package) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class DepotFilter : public PackageFilter {
|
||||
public:
|
||||
DepotFilter(const DepotInfo& depot)
|
||||
:
|
||||
fDepot(depot)
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool AcceptsPackage(const PackageInfo& package) const
|
||||
{
|
||||
// TODO: Maybe a PackageInfo ought to know the Depot it came from?
|
||||
// But right now the same package could theoretically be provided
|
||||
// from different depots and the filter would work correctly.
|
||||
// Also the PackageList could actually contain references to packages
|
||||
// instead of the packages as objects. The equal operator is quite
|
||||
// expensive as is.
|
||||
const PackageInfoList& packageList = fDepot.PackageList();
|
||||
for (int i = packageList.CountItems() - 1; i >= 0; i--) {
|
||||
if (packageList.ItemAtFast(i) == package)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
DepotInfo fDepot;
|
||||
};
|
||||
|
||||
|
||||
// #pragma mark - Model
|
||||
|
||||
|
||||
Model::Model()
|
||||
:
|
||||
fSearchTerms(),
|
||||
@@ -36,7 +85,14 @@ Model::Model()
|
||||
B_TRANSLATE("Development"), "development"), true),
|
||||
fCategoryCommandLine(new PackageCategory(
|
||||
BitmapRef(),
|
||||
B_TRANSLATE("Command line"), "command-line"), true)
|
||||
B_TRANSLATE("Command line"), "command-line"), true),
|
||||
fCategoryGames(new PackageCategory(
|
||||
BitmapRef(),
|
||||
B_TRANSLATE("Games"), "games"), true),
|
||||
|
||||
fCategoryFilter(PackageFilterRef(new AnyFilter(), true)),
|
||||
fDepotFilter(PackageFilterRef(new AnyFilter(), true)),
|
||||
fSearchTermsFilter(PackageFilterRef(new AnyFilter(), true))
|
||||
{
|
||||
// Don't forget to add new categories to this list:
|
||||
fCategories.Add(fCategoryAudio);
|
||||
@@ -45,6 +101,7 @@ Model::Model()
|
||||
fCategories.Add(fCategoryProductivity);
|
||||
fCategories.Add(fCategoryDevelopment);
|
||||
fCategories.Add(fCategoryCommandLine);
|
||||
fCategories.Add(fCategoryGames);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +118,12 @@ Model::CreatePackageList() const
|
||||
= fDepots.ItemAtFast(i).PackageList();
|
||||
|
||||
for (int32 j = 0; j < packageList.CountItems(); j++) {
|
||||
resultList.Add(packageList.ItemAtFast(j));
|
||||
const PackageInfo& package = packageList.ItemAtFast(j);
|
||||
if (fCategoryFilter->AcceptsPackage(package)
|
||||
&& fDepotFilter->AcceptsPackage(package)
|
||||
&& fSearchTermsFilter->AcceptsPackage(package)) {
|
||||
resultList.Add(package);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,17 @@
|
||||
#include "PackageInfo.h"
|
||||
|
||||
|
||||
class PackageFilter : public BReferenceable {
|
||||
public:
|
||||
virtual ~PackageFilter();
|
||||
|
||||
virtual bool AcceptsPackage(
|
||||
const PackageInfo& package) const = 0;
|
||||
};
|
||||
|
||||
typedef BReference<PackageFilter> PackageFilterRef;
|
||||
|
||||
|
||||
class Model {
|
||||
public:
|
||||
Model();
|
||||
@@ -31,6 +42,8 @@ public:
|
||||
{ return fCategoryDevelopment; }
|
||||
const CategoryRef& CategoryCommandLine() const
|
||||
{ return fCategoryCommandLine; }
|
||||
const CategoryRef& CategoryGames() const
|
||||
{ return fCategoryGames; }
|
||||
|
||||
const CategoryList& Categories() const
|
||||
{ return fCategories; }
|
||||
@@ -46,9 +59,14 @@ private:
|
||||
CategoryRef fCategoryProductivity;
|
||||
CategoryRef fCategoryDevelopment;
|
||||
CategoryRef fCategoryCommandLine;
|
||||
CategoryRef fCategoryGames;
|
||||
// TODO: More categories
|
||||
|
||||
CategoryList fCategories;
|
||||
|
||||
PackageFilterRef fCategoryFilter;
|
||||
PackageFilterRef fDepotFilter;
|
||||
PackageFilterRef fSearchTermsFilter;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user