HaikuDepot: added "available" filter.

* That's the only one I would ever want to see (in most cases).
* I must admit that I don't really understand why the lists are created
  and updated only for filtering, instead of just testing against the
  package state.
* However, I also have no idea, why the NotContainedInFilter does not
  work. I left it in because someone might see what I didn't, and maybe,
  if the first confusion is cleared, it might even find some use.
This commit is contained in:
Axel Dörfler
2014-03-12 21:49:09 +01:00
parent 5f448959ec
commit 634c2c68b2
+67 -8
View File
@@ -1,10 +1,12 @@
/* /*
* Copyright 2013, Stephan Aßmus <[email protected]>. * Copyright 2013, Stephan Aßmus <[email protected]>.
* Copyright 2014, Axel Dörfler <[email protected]>.
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
#include "Model.h" #include "Model.h"
#include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <Autolock.h> #include <Autolock.h>
@@ -48,12 +50,7 @@ public:
// Also the PackageList could actually contain references to packages // Also the PackageList could actually contain references to packages
// instead of the packages as objects. The equal operator is quite // instead of the packages as objects. The equal operator is quite
// expensive as is. // expensive as is.
const PackageList& packages = fDepot.Packages(); return fDepot.Packages().Contains(package);
for (int i = packages.CountItems() - 1; i >= 0; i--) {
if (packages.ItemAtFast(i) == package)
return true;
}
return false;
} }
private: private:
@@ -73,6 +70,7 @@ public:
{ {
if (package.Get() == NULL) if (package.Get() == NULL)
return false; return false;
const CategoryList& categories = package->Categories(); 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);
@@ -129,6 +127,58 @@ private:
}; };
class NotContainedInFilter : public PackageFilter {
public:
NotContainedInFilter(const PackageList* packageList, ...)
{
va_list args;
va_start(args, packageList);
while (true) {
const PackageList* packageList = va_arg(args, const PackageList*);
if (packageList == NULL)
break;
fPackageLists.Add(packageList);
}
va_end(args);
}
virtual bool AcceptsPackage(const PackageInfoRef& package) const
{
if (package.Get()==NULL)
return false;
printf("TEST %s\n", package->Title().String());
for (int32 i = 0; i < fPackageLists.CountItems(); i++) {
if (fPackageLists.ItemAtFast(i)->Contains(package)) {
printf(" contained in %ld\n", i);
return false;
}
}
return true;
}
private:
List<const PackageList*, true> fPackageLists;
};
class StateFilter : public PackageFilter {
public:
StateFilter(PackageState state)
:
fState(state)
{
}
virtual bool AcceptsPackage(const PackageInfoRef& package) const
{
return package->State() == NONE;
}
private:
PackageState fState;
};
class SearchTermsFilter : public PackageFilter { class SearchTermsFilter : public PackageFilter {
public: public:
SearchTermsFilter(const BString& searchTerms) SearchTermsFilter(const BString& searchTerms)
@@ -245,6 +295,11 @@ Model::Model()
BitmapRef(), BitmapRef(),
B_TRANSLATE("Installed packages"), "installed"), true)); B_TRANSLATE("Installed packages"), "installed"), true));
// A category for packages that not yet installed.
fUserCategories.Add(CategoryRef(new PackageCategory(
BitmapRef(),
B_TRANSLATE("Available packages"), "available"), true));
// A category for packages that the user specifically uninstalled. // A category for packages that the user specifically uninstalled.
// For example, a user may have removed packages from a default // For example, a user may have removed packages from a default
// Haiku installation // Haiku installation
@@ -363,7 +418,12 @@ Model::SetCategory(const BString& category)
filter = new ContainedInFilter(fInstalledPackages); filter = new ContainedInFilter(fInstalledPackages);
else if (category == "uninstalled") else if (category == "uninstalled")
filter = new ContainedInFilter(fUninstalledPackages); filter = new ContainedInFilter(fUninstalledPackages);
else if (category == "modified") { else if (category == "available") {
filter = new StateFilter(NONE);
// filter = new NotContainedInFilter(&fInstalledPackages,
// &fUninstalledPackages, &fDownloadingPackages, &fUpdateablePackages,
// NULL);
} else if (category == "modified") {
filter = new ContainedInEitherFilter(fInstalledPackages, filter = new ContainedInEitherFilter(fInstalledPackages,
fUninstalledPackages); fUninstalledPackages);
} else if (category == "downloading") } else if (category == "downloading")
@@ -412,7 +472,6 @@ Model::SetShowDevelopPackages(bool show)
} }
// #pragma mark - information retrival // #pragma mark - information retrival