blob: aa1f3b89cad9cdc6fa8eec7f88ef1d7b4f6a5169 [file] [log] [blame]
jareda9541812013-01-09 00:08:46 -08001#ifndef FILESYSTEMWATCHER_H
2#define FILESYSTEMWATCHER_H
3
4#include <QtGui>
Jared Lindblom4d1d00a2013-01-11 01:14:23 -08005#include <QDebug>
6#include <QHash>
Jared Lindbloma9996302013-01-12 00:25:16 -08007#include <QCryptographicHash>
Jared Lindblomc1259722013-01-12 16:47:32 -08008
9#define DEBUG 1
Jared Lindblom264310d2013-01-12 01:18:58 -080010
11enum eEvent {
12 ADDED = 0,
13 MODIFIED,
14 DELETED
15};
16
17struct sEventInfo {
18 eEvent event;
Jared Lindblom8278b982013-01-12 15:45:09 -080019 std::string absFilePath;
Jared Lindbloma9996302013-01-12 00:25:16 -080020};
jareda9541812013-01-09 00:08:46 -080021
22namespace Ui {
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080023class FileSystemWatcher;
jareda9541812013-01-09 00:08:46 -080024}
25
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080026class FileSystemWatcher : public QMainWindow
jareda9541812013-01-09 00:08:46 -080027{
28 Q_OBJECT
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080029
jareda9541812013-01-09 00:08:46 -080030public:
31 // constructor
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080032 FileSystemWatcher(QString dirPath, QWidget *parent = 0);
jareda9541812013-01-09 00:08:46 -080033
34 // destructor
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080035 ~FileSystemWatcher();
jareda9541812013-01-09 00:08:46 -080036
Jared Lindblomc1259722013-01-12 16:47:32 -080037signals:
38 // directory event signal
39 void dirEventSignal(std::vector<sEventInfo> dirChanges);
40
jareda9541812013-01-09 00:08:46 -080041private slots:
Jared Lindblomf8d32ad2013-01-12 11:32:27 -080042 // handle callback from watcher
43 void watcherCallbackSlot(QString dirPath);
44
45 // handle callback from timer
46 void timerCallbackSlot();
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080047
jareda9541812013-01-09 00:08:46 -080048private:
Jared Lindblomf8d32ad2013-01-12 11:32:27 -080049 // handle callback from either the watcher or timer
50 void handleCallback(QString dirPath);
51
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080052 // scan directory and populate file list
Jared Lindblom8278b982013-01-12 15:45:09 -080053 QHash<QString, qint64> scanDirectory(QString dirPath);
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080054
55 // reconcile directory, find changes
Jared Lindblomc1259722013-01-12 16:47:32 -080056 std::vector<sEventInfo> reconcileDirectory(QHash<QString, qint64> fileList, QString dirPath);
Jared Lindblomf8d32ad2013-01-12 11:32:27 -080057
58 // calculate checksum
59 QByteArray calcChecksum(QString absFilePath);
60
Jared Lindblomc1259722013-01-12 16:47:32 -080061 // print Changes (DEBUG)
62 void printChanges(std::vector<sEventInfo> dirChanges);
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080063
64private:
65 Ui::FileSystemWatcher* m_ui; // user interface
jareda9541812013-01-09 00:08:46 -080066 QFileSystemWatcher* m_watcher; // filesystem watcher
67 QStringListModel* m_listViewModel; // list view model
68 QListView* m_listView; // list
Jared Lindbloma9996302013-01-12 00:25:16 -080069 QTimer* m_timer; // timer
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080070
Jared Lindbloma9996302013-01-12 00:25:16 -080071 QString m_dirPath; // monitored path
Jared Lindblom8278b982013-01-12 15:45:09 -080072 QHash<QString, qint64> m_storedState; // stored state of directory
jareda9541812013-01-09 00:08:46 -080073};
74
75#endif // FILESYSTEMWATCHER_H