blob: 5891d6ca258ce16d9ef6f187a3c7a763c28f0390 [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>
12
13struct sFileInfo {
14 QByteArray hash;
15 QFileInfo fileInfo;
16};
jareda9541812013-01-09 00:08:46 -080017
18namespace Ui {
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080019class FileSystemWatcher;
jareda9541812013-01-09 00:08:46 -080020}
21
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080022class FileSystemWatcher : public QMainWindow
jareda9541812013-01-09 00:08:46 -080023{
24 Q_OBJECT
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080025
jareda9541812013-01-09 00:08:46 -080026public:
27 // constructor
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080028 FileSystemWatcher(QString dirPath, QWidget *parent = 0);
jareda9541812013-01-09 00:08:46 -080029
30 // destructor
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080031 ~FileSystemWatcher();
jareda9541812013-01-09 00:08:46 -080032
33private slots:
Jared Lindbloma9996302013-01-12 00:25:16 -080034 // handle callback from either the watcher or timer
35 void handleCallback();
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080036
jareda9541812013-01-09 00:08:46 -080037private:
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080038 // scan directory and populate file list
Jared Lindbloma9996302013-01-12 00:25:16 -080039 QHash<QString, sFileInfo> scanDirectory(QString filePath);
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080040
41 // reconcile directory, find changes
Jared Lindbloma9996302013-01-12 00:25:16 -080042 QStringList reconcileDirectory(QHash<QString, sFileInfo> fileList);
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080043
44private:
45 Ui::FileSystemWatcher* m_ui; // user interface
jareda9541812013-01-09 00:08:46 -080046 QFileSystemWatcher* m_watcher; // filesystem watcher
47 QStringListModel* m_listViewModel; // list view model
48 QListView* m_listView; // list
Jared Lindbloma9996302013-01-12 00:25:16 -080049 QTimer* m_timer; // timer
Jared Lindblom4d1d00a2013-01-11 01:14:23 -080050
Jared Lindbloma9996302013-01-12 00:25:16 -080051 QString m_dirPath; // monitored path
52 QHash<QString, sFileInfo> m_storedState; // stored state of directory
jareda9541812013-01-09 00:08:46 -080053};
54
55#endif // FILESYSTEMWATCHER_H