2 * Copyright 2017 Julian Harnath <julian.harnath@rwth-aachen.de>
3 * All rights reserved. Distributed under the terms of the MIT license.
7 #include "WorkStatusView.h"
9 #include <CardLayout.h>
11 #include <LayoutBuilder.h>
12 #include <SeparatorView.h>
13 #include <StatusBar.h>
14 #include <StringView.h>
18 #include "BarberPole.h"
21 #undef B_TRANSLATION_CONTEXT
22 #define B_TRANSLATION_CONTEXT "WorkStatusView"
25 WorkStatusView::WorkStatusView(const char* name
)
28 fProgressBar(new BStatusBar("progress bar")),
29 fBarberPole(new BarberPole("barber pole")),
30 fProgressLayout(new BCardLayout()),
31 fProgressView(new BView("progress view", 0)),
32 fStatusText(new BStringView("status text", NULL
))
34 fProgressView
->SetLayout(fProgressLayout
);
35 fProgressLayout
->AddView(fBarberPole
);
36 fProgressLayout
->AddView(fProgressBar
);
38 fProgressBar
->SetMaxValue(1.0f
);
39 fProgressBar
->SetBarHeight(20);
41 fStatusText
->SetFontSize(be_plain_font
->Size() * 0.9f
);
43 BLayoutBuilder::Group
<>(this, B_VERTICAL
, 0)
44 .Add(new BSeparatorView())
45 .AddGroup(B_HORIZONTAL
)
46 .SetInsets(5, 2, 5, 2)
47 .Add(fProgressLayout
, 0.2f
)
55 WorkStatusView::~WorkStatusView()
61 WorkStatusView::SetBusy(const BString
& text
)
69 WorkStatusView::SetBusy()
72 if (fProgressLayout
->VisibleIndex() != 0)
73 fProgressLayout
->SetVisibleItem((int32
)0);
78 WorkStatusView::SetIdle()
81 fProgressLayout
->SetVisibleItem((int32
)0);
87 WorkStatusView::SetProgress(float value
)
89 fProgressBar
->SetTo(value
);
90 if (fProgressLayout
->VisibleIndex() != 1)
91 fProgressLayout
->SetVisibleItem(1);
96 WorkStatusView::SetText(const BString
& text
)
98 fStatusText
->SetText(text
);
103 WorkStatusView::PackageStatusChanged(const PackageInfoRef
& package
)
105 switch (package
->State()) {
107 fPendingPackages
.erase(package
->Name());
108 if (package
->Name() != fDownloadingPackage
) {
109 fDownloadingPackage
= package
->Name();
110 _SetTextDownloading(package
->Title());
112 SetProgress(package
->DownloadProgress());
116 fPendingPackages
.insert(package
->Name());
117 if (package
->Name() == fDownloadingPackage
)
118 fDownloadingPackage
= "";
119 if (fDownloadingPackage
.IsEmpty()) {
120 _SetTextPendingDownloads();
129 if (package
->Name() == fDownloadingPackage
)
130 fDownloadingPackage
= "";
131 fPendingPackages
.erase(package
->Name());
132 if (fPendingPackages
.empty())
135 _SetTextPendingDownloads();
144 WorkStatusView::_SetTextPendingDownloads()
147 const size_t pendingCount
= fPendingPackages
.size();
148 text
<< pendingCount
;
149 if (pendingCount
> 1)
150 text
<< B_TRANSLATE(" packages to download");
152 text
<< B_TRANSLATE(" package to download");
158 WorkStatusView::_SetTextDownloading(const BString
& title
)
160 BString
text(B_TRANSLATE("Downloading package "));
162 if (!fPendingPackages
.empty()) {
164 text
<< fPendingPackages
.size();
165 text
<< B_TRANSLATE(" more to download)");