QCodeEdit  2.2
qreliablefilewatch.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
4 **
5 ** This file is part of the Edyuk project <http://edyuk.org>
6 **
7 ** This file may be used under the terms of the GNU General Public License
8 ** version 3 as published by the Free Software Foundation and appearing in the
9 ** file GPL.txt included in the packaging of this file.
10 **
11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 **
14 ****************************************************************************/
15 
16 #ifndef _QRELIABLE_FILE_WATCH_H_
17 #define _QRELIABLE_FILE_WATCH_H_
18 
19 #include "qce-config.h"
20 
26 #include <QHash>
27 #include <QTimer>
28 #include <QPointer>
29 #include <QFileSystemWatcher>
30 
32 {
33  friend class QPointer<QReliableFileWatch>;
34 
35  Q_OBJECT
36 
37  public:
38  QReliableFileWatch(QObject *p = 0);
39  virtual ~QReliableFileWatch();
40 
41  public slots:
42  void addWatch(const QString& file, QObject *recipient);
43 
44  void removeWatch(QObject *recipient);
45  void removeWatch(const QString& file, QObject *recipient);
46 
47  protected:
48  virtual void timerEvent(QTimerEvent *e);
49 
50  private slots:
51  void sourceChanged(const QString& filepath);
52 
53  private:
54  enum State
55  {
56  Clean = 0,
57  Recent = 1,
58  Duplicate = 2
59  };
60 
61  struct Watch
62  {
63  char state;
64  qint64 size;
65  QList< QPointer<QObject> > recipients;
66  };
67 
68  QBasicTimer m_timer;
69 
70  QHash<QString, Watch> m_targets;
71 };
72 
73 #endif // !_QRELIABLE_FILE_WATCH_H_