xref: /haiku/src/apps/diskusage/Scanner.h (revision 959ff00ddee8411dabb09211f3bfbd52d87229da)
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 #include <string>
13 
14 #include <Looper.h>
15 #include <Message.h>
16 #include <Messenger.h>
17 #include <Volume.h>
18 
19 #include "Snapshot.h"
20 
21 
22 class BDirectory;
23 
24 using std::string;
25 
26 class Scanner: public BLooper {
27 public:
28 								Scanner(BVolume* volume, BHandler* handler);
29 	virtual						~Scanner();
30 
31 	virtual	void				MessageReceived(BMessage* message);
32 
33 			VolumeSnapshot*		Snapshot() const
34 									{ return fBusy ? NULL : fSnapshot; }
35 			void				Refresh(FileInfo* startInfo = NULL);
36 			bool				IsBusy() const
37 									{ return fBusy; }
38 			const char*			Task() const
39 									{ return fTask.c_str(); }
40 			float				Progress() const
41 									{ return min_c(100.0, fProgress); }
42 			FileInfo*			CurrentDir() const
43 									{ return fBusy ? NULL : fSnapshot->currentDir; }
44 			void				ChangeDir(FileInfo* info)
45 									{ fSnapshot->currentDir = info; }
46 			void				SetDesiredPath(string &path);
47 			dev_t				Device() const
48 									{ return fVolume->Device(); }
49 			void				RequestQuit();
50 
51 private:
52 			void				_RunScan(FileInfo *startInfo);
53 			FileInfo*			_GetFileInfo(BDirectory* dir, FileInfo* parent);
54 			void				_ChangeToDesired();
55 
56 			BMessenger			fListener;
57 			BMessage			fDoneMessage;
58 			BMessage			fProgressMessage;
59 
60 			BVolume*			fVolume;
61 			off_t				fVolumeBytesInUse;
62 			off_t				fVolumeBytesScanned;
63 			float				fProgress;
64 			float				fLastReport;
65 			VolumeSnapshot*		fSnapshot;
66 			string				fDesiredPath;
67 			string				fTask;
68 			bool				fBusy;
69 			bool				fQuitRequested;
70 };
71 
72 #endif // SCANNER_H
73 
74