HaikuDepot: Set package state when loading single package

Without this, even installed packages still get an "Install" button.

Fixes #14821.

This was implemented by adding BPackageRoster::IsPackageActive. I decided to
have this take a location since GetActivePackages also did, but as noted in my
TODO comment, I think this is awkward.

It would also be nice to show the user they have a different version of a
particular package, but that would require some changes to IsPackageActive.

Change-Id: Iab0d35eb6b671a17711b0214b15164d296927e5a
Reviewed-on: https://review.haiku-os.org/c/1694
Reviewed-by: Stephan Aßmus <superstippi@gmx.de>
This commit is contained in:
Ryan Leavengood 2019-08-07 21:18:57 -04:00 committed by Stephan Aßmus
parent 925c3a133b
commit b711002d34
3 changed files with 64 additions and 0 deletions

View File

@ -32,6 +32,7 @@ class BInstallationLocationInfo;
class BPackageInfoSet;
class BRepositoryCache;
class BRepositoryConfig;
class BPackageInfo;
// watchable events
@ -87,6 +88,10 @@ public:
BPackageInstallationLocation location,
BPackageInfoSet& packageInfos);
status_t IsPackageActive(
BPackageInstallationLocation location,
const BPackageInfo info, bool* active);
status_t StartWatching(const BMessenger& target,
uint32 eventMask);
status_t StopWatching(const BMessenger& target);

View File

@ -13,7 +13,9 @@
#include <Catalog.h>
#include <Entry.h>
#include <Message.h>
#include <package/PackageDefs.h>
#include <package/PackageInfo.h>
#include <package/PackageRoster.h>
#include <Path.h>
#include <Roster.h>
#include <Screen.h>
@ -365,6 +367,35 @@ App::_Open(const BEntry& entry)
package->SetLocalFilePath(path.Path());
// Set if the package is active
//
// TODO(leavengood): It is very awkward having to check these two locations
// here, and in many other places in HaikuDepot. Why do clients of the
// package kit have to know about these locations?
bool active = false;
BPackageKit::BPackageRoster roster;
status = roster.IsPackageActive(
BPackageKit::B_PACKAGE_INSTALLATION_LOCATION_SYSTEM, info, &active);
if (status != B_OK) {
fprintf(stderr, "Could not check if package was active in system: %s\n",
strerror(status));
return;
}
if (!active) {
status = roster.IsPackageActive(
BPackageKit::B_PACKAGE_INSTALLATION_LOCATION_HOME, info, &active);
if (status != B_OK) {
fprintf(stderr,
"Could not check if package was active in home: %s\n",
strerror(status));
return;
}
}
if (active) {
package->SetState(ACTIVATED);
}
BMessage settings;
_LoadSettings(settings);

View File

@ -252,6 +252,34 @@ BPackageRoster::GetActivePackages(BPackageInstallationLocation location,
}
status_t
BPackageRoster::IsPackageActive(BPackageInstallationLocation location,
const BPackageInfo info, bool* active)
{
// This method makes sense only on an installed Haiku, but not for the build
// tools.
#if defined(__HAIKU__) && !defined(HAIKU_HOST_PLATFORM_HAIKU)
BPackageInfoSet packageInfos;
status_t error = GetActivePackages(location, packageInfos);
if (error != B_OK)
return error;
BRepositoryCache::Iterator it = packageInfos.GetIterator();
while (const BPackageInfo* packageInfo = it.Next()) {
if (info.Name() == packageInfo->Name() &&
info.Version().Compare(packageInfo->Version()) == 0) {
*active = true;
break;
}
}
return B_OK;
#else
return B_NOT_SUPPORTED;
#endif
}
status_t
BPackageRoster::StartWatching(const BMessenger& target, uint32 eventMask)
{