hrev53354 adds 1 changeset to branch 'master'
old head: 925c3a133b29d8f0f748a22189dea50e169d96ab
new head: b711002d345e2e9e0075be46a37492624f73ccdd
overview:
https://git.haiku-os.org/haiku/log/?qt=range&q=b711002d345e+%5E925c3a133b29
----------------------------------------------------------------------------
b711002d345e: 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@xxxxxx>
[ Ryan Leavengood <leavengood@xxxxxxxxx> ]
----------------------------------------------------------------------------
Revision: hrev53354
Commit: b711002d345e2e9e0075be46a37492624f73ccdd
URL: https://git.haiku-os.org/haiku/commit/?id=b711002d345e
Author: Ryan Leavengood <leavengood@xxxxxxxxx>
Date: Thu Aug 8 01:18:57 2019 UTC
Committer: Stephan Aßmus <superstippi@xxxxxx>
Commit-Date: Thu Aug 8 07:09:35 2019 UTC
Ticket: https://dev.haiku-os.org/ticket/14821
----------------------------------------------------------------------------
3 files changed, 64 insertions(+)
headers/os/package/PackageRoster.h | 5 +++++
src/apps/haikudepot/ui/App.cpp | 31 +++++++++++++++++++++++++++++++
src/kits/package/PackageRoster.cpp | 28 ++++++++++++++++++++++++++++
----------------------------------------------------------------------------
diff --git a/headers/os/package/PackageRoster.h
b/headers/os/package/PackageRoster.h
index 61d6e9f5ef..431ae01f1d 100644
--- a/headers/os/package/PackageRoster.h
+++ b/headers/os/package/PackageRoster.h
@@ -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);
diff --git a/src/apps/haikudepot/ui/App.cpp b/src/apps/haikudepot/ui/App.cpp
index 02161660c5..fbc339bc89 100644
--- a/src/apps/haikudepot/ui/App.cpp
+++ b/src/apps/haikudepot/ui/App.cpp
@@ -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);
diff --git a/src/kits/package/PackageRoster.cpp
b/src/kits/package/PackageRoster.cpp
index 16e13fbc9d..056037c324 100644
--- a/src/kits/package/PackageRoster.cpp
+++ b/src/kits/package/PackageRoster.cpp
@@ -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)
{