blob: 002ff5f1a86e952955874a5bfc2679890630590a [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 <QSqlDatabase>
6#include <QSqlQuery>
7#include <QSqlResult>
Jared Lindbloma9996302013-01-12 00:25:16 -08008#include <QSqlError>
Jared Lindblom4d1d00a2013-01-11 01:14:23 -08009#include <QDebug>
10#include <QHash>
Jared Lindbloma9996302013-01-12 00:25:16 -080011#include <QCryptographicHash>
Jared Lindblom264310d2013-01-12 01:18:58 -080012#include <QVector>
13
14enum eEvent {
15 ADDED = 0,
16 MODIFIED,
17 DELETED
18};
19
20struct sEventInfo {
21 eEvent event;
22 QString absFilePath;
23};
Jared Lindbloma9996302013-01-12 00:25:16 -080024
25struct sFileInfo {
26 QByteArray hash;
27 QFileInfo fileInfo;
28};
jareda9541812013-01-09 00:08:46 -080029
30namespace Ui {
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080031class FileSystemWatcher;
jareda9541812013-01-09 00:08:46 -080032}
33
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080034class FileSystemWatcher : public QMainWindow
jareda9541812013-01-09 00:08:46 -080035{
36 Q_OBJECT
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080037
jareda9541812013-01-09 00:08:46 -080038public:
39 // constructor
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080040 FileSystemWatcher(QString dirPath, QWidget *parent = 0);
jareda9541812013-01-09 00:08:46 -080041
42 // destructor
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080043 ~FileSystemWatcher();
jareda9541812013-01-09 00:08:46 -080044
45private slots:
Jared Lindblomf8d32ad2013-01-12 11:32:27 -080046 // handle callback from watcher
47 void watcherCallbackSlot(QString dirPath);
48
49 // handle callback from timer
50 void timerCallbackSlot();
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080051
jareda9541812013-01-09 00:08:46 -080052private:
Jared Lindblomf8d32ad2013-01-12 11:32:27 -080053 // handle callback from either the watcher or timer
54 void handleCallback(QString dirPath);
55
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080056 // scan directory and populate file list
Jared Lindblomf8d32ad2013-01-12 11:32:27 -080057 QHash<QString, sFileInfo> scanDirectory(QString dirPath);
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080058
59 // reconcile directory, find changes
Jared Lindblomf8d32ad2013-01-12 11:32:27 -080060 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 Lindblom4d1d00a2013-01-11 01:14:23 -080067
68private:
69 Ui::FileSystemWatcher* m_ui; // user interface
jareda9541812013-01-09 00:08:46 -080070 QFileSystemWatcher* m_watcher; // filesystem watcher
71 QStringListModel* m_listViewModel; // list view model
72 QListView* m_listView; // list
Jared Lindbloma9996302013-01-12 00:25:16 -080073 QTimer* m_timer; // timer
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080074
Jared Lindbloma9996302013-01-12 00:25:16 -080075 QString m_dirPath; // monitored path
76 QHash<QString, sFileInfo> m_storedState; // stored state of directory
jareda9541812013-01-09 00:08:46 -080077};
78
79#endif // FILESYSTEMWATCHER_H