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 | f8d32ad | 2013-01-12 11:32:27 -0800 | [diff] [blame^] | 46 | // handle callback from watcher |
| 47 | void watcherCallbackSlot(QString dirPath); |
| 48 | |
| 49 | // handle callback from timer |
| 50 | void timerCallbackSlot(); |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 51 | |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 52 | private: |
Jared Lindblom | f8d32ad | 2013-01-12 11:32:27 -0800 | [diff] [blame^] | 53 | // handle callback from either the watcher or timer |
| 54 | void handleCallback(QString dirPath); |
| 55 | |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 56 | // scan directory and populate file list |
Jared Lindblom | f8d32ad | 2013-01-12 11:32:27 -0800 | [diff] [blame^] | 57 | QHash<QString, sFileInfo> scanDirectory(QString dirPath); |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 58 | |
| 59 | // reconcile directory, find changes |
Jared Lindblom | f8d32ad | 2013-01-12 11:32:27 -0800 | [diff] [blame^] | 60 | QVector<sEventInfo> reconcileDirectory(QHash<QString, sFileInfo> fileList, QString dirPath); |
| 61 | |
| 62 | // calculate checksum |
| 63 | QByteArray calcChecksum(QString absFilePath); |
| 64 | |
| 65 | // print to GUI (DEBUG) |
| 66 | void printToGui(QVector<sEventInfo> dirChanges); |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 67 | |
| 68 | private: |
| 69 | Ui::FileSystemWatcher* m_ui; // user interface |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 70 | QFileSystemWatcher* m_watcher; // filesystem watcher |
| 71 | QStringListModel* m_listViewModel; // list view model |
| 72 | QListView* m_listView; // list |
Jared Lindblom | a999630 | 2013-01-12 00:25:16 -0800 | [diff] [blame] | 73 | QTimer* m_timer; // timer |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 74 | |
Jared Lindblom | a999630 | 2013-01-12 00:25:16 -0800 | [diff] [blame] | 75 | QString m_dirPath; // monitored path |
| 76 | QHash<QString, sFileInfo> m_storedState; // stored state of directory |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | #endif // FILESYSTEMWATCHER_H |