jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 1 | #ifndef FILESYSTEMWATCHER_H |
| 2 | #define FILESYSTEMWATCHER_H |
| 3 | |
| 4 | #include <QtGui> |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 5 | #include <QDebug> |
| 6 | #include <QHash> |
Jared Lindblom | a999630 | 2013-01-12 00:25:16 -0800 | [diff] [blame] | 7 | #include <QCryptographicHash> |
Jared Lindblom | c125972 | 2013-01-12 16:47:32 -0800 | [diff] [blame^] | 8 | |
| 9 | #define DEBUG 1 |
Jared Lindblom | 264310d | 2013-01-12 01:18:58 -0800 | [diff] [blame] | 10 | |
| 11 | enum eEvent { |
| 12 | ADDED = 0, |
| 13 | MODIFIED, |
| 14 | DELETED |
| 15 | }; |
| 16 | |
| 17 | struct sEventInfo { |
| 18 | eEvent event; |
Jared Lindblom | 8278b98 | 2013-01-12 15:45:09 -0800 | [diff] [blame] | 19 | std::string absFilePath; |
Jared Lindblom | a999630 | 2013-01-12 00:25:16 -0800 | [diff] [blame] | 20 | }; |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 21 | |
| 22 | namespace Ui { |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 23 | class FileSystemWatcher; |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 24 | } |
| 25 | |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 26 | class FileSystemWatcher : public QMainWindow |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 27 | { |
| 28 | Q_OBJECT |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 29 | |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 30 | public: |
| 31 | // constructor |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 32 | FileSystemWatcher(QString dirPath, QWidget *parent = 0); |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 33 | |
| 34 | // destructor |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 35 | ~FileSystemWatcher(); |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 36 | |
Jared Lindblom | c125972 | 2013-01-12 16:47:32 -0800 | [diff] [blame^] | 37 | signals: |
| 38 | // directory event signal |
| 39 | void dirEventSignal(std::vector<sEventInfo> dirChanges); |
| 40 | |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 41 | private slots: |
Jared Lindblom | f8d32ad | 2013-01-12 11:32:27 -0800 | [diff] [blame] | 42 | // handle callback from watcher |
| 43 | void watcherCallbackSlot(QString dirPath); |
| 44 | |
| 45 | // handle callback from timer |
| 46 | void timerCallbackSlot(); |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 47 | |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 48 | private: |
Jared Lindblom | f8d32ad | 2013-01-12 11:32:27 -0800 | [diff] [blame] | 49 | // handle callback from either the watcher or timer |
| 50 | void handleCallback(QString dirPath); |
| 51 | |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 52 | // scan directory and populate file list |
Jared Lindblom | 8278b98 | 2013-01-12 15:45:09 -0800 | [diff] [blame] | 53 | QHash<QString, qint64> scanDirectory(QString dirPath); |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 54 | |
| 55 | // reconcile directory, find changes |
Jared Lindblom | c125972 | 2013-01-12 16:47:32 -0800 | [diff] [blame^] | 56 | std::vector<sEventInfo> reconcileDirectory(QHash<QString, qint64> fileList, QString dirPath); |
Jared Lindblom | f8d32ad | 2013-01-12 11:32:27 -0800 | [diff] [blame] | 57 | |
| 58 | // calculate checksum |
| 59 | QByteArray calcChecksum(QString absFilePath); |
| 60 | |
Jared Lindblom | c125972 | 2013-01-12 16:47:32 -0800 | [diff] [blame^] | 61 | // print Changes (DEBUG) |
| 62 | void printChanges(std::vector<sEventInfo> dirChanges); |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 63 | |
| 64 | private: |
| 65 | Ui::FileSystemWatcher* m_ui; // user interface |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 66 | QFileSystemWatcher* m_watcher; // filesystem watcher |
| 67 | QStringListModel* m_listViewModel; // list view model |
| 68 | QListView* m_listView; // list |
Jared Lindblom | a999630 | 2013-01-12 00:25:16 -0800 | [diff] [blame] | 69 | QTimer* m_timer; // timer |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 70 | |
Jared Lindblom | a999630 | 2013-01-12 00:25:16 -0800 | [diff] [blame] | 71 | QString m_dirPath; // monitored path |
Jared Lindblom | 8278b98 | 2013-01-12 15:45:09 -0800 | [diff] [blame] | 72 | QHash<QString, qint64> m_storedState; // stored state of directory |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | #endif // FILESYSTEMWATCHER_H |