diff --git a/src/apps/haiku-depot/FilterView.cpp b/src/apps/haiku-depot/FilterView.cpp index df090f9790..5f0e9541af 100644 --- a/src/apps/haiku-depot/FilterView.cpp +++ b/src/apps/haiku-depot/FilterView.cpp @@ -23,6 +23,19 @@ #define B_TRANSLATION_CONTEXT "FilterView" +static void +add_categories_to_menu(const CategoryList& categories, BMenu* menu) +{ + 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); + menu->AddItem(item); + } +} + + FilterView::FilterView(const Model& model) : BGroupView("filter view") @@ -32,29 +45,12 @@ FilterView::FilterView(const Model& model) categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("All packages"), new BMessage(MSG_CATEGORY_SELECTED))); categoryMenu->AddItem(new BSeparatorItem()); - - 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); - } - + add_categories_to_menu(model.Categories(), categoryMenu); 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)); - + add_categories_to_menu(model.UserCategories(), categoryMenu); categoryMenu->AddItem(new BSeparatorItem()); + add_categories_to_menu(model.ProgressCategories(), categoryMenu); - categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("Downloading"), NULL)); - categoryMenu->AddItem(new BMenuItem(B_TRANSLATE("Update available"), NULL)); categoryMenu->ItemAt(0)->SetMarked(true); fShowField = new BMenuField("category", B_TRANSLATE("Show:"), diff --git a/src/apps/haiku-depot/MainWindow.cpp b/src/apps/haiku-depot/MainWindow.cpp index 40cbfd43e7..22ab1281b5 100644 --- a/src/apps/haiku-depot/MainWindow.cpp +++ b/src/apps/haiku-depot/MainWindow.cpp @@ -228,4 +228,7 @@ MainWindow::_InitDummyModel() depot.AddPackage(paladin); fModel.AddDepot(depot); + + fModel.SetPackageState(wonderbrush, UNINSTALLED); + fModel.SetPackageState(paladin, ACTIVATED); } diff --git a/src/apps/haiku-depot/Model.cpp b/src/apps/haiku-depot/Model.cpp index 21bc600412..d6bd927ba0 100644 --- a/src/apps/haiku-depot/Model.cpp +++ b/src/apps/haiku-depot/Model.cpp @@ -86,6 +86,46 @@ private: }; +class ContainedInFilter : public PackageFilter { +public: + ContainedInFilter(const PackageList& packageList) + : + fPackageList(packageList) + { + } + + virtual bool AcceptsPackage(const PackageInfo& package) const + { + return fPackageList.Contains(package); + } + +private: + const PackageList& fPackageList; +}; + + +class ContainedInEitherFilter : public PackageFilter { +public: + ContainedInEitherFilter(const PackageList& packageListA, + const PackageList& packageListB) + : + fPackageListA(packageListA), + fPackageListB(packageListB) + { + } + + virtual bool AcceptsPackage(const PackageInfo& package) const + { + return fPackageListA.Contains(package) + || fPackageListB.Contains(package); + } + +private: + const PackageList& fPackageListA; + const PackageList& fPackageListB; +}; + + // #pragma mark - Model @@ -128,6 +168,34 @@ Model::Model() fCategories.Add(fCategoryDevelopment); fCategories.Add(fCategoryCommandLine); fCategories.Add(fCategoryGames); + + // A category for packages that the user installed. + fUserCategories.Add(CategoryRef(new PackageCategory( + BitmapRef(), + B_TRANSLATE("Installed packages"), "installed"), true)); + + // A category for packages that the user specifically uninstalled. + // For example, a user may have removed packages from a default + // Haiku installation + fUserCategories.Add(CategoryRef(new PackageCategory( + BitmapRef(), + B_TRANSLATE("Uninstalled packages"), "uninstalled"), true)); + + // A category for all packages that the user has installed or uninstalled. + // Those packages resemble what makes their system different from a + // fresh Haiku installation. + fUserCategories.Add(CategoryRef(new PackageCategory( + BitmapRef(), + B_TRANSLATE("User modified packages"), "modified"), true)); + + // Two categories to see just the packages which are downloading or + // have updates available + fProgressCategories.Add(CategoryRef(new PackageCategory( + BitmapRef(), + B_TRANSLATE("Downloading"), "downloading"), true)); + fProgressCategories.Add(CategoryRef(new PackageCategory( + BitmapRef(), + B_TRANSLATE("Update available"), "updates"), true)); } @@ -198,9 +266,24 @@ Model::SetPackageState(const PackageInfo& package, PackageState state) void Model::SetCategory(const BString& category) { + PackageFilter* filter; + if (category.Length() == 0) - fCategoryFilter.SetTo(new AnyFilter(), true); + filter = new AnyFilter(); + else if (category == "installed") + filter = new ContainedInFilter(fInstalledPackages); + else if (category == "uninstalled") + filter = new ContainedInFilter(fUninstalledPackages); + else if (category == "modified") { + filter = new ContainedInEitherFilter(fInstalledPackages, + fUninstalledPackages); + } else if (category == "downloading") + filter = new ContainedInFilter(fDownloadingPackages); + else if (category == "updates") + filter = new ContainedInFilter(fUpdateablePackages); else - fCategoryFilter.SetTo(new CategoryFilter(category), true); + filter = new CategoryFilter(category); + + fCategoryFilter.SetTo(filter, true); } diff --git a/src/apps/haiku-depot/Model.h b/src/apps/haiku-depot/Model.h index e455035029..ebb3621f36 100644 --- a/src/apps/haiku-depot/Model.h +++ b/src/apps/haiku-depot/Model.h @@ -49,6 +49,10 @@ public: const CategoryList& Categories() const { return fCategories; } + const CategoryList& UserCategories() const + { return fUserCategories; } + const CategoryList& ProgressCategories() const + { return fProgressCategories; } void SetPackageState( const PackageInfo& package, @@ -72,10 +76,14 @@ private: // TODO: More categories CategoryList fCategories; + CategoryList fUserCategories; + CategoryList fProgressCategories; PackageList fInstalledPackages; PackageList fActivatedPackages; PackageList fUninstalledPackages; + PackageList fDownloadingPackages; + PackageList fUpdateablePackages; PackageFilterRef fCategoryFilter; PackageFilterRef fDepotFilter;