Scribus
Open source desktop publishing at your fingertips
filewatcher.h
1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 #ifndef FILEWATCHER_H
8 #define FILEWATCHER_H
9 
10 #include <QDateTime>
11 #include <QFileInfo>
12 #include <QList>
13 #include <QMap>
14 #include <QObject>
15 #include <QTimer>
16 
17 #include "scribusapi.h"
18 
19 #include "scribusdoc.h"
20 class SCRIBUS_API FileWatcher : public QObject
21 {
22  Q_OBJECT
23 
24 public:
25  FileWatcher(QObject* parent);
26  ~FileWatcher();
27  bool isActive();
28  // Get if file check loop is running
29  void isFileCheckRunning();
30  // Set the timer length in milliseconds
31  void setTimeOut(const int newTimeOut, const bool restartTimer=false);
32  // Get the timer length
33  int timeOut() const;
34  QList<QString> files();
35 
36 public slots:
37  //Add a file to the watch list for monitoring
38  void addFile(QString fileName, bool fast = false, ScribusDoc* doc=0); //see struct note for doc var
39  //Remove a file from the watch list
40  void removeFile(QString fileName);
41  //Add a directory to the watch list for monitoring
42  void addDir(QString fileName, bool fast = false);
43  //Remove a directory from the watch list
44  void removeDir(QString fileName);
45  //Start the watcher's timer for file monitoring
46  void start();
47  //Stop the watcher's timer
48  void stop();
49  //Force a scan of the watched item list
50  void forceScan();
51 
52 private:
53  struct fileMod
54  {
55  QFileInfo info;
56  QDateTime timeInfo;
57  int pendingCount;
58  bool pending;
59  int refCount;
60  bool isDir;
61  bool fast;
62  ScribusDoc* doc; //CB Added as part of #9845 but unused for now, we could avoid scanning docs in updatePict() if we used this
63 
64  };
65 
66  typedef enum
67  {
68  AddRemoveBlocked = 1,
69  FileCheckRunning = 2,
70  StopRequested = 4,
71  TimerStopped = 8,
72  Dying = 16,
73  FileCheckMustStop = 20 //StopRequested + Dying
74  } StateFlags;
75 
76  QMap<QString, fileMod> watchedFiles;
77  QTimer* watchTimer;
78  int m_stateFlags;
79  int m_timeOut; // milliseconds
80 
81 private slots:
82  void checkFiles();
83 
84 signals:
85  void fileChanged(QString);
86  void fileDeleted(QString);
87  void dirChanged(QString);
88  void dirDeleted(QString);
89  void statePending(QString);
90 
91 };
92 
93 #endif
Definition: filewatcher.h:20
the Document Class
Definition: scribusdoc.h:90