hrev46153 adds 1 changeset to branch 'master' old head: 8bf87f93417aa5ea697a68e409ebea80569bf294 new head: 88cd0fd25b8f171fcd79bf006a41c0061b554982 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=88cd0fd+%5E8bf87f9 ---------------------------------------------------------------------------- 88cd0fd: HaikuDepot: improve progress tracking. - PackageManager: Adjust progress listener interface to also supply the package name to the hook. Adjust implementors. - PackageActions now get a pointer to the model. InstallPackageAction uses that to resolve the package name given in the download progress hook to the package currently being downloaded, and updates progress accordingly. Consequently, if one requests installation of a package that has dependencies, Depot now correctly updates the download progress status of those accordingly, rather than updating the original package repeatedly. [ Rene Gollent <rene@xxxxxxxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev46153 Commit: 88cd0fd25b8f171fcd79bf006a41c0061b554982 URL: http://cgit.haiku-os.org/haiku/commit/?id=88cd0fd Author: Rene Gollent <rene@xxxxxxxxxxx> Date: Tue Oct 1 03:07:19 2013 UTC ---------------------------------------------------------------------------- 8 files changed, 75 insertions(+), 23 deletions(-) src/apps/haiku-depot/MainWindow.cpp | 7 ++++ src/apps/haiku-depot/MainWindow.h | 1 + src/apps/haiku-depot/PackageAction.cpp | 5 ++- src/apps/haiku-depot/PackageAction.h | 9 +++- src/apps/haiku-depot/PackageActionHandler.h | 5 +++ src/apps/haiku-depot/PackageInfoView.cpp | 7 ++-- src/apps/haiku-depot/PackageManager.cpp | 55 ++++++++++++++++++------- src/apps/haiku-depot/PackageManager.h | 9 ++-- ---------------------------------------------------------------------------- diff --git a/src/apps/haiku-depot/MainWindow.cpp b/src/apps/haiku-depot/MainWindow.cpp index 692c67c..6c2ca93 100644 --- a/src/apps/haiku-depot/MainWindow.cpp +++ b/src/apps/haiku-depot/MainWindow.cpp @@ -278,6 +278,13 @@ MainWindow::SchedulePackageActions(PackageActionList& list) } +Model* +MainWindow::GetModel() +{ + return &fModel; +} + + void MainWindow::_BuildMenu(BMenuBar* menuBar) { diff --git a/src/apps/haiku-depot/MainWindow.h b/src/apps/haiku-depot/MainWindow.h index a72ff1c..46f8816 100644 --- a/src/apps/haiku-depot/MainWindow.h +++ b/src/apps/haiku-depot/MainWindow.h @@ -48,6 +48,7 @@ private: // PackageActionHandler virtual status_t SchedulePackageActions( PackageActionList& list); + virtual Model* GetModel(); private: void _BuildMenu(BMenuBar* menuBar); diff --git a/src/apps/haiku-depot/PackageAction.cpp b/src/apps/haiku-depot/PackageAction.cpp index e4697aa..913dc0d 100644 --- a/src/apps/haiku-depot/PackageAction.cpp +++ b/src/apps/haiku-depot/PackageAction.cpp @@ -16,10 +16,11 @@ using namespace BPackageKit; // #pragma mark - PackageAction -PackageAction::PackageAction(int32 type, PackageInfoRef package) +PackageAction::PackageAction(int32 type, PackageInfoRef package, Model* model) : fPackage(package), - fType(type) + fType(type), + fModel(model) { // TODO: allow configuring the installation location fPackageManager = new(std::nothrow) PackageManager( diff --git a/src/apps/haiku-depot/PackageAction.h b/src/apps/haiku-depot/PackageAction.h index 7f9ed8d..3808947 100644 --- a/src/apps/haiku-depot/PackageAction.h +++ b/src/apps/haiku-depot/PackageAction.h @@ -21,15 +21,21 @@ enum { }; +class Model; + + class PackageAction : public BReferenceable { public: PackageAction(int32 type, - PackageInfoRef package); + PackageInfoRef package, Model* model); virtual ~PackageAction(); int32 Type() const { return fType; } + Model* GetModel() const + { return fModel; } + virtual const char* Label() const = 0; virtual status_t Perform() = 0; @@ -43,6 +49,7 @@ protected: private: PackageInfoRef fPackage; int32 fType; + Model* fModel; }; diff --git a/src/apps/haiku-depot/PackageActionHandler.h b/src/apps/haiku-depot/PackageActionHandler.h index f98b4a1..c413014 100644 --- a/src/apps/haiku-depot/PackageActionHandler.h +++ b/src/apps/haiku-depot/PackageActionHandler.h @@ -12,12 +12,17 @@ #include "PackageAction.h" +class Model; + + class PackageActionHandler { public: virtual ~PackageActionHandler(); virtual status_t SchedulePackageActions( PackageActionList& list) = 0; + + virtual Model* GetModel() = 0; }; #endif // PACKAGE_ACTION_HANDLER_H diff --git a/src/apps/haiku-depot/PackageInfoView.cpp b/src/apps/haiku-depot/PackageInfoView.cpp index bcb573a..a574102 100644 --- a/src/apps/haiku-depot/PackageInfoView.cpp +++ b/src/apps/haiku-depot/PackageInfoView.cpp @@ -446,10 +446,10 @@ public: BString avgRating; avgRating.SetToFormat("%.1f", ratingSummary.averageRating); fAvgRating->SetText(avgRating); - + BString votes; votes.SetToFormat("%d", ratingSummary.ratingCount); - + BString voteInfo(B_TRANSLATE("(%Votes%)")); voteInfo.ReplaceAll("%Votes%", votes); @@ -545,7 +545,8 @@ public: BPackageKit::B_PACKAGE_INSTALLATION_LOCATION_HOME); PackageActionList actions = manager.GetPackageActions( - const_cast<PackageInfo*>(&package)); + const_cast<PackageInfo*>(&package), + fPackageActionHandler->GetModel()); bool clearNeeded = false; if (actions.CountItems() != fPackageActions.CountItems()) diff --git a/src/apps/haiku-depot/PackageManager.cpp b/src/apps/haiku-depot/PackageManager.cpp index eb17403..f4250ce 100644 --- a/src/apps/haiku-depot/PackageManager.cpp +++ b/src/apps/haiku-depot/PackageManager.cpp @@ -5,7 +5,7 @@ * Authors: * Ingo Weinhold <ingo_weinhold@xxxxxx> * Stephan Aßmus <superstippi@xxxxxx> - * Rene Gollent, reneGollent.com. + * Rene Gollent <rene@xxxxxxxxxxx> */ @@ -24,6 +24,7 @@ #include "AutoDeleter.h" #include "AutoLocker.h" +#include "Model.h" #include "PackageInfo.h" #include "ProblemWindow.h" #include "ResultWindow.h" @@ -57,9 +58,9 @@ DownloadProgressListener::~DownloadProgressListener() class InstallPackageAction : public PackageAction, private DownloadProgressListener { public: - InstallPackageAction(PackageInfoRef package) + InstallPackageAction(PackageInfoRef package, Model* model) : - PackageAction(PACKAGE_ACTION_INSTALL, package), + PackageAction(PACKAGE_ACTION_INSTALL, package, model), fLastDownloadUpdate(0) { } @@ -102,16 +103,42 @@ public: } // DownloadProgressListener - virtual void DownloadProgressChanged(float progress) + virtual void DownloadProgressChanged(const char* packageName, + float progress) { bigtime_t now = system_time(); if (now - fLastDownloadUpdate > 250000) { - PackageInfoRef ref(Package()); - ref->SetDownloadProgress(progress); - fLastDownloadUpdate = now; + BString tempName(packageName); + tempName.Truncate(tempName.FindFirst('-')); + // strip version suffix off package filename + PackageInfoRef ref(_FindPackageByName(tempName)); + if (ref.Get() != NULL) { + ref->SetDownloadProgress(progress); + fLastDownloadUpdate = now; + } } } + +private: + PackageInfoRef _FindPackageByName(const BString& name) + { + Model* model = GetModel(); + const DepotList& depots = model->Depots(); + // TODO: optimize! + for (int32 i = 0; i < depots.CountItems(); i++) { + const DepotInfo& depot = depots.ItemAtFast(i); + const PackageList& packages = depot.Packages(); + for (int32 j = 0; j < packages.CountItems(); j++) { + PackageInfoRef info = packages.ItemAtFast(j); + if (info->Title() == name) + return info; + } + } + + return PackageInfoRef(); + } + private: bigtime_t fLastDownloadUpdate; }; @@ -122,9 +149,9 @@ private: class UninstallPackageAction : public PackageAction { public: - UninstallPackageAction(PackageInfoRef package) + UninstallPackageAction(PackageInfoRef package, Model* model) : - PackageAction(PACKAGE_ACTION_UNINSTALL, package) + PackageAction(PACKAGE_ACTION_UNINSTALL, package, model) { } @@ -198,7 +225,7 @@ PackageManager::GetPackageState(const PackageInfo& package) PackageActionList -PackageManager::GetPackageActions(PackageInfoRef package) +PackageManager::GetPackageActions(PackageInfoRef package, Model* model) { Init(B_ADD_INSTALLED_REPOSITORIES | B_ADD_REMOTE_REPOSITORIES); PackageActionList actionList; @@ -225,11 +252,11 @@ PackageManager::GetPackageActions(PackageInfoRef package) if (installed) { if (!systemPackage) { actionList.Add(PackageActionRef(new UninstallPackageAction( - package), true)); + package, model), true)); } } else { - actionList.Add(PackageActionRef(new InstallPackageAction(package), - true)); + actionList.Add(PackageActionRef(new InstallPackageAction(package, + model), true)); } // TODO: activation status @@ -369,7 +396,7 @@ PackageManager::ProgressPackageDownloadActive(const char* packageName, { for (int32 i = 0; i < fDownloadProgressListeners.CountItems(); i++) { fDownloadProgressListeners.ItemAt(i)->DownloadProgressChanged( - completionPercentage); + packageName, completionPercentage); } } diff --git a/src/apps/haiku-depot/PackageManager.h b/src/apps/haiku-depot/PackageManager.h index 2d2bb81..ea162bb 100644 --- a/src/apps/haiku-depot/PackageManager.h +++ b/src/apps/haiku-depot/PackageManager.h @@ -23,7 +23,7 @@ namespace BPackageKit { class BSolverPackage; } - +class Model; class PackageManager; class ProblemWindow; class ResultWindow; @@ -40,7 +40,9 @@ class DownloadProgressListener { public: virtual ~DownloadProgressListener(); - virtual void DownloadProgressChanged(float progress) = 0; + virtual void DownloadProgressChanged( + const char* packageName, + float progress) = 0; }; @@ -55,7 +57,8 @@ public: virtual ~PackageManager(); virtual PackageState GetPackageState(const PackageInfo& package); - virtual PackageActionList GetPackageActions(PackageInfoRef package); + virtual PackageActionList GetPackageActions(PackageInfoRef package, + Model* model); void SetCurrentActionPackage( PackageInfoRef package,