xref: /haiku/src/apps/webpositive/DownloadProgressView.h (revision 7a74a5df454197933bc6e80a542102362ee98703)
1 /*
2  * Copyright (C) 2010 Stephan Aßmus <superstippi@gmx.de>
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 #ifndef DOWNLOAD_PROGRESS_VIEW_H
28 #define DOWNLOAD_PROGRESS_VIEW_H
29 
30 
31 #include <GroupView.h>
32 #include <Path.h>
33 #include <String.h>
34 
35 class BEntry;
36 class BStatusBar;
37 class BStringView;
38 class BWebDownload;
39 class IconView;
40 class SmallButton;
41 
42 
43 enum {
44 	SAVE_SETTINGS = 'svst'
45 };
46 
47 
48 class DownloadProgressView : public BGroupView {
49 public:
50 								DownloadProgressView(BWebDownload* download);
51 								DownloadProgressView(const BMessage* archive);
52 
53 			bool				Init(BMessage* archive = NULL);
54 
55 			status_t			SaveSettings(BMessage* archive);
56 	virtual	void				AttachedToWindow();
57 	virtual	void				DetachedFromWindow();
58 	virtual	void				AllAttached();
59 
60 	virtual	void				Draw(BRect updateRect);
61 
62 	virtual	void				MessageReceived(BMessage* message);
63 
64 			void				ShowContextMenu(BPoint screenWhere);
65 
66 			BWebDownload*		Download() const;
67 			const BString&		URL() const;
68 			bool				IsMissing() const;
69 			bool				IsFinished() const;
70 
71 			void				DownloadFinished();
72 			void				DownloadCanceled();
73 
74 	static	void				SpeedVersusEstimatedFinishTogglePulse();
75 
76 private:
77 			void				_UpdateStatus(off_t currentSize,
78 									off_t expectedSize);
79 			void				_UpdateStatusText();
80 			void				_StartNodeMonitor(const BEntry& entry);
81 			void				_StopNodeMonitor();
82 
83 private:
84 			IconView*			fIconView;
85 			BStatusBar*			fStatusBar;
86 			BStringView*		fInfoView;
87 			SmallButton*		fTopButton;
88 			SmallButton*		fBottomButton;
89 			BWebDownload*		fDownload;
90 			BString				fURL;
91 			BPath				fPath;
92 
93 			off_t				fCurrentSize;
94 			off_t				fExpectedSize;
95 			off_t				fLastSpeedReferenceSize;
96 			off_t				fEstimatedFinishReferenceSize;
97 			bigtime_t			fLastUpdateTime;
98 			bigtime_t			fLastSpeedReferenceTime;
99 			bigtime_t			fProcessStartTime;
100 			bigtime_t			fLastSpeedUpdateTime;
101 			bigtime_t			fEstimatedFinishReferenceTime;
102 	static	const size_t		kBytesPerSecondSlots = 10;
103 			size_t				fCurrentBytesPerSecondSlot;
104 			double				fBytesPerSecondSlot[kBytesPerSecondSlots];
105 			double				fBytesPerSecond;
106 
107 	static	bigtime_t			sLastEstimatedFinishSpeedToggleTime;
108 	static	bool				sShowSpeed;
109 };
110 
111 #endif // DOWNLOAD_PROGRESS_VIEW_H
112