blob: 1e17524b55a6e3a80736a34222cc9adbaf8b439e [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 Lindbloma9996302013-01-12 00:25:16 -080046 // handle callback from either the watcher or timer
47 void handleCallback();
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080048
jareda9541812013-01-09 00:08:46 -080049private:
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080050 // scan directory and populate file list
Jared Lindbloma9996302013-01-12 00:25:16 -080051 QHash<QString, sFileInfo> scanDirectory(QString filePath);
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080052
53 // reconcile directory, find changes
Jared Lindblom264310d2013-01-12 01:18:58 -080054 QVector<sEventInfo> reconcileDirectory(QHash<QString, sFileInfo> fileList);
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080055
56private:
57 Ui::FileSystemWatcher* m_ui; // user interface
jareda9541812013-01-09 00:08:46 -080058 QFileSystemWatcher* m_watcher; // filesystem watcher
59 QStringListModel* m_listViewModel; // list view model
60 QListView* m_listView; // list
Jared Lindbloma9996302013-01-12 00:25:16 -080061 QTimer* m_timer; // timer
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080062
Jared Lindbloma9996302013-01-12 00:25:16 -080063 QString m_dirPath; // monitored path
64 QHash<QString, sFileInfo> m_storedState; // stored state of directory
jareda9541812013-01-09 00:08:46 -080065};
66
67#endif // FILESYSTEMWATCHER_H