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; |
Jared Lindblom | 8278b98 | 2013-01-12 15:45:09 -0800 | [diff] [blame^] | 22 | std::string absFilePath; |
Jared Lindblom | a999630 | 2013-01-12 00:25:16 -0800 | [diff] [blame] | 23 | }; |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 24 | |
| 25 | namespace Ui { |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 26 | class FileSystemWatcher; |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 27 | } |
| 28 | |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 29 | class FileSystemWatcher : public QMainWindow |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 30 | { |
| 31 | Q_OBJECT |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 32 | |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 33 | public: |
| 34 | // constructor |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 35 | FileSystemWatcher(QString dirPath, QWidget *parent = 0); |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 36 | |
| 37 | // destructor |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 38 | ~FileSystemWatcher(); |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 39 | |
| 40 | private slots: |
Jared Lindblom | f8d32ad | 2013-01-12 11:32:27 -0800 | [diff] [blame] | 41 | // handle callback from watcher |
| 42 | void watcherCallbackSlot(QString dirPath); |
| 43 | |
| 44 | // handle callback from timer |
| 45 | void timerCallbackSlot(); |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 46 | |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 47 | private: |
Jared Lindblom | f8d32ad | 2013-01-12 11:32:27 -0800 | [diff] [blame] | 48 | // handle callback from either the watcher or timer |
| 49 | void handleCallback(QString dirPath); |
| 50 | |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 51 | // scan directory and populate file list |
Jared Lindblom | 8278b98 | 2013-01-12 15:45:09 -0800 | [diff] [blame^] | 52 | QHash<QString, qint64> scanDirectory(QString dirPath); |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 53 | |
| 54 | // reconcile directory, find changes |
Jared Lindblom | 8278b98 | 2013-01-12 15:45:09 -0800 | [diff] [blame^] | 55 | QVector<sEventInfo> reconcileDirectory(QHash<QString, qint64> fileList, QString dirPath); |
Jared Lindblom | f8d32ad | 2013-01-12 11:32:27 -0800 | [diff] [blame] | 56 | |
| 57 | // calculate checksum |
| 58 | QByteArray calcChecksum(QString absFilePath); |
| 59 | |
| 60 | // print to GUI (DEBUG) |
| 61 | void printToGui(QVector<sEventInfo> dirChanges); |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 62 | |
| 63 | private: |
| 64 | Ui::FileSystemWatcher* m_ui; // user interface |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 65 | QFileSystemWatcher* m_watcher; // filesystem watcher |
| 66 | QStringListModel* m_listViewModel; // list view model |
| 67 | QListView* m_listView; // list |
Jared Lindblom | a999630 | 2013-01-12 00:25:16 -0800 | [diff] [blame] | 68 | QTimer* m_timer; // timer |
Jared Lindblom | 4d1d00a | 2013-01-11 01:14:23 -0800 | [diff] [blame] | 69 | |
Jared Lindblom | a999630 | 2013-01-12 00:25:16 -0800 | [diff] [blame] | 70 | QString m_dirPath; // monitored path |
Jared Lindblom | 8278b98 | 2013-01-12 15:45:09 -0800 | [diff] [blame^] | 71 | QHash<QString, qint64> m_storedState; // stored state of directory |
jared | a954181 | 2013-01-09 00:08:46 -0800 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | #endif // FILESYSTEMWATCHER_H |