HaikuDepot: Flesh out PackageManager::GetPackageActions().

- Now actually checks if and where the package is installed, and
  correspondingly returns back the appropriate install/uninstall
  actions. Consequently, HaikuDepot now allows uninstallation of
  (non-system) packages.
This commit is contained in:
Rene Gollent 2013-09-19 12:16:41 +02:00
parent f7bf1d3282
commit adde35ff14

View File

@ -29,11 +29,15 @@
#define B_TRANSLATION_CONTEXT "PackageManager" #define B_TRANSLATION_CONTEXT "PackageManager"
using namespace BPackageKit::BPrivate;
using BPackageKit::BRefreshRepositoryRequest; using BPackageKit::BRefreshRepositoryRequest;
using BPackageKit::DownloadFileRequest; using BPackageKit::DownloadFileRequest;
using namespace BPackageKit::BPrivate;
using BPackageKit::BManager::BPrivate::BException; using BPackageKit::BManager::BPrivate::BException;
using BPackageKit::BManager::BPrivate::BFatalErrorException; using BPackageKit::BManager::BPrivate::BFatalErrorException;
using BPackageKit::BSolver;
using BPackageKit::BSolverPackage;
using BPackageKit::BSolverRepository;
// #pragma mark - PackageAction // #pragma mark - PackageAction
@ -173,17 +177,42 @@ PackageManager::GetPackageActions(const PackageInfo& package)
{ {
PackageActionList actionList; PackageActionList actionList;
// TODO: Actually fetch applicable actions for this package. BObjectList<BSolverPackage> packages;
// If the package is installed and active, it can be status_t result = Solver()->FindPackages(package.Title(),
// * uninstalled BSolver::B_FIND_IN_NAME, packages);
// * deactivated if (result == B_OK) {
// If the package is installed and inactive, it can be bool installed = false;
// * uninstalled bool systemPackage = false;
// * activated for (int32 i = 0; i < packages.CountItems(); i++) {
// If the package is not installed, it can be const BSolverPackage* solverPackage = packages.ItemAt(i);
// * installed (and it will be automatically activated) if (solverPackage->Name() != package.Title())
actionList.Add(PackageActionRef(new InstallPackageAction(package, this), continue;
true));
const BSolverRepository* repository = solverPackage->Repository();
if (repository == static_cast<const BSolverRepository*>(
SystemRepository())) {
installed = true;
systemPackage = true;
} else if (repository == static_cast<const BSolverRepository*>(
CommonRepository())) {
installed = true;
} else if (repository == static_cast<const BSolverRepository*>(
HomeRepository())) {
installed = true;
}
}
if (installed) {
if (!systemPackage) {
actionList.Add(PackageActionRef(new UninstallPackageAction(
package, this), true));
}
} else {
actionList.Add(PackageActionRef(new InstallPackageAction(package,
this), true));
}
// TODO: activation status
}
return actionList; return actionList;
} }