1/* 2Open Tracker License 3 4Terms and Conditions 5 6Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 8Permission is hereby granted, free of charge, to any person obtaining a copy of 9this software and associated documentation files (the "Software"), to deal in 10the Software without restriction, including without limitation the rights to 11use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12of the Software, and to permit persons to whom the Software is furnished to do 13so, subject to the following conditions: 14 15The above copyright notice and this permission notice applies to all licensees 16and shall be included in all copies or substantial portions of the Software. 17 18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 23WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 25Except as contained in this notice, the name of Be Incorporated shall not be 26used in advertising or otherwise to promote the sale, use or other dealings in 27this Software without prior written authorization from Be Incorporated. 28 29Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 30of Be Incorporated in the United States and other countries. Other brand product 31names are registered trademarks or trademarks of their respective holders. 32All rights reserved. 33*/ 34#ifndef _STATUS_WINDOW_H 35#define _STATUS_WINDOW_H 36 37 38#include <Bitmap.h> 39#include <ObjectList.h> 40#include <StatusBar.h> 41#include <String.h> 42#include <View.h> 43#include <Window.h> 44 45 46namespace BPrivate { 47 48 49enum StatusWindowState { 50 kCopyState, 51 kMoveState, 52 kDeleteState, 53 kTrashState, 54 kVolumeState, 55 kCreateLinkState, 56 kRestoreFromTrashState 57}; 58 59class BStatusView; 60 61 62class BStatusWindow : public BWindow { 63public: 64 BStatusWindow(); 65 virtual ~BStatusWindow(); 66 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); 79 80 bool CheckCanceledOrPaused(thread_id); 81 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. 88protected: 89 virtual void WindowActivated(bool state); 90 91private: 92 BObjectList<BStatusView> fViewList; 93 BMessageFilter* fMouseDownFilter; 94 95 bool fRetainDesktopFocus; 96 97 typedef BWindow _inherited; 98}; 99 100 101class BStatusView : public BView { 102public: 103 BStatusView(BRect frame, thread_id, 104 StatusWindowState state); 105 virtual ~BStatusView(); 106 107 void Init(); 108 109 void InitStatus(int32 totalItems, off_t totalSize, 110 const entry_ref* destDir, bool showCount); 111 112 // BView overrides 113 virtual void Draw(BRect updateRect); 114 virtual void AttachedToWindow(); 115 virtual void MessageReceived(BMessage* message); 116 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. 122 123 bool WasCanceled() const; 124 bool IsPaused() const; 125 thread_id Thread() const; 126 127 void SetWasCanceled(); 128 // called by AboutToQuit 129 130private: 131 BString _DestinationString(float* _width); 132 BString _StatusString(float availableSpace, 133 float fontSize, float* _width); 134 135 BString _SpeedStatusString(float availableSpace, 136 float* _width); 137 BString _FullSpeedString(); 138 BString _ShortSpeedString(); 139 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); 145 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]; 172 173 typedef BView _inherited; 174}; 175 176 177inline bool 178BStatusView::IsPaused() const 179{ 180 return fIsPaused; 181} 182 183 184inline bool 185BStatusView::WasCanceled() const 186{ 187 return fWasCanceled; 188} 189 190 191inline thread_id 192BStatusView::Thread() const 193{ 194 return fThread; 195} 196 197 198extern BStatusWindow* gStatusWindow; 199 200 201} // namespace BPrivate 202 203using namespace BPrivate; 204 205 206#endif // _STATUS_WINDOW_H 207