From dea8809802047297cfc62d34a3af9201c0a9fa24 Mon Sep 17 00:00:00 2001
From: Stefano Ceccherini <stefano.ceccherini@gmail.com>
Date: Fri, 22 Jan 2016 21:31:43 +0100
Subject: [PATCH] Implement GlobalProgressView which shows, for now, the
download progress of single packages
---
src/apps/haikudepot/Jamfile | 2 +
src/apps/haikudepot/model/Model.cpp | 4 +-
src/apps/haikudepot/model/Model.h | 29 +++++++++++++++
src/apps/haikudepot/model/PackageAction.cpp | 2 +
src/apps/haikudepot/ui/GlobalProgressView.cpp | 53 +++++++++++++++++++++++++++
src/apps/haikudepot/ui/GlobalProgressView.h | 27 ++++++++++++++
src/apps/haikudepot/ui/MainWindow.cpp | 3 ++
src/apps/haikudepot/ui/MainWindow.h | 2 +
8 files changed, 121 insertions(+), 1 deletion(-)
create mode 100644 src/apps/haikudepot/ui/GlobalProgressView.cpp
create mode 100644 src/apps/haikudepot/ui/GlobalProgressView.h
diff --git a/src/apps/haikudepot/Jamfile b/src/apps/haikudepot/Jamfile
index 30cc734..7bfcf26 100644
a
|
b
|
Application HaikuDepot :
|
49 | 49 | DecisionProvider.cpp |
50 | 50 | FeaturedPackagesView.cpp |
51 | 51 | FilterView.cpp |
| 52 | GlobalProgressView.cpp |
52 | 53 | JobStateListener.cpp |
53 | 54 | LinkView.cpp |
54 | 55 | LinkedBitmapView.cpp |
… |
… |
DoCatalogs HaikuDepot :
|
92 | 93 | App.cpp |
93 | 94 | FeaturedPackagesView.cpp |
94 | 95 | FilterView.cpp |
| 96 | GlobalProgressView.cpp |
95 | 97 | MainWindow.cpp |
96 | 98 | Model.cpp |
97 | 99 | PackageContentsView.cpp |
diff --git a/src/apps/haikudepot/model/Model.cpp b/src/apps/haikudepot/model/Model.cpp
index 289e5e9..3f78e61 100644
a
|
b
|
Model::Model()
|
355 | 355 | fShowDevelopPackages(false), |
356 | 356 | |
357 | 357 | fPopulateAllPackagesThread(-1), |
358 | | fStopPopulatingAllPackages(false) |
| 358 | fStopPopulatingAllPackages(false), |
| 359 | fGlobalProgressListener(new GlobalProgressListener()) |
359 | 360 | { |
360 | 361 | _UpdateIsFeaturedFilter(); |
361 | 362 | |
… |
… |
Model::Model()
|
410 | 411 | |
411 | 412 | Model::~Model() |
412 | 413 | { |
| 414 | delete fGlobalProgressListener; |
413 | 415 | StopPopulatingAllPackages(); |
414 | 416 | } |
415 | 417 | |
diff --git a/src/apps/haikudepot/model/Model.h b/src/apps/haikudepot/model/Model.h
index 36454a9..ba73997 100644
a
|
b
|
|
9 | 9 | #include <Locker.h> |
10 | 10 | |
11 | 11 | #include "PackageInfo.h" |
| 12 | #include "PackageManager.h" |
12 | 13 | #include "WebAppInterface.h" |
13 | 14 | |
| 15 | #include <iostream> |
14 | 16 | |
15 | 17 | class BFile; |
16 | 18 | class BMessage; |
… |
… |
typedef BReference<ModelListener> ModelListenerRef;
|
39 | 41 | typedef List<ModelListenerRef, false> ModelListenerList; |
40 | 42 | |
41 | 43 | |
| 44 | class GlobalProgressListener : public PackageProgressListener { |
| 45 | public: |
| 46 | GlobalProgressListener() {}; |
| 47 | virtual ~GlobalProgressListener() {}; |
| 48 | const char* PackageName() const { return fPackageName.String(); } |
| 49 | float Progress() const { return fProgress; } |
| 50 | private: |
| 51 | virtual void DownloadProgressChanged( |
| 52 | const char* packageName, |
| 53 | float progress) |
| 54 | { |
| 55 | fPackageName = packageName; |
| 56 | fProgress = progress; |
| 57 | } |
| 58 | virtual void DownloadProgressComplete( |
| 59 | const char* packageName) |
| 60 | { |
| 61 | fPackageName = packageName; |
| 62 | } |
| 63 | private: |
| 64 | BString fPackageName; |
| 65 | float fProgress; |
| 66 | }; |
| 67 | |
42 | 68 | class Model { |
43 | 69 | public: |
44 | 70 | Model(); |
… |
… |
public:
|
144 | 170 | const WebAppInterface& GetWebAppInterface() const |
145 | 171 | { return fWebAppInterface; } |
146 | 172 | |
| 173 | PackageProgressListener* GetGlobalProgressListener() |
| 174 | { return fGlobalProgressListener; } |
147 | 175 | |
148 | 176 | private: |
149 | 177 | void _UpdateIsFeaturedFilter(); |
… |
… |
private:
|
231 | 259 | WebAppInterface fWebAppInterface; |
232 | 260 | |
233 | 261 | ModelListenerList fListeners; |
| 262 | GlobalProgressListener* fGlobalProgressListener; |
234 | 263 | }; |
235 | 264 | |
236 | 265 | |
diff --git a/src/apps/haikudepot/model/PackageAction.cpp b/src/apps/haikudepot/model/PackageAction.cpp
index ee14c5c..48b2b8f 100644
a
|
b
|
PackageAction::PackageAction(int32 type, PackageInfoRef package, Model* model)
|
29 | 29 | // TODO: allow configuring the installation location |
30 | 30 | fPackageManager = new(std::nothrow) PackageManager( |
31 | 31 | (BPackageInstallationLocation)fInstallLocation); |
| 32 | fPackageManager->AddProgressListener(fModel->GetGlobalProgressListener()); |
32 | 33 | } |
33 | 34 | |
34 | 35 | |
35 | 36 | PackageAction::~PackageAction() |
36 | 37 | { |
| 38 | fPackageManager->RemoveProgressListener(fModel->GetGlobalProgressListener()); |
37 | 39 | delete fPackageManager; |
38 | 40 | } |
39 | 41 | |
diff --git a/src/apps/haikudepot/ui/GlobalProgressView.cpp b/src/apps/haikudepot/ui/GlobalProgressView.cpp
new file mode 100644
index 0000000..23cf022
-
|
+
|
|
| 1 | /* |
| 2 | * GlobalProgressView.cpp |
| 3 | * |
| 4 | * Created on: 17/gen/2016 |
| 5 | * Author: stefano |
| 6 | */ |
| 7 | |
| 8 | #include "GlobalProgressView.h" |
| 9 | |
| 10 | #include "MainWindow.h" |
| 11 | #include "Model.h" |
| 12 | |
| 13 | #include <LayoutBuilder.h> |
| 14 | #include <StringView.h> |
| 15 | |
| 16 | #include <iostream> |
| 17 | |
| 18 | GlobalProgressView::GlobalProgressView(Model& model) |
| 19 | : |
| 20 | BGroupView("global_progress_view", B_VERTICAL), |
| 21 | fModel(model) |
| 22 | { |
| 23 | BLayoutBuilder::Group<>(this) |
| 24 | .AddGroup(B_HORIZONTAL) |
| 25 | .Add(fStringView = new BStringView("Progress", "")) |
| 26 | .End(); |
| 27 | SetFlags(Flags() | B_PULSE_NEEDED); |
| 28 | } |
| 29 | |
| 30 | |
| 31 | GlobalProgressView::~GlobalProgressView() |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | |
| 36 | /* virtual */ |
| 37 | void |
| 38 | GlobalProgressView::AttachedToWindow() |
| 39 | { |
| 40 | Window()->SetPulseRate(20000); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | /* virtual */ |
| 45 | void |
| 46 | GlobalProgressView::Pulse() |
| 47 | { |
| 48 | GlobalProgressListener* progressListener = (GlobalProgressListener*)fModel.GetGlobalProgressListener(); |
| 49 | BString text; |
| 50 | text << "Dowloading " << progressListener->PackageName(); |
| 51 | text << ": " << (progressListener->Progress() * 100); |
| 52 | fStringView->SetText(text.String()); |
| 53 | } |
diff --git a/src/apps/haikudepot/ui/GlobalProgressView.h b/src/apps/haikudepot/ui/GlobalProgressView.h
new file mode 100644
index 0000000..1c04c0d
-
|
+
|
|
| 1 | /* |
| 2 | * GlobalProgressView.h |
| 3 | * |
| 4 | * Created on: 17/gen/2016 |
| 5 | * Author: stefano |
| 6 | */ |
| 7 | |
| 8 | #ifndef SRC_APPS_HAIKUDEPOT_UI_GLOBALPROGRESSVIEW_H_ |
| 9 | #define SRC_APPS_HAIKUDEPOT_UI_GLOBALPROGRESSVIEW_H_ |
| 10 | |
| 11 | #include <GroupView.h> |
| 12 | |
| 13 | #include "PackageManager.h" |
| 14 | |
| 15 | class BStringView; |
| 16 | class GlobalProgressView: public BGroupView { |
| 17 | public: |
| 18 | GlobalProgressView(Model& model); |
| 19 | virtual ~GlobalProgressView(); |
| 20 | virtual void AttachedToWindow(); |
| 21 | virtual void Pulse(); |
| 22 | private: |
| 23 | Model& fModel; |
| 24 | BStringView* fStringView; |
| 25 | }; |
| 26 | |
| 27 | #endif /* SRC_APPS_HAIKUDEPOT_UI_GLOBALPROGRESSVIEW_H_ */ |
diff --git a/src/apps/haikudepot/ui/MainWindow.cpp b/src/apps/haikudepot/ui/MainWindow.cpp
index b9f7529..b11781e 100644
a
|
b
|
|
46 | 46 | #include "DecisionProvider.h" |
47 | 47 | #include "FeaturedPackagesView.h" |
48 | 48 | #include "FilterView.h" |
| 49 | #include "GlobalProgressView.h" |
49 | 50 | #include "JobStateListener.h" |
50 | 51 | #include "PackageInfoView.h" |
51 | 52 | #include "PackageListView.h" |
… |
… |
MainWindow::MainWindow(const BMessage& settings)
|
143 | 144 | fFeaturedPackagesView = new FeaturedPackagesView(); |
144 | 145 | fPackageListView = new PackageListView(fModel.Lock()); |
145 | 146 | fPackageInfoView = new PackageInfoView(fModel.Lock(), this); |
| 147 | fGlobalProgressView = new GlobalProgressView(fModel); |
146 | 148 | |
147 | 149 | fSplitView = new BSplitView(B_VERTICAL, 5.0f); |
148 | 150 | |
… |
… |
MainWindow::MainWindow(const BMessage& settings)
|
178 | 180 | B_USE_DEFAULT_SPACING, 0.0f, |
179 | 181 | B_USE_DEFAULT_SPACING, 0.0f) |
180 | 182 | .End() |
| 183 | .Add(fGlobalProgressView) |
181 | 184 | .Add(fPackageInfoView) |
182 | 185 | .End() |
183 | 186 | ; |
diff --git a/src/apps/haikudepot/ui/MainWindow.h b/src/apps/haikudepot/ui/MainWindow.h
index 784350a..4f09acf 100644
a
|
b
|
class BMenuItem;
|
20 | 20 | class BSplitView; |
21 | 21 | class FeaturedPackagesView; |
22 | 22 | class FilterView; |
| 23 | class GlobalProgressView; |
23 | 24 | class PackageActionsView; |
24 | 25 | class PackageInfoView; |
25 | 26 | class PackageListView; |
… |
… |
private:
|
94 | 95 | FeaturedPackagesView* fFeaturedPackagesView; |
95 | 96 | PackageListView* fPackageListView; |
96 | 97 | PackageInfoView* fPackageInfoView; |
| 98 | GlobalProgressView* fGlobalProgressView; |
97 | 99 | BSplitView* fSplitView; |
98 | 100 | |
99 | 101 | ScreenshotWindow* fScreenshotWindow; |