xref: /haiku/src/kits/tracker/StatusWindow.h (revision 62f5ba006a08b0df30631375878effaf67ae5dbc)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
28 
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
33 */
34 #ifndef	STATUS_WINDOW_H
35 #define STATUS_WINDOW_H
36 
37 
38 #include <Window.h>
39 #include <View.h>
40 #include <Bitmap.h>
41 #include <StatusBar.h>
42 #include <String.h>
43 
44 #include "ObjectList.h"
45 
46 
47 namespace BPrivate {
48 
49 
50 enum StatusWindowState {
51 	kCopyState,
52 	kMoveState,
53 	kDeleteState,
54 	kTrashState,
55 	kVolumeState,
56 	kCreateLinkState,
57 	kRestoreFromTrashState
58 };
59 
60 class BStatusView;
61 
62 
63 class BStatusWindow : public BWindow {
64 public:
65 								BStatusWindow();
66 	virtual						~BStatusWindow();
67 
68 			void				CreateStatusItem(thread_id,
69 									StatusWindowState);
70 			void				InitStatusItem(thread_id, int32 totalItems,
71 									off_t totalSize,
72 									const entry_ref* destDir = NULL,
73 									bool showCount = true);
74 			void				UpdateStatus(thread_id, const char* curItem,
75 									off_t itemSize, bool optional = false);
76 									// If true is passed in <optional> status
77 									// will only be updated if 0.2 seconds
78 									// elapsed since the last update
79 			void				RemoveStatusItem(thread_id);
80 
81 			bool				CheckCanceledOrPaused(thread_id);
82 
83 			bool				AttemptToQuit();
84 									// Called by the tracker app during quit
85 									// time, before inherited QuitRequested;
86 									// kills all the copy/move/empty trash
87 									// threads in a clean way by issuing a
88 									// cancel.
89 protected:
90 	virtual	void				WindowActivated(bool state);
91 
92 private:
93 			BObjectList<BStatusView> fViewList;
94 			BMessageFilter*		fMouseDownFilter;
95 
96 			bool				fRetainDesktopFocus;
97 
98 			typedef BWindow		_inherited;
99 };
100 
101 
102 class BStatusView : public BView {
103 public:
104 								BStatusView(BRect frame, thread_id,
105 									StatusWindowState state);
106 	virtual						~BStatusView();
107 
108 			void				Init();
109 
110 			void				InitStatus(int32 totalItems, off_t totalSize,
111 									const entry_ref* destDir, bool showCount);
112 
113 	// BView overrides
114 	virtual	void				Draw(BRect updateRect);
115 	virtual	void				AttachedToWindow();
116 	virtual	void				MessageReceived(BMessage* message);
117 
118 			void				UpdateStatus(const char* currentItem,
119 									off_t itemSize, bool optional = false);
120 									// If true is passed in <optional> status
121 									// will only be updated if 0.2 seconds
122 									// elapsed since the last update.
123 
124 			bool				WasCanceled() const;
125 			bool				IsPaused() const;
126 			thread_id			Thread() const;
127 
128 			void				SetWasCanceled();
129 									// called by AboutToQuit
130 
131 private:
132 			BStatusBar*			fStatusBar;
133 			off_t				fTotalSize;
134 			off_t				fItemSize;
135 			off_t				fSizeProcessed;
136 			off_t				fLastSpeedReferenceSize;
137 			off_t				fEstimatedFinishReferenceSize;
138 			int32				fCurItem;
139 			int32				fType;
140 			BBitmap*			fBitmap;
141 			BButton*			fStopButton;
142 			BButton*			fPauseButton;
143 			thread_id			fThread;
144 			bigtime_t			fLastUpdateTime;
145 			bigtime_t			fLastSpeedReferenceTime;
146 			bigtime_t			fProcessStartTime;
147 			bigtime_t			fLastSpeedUpdateTime;
148 			bigtime_t			fEstimatedFinishReferenceTime;
149 	static	const size_t		kBytesPerSecondSlots = 10;
150 			size_t				fCurrentBytesPerSecondSlot;
151 			double				fBytesPerSecondSlot[kBytesPerSecondSlots];
152 			double				fBytesPerSecond;
153 			bool				fShowCount;
154 			bool				fWasCanceled;
155 			bool				fIsPaused;
156 			BString				fDestDir;
157 			char				fPendingStatusString[128];
158 
159 			typedef BView		_inherited;
160 };
161 
162 
163 inline bool
164 BStatusView::IsPaused() const
165 {
166 	return fIsPaused;
167 }
168 
169 
170 inline bool
171 BStatusView::WasCanceled() const
172 {
173 	return fWasCanceled;
174 }
175 
176 
177 inline thread_id
178 BStatusView::Thread() const
179 {
180 	return fThread;
181 }
182 
183 
184 extern BStatusWindow* gStatusWindow;
185 
186 
187 } // namespace BPrivate
188 
189 using namespace BPrivate;
190 
191 #endif // STATUS_WINDOW_H
192