HaikuDepot: Implement download progress handling.
- PackageManager: Add simple progress listener class for other parts of depot to use, which in turn is notified when the user interaction handler's download progress hook is called. - InstallAction: Implement progress listener interface and add self as listener when initiating a package installation. This gets basic download progress reporting working in Depot, but isn't yet complete, as, with the current implementation it doesn't properly handle any dependent packages that might get downloaded, since InstallAction currently only knows about the package info that it's directly responsible for. Needs a bit more work to handle that correctly.
This commit is contained in:
parent
647fb4ed35
commit
47b36c83e9
@ -43,14 +43,24 @@ using BPackageKit::BSolverPackage;
|
||||
using BPackageKit::BSolverRepository;
|
||||
|
||||
|
||||
// #pragma mark - DownloadProgressListener
|
||||
|
||||
|
||||
DownloadProgressListener::~DownloadProgressListener()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - InstallPackageAction
|
||||
|
||||
|
||||
class InstallPackageAction : public PackageAction {
|
||||
class InstallPackageAction : public PackageAction,
|
||||
private DownloadProgressListener {
|
||||
public:
|
||||
InstallPackageAction(PackageInfoRef package)
|
||||
:
|
||||
PackageAction(PACKAGE_ACTION_INSTALL, package)
|
||||
PackageAction(PACKAGE_ACTION_INSTALL, package),
|
||||
fLastDownloadUpdate(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -66,6 +76,7 @@ public:
|
||||
| BPackageManager::B_REFRESH_REPOSITORIES);
|
||||
PackageInfoRef ref(Package());
|
||||
fPackageManager->SetCurrentActionPackage(ref, true);
|
||||
fPackageManager->AddProgressListener(this);
|
||||
const char* packageName = ref->Title().String();
|
||||
try {
|
||||
fPackageManager->Install(&packageName, 1);
|
||||
@ -84,10 +95,25 @@ public:
|
||||
return B_ERROR;;
|
||||
}
|
||||
|
||||
fPackageManager->RemoveProgressListener(this);
|
||||
ref->SetState(ACTIVATED);
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
// DownloadProgressListener
|
||||
virtual void DownloadProgressChanged(float progress)
|
||||
{
|
||||
bigtime_t now = system_time();
|
||||
if (now - fLastDownloadUpdate > 250000) {
|
||||
PackageInfoRef ref(Package());
|
||||
ref->SetDownloadProgress(progress);
|
||||
fLastDownloadUpdate = now;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bigtime_t fLastDownloadUpdate;
|
||||
};
|
||||
|
||||
|
||||
@ -263,6 +289,20 @@ PackageManager::DownloadPackage(const BString& fileURL,
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageManager::AddProgressListener(DownloadProgressListener* listener)
|
||||
{
|
||||
fDownloadProgressListeners.AddItem(listener);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageManager::RemoveProgressListener(DownloadProgressListener* listener)
|
||||
{
|
||||
fDownloadProgressListeners.RemoveItem(listener);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageManager::HandleProblems()
|
||||
{
|
||||
@ -327,7 +367,10 @@ void
|
||||
PackageManager::ProgressPackageDownloadActive(const char* packageName,
|
||||
float completionPercentage)
|
||||
{
|
||||
// TODO: implement
|
||||
for (int32 i = 0; i < fDownloadProgressListeners.CountItems(); i++) {
|
||||
fDownloadProgressListeners.ItemAt(i)->DownloadProgressChanged(
|
||||
completionPercentage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,6 +36,17 @@ using BPackageKit::BPrivate::BDaemonClient;
|
||||
using BPackageKit::BManager::BPrivate::BPackageManager;
|
||||
|
||||
|
||||
class DownloadProgressListener {
|
||||
public:
|
||||
virtual ~DownloadProgressListener();
|
||||
|
||||
virtual void DownloadProgressChanged(float progress) = 0;
|
||||
};
|
||||
|
||||
|
||||
typedef BObjectList<DownloadProgressListener> DownloadProgressListenerList;
|
||||
|
||||
|
||||
class PackageManager : public BPackageManager,
|
||||
private BPackageManager::UserInteractionHandler {
|
||||
public:
|
||||
@ -56,6 +67,11 @@ public:
|
||||
const BEntry& targetEntry,
|
||||
const BString& checksum);
|
||||
|
||||
void AddProgressListener(
|
||||
DownloadProgressListener* listener);
|
||||
void RemoveProgressListener(
|
||||
DownloadProgressListener* listener);
|
||||
|
||||
private:
|
||||
// UserInteractionHandler
|
||||
virtual void HandleProblems();
|
||||
@ -102,6 +118,9 @@ private:
|
||||
fCurrentInstallPackage;
|
||||
BPackageKit::BSolverPackage*
|
||||
fCurrentUninstallPackage;
|
||||
|
||||
DownloadProgressListenerList
|
||||
fDownloadProgressListeners;
|
||||
};
|
||||
|
||||
#endif // PACKAGE_MANAGER_H
|
||||
|
Loading…
Reference in New Issue
Block a user