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