@@ -26,12 +26,13 @@
|
|||||||
#include <CoreServices/CoreServices.h>
|
#include <CoreServices/CoreServices.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QTimer>
|
#include <QString>
|
||||||
|
|
||||||
#include "filesystemwatcherinterface.h"
|
#include "filesystemwatcherinterface.h"
|
||||||
|
|
||||||
|
class QTimer;
|
||||||
|
|
||||||
class MacFSListener : public FileSystemWatcherInterface {
|
class MacFSListener : public FileSystemWatcherInterface {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -57,7 +58,7 @@ signals:
|
|||||||
FSEventStreamRef stream_;
|
FSEventStreamRef stream_;
|
||||||
|
|
||||||
QSet<QString> paths_;
|
QSet<QString> paths_;
|
||||||
QTimer update_timer_;
|
QTimer *update_timer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include <CoreFoundation/CFArray.h>
|
#include <CoreFoundation/CFArray.h>
|
||||||
#include <Foundation/NSArray.h>
|
#include <Foundation/NSArray.h>
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
@@ -30,21 +32,21 @@
|
|||||||
#include "scoped_nsobject.h"
|
#include "scoped_nsobject.h"
|
||||||
|
|
||||||
MacFSListener::MacFSListener(QObject* parent)
|
MacFSListener::MacFSListener(QObject* parent)
|
||||||
: FileSystemWatcherInterface(parent), run_loop_(nullptr), stream_(nullptr) {
|
: FileSystemWatcherInterface(parent),
|
||||||
update_timer_.setSingleShot(true);
|
run_loop_(nullptr),
|
||||||
update_timer_.setInterval(2000);
|
stream_(nullptr),
|
||||||
connect(&update_timer_, SIGNAL(timeout()), SLOT(UpdateStream()));
|
update_timer_(new QTimer(this)) {
|
||||||
|
|
||||||
|
update_timer_->setSingleShot(true);
|
||||||
|
update_timer_->setInterval(2000);
|
||||||
|
connect(update_timer_, SIGNAL(timeout()), SLOT(UpdateStream()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacFSListener::Init() { run_loop_ = CFRunLoopGetCurrent(); }
|
void MacFSListener::Init() { run_loop_ = CFRunLoopGetCurrent(); }
|
||||||
|
|
||||||
void MacFSListener::EventStreamCallback(
|
void MacFSListener::EventStreamCallback(ConstFSEventStreamRef stream, void* user_data, size_t num_events, void* event_paths, const FSEventStreamEventFlags event_flags[], const FSEventStreamEventId event_ids[]) {
|
||||||
ConstFSEventStreamRef stream,
|
|
||||||
void* user_data,
|
|
||||||
size_t num_events,
|
|
||||||
void* event_paths,
|
|
||||||
const FSEventStreamEventFlags event_flags[],
|
|
||||||
const FSEventStreamEventId event_ids[]) {
|
|
||||||
MacFSListener* me = reinterpret_cast<MacFSListener*>(user_data);
|
MacFSListener* me = reinterpret_cast<MacFSListener*>(user_data);
|
||||||
char** paths = reinterpret_cast<char**>(event_paths);
|
char** paths = reinterpret_cast<char**>(event_paths);
|
||||||
for (int i = 0; i < num_events; ++i) {
|
for (int i = 0; i < num_events; ++i) {
|
||||||
@@ -55,26 +57,35 @@ void MacFSListener::EventStreamCallback(
|
|||||||
}
|
}
|
||||||
emit me->PathChanged(path);
|
emit me->PathChanged(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacFSListener::AddPath(const QString& path) {
|
void MacFSListener::AddPath(const QString& path) {
|
||||||
|
|
||||||
Q_ASSERT(run_loop_);
|
Q_ASSERT(run_loop_);
|
||||||
paths_.insert(path);
|
paths_.insert(path);
|
||||||
UpdateStreamAsync();
|
UpdateStreamAsync();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacFSListener::RemovePath(const QString& path) {
|
void MacFSListener::RemovePath(const QString& path) {
|
||||||
|
|
||||||
Q_ASSERT(run_loop_);
|
Q_ASSERT(run_loop_);
|
||||||
paths_.remove(path);
|
paths_.remove(path);
|
||||||
UpdateStreamAsync();
|
UpdateStreamAsync();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacFSListener::Clear() {
|
void MacFSListener::Clear() {
|
||||||
|
|
||||||
paths_.clear();
|
paths_.clear();
|
||||||
UpdateStreamAsync();
|
UpdateStreamAsync();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacFSListener::UpdateStreamAsync() { update_timer_.start(); }
|
void MacFSListener::UpdateStreamAsync() {
|
||||||
|
update_timer_->start();
|
||||||
|
}
|
||||||
|
|
||||||
void MacFSListener::UpdateStream() {
|
void MacFSListener::UpdateStream() {
|
||||||
if (stream_) {
|
if (stream_) {
|
||||||
@@ -88,11 +99,10 @@ void MacFSListener::UpdateStream() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
scoped_nsobject<NSMutableArray> array([[NSMutableArray alloc] init]);
|
scoped_nsobject<NSMutableArray> array([ [NSMutableArray alloc] init]);
|
||||||
|
|
||||||
for (const QString& path : paths_) {
|
for (const QString& path : paths_) {
|
||||||
scoped_nsobject<NSString> string(
|
scoped_nsobject<NSString> string([ [NSString alloc] initWithUTF8String:path.toUtf8().constData()]);
|
||||||
[[NSString alloc] initWithUTF8String:path.toUtf8().constData()]);
|
|
||||||
[array addObject:string.get()];
|
[array addObject:string.get()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user