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 #include #include +#include #include +#include #include #include #include @@ -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) {