# HG changeset patch # User Chris Cannam # Date 1331661497 0 # Node ID fa242885a233cf3acf28b170833f0affebccbb7a # Parent 09b9849b98001e068e6a8f5b3618d1fe5477e867 Partially working FSEvents implementation: ignores some file changes it should be taking into account, at the moment diff -r 09b9849b9800 -r fa242885a233 easyhg.pro --- 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 } diff -r 09b9849b9800 -r fa242885a233 src/fswatcher.cpp --- 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 -//#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(clientCallBackInfo); + const char *const *cpaths = reinterpret_cast(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(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 } diff -r 09b9849b9800 -r fa242885a233 src/fswatcher.h --- 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); diff -r 09b9849b9800 -r fa242885a233 src/mainwindow.cpp --- 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