Remove MacFSListener
It's no longer needed. This code dates back to before Qt had a FSEvents-based filesystem listener.
This commit is contained in:
@@ -866,7 +866,6 @@ optional_source(APPLE
|
|||||||
core/scoped_nsautorelease_pool.mm
|
core/scoped_nsautorelease_pool.mm
|
||||||
core/mac_startup.mm
|
core/mac_startup.mm
|
||||||
core/macsystemtrayicon.mm
|
core/macsystemtrayicon.mm
|
||||||
core/macfslistener.mm
|
|
||||||
osd/osdmac.mm
|
osd/osdmac.mm
|
||||||
widgets/searchfield_mac.mm
|
widgets/searchfield_mac.mm
|
||||||
engine/macosdevicefinder.cpp
|
engine/macosdevicefinder.cpp
|
||||||
@@ -875,7 +874,6 @@ optional_source(APPLE
|
|||||||
device/macosdevicelister.mm
|
device/macosdevicelister.mm
|
||||||
HEADERS
|
HEADERS
|
||||||
core/macsystemtrayicon.h
|
core/macsystemtrayicon.h
|
||||||
core/macfslistener.h
|
|
||||||
osd/osdmac.h
|
osd/osdmac.h
|
||||||
globalshortcuts/globalshortcutsbackend-macos.h
|
globalshortcuts/globalshortcutsbackend-macos.h
|
||||||
device/macosdevicelister.h
|
device/macosdevicelister.h
|
||||||
|
|||||||
@@ -25,22 +25,14 @@
|
|||||||
#include "filesystemwatcherinterface.h"
|
#include "filesystemwatcherinterface.h"
|
||||||
#include "qtfslistener.h"
|
#include "qtfslistener.h"
|
||||||
|
|
||||||
#ifdef Q_OS_MACOS
|
|
||||||
# include "macfslistener.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
FileSystemWatcherInterface::FileSystemWatcherInterface(QObject *parent)
|
FileSystemWatcherInterface::FileSystemWatcherInterface(QObject *parent)
|
||||||
: QObject(parent) {}
|
: QObject(parent) {}
|
||||||
|
|
||||||
FileSystemWatcherInterface *FileSystemWatcherInterface::Create(QObject *parent) {
|
FileSystemWatcherInterface *FileSystemWatcherInterface::Create(QObject *parent) {
|
||||||
|
|
||||||
#ifdef Q_OS_MACOS
|
FileSystemWatcherInterface *listener = new QtFSListener(parent);
|
||||||
FileSystemWatcherInterface *ret = new MacFSListener(parent);
|
listener->Init();
|
||||||
#else
|
|
||||||
FileSystemWatcherInterface *ret = new QtFSListener(parent);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ret->Init();
|
return listener;
|
||||||
return ret;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* Strawberry Music Player
|
|
||||||
* This file was part of Clementine.
|
|
||||||
* Copyright 2012, David Sansome <me@davidsansome.com>
|
|
||||||
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
|
||||||
*
|
|
||||||
* Strawberry is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef MACFSLISTENER_H
|
|
||||||
#define MACFSLISTENER_H
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <CoreServices/CoreServices.h>
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QSet>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
#include "filesystemwatcherinterface.h"
|
|
||||||
|
|
||||||
class QTimer;
|
|
||||||
|
|
||||||
class MacFSListener : public FileSystemWatcherInterface {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit MacFSListener(QObject *parent = nullptr);
|
|
||||||
void Init();
|
|
||||||
void AddPath(const QString &path);
|
|
||||||
void RemovePath(const QString &path);
|
|
||||||
void Clear();
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void PathChanged(const QString &path);
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void UpdateStream();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void UpdateStreamAsync();
|
|
||||||
|
|
||||||
static void EventStreamCallback(ConstFSEventStreamRef stream, void *user_data, size_t num_events, void *event_paths, const FSEventStreamEventFlags event_flags[], const FSEventStreamEventId event_ids[]);
|
|
||||||
|
|
||||||
CFRunLoopRef run_loop_;
|
|
||||||
FSEventStreamRef stream_;
|
|
||||||
|
|
||||||
QSet<QString> paths_;
|
|
||||||
QTimer *update_timer_;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // MACFSLISTENER_H
|
|
||||||
@@ -1,130 +0,0 @@
|
|||||||
/*
|
|
||||||
* Strawberry Music Player
|
|
||||||
* This file was part of Clementine.
|
|
||||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
|
||||||
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
|
||||||
*
|
|
||||||
* Strawberry is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "macfslistener.h"
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include <CoreFoundation/CFArray.h>
|
|
||||||
#include <Foundation/NSArray.h>
|
|
||||||
#include <Foundation/NSString.h>
|
|
||||||
|
|
||||||
#include "core/logging.h"
|
|
||||||
#include "scoped_nsobject.h"
|
|
||||||
|
|
||||||
using namespace Qt::Literals::StringLiterals;
|
|
||||||
|
|
||||||
MacFSListener::MacFSListener(QObject *parent)
|
|
||||||
: FileSystemWatcherInterface(parent),
|
|
||||||
run_loop_(nullptr),
|
|
||||||
stream_(nullptr),
|
|
||||||
update_timer_(new QTimer(this)) {
|
|
||||||
|
|
||||||
update_timer_->setSingleShot(true);
|
|
||||||
update_timer_->setInterval(2000);
|
|
||||||
QObject::connect(update_timer_, &QTimer::timeout, this, &MacFSListener::UpdateStream);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacFSListener::Init() { run_loop_ = CFRunLoopGetCurrent(); }
|
|
||||||
|
|
||||||
void MacFSListener::EventStreamCallback(ConstFSEventStreamRef stream, void *user_data, size_t num_events, void *event_paths, const FSEventStreamEventFlags event_flags[], const FSEventStreamEventId event_ids[]) {
|
|
||||||
|
|
||||||
Q_UNUSED(stream);
|
|
||||||
Q_UNUSED(event_flags);
|
|
||||||
Q_UNUSED(event_ids);
|
|
||||||
|
|
||||||
MacFSListener *me = reinterpret_cast<MacFSListener*>(user_data);
|
|
||||||
char **paths = reinterpret_cast<char**>(event_paths);
|
|
||||||
for (size_t i = 0; i < num_events; ++i) {
|
|
||||||
QString path = QString::fromUtf8(paths[i]);
|
|
||||||
qLog(Debug) << "Something changed at:" << path;
|
|
||||||
while (path.endsWith(u'/')) {
|
|
||||||
path.chop(1);
|
|
||||||
}
|
|
||||||
Q_EMIT me->PathChanged(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacFSListener::AddPath(const QString &path) {
|
|
||||||
|
|
||||||
Q_ASSERT(run_loop_);
|
|
||||||
paths_.insert(path);
|
|
||||||
UpdateStreamAsync();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacFSListener::RemovePath(const QString &path) {
|
|
||||||
|
|
||||||
Q_ASSERT(run_loop_);
|
|
||||||
paths_.remove(path);
|
|
||||||
UpdateStreamAsync();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacFSListener::Clear() {
|
|
||||||
|
|
||||||
paths_.clear();
|
|
||||||
UpdateStreamAsync();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacFSListener::UpdateStreamAsync() {
|
|
||||||
update_timer_->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacFSListener::UpdateStream() {
|
|
||||||
|
|
||||||
if (stream_) {
|
|
||||||
FSEventStreamStop(stream_);
|
|
||||||
FSEventStreamInvalidate(stream_);
|
|
||||||
FSEventStreamRelease(stream_);
|
|
||||||
stream_ = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (paths_.empty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
scoped_nsobject<NSMutableArray> array([ [NSMutableArray alloc] init]);
|
|
||||||
|
|
||||||
for (const QString &path : paths_) {
|
|
||||||
scoped_nsobject<NSString> string([ [NSString alloc] initWithUTF8String:path.toUtf8().constData()]);
|
|
||||||
[array addObject:string.get()];
|
|
||||||
}
|
|
||||||
|
|
||||||
FSEventStreamContext context;
|
|
||||||
memset(&context, 0, sizeof(context));
|
|
||||||
context.info = this;
|
|
||||||
CFAbsoluteTime latency = 1.0;
|
|
||||||
|
|
||||||
stream_ = FSEventStreamCreate(nullptr, &EventStreamCallback, &context, // Copied
|
|
||||||
reinterpret_cast<CFArrayRef>(array.get()),
|
|
||||||
kFSEventStreamEventIdSinceNow, latency,
|
|
||||||
kFSEventStreamCreateFlagNone);
|
|
||||||
|
|
||||||
FSEventStreamScheduleWithRunLoop(stream_, run_loop_, kCFRunLoopDefaultMode);
|
|
||||||
FSEventStreamStart(stream_);
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user