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 BString _DestinationString(float* _width); 133 BString _StatusString(float availableSpace, 134 float fontSize, float* _width); 135 136 BString _SpeedStatusString(float availableSpace, 137 float* _width); 138 BString _FullSpeedString(); 139 BString _ShortSpeedString(); 140 141 BString _TimeStatusString(float availableSpace, 142 float* _width); 143 BString _ShortTimeRemainingString(const char* timeText); 144 BString _FullTimeRemainingString(time_t now, 145 time_t finishTime, const char* timeText); 146 147 BStatusBar* fStatusBar; 148 off_t fTotalSize; 149 off_t fItemSize; 150 off_t fSizeProcessed; 151 off_t fLastSpeedReferenceSize; 152 off_t fEstimatedFinishReferenceSize; 153 int32 fCurItem; 154 int32 fType; 155 BBitmap* fBitmap; 156 BButton* fStopButton; 157 BButton* fPauseButton; 158 thread_id fThread; 159 bigtime_t fLastUpdateTime; 160 bigtime_t fLastSpeedReferenceTime; 161 bigtime_t fProcessStartTime; 162 bigtime_t fLastSpeedUpdateTime; 163 bigtime_t fEstimatedFinishReferenceTime; 164 static const size_t kBytesPerSecondSlots = 10; 165 size_t fCurrentBytesPerSecondSlot; 166 double fBytesPerSecondSlot[kBytesPerSecondSlots]; 167 double fBytesPerSecond; 168 bool fShowCount; 169 bool fWasCanceled; 170 bool fIsPaused; 171 BString fDestDir; 172 char fPendingStatusString[128]; 173 174 typedef BView _inherited; 175 }; 176 177 178 inline bool 179 BStatusView::IsPaused() const 180 { 181 return fIsPaused; 182 } 183 184 185 inline bool 186 BStatusView::WasCanceled() const 187 { 188 return fWasCanceled; 189 } 190 191 192 inline thread_id 193 BStatusView::Thread() const 194 { 195 return fThread; 196 } 197 198 199 extern BStatusWindow* gStatusWindow; 200 201 202 } // namespace BPrivate 203 204 using namespace BPrivate; 205 206 207 #endif // STATUS_WINDOW_H 208