blob: f02576950410047f3fb0c5196c7cc3b545571d0c [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;
Jared Lindblom8278b982013-01-12 15:45:09 -080022 std::string absFilePath;
Jared Lindbloma9996302013-01-12 00:25:16 -080023};
jareda9541812013-01-09 00:08:46 -080024
25namespace Ui {
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080026class FileSystemWatcher;
jareda9541812013-01-09 00:08:46 -080027}
28
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080029class FileSystemWatcher : public QMainWindow
jareda9541812013-01-09 00:08:46 -080030{
31 Q_OBJECT
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080032
jareda9541812013-01-09 00:08:46 -080033public:
34 // constructor
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080035 FileSystemWatcher(QString dirPath, QWidget *parent = 0);
jareda9541812013-01-09 00:08:46 -080036
37 // destructor
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080038 ~FileSystemWatcher();
jareda9541812013-01-09 00:08:46 -080039
40private slots:
Jared Lindblomf8d32ad2013-01-12 11:32:27 -080041 // handle callback from watcher
42 void watcherCallbackSlot(QString dirPath);
43
44 // handle callback from timer
45 void timerCallbackSlot();
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080046
jareda9541812013-01-09 00:08:46 -080047private:
Jared Lindblomf8d32ad2013-01-12 11:32:27 -080048 // handle callback from either the watcher or timer
49 void handleCallback(QString dirPath);
50
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080051 // scan directory and populate file list
Jared Lindblom8278b982013-01-12 15:45:09 -080052 QHash<QString, qint64> scanDirectory(QString dirPath);
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080053
54 // reconcile directory, find changes
Jared Lindblom8278b982013-01-12 15:45:09 -080055 QVector<sEventInfo> reconcileDirectory(QHash<QString, qint64> fileList, QString dirPath);
Jared Lindblomf8d32ad2013-01-12 11:32:27 -080056
57 // calculate checksum
58 QByteArray calcChecksum(QString absFilePath);
59
60 // print to GUI (DEBUG)
61 void printToGui(QVector<sEventInfo> dirChanges);
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080062
63private:
64 Ui::FileSystemWatcher* m_ui; // user interface
jareda9541812013-01-09 00:08:46 -080065 QFileSystemWatcher* m_watcher; // filesystem watcher
66 QStringListModel* m_listViewModel; // list view model
67 QListView* m_listView; // list
Jared Lindbloma9996302013-01-12 00:25:16 -080068 QTimer* m_timer; // timer
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080069
Jared Lindbloma9996302013-01-12 00:25:16 -080070 QString m_dirPath; // monitored path
Jared Lindblom8278b982013-01-12 15:45:09 -080071 QHash<QString, qint64> m_storedState; // stored state of directory
jareda9541812013-01-09 00:08:46 -080072};
73
74#endif // FILESYSTEMWATCHER_H