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.
This commit is contained in:
Stephan Aßmus
2013-11-24 22:45:54 +01:00
parent bab9e168ab
commit 8589dae5e8
+60 -10
View File
@@ -22,6 +22,7 @@
#include <TabView.h> #include <TabView.h>
#include <ScrollView.h> #include <ScrollView.h>
#include <SpaceLayoutItem.h> #include <SpaceLayoutItem.h>
#include <StatusBar.h>
#include <StringView.h> #include <StringView.h>
#include <support/Url.h> #include <support/Url.h>
@@ -502,7 +503,9 @@ public:
: :
BView("about view", B_WILL_DRAW), BView("about view", B_WILL_DRAW),
fLayout(new BGroupLayout(B_HORIZONTAL)), fLayout(new BGroupLayout(B_HORIZONTAL)),
fPackageActionHandler(handler) fPackageActionHandler(handler),
fStatusLabel(NULL),
fStatusBar(NULL)
{ {
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
@@ -546,6 +549,16 @@ public:
} }
void SetPackage(const PackageInfo& package) void SetPackage(const PackageInfo& package)
{
if (package.State() == DOWNLOADING) {
AdoptDownloadProgress(package);
} else {
AdoptActions(package);
}
}
void AdoptActions(const PackageInfo& package)
{ {
PackageManager manager( PackageManager manager(
BPackageKit::B_PACKAGE_INSTALLATION_LOCATION_HOME); BPackageKit::B_PACKAGE_INSTALLATION_LOCATION_HOME);
@@ -557,15 +570,17 @@ public:
const_cast<PackageInfo*>(&package), const_cast<PackageInfo*>(&package),
fPackageActionHandler->GetModel()); fPackageActionHandler->GetModel());
bool clearNeeded = false; bool clearNeeded = fStatusBar != NULL;
if (actions.CountItems() != fPackageActions.CountItems()) if (!clearNeeded) {
clearNeeded = true; if (actions.CountItems() != fPackageActions.CountItems())
else { clearNeeded = true;
for (int32 i = 0; i < actions.CountItems(); i++) { else {
if (actions.ItemAtFast(i)->Type() for (int32 i = 0; i < actions.CountItems(); i++) {
!= fPackageActions.ItemAtFast(i)->Type()) { if (actions.ItemAtFast(i)->Type()
clearNeeded = true; != fPackageActions.ItemAtFast(i)->Type()) {
break; 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() void Clear()
{ {
for (int32 i = fButtons.CountItems() - 1; i >= 0; i--) { for (int32 i = fButtons.CountItems() - 1; i >= 0; i--) {
@@ -599,6 +635,17 @@ public:
delete button; delete button;
} }
fButtons.MakeEmpty(); fButtons.MakeEmpty();
if (fStatusBar != NULL) {
fStatusBar->RemoveSelf();
delete fStatusBar;
fStatusBar = NULL;
}
if (fStatusLabel != NULL) {
fStatusLabel->RemoveSelf();
delete fStatusLabel;
fStatusLabel = NULL;
}
} }
private: private:
@@ -606,6 +653,9 @@ private:
PackageActionList fPackageActions; PackageActionList fPackageActions;
PackageActionHandler* fPackageActionHandler; PackageActionHandler* fPackageActionHandler;
BList fButtons; BList fButtons;
BStringView* fStatusLabel;
BStatusBar* fStatusBar;
}; };