Commits

Chris Cannam committed fa24288

Partially working FSEvents implementation: ignores some file changes it should be taking into account, at the moment

Comments (0)

Files changed (4)

 
 macx-* {
     SOURCES += src/common_osx.mm
-    LIBS += -framework Foundation
+    LIBS += -framework CoreServices -framework Foundation
     ICON = easyhg-icon.icns
 }
 

src/fswatcher.cpp

 
 #include <deque>
 
-//#define DEBUG_FSWATCHER 1
+#define DEBUG_FSWATCHER 1
 
 /*
  * Watching the filesystem is trickier than it seems at first glance.
 
 #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
 
 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
 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
 }
      */
     void changed();
 
-private slots:
+public slots:
     void fsDirectoryChanged(QString);
     void fsFileChanged(QString);
 

src/mainwindow.cpp

-/* -*- 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