Vital
Loading...
Searching...
No Matches
download_section.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include "JuceHeader.h"
7#include "overlay.h"
8
10
17class DownloadSection : public Overlay, public URL::DownloadTask::Listener, public Timer {
18public:
20 static const std::string kFactoryDownloadPath;
22 static constexpr int kY = 180;
24 static constexpr int kDownloadWidth = 450;
26 static constexpr int kDownloadInitialHeight = 380;
28 static constexpr int kDownloadAdditionalHeight = 324;
30 static constexpr int kTextHeight = 15;
32 static constexpr int kPaddingX = 20;
34 static constexpr int kPaddingY = 20;
36 static constexpr int kButtonHeight = 36;
38 static constexpr int kCompletionWaitMs = 1000;
39
41 struct DownloadPack {
42 DownloadPack(std::string n, std::string a, int i, URL u, File d) :
43 name(std::move(n)), author(std::move(a)), id(i), url(u), download_location(d), finished(false) { }
44 std::string name;
45 std::string author;
46 int id;
47 URL url;
49 bool finished;
50 };
51
54 class Listener {
55 public:
56 virtual ~Listener() = default;
57
59 virtual void dataDirectoryChanged() = 0;
60
62 virtual void noDownloadNeeded() = 0;
63 };
64
66 class DownloadThread : public Thread {
67 public:
68 DownloadThread(DownloadSection* ref, URL url, File dest) :
69 Thread("Vial Download Thread"), ref_(ref), url_(std::move(url)), dest_(std::move(dest)) { }
70 virtual ~DownloadThread() { }
71
72 void run() override {
73 ref_->startDownload(this, url_, dest_);
74 }
75
76 private:
77 DownloadSection* ref_;
78 URL url_;
79 File dest_;
80 };
81
83 class InstallThread : public Thread {
84 public:
85 InstallThread(DownloadSection* ref) : Thread("Vial Install Thread"), ref_(ref) { }
86 virtual ~InstallThread() { }
87
88 void run() override {
89 ref_->startInstall(this);
90 }
91
92 private:
93 DownloadSection* ref_;
94 };
95
99 DownloadSection(String name, Authentication* auth);
100
103 for (auto& thread : download_threads_)
104 thread->stopThread(300);
105 }
106
108 void resized() override;
109
112 void setVisible(bool should_be_visible) override;
113
115 void timerCallback() override {
116 stopTimer();
117 setVisible(false);
118 }
119
122 void mouseUp(const MouseEvent& e) override;
123
126 void buttonClicked(Button* clicked_button) override;
127
131 void renderOpenGlComponents(OpenGlWrapper& open_gl, bool animate) override;
132
136 void finished(URL::DownloadTask* task, bool success) override;
137
142 void progress(URL::DownloadTask* task, int64 bytesDownloaded, int64 totalLength) override;
143
146 Rectangle<int> getDownloadRect();
147
149 void triggerDownload();
150
152 void triggerInstall();
153
158 void startDownload(Thread* thread, URL& url, const File& dest);
159
162 void startInstall(Thread* thread);
163
165 void cancelDownload();
166
168 void chooseInstallFolder();
169
172 void addListener(Listener* listener) { listeners_.push_back(listener); }
173
174private:
175 Authentication* auth_;
176 OpenGlQuad body_;
177 bool cancel_;
178 bool initial_download_;
179 float progress_value_;
180
181 OpenGlQuad download_progress_;
182 OpenGlQuad download_background_;
183 OpenGlQuad install_text_background_;
184
185 std::unique_ptr<AppLogo> logo_;
186 std::unique_ptr<LoadingWheel> loading_wheel_;
187
188 std::vector<std::unique_ptr<DownloadThread>> download_threads_;
189 InstallThread install_thread_;
190
191 URL packs_url_;
192 URL factory_download_url_;
193 File available_packs_location_;
194 std::vector<DownloadPack> awaiting_install_;
195 std::vector<DownloadPack> awaiting_download_;
196
197 std::vector<std::unique_ptr<URL::DownloadTask>> download_tasks_;
198 File install_location_;
199 std::vector<Listener*> listeners_;
200
201 std::unique_ptr<OpenGlShapeButton> folder_button_;
202 std::unique_ptr<PlainTextComponent> download_text_;
203 std::unique_ptr<PlainTextComponent> install_location_text_;
204 std::unique_ptr<OpenGlToggleButton> install_button_;
205 std::unique_ptr<OpenGlToggleButton> cancel_button_;
206
207 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DownloadSection)
208};
A no-op stub implementation used when authentication is disabled.
Definition authentication.h:163
A background thread to handle downloading content without blocking the GUI.
Definition download_section.h:66
virtual ~DownloadThread()
Definition download_section.h:70
DownloadThread(DownloadSection *ref, URL url, File dest)
Definition download_section.h:68
void run() override
Definition download_section.h:72
A background thread for installing downloaded packs.
Definition download_section.h:83
void run() override
Definition download_section.h:88
InstallThread(DownloadSection *ref)
Definition download_section.h:85
virtual ~InstallThread()
Definition download_section.h:86
Interface for objects that need to respond to data directory changes or no-download scenarios.
Definition download_section.h:54
virtual void noDownloadNeeded()=0
Called when no downloads are needed (all content is up-to-date).
virtual ~Listener()=default
virtual void dataDirectoryChanged()=0
Called when the data directory changes (e.g., after a successful installation).
An overlay component handling the download and installation of factory content and packs.
Definition download_section.h:17
void timerCallback() override
Timer callback used for hiding the UI after a delay.
Definition download_section.h:115
void startDownload(Thread *thread, URL &url, const File &dest)
Definition download_section.cpp:319
void triggerInstall()
Starts the installation process after all downloads are completed.
Definition download_section.cpp:298
static constexpr int kDownloadAdditionalHeight
The additional height if more content is available.
Definition download_section.h:28
static const std::string kFactoryDownloadPath
The URL path for the factory download.
Definition download_section.h:20
void renderOpenGlComponents(OpenGlWrapper &open_gl, bool animate) override
Definition download_section.cpp:172
virtual ~DownloadSection()
Destructor.
Definition download_section.h:102
static constexpr int kDownloadWidth
The width of the download UI.
Definition download_section.h:24
void triggerDownload()
Triggers the process of checking available packs and downloading necessary content.
Definition download_section.cpp:286
static constexpr int kTextHeight
The text height for labels.
Definition download_section.h:30
Rectangle< int > getDownloadRect()
Definition download_section.cpp:275
static constexpr int kY
The vertical offset for the download UI.
Definition download_section.h:22
void mouseUp(const MouseEvent &e) override
Definition download_section.cpp:158
void cancelDownload()
Cancels all ongoing downloads.
Definition download_section.cpp:366
void setVisible(bool should_be_visible) override
Definition download_section.cpp:148
void chooseInstallFolder()
Allows the user to choose a folder for installation.
Definition download_section.cpp:372
static constexpr int kPaddingX
Horizontal padding inside the UI.
Definition download_section.h:32
void progress(URL::DownloadTask *task, int64 bytesDownloaded, int64 totalLength) override
Definition download_section.cpp:266
void startInstall(Thread *thread)
Definition download_section.cpp:323
static constexpr int kButtonHeight
Height of buttons.
Definition download_section.h:36
static constexpr int kDownloadInitialHeight
The initial height of the download UI before any content is loaded.
Definition download_section.h:26
DownloadSection(String name, Authentication *auth)
Definition download_section.cpp:17
static constexpr int kPaddingY
Vertical padding inside the UI.
Definition download_section.h:34
void resized() override
Lays out the UI components within the overlay.
Definition download_section.cpp:81
void addListener(Listener *listener)
Definition download_section.h:172
static constexpr int kCompletionWaitMs
Time in milliseconds to wait before hiding the UI after completion.
Definition download_section.h:38
void finished(URL::DownloadTask *task, bool success) override
Definition download_section.cpp:180
void buttonClicked(Button *clicked_button) override
Definition download_section.cpp:163
A convenience class for a single quad rendered via OpenGL.
Definition open_gl_multi_quad.h:447
A SynthSection that displays an overlay with a background and optional listeners.
Definition overlay.h:180
virtual void animate(bool animate)
Triggers animation state change in sub-sections if needed.
Definition synth_section.cpp:822
Represents a downloadable pack with name, author, ID, URL, and local destination file.
Definition download_section.h:41
bool finished
Whether the download is finished.
Definition download_section.h:49
std::string author
The author of the pack.
Definition download_section.h:45
int id
The pack's unique ID.
Definition download_section.h:46
std::string name
The name of the pack.
Definition download_section.h:44
File download_location
The local file where the pack is downloaded.
Definition download_section.h:48
DownloadPack(std::string n, std::string a, int i, URL u, File d)
Definition download_section.h:42
URL url
The download URL for the pack.
Definition download_section.h:47
A helper struct containing references to OpenGL context, shaders, and display scale.
Definition shaders.h:174