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.
This commit is contained in:
Rene Gollent 2013-09-30 23:07:19 -04:00
parent 8bf87f9341
commit 88cd0fd25b
8 changed files with 75 additions and 23 deletions

View File

@ -278,6 +278,13 @@ MainWindow::SchedulePackageActions(PackageActionList& list)
}
Model*
MainWindow::GetModel()
{
return &fModel;
}
void
MainWindow::_BuildMenu(BMenuBar* menuBar)
{

View File

@ -48,6 +48,7 @@ private:
// PackageActionHandler
virtual status_t SchedulePackageActions(
PackageActionList& list);
virtual Model* GetModel();
private:
void _BuildMenu(BMenuBar* menuBar);

View File

@ -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(

View File

@ -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;
};

View File

@ -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

View File

@ -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())

View File

@ -5,7 +5,7 @@
* Authors:
* Ingo Weinhold <ingo_weinhold@gmx.de>
* Stephan Aßmus <superstippi@gmx.de>
* Rene Gollent, reneGollent.com.
* Rene Gollent <rene@gollent.com>
*/
@ -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);
}
}

View File

@ -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,