From 8589dae5e873cfd16d9ba96c4c168024ee58353b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 24 Nov 2013 22:42:50 +0100 Subject: [PATCH] HaikuDepot: Better feedback while installing * Replace the package action button with a download-progress bar while the package downloads. Needs some tweaks to the layout code to avoid pushing the rest of the title area to the left, but its a first step. An additional dedicated area somewhere in the UI which lists all on-going tasks would be nice as well. --- src/apps/haiku-depot/PackageInfoView.cpp | 70 ++++++++++++++++++++---- 1 file changed, 60 insertions(+), 10 deletions(-) diff --git a/src/apps/haiku-depot/PackageInfoView.cpp b/src/apps/haiku-depot/PackageInfoView.cpp index 49a1c58c12..9042386c24 100644 --- a/src/apps/haiku-depot/PackageInfoView.cpp +++ b/src/apps/haiku-depot/PackageInfoView.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -502,7 +503,9 @@ public: : BView("about view", B_WILL_DRAW), fLayout(new BGroupLayout(B_HORIZONTAL)), - fPackageActionHandler(handler) + fPackageActionHandler(handler), + fStatusLabel(NULL), + fStatusBar(NULL) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); @@ -546,6 +549,16 @@ public: } void SetPackage(const PackageInfo& package) + { + if (package.State() == DOWNLOADING) { + AdoptDownloadProgress(package); + } else { + AdoptActions(package); + } + + } + + void AdoptActions(const PackageInfo& package) { PackageManager manager( BPackageKit::B_PACKAGE_INSTALLATION_LOCATION_HOME); @@ -557,15 +570,17 @@ public: const_cast(&package), fPackageActionHandler->GetModel()); - bool clearNeeded = false; - if (actions.CountItems() != fPackageActions.CountItems()) - clearNeeded = true; - else { - for (int32 i = 0; i < actions.CountItems(); i++) { - if (actions.ItemAtFast(i)->Type() - != fPackageActions.ItemAtFast(i)->Type()) { - clearNeeded = true; - break; + bool clearNeeded = fStatusBar != NULL; + if (!clearNeeded) { + if (actions.CountItems() != fPackageActions.CountItems()) + clearNeeded = true; + else { + for (int32 i = 0; i < actions.CountItems(); i++) { + if (actions.ItemAtFast(i)->Type() + != fPackageActions.ItemAtFast(i)->Type()) { + clearNeeded = true; + break; + } } } } @@ -591,6 +606,27 @@ public: } } + void AdoptDownloadProgress(const PackageInfo& package) + { + if (fButtons.CountItems() > 0) + Clear(); + + if (fStatusBar == NULL) { + fStatusLabel = new BStringView("progress label", + B_TRANSLATE("Downloading:")); + fLayout->AddView(fStatusLabel); + + fStatusBar = new BStatusBar("progress"); + fStatusBar->SetMaxValue(100.0); + fStatusBar->SetExplicitMinSize( + BSize(StringWidth("XXX") * 5, B_SIZE_UNSET)); + + fLayout->AddView(fStatusBar); + } + + fStatusBar->SetTo(package.DownloadProgress() * 100.0); + } + void Clear() { for (int32 i = fButtons.CountItems() - 1; i >= 0; i--) { @@ -599,6 +635,17 @@ public: delete button; } fButtons.MakeEmpty(); + + if (fStatusBar != NULL) { + fStatusBar->RemoveSelf(); + delete fStatusBar; + fStatusBar = NULL; + } + if (fStatusLabel != NULL) { + fStatusLabel->RemoveSelf(); + delete fStatusLabel; + fStatusLabel = NULL; + } } private: @@ -606,6 +653,9 @@ private: PackageActionList fPackageActions; PackageActionHandler* fPackageActionHandler; BList fButtons; + + BStringView* fStatusLabel; + BStatusBar* fStatusBar; };