summaryrefslogtreecommitdiff
path: root/plugins/CopyEngine/Ultracopier-0.3/scanFileOrFolder.h
blob: 787d8af9da8906396a07e2498ce18c0cd9a949e7 (plain)
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
/** \file scanFileOrFolder.h
\brief Thread changed to list recursively the folder
\author alpha_one_x86
\version 0.3
\date 2011 */

#include <QThread>
#include <QStringList>
#include <QString>
#include <QList>
#include <QFileInfo>
#include <QDir>
#include <QSemaphore>
#include <QEventLoop>
#include <QCoreApplication>
#include <QMutexLocker>

#include "Environment.h"

#ifndef SCANFILEORFOLDER_H
#define SCANFILEORFOLDER_H

/// \brief Thread changed to list recursively the folder
class scanFileOrFolder : public QThread
{
	Q_OBJECT
public:
	explicit scanFileOrFolder(CopyMode mode);
	~scanFileOrFolder();
	/// \brief to the a folder listing
	void stop();
	/// \brief to get if is finished
	bool isFinished();
	/// \brief set action if Folder are same or exists
	void setFolderExistsAction(FolderExistsAction action,QString newName="");
	/// \brief set action if error
	void setFolderErrorAction(FileErrorAction action);
	/// \brief set if need check if the destination exists
	void setCheckDestinationFolderExists(const bool checkDestinationFolderExists);
	void setRenamingRules(QString firstRenamingRule,QString otherRenamingRule);
signals:
	void fileTransfer(const QFileInfo &source,const QFileInfo &destination,const CopyMode &mode);
	/// \brief To debug source
	void debugInformation(const DebugLevel &level,const QString &fonction,const QString &text,const QString &file,const int &ligne);
	void folderAlreadyExists(const QFileInfo &source,const QFileInfo &destination,const bool &isSame);
	void errorOnFolder(const QFileInfo &fileInfo,const QString &errorString);
	void finishedTheListing();

	void newFolderListing(const QString &path);
	void addToMkPath(const QString& folder);
	void addToRmPath(const QString& folder,const int& inodeToRemove);
public slots:
	void addToList(const QStringList& sources,const QString& destination);
	void setFilters(QList<Filters_rules> include,QList<Filters_rules> exclude);
protected:
	void run();
private:
	QStringList		sources;
	QString			destination;
	volatile bool		stopIt;
        void			listFolder(const QString& source,const QString& destination,const QString& sourceSuffixPath,QString destinationSuffixPath);
	volatile bool		stopped;
	QSemaphore		waitOneAction;
	FolderExistsAction	folderExistsAction;
	FileErrorAction		fileErrorAction;
	volatile bool		checkDestinationExists;
	QString			newName;
	QRegExp			folder_isolation;
	QString			prefix;
	QString			suffix;
	CopyMode		mode;
	QList<Filters_rules>	include,exclude;
	QList<Filters_rules>	include_send,exclude_send;
	bool			reloadTheNewFilters;
	bool			haveFilters;
	QMutex			filtersMutex;
	QString			firstRenamingRule;
	QString			otherRenamingRule;
	/** Parse the multiple wildcard source, it allow resolv multiple wildcard with Qt into their path
	 * The string: /toto/f*a/yy*a/toto.mp3
	 * Will give: /toto/f1a/yy*a/toto.mp3, /toto/f2a/yy*a/toto.mp3
	 * Will give: /toto/f2a/yy1a/toto.mp3, /toto/f2a/yy2a/toto.mp3
	*/
	QStringList		parseWildcardSources(const QStringList &sources);
};

#endif // SCANFILEORFOLDER_H