-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirwatcher.h
83 lines (68 loc) · 1.87 KB
/
dirwatcher.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
#ifndef DIRWATCHER_H
#define DIRWATCHER_H
#include <QObject>
#include <QSettings>
#include <QList>
#include <QFileSystemWatcher>
#include <QStringList>
#include <QQueue>
#include <QFileInfo>
#include <QHash>
#include <QQmlListProperty>
#include <QQmlEngine>
#include <QJSEngine>
#include <QMutex>
#include <QMutexLocker>
#include <QFutureWatcher>
enum DirType {
AUDIO,
VIDEO,
IMAGE,
DOCUMENT,
ARCHIVE,
CODE,
OTHERS
};
class DirWatcher : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE void addToSettings(const QString &folderName);
void setFolders(const QList<QVariant> &folderList);
Q_INVOKABLE QList<QVariant> getFolders();
Q_INVOKABLE bool removeFromSettings(const QString& folderName);
Q_INVOKABLE void startWatch();
Q_INVOKABLE void clearWatch();
~DirWatcher();
bool isSpecialDirectory(QFileInfo& path);
static DirWatcher* getInstance(QObject *parent);
bool isFirstLaunch();
static QObject *singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine);
Q_INVOKABLE void startSort();
Q_INVOKABLE void launchFileDialog();
signals:
void textChanged(QString msg);
void foldersChanged(QList<QString> folders);
void fileSelected(QString fileName);
public slots:
void contentChanged(QString path);
void sortDirectory(QString path);
void sortFinished();
void openFileNameReady(QString fileName);
private :
void sortAll();
explicit DirWatcher(QObject *parent = 0);
DirType getType(QFileInfo& path);
DirType typeFromMime(QString mimeType);
void move(const QFileInfo &info, DirType type, const QString& path);
QString getStringType(DirType dirType);
QSettings *mSettings;
QList<QVariant> *mFolderList;
QFileSystemWatcher *mWatcher;
QQueue<QFileInfo> *mQ;
QHash<DirType, QString> *mDirNames;
static DirWatcher *mSelf;
QMutex mutex;
QFutureWatcher<void> mFutureWatcher;
};
#endif // DIRWATCHER_H