forked from mihow/bpmdj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dirscanner.h
122 lines (117 loc) · 3.89 KB
/
dirscanner.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/****
BpmDj v4.2-pl4: Free Dj Tools
Copyright (C) 2001-2012 Werner Van Belle
http://bpmdj.yellowcouch.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose. See the
GNU General Public License for more details.
See the authors.txt for a full list of people involved.
****/
#ifndef __loaded__dirscanner_h__
#define __loaded__dirscanner_h__
using namespace std;
#include <dirent.h>
#include <stdlib.h>
#include <qstring.h>
#include <stack>
#include "Data/types.h"
/**
* The directory scanner provides the possibility to scan a directory tree
* in specific chunk sizes. For each filename it will check its extension,
* and if it matches it will call the checkFile virtual function.
*/
class DirectoryScanner
{
private:
/**
* A subclass used to track in which directory we currently are. The stack of
* open directories is maintained in dir_stack. Each frame e on this stack
* contains an opened directory entry (so the readdir function can be called)
* and the full path to reach that directory.
*/
class DirPos
{
public:
DIR * dir;
QString path;
};
/**
* The stack of open directory entries. Since we can a number of files per
* turn and then continue later on we need this.
*/
stack<DirPos> dir_stack;
/**
* How many files will we scan per scan() call ?
*/
unsigned4 files_per_turn;
private:
/**
* Called internally to check a specific filename. If the filename has the
* proper extension, checkFile will be called
*/
void scanfile(const QString dir, const QString filename);
protected:
/**
* Should we recurse into sub directories
*/
bool recurse;
/**
* The length of the initial directory. This can be used in check_file to
* strip the common root from the files that are being checked
*/
int prefix_length;
/**
* The required extension before a file can be send to checkFile
*/
QString required_extension;
virtual void recursing(const QString dir);
/**
* Called for each file that has a proper extension.
*/
virtual void checkfile(const QString dir, const QString filename) = 0;
/**
* The function used to check whether the extension matches
* If the extension does not match the file is not sent to checkfile.
* The standard function will check the required_extension.
*/
virtual bool matchextension(const QString filename);
virtual ~DirectoryScanner()
{
};
public:
/**
* Will create a directory scanner which will target the required extension.
* To use it first reset it to a certain directory and then use scan()
*/
DirectoryScanner(QString extension);
/**
* Creates a directory scanner that will target the given extension and start
* searching for files under @arg dir. Normally recursion is enabled. Use the
* last parameter to turn it off if necessary
*/
DirectoryScanner(QString dir, QString extension, bool rec=true);
/**
* Will reset the scanner into a certain directory. Normally all files will
* be scanned at once. If necessary to use smaller chunk sizes use the
* files_per_turn argument.
*/
virtual void reset(const QString dirname,
unsigned4 files_per_turn=0xffffffff);
static bool goodName(QString name);
void set_file_per_turn(unsigned4 fpt)
{
files_per_turn=fpt;
}
/**
* Will scan a collection of files. It returns the number of files
* found, which is not the same as the number of satisfactory files found.
* If this function returns 0, then the process has ended.
*/
virtual unsigned4 scan();
};
#endif // __loaded__dirscanner_h__