HaikuDepot: Implemented filtering by category

This commit is contained in:
Stephan Aßmus
2013-08-10 20:37:08 +02:00
parent 4abd2b7110
commit 42479955ae
7 changed files with 88 additions and 22 deletions
+16 -9
View File
@@ -23,20 +23,14 @@
#define B_TRANSLATION_CONTEXT "FilterView" #define B_TRANSLATION_CONTEXT "FilterView"
enum {
MSG_CATEGORY_SELECTED = 'ctsl',
MSG_REPOSITORY_SELECTED = 'rpsl',
MSG_SEARCH_TERMS_MODIFIED = 'stmd',
};
FilterView::FilterView(const Model& model) FilterView::FilterView(const Model& model)
: :
BGroupView("filter view") BGroupView("filter view")
{ {
// Contruct category popup // Contruct category popup
BPopUpMenu* categoryMenu = new BPopUpMenu(B_TRANSLATE("Show")); 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()); categoryMenu->AddItem(new BSeparatorItem());
const CategoryList& categories = model.Categories(); const CategoryList& categories = model.Categories();
@@ -68,8 +62,21 @@ FilterView::FilterView(const Model& model)
// Construct repository popup // Construct repository popup
BPopUpMenu* repositoryMenu = new BPopUpMenu(B_TRANSLATE("Depot")); 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->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:"), fRepositoryField = new BMenuField("repository", B_TRANSLATE("Depot:"),
repositoryMenu); repositoryMenu);
+7
View File
@@ -13,6 +13,13 @@ class BTextControl;
class Model; class Model;
enum {
MSG_CATEGORY_SELECTED = 'ctsl',
MSG_DEPOT_SELECTED = 'dpsl',
MSG_SEARCH_TERMS_MODIFIED = 'stmd',
};
class FilterView : public BGroupView { class FilterView : public BGroupView {
public: public:
FilterView(const Model& model); FilterView(const Model& model);
+12 -1
View File
@@ -33,6 +33,8 @@ MainWindow::MainWindow(BRect frame)
B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS)
{ {
_InitDummyModel();
BMenuBar* menuBar = new BMenuBar(B_TRANSLATE("Main Menu")); BMenuBar* menuBar = new BMenuBar(B_TRANSLATE("Main Menu"));
_BuildMenu(menuBar); _BuildMenu(menuBar);
@@ -59,7 +61,6 @@ MainWindow::MainWindow(BRect frame)
fSplitView->SetCollapsible(0, false); fSplitView->SetCollapsible(0, false);
fSplitView->SetCollapsible(1, false); fSplitView->SetCollapsible(1, false);
_InitDummyModel();
_AdoptModel(); _AdoptModel();
} }
@@ -100,6 +101,16 @@ MainWindow::MessageReceived(BMessage* message)
break; break;
} }
case MSG_CATEGORY_SELECTED:
{
BString name;
if (message->FindString("name", &name) != B_OK)
name = "";
fModel.SetCategory(name);
_AdoptModel();
break;
}
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; break;
+36
View File
@@ -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 // #pragma mark - Model
@@ -137,3 +163,13 @@ Model::AddDepot(const DepotInfo& depot)
return fDepots.Add(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);
}
+6 -1
View File
@@ -28,6 +28,8 @@ public:
PackageInfoList CreatePackageList() const; PackageInfoList CreatePackageList() const;
bool AddDepot(const DepotInfo& depot); bool AddDepot(const DepotInfo& depot);
const DepotList& Depots() const
{ return fDepots; }
// Access to global categories // Access to global categories
const CategoryRef& CategoryAudio() const const CategoryRef& CategoryAudio() const
@@ -48,10 +50,13 @@ public:
const CategoryList& Categories() const const CategoryList& Categories() const
{ return fCategories; } { return fCategories; }
// Configure PackageFilters
void SetCategory(const BString& category);
private: private:
BString fSearchTerms; BString fSearchTerms;
DepotInfoList fDepots; DepotList fDepots;
CategoryRef fCategoryAudio; CategoryRef fCategoryAudio;
CategoryRef fCategoryVideo; CategoryRef fCategoryVideo;
+6 -6
View File
@@ -584,15 +584,15 @@ PackageInfo::AddScreenshot(const BitmapRef& screenshot)
DepotInfo::DepotInfo() DepotInfo::DepotInfo()
: :
fTitle(), fName(),
fPackages() fPackages()
{ {
} }
DepotInfo::DepotInfo(const BString& title) DepotInfo::DepotInfo(const BString& name)
: :
fTitle(title), fName(name),
fPackages() fPackages()
{ {
} }
@@ -600,7 +600,7 @@ DepotInfo::DepotInfo(const BString& title)
DepotInfo::DepotInfo(const DepotInfo& other) DepotInfo::DepotInfo(const DepotInfo& other)
: :
fTitle(other.fTitle), fName(other.fName),
fPackages(other.fPackages) fPackages(other.fPackages)
{ {
} }
@@ -609,7 +609,7 @@ DepotInfo::DepotInfo(const DepotInfo& other)
DepotInfo& DepotInfo&
DepotInfo::operator=(const DepotInfo& other) DepotInfo::operator=(const DepotInfo& other)
{ {
fTitle = other.fTitle; fName = other.fName;
fPackages = other.fPackages; fPackages = other.fPackages;
return *this; return *this;
} }
@@ -618,7 +618,7 @@ DepotInfo::operator=(const DepotInfo& other)
bool bool
DepotInfo::operator==(const DepotInfo& other) const DepotInfo::operator==(const DepotInfo& other) const
{ {
return fTitle == other.fTitle return fName == other.fName
&& fPackages == other.fPackages; && fPackages == other.fPackages;
} }
+5 -5
View File
@@ -238,15 +238,15 @@ typedef List<PackageInfo, false> PackageInfoList;
class DepotInfo { class DepotInfo {
public: public:
DepotInfo(); DepotInfo();
DepotInfo(const BString& title); DepotInfo(const BString& name);
DepotInfo(const DepotInfo& other); DepotInfo(const DepotInfo& other);
DepotInfo& operator=(const DepotInfo& other); DepotInfo& operator=(const DepotInfo& other);
bool operator==(const DepotInfo& other) const; bool operator==(const DepotInfo& other) const;
bool operator!=(const DepotInfo& other) const; bool operator!=(const DepotInfo& other) const;
const BString& Title() const const BString& Name() const
{ return fTitle; } { return fName; }
const PackageInfoList& PackageList() const const PackageInfoList& PackageList() const
{ return fPackages; } { return fPackages; }
@@ -254,12 +254,12 @@ public:
bool AddPackage(const PackageInfo& package); bool AddPackage(const PackageInfo& package);
private: private:
BString fTitle; BString fName;
PackageInfoList fPackages; PackageInfoList fPackages;
}; };
typedef List<DepotInfo, false> DepotInfoList; typedef List<DepotInfo, false> DepotList;
#endif // PACKAGE_INFO_H #endif // PACKAGE_INFO_H