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