Added a registerable signal (callback) function and an example use class, simpleeventcatcher. filesystemwatcher is fully implemented.
diff --git a/filesystemwatcher/filesystemwatcher.cpp b/filesystemwatcher/filesystemwatcher.cpp
index 13b1c7d..79363e8 100644
--- a/filesystemwatcher/filesystemwatcher.cpp
+++ b/filesystemwatcher/filesystemwatcher.cpp
@@ -1,34 +1,40 @@
-#include "filesystemwatcher.h"
-#include "ui_filesystemwatcher.h"
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012-2013 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Jared Lindblom <lindblom@cs.ucla.edu>
+ */
-FileSystemWatcher::FileSystemWatcher(QString dirPath, QWidget *parent) :
- QMainWindow(parent),
- m_ui(new Ui::FileSystemWatcher),
+#include "filesystemwatcher.h"
+
+FileSystemWatcher::FileSystemWatcher(QString dirPath, QObject* parent) :
+ QObject(parent),
m_watcher(new QFileSystemWatcher()),
- m_listViewModel(new QStringListModel()),
- m_listView(new QListView()),
- m_timer(new QTimer(this)),
+ m_timer(new QTimer()),
m_dirPath(dirPath)
{
- // setup user interface
- m_ui->setupUi(this);
-
// add main directory to monitor
m_watcher->addPath(m_dirPath);
- // create the view
- m_listView->setModel(m_listViewModel);
- setCentralWidget(m_listView);
-
- // set title
- setWindowTitle("ChronoShare");
-
// register signals (callback functions)
connect(m_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(watcherCallbackSlot(QString)));
connect(m_timer, SIGNAL(timeout()), this, SLOT(timerCallbackSlot()));
// bootstrap
- timerCallbackSlot();
+ QTimer::singleShot(1000, this, SLOT(bootstrap()));
// start timer
m_timer->start(300000);
@@ -37,13 +43,16 @@
FileSystemWatcher::~FileSystemWatcher()
{
// clean up
- delete m_ui;
delete m_watcher;
- delete m_listViewModel;
- delete m_listView;
delete m_timer;
}
+void FileSystemWatcher::bootstrap()
+{
+ // bootstrap specific steps
+ timerCallbackSlot();
+}
+
void FileSystemWatcher::watcherCallbackSlot(QString dirPath)
{
// watcher specific steps
@@ -69,13 +78,12 @@
// reconcile directory and report changes
std::vector<sEventInfo> dirChanges = reconcileDirectory(currentState, dirPath);
-
- emit dirEventSignal(dirChanges);
-
#if DEBUG
// DEBUG: Print Changes
printChanges(dirChanges);
#endif
+ // emit the signal
+ emit dirEventSignal(dirChanges);
}
QHash<QString, qint64> FileSystemWatcher::scanDirectory(QString dirPath)
@@ -219,8 +227,6 @@
{
if(!dirChanges.empty())
{
- QStringList dirChangesList;
-
for(size_t i = 0; i < dirChanges.size(); i++)
{
QString tempString;
@@ -242,19 +248,13 @@
}
tempString.append(absFilePath);
-#if DEBUG
- qDebug() << "\t" << tempString;
-#endif
- dirChangesList.append(tempString);
- }
- m_listViewModel->setStringList(dirChangesList);
+ qDebug() << "\t" << tempString;
+ }
}
else
{
-#if DEBUG
qDebug() << "\t[EMPTY]";
-#endif
}
}