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 <[email protected]>
This commit is contained in:
committed by
Stephan Aßmus
parent
925c3a133b
commit
b711002d34
@@ -32,6 +32,7 @@ class BInstallationLocationInfo;
|
|||||||
class BPackageInfoSet;
|
class BPackageInfoSet;
|
||||||
class BRepositoryCache;
|
class BRepositoryCache;
|
||||||
class BRepositoryConfig;
|
class BRepositoryConfig;
|
||||||
|
class BPackageInfo;
|
||||||
|
|
||||||
|
|
||||||
// watchable events
|
// watchable events
|
||||||
@@ -87,6 +88,10 @@ public:
|
|||||||
BPackageInstallationLocation location,
|
BPackageInstallationLocation location,
|
||||||
BPackageInfoSet& packageInfos);
|
BPackageInfoSet& packageInfos);
|
||||||
|
|
||||||
|
status_t IsPackageActive(
|
||||||
|
BPackageInstallationLocation location,
|
||||||
|
const BPackageInfo info, bool* active);
|
||||||
|
|
||||||
status_t StartWatching(const BMessenger& target,
|
status_t StartWatching(const BMessenger& target,
|
||||||
uint32 eventMask);
|
uint32 eventMask);
|
||||||
status_t StopWatching(const BMessenger& target);
|
status_t StopWatching(const BMessenger& target);
|
||||||
|
|||||||
@@ -13,7 +13,9 @@
|
|||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
|
#include <package/PackageDefs.h>
|
||||||
#include <package/PackageInfo.h>
|
#include <package/PackageInfo.h>
|
||||||
|
#include <package/PackageRoster.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
#include <Screen.h>
|
#include <Screen.h>
|
||||||
@@ -365,6 +367,35 @@ App::_Open(const BEntry& entry)
|
|||||||
|
|
||||||
package->SetLocalFilePath(path.Path());
|
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;
|
BMessage settings;
|
||||||
_LoadSettings(settings);
|
_LoadSettings(settings);
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
status_t
|
||||||
BPackageRoster::StartWatching(const BMessenger& target, uint32 eventMask)
|
BPackageRoster::StartWatching(const BMessenger& target, uint32 eventMask)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user