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:45 -04:00
parent 8bf87f9341
commit 88cd0fd25b
8 changed files with 75 additions and 23 deletions
+7
View File
@@ -278,6 +278,13 @@ MainWindow::SchedulePackageActions(PackageActionList& list)
} }
Model*
MainWindow::GetModel()
{
return &fModel;
}
void void
MainWindow::_BuildMenu(BMenuBar* menuBar) MainWindow::_BuildMenu(BMenuBar* menuBar)
{ {
+1
View File
@@ -48,6 +48,7 @@ private:
// PackageActionHandler // PackageActionHandler
virtual status_t SchedulePackageActions( virtual status_t SchedulePackageActions(
PackageActionList& list); PackageActionList& list);
virtual Model* GetModel();
private: private:
void _BuildMenu(BMenuBar* menuBar); void _BuildMenu(BMenuBar* menuBar);
+3 -2
View File
@@ -16,10 +16,11 @@ using namespace BPackageKit;
// #pragma mark - PackageAction // #pragma mark - PackageAction
PackageAction::PackageAction(int32 type, PackageInfoRef package) PackageAction::PackageAction(int32 type, PackageInfoRef package, Model* model)
: :
fPackage(package), fPackage(package),
fType(type) fType(type),
fModel(model)
{ {
// TODO: allow configuring the installation location // TODO: allow configuring the installation location
fPackageManager = new(std::nothrow) PackageManager( fPackageManager = new(std::nothrow) PackageManager(
+8 -1
View File
@@ -21,15 +21,21 @@ enum {
}; };
class Model;
class PackageAction : public BReferenceable { class PackageAction : public BReferenceable {
public: public:
PackageAction(int32 type, PackageAction(int32 type,
PackageInfoRef package); PackageInfoRef package, Model* model);
virtual ~PackageAction(); virtual ~PackageAction();
int32 Type() const int32 Type() const
{ return fType; } { return fType; }
Model* GetModel() const
{ return fModel; }
virtual const char* Label() const = 0; virtual const char* Label() const = 0;
virtual status_t Perform() = 0; virtual status_t Perform() = 0;
@@ -43,6 +49,7 @@ protected:
private: private:
PackageInfoRef fPackage; PackageInfoRef fPackage;
int32 fType; int32 fType;
Model* fModel;
}; };
@@ -12,12 +12,17 @@
#include "PackageAction.h" #include "PackageAction.h"
class Model;
class PackageActionHandler { class PackageActionHandler {
public: public:
virtual ~PackageActionHandler(); virtual ~PackageActionHandler();
virtual status_t SchedulePackageActions( virtual status_t SchedulePackageActions(
PackageActionList& list) = 0; PackageActionList& list) = 0;
virtual Model* GetModel() = 0;
}; };
#endif // PACKAGE_ACTION_HANDLER_H #endif // PACKAGE_ACTION_HANDLER_H
+2 -1
View File
@@ -545,7 +545,8 @@ public:
BPackageKit::B_PACKAGE_INSTALLATION_LOCATION_HOME); BPackageKit::B_PACKAGE_INSTALLATION_LOCATION_HOME);
PackageActionList actions = manager.GetPackageActions( PackageActionList actions = manager.GetPackageActions(
const_cast<PackageInfo*>(&package)); const_cast<PackageInfo*>(&package),
fPackageActionHandler->GetModel());
bool clearNeeded = false; bool clearNeeded = false;
if (actions.CountItems() != fPackageActions.CountItems()) if (actions.CountItems() != fPackageActions.CountItems())
+41 -14
View File
@@ -5,7 +5,7 @@
* Authors: * Authors:
* Ingo Weinhold <ingo_weinhold@gmx.de> * Ingo Weinhold <ingo_weinhold@gmx.de>
* Stephan Aßmus <superstippi@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 "AutoDeleter.h"
#include "AutoLocker.h" #include "AutoLocker.h"
#include "Model.h"
#include "PackageInfo.h" #include "PackageInfo.h"
#include "ProblemWindow.h" #include "ProblemWindow.h"
#include "ResultWindow.h" #include "ResultWindow.h"
@@ -57,9 +58,9 @@ DownloadProgressListener::~DownloadProgressListener()
class InstallPackageAction : public PackageAction, class InstallPackageAction : public PackageAction,
private DownloadProgressListener { private DownloadProgressListener {
public: public:
InstallPackageAction(PackageInfoRef package) InstallPackageAction(PackageInfoRef package, Model* model)
: :
PackageAction(PACKAGE_ACTION_INSTALL, package), PackageAction(PACKAGE_ACTION_INSTALL, package, model),
fLastDownloadUpdate(0) fLastDownloadUpdate(0)
{ {
} }
@@ -102,16 +103,42 @@ public:
} }
// DownloadProgressListener // DownloadProgressListener
virtual void DownloadProgressChanged(float progress) virtual void DownloadProgressChanged(const char* packageName,
float progress)
{ {
bigtime_t now = system_time(); bigtime_t now = system_time();
if (now - fLastDownloadUpdate > 250000) { if (now - fLastDownloadUpdate > 250000) {
PackageInfoRef ref(Package()); BString tempName(packageName);
ref->SetDownloadProgress(progress); tempName.Truncate(tempName.FindFirst('-'));
fLastDownloadUpdate = now; // 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: private:
bigtime_t fLastDownloadUpdate; bigtime_t fLastDownloadUpdate;
}; };
@@ -122,9 +149,9 @@ private:
class UninstallPackageAction : public PackageAction { class UninstallPackageAction : public PackageAction {
public: 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 PackageActionList
PackageManager::GetPackageActions(PackageInfoRef package) PackageManager::GetPackageActions(PackageInfoRef package, Model* model)
{ {
Init(B_ADD_INSTALLED_REPOSITORIES | B_ADD_REMOTE_REPOSITORIES); Init(B_ADD_INSTALLED_REPOSITORIES | B_ADD_REMOTE_REPOSITORIES);
PackageActionList actionList; PackageActionList actionList;
@@ -225,11 +252,11 @@ PackageManager::GetPackageActions(PackageInfoRef package)
if (installed) { if (installed) {
if (!systemPackage) { if (!systemPackage) {
actionList.Add(PackageActionRef(new UninstallPackageAction( actionList.Add(PackageActionRef(new UninstallPackageAction(
package), true)); package, model), true));
} }
} else { } else {
actionList.Add(PackageActionRef(new InstallPackageAction(package), actionList.Add(PackageActionRef(new InstallPackageAction(package,
true)); model), true));
} }
// TODO: activation status // TODO: activation status
@@ -369,7 +396,7 @@ PackageManager::ProgressPackageDownloadActive(const char* packageName,
{ {
for (int32 i = 0; i < fDownloadProgressListeners.CountItems(); i++) { for (int32 i = 0; i < fDownloadProgressListeners.CountItems(); i++) {
fDownloadProgressListeners.ItemAt(i)->DownloadProgressChanged( fDownloadProgressListeners.ItemAt(i)->DownloadProgressChanged(
completionPercentage); packageName, completionPercentage);
} }
} }
+6 -3
View File
@@ -23,7 +23,7 @@ namespace BPackageKit {
class BSolverPackage; class BSolverPackage;
} }
class Model;
class PackageManager; class PackageManager;
class ProblemWindow; class ProblemWindow;
class ResultWindow; class ResultWindow;
@@ -40,7 +40,9 @@ class DownloadProgressListener {
public: public:
virtual ~DownloadProgressListener(); 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 ~PackageManager();
virtual PackageState GetPackageState(const PackageInfo& package); virtual PackageState GetPackageState(const PackageInfo& package);
virtual PackageActionList GetPackageActions(PackageInfoRef package); virtual PackageActionList GetPackageActions(PackageInfoRef package,
Model* model);
void SetCurrentActionPackage( void SetCurrentActionPackage(
PackageInfoRef package, PackageInfoRef package,