1 /* 2 * Copyright (c) 2008 Stephan Aßmus <superstippi@gmx.de>. All rights reserved. 3 * Distributed under the terms of the MIT/X11 license. 4 * 5 * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software 6 * as long as it is accompanied by it's documentation and this copyright notice. 7 * The software comes with no warranty, etc. 8 */ 9 #ifndef SCANNER_H 10 #define SCANNER_H 11 12 13 #include <string> 14 15 #include <Looper.h> 16 #include <Message.h> 17 #include <Messenger.h> 18 #include <Volume.h> 19 20 #include "Snapshot.h" 21 22 23 class BDirectory; 24 25 using std::string; 26 27 28 class Scanner: public BLooper { 29 public: 30 Scanner(BVolume* volume, BHandler* handler); 31 virtual ~Scanner(); 32 33 virtual void MessageReceived(BMessage* message); 34 Snapshot()35 VolumeSnapshot* Snapshot() const 36 { return fBusy ? NULL : fSnapshot; } 37 void Refresh(FileInfo* startInfo = NULL); 38 void Cancel(); IsBusy()39 bool IsBusy() const 40 { return fBusy; } Task()41 const char* Task() const 42 { return fTask.c_str(); } Progress()43 float Progress() const 44 { return min_c(1.0, fProgress); } CurrentDir()45 FileInfo* CurrentDir() const 46 { return fBusy ? NULL : fSnapshot->currentDir; } ChangeDir(FileInfo * info)47 void ChangeDir(FileInfo* info) 48 { fSnapshot->currentDir = info; } 49 void SetDesiredPath(string &path); Device()50 dev_t Device() const 51 { return fVolume->Device(); } 52 void RequestQuit(); 53 54 private: 55 void _RunScan(FileInfo *startInfo); 56 FileInfo* _GetFileInfo(BDirectory* dir, FileInfo* parent); 57 void _ChangeToDesired(); 58 bool _DirectoryContains(FileInfo* currentDir, 59 entry_ref* ref); 60 61 BMessenger fListener; 62 BMessage fDoneMessage; 63 BMessage fProgressMessage; 64 65 BVolume* fVolume; 66 off_t fVolumeBytesInUse; 67 off_t fVolumeBytesScanned; 68 float fProgress; 69 float fLastReport; 70 VolumeSnapshot* fSnapshot; 71 string fDesiredPath; 72 string fTask; 73 bool fBusy; 74 bool fQuitRequested; 75 }; 76 77 #endif // SCANNER_H 78