HaikuDepot: Implemented filtering by category
This commit is contained in:
parent
4abd2b7110
commit
42479955ae
@ -23,20 +23,14 @@
|
||||
#define B_TRANSLATION_CONTEXT "FilterView"
|
||||
|
||||
|
||||
enum {
|
||||
MSG_CATEGORY_SELECTED = 'ctsl',
|
||||
MSG_REPOSITORY_SELECTED = 'rpsl',
|
||||
MSG_SEARCH_TERMS_MODIFIED = 'stmd',
|
||||
};
|
||||
|
||||
|
||||
FilterView::FilterView(const Model& model)
|
||||
:
|
||||
BGroupView("filter view")
|
||||
{
|
||||
// Contruct category popup
|
||||
BPopUpMenu* categoryMenu = new BPopUpMenu(B_TRANSLATE("Show"));
|
||||
categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("All packages"), NULL));
|
||||
categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("All packages"),
|
||||
new BMessage(MSG_CATEGORY_SELECTED)));
|
||||
categoryMenu->AddItem(new BSeparatorItem());
|
||||
|
||||
const CategoryList& categories = model.Categories();
|
||||
@ -68,8 +62,21 @@ FilterView::FilterView(const Model& model)
|
||||
|
||||
// Construct repository popup
|
||||
BPopUpMenu* repositoryMenu = new BPopUpMenu(B_TRANSLATE("Depot"));
|
||||
repositoryMenu->AddItem(new BMenuItem(B_TRANSLATE("All depots"), NULL));
|
||||
repositoryMenu->AddItem(new BMenuItem(B_TRANSLATE("All depots"),
|
||||
new BMessage(MSG_DEPOT_SELECTED)));
|
||||
repositoryMenu->ItemAt(0)->SetMarked(true);
|
||||
|
||||
repositoryMenu->AddItem(new BSeparatorItem());
|
||||
|
||||
const DepotList& depots = model.Depots();
|
||||
for (int i = 0; i < depots.CountItems(); i++) {
|
||||
const DepotInfo& depot = depots.ItemAtFast(i);
|
||||
BMessage* message = new BMessage(MSG_DEPOT_SELECTED);
|
||||
message->AddString("name", depot.Name());
|
||||
BMenuItem* item = new BMenuItem(depot.Name(), message);
|
||||
repositoryMenu->AddItem(item);
|
||||
}
|
||||
|
||||
fRepositoryField = new BMenuField("repository", B_TRANSLATE("Depot:"),
|
||||
repositoryMenu);
|
||||
|
||||
|
@ -13,6 +13,13 @@ class BTextControl;
|
||||
class Model;
|
||||
|
||||
|
||||
enum {
|
||||
MSG_CATEGORY_SELECTED = 'ctsl',
|
||||
MSG_DEPOT_SELECTED = 'dpsl',
|
||||
MSG_SEARCH_TERMS_MODIFIED = 'stmd',
|
||||
};
|
||||
|
||||
|
||||
class FilterView : public BGroupView {
|
||||
public:
|
||||
FilterView(const Model& model);
|
||||
|
@ -33,6 +33,8 @@ MainWindow::MainWindow(BRect frame)
|
||||
B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||
B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS)
|
||||
{
|
||||
_InitDummyModel();
|
||||
|
||||
BMenuBar* menuBar = new BMenuBar(B_TRANSLATE("Main Menu"));
|
||||
_BuildMenu(menuBar);
|
||||
|
||||
@ -59,7 +61,6 @@ MainWindow::MainWindow(BRect frame)
|
||||
fSplitView->SetCollapsible(0, false);
|
||||
fSplitView->SetCollapsible(1, false);
|
||||
|
||||
_InitDummyModel();
|
||||
_AdoptModel();
|
||||
}
|
||||
|
||||
@ -100,6 +101,16 @@ MainWindow::MessageReceived(BMessage* message)
|
||||
break;
|
||||
}
|
||||
|
||||
case MSG_CATEGORY_SELECTED:
|
||||
{
|
||||
BString name;
|
||||
if (message->FindString("name", &name) != B_OK)
|
||||
name = "";
|
||||
fModel.SetCategory(name);
|
||||
_AdoptModel();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
break;
|
||||
|
@ -60,6 +60,32 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class CategoryFilter : public PackageFilter {
|
||||
public:
|
||||
CategoryFilter(const BString& category)
|
||||
:
|
||||
fCategory(category)
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool AcceptsPackage(const PackageInfo& package) const
|
||||
{
|
||||
const CategoryList& categories = package.Categories();
|
||||
for (int i = categories.CountItems() - 1; i >= 0; i--) {
|
||||
const CategoryRef& category = categories.ItemAtFast(i);
|
||||
if (category.Get() == NULL)
|
||||
continue;
|
||||
if (category->Name() == fCategory)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
BString fCategory;
|
||||
};
|
||||
|
||||
|
||||
// #pragma mark - Model
|
||||
|
||||
|
||||
@ -137,3 +163,13 @@ Model::AddDepot(const DepotInfo& depot)
|
||||
return fDepots.Add(depot);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Model::SetCategory(const BString& category)
|
||||
{
|
||||
if (category.Length() == 0)
|
||||
fCategoryFilter.SetTo(new AnyFilter(), true);
|
||||
else
|
||||
fCategoryFilter.SetTo(new CategoryFilter(category), true);
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,8 @@ public:
|
||||
PackageInfoList CreatePackageList() const;
|
||||
|
||||
bool AddDepot(const DepotInfo& depot);
|
||||
const DepotList& Depots() const
|
||||
{ return fDepots; }
|
||||
|
||||
// Access to global categories
|
||||
const CategoryRef& CategoryAudio() const
|
||||
@ -48,10 +50,13 @@ public:
|
||||
const CategoryList& Categories() const
|
||||
{ return fCategories; }
|
||||
|
||||
// Configure PackageFilters
|
||||
void SetCategory(const BString& category);
|
||||
|
||||
private:
|
||||
BString fSearchTerms;
|
||||
|
||||
DepotInfoList fDepots;
|
||||
DepotList fDepots;
|
||||
|
||||
CategoryRef fCategoryAudio;
|
||||
CategoryRef fCategoryVideo;
|
||||
|
@ -584,15 +584,15 @@ PackageInfo::AddScreenshot(const BitmapRef& screenshot)
|
||||
|
||||
DepotInfo::DepotInfo()
|
||||
:
|
||||
fTitle(),
|
||||
fName(),
|
||||
fPackages()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DepotInfo::DepotInfo(const BString& title)
|
||||
DepotInfo::DepotInfo(const BString& name)
|
||||
:
|
||||
fTitle(title),
|
||||
fName(name),
|
||||
fPackages()
|
||||
{
|
||||
}
|
||||
@ -600,7 +600,7 @@ DepotInfo::DepotInfo(const BString& title)
|
||||
|
||||
DepotInfo::DepotInfo(const DepotInfo& other)
|
||||
:
|
||||
fTitle(other.fTitle),
|
||||
fName(other.fName),
|
||||
fPackages(other.fPackages)
|
||||
{
|
||||
}
|
||||
@ -609,7 +609,7 @@ DepotInfo::DepotInfo(const DepotInfo& other)
|
||||
DepotInfo&
|
||||
DepotInfo::operator=(const DepotInfo& other)
|
||||
{
|
||||
fTitle = other.fTitle;
|
||||
fName = other.fName;
|
||||
fPackages = other.fPackages;
|
||||
return *this;
|
||||
}
|
||||
@ -618,7 +618,7 @@ DepotInfo::operator=(const DepotInfo& other)
|
||||
bool
|
||||
DepotInfo::operator==(const DepotInfo& other) const
|
||||
{
|
||||
return fTitle == other.fTitle
|
||||
return fName == other.fName
|
||||
&& fPackages == other.fPackages;
|
||||
}
|
||||
|
||||
|
@ -238,15 +238,15 @@ typedef List<PackageInfo, false> PackageInfoList;
|
||||
class DepotInfo {
|
||||
public:
|
||||
DepotInfo();
|
||||
DepotInfo(const BString& title);
|
||||
DepotInfo(const BString& name);
|
||||
DepotInfo(const DepotInfo& other);
|
||||
|
||||
DepotInfo& operator=(const DepotInfo& other);
|
||||
bool operator==(const DepotInfo& other) const;
|
||||
bool operator!=(const DepotInfo& other) const;
|
||||
|
||||
const BString& Title() const
|
||||
{ return fTitle; }
|
||||
const BString& Name() const
|
||||
{ return fName; }
|
||||
|
||||
const PackageInfoList& PackageList() const
|
||||
{ return fPackages; }
|
||||
@ -254,12 +254,12 @@ public:
|
||||
bool AddPackage(const PackageInfo& package);
|
||||
|
||||
private:
|
||||
BString fTitle;
|
||||
BString fName;
|
||||
PackageInfoList fPackages;
|
||||
};
|
||||
|
||||
|
||||
typedef List<DepotInfo, false> DepotInfoList;
|
||||
typedef List<DepotInfo, false> DepotList;
|
||||
|
||||
|
||||
#endif // PACKAGE_INFO_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user