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
23class BDirectory;
24
25using std::string;
26
27
28class Scanner: public BLooper {
29public:
30								Scanner(BVolume* volume, BHandler* handler);
31	virtual						~Scanner();
32
33	virtual	void				MessageReceived(BMessage* message);
34
35			VolumeSnapshot*		Snapshot() const
36									{ return fBusy ? NULL : fSnapshot; }
37			void				Refresh(FileInfo* startInfo = NULL);
38			void				Cancel();
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(1.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
54private:
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