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 Header_QReliable_FileWatch 17 #define Header_QReliable_FileWatch 18 19 #include "mostQtHeaders.h" 20 21 #include "qce-config.h" 22 23 /*! 24 \file qreliablefilewatch.h 25 \brief Definition of the QReliableFileWatch class 26 */ 27 28 class QCE_EXPORT QReliableFileWatch : protected QFileSystemWatcher 29 { 30 friend class QPointer<QReliableFileWatch>; 31 32 Q_OBJECT 33 34 public: 35 QReliableFileWatch(QObject *p = 0); 36 virtual ~QReliableFileWatch(); 37 38 public slots: 39 void addWatch(const QString& file, QObject *recipient); 40 41 void removeWatch(QObject *recipient); 42 void removeWatch(const QString& file, QObject *recipient); 43 44 protected: 45 virtual void timerEvent(QTimerEvent *e); 46 47 private slots: 48 void sourceChanged(const QString& filepath); 49 50 private: 51 enum State 52 { 53 Clean = 0, 54 Recent = 1, 55 Duplicate = 2 56 }; 57 58 struct Watch 59 { 60 char state; 61 qint64 size; 62 QList< QPointer<QObject> > recipients; 63 QDateTime lastModified; 64 }; 65 66 QBasicTimer m_timer; 67 68 QHash<QString, Watch> m_targets; 69 }; 70 71 #endif // !_QRELIABLE_FILE_WATCH_H_ 72