changeset 585:fa242885a233 fswatcher

Partially working FSEvents implementation: ignores some file changes it should be taking into account, at the moment
author Chris Cannam
date Tue, 13 Mar 2012 17:58:17 +0000
parents 09b9849b9800
children 687d9e700e81
files easyhg.pro src/fswatcher.cpp src/fswatcher.h src/mainwindow.cpp
diffstat 4 files changed, 28 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/easyhg.pro	Mon Mar 12 17:25:41 2012 +0000
+++ b/easyhg.pro	Tue Mar 13 17:58:17 2012 +0000
@@ -109,7 +109,7 @@
 
 macx-* {
     SOURCES += src/common_osx.mm
-    LIBS += -framework Foundation
+    LIBS += -framework CoreServices -framework Foundation
     ICON = easyhg-icon.icns
 }
 
--- a/src/fswatcher.cpp	Mon Mar 12 17:25:41 2012 +0000
+++ b/src/fswatcher.cpp	Tue Mar 13 17:58:17 2012 +0000
@@ -28,7 +28,7 @@
 
 #include <deque>
 
-//#define DEBUG_FSWATCHER 1
+#define DEBUG_FSWATCHER 1
 
 /*
  * Watching the filesystem is trickier than it seems at first glance.
@@ -142,13 +142,18 @@
 
 #ifdef Q_OS_MAC
 static void
-fsEventsCallback(FSEventStreamRef streamRef,
+fsEventsCallback(ConstFSEventStreamRef streamRef,
                  void *clientCallBackInfo,
-                 int numEvents,
-                 const char *const eventPaths[],
-                 const FSEventStreamEventFlags *eventFlags,
-                 const uint64_t *eventIDs)
+                 size_t numEvents,
+                 void *paths,
+                 const FSEventStreamEventFlags eventFlags[],
+                 const FSEventStreamEventId eventIDs[])
 {
+    FsWatcher *watcher = reinterpret_cast<FsWatcher *>(clientCallBackInfo);
+    const char *const *cpaths = reinterpret_cast<const char *const *>(paths);
+    for (size_t i = 0; i < numEvents; ++i) {
+        watcher->fsDirectoryChanged(QString::fromLocal8Bit(cpaths[i]));
+    }
 }
 #endif
 
@@ -156,10 +161,20 @@
 FsWatcher::addWorkDirectory(QString path)
 {
 #ifdef Q_OS_MAC
+
+    CFStringRef cfPath = CFStringCreateWithCharacters
+        (0, reinterpret_cast<const UniChar *>(path.unicode()),
+         path.length());
+
+    CFArrayRef cfPaths = CFArrayCreate(0, (const void **)&cfPath, 1, 0);
+
+    FSEventStreamContext ctx = { 0, 0, 0, 0, 0 };
+    ctx.info = this;
+
     FSEventStreamRef stream =
         FSEventStreamCreate(kCFAllocatorDefault,
-                            (FSEventStreamCallback)&fsEventsCallback,
-                            this,
+                            &fsEventsCallback,
+                            &ctx,
                             cfPaths,
                             kFSEventStreamEventIdSinceNow,
                             1.0, // latency, seconds
@@ -377,8 +392,10 @@
 FsWatcher::debugPrint()
 {
 #ifdef DEBUG_FSWATCHER
+#ifndef Q_OS_MAC
     std::cerr << "FsWatcher: Now watching " << m_watcher.directories().size()
               << " directories and " << m_watcher.files().size()
               << " files" << std::endl;
 #endif
+#endif
 }
--- a/src/fswatcher.h	Mon Mar 12 17:25:41 2012 +0000
+++ b/src/fswatcher.h	Tue Mar 13 17:58:17 2012 +0000
@@ -92,7 +92,7 @@
      */
     void changed();
 
-private slots:
+public slots:
     void fsDirectoryChanged(QString);
     void fsFileChanged(QString);
 
--- a/src/mainwindow.cpp	Mon Mar 12 17:25:41 2012 +0000
+++ b/src/mainwindow.cpp	Tue Mar 13 17:58:17 2012 +0000
@@ -1,4 +1,4 @@
-/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+ /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
 
 /*
     EasyMercurial