1/*
2 * LegacyClonk
3 *
4 * Copyright (c) RedWolf Design
5 * Copyright (c) 2007, Sven2
6 * Copyright (c) 2017-2020, The LegacyClonk Team and contributors
7 *
8 * Distributed under the terms of the ISC license; see accompanying file
9 * "COPYING" for details.
10 *
11 * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12 * See accompanying file "TRADEMARK" for details.
13 *
14 * To redistribute this file separately, substitute the full license texts
15 * for the above references.
16 */
17
18// HTTP download dialog; downloads a file
19// (like, e.g., a .c4u update group)
20
21#pragma once
22
23#include "C4Gui.h"
24#include "C4GuiDialogs.h"
25#include "C4Network2Reference.h" // includes HTTP client
26
27// dialog to download a file
28class C4DownloadDlg : public C4GUI::Dialog
29{
30private:
31 C4Network2HTTPClient HTTPClient;
32
33 C4GUI::Icon *pIcon;
34 C4GUI::Label *pStatusLabel;
35 C4GUI::ProgressBar *pProgressBar;
36 C4GUI::Button *pCancelBtn;
37 const char *szError;
38#ifdef _WIN32
39 bool fWinSock;
40#endif
41
42protected:
43 C4DownloadDlg(const char *szDLType);
44 virtual ~C4DownloadDlg();
45
46private:
47 // updates the displayed status text and progress bar - repositions elements if necessary
48 void SetStatus(const char *szNewText, int32_t iProgressPercent);
49
50protected:
51 // idle proc: Continue download; close when finished
52 virtual void OnIdle() override;
53
54 // user presses cancel button: Abort download
55 virtual void UserClose(bool fOK) override;
56
57 // downloads the specified file to the specified location. Returns whether successful
58 bool ShowModal(C4GUI::Screen *pScreen, const char *szURL, const char *szSaveAsFilename);
59
60 const char *GetError();
61
62public:
63 // download file showing download dialog; display error if download failed
64 static bool DownloadFile(const char *szDLType, C4GUI::Screen *pScreen, const char *szURL, const char *szSaveAsFilename, const char *szNotFoundMessage = nullptr);
65};
66