WebPositive: Animate indeterminate downloads for unknown sizes

* Use BarberPole to visually indicate download activity when the
  total file size is unknown, consistent with other parts of the UI.
* Show "2 GB received, 1.2 MiB/s" in the info label instead of the
  incorrect "2 GB of 0 bytes" text that appeared previously.

Change-Id: Ia8985e03f55202dd5d55197a76464e4717779e1f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10385
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
Yash Suthar
2026-03-20 21:55:00 +00:00
committed by Adrien Destugues
parent 9e7b79a90e
commit 85a56fe86c
2 changed files with 71 additions and 14 deletions
+67 -14
View File
@@ -231,6 +231,16 @@ DownloadProgressView::Init(BMessage* archive)
fStatusBar = new BStatusBar("download progress", "Download"); fStatusBar = new BStatusBar("download progress", "Download");
fStatusBar->SetMaxValue(100); fStatusBar->SetMaxValue(100);
fStatusBar->SetBarHeight(12); fStatusBar->SetBarHeight(12);
fStatusBar->SetExplicitMinSize(BSize(0, B_SIZE_UNSET));
fFileNameView = new BStringView("download progress label", fStatusBar->Label());
fFileNameView->SetTruncation(B_TRUNCATE_END);
fFileNameView->SetExplicitMinSize(BSize(0, B_SIZE_UNSET));
fFileNameView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
fBarberPole = new BarberPole("barber pole");
fBarberPole->SetExplicitMinSize(BSize(0, fStatusBar->BarHeight()));
fBarberPole->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, fStatusBar->BarHeight()));
// fPath is only valid when constructed from archive (fDownload == NULL) // fPath is only valid when constructed from archive (fDownload == NULL)
BEntry entry(fPath.Path()); BEntry entry(fPath.Path());
@@ -275,9 +285,13 @@ DownloadProgressView::Init(BMessage* archive)
layout->AddView(fIconView); layout->AddView(fIconView);
BView* verticalGroup = BGroupLayoutBuilder(B_VERTICAL, 3) BView* verticalGroup = BGroupLayoutBuilder(B_VERTICAL, 3)
.Add(fStatusBar) .Add(fStatusBar)
.Add(fFileNameView)
.Add(fBarberPole)
.Add(fInfoView) .Add(fInfoView)
.TopView() .TopView()
; ;
fFileNameView->Hide();
fBarberPole->Hide();
verticalGroup->SetViewColor(ViewColor()); verticalGroup->SetViewColor(ViewColor());
layout->AddView(verticalGroup); layout->AddView(verticalGroup);
@@ -381,6 +395,7 @@ DownloadProgressView::MessageReceived(BMessage* message)
BEntry entry(fPath.Path()); BEntry entry(fPath.Path());
fIconView->SetTo(entry); fIconView->SetTo(entry);
fStatusBar->Reset(fPath.Leaf()); fStatusBar->Reset(fPath.Leaf());
fFileNameView->SetText(fPath.Leaf());
_StartNodeMonitor(entry); _StartNodeMonitor(entry);
// Immediately switch to speed display whenever a new download // Immediately switch to speed display whenever a new download
@@ -509,6 +524,7 @@ DownloadProgressView::MessageReceived(BMessage* message)
float value = fStatusBar->CurrentValue(); float value = fStatusBar->CurrentValue();
fStatusBar->Reset(name); fStatusBar->Reset(name);
fStatusBar->SetTo(value); fStatusBar->SetTo(value);
fFileNameView->SetText(name);
Window()->PostMessage(SAVE_SETTINGS); Window()->PostMessage(SAVE_SETTINGS);
break; break;
} }
@@ -619,7 +635,13 @@ void
DownloadProgressView::DownloadFinished() DownloadProgressView::DownloadFinished()
{ {
fDownload = NULL; fDownload = NULL;
if (fExpectedSize == -1) { if (fExpectedSize <= 0) {
if (fStatusBar->IsHidden()) {
fStatusBar->Show();
fFileNameView->Hide();
fBarberPole->Hide();
fBarberPole->Stop();
}
fStatusBar->SetTo(100.0); fStatusBar->SetTo(100.0);
fExpectedSize = fCurrentSize; fExpectedSize = fCurrentSize;
} }
@@ -653,6 +675,15 @@ DownloadProgressView::CancelDownload()
if (fDownload) { if (fDownload) {
// Also cancel the download // Also cancel the download
fDownload->Cancel(); fDownload->Cancel();
if (fStatusBar->IsHidden()) {
fStatusBar->Show();
fFileNameView->Hide();
fBarberPole->Hide();
fBarberPole->Stop();
fStatusBar->SetTo(100.0);
}
BNotification success(B_ERROR_NOTIFICATION); BNotification success(B_ERROR_NOTIFICATION);
success.SetGroup(B_TRANSLATE_SYSTEM_NAME("WebPositive")); success.SetGroup(B_TRANSLATE_SYSTEM_NAME("WebPositive"));
success.SetTitle(B_TRANSLATE("Download aborted")); success.SetTitle(B_TRANSLATE("Download aborted"));
@@ -705,7 +736,21 @@ DownloadProgressView::_UpdateStatus(off_t currentSize, off_t expectedSize)
fCurrentSize = currentSize; fCurrentSize = currentSize;
fExpectedSize = expectedSize; fExpectedSize = expectedSize;
fStatusBar->SetTo(100.0 * currentSize / expectedSize);
if (expectedSize > 0) {
if (fStatusBar->IsHidden()) {
fStatusBar->Show();
fFileNameView->Hide();
fBarberPole->Hide();
fBarberPole->Stop();
}
fStatusBar->SetTo(100.0 * currentSize / expectedSize);
} else if (!fStatusBar->IsHidden()) {
fStatusBar->Hide();
fFileNameView->Show();
fBarberPole->Show();
fBarberPole->Start();
}
bigtime_t currentTime = system_time(); bigtime_t currentTime = system_time();
if ((currentTime - fLastUpdateTime) > kMaxUpdateInterval) { if ((currentTime - fLastUpdateTime) > kMaxUpdateInterval) {
@@ -741,7 +786,7 @@ DownloadProgressView::_UpdateStatusText()
{ {
fInfoView->SetText(""); fInfoView->SetText("");
BString buffer; BString buffer;
if (sShowSpeed && fBytesPerSecond != 0.0) { if ((sShowSpeed && fBytesPerSecond != 0.0) || fExpectedSize <= 0) {
// Draw speed info // Draw speed info
char sizeBuffer[128]; char sizeBuffer[128];
// Get strings for current and expected size and remove the unit // Get strings for current and expected size and remove the unit
@@ -749,19 +794,27 @@ DownloadProgressView::_UpdateStatusText()
// size unit. // size unit.
BString currentSize = string_for_size((double)fCurrentSize, sizeBuffer, BString currentSize = string_for_size((double)fCurrentSize, sizeBuffer,
sizeof(sizeBuffer)); sizeof(sizeBuffer));
BString expectedSize = string_for_size((double)fExpectedSize, sizeBuffer,
sizeof(sizeBuffer)); if (fExpectedSize > 0) {
int currentSizeUnitPos = currentSize.FindLast(' '); BString expectedSize
int expectedSizeUnitPos = expectedSize.FindLast(' '); = string_for_size((double)fExpectedSize, sizeBuffer, sizeof(sizeBuffer));
if (currentSizeUnitPos >= 0 && expectedSizeUnitPos >= 0 int currentSizeUnitPos = currentSize.FindLast(' ');
&& strcmp(currentSize.String() + currentSizeUnitPos, int expectedSizeUnitPos = expectedSize.FindLast(' ');
expectedSize.String() + expectedSizeUnitPos) == 0) { if (currentSizeUnitPos >= 0 && expectedSizeUnitPos >= 0
currentSize.Truncate(currentSizeUnitPos); && strcmp(currentSize.String() + currentSizeUnitPos,
expectedSize.String() + expectedSizeUnitPos)
== 0) {
currentSize.Truncate(currentSizeUnitPos);
}
buffer = B_TRANSLATE("(%currentSize% of %expectedSize%, %rate%/s)");
buffer.ReplaceFirst("%currentSize%", currentSize);
buffer.ReplaceFirst("%expectedSize%", expectedSize);
} else {
buffer = B_TRANSLATE("(%currentSize% received, %rate%/s)");
buffer.ReplaceFirst("%currentSize%", currentSize);
} }
buffer = B_TRANSLATE("(%currentSize% of %expectedSize%, %rate%/s)");
buffer.ReplaceFirst("%currentSize%", currentSize);
buffer.ReplaceFirst("%expectedSize%", expectedSize);
buffer.ReplaceFirst("%rate%", string_for_size(fBytesPerSecond, buffer.ReplaceFirst("%rate%", string_for_size(fBytesPerSecond,
sizeBuffer, sizeof(sizeBuffer))); sizeBuffer, sizeof(sizeBuffer)));
@@ -10,6 +10,8 @@
#include <GroupView.h> #include <GroupView.h>
#include <Path.h> #include <Path.h>
#include <String.h> #include <String.h>
#include <shared/BarberPole.h>
class BEntry; class BEntry;
class BStatusBar; class BStatusBar;
@@ -62,6 +64,8 @@ private:
private: private:
IconView* fIconView; IconView* fIconView;
BStatusBar* fStatusBar; BStatusBar* fStatusBar;
BarberPole* fBarberPole;
BStringView* fFileNameView;
BStringView* fInfoView; BStringView* fInfoView;
SmallButton* fTopButton; SmallButton* fTopButton;
SmallButton* fBottomButton; SmallButton* fBottomButton;