btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / kits / tracker / StatusWindow.h
blob2341bf3bbbbc786127cf7f6ef7ed71264c9a4c8c
1 /*
2 Open Tracker License
4 Terms and Conditions
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
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:
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.
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.
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.
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.
34 #ifndef _STATUS_WINDOW_H
35 #define _STATUS_WINDOW_H
38 #include <Bitmap.h>
39 #include <ObjectList.h>
40 #include <StatusBar.h>
41 #include <String.h>
42 #include <View.h>
43 #include <Window.h>
46 namespace BPrivate {
49 enum StatusWindowState {
50 kCopyState,
51 kMoveState,
52 kDeleteState,
53 kTrashState,
54 kVolumeState,
55 kCreateLinkState,
56 kRestoreFromTrashState
59 class BStatusView;
62 class BStatusWindow : public BWindow {
63 public:
64 BStatusWindow();
65 virtual ~BStatusWindow();
67 void CreateStatusItem(thread_id,
68 StatusWindowState);
69 void InitStatusItem(thread_id, int32 totalItems,
70 off_t totalSize,
71 const entry_ref* destDir = NULL,
72 bool showCount = true);
73 void UpdateStatus(thread_id, const char* curItem,
74 off_t itemSize, bool optional = false);
75 // If true is passed in <optional> status
76 // will only be updated if 0.2 seconds
77 // elapsed since the last update
78 void RemoveStatusItem(thread_id);
80 bool CheckCanceledOrPaused(thread_id);
82 bool AttemptToQuit();
83 // Called by the tracker app during quit
84 // time, before inherited QuitRequested;
85 // kills all the copy/move/empty trash
86 // threads in a clean way by issuing a
87 // cancel.
88 protected:
89 virtual void WindowActivated(bool state);
91 private:
92 BObjectList<BStatusView> fViewList;
93 BMessageFilter* fMouseDownFilter;
95 bool fRetainDesktopFocus;
97 typedef BWindow _inherited;
101 class BStatusView : public BView {
102 public:
103 BStatusView(BRect frame, thread_id,
104 StatusWindowState state);
105 virtual ~BStatusView();
107 void Init();
109 void InitStatus(int32 totalItems, off_t totalSize,
110 const entry_ref* destDir, bool showCount);
112 // BView overrides
113 virtual void Draw(BRect updateRect);
114 virtual void AttachedToWindow();
115 virtual void MessageReceived(BMessage* message);
117 void UpdateStatus(const char* currentItem,
118 off_t itemSize, bool optional = false);
119 // If true is passed in <optional> status
120 // will only be updated if 0.2 seconds
121 // elapsed since the last update.
123 bool WasCanceled() const;
124 bool IsPaused() const;
125 thread_id Thread() const;
127 void SetWasCanceled();
128 // called by AboutToQuit
130 private:
131 BString _DestinationString(float* _width);
132 BString _StatusString(float availableSpace,
133 float fontSize, float* _width);
135 BString _SpeedStatusString(float availableSpace,
136 float* _width);
137 BString _FullSpeedString();
138 BString _ShortSpeedString();
140 BString _TimeStatusString(float availableSpace,
141 float* _width);
142 BString _ShortTimeRemainingString(const char* timeText);
143 BString _FullTimeRemainingString(time_t now,
144 time_t finishTime, const char* timeText);
146 BStatusBar* fStatusBar;
147 off_t fTotalSize;
148 off_t fItemSize;
149 off_t fSizeProcessed;
150 off_t fLastSpeedReferenceSize;
151 off_t fEstimatedFinishReferenceSize;
152 int32 fCurItem;
153 int32 fType;
154 BBitmap* fBitmap;
155 BButton* fStopButton;
156 BButton* fPauseButton;
157 thread_id fThread;
158 bigtime_t fLastUpdateTime;
159 bigtime_t fLastSpeedReferenceTime;
160 bigtime_t fProcessStartTime;
161 bigtime_t fLastSpeedUpdateTime;
162 bigtime_t fEstimatedFinishReferenceTime;
163 static const size_t kBytesPerSecondSlots = 10;
164 size_t fCurrentBytesPerSecondSlot;
165 double fBytesPerSecondSlot[kBytesPerSecondSlots];
166 double fBytesPerSecond;
167 bool fShowCount;
168 bool fWasCanceled;
169 bool fIsPaused;
170 BString fDestDir;
171 char fPendingStatusString[128];
173 typedef BView _inherited;
177 inline bool
178 BStatusView::IsPaused() const
180 return fIsPaused;
184 inline bool
185 BStatusView::WasCanceled() const
187 return fWasCanceled;
191 inline thread_id
192 BStatusView::Thread() const
194 return fThread;
198 extern BStatusWindow* gStatusWindow;
201 } // namespace BPrivate
203 using namespace BPrivate;
206 #endif // _STATUS_WINDOW_H