1/*
2 * Copyright (C) 2010 Stephan A��mus <superstippi@gmx.de>
3 *
4 * All rights reserved. Distributed under the terms of the MIT License.
5 */
6#ifndef DOWNLOAD_PROGRESS_VIEW_H
7#define DOWNLOAD_PROGRESS_VIEW_H
8
9
10#include <GroupView.h>
11#include <Path.h>
12#include <String.h>
13
14class BEntry;
15class BStatusBar;
16class BStringView;
17class BWebDownload;
18class IconView;
19class SmallButton;
20
21
22enum {
23	SAVE_SETTINGS = 'svst'
24};
25
26
27class DownloadProgressView : public BGroupView {
28public:
29								DownloadProgressView(BWebDownload* download);
30								DownloadProgressView(const BMessage* archive);
31
32			bool				Init(BMessage* archive = NULL);
33
34			status_t			SaveSettings(BMessage* archive);
35	virtual	void				AttachedToWindow();
36	virtual	void				DetachedFromWindow();
37	virtual	void				AllAttached();
38
39	virtual	void				Draw(BRect updateRect);
40
41	virtual	void				MessageReceived(BMessage* message);
42
43			void				ShowContextMenu(BPoint screenWhere);
44
45			BWebDownload*		Download() const;
46			const BString&		URL() const;
47			bool				IsMissing() const;
48			bool				IsFinished() const;
49
50			void				DownloadFinished();
51			void				CancelDownload();
52
53	static	void				SpeedVersusEstimatedFinishTogglePulse();
54
55private:
56			void				_UpdateStatus(off_t currentSize,
57									off_t expectedSize);
58			void				_UpdateStatusText();
59			void				_StartNodeMonitor(const BEntry& entry);
60			void				_StopNodeMonitor();
61
62private:
63			IconView*			fIconView;
64			BStatusBar*			fStatusBar;
65			BStringView*		fInfoView;
66			SmallButton*		fTopButton;
67			SmallButton*		fBottomButton;
68			BWebDownload*		fDownload;
69			BString				fURL;
70			BPath				fPath;
71
72			off_t				fCurrentSize;
73			off_t				fExpectedSize;
74			off_t				fLastSpeedReferenceSize;
75			off_t				fEstimatedFinishReferenceSize;
76			bigtime_t			fLastUpdateTime;
77			bigtime_t			fLastSpeedReferenceTime;
78			bigtime_t			fProcessStartTime;
79			bigtime_t			fLastSpeedUpdateTime;
80			bigtime_t			fEstimatedFinishReferenceTime;
81	static	const size_t		kBytesPerSecondSlots = 10;
82			size_t				fCurrentBytesPerSecondSlot;
83			double				fBytesPerSecondSlot[kBytesPerSecondSlots];
84			double				fBytesPerSecond;
85
86	static	bigtime_t			sLastEstimatedFinishSpeedToggleTime;
87	static	bool				sShowSpeed;
88};
89
90#endif // DOWNLOAD_PROGRESS_VIEW_H
91