HaikuDepot: add change confirmation event to progress listener

* Add a new event "ConfirmedChanges" to PackageProgressListener. It
  triggers when a package action was confirmed by the user and is
  about to be run. This can be used to e.g. get a full list of
  packages about to be installed (i.e. including dependencies)
  right before the process of fetching/installing them is started.

* Add a handler for it which looks at PackagesToActivate and sets
  all their PackageInfo states to pending (so now, when installing
  a package, its dependencies immediately become pending as well).
This commit is contained in:
Julian Harnath
2017-11-24 18:22:14 +01:00
parent 2a493ea0e0
commit d737433974
2 changed files with 48 additions and 2 deletions
+42 -2
View File
@@ -1,11 +1,12 @@
/*
* Copyright 2013-2015, Haiku, Inc. All Rights Reserved.
* Copyright 2013-2017, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Ingo Weinhold <[email protected]>
* Stephan Aßmus <[email protected]>
* Rene Gollent <[email protected]>
* Julian Harnath <[email protected]>
*/
@@ -86,6 +87,13 @@ PackageProgressListener::DownloadProgressComplete(const char* packageName)
}
void
PackageProgressListener::ConfirmedChanges(
BPackageManager::InstalledRepository& repository)
{
}
void
PackageProgressListener::StartApplyingChanges(
BPackageManager::InstalledRepository& repository)
@@ -209,6 +217,20 @@ public:
}
}
virtual void ConfirmedChanges(BPackageManager::InstalledRepository&
repository)
{
BPackageManager::InstalledRepository::PackageList& activationList =
repository.PackagesToActivate();
BSolverPackage* package = NULL;
for (int32 i = 0; (package = activationList.ItemAt(i)); i++) {
PackageInfoRef ref(FindPackageByName(package->Info().Name()));
if (ref.Get() != NULL)
ref->SetState(PENDING);
}
}
private:
void _SetDownloadedPackagesState(PackageState state)
{
@@ -690,6 +712,7 @@ PackageManager::ConfirmChanges(bool fromMostSpecific)
bool hasOtherChanges = false;
int32 count = fInstalledRepositories.CountItems();
if (fromMostSpecific) {
for (int32 i = count - 1; i >= 0; i--)
hasOtherChanges
@@ -700,12 +723,16 @@ PackageManager::ConfirmChanges(bool fromMostSpecific)
|= _AddResults(*fInstalledRepositories.ItemAt(i), window);
}
if (!hasOtherChanges)
if (!hasOtherChanges) {
_NotifyChangesConfirmed();
return;
}
// show the window
if (windowDeleter.Detach()->Go() == 0)
throw BAbortedByUserException();
_NotifyChangesConfirmed();
}
@@ -813,6 +840,19 @@ PackageManager::_AddResults(InstalledRepository& repository,
}
void
PackageManager::_NotifyChangesConfirmed()
{
int32 count = fInstalledRepositories.CountItems();
for (int32 i = 0; i < count; i++) {
for (int32 j = 0; j < fPackageProgressListeners.CountItems(); j++) {
fPackageProgressListeners.ItemAt(j)->ConfirmedChanges(
*fInstalledRepositories.ItemAt(i));
}
}
}
BSolverPackage*
PackageManager::_GetSolverPackage(PackageInfoRef package)
{
@@ -2,6 +2,7 @@
* Copyright 2013, Stephan Aßmus <[email protected]>.
* Copyright 2011, Ingo Weinhold, <[email protected]>
* Copyright 2013, Rene Gollent, <[email protected]>
* Copyright 2017, Julian Harnath <[email protected]>.
*
* All rights reserved. Distributed under the terms of the MIT License.
*/
@@ -47,6 +48,10 @@ class PackageProgressListener {
virtual void DownloadProgressComplete(
const char* packageName);
virtual void ConfirmedChanges(
BPackageManager::InstalledRepository&
repository);
virtual void StartApplyingChanges(
BPackageManager::InstalledRepository&
repository);
@@ -119,6 +124,7 @@ private:
BPackageManager::InstalledRepository&
repository,
ResultWindow* window);
void _NotifyChangesConfirmed();
BPackageKit::BSolverPackage*
_GetSolverPackage(PackageInfoRef package);