Added dirEvent signal for rest of chronoshare, cleaned code
diff --git a/filesystemwatcher/filesystemwatcher.cpp b/filesystemwatcher/filesystemwatcher.cpp
index d6e82ee..13b1c7d 100644
--- a/filesystemwatcher/filesystemwatcher.cpp
+++ b/filesystemwatcher/filesystemwatcher.cpp
@@ -47,16 +47,18 @@
void FileSystemWatcher::watcherCallbackSlot(QString dirPath)
{
// watcher specific steps
+#if DEBUG
qDebug() << endl << "[WATCHER] Triggered Path: " << dirPath;
-
+#endif
handleCallback(dirPath);
}
void FileSystemWatcher::timerCallbackSlot()
{
// timer specific steps
+#if DEBUG
qDebug() << endl << "[TIMER] Triggered Path: " << m_dirPath;
-
+#endif
handleCallback(m_dirPath);
}
@@ -66,10 +68,14 @@
QHash<QString, qint64> currentState = scanDirectory(dirPath);
// reconcile directory and report changes
- QVector<sEventInfo> dirChanges = reconcileDirectory(currentState, dirPath);
+ std::vector<sEventInfo> dirChanges = reconcileDirectory(currentState, dirPath);
- // DEBUG: Print to Gui
- printToGui(dirChanges);
+ emit dirEventSignal(dirChanges);
+
+#if DEBUG
+ // DEBUG: Print Changes
+ printChanges(dirChanges);
+#endif
}
QHash<QString, qint64> FileSystemWatcher::scanDirectory(QString dirPath)
@@ -118,10 +124,10 @@
return currentState;
}
-QVector<sEventInfo> FileSystemWatcher::reconcileDirectory(QHash<QString, qint64> currentState, QString dirPath)
+std::vector<sEventInfo> FileSystemWatcher::reconcileDirectory(QHash<QString, qint64> currentState, QString dirPath)
{
// list of files changed
- QVector<sEventInfo> dirChanges;
+ std::vector<sEventInfo> dirChanges;
// compare result (database/stored snapshot) to fileList (current snapshot)
QMutableHashIterator<QString, qint64> i(m_storedState);
@@ -209,13 +215,13 @@
return crypto.result();
}
-void FileSystemWatcher::printToGui(QVector<sEventInfo> dirChanges)
+void FileSystemWatcher::printChanges(std::vector<sEventInfo> dirChanges)
{
- if(!dirChanges.isEmpty())
+ if(!dirChanges.empty())
{
QStringList dirChangesList;
- for(int i = 0; i < dirChanges.size(); i++)
+ for(size_t i = 0; i < dirChanges.size(); i++)
{
QString tempString;
@@ -236,14 +242,20 @@
}
tempString.append(absFilePath);
-
- dirChangesList.append(tempString);
-
+#if DEBUG
qDebug() << "\t" << tempString;
+#endif
+ dirChangesList.append(tempString);
}
m_listViewModel->setStringList(dirChangesList);
}
+ else
+ {
+#if DEBUG
+ qDebug() << "\t[EMPTY]";
+#endif
+ }
}
#if WAF
diff --git a/filesystemwatcher/filesystemwatcher.h b/filesystemwatcher/filesystemwatcher.h
index f025769..aa1f3b8 100644
--- a/filesystemwatcher/filesystemwatcher.h
+++ b/filesystemwatcher/filesystemwatcher.h
@@ -2,14 +2,11 @@
#define FILESYSTEMWATCHER_H
#include <QtGui>
-#include <QSqlDatabase>
-#include <QSqlQuery>
-#include <QSqlResult>
-#include <QSqlError>
#include <QDebug>
#include <QHash>
#include <QCryptographicHash>
-#include <QVector>
+
+#define DEBUG 1
enum eEvent {
ADDED = 0,
@@ -37,6 +34,10 @@
// destructor
~FileSystemWatcher();
+signals:
+ // directory event signal
+ void dirEventSignal(std::vector<sEventInfo> dirChanges);
+
private slots:
// handle callback from watcher
void watcherCallbackSlot(QString dirPath);
@@ -52,13 +53,13 @@
QHash<QString, qint64> scanDirectory(QString dirPath);
// reconcile directory, find changes
- QVector<sEventInfo> reconcileDirectory(QHash<QString, qint64> fileList, QString dirPath);
+ std::vector<sEventInfo> reconcileDirectory(QHash<QString, qint64> fileList, QString dirPath);
// calculate checksum
QByteArray calcChecksum(QString absFilePath);
- // print to GUI (DEBUG)
- void printToGui(QVector<sEventInfo> dirChanges);
+ // print Changes (DEBUG)
+ void printChanges(std::vector<sEventInfo> dirChanges);
private:
Ui::FileSystemWatcher* m_ui; // user interface