xref: /haiku/src/kits/tracker/StatusWindow.h (revision b55a57da7173b9af0432bd3e148d03f06161d036)
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 			int32				fCurItem;
136 			int32				fType;
137 			BBitmap*			fBitmap;
138 			BButton*			fStopButton;
139 			BButton*			fPauseButton;
140 			thread_id			fThread;
141 			float				fLastUpdateTime;
142 			bool				fShowCount;
143 			bool				fWasCanceled;
144 			bool				fIsPaused;
145 			BString				fDestDir;
146 			char				fPendingStatusString[128];
147 
148 			typedef BView		_inherited;
149 };
150 
151 
152 inline bool
153 BStatusView::IsPaused() const
154 {
155 	return fIsPaused;
156 }
157 
158 
159 inline bool
160 BStatusView::WasCanceled() const
161 {
162 	return fWasCanceled;
163 }
164 
165 
166 inline thread_id
167 BStatusView::Thread() const
168 {
169 	return fThread;
170 }
171 
172 
173 extern BStatusWindow* gStatusWindow;
174 
175 
176 } // namespace BPrivate
177 
178 using namespace BPrivate;
179 
180 #endif // STATUS_WINDOW_H
181