summaryrefslogtreecommitdiff
path: root/plugins/CopyEngine/Ultracopier/ScanFileOrFolder.h
blob: e9e59ce0e46d25c183529c666a12378e3d52a68d (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/** \file scanFileOrFolder.h
\brief Thread changed to list recursively the folder
\author alpha_one_x86
\licence GPL3, see the file COPYING */

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

#include "Environment.h"
#include "DriveManagement.h"

#ifndef SCANFILEORFOLDER_H
#define SCANFILEORFOLDER_H

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

    void newFolderListing(const QString &path) const;
    void addToMkPath(const QFileInfo& source,const QFileInfo& destination, const int& inode) const;
    void addToMovePath(const QFileInfo& source,const QFileInfo& destination, const int& inodeToRemove) const;
    void addToRealMove(const QFileInfo& source,const QFileInfo& destination) const;
    #ifdef ULTRACOPIER_PLUGIN_RSYNC
    void addToRmForRsync(const QFileInfo& destination) const;
    #endif
public slots:
    void addToList(const QStringList& sources,const QString& destination);
    void setFilters(const QList<Filters_rules> &include,const QList<Filters_rules> &exclude);
    void setCopyListOrder(const bool &order);
    void set_updateMount();
protected:
    void run();
private:
    DriveManagement     driveManagement;
    bool                moveTheWholeFolder;
    QStringList         sources;
    QString             destination;
    volatile bool		stopIt;
    void                listFolder(QFileInfo source, QFileInfo destination);
    bool                isBlackListed(const QFileInfo &destination);
    QFileInfo           resolvDestination(const QFileInfo &destination);
    volatile bool		stopped;
    QSemaphore          waitOneAction;
    FolderExistsAction	folderExistsAction;
    FileErrorAction		fileErrorAction;
    volatile bool		checkDestinationExists;
    QString             newName;
    bool                copyListOrder;
    QRegularExpression	folder_isolation;
    #ifdef ULTRACOPIER_PLUGIN_RSYNC
    bool                rsync;
    #endif
    Ultracopier::CopyMode	mode;
    QList<Filters_rules>	include,exclude;
    QList<Filters_rules>	include_send,exclude_send;
    bool			reloadTheNewFilters;
    bool			haveFilters;
    QMutex			filtersMutex;
    QString			firstRenamingRule;
    QString			otherRenamingRule;
    QStringList     blackList;
    /** 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) const;

    static QString text_slash;
    static QString text_antislash;
    static QString text_dot;
};

#endif // SCANFILEORFOLDER_H