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 <QSqlDatabase> |
| 6 | #include <QSqlQuery> |
| 7 | #include <QSqlResult> |
Jared Lindblom | a999630 | 2013-01-12 00:25:16 -0800 | [diff] [blame] | 8 | #include <QSqlError> |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 9 | #include <QDebug> |
| 10 | #include <QHash> |
Jared Lindblom | a999630 | 2013-01-12 00:25:16 -0800 | [diff] [blame] | 11 | #include <QCryptographicHash> |
Jared Lindblom | 264310d | 2013-01-12 01:18:58 -0800 | [diff] [blame^] | 12 | #include <QVector> |
| 13 | |
| 14 | enum eEvent { |
| 15 | ADDED = 0, |
| 16 | MODIFIED, |
| 17 | DELETED |
| 18 | }; |
| 19 | |
| 20 | struct sEventInfo { |
| 21 | eEvent event; |
| 22 | QString absFilePath; |
| 23 | }; |
Jared Lindblom | a999630 | 2013-01-12 00:25:16 -0800 | [diff] [blame] | 24 | |
| 25 | struct sFileInfo { |
| 26 | QByteArray hash; |
| 27 | QFileInfo fileInfo; |
| 28 | }; |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 29 | |
| 30 | namespace Ui { |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 31 | class FileSystemWatcher; |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 32 | } |
| 33 | |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 34 | class FileSystemWatcher : public QMainWindow |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 35 | { |
| 36 | Q_OBJECT |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 37 | |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 38 | public: |
| 39 | // constructor |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 40 | FileSystemWatcher(QString dirPath, QWidget *parent = 0); |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 41 | |
| 42 | // destructor |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 43 | ~FileSystemWatcher(); |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 44 | |
| 45 | private slots: |
Jared Lindblom | a999630 | 2013-01-12 00:25:16 -0800 | [diff] [blame] | 46 | // handle callback from either the watcher or timer |
| 47 | void handleCallback(); |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 48 | |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 49 | private: |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 50 | // scan directory and populate file list |
Jared Lindblom | a999630 | 2013-01-12 00:25:16 -0800 | [diff] [blame] | 51 | QHash<QString, sFileInfo> scanDirectory(QString filePath); |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 52 | |
| 53 | // reconcile directory, find changes |
Jared Lindblom | 264310d | 2013-01-12 01:18:58 -0800 | [diff] [blame^] | 54 | QVector<sEventInfo> reconcileDirectory(QHash<QString, sFileInfo> fileList); |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 55 | |
| 56 | private: |
| 57 | Ui::FileSystemWatcher* m_ui; // user interface |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 58 | QFileSystemWatcher* m_watcher; // filesystem watcher |
| 59 | QStringListModel* m_listViewModel; // list view model |
| 60 | QListView* m_listView; // list |
Jared Lindblom | a999630 | 2013-01-12 00:25:16 -0800 | [diff] [blame] | 61 | QTimer* m_timer; // timer |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 62 | |
Jared Lindblom | a999630 | 2013-01-12 00:25:16 -0800 | [diff] [blame] | 63 | QString m_dirPath; // monitored path |
| 64 | QHash<QString, sFileInfo> m_storedState; // stored state of directory |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | #endif // FILESYSTEMWATCHER_H |