1 #ifndef FILEZILLA_INTERFACE_STATUSLINECTRL_HEADER
2 #define FILEZILLA_INTERFACE_STATUSLINECTRL_HEADER
3 
4 class CQueueView;
5 class CStatusLineCtrl final : public wxWindow
6 {
7 public:
8 	CStatusLineCtrl(CQueueView* pParent, const t_EngineData* const pEngineData, const wxRect& initialPosition);
9 	~CStatusLineCtrl();
10 
GetItem()11 	const CFileItem* GetItem() const { return m_pEngineData->pItem; }
12 
13 	void SetEngineData(const t_EngineData* const pEngineData);
14 
15 	void SetTransferStatus(CTransferStatus const& status);
16 	void ClearTransferStatus();
17 
GetLastOffset()18 	int64_t GetLastOffset() const { return status_.empty() ? m_lastOffset : status_.currentOffset; }
GetTotalSize()19 	int64_t GetTotalSize() const { return status_.empty() ? -1 : status_.totalSize; }
20 	wxFileOffset GetAverageSpeed(int elapsed_milli_seconds);
21 	wxFileOffset GetMomentarySpeed();
22 
23 	virtual bool Show(bool show = true);
24 
25 protected:
26 	void InitFieldOffsets();
27 
28 	void DrawRightAlignedText(wxDC& dc, wxString const& text, int x, int y);
29 	void DrawProgressBar(wxDC& dc, int x, int y, int height, int bar_split, int permill);
30 
31 	CQueueView* m_pParent;
32 	const t_EngineData* m_pEngineData;
33 	CTransferStatus status_;
34 
35 	wxString m_statusText;
36 	wxTimer m_transferStatusTimer;
37 
38 	static int m_fieldOffsets[4];
39 	static int m_barWidth;
40 	static wxCoord m_textHeight;
41 	static bool m_initialized;
42 
43 	bool m_madeProgress;
44 
45 	int64_t m_lastOffset{-1}; // Stores the last transfer offset so that the total queue size can be accurately calculated.
46 
47 	// This is used by GetSpeed to forget about the first 10 seconds on longer transfers
48 	// since at the very start the speed is hardly accurate (e.g. due to TCP slow start)
49 	struct _past_data final
50 	{
51 		int elapsed{};
52 		wxFileOffset offset{};
53 	} m_past_data[10];
54 	int m_past_data_count{};
55 
56 	//Used by GetMomentarySpeed
57 	struct monentary_speed_data {
58 		fz::monotonic_clock last_update;
59 		wxFileOffset last_offset{-1};
60 		wxFileOffset last_speed{-1};
61 	} m_monentary_speed_data;
62 
63 	//Used to avoid excessive redraws
64 	wxBitmap m_data;
65 	std::unique_ptr<wxMemoryDC> m_mdc;
66 	wxString m_previousStatusText;
67 	int m_last_elapsed_seconds{};
68 	int m_last_left{};
69 	wxString m_last_bytes_and_rate;
70 	int m_last_bar_split{-1};
71 	int m_last_permill{-1};
72 
73 	DECLARE_EVENT_TABLE()
74 	void OnPaint(wxPaintEvent& event);
75 	void OnTimer(wxTimerEvent& event);
76 	void OnEraseBackground(wxEraseEvent& event);
77 };
78 
79 #endif
80