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:
committed by
Adrien Destugues
parent
9e7b79a90e
commit
85a56fe86c
@@ -231,6 +231,16 @@ DownloadProgressView::Init(BMessage* archive)
|
||||
fStatusBar = new BStatusBar("download progress", "Download");
|
||||
fStatusBar->SetMaxValue(100);
|
||||
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)
|
||||
BEntry entry(fPath.Path());
|
||||
@@ -275,9 +285,13 @@ DownloadProgressView::Init(BMessage* archive)
|
||||
layout->AddView(fIconView);
|
||||
BView* verticalGroup = BGroupLayoutBuilder(B_VERTICAL, 3)
|
||||
.Add(fStatusBar)
|
||||
.Add(fFileNameView)
|
||||
.Add(fBarberPole)
|
||||
.Add(fInfoView)
|
||||
.TopView()
|
||||
;
|
||||
fFileNameView->Hide();
|
||||
fBarberPole->Hide();
|
||||
verticalGroup->SetViewColor(ViewColor());
|
||||
layout->AddView(verticalGroup);
|
||||
|
||||
@@ -381,6 +395,7 @@ DownloadProgressView::MessageReceived(BMessage* message)
|
||||
BEntry entry(fPath.Path());
|
||||
fIconView->SetTo(entry);
|
||||
fStatusBar->Reset(fPath.Leaf());
|
||||
fFileNameView->SetText(fPath.Leaf());
|
||||
_StartNodeMonitor(entry);
|
||||
|
||||
// Immediately switch to speed display whenever a new download
|
||||
@@ -509,6 +524,7 @@ DownloadProgressView::MessageReceived(BMessage* message)
|
||||
float value = fStatusBar->CurrentValue();
|
||||
fStatusBar->Reset(name);
|
||||
fStatusBar->SetTo(value);
|
||||
fFileNameView->SetText(name);
|
||||
Window()->PostMessage(SAVE_SETTINGS);
|
||||
break;
|
||||
}
|
||||
@@ -619,7 +635,13 @@ void
|
||||
DownloadProgressView::DownloadFinished()
|
||||
{
|
||||
fDownload = NULL;
|
||||
if (fExpectedSize == -1) {
|
||||
if (fExpectedSize <= 0) {
|
||||
if (fStatusBar->IsHidden()) {
|
||||
fStatusBar->Show();
|
||||
fFileNameView->Hide();
|
||||
fBarberPole->Hide();
|
||||
fBarberPole->Stop();
|
||||
}
|
||||
fStatusBar->SetTo(100.0);
|
||||
fExpectedSize = fCurrentSize;
|
||||
}
|
||||
@@ -653,6 +675,15 @@ DownloadProgressView::CancelDownload()
|
||||
if (fDownload) {
|
||||
// Also cancel the download
|
||||
fDownload->Cancel();
|
||||
|
||||
if (fStatusBar->IsHidden()) {
|
||||
fStatusBar->Show();
|
||||
fFileNameView->Hide();
|
||||
fBarberPole->Hide();
|
||||
fBarberPole->Stop();
|
||||
fStatusBar->SetTo(100.0);
|
||||
}
|
||||
|
||||
BNotification success(B_ERROR_NOTIFICATION);
|
||||
success.SetGroup(B_TRANSLATE_SYSTEM_NAME("WebPositive"));
|
||||
success.SetTitle(B_TRANSLATE("Download aborted"));
|
||||
@@ -705,7 +736,21 @@ DownloadProgressView::_UpdateStatus(off_t currentSize, off_t expectedSize)
|
||||
fCurrentSize = currentSize;
|
||||
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();
|
||||
if ((currentTime - fLastUpdateTime) > kMaxUpdateInterval) {
|
||||
@@ -741,7 +786,7 @@ DownloadProgressView::_UpdateStatusText()
|
||||
{
|
||||
fInfoView->SetText("");
|
||||
BString buffer;
|
||||
if (sShowSpeed && fBytesPerSecond != 0.0) {
|
||||
if ((sShowSpeed && fBytesPerSecond != 0.0) || fExpectedSize <= 0) {
|
||||
// Draw speed info
|
||||
char sizeBuffer[128];
|
||||
// Get strings for current and expected size and remove the unit
|
||||
@@ -749,19 +794,27 @@ DownloadProgressView::_UpdateStatusText()
|
||||
// size unit.
|
||||
BString currentSize = string_for_size((double)fCurrentSize, sizeBuffer,
|
||||
sizeof(sizeBuffer));
|
||||
BString expectedSize = string_for_size((double)fExpectedSize, sizeBuffer,
|
||||
sizeof(sizeBuffer));
|
||||
int currentSizeUnitPos = currentSize.FindLast(' ');
|
||||
int expectedSizeUnitPos = expectedSize.FindLast(' ');
|
||||
if (currentSizeUnitPos >= 0 && expectedSizeUnitPos >= 0
|
||||
&& strcmp(currentSize.String() + currentSizeUnitPos,
|
||||
expectedSize.String() + expectedSizeUnitPos) == 0) {
|
||||
currentSize.Truncate(currentSizeUnitPos);
|
||||
|
||||
if (fExpectedSize > 0) {
|
||||
BString expectedSize
|
||||
= string_for_size((double)fExpectedSize, sizeBuffer, sizeof(sizeBuffer));
|
||||
int currentSizeUnitPos = currentSize.FindLast(' ');
|
||||
int expectedSizeUnitPos = expectedSize.FindLast(' ');
|
||||
if (currentSizeUnitPos >= 0 && expectedSizeUnitPos >= 0
|
||||
&& 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,
|
||||
sizeBuffer, sizeof(sizeBuffer)));
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <GroupView.h>
|
||||
#include <Path.h>
|
||||
#include <String.h>
|
||||
#include <shared/BarberPole.h>
|
||||
|
||||
|
||||
class BEntry;
|
||||
class BStatusBar;
|
||||
@@ -62,6 +64,8 @@ private:
|
||||
private:
|
||||
IconView* fIconView;
|
||||
BStatusBar* fStatusBar;
|
||||
BarberPole* fBarberPole;
|
||||
BStringView* fFileNameView;
|
||||
BStringView* fInfoView;
|
||||
SmallButton* fTopButton;
|
||||
SmallButton* fBottomButton;
|
||||
|
||||
Reference in New Issue
Block a user