blob: 64a3cfd9db558f95983733dfcbfcf0369f4b8b1b (
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
|
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#ifndef FILEWATCHER_H
#define FILEWATCHER_H
#include <QDateTime>
#include <QFileInfo>
#include <QList>
#include <QMap>
#include <QObject>
#include <QTimer>
#include "scribusapi.h"
class SCRIBUS_API FileWatcher : public QObject
{
Q_OBJECT
public:
FileWatcher(QObject* parent);
~FileWatcher();
bool isActive();
// Get if file check loop is running
void isFileCheckRunning();
// Set the timer length in milliseconds
void setTimeOut(const int newTimeOut, const bool restartTimer=false);
// Get the timer length
int timeOut() const;
QList<QString> files();
public slots:
//Add a file to the watch list for monitoring
void addFile(QString fileName);
//Remove a file from the watch list
void removeFile(QString fileName);
//Add a directory to the watch list for monitoring
void addDir(QString fileName);
//Remove a directory from the watch list
void removeDir(QString fileName);
//Start the watcher's timer for file monitoring
void start();
//Stop the watcher's timer
void stop();
//Force a scan of the watched item list
void forceScan();
private:
struct fileMod
{
QFileInfo info;
QDateTime timeInfo;
int pendingCount;
bool pending;
int refCount;
};
typedef enum
{
AddRemoveBlocked = 1,
FileCheckRunning = 2,
StopRequested = 4,
TimerStopped = 8,
Dying = 16,
FileCheckMustStop = 20 //StopRequested + Dying
} StateFlags;
QMap<QString, fileMod> watchedFiles;
QTimer* watchTimer;
int m_stateFlags;
int m_timeOut; // milliseconds
private slots:
void checkFiles();
signals:
void fileChanged(QString);
void fileDeleted(QString);
void dirChanged(QString);
void dirDeleted(QString);
void statePending(QString);
};
#endif
|